Changeset 529
- Timestamp:
- 05/02/08 07:55:03 (8 months ago)
- Files:
-
- trunk/run/data/shaders/model.pixel.glsl (modified) (1 diff)
- trunk/run/data/shaders/shadowmap.glsl (modified) (1 diff)
- trunk/run/data/shaders/terrain.pixel.glsl (modified) (1 diff)
- trunk/src/defend/game/hud/MiniMap.d (modified) (2 diffs)
- trunk/src/defend/game/hud/Mouse.d (modified) (1 diff)
- trunk/src/defend/objects/SceneNode.d (modified) (1 diff)
- trunk/src/defend/terrain/Terrain.d (modified) (1 diff)
- trunk/src/gen/rend/Framebuffer.d (added)
- trunk/src/gen/rend/Renderer.d (modified) (2 diffs)
- trunk/src/gen/rend/opengl/FBO.d (added)
- trunk/src/gen/rend/opengl/Renderer.d (modified) (2 diffs)
- trunk/src/gen/rend/opengl/Shader.d (modified) (1 diff)
- trunk/src/gen/rend/opengl/Texture.d (modified) (4 diffs)
- trunk/src/gen/scene/Graph.d (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/run/data/shaders/model.pixel.glsl
r528 r529 14 14 vec4 light = texture2D(lightTexture, vec2(gl_TexCoord[1])); 15 15 16 gl_FragColor = vec4(tex.rgb * tex.a + color * (1 - tex.a), 1.0) * gl_Color * (light * 2) * shadowMap(shadow, lightSpacePos); 16 gl_FragColor = vec4(tex.rgb * tex.a + color * (1 - tex.a), 1.0) * gl_Color * (light * 2); //* shadowMap(shadow, lightSpacePos); 17 //gl_FragColor = vec4(shadowMap(shadow, lightSpacePos)); 17 18 } trunk/run/data/shaders/shadowmap.glsl
r523 r529 8 8 float lightDistance = lightSpacePos.z / lightSpacePos.w; 9 9 10 //if(shadowMapCoord.x >= 0 && shadowMapCoord.x <= 1 && shadowMapCoord.y >= 0 && shadowMapCoord.y <= 1) 11 // return 1.0f; 12 13 //return lightDistance; 14 //return shadowMapDistance; 15 10 16 if(shadowMapCoord.x >= 0 && shadowMapCoord.x <= 1 && shadowMapCoord.y >= 0 && shadowMapCoord.y <= 1 && 11 lightDistance + 0.2f >= shadowMapDistance && shadowMapDistance != 1.0f) // point is in shadow 12 return 0.3; 17 lightDistance + 1.2f >= shadowMapDistance && shadowMapDistance != 1.0f) // point is in shadow 18 return 0.35f; 19 20 //if(shadowMapCoord.x >= 0 && shadowMapCoord.x <= 1 && shadowMapCoord.y >= 0 && shadowMapCoord.y <= 1) 21 // return shadowMapDistance - lightDistance; 13 22 14 23 return 1.0f; trunk/run/data/shaders/terrain.pixel.glsl
r528 r529 23 23 c3 *= a.b * inverse; 24 24 25 //gl_FragColor = vec4(shadowMap(shadow, lightSpacePos)); 25 26 gl_FragColor = (c1 + c2 + c3) * (l * 2) * shadowMap(shadow, lightSpacePos); 26 27 } trunk/src/defend/game/hud/MiniMap.d
r528 r529 23 23 { 24 24 private: 25 const width = 128;26 const height = 128;25 const width = 2048; 26 const height = 2048; 27 27 28 28 Image image; … … 73 73 { 74 74 // shadow map test 75 texture = renderer.createTexture(vec2i(width, height), ImageFormat.A); 75 auto fb = renderer.createFramebuffer(vec2i(width, height), ImageFormat.A); 76 texture = fb.texture; 76 77 77 auto camera = new StaticCamera(vec3(- 50, 150, -59), vec3(-0.9, -1.57, 0),78 mat4.projection(width / height, 70, 50, 300));78 auto camera = new StaticCamera(vec3(-20, 40, -39), vec3(-0.9, -1.57, 0), 79 mat4.projection(width / height, 70, 50, 200)); 79 80 80 sceneGraph.addCamera("shadow", camera, vec3(0), texture, true); 81 //auto camera = new StaticCamera(vec3(-50, 150, -59), vec3(-0.9, -1.57, 0), 82 // mat4.projection(width / height, 70, 50, 300)); 83 84 sceneGraph.addCamera("shadow", camera, vec3(0), fb, true); 85 81 86 //sceneGraph.addCamera("shadow", sceneGraph.getCamera("main").core, vec3(0), texture, false); 82 87 trunk/src/defend/game/hud/Mouse.d
r524 r529 586 586 mouseCube.scaling = vec3(0.05); 587 587 mouseCube.hide = true; 588 mouseCube.renderShadow = true; 588 589 589 590 placeObjectNode = new ModelNode(sceneGraph.root); trunk/src/defend/objects/SceneNode.d
r528 r529 122 122 123 123 renderer.setTexture(1, terrain.lightmapTexture); 124 renderer.setTexture(2, shadow. texture);124 renderer.setTexture(2, shadow.framebuffer.texture); 125 125 126 126 mesh.render(); trunk/src/defend/terrain/Terrain.d
r528 r529 389 389 renderer.setTexture(3, diffuseMaps[2]); 390 390 renderer.setTexture(4, lightmapTexture); 391 renderer.setTexture(5, shadow. texture);391 renderer.setTexture(5, shadow.framebuffer.texture); 392 392 393 393 shader.setUniform("alpha", 0); trunk/src/gen/rend/Renderer.d
r520 r529 165 165 } 166 166 167 /** 168 * Framebuffers 169 */ 170 abstract class Framebuffer 171 { 172 Texture texture(); 173 } 167 174 168 175 /** … … 358 365 359 366 /** 367 * Create a framebuffer 368 */ 369 Framebuffer createFramebuffer(vec2i dimension, ImageFormat format = ImageFormat.RGB); 370 371 /** 372 * Set a framebuffer 373 */ 374 void setFramebuffer(Framebuffer framebuffer); 375 376 /** 360 377 * Set a renderstate 361 378 */ trunk/src/gen/rend/opengl/Renderer.d
r521 r529 52 52 import gen.rend.opengl.VertexFormat; 53 53 import gen.rend.opengl.Wrapper; 54 import gen.rend.opengl.FBO; 54 55 import gen.rend.opengl.sdl.Window; 55 56 … … 519 520 } 520 521 522 Framebuffer createFramebuffer(vec2i dimension, ImageFormat format = ImageFormat.RGB) 523 { 524 return new FBO(cast(OGLTexture)createTexture(dimension, format)); 525 } 526 527 void setFramebuffer(Framebuffer framebuffer) 528 { 529 if(framebuffer is null) 530 { 531 FBO.unbind(); 532 return; 533 } 534 535 (cast(FBO)framebuffer).bind(); 536 } 537 521 538 override void setRenderState(RenderState state, uint value) 522 539 { trunk/src/gen/rend/opengl/Shader.d
r521 r529 19 19 import gen.rend.Shader; 20 20 21 class OGLShader : Shader21 package class OGLShader : Shader 22 22 { 23 23 private: trunk/src/gen/rend/opengl/Texture.d
r520 r529 14 14 private: 15 15 ImageFormat _format; 16 float[] depthBuffer;17 18 GLuint id;19 16 20 17 vec2i dim; … … 30 27 31 28 package: 29 GLuint id; 30 32 31 void bind() 33 32 { … … 67 66 create(); 68 67 69 // hack70 if(format == ImageFormat.A)71 68 { 72 depthBuffer.alloc(width * height); 73 return; 69 auto t = cast(uint)format; 70 auto f = Image.formatToOpenGL(format); 71 72 if(format == ImageFormat.A) 73 { 74 t = GL_DEPTH_COMPONENT24; 75 f = GL_DEPTH_COMPONENT; 76 } 77 78 glTexImage2D(GL_TEXTURE_2D, 0, t, dim.x, dim.y, 0, f, GL_UNSIGNED_BYTE, null); 74 79 } 75 76 glTexImage2D(GL_TEXTURE_2D, 0, cast(uint)format, dim.x, dim.y, 0,77 Image.formatToOpenGL(format), GL_UNSIGNED_BYTE, null);78 80 } 79 81 80 82 ~this() 81 83 { 82 // hack83 if(depthBuffer)84 depthBuffer.free();85 86 84 glDeleteTextures(1, &id); 87 85 } … … 109 107 override void copyFromScreen() 110 108 { 111 // hack 112 if(format == ImageFormat.A) 113 { 114 /*int i; 115 float f; 116 glGetFloatv(GL_DEPTH_BIAS, &f); 117 glGetIntegerv(GL_DEPTH_BITS, &i); 118 119 Stdout(f).newline;*/ 120 121 glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, depthBuffer.ptr); 122 123 /*foreach(i, x; depthBuffer) 124 { 125 Stdout(x)(" "); 126 127 if(i % 10000 == 0) 128 { 129 Stdout(); 130 Cin.get; 131 } 132 } 133 134 Stdout(); 135 Cin.get;*/ 136 137 bind(); 138 glTexImage2D(GL_TEXTURE_2D, 0, cast(uint)format, width, height, 139 0, GL_RED, GL_FLOAT, depthBuffer.ptr); 140 return; 141 } 109 assert(false, "use fbo"); 142 110 143 111 assert(format == ImageFormat.RGB); trunk/src/gen/scene/Graph.d
r520 r529 15 15 import gen.math.Frustum; 16 16 import gen.rend.Renderer; 17 import gen.rend.Framebuffer; 17 18 import gen.rend.Texture; 18 19 import gen.scene.Node; … … 45 46 char[] name; 46 47 Camera core; 47 Texture texture; // The texturethat is rendered to (not available for the main camera)48 Framebuffer framebuffer; // The framebuffer that is rendered to (not available for the main camera) 48 49 bool shadowMap; 49 50 50 51 bool isMain() 51 52 { 52 return textureis null;53 return framebuffer is null; 53 54 } 54 55 … … 100 101 delete cam.core; 101 102 102 if(cam.texture)103 Texture.release(cam.texture);103 //if(cam.texture) 104 // Texture.release(cam.texture); 104 105 105 106 delete cam; … … 121 122 // Add a new camera 122 123 CameraData addCamera(char[] name, Camera core, vec3 clearColor, 123 Texture texture = null, bool shadowMap = false) 124 Framebuffer framebuffer = null, bool shadowMap = false) 125 in 126 { 127 if(shadowMap) 128 assert(framebuffer !is null); 129 } 130 body 124 131 { 125 132 logger.info("adding camera {}", name); … … 130 137 data.clearColor = clearColor; 131 138 data.core = core; 132 data. texture = texture;139 data.framebuffer = framebuffer; 133 140 data.shadowMap = shadowMap; 134 141 135 if(shadowMap) 136 assert(texture !is null); 137 138 if(data.texture) 139 Texture.acquire(data.texture); 142 //if(data.texture) 143 // Texture.acquire(data.texture); 140 144 141 145 foreach(ref pass; data.renderPasses) … … 251 255 }); 252 256 253 if(cam. texture!is null)254 renderer.setViewport(Rect(0, 0, cam. texture.width,255 cam. texture.height));257 if(cam.framebuffer !is null) 258 renderer.setViewport(Rect(0, 0, cam.framebuffer.texture.width, 259 cam.framebuffer.texture.height)); 256 260 else 257 261 renderer.setViewport(Rect(0, 0, renderer.width, 258 262 renderer.height)); 263 264 renderer.setFramebuffer(cam.framebuffer); 259 265 260 266 renderer.setClearColor(cam.clearColor); … … 315 321 }); 316 322 317 if(cam. texture!is null)323 if(cam.framebuffer !is null) 318 324 { 319 325 profile!("copy framebuffer") 320 326 ({ 321 cam.texture.copyFromScreen();327 //cam.texture.copyFromScreen(); 322 328 }); 323 329 }
