Changeset 2821


Ignore:
Timestamp:
07/07/08 18:41:45 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2820 r2821  
    145145bool eightKeyPressed = false; 
    146146 
     147bool useSsao = false; 
     148 
    147149GLubyte *randomNormals = NULL; 
    148150 
     
    216218static CGcontext sCgContext = NULL; 
    217219static CGprogram sCgMrtVertexProgram = NULL; 
    218 static CGprogram sCgSSAOProgram = NULL; 
    219  
     220static CGprogram sCgSsaoProgram = NULL; 
     221static CGprogram sCgDeferredProgram = NULL; 
    220222 
    221223static CGparameter sColorsTexParam; 
    222224static CGparameter sPositionsTexParam; 
    223225static CGparameter sNormalsTexParam; 
    224 static CGparameter sNoiseTexParam; 
     226//static CGparameter sNoiseTexParam; 
     227 
     228static CGparameter sColorsTexParamSsao; 
     229static CGparameter sPositionsTexParamSsao; 
     230static CGparameter sNormalsTexParamSsao; 
     231static CGparameter sNoiseTexParamSsao; 
    225232 
    226233static CGparameter sModelViewProjMatrixParam; 
     
    229236static CGparameter sMaxDepthParamTex; 
    230237 
    231 static CGparameter sSamplesParam;  
     238//static CGparameter sSamplesParam;  
     239static CGparameter sSamplesParamSsao;  
    232240 
    233241 
     
    279287        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); 
    280288 
     289#if 1 
    281290        glutCreateWindow("FriendlyCulling"); 
    282  
    283         //glutGameModeString( "1024x768:32@75" ); //the settings for fullscreen mode 
    284         //glutEnterGameMode(); //set glut to fullscreen using the settings in the line above 
    285  
     291#else 
     292        glutGameModeString( "1024x768:32@75" ); //the settings for fullscreen mode 
     293        glutEnterGameMode(); //set glut to fullscreen using the settings in the line above 
     294#endif 
    286295        glutDisplayFunc(Display); 
    287296        glutKeyboardFunc(KeyBoard); 
     
    398407                                                                NULL); 
    399408 
    400         if(sCgMrtVertexProgram != NULL) 
     409        if (sCgMrtVertexProgram != NULL) 
    401410        { 
    402411                cgGLLoadProgram(sCgMrtVertexProgram); 
     
    451460        /////////////// 
    452461 
    453         sCgSSAOProgram =  
     462        sCgSsaoProgram =  
    454463                cgCreateProgramFromFile(sCgContext,  
    455464                                                                CG_SOURCE, 
    456465                                                                "src/shaders/deferred.cg",  
    457                                                                 //"src/test.cg",  
    458466                                                                RenderState::sCgFragmentProfile, 
    459                                                                 NULL, 
     467                                                                "main_ssao", 
    460468                                                                NULL); 
    461469 
    462         if(sCgSSAOProgram != NULL) 
    463         { 
    464                 cgGLLoadProgram(sCgSSAOProgram); 
     470        if (sCgSsaoProgram != NULL) 
     471        { 
     472                cgGLLoadProgram(sCgSsaoProgram); 
    465473 
    466474                // we need size of texture for scaling 
    467                 sPositionsTexParam = cgGetNamedParameter(sCgSSAOProgram, "positions");   
    468                 sColorsTexParam = cgGetNamedParameter(sCgSSAOProgram, "colors");   
    469                 sNormalsTexParam = cgGetNamedParameter(sCgSSAOProgram, "normals");   
    470                 sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture"); 
    471  
    472                 sSamplesParam = cgGetNamedParameter(sCgSSAOProgram, "samples"); 
    473                 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 
     475                sPositionsTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "positions");   
     476                sColorsTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "colors");   
     477                sNormalsTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "normals");   
     478                sNoiseTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "noiseTexture"); 
     479 
     480                sSamplesParamSsao = cgGetNamedParameter(sCgSsaoProgram, "samples"); 
     481                cgGLSetParameterArray2f(sSamplesParamSsao, 0, NUM_SAMPLES, (const float *)samples); 
    474482        } 
    475483        else 
    476484                cerr << "ssao program failed to load" << endl; 
     485 
     486         
     487        sCgDeferredProgram =  
     488                cgCreateProgramFromFile(sCgContext,  
     489                                                                CG_SOURCE, 
     490                                                                "src/shaders/deferred.cg",  
     491                                                                RenderState::sCgFragmentProfile, 
     492                                                                "main", 
     493                                                                NULL); 
     494 
     495        if (sCgDeferredProgram != NULL) 
     496        { 
     497                cgGLLoadProgram(sCgDeferredProgram); 
     498 
     499                // we need size of texture for scaling 
     500                sPositionsTexParam = cgGetNamedParameter(sCgDeferredProgram, "positions");   
     501                sColorsTexParam = cgGetNamedParameter(sCgDeferredProgram, "colors");   
     502                sNormalsTexParam = cgGetNamedParameter(sCgDeferredProgram, "normals");   
     503                //sNoiseTexParam = cgGetNamedParameter(sCgDeferredProgram, "noiseTexture"); 
     504 
     505                //sSamplesParam = cgGetNamedParameter(sCgDeferredProgram, "samples"); 
     506                //cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 
     507        } 
     508        else 
     509                cerr << "deferred program failed to load" << endl; 
     510 
    477511 
    478512        PrintGLerror("init"); 
     
    666700                "'F7',          - depth pass", 
    667701                "'F8',          - enable/disable glFinish for more accurate timings", 
     702                "'F9',          - enables/disables ambient occlusion", 
    668703                "'SPACE'        - cycles through occlusion culling algorithms", 
    669704                "", 
     
    11591194                useGlFinish = !useGlFinish; 
    11601195                break; 
     1196        case GLUT_KEY_F9: 
     1197                useSsao = !useSsao; 
     1198                break; 
    11611199        case GLUT_KEY_LEFT: 
    11621200                { 
     
    14461484        if (sCgMrtVertexProgram) 
    14471485                cgDestroyProgram(sCgMrtVertexProgram); 
    1448         if (sCgSSAOProgram) 
    1449                 cgDestroyProgram(sCgSSAOProgram); 
     1486        if (sCgSsaoProgram) 
     1487                cgDestroyProgram(sCgSsaoProgram); 
     1488        if (sCgDeferredProgram) 
     1489                cgDestroyProgram(sCgDeferredProgram); 
    14501490        if (sCgContext) 
    14511491                cgDestroyContext(sCgContext); 
     
    16451685 
    16461686        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    1647         cgGLBindProgram(sCgSSAOProgram); 
    1648  
    1649         cgGLEnableTextureParameter(sPositionsTexParam); 
    1650         cgGLSetTextureParameter(sPositionsTexParam, positionsTex); 
    1651          
    1652         cgGLEnableTextureParameter(sColorsTexParam); 
    1653         cgGLSetTextureParameter(sColorsTexParam, colorsTex); 
    1654          
    1655         cgGLEnableTextureParameter(sNormalsTexParam); 
    1656         cgGLSetTextureParameter(sNormalsTexParam, normalsTex); 
    1657  
    1658         cgGLEnableTextureParameter(sNoiseTexParam); 
    1659         cgGLSetTextureParameter(sNoiseTexParam, noiseTex); 
     1687 
     1688        if (useSsao) 
     1689        { 
     1690                cgGLBindProgram(sCgSsaoProgram); 
     1691                 
     1692                cgGLEnableTextureParameter(sPositionsTexParamSsao); 
     1693                cgGLSetTextureParameter(sPositionsTexParamSsao, positionsTex); 
     1694         
     1695                cgGLEnableTextureParameter(sColorsTexParamSsao); 
     1696                cgGLSetTextureParameter(sColorsTexParamSsao, colorsTex); 
     1697 
     1698                cgGLEnableTextureParameter(sNormalsTexParamSsao); 
     1699                cgGLSetTextureParameter(sNormalsTexParamSsao, normalsTex); 
     1700 
     1701                cgGLEnableTextureParameter(sNoiseTexParamSsao); 
     1702                cgGLSetTextureParameter(sNoiseTexParamSsao, noiseTex); 
     1703        } 
     1704        else 
     1705        { 
     1706                cgGLBindProgram(sCgDeferredProgram); 
     1707 
     1708                cgGLEnableTextureParameter(sPositionsTexParam); 
     1709                cgGLSetTextureParameter(sPositionsTexParam, positionsTex); 
     1710         
     1711                cgGLEnableTextureParameter(sColorsTexParam); 
     1712                cgGLSetTextureParameter(sColorsTexParam, colorsTex); 
     1713 
     1714                cgGLEnableTextureParameter(sNormalsTexParam); 
     1715                cgGLSetTextureParameter(sNormalsTexParam, normalsTex); 
     1716        } 
    16601717 
    16611718        Vector3 tl, tr, bl, br; 
     
    16771734        glEnd(); 
    16781735 
    1679         cgGLDisableTextureParameter(sColorsTexParam); 
    1680         cgGLDisableTextureParameter(sPositionsTexParam); 
    1681         cgGLDisableTextureParameter(sNormalsTexParam); 
    1682         cgGLDisableTextureParameter(sNoiseTexParam); 
     1736        if (useSsao) 
     1737        { 
     1738                cgGLDisableTextureParameter(sColorsTexParamSsao); 
     1739                cgGLDisableTextureParameter(sPositionsTexParamSsao); 
     1740                cgGLDisableTextureParameter(sNormalsTexParamSsao); 
     1741 
     1742                cgGLDisableTextureParameter(sNoiseTexParamSsao); 
     1743                //cgGLDisableTextureParameter(sSamplesParamSsao); 
     1744        } 
     1745        else 
     1746        { 
     1747                cgGLDisableTextureParameter(sColorsTexParam); 
     1748                cgGLDisableTextureParameter(sPositionsTexParam); 
     1749                cgGLDisableTextureParameter(sNormalsTexParam); 
     1750        } 
    16831751 
    16841752        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2820 r2821  
    11#define NUM_SAMPLES 8 
    2 #define SAMPLE_INTENSITY 0.6 
     2#define SAMPLE_INTENSITY 0.5f 
     3//#define SAMPLE_INTENSITY 0.2f 
    34#define AREA_SIZE 3e-1f 
     5 
    46// kustls magic sample positions 
    57/*static const float2 samples[NUM_SAMPLES] = 
     
    5759 
    5860 
     61float2 rotate(float2 pt, float2 n) 
     62{ 
     63  float2 ptTransformed; 
     64  ptTransformed.x = n.r * pt.x - n.g * pt.y; 
     65  ptTransformed.y = n.g * pt.x + n.r * pt.y; 
     66 
     67  return ptTransformed; 
     68} 
     69 
     70 
    5971//based on kustls shader         
    6072float ssao(fragment IN, 
     
    88100     
    89101    //sample noisetex; r stores costheta, g stores sintheta 
    90     float3 noise = tex2D(noiseTexture, IN.texCoord.xy).xyz * 2.0f - 1.0f; 
     102    float2 noise = tex2D(noiseTexture, IN.texCoord.xy).xy * 2.0f - 1.0f; 
    91103         
    92104    // rotation 
    93105    //float2 offsetTransformed = offset; 
    94     float2 offsetTransformed; 
    95     offsetTransformed.x = noise.r * offset.x - noise.g * offset.y; 
    96     offsetTransformed.y = noise.g * offset.x + noise.r * offset.y; 
     106    float2 offsetTransformed = rotate(offset, noise); 
     107    //float2 offsetTransformed = reflect(offset, noise); 
     108 
     109    //offsetTransformed.x = noise.r * offset.x - noise.g * offset.y; 
     110    //offsetTransformed.y = noise.g * offset.x + noise.r * offset.y; 
    97111                 
    98112    // weight with projected coordinate to reach similar kernel size for near and far 
     
    114128 
    115129    float distance_intensity = maxdist - length_to_sample; 
     130    distance_intensity = max(distance_intensity, 0.0f); 
     131    // quadratic influence 
    116132    distance_intensity *= distance_intensity; 
    117     distance_intensity = max(distance_intensity, 0.0f); 
    118133     
    119134    total_ao += cos_angle * SAMPLE_INTENSITY * distance_intensity; 
     
    155170 
    156171 
     172pixel main_ssao(fragment IN,  
     173               uniform sampler2D colors, 
     174               uniform sampler2D positions, 
     175               uniform sampler2D normals, 
     176               uniform sampler2D noiseTexture, 
     177               uniform float2 samples[NUM_SAMPLES]) 
     178{ 
     179  pixel OUT; 
     180 
     181  float4 col = shade(IN, colors, positions, normals); 
     182  float ao = ssao(IN, positions, normals, noiseTexture, samples); 
     183   
     184  //OUT.color = tex2D(positions, IN.texCoord.xy); 
     185  //OUT.color = ao; 
     186  //OUT.color =  col; 
     187  OUT.color = ao * col; 
     188 
     189  return OUT; 
     190} 
     191 
     192 
    157193pixel main(fragment IN,  
    158194           uniform sampler2D colors, 
    159195           uniform sampler2D positions, 
    160            uniform sampler2D normals, 
    161            uniform sampler2D noiseTexture, 
    162            uniform float2 samples[NUM_SAMPLES]) 
     196           uniform sampler2D normals) 
    163197{ 
    164198  pixel OUT; 
    165199 
    166   float4 col = Shade(IN, positions, normals); 
    167   float ao = ssao(IN, positions, normals, noiseTexture, samples); 
    168   //float ao = 1.0f; 
    169   OUT.color = ao * col;  
    170   //OUT.color = ao * (ambient + diffuse) * color; 
    171   //OUT.color = (ambient + diffuse) * color; 
    172        
     200  float4 col = shade(IN, colors, positions, normals); 
     201  OUT.color = col; 
     202 
    173203  return OUT; 
    174204} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2819 r2821  
    5656   OUT.position = mul(ModelViewProj, OUT.worldPos); 
    5757 
    58    OUT.worldPos = IN.position; 
    59  
    6058   OUT.normal = IN.normal; 
    6159 
    6260   return OUT; 
    6361} 
    64  
    65 /*struct Material 
    66 { 
    67   float4 diffuse; 
    68 }*/ 
    6962 
    7063 
Note: See TracChangeset for help on using the changeset viewer.