Changeset 2821 for GTP/trunk/App/Demos
- Timestamp:
- 07/07/08 18:41:45 (16 years ago)
- 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 145 145 bool eightKeyPressed = false; 146 146 147 bool useSsao = false; 148 147 149 GLubyte *randomNormals = NULL; 148 150 … … 216 218 static CGcontext sCgContext = NULL; 217 219 static CGprogram sCgMrtVertexProgram = NULL; 218 static CGprogram sCgS SAOProgram = NULL;219 220 static CGprogram sCgSsaoProgram = NULL; 221 static CGprogram sCgDeferredProgram = NULL; 220 222 221 223 static CGparameter sColorsTexParam; 222 224 static CGparameter sPositionsTexParam; 223 225 static CGparameter sNormalsTexParam; 224 static CGparameter sNoiseTexParam; 226 //static CGparameter sNoiseTexParam; 227 228 static CGparameter sColorsTexParamSsao; 229 static CGparameter sPositionsTexParamSsao; 230 static CGparameter sNormalsTexParamSsao; 231 static CGparameter sNoiseTexParamSsao; 225 232 226 233 static CGparameter sModelViewProjMatrixParam; … … 229 236 static CGparameter sMaxDepthParamTex; 230 237 231 static CGparameter sSamplesParam; 238 //static CGparameter sSamplesParam; 239 static CGparameter sSamplesParamSsao; 232 240 233 241 … … 279 287 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); 280 288 289 #if 1 281 290 glutCreateWindow("FriendlyCulling"); 282 283 //glutGameModeString( "1024x768:32@75" ); //the settings for fullscreen mode284 //glutEnterGameMode(); //set glut to fullscreen using the settings in the line above285 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 286 295 glutDisplayFunc(Display); 287 296 glutKeyboardFunc(KeyBoard); … … 398 407 NULL); 399 408 400 if (sCgMrtVertexProgram != NULL)409 if (sCgMrtVertexProgram != NULL) 401 410 { 402 411 cgGLLoadProgram(sCgMrtVertexProgram); … … 451 460 /////////////// 452 461 453 sCgS SAOProgram =462 sCgSsaoProgram = 454 463 cgCreateProgramFromFile(sCgContext, 455 464 CG_SOURCE, 456 465 "src/shaders/deferred.cg", 457 //"src/test.cg",458 466 RenderState::sCgFragmentProfile, 459 NULL,467 "main_ssao", 460 468 NULL); 461 469 462 if (sCgSSAOProgram != NULL)463 { 464 cgGLLoadProgram(sCgS SAOProgram);470 if (sCgSsaoProgram != NULL) 471 { 472 cgGLLoadProgram(sCgSsaoProgram); 465 473 466 474 // 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); 474 482 } 475 483 else 476 484 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 477 511 478 512 PrintGLerror("init"); … … 666 700 "'F7', - depth pass", 667 701 "'F8', - enable/disable glFinish for more accurate timings", 702 "'F9', - enables/disables ambient occlusion", 668 703 "'SPACE' - cycles through occlusion culling algorithms", 669 704 "", … … 1159 1194 useGlFinish = !useGlFinish; 1160 1195 break; 1196 case GLUT_KEY_F9: 1197 useSsao = !useSsao; 1198 break; 1161 1199 case GLUT_KEY_LEFT: 1162 1200 { … … 1446 1484 if (sCgMrtVertexProgram) 1447 1485 cgDestroyProgram(sCgMrtVertexProgram); 1448 if (sCgSSAOProgram) 1449 cgDestroyProgram(sCgSSAOProgram); 1486 if (sCgSsaoProgram) 1487 cgDestroyProgram(sCgSsaoProgram); 1488 if (sCgDeferredProgram) 1489 cgDestroyProgram(sCgDeferredProgram); 1450 1490 if (sCgContext) 1451 1491 cgDestroyContext(sCgContext); … … 1645 1685 1646 1686 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 } 1660 1717 1661 1718 Vector3 tl, tr, bl, br; … … 1677 1734 glEnd(); 1678 1735 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 } 1683 1751 1684 1752 cgGLDisableProfile(RenderState::sCgFragmentProfile); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2820 r2821 1 1 #define NUM_SAMPLES 8 2 #define SAMPLE_INTENSITY 0.6 2 #define SAMPLE_INTENSITY 0.5f 3 //#define SAMPLE_INTENSITY 0.2f 3 4 #define AREA_SIZE 3e-1f 5 4 6 // kustls magic sample positions 5 7 /*static const float2 samples[NUM_SAMPLES] = … … 57 59 58 60 61 float2 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 59 71 //based on kustls shader 60 72 float ssao(fragment IN, … … 88 100 89 101 //sample noisetex; r stores costheta, g stores sintheta 90 float 3 noise = tex2D(noiseTexture, IN.texCoord.xy).xyz* 2.0f - 1.0f;102 float2 noise = tex2D(noiseTexture, IN.texCoord.xy).xy * 2.0f - 1.0f; 91 103 92 104 // rotation 93 105 //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; 97 111 98 112 // weight with projected coordinate to reach similar kernel size for near and far … … 114 128 115 129 float distance_intensity = maxdist - length_to_sample; 130 distance_intensity = max(distance_intensity, 0.0f); 131 // quadratic influence 116 132 distance_intensity *= distance_intensity; 117 distance_intensity = max(distance_intensity, 0.0f);118 133 119 134 total_ao += cos_angle * SAMPLE_INTENSITY * distance_intensity; … … 155 170 156 171 172 pixel 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 157 193 pixel main(fragment IN, 158 194 uniform sampler2D colors, 159 195 uniform sampler2D positions, 160 uniform sampler2D normals, 161 uniform sampler2D noiseTexture, 162 uniform float2 samples[NUM_SAMPLES]) 196 uniform sampler2D normals) 163 197 { 164 198 pixel OUT; 165 199 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 173 203 return OUT; 174 204 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2819 r2821 56 56 OUT.position = mul(ModelViewProj, OUT.worldPos); 57 57 58 OUT.worldPos = IN.position;59 60 58 OUT.normal = IN.normal; 61 59 62 60 return OUT; 63 61 } 64 65 /*struct Material66 {67 float4 diffuse;68 }*/69 62 70 63
Note: See TracChangeset
for help on using the changeset viewer.