Changeset 2834


Ignore:
Timestamp:
07/13/08 23:51:02 (16 years ago)
Author:
mattausch
Message:

research version: implemented temporal smoothing and color bleeding

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj

    r2827 r2834  
    716716                        </Filter> 
    717717                </Filter> 
     718                <Filter 
     719                        Name="shaders" 
     720                        > 
     721                        <File 
     722                                RelativePath=".\src\shaders\deferred.cg" 
     723                                > 
     724                        </File> 
     725                        <File 
     726                                RelativePath=".\src\shaders\mrt.cg" 
     727                                > 
     728                        </File> 
     729                </Filter> 
    718730                <File 
    719731                        RelativePath=".\ReadMe.txt" 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp

    r2833 r2834  
    9696 
    9797        matProjectionView = matViewing * matProjectionView; 
    98         //matProjectionView = matProjectionView * matViewing; 
    99          
     98                 
    10099        float planes[6][4]; 
    101100 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PerformanceGraph.cpp

    r2829 r2834  
    5151        glLineWidth(2); 
    5252        glDisable(GL_DEPTH_TEST); 
    53         //glDepthMask(true); 
    5453 
    5554        glDisable(GL_LIGHTING); 
     
    7473        DrawGrid(); 
    7574 
    76         glPopMatrix(); 
    77          
    7875        // restore the projection matrix 
    7976        glMatrixMode(GL_PROJECTION); 
     
    8178 
    8279        glMatrixMode(GL_MODELVIEW); 
     80        glPopMatrix(); 
    8381 
    8482        glPopAttrib(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r2809 r2834  
    149149        { 
    150150                glViewport(0, 0, texWidth, texHeight); 
     151                glPushAttrib(GL_VIEWPORT_BIT); 
    151152 
    152153                glClearColor(1, 1, 1, 1); 
     
    162163 
    163164                glMatrixMode(GL_PROJECTION); 
    164                 glLoadIdentity(); 
     165                glPushMatrix(); 
    165166 
    166167                glOrtho(-xlen, xlen, -ylen, ylen, 0.0f, mSceneBox.Size().z);  
    167168 
    168169                glMatrixMode(GL_MODELVIEW); 
     170                glPushMatrix(); 
    169171 
    170172                orthoCam->SetupCameraView(); 
     
    174176                //renderer->SetCamera(orthoCam); 
    175177                renderer->RenderScene(); 
     178 
     179                glPopMatrix(); 
     180                glPopMatrix(); 
     181 
     182                glPopAttrib(); 
    176183        } 
    177184        depthTexture->EndCapture(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2833 r2834  
    3939 
    4040///////////// 
    41 //-- textures 
     41//-- fbos 
     42 
    4243GLuint fbo; 
     44GLuint fbo1; 
     45GLuint fbo2; 
     46 
     47bool isFirstTexture = true; 
     48 
     49///////////// 
     50//-- renderbuffers 
     51 
    4352 
    4453GLuint depthBuffer; 
     
    4655GLuint positionsBuffer; 
    4756GLuint colorsBuffer; 
     57GLuint colorsBuffer1; 
     58GLuint colorsBuffer2; 
    4859GLuint normalsBuffer; 
     60 
     61 
     62///////////// 
     63//-- textures 
     64 
    4965 
    5066GLuint positionsTex; 
    5167GLuint colorsTex; 
     68GLuint colorsTex1; 
     69GLuint colorsTex2; 
     70 
    5271GLuint normalsTex; 
    5372 
     
    169188 
    170189// ssao number of samples 
    171 #define NUM_SAMPLES 8 
     190//#define NUM_SAMPLES 8 
     191#define NUM_SAMPLES 16 
    172192 
    173193// ssao random spherical samples 
    174194static float samples[NUM_SAMPLES * 2]; 
     195 
     196static Matrix4x4 matProjectionView = IdentityMatrix(); 
    175197 
    176198 
     
    249271 
    250272static CGparameter sModelViewProjMatrixParam; 
     273static CGparameter sOldModelViewProjMatrixParam; 
    251274static CGparameter sMaxDepthParam; 
    252275static CGparameter sMaxDepthParamTex; 
    253276 
    254277static CGparameter sSamplesParamSsao;  
    255 //static CGparameter sNoiseMultiplierParam;;  
    256  
    257  
     278 
     279static CGparameter sOldTexParam; 
     280static CGparameter sOldTexParamSsao; 
     281 
     282static CGparameter sNoiseMultiplierParam; 
    258283 
    259284static void cgErrorCallback() 
     
    439464void InitCg(void)  
    440465{ 
    441         GenerateSamples(); 
    442  
    443466        // Setup Cg 
    444467        cgSetErrorCallback(cgErrorCallback); 
     
    488511 
    489512                cgGLSetParameter1f(sMaxDepthParamTex, 10.0f / myfar); 
     513                Debug << "maxdepth: " << 10.0f / myfar << endl; 
    490514        } 
    491515        else 
     
    535559                sNormalsTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "normals");   
    536560                sNoiseTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "noiseTexture"); 
    537                 //sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier"); 
     561                sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier"); 
     562                sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); 
    538563                 
    539564                cgGLDisableTextureParameter(sNoiseTexParamSsao); 
    540565 
    541566                sSamplesParamSsao = cgGetNamedParameter(sCgSsaoProgram, "samples"); 
     567                sOldTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "oldTex");   
     568 
     569                GenerateSamples(); 
    542570                cgGLSetParameterArray2f(sSamplesParamSsao, 0, NUM_SAMPLES, (const float *)samples); 
    543571        } 
     
    561589                sPositionsTexParam = cgGetNamedParameter(sCgDeferredProgram, "positions");   
    562590                sColorsTexParam = cgGetNamedParameter(sCgDeferredProgram, "colors");   
    563                 sNormalsTexParam = cgGetNamedParameter(sCgDeferredProgram, "normals");   
     591                sNormalsTexParam = cgGetNamedParameter(sCgDeferredProgram, "normals");  
     592 
     593                sOldTexParam = cgGetNamedParameter(sCgDeferredProgram, "oldTex");   
    564594        } 
    565595        else 
     
    569599        PrintGLerror("init"); 
    570600 
    571         cout << "cg initialised" << endl; 
     601        cout << "cg initialization successful" << endl; 
    572602} 
    573603 
     
    619649        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer); 
    620650         
    621         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, texWidth, texHeight); 
     651        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 
    622652        int samples = 8; 
    623653        //glEnable(GL_MULTISAMPLE_ARB); 
     
    628658        glBindTexture(GL_TEXTURE_2D, colorsTex); 
    629659 
    630         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 
     660        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
    631661        glGenerateMipmapEXT(GL_TEXTURE_2D); 
    632662        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0); 
     
    651681        glGenTextures(1, &positionsTex); 
    652682        glBindTexture(GL_TEXTURE_2D, positionsTex); 
    653         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
     683        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
    654684        //glGenerateMipmapEXT(GL_TEXTURE_2D); 
    655685        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, positionsTex, 0); 
     
    675705        glGenTextures(1, &normalsTex); 
    676706        glBindTexture(GL_TEXTURE_2D, normalsTex); 
    677         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 
    678         //glGenerateMipmapEXT(GL_TEXTURE_2D); 
     707        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 
    679708        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, normalsTex, 0); 
    680709 
     
    699728        PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 
    700729         
     730         
     731 
     732        ////////////////////////////////// 
     733 
     734 
     735 
     736        glGenFramebuffersEXT(1, &fbo1); 
     737        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo1); 
     738 
     739         
     740        //////////// 
     741        //-- colors buffer 
     742 
     743        glGenRenderbuffersEXT(1, &colorsBuffer1); 
     744        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer1); 
     745         
     746        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 
     747        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer1); 
     748         
     749        glGenTextures(1, &colorsTex1); 
     750        glBindTexture(GL_TEXTURE_2D, colorsTex1); 
     751 
     752        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
     753        glGenerateMipmapEXT(GL_TEXTURE_2D); 
     754        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex1, 0); 
     755 
     756        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
     757        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
     758 
     759        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
     760        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
     761 
     762        PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 
     763 
     764 
     765 
     766        ///////////////////////// 
     767 
     768        glGenFramebuffersEXT(1, &fbo2); 
     769        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2); 
     770 
     771         
     772        //////////// 
     773        //-- colors buffer 
     774 
     775        glGenRenderbuffersEXT(1, &colorsBuffer2); 
     776        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer2); 
     777         
     778        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 
     779        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer2); 
     780         
     781        glGenTextures(1, &colorsTex2); 
     782        glBindTexture(GL_TEXTURE_2D, colorsTex2); 
     783 
     784        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
     785        glGenerateMipmapEXT(GL_TEXTURE_2D); 
     786        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex2, 0); 
     787 
     788        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
     789        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
     790 
     791        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
     792        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
     793 
     794        PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 
     795 
    701796        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
    702797 
     
    9171012void SetupEyeView() 
    9181013{ 
     1014        Matrix4x4 matViewing, matProjection; 
     1015 
     1016        if (renderType == RenderState::DEFERRED) 
     1017        { 
     1018                cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)matProjectionView.x); 
     1019        } 
     1020 
    9191021        glMatrixMode(GL_PROJECTION); 
    9201022        glLoadIdentity(); 
     
    9321034        glLightfv(GL_LIGHT1, GL_POSITION, position1); 
    9331035 
     1036         
     1037        camera->GetModelViewMatrix(matViewing); 
     1038        camera->GetProjectionMatrix(matProjection); 
     1039 
     1040        matProjectionView = matViewing * matProjection; 
    9341041         
    9351042        if (renderType == RenderState::DEFERRED) 
     
    9421049                static Matrix4x4 identity = IdentityMatrix(); 
    9431050                cgGLSetMatrixParameterfc(SceneEntity::sModelMatrixParam, (const float *)identity.x); 
    944         }        
     1051        }                
    9451052} 
    9461053 
     
    11241231                perfGraph->AddData(algTime); 
    11251232 
    1126                 /*float col[3]; 
    1127                 switch (renderMode) 
    1128                 { 
    1129                 case RenderTraverser::CHCPLUSPLUS: 
    1130                         col[0] = 1.0f; col[1] = 0.0f; col[2] = 0.0f; 
    1131                         break; 
    1132                 case RenderTraverser::CHC: 
    1133                         col[0] = 0.0f; col[1] = 1.0f; col[2] = 1.0f; 
    1134                         break; 
    1135                 case RenderTraverser::STOP_AND_WAIT: 
    1136                         col[0] = 1.0f; col[1] = 1.0f; col[2] = 0.0f; 
    1137                         break; 
    1138                 case RenderTraverser::CULL_FRUSTUM: 
    1139                         col[0] = 1.0f; col[1] = 0.0f; col[2] = 1.0f; 
    1140                         break; 
    1141                 default: 
    1142                         col[0] = 1.0f; col[1] = 0.0f; col[2] = 0.0f; 
    1143                 } 
    1144                 perfGraph->SetGraphColor(col); 
    1145                 */ 
    11461233                perfGraph->Draw(); 
    11471234        } 
     
    11521239 
    11531240        DisplayStats(); 
     1241 
     1242        isFirstTexture = !isFirstTexture; 
    11541243 
    11551244        glutSwapBuffers(); 
     
    15301619        glPushMatrix(); 
    15311620        glLoadIdentity(); 
     1621 
    15321622        gluOrtho2D(0, winWidth, 0, winHeight); 
    15331623 
     
    15401630void End2D()  
    15411631{ 
     1632        glMatrixMode(GL_PROJECTION); 
    15421633        glPopMatrix(); 
     1634 
    15431635        glMatrixMode(GL_MODELVIEW); 
    15441636        glPopMatrix(); 
     
    15701662 
    15711663        const float offs = box.Size().x * 0.3f; 
    1572         //const float yoffs = box.Size().y * 0.5f; 
    1573  
     1664         
    15741665        Vector3 pos = camera->GetPosition(); 
    15751666 
     
    15781669        visCamera->SetPosition(vizpos); 
    15791670         
     1671        glPushAttrib(GL_VIEWPORT_BIT); 
    15801672        glViewport(winWidth - winWidth / 3, winHeight - winHeight / 3, winWidth / 3, winHeight / 3); 
    15811673 
    15821674        glMatrixMode(GL_PROJECTION); 
     1675        glPushMatrix(); 
     1676 
    15831677        glLoadIdentity(); 
    15841678         
     
    15861680 
    15871681        glMatrixMode(GL_MODELVIEW); 
     1682        glPushMatrix(); 
    15881683 
    15891684        visCamera->SetupCameraView(); 
     
    16091704        visualization->Render(); 
    16101705         
    1611         // reset vp 
    1612         glViewport(0, 0, winWidth, winHeight); 
     1706         
     1707        // reset previous settings 
     1708        glPopAttrib(); 
     1709 
     1710        glMatrixMode(GL_PROJECTION); 
     1711        glPopMatrix(); 
     1712        glMatrixMode(GL_MODELVIEW); 
     1713        glPopMatrix(); 
    16131714} 
    16141715 
     
    18801981 
    18811982 
     1983void DisplayRenderTexture3() 
     1984{ 
     1985        glEnable(GL_TEXTURE_2D); 
     1986 
     1987        if (isFirstTexture) 
     1988                glBindTexture(GL_TEXTURE_2D, colorsTex1); 
     1989        else 
     1990                glBindTexture(GL_TEXTURE_2D, colorsTex2); 
     1991 
     1992        glDisable(GL_LIGHTING); 
     1993         
     1994        glMatrixMode(GL_PROJECTION); 
     1995        glPushMatrix(); 
     1996        glLoadIdentity(); 
     1997 
     1998        glMatrixMode(GL_MODELVIEW); 
     1999        glPushMatrix(); 
     2000        glLoadIdentity(); 
     2001 
     2002        const float offs = 0.5f; 
     2003        glOrtho(-offs, offs, -offs, offs, 0, 1); 
     2004         
     2005        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     2006 
     2007        glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 
     2008        glBegin(GL_QUADS); 
     2009 
     2010        glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 
     2011        glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 
     2012        glTexCoord2f(1, 1); glVertex3f( offs,  offs, -0.5f); 
     2013        glTexCoord2f(0, 1); glVertex3f(-offs,  offs, -0.5f); 
     2014 
     2015        glEnd(); 
     2016 
     2017        glEnable(GL_LIGHTING); 
     2018        glDisable(GL_TEXTURE_2D); 
     2019         
     2020        glMatrixMode(GL_PROJECTION); 
     2021        glPopMatrix(); 
     2022 
     2023        glMatrixMode(GL_MODELVIEW); 
     2024        glPopMatrix(); 
     2025 
     2026        PrintGLerror("displaytexture3"); 
     2027} 
     2028 
     2029 
    18822030void DisplayRenderTexture() 
    18832031{ 
     2032        GLuint oldTex; 
     2033 
     2034        if (isFirstTexture) 
     2035        { 
     2036                glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo1); 
     2037                oldTex = colorsTex2; 
     2038        } 
     2039        else  
     2040        { 
     2041                glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2); 
     2042                oldTex = colorsTex1; 
     2043        } 
     2044 
     2045        glPushAttrib(GL_VIEWPORT_BIT); 
     2046        glViewport(0, 0, texWidth, texHeight); 
     2047 
     2048        glDrawBuffers(1, mrt); 
     2049 
    18842050        glDisable(GL_ALPHA_TEST); 
    18852051        glDisable(GL_TEXTURE_2D); 
     
    19062072                cgGLBindProgram(sCgSsaoProgram); 
    19072073                 
     2074                cgGLSetTextureParameter(sPositionsTexParamSsao, positionsTex); 
    19082075                cgGLEnableTextureParameter(sPositionsTexParamSsao); 
    1909                 cgGLSetTextureParameter(sPositionsTexParamSsao, positionsTex); 
    1910          
     2076 
     2077                cgGLSetTextureParameter(sColorsTexParamSsao, colorsTex); 
    19112078                cgGLEnableTextureParameter(sColorsTexParamSsao); 
    1912                 cgGLSetTextureParameter(sColorsTexParamSsao, colorsTex); 
    1913  
     2079 
     2080                cgGLSetTextureParameter(sNormalsTexParamSsao, normalsTex); 
    19142081                cgGLEnableTextureParameter(sNormalsTexParamSsao); 
    1915                 cgGLSetTextureParameter(sNormalsTexParamSsao, normalsTex); 
    1916  
     2082 
     2083                cgGLSetTextureParameter(sNoiseTexParamSsao, noiseTex); 
    19172084                cgGLEnableTextureParameter(sNoiseTexParamSsao); 
    1918                 cgGLSetTextureParameter(sNoiseTexParamSsao, noiseTex); 
    1919  
    1920                 //cgGLSetParameter1f(sNoiseMultiplierParam, RandomValue(3.0f, 7.0f)); 
     2085 
     2086                cgGLSetTextureParameter(sOldTexParamSsao, oldTex); 
     2087                cgGLEnableTextureParameter(sOldTexParamSsao); 
     2088 
     2089                cgGLSetParameter1f(sNoiseMultiplierParam, RandomValue(3.0f, 17.0f)); 
     2090 
     2091                //GenerateSamples(); cgGLSetParameterArray2f(sSamplesParamSsao, 0, NUM_SAMPLES, (const float *)samples); 
    19212092        } 
    19222093        else 
     
    19242095                cgGLBindProgram(sCgDeferredProgram); 
    19252096 
     2097                cgGLSetTextureParameter(sPositionsTexParam, positionsTex); 
    19262098                cgGLEnableTextureParameter(sPositionsTexParam); 
    1927                 cgGLSetTextureParameter(sPositionsTexParam, positionsTex); 
    1928          
     2099 
     2100                cgGLSetTextureParameter(sColorsTexParam, colorsTex); 
    19292101                cgGLEnableTextureParameter(sColorsTexParam); 
    1930                 cgGLSetTextureParameter(sColorsTexParam, colorsTex); 
    1931  
     2102 
     2103                cgGLSetTextureParameter(sNormalsTexParam, normalsTex); 
    19322104                cgGLEnableTextureParameter(sNormalsTexParam); 
    1933                 cgGLSetTextureParameter(sNormalsTexParam, normalsTex); 
     2105 
     2106                cgGLSetTextureParameter(sOldTexParam, oldTex); 
     2107                cgGLEnableTextureParameter(sOldTexParam); 
    19342108        } 
    19352109 
     
    19522126        glEnd(); 
    19532127 
    1954         cgGLDisableTextureParameter(sColorsTexParamSsao); 
    1955         cgGLDisableTextureParameter(sPositionsTexParamSsao); 
    1956         cgGLDisableTextureParameter(sNormalsTexParamSsao); 
    19572128         
    19582129        if (useSsao) 
     2130        { 
     2131                cgGLDisableTextureParameter(sColorsTexParamSsao); 
     2132                cgGLDisableTextureParameter(sPositionsTexParamSsao); 
     2133                cgGLDisableTextureParameter(sNormalsTexParamSsao); 
    19592134                cgGLDisableTextureParameter(sNoiseTexParamSsao); 
     2135                cgGLDisableTextureParameter(sOldTexParamSsao); 
     2136        } 
     2137        else 
     2138        { 
     2139                cgGLDisableTextureParameter(sColorsTexParam); 
     2140                cgGLDisableTextureParameter(sPositionsTexParam); 
     2141                cgGLDisableTextureParameter(sNormalsTexParam); 
     2142                cgGLDisableTextureParameter(sOldTexParam); 
     2143        } 
    19602144 
    19612145        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     
    19702154        glPopMatrix(); 
    19712155 
    1972          
     2156        glPopAttrib(); 
     2157 
    19732158        PrintGLerror("displaytexture"); 
     2159 
     2160        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
     2161 
     2162        DisplayRenderTexture3(); 
    19742163} 
    19752164 
     
    20142203#else 
    20152204 
    2016 /*void GenerateSamples() 
    2017 { 
    2018         float scale = 1.0f / (float)NUM_SAMPLES; 
    2019  
    2020         //////// 
    2021         //-- generate uniformly distributed spherical samples 
    2022  
    2023         for (int i = 0; i < NUM_SAMPLES; ++ i) 
    2024         { 
    2025                 // create stratified samples over sphere 
    2026                 const float rx = ((float)i + RandomValue(0, 1)) * scale; 
    2027                 const float ry = ((float)i + RandomValue(0, 1)) * scale; 
    2028  
    2029                 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
    2030                 const float phi = 2.0f * M_PI * ry; 
    2031  
    2032                 Vector3 unit = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); 
    2033  
    2034                 ////// 
    2035                 //-- we sample in texture space => store 2D component 
    2036  
    2037                 // q: project to plane or just drop z? 
    2038                 Vector3 proj = unit / (1.0f + fabs(unit.z)); 
    2039                 //Vector3 proj = unit; 
    2040  
    2041                 samples[i + 0] = proj.x; 
    2042                 samples[i + 1] = proj.y; 
    2043                 //cout << samples[i] << " " << samples[i + 1] << endl; 
    2044         } 
    2045 }*/ 
    20462205 
    20472206void GenerateSamples() 
    20482207{ 
    20492208        // generates poisson distribution on disc 
    2050         //float factor = 5.0f; 
    2051         float minDist = 2.0f;//factor / sqrt((float)NUM_SAMPLES); 
    2052  
    2053         cout << "minDist= " << minDist << endl; 
     2209        float minDist = 2.0f / sqrt((float)NUM_SAMPLES); 
     2210 
     2211        //cout << "minDist before= " << minDist << endl; 
    20542212 
    20552213        for (int i = 0; i < NUM_SAMPLES * 2; i += 2) 
     
    20962254                        } 
    20972255                } 
    2098                 cout << "sample: " << samples[i] << " " << i /2 << " " << samples[i + 1] << " r: " << sqrt(samples[i] * samples[i]  + samples[i + 1] * samples[i + 1]) << " tries: " << totalTries << endl; 
    2099         } 
    2100  
    2101         cout << "minDist= " << minDist << endl; 
     2256                //cout << "sample: " << samples[i] << " " << i /2 << " " << samples[i + 1] << " r: " << sqrt(samples[i] * samples[i]  + samples[i + 1] * samples[i + 1]) << " tries: " << totalTries << endl; 
     2257        } 
     2258 
     2259        //cout << "minDist after= " << minDist << endl; 
    21022260} 
    21032261 
     
    21182276        float t2 = w_far * 0.5f; 
    21192277 
     2278#if 0 
    21202279        bl = Normalize(-Vector3(-t1, -t2, 1.0f)); 
    21212280        br = Normalize(-Vector3( t1, -t2, 1.0f)); 
    21222281        tl = Normalize(-Vector3(-t1,  t2, 1.0f)); 
    21232282        tr = Normalize(-Vector3( t1,  t2, 1.0f)); 
    2124  
     2283#else 
     2284        bl = -Normalize(camera->GetDirection()); 
     2285        br = -Normalize(camera->GetDirection()); 
     2286        tl = -Normalize(camera->GetDirection()); 
     2287        tr = -Normalize(camera->GetDirection()); 
     2288#endif 
    21252289        // normalize to 0 .. 1 
    21262290        bl = bl * 0.5f + 0.5f; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2833 r2834  
    11//////////////////// 
    22// Screen Spaced Ambient Occlusion shader 
    3 // mainly based on Kustls shader 
    4  
    5 #define NUM_SAMPLES 8 
    6 //#define SAMPLE_INTENSITY 0.5f 
    7 //#define SAMPLE_INTENSITY 1.1f 
    8 #define SAMPLE_INTENSITY 0.25f 
     3// mainly based on shader of Alexander Kusternig 
     4 
     5//#define NUM_SAMPLES 8 
     6#define NUM_SAMPLES 16 
     7//#define SAMPLE_INTENSITY 0.125f 
     8// rule of thumb: approx 1 / NUM_SAMPLES 
     9#define SAMPLE_INTENSITY 0.2 //0.0625f 
     10 
    911#define AREA_SIZE 5e-1f 
    1012 
     
    3032  // reflect around plane 
    3133  float2 rpt = pt - d * 2.0f * n; 
    32    
     34 
    3335  //return pt; 
    3436  return rpt; 
     
    3840float2 rotate(float2 pt, float2 n) 
    3941{ 
    40   float2 ptTransformed; 
    41   ptTransformed.x = n.r * pt.x - n.g * pt.y; 
    42   ptTransformed.y = n.g * pt.x + n.r * pt.y; 
    43  
    44   return ptTransformed; 
    45 } 
    46  
    47  
    48 //based on kustls shader         
     42        float2 ptTransformed; 
     43        ptTransformed.x = n.r * pt.x - n.g * pt.y; 
     44        ptTransformed.y = n.g * pt.x + n.r * pt.y; 
     45 
     46        return ptTransformed; 
     47} 
     48 
     49 
    4950float ssao(fragment IN, 
    50            uniform sampler2D positions, 
    51            uniform sampler2D noiseTexture, 
    52            uniform float2 samples[NUM_SAMPLES], 
    53            uniform float3 currentNormal, 
    54            uniform float3 currentViewDir) 
    55 { 
    56   // the current world position 
    57   float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
    58   // the w coordinate from the persp. projection 
    59   float w = centerPosition.w; 
    60  
    61   // Check in a circular area around the current position. 
    62   // Shoot vectors to the positions there, and check the angle to these positions. 
    63   // Summing up these angles gives an estimation of the occlusion at the current position. 
    64    
    65   float total_ao = 0.0; 
    66  
    67   const float areaSize = 5e-1f; 
    68   //const float areaSize = 3e-1f; 
    69   //const float sampleIntensity = 0.2f; 
    70    
    71   for (int i = 0; i < NUM_SAMPLES; i ++) { 
    72     float2 offset = samples[i]; 
    73      
    74     //sample noisetex; r stores costheta, g stores sintheta 
    75     float2 noise = tex2D(noiseTexture, IN.texCoord.xy * 7.1f).xy * 2.0f - 1.0f; 
     51                   uniform sampler2D positions, 
     52                   uniform sampler2D noiseTexture, 
     53                   uniform float2 samples[NUM_SAMPLES], 
     54                   uniform float3 currentNormal, 
     55                   uniform float3 currentViewDir, 
     56                   uniform float noiseMultiplier, 
     57                   uniform float4 centerPosition 
     58                   ) 
     59{ 
     60        // the w coordinate from the persp. projection 
     61        float w = centerPosition.w; 
     62 
     63        // Check in a circular area around the current position. 
     64        // Shoot vectors to the positions there, and check the angle to these positions. 
     65        // Summing up these angles gives an estimation of the occlusion at the current position. 
     66 
     67        float total_ao = 0.0; 
     68 
     69        const float areaSize = 5e-1f; 
     70        //const float areaSize = 3e-1f; 
     71        //const float sampleIntensity = 0.2f; 
     72 
     73        for (int i = 0; i < NUM_SAMPLES; i ++)  
     74        { 
     75                float2 offset = samples[i]; 
     76 
     77                //sample noisetex; r stores costheta, g stores sintheta 
     78                float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
     79 
     80                // rotation 
     81                //float2 offsetTransformed = offset; 
     82                float2 offsetTransformed = rotate(offset, noise); 
     83                //float2 offsetTransformed = reflect(offset, noise); 
     84 
     85                // weight with projected coordinate to reach similar kernel size for near and far 
     86                float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 
     87 
     88                float3 sample_position = tex2D(positions, texcoord).xyz; 
     89 
     90                float3 vector_to_sample = sample_position - centerPosition.xyz; 
     91                float length_to_sample = length(vector_to_sample); 
     92                float3 direction_to_sample = vector_to_sample / length_to_sample; 
     93 
     94                // Angle between current normal and direction to sample controls AO intensity. 
     95                float cos_angle = dot(direction_to_sample, currentNormal); 
     96                cos_angle = max(cos_angle, 0.0f); 
     97                // take quadratic influence to sharpen contrast 
     98                //cos_angle *= cos_angle; 
     99 
     100                // distance between current position and sample position controls AO intensity. 
     101                //const float maxdist = 2e-1f; 
     102                //const float maxdist = 5e-1f; 
     103                const float distanceScale = 1e-6f; 
     104 
     105                float distance_intensity =  
     106                        (SAMPLE_INTENSITY * distanceScale) / (distanceScale + length_to_sample * length_to_sample); 
     107 
     108                // if normal perpenticular to view dir, only half of the samples count 
     109                float view_correction = (2.0f - dot(currentViewDir, currentNormal)); 
     110                view_correction *= view_correction; 
     111 
     112                total_ao += cos_angle * distance_intensity * view_correction; 
     113        } 
     114 
     115        return (1.0f - total_ao); 
     116} 
     117 
     118 
     119float4 globIllum(fragment IN, 
     120                                 uniform sampler2D colors, 
     121                                 uniform sampler2D positions, 
     122                                 uniform sampler2D noiseTexture, 
     123                                 uniform float2 samples[NUM_SAMPLES], 
     124                                 uniform float3 currentNormal, 
     125                                 uniform float3 currentViewDir, 
     126                                 uniform float noiseMultiplier, 
     127                                 uniform float4 centerPosition) 
     128{ 
     129        // the w coordinate from the persp. projection 
     130        float w = centerPosition.w; 
     131 
     132        // Check in a circular area around the current position. 
     133        // Shoot vectors to the positions there, and check the angle to these positions. 
     134        // Summing up these angles gives an estimation of the occlusion at the current position. 
     135 
     136        float total_ao = 0.0; 
     137        float3 total_color = float3(0.0f); 
     138 
     139        const float areaSize = 5e-1f; 
     140 
     141        for (int i = 0; i < NUM_SAMPLES; i ++)  
     142        { 
     143                float2 offset = samples[i]; 
     144 
     145                //sample noisetex; r stores costheta, g stores sintheta 
     146                float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
     147 
     148                // rotation 
     149                float2 offsetTransformed = rotate(offset, noise); 
     150 
     151                // weight with projected coordinate to reach similar kernel size for near and far 
     152                float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 
     153 
     154                float3 sample_position = tex2D(positions, texcoord).xyz; 
     155                float3 sample_color = tex2D(colors, texcoord).xyz; 
     156 
     157                float3 vector_to_sample = sample_position - centerPosition.xyz; 
     158                float length_to_sample = length(vector_to_sample); 
     159                float3 direction_to_sample = vector_to_sample / length_to_sample; 
     160 
     161                // Angle between current normal and direction to sample controls AO intensity. 
     162                float cos_angle = dot(direction_to_sample, currentNormal); 
     163                cos_angle = max(cos_angle, 0.0f); 
     164 
     165                // distance between current position and sample position controls AO intensity. 
     166                const float distanceScale = 1e-6f; 
     167 
     168                float distance_intensity =  
     169                        (SAMPLE_INTENSITY * distanceScale) / (distanceScale + length_to_sample * length_to_sample); 
     170 
     171                // if normal perpenticular to view dir, only half of the samples count 
     172                float view_correction = 1.0f + 0.5f * (1.0f - dot(currentViewDir, currentNormal)); 
     173                //view_correction *= view_correction; 
     174 
     175                total_ao += cos_angle * distance_intensity * view_correction; 
     176                total_color += cos_angle * distance_intensity * view_correction * sample_color; 
     177        } 
     178 
     179        return float4(total_color, 1.0f - total_ao); 
     180} 
     181 
     182 
     183float4 shade(fragment IN,  
     184                         uniform sampler2D colors, 
     185                         uniform sampler2D positions, 
     186                         uniform float3 normal, 
     187                         uniform float amb) 
     188{ 
     189        float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 
     190        float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); 
     191 
     192        float4 color = tex2D(colors, IN.texCoord.xy); 
     193 
     194        float4 position = tex2D(positions, IN.texCoord.xy); 
     195 
     196        float4 ambient = 0.3f; 
     197 
     198        // float3 L = normalize(lightPosition - position); 
     199        float3 light = normalize(lightDir.xyz); 
     200        float3 light2 = normalize(lightDir2.xyz); 
     201 
     202        float diffuseLight = max(dot(normal, light), 0.0f); 
     203        float diffuseLight2 = max(dot(normal, light2), 0.0f); 
     204 
     205        float diffuse = diffuseLight + diffuseLight2; 
     206        //float diffuse = diffuseLight; 
     207 
     208        return (ambient + diffuse) * color * (1.0f - amb) + amb * color; 
     209} 
     210 
     211 
     212pixel main_ssao(fragment IN,  
     213                                uniform sampler2D colors, 
     214                                uniform sampler2D positions, 
     215                                uniform sampler2D normals, 
     216                                uniform sampler2D noiseTexture, 
     217                                uniform float2 samples[NUM_SAMPLES], 
     218                                uniform float noiseMultiplier, 
     219                                uniform sampler2D oldTex, 
     220                                const uniform float4x4 oldModelViewProj 
     221                                ) 
     222{ 
     223        pixel OUT; 
     224 
     225        float4 normal = tex2D(normals, IN.texCoord.xy); 
     226        float amb = normal.w; 
     227 
     228        // expand normal 
     229        normal = normalize(normal * 2.0f - 1.0f); 
     230        float3 viewDir = normalize(IN.view * 2.0f - float3(1.0f)); 
     231 
     232        // the current world position 
     233        float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
    76234         
    77     // rotation 
    78     //float2 offsetTransformed = offset; 
    79     float2 offsetTransformed = rotate(offset, noise); 
    80     //float2 offsetTransformed = reflect(offset, noise); 
    81                 
    82     // weight with projected coordinate to reach similar kernel size for near and far 
    83     float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 
    84      
    85     float3 sample_position = tex2D(positions, texcoord).xyz; 
    86      
    87     float3 vector_to_sample = sample_position - centerPosition.xyz; 
    88     float length_to_sample = length(vector_to_sample); 
    89     float3 direction_to_sample = vector_to_sample / length_to_sample; 
    90      
    91     // Angle between current normal and direction to sample controls AO intensity. 
    92     float cos_angle = dot(direction_to_sample, currentNormal); 
    93     cos_angle = max(cos_angle, 0.0f); 
    94     // take quadratic influence to sharpen contrast 
    95     //cos_angle *= cos_angle; 
    96  
    97     // distance between current position and sample position controls AO intensity. 
    98     //const float maxdist = 2e-1f; 
    99     //const float maxdist = 5e-1f; 
    100     const float distanceScale = 1e-6f; 
    101  
    102     float distance_intensity =  
    103       (SAMPLE_INTENSITY * distanceScale) / (distanceScale + length_to_sample * length_to_sample); 
    104  
    105     // if normal perpenticular to view dir, only half of the samples count 
    106     float view_correction = (2.0f - dot(currentViewDir, currentNormal)); 
    107  
    108     total_ao += cos_angle * distance_intensity * view_correction; 
    109   } 
    110          
    111   return (1.0f - total_ao); 
    112 } 
    113  
    114  
    115 float4 shade(fragment IN,  
    116              uniform sampler2D colors, 
    117              uniform sampler2D positions, 
    118              uniform float3 normal, 
    119              uniform float amb) 
    120 { 
    121   float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 
    122   float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); 
    123    
    124   float4 color = tex2D(colors, IN.texCoord.xy); 
     235        float4 col = shade(IN, colors, positions, normal.xyz, amb); 
     236 
     237        //float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 
     238        float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 
     239        float ao = new_col.w; 
     240 
     241        //float4 attenuated_color = ao * col + new_col; 
     242        float4 attenuated_color = ao * col; 
     243 
     244        //OUT.color = ao; 
     245        //OUT.color = ao * col;  
     246        float4 dummy = centerPosition / 0.000487676f; 
     247        dummy.w = 1.0f; 
     248        float4 oldPos = mul(oldModelViewProj, dummy); 
     249 
     250        float newDepth = oldPos.z / oldPos.w; 
    125251  
    126   float4 position = tex2D(positions, IN.texCoord.xy); 
    127  
    128   float4 ambient = 0.3f; 
    129  
    130   // float3 L = normalize(lightPosition - position); 
    131   float3 light = normalize(lightDir.xyz); 
    132   float3 light2 = normalize(lightDir2.xyz); 
    133   
    134   float diffuseLight = max(dot(normal, light), 0.0f); 
    135   float diffuseLight2 = max(dot(normal, light2), 0.0f); 
    136  
    137   //float diffuse = diffuseLight + diffuseLight2; 
    138   float diffuse = diffuseLight; 
    139  
    140   return (ambient + diffuse) * color * (1.0f - amb) + amb * color; 
    141 } 
    142  
    143  
    144 pixel main_ssao(fragment IN,  
    145                 uniform sampler2D colors, 
    146                 uniform sampler2D positions, 
    147                 uniform sampler2D normals, 
    148                 uniform sampler2D noiseTexture, 
    149                 uniform float2 samples[NUM_SAMPLES]) 
    150 { 
    151   pixel OUT; 
    152  
    153   float4 normal = tex2D(normals, IN.texCoord.xy); 
    154   float amb = normal.w; 
    155  
    156   // expand normal 
    157   normal = normalize(normal * 2.0f - 1.0f); 
    158   float3 viewDir = normalize(IN.view * 2.0f - float(1.0f)); 
    159  
    160   float4 col = shade(IN, colors, positions, normal, amb); 
    161   float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir); 
    162    
    163    //OUT.color = ao; 
    164    OUT.color = ao * col;  
    165  
    166   return OUT; 
     252        const float x = 0.05f; 
     253 
     254        float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; 
     255        float4 col1 = tex2D(oldTex, tex); 
     256 
     257        float oldDepth = col1.w; 
     258 
     259        if ((tex.x >= 0) && (tex.x <= 1) && (tex.y >= 0) && (tex.y <= 1) && (abs(newDepth - oldDepth) < 5e-4f)) 
     260                OUT.color = attenuated_color * x + col1 * float4(1.0f - x); 
     261        else            OUT.color = attenuated_color;// * x + col1 * float4(1.0f - x); 
     262 
     263        //OUT.color = float4(centerPosition.w); 
     264        //OUT.color = float4(oldDepth); 
     265        //OUT.color = float4(newDepth); 
     266        //OUT.color = float4(abs(newDepth - oldDepth)); 
     267        OUT.color.w = tex2D(colors, IN.texCoord.xy).w; 
     268 
     269        return OUT; 
    167270} 
    168271 
    169272 
    170273pixel main(fragment IN,  
    171            uniform sampler2D colors, 
    172            uniform sampler2D positions, 
    173            uniform sampler2D normals) 
    174 { 
    175   pixel OUT; 
    176    
    177   float4 normal = tex2D(normals, IN.texCoord.xy); 
    178   float amb = normal.w; 
    179  
    180   //OUT.color.xyz = IN.view; 
    181   // expand normal 
    182   normal = normalize(normal * 2.0f - float4(1.0f)); 
    183    
    184   float4 col = shade(IN, colors, positions, normal.xyz, amb); 
    185   OUT.color = col; 
    186  
    187   return OUT; 
    188 } 
     274                   uniform sampler2D colors, 
     275                   uniform sampler2D positions, 
     276                   uniform sampler2D normals, 
     277                   uniform sampler2D oldTex 
     278                   ) 
     279{ 
     280        pixel OUT; 
     281 
     282        float4 normal = tex2D(normals, IN.texCoord.xy); 
     283        float amb = normal.w; 
     284 
     285        //OUT.color.xyz = IN.view; 
     286        // expand normal 
     287        normal = normalize(normal * 2.0f - float4(1.0f)); 
     288 
     289        float4 col = shade(IN, colors, positions, normal.xyz, amb); 
     290        //OUT.color = col; 
     291 
     292        float4 col1 = tex2D(oldTex, IN.texCoord.xy); 
     293 
     294        const float x = 0.1f; 
     295        OUT.color = col * x + col1 * float4(1.0f - x); 
     296 
     297        return OUT; 
     298} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2833 r2834  
    1717  float4 worldPos: TEXCOORD1; // world position 
    1818  float3 normal: TEXCOORD2; 
     19  float4 mypos: TEXCOORD3; 
    1920}; 
    2021 
     
    3031  float4 worldPos: TEXCOORD1; // world position 
    3132  float3 normal: TEXCOORD2; 
     33 
     34  float4 mypos: TEXCOORD3; 
     35  //float DEPTH; 
    3236}; 
    3337 
     
    4246 
    4347vtxout vtx(vtxin IN,  
    44            const uniform float4x4 ModelViewProj, 
    45            uniform float4x4 ModelMatrix) 
     48                   const uniform float4x4 ModelViewProj, 
     49                   uniform float4x4 ModelMatrix) 
    4650{ 
    4751   vtxout OUT; 
     
    5862   OUT.normal = IN.normal; 
    5963 
     64   OUT.mypos = OUT.position; 
    6065   return OUT; 
    6166} 
     
    6368 
    6469pixel fragtex(fragin IN,  
    65               uniform sampler2D tex,  
    66               uniform float maxDepth,  
    67               uniform float4 ambient,  
    68               uniform float4 diffuse) 
     70                          uniform sampler2D tex,  
     71                          uniform float maxDepth,  
     72                          uniform float4 ambient,  
     73                          uniform float4 diffuse) 
    6974{ 
    7075  pixel pix; 
     
    7782  // hack: store projection coordinate for scaling ssao 
    7883  pix.pos.w = IN.projPos.w; 
     84  pix.col.w = IN.mypos.z / IN.mypos.w; 
    7985 
    8086  return pix; 
     
    9197  pix.col = diffuse; 
    9298  pix.pos = IN.worldPos * maxDepth; 
    93   pix.norm.xyz = IN.normal * 0.5f + float4(0.5f); 
     99  pix.norm.xyz = IN.normal * 0.5f + float3(0.5f); 
    94100  // hack: squeeze some information about ambient into the texture 
    95101  pix.norm.w = ambient.x; 
    96   pix.pos.w = IN.projPos.w; 
     102  pix.pos.w = IN.mypos.w; //IN.projPos.w; 
     103  pix.col.w = IN.mypos.z / IN.mypos.w; 
    97104 
    98105  return pix; 
Note: See TracChangeset for help on using the changeset viewer.