Changeset 529

Show
Ignore:
Timestamp:
05/02/08 07:55:03 (8 months ago)
Author:
LeoD
Message:

framebuffers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/run/data/shaders/model.pixel.glsl

    r528 r529  
    1414    vec4 light = texture2D(lightTexture, vec2(gl_TexCoord[1])); 
    1515     
    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)); 
    1718} 
  • trunk/run/data/shaders/shadowmap.glsl

    r523 r529  
    88    float lightDistance = lightSpacePos.z / lightSpacePos.w; 
    99 
     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     
    1016    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; 
    1322     
    1423    return 1.0f; 
  • trunk/run/data/shaders/terrain.pixel.glsl

    r528 r529  
    2323    c3 *= a.b * inverse;     
    2424     
     25    //gl_FragColor = vec4(shadowMap(shadow, lightSpacePos)); 
    2526    gl_FragColor = (c1 + c2 + c3) * (l * 2) * shadowMap(shadow, lightSpacePos); 
    2627} 
  • trunk/src/defend/game/hud/MiniMap.d

    r528 r529  
    2323{ 
    2424private: 
    25     const width = 128; 
    26     const height = 128; 
     25    const width = 2048; 
     26    const height = 2048; 
    2727 
    2828    Image image; 
     
    7373    { 
    7474        // 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; 
    7677         
    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)); 
    7980         
    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 
    8186        //sceneGraph.addCamera("shadow", sceneGraph.getCamera("main").core, vec3(0), texture, false); 
    8287         
  • trunk/src/defend/game/hud/Mouse.d

    r524 r529  
    586586        mouseCube.scaling = vec3(0.05); 
    587587        mouseCube.hide = true; 
     588        mouseCube.renderShadow = true; 
    588589 
    589590        placeObjectNode = new ModelNode(sceneGraph.root); 
  • trunk/src/defend/objects/SceneNode.d

    r528 r529  
    122122         
    123123        renderer.setTexture(1, terrain.lightmapTexture); 
    124         renderer.setTexture(2, shadow.texture); 
     124        renderer.setTexture(2, shadow.framebuffer.texture); 
    125125         
    126126        mesh.render(); 
  • trunk/src/defend/terrain/Terrain.d

    r528 r529  
    389389            renderer.setTexture(3, diffuseMaps[2]); 
    390390            renderer.setTexture(4, lightmapTexture); 
    391             renderer.setTexture(5, shadow.texture); 
     391            renderer.setTexture(5, shadow.framebuffer.texture); 
    392392             
    393393            shader.setUniform("alpha", 0); 
  • trunk/src/gen/rend/Renderer.d

    r520 r529  
    165165} 
    166166 
     167/** 
     168 * Framebuffers 
     169 */ 
     170abstract class Framebuffer 
     171{ 
     172    Texture texture(); 
     173} 
    167174 
    168175/** 
     
    358365     
    359366    /** 
     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    /** 
    360377     * Set a renderstate 
    361378     */ 
  • trunk/src/gen/rend/opengl/Renderer.d

    r521 r529  
    5252import gen.rend.opengl.VertexFormat; 
    5353import gen.rend.opengl.Wrapper; 
     54import gen.rend.opengl.FBO; 
    5455import gen.rend.opengl.sdl.Window; 
    5556 
     
    519520    } 
    520521     
     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     
    521538    override void setRenderState(RenderState state, uint value) 
    522539    { 
  • trunk/src/gen/rend/opengl/Shader.d

    r521 r529  
    1919import gen.rend.Shader; 
    2020 
    21 class OGLShader : Shader 
     21package class OGLShader : Shader 
    2222{ 
    2323private: 
  • trunk/src/gen/rend/opengl/Texture.d

    r520 r529  
    1414private: 
    1515    ImageFormat _format; 
    16     float[] depthBuffer; 
    17      
    18     GLuint id; 
    1916 
    2017    vec2i dim; 
     
    3027     
    3128package: 
     29    GLuint id; 
     30 
    3231    void bind() 
    3332    {        
     
    6766        create(); 
    6867 
    69         // hack 
    70         if(format == ImageFormat.A) 
    7168        { 
    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); 
    7479        } 
    75          
    76         glTexImage2D(GL_TEXTURE_2D, 0, cast(uint)format, dim.x, dim.y, 0, 
    77                      Image.formatToOpenGL(format), GL_UNSIGNED_BYTE, null); 
    7880    } 
    7981     
    8082    ~this() 
    8183    { 
    82         // hack 
    83         if(depthBuffer) 
    84             depthBuffer.free(); 
    85      
    8684        glDeleteTextures(1, &id); 
    8785    } 
     
    109107    override void copyFromScreen() 
    110108    { 
    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"); 
    142110     
    143111        assert(format == ImageFormat.RGB); 
  • trunk/src/gen/scene/Graph.d

    r520 r529  
    1515import gen.math.Frustum; 
    1616import gen.rend.Renderer; 
     17import gen.rend.Framebuffer; 
    1718import gen.rend.Texture; 
    1819import gen.scene.Node; 
     
    4546    char[] name; 
    4647    Camera core; 
    47     Texture texture; // The texture that is rendered to (not available for the main camera) 
     48    Framebuffer framebuffer; // The framebuffer that is rendered to (not available for the main camera) 
    4849    bool shadowMap; 
    4950     
    5051    bool isMain() 
    5152    { 
    52         return texture is null; 
     53        return framebuffer is null; 
    5354    } 
    5455     
     
    100101            delete cam.core; 
    101102             
    102             if(cam.texture) 
    103               Texture.release(cam.texture); 
     103            //if(cam.texture) 
     104            //    Texture.release(cam.texture); 
    104105 
    105106            delete cam; 
     
    121122    // Add a new camera 
    122123    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 
    124131    { 
    125132        logger.info("adding camera {}", name); 
     
    130137        data.clearColor = clearColor; 
    131138        data.core = core; 
    132         data.texture = texture
     139        data.framebuffer = framebuffer
    133140        data.shadowMap = shadowMap; 
    134141 
    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); 
    140144 
    141145        foreach(ref pass; data.renderPasses) 
     
    251255            }); 
    252256             
    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)); 
    256260            else 
    257261                renderer.setViewport(Rect(0, 0, renderer.width, 
    258262                                                renderer.height));  
     263                                                 
     264            renderer.setFramebuffer(cam.framebuffer); 
    259265 
    260266            renderer.setClearColor(cam.clearColor); 
     
    315321            }); 
    316322 
    317             if(cam.texture !is null) 
     323            if(cam.framebuffer !is null) 
    318324            { 
    319325                profile!("copy framebuffer") 
    320326                ({ 
    321                     cam.texture.copyFromScreen(); 
     327                    //cam.texture.copyFromScreen(); 
    322328                }); 
    323329            }