Changeset 2822 for GTP/trunk/App/Demos/Vis
- Timestamp:
- 07/08/08 03:35:16 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
r2819 r2822 11 11 CGparameter Material::sDiffuseParam; 12 12 CGparameter Material::sDiffuseTexParam; 13 CGparameter Material::sAmbientParam; 14 CGparameter Material::sAmbientTexParam; 15 13 16 14 17 RgbaColor RandomColor(float a, float b) … … 65 68 { 66 69 mTexture->Bind(); 70 71 cgGLSetParameter4f(sAmbientTexParam, 72 mEmmisiveColor.r, 73 mEmmisiveColor.g, 74 mEmmisiveColor.b, 75 mEmmisiveColor.a); 76 67 77 cgGLSetParameter4f(sDiffuseTexParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a); 68 78 } 69 79 else 70 80 { 81 cgGLSetParameter4f(sAmbientParam, 82 mEmmisiveColor.r, 83 mEmmisiveColor.g, 84 mEmmisiveColor.b, 85 mEmmisiveColor.a); 86 71 87 cgGLSetParameter4f(sDiffuseParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a); 88 72 89 glBindTexture(GL_TEXTURE_2D, 0); 73 90 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
r2819 r2822 75 75 static CGparameter sDiffuseTexParam; 76 76 77 static CGparameter sAmbientParam; 78 static CGparameter sAmbientTexParam; 79 77 80 protected: 78 81 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2821 r2822 67 67 int renderMode = RenderTraverser::CHCPLUSPLUS; 68 68 // eye near plane distance 69 float nearDist = 1.0f;69 float nearDist = 0.2f; 70 70 /// the pixel threshold where a node is still considered invisible 71 71 int threshold; … … 152 152 153 153 154 #define NUM_SAMPLES 8154 #define NUM_SAMPLES 12 155 155 156 156 static float samples[NUM_SAMPLES * 2]; … … 429 429 sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth"); 430 430 Material::sDiffuseTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "diffuse"); 431 Material::sAmbientTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "ambient"); 431 432 432 433 cgGLSetParameter1f(sMaxDepthParamTex, 10.0f / myfar); … … 449 450 sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth"); 450 451 Material::sDiffuseParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "diffuse"); 452 Material::sAmbientParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "ambient"); 451 453 452 454 cgGLSetParameter1f(sMaxDepthParam, 10.0f / myfar); … … 555 557 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 556 558 559 560 //////////// 561 //-- colors buffer 562 563 glGenRenderbuffersEXT(1, &colorsBuffer); 564 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer); 565 566 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, texWidth, texHeight); 567 int samples = 8; 568 //glEnable(GL_MULTISAMPLE_ARB); 569 //glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_RGBA8, texWidth, texHeight); 570 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer); 571 572 glGenTextures(1, &colorsTex); 573 glBindTexture(GL_TEXTURE_2D, colorsTex); 574 575 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 576 glGenerateMipmapEXT(GL_TEXTURE_2D); 577 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0); 578 579 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 580 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 581 582 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 583 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 584 585 557 586 ////////// 558 587 //-- positions buffer 559 560 int samples = 8;561 562 ////////////563 //-- colors buffer564 565 glGenRenderbuffersEXT(1, &colorsBuffer);566 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer);567 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);568 569 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer);570 571 glGenTextures(1, &colorsTex);572 glBindTexture(GL_TEXTURE_2D, colorsTex);573 574 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);575 glGenerateMipmapEXT(GL_TEXTURE_2D);576 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0);577 578 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);579 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);580 581 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);582 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);583 588 584 589 PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 585 590 glGenRenderbuffersEXT(1, &positionsBuffer); 586 591 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, positionsBuffer); 587 //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 588 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_RGBA32F_ARB, texWidth, texHeight); 589 592 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 593 590 594 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, positionsBuffer); 591 595 … … 610 614 glGenRenderbuffersEXT(1, &normalsBuffer); 611 615 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, normalsBuffer); 612 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA 32F_ARB, texWidth, texHeight);616 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, texWidth, texHeight); 613 617 614 618 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_RENDERBUFFER_EXT, normalsBuffer); … … 616 620 glGenTextures(1, &normalsTex); 617 621 glBindTexture(GL_TEXTURE_2D, normalsTex); 618 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA 32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);622 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 619 623 //glGenerateMipmapEXT(GL_TEXTURE_2D); 620 624 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, normalsTex, 0); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2821 r2822 1 #define NUM_SAMPLES 82 #define SAMPLE_INTENSITY 0.5f3 //#define SAMPLE_INTENSITY 0.2f4 #define AREA_SIZE 3e-1f1 #define NUM_SAMPLES 12 2 //#define SAMPLE_INTENSITY 0.4f 3 #define SAMPLE_INTENSITY 0.7f 4 #define AREA_SIZE 5e-1f 5 5 6 6 // kustls magic sample positions … … 72 72 float ssao(fragment IN, 73 73 uniform sampler2D positions, 74 uniform sampler2D normals,75 74 uniform sampler2D noiseTexture, 76 uniform float2 samples[NUM_SAMPLES] 75 uniform float2 samples[NUM_SAMPLES], 76 uniform float3 currentNormal 77 77 ) 78 78 { … … 82 82 float w = centerPosition.w; 83 83 84 // the normal on the current position85 float3 centerNormal = tex2D(normals, IN.texCoord.xy).xyz;86 //normalize(centerNormal);87 88 84 // Check in a circular area around the current position. 89 85 // Shoot vectors to the positions there, and check the angle to these positions. … … 120 116 121 117 // Angle between current normal and direction to sample controls AO intensity. 122 float cos_angle = dot(direction_to_sample, c enterNormal);118 float cos_angle = dot(direction_to_sample, currentNormal); 123 119 cos_angle = max(cos_angle, 0.0f); 124 120 125 121 // distance between current position and sample position controls AO intensity. 122 //const float maxdist = 2e-1f; 126 123 const float maxdist = 5e-1f; 127 //const float scale = 50.0f; 128 124 129 125 float distance_intensity = maxdist - length_to_sample; 126 //float distance_intensity = 0.5f / (1.0f + length_to_sample * length_to_sample); 130 127 distance_intensity = max(distance_intensity, 0.0f); 131 128 // quadratic influence … … 142 139 uniform sampler2D colors, 143 140 uniform sampler2D positions, 144 uniform sampler2D normals) 141 uniform float3 normal, 142 uniform float amb) 145 143 { 146 144 float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); … … 148 146 149 147 float4 color = tex2D(colors, IN.texCoord.xy); 150 float3 normal = tex2D(normals, IN.texCoord.xy).xyz; 151 152 // expand normal 153 normal = normalize(normal * 2.0f - 1.0f); 154 148 155 149 float4 position = tex2D(positions, IN.texCoord.xy); 156 150 157 float4 ambient = float4(0.3f);151 float4 ambient = 0.3f; 158 152 159 153 // float3 L = normalize(lightPosition - position); … … 166 160 float diffuse = diffuseLight + diffuseLight2; 167 161 168 return (ambient + diffuse) * color ;162 return (ambient + diffuse) * color * (1.0f - amb) + amb * color; 169 163 } 170 164 … … 179 173 pixel OUT; 180 174 181 float4 col = shade(IN, colors, positions, normals); 182 float ao = ssao(IN, positions, normals, noiseTexture, samples); 175 float4 normal = tex2D(normals, IN.texCoord.xy); 176 float amb = normal.w; 177 178 // expand normal 179 normal = normalize(normal * 2.0f - 1.0f); 180 181 float4 col = shade(IN, colors, positions, normal, amb); 182 float ao = ssao(IN, positions, noiseTexture, samples, normal); 183 183 184 184 //OUT.color = tex2D(positions, IN.texCoord.xy); 185 185 //OUT.color = ao; 186 //OUT.color = 186 //OUT.color = col; 187 187 OUT.color = ao * col; 188 188 … … 197 197 { 198 198 pixel OUT; 199 200 float4 col = shade(IN, colors, positions, normals); 199 200 float4 normal = tex2D(normals, IN.texCoord.xy); 201 float amb = normal.w; 202 203 // expand normal 204 normal = normalize(normal * 2.0f - 1.0f); 205 206 float4 col = shade(IN, colors, positions, normal.xyz, amb); 201 207 OUT.color = col; 202 208 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2821 r2822 37 37 float4 col: COLOR0; 38 38 float4 pos: COLOR1; 39 float 3norm: COLOR2;39 float4 norm: COLOR2; 40 40 }; 41 41 … … 62 62 63 63 64 pixel fragtex(fragin IN, uniform sampler2D tex, uniform float maxDepth, uniform float4 diffuse) 64 pixel fragtex(fragin IN, 65 uniform sampler2D tex, 66 uniform float maxDepth, 67 uniform float4 ambient, 68 uniform float4 diffuse) 65 69 { 66 70 pixel pix; 67 71 68 pix.col = diffuse* tex2D(tex, IN.texCoord.xy);72 pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy); 69 73 pix.pos = IN.worldPos * maxDepth; 70 pix.norm = IN.normal; 74 pix.norm.xyz = IN.normal * 0.5f + 0.5f; 75 // hack: squeeze some information about ambient into the texture 76 pix.norm.w = ambient.x; 77 // hack: store projection coordinate for scaling ssao 71 78 pix.pos.w = IN.projPos.w; 72 79 … … 75 82 76 83 77 pixel frag(fragin IN, uniform float maxDepth, uniform float4 diffuse) 84 pixel frag(fragin IN, 85 uniform float maxDepth, 86 uniform float4 ambient, 87 uniform float4 diffuse) 78 88 { 79 89 pixel pix; … … 81 91 pix.col = diffuse; 82 92 pix.pos = IN.worldPos * maxDepth; 83 pix.norm = IN.normal; 93 pix.norm.xyz = IN.normal * 0.5f + 0.5f; 94 // hack: squeeze some information about ambient into the texture 95 pix.norm.w = ambient.x; 84 96 pix.pos.w = IN.projPos.w; 85 97
Note: See TracChangeset
for help on using the changeset viewer.