Changeset 2822 for GTP/trunk/App/Demos


Ignore:
Timestamp:
07/08/08 03:35:16 (16 years ago)
Author:
mattausch
Message:

worked on deferred shading

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  
    1111CGparameter Material::sDiffuseParam; 
    1212CGparameter Material::sDiffuseTexParam; 
     13CGparameter Material::sAmbientParam; 
     14CGparameter Material::sAmbientTexParam; 
     15 
    1316 
    1417RgbaColor RandomColor(float a, float b) 
     
    6568        { 
    6669                mTexture->Bind(); 
     70 
     71                cgGLSetParameter4f(sAmbientTexParam,  
     72                                                   mEmmisiveColor.r,  
     73                                                   mEmmisiveColor.g,  
     74                                                   mEmmisiveColor.b,  
     75                                                   mEmmisiveColor.a); 
     76 
    6777                cgGLSetParameter4f(sDiffuseTexParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a); 
    6878        } 
    6979        else 
    7080        { 
     81                cgGLSetParameter4f(sAmbientParam,  
     82                                                   mEmmisiveColor.r,  
     83                                                   mEmmisiveColor.g,  
     84                                                   mEmmisiveColor.b,  
     85                                                   mEmmisiveColor.a); 
     86 
    7187                cgGLSetParameter4f(sDiffuseParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a); 
     88                 
    7289                glBindTexture(GL_TEXTURE_2D, 0); 
    7390        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h

    r2819 r2822  
    7575        static CGparameter sDiffuseTexParam; 
    7676 
     77        static CGparameter sAmbientParam; 
     78        static CGparameter sAmbientTexParam; 
     79 
    7780protected: 
    7881 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2821 r2822  
    6767int renderMode = RenderTraverser::CHCPLUSPLUS; 
    6868// eye near plane distance 
    69 float nearDist = 1.0f;  
     69float nearDist = 0.2f;  
    7070/// the pixel threshold where a node is still considered invisible 
    7171int threshold; 
     
    152152 
    153153 
    154 #define NUM_SAMPLES 8 
     154#define NUM_SAMPLES 12 
    155155 
    156156static float samples[NUM_SAMPLES * 2]; 
     
    429429                sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth"); 
    430430                Material::sDiffuseTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "diffuse"); 
     431                Material::sAmbientTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "ambient"); 
    431432 
    432433                cgGLSetParameter1f(sMaxDepthParamTex, 10.0f / myfar); 
     
    449450                sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth"); 
    450451                Material::sDiffuseParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "diffuse"); 
     452                Material::sAmbientParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "ambient"); 
    451453 
    452454                cgGLSetParameter1f(sMaxDepthParam, 10.0f / myfar); 
     
    555557        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 
    556558 
     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 
    557586        ////////// 
    558587        //-- positions buffer 
    559  
    560         int samples = 8; 
    561  
    562         //////////// 
    563         //-- colors buffer 
    564  
    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); 
    583588 
    584589        PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 
    585590        glGenRenderbuffersEXT(1, &positionsBuffer); 
    586591        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 
    590594        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, positionsBuffer); 
    591595 
     
    610614        glGenRenderbuffersEXT(1, &normalsBuffer); 
    611615        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, normalsBuffer); 
    612         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 
     616        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, texWidth, texHeight); 
    613617         
    614618        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_RENDERBUFFER_EXT, normalsBuffer); 
     
    616620        glGenTextures(1, &normalsTex); 
    617621        glBindTexture(GL_TEXTURE_2D, normalsTex); 
    618         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_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); 
    619623        //glGenerateMipmapEXT(GL_TEXTURE_2D); 
    620624        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 8 
    2 #define SAMPLE_INTENSITY 0.5f 
    3 //#define SAMPLE_INTENSITY 0.2f 
    4 #define AREA_SIZE 3e-1f 
     1#define NUM_SAMPLES 12 
     2//#define SAMPLE_INTENSITY 0.4f 
     3#define SAMPLE_INTENSITY 0.7f 
     4#define AREA_SIZE 5e-1f 
    55 
    66// kustls magic sample positions 
     
    7272float ssao(fragment IN, 
    7373           uniform sampler2D positions, 
    74            uniform sampler2D normals, 
    7574           uniform sampler2D noiseTexture, 
    76            uniform float2 samples[NUM_SAMPLES] 
     75           uniform float2 samples[NUM_SAMPLES], 
     76           uniform float3 currentNormal 
    7777           ) 
    7878{ 
     
    8282  float w = centerPosition.w; 
    8383 
    84   // the normal on the current position 
    85   float3 centerNormal = tex2D(normals, IN.texCoord.xy).xyz; 
    86   //normalize(centerNormal); 
    87    
    8884  // Check in a circular area around the current position. 
    8985  // Shoot vectors to the positions there, and check the angle to these positions. 
     
    120116     
    121117    // Angle between current normal and direction to sample controls AO intensity. 
    122     float cos_angle = dot(direction_to_sample, centerNormal); 
     118    float cos_angle = dot(direction_to_sample, currentNormal); 
    123119    cos_angle = max(cos_angle, 0.0f); 
    124120     
    125121    // distance between current position and sample position controls AO intensity. 
     122    //const float maxdist = 2e-1f; 
    126123    const float maxdist = 5e-1f; 
    127     //const float scale = 50.0f; 
    128  
     124     
    129125    float distance_intensity = maxdist - length_to_sample; 
     126    //float distance_intensity = 0.5f / (1.0f + length_to_sample * length_to_sample); 
    130127    distance_intensity = max(distance_intensity, 0.0f); 
    131128    // quadratic influence 
     
    142139             uniform sampler2D colors, 
    143140             uniform sampler2D positions, 
    144              uniform sampler2D normals) 
     141             uniform float3 normal, 
     142             uniform float amb) 
    145143{ 
    146144  float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 
     
    148146   
    149147  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  
    155149  float4 position = tex2D(positions, IN.texCoord.xy); 
    156150 
    157   float4 ambient = float4(0.3f); 
     151  float4 ambient = 0.3f; 
    158152 
    159153  // float3 L = normalize(lightPosition - position); 
     
    166160  float diffuse = diffuseLight + diffuseLight2; 
    167161 
    168   return (ambient + diffuse) * color; 
     162  return (ambient + diffuse) * color * (1.0f - amb) + amb * color; 
    169163} 
    170164 
     
    179173  pixel OUT; 
    180174 
    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); 
    183183   
    184184  //OUT.color = tex2D(positions, IN.texCoord.xy); 
    185185  //OUT.color = ao; 
    186   //OUT.color =  col; 
     186  //OUT.color = col; 
    187187  OUT.color = ao * col; 
    188188 
     
    197197{ 
    198198  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); 
    201207  OUT.color = col; 
    202208 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2821 r2822  
    3737  float4 col: COLOR0; 
    3838  float4 pos: COLOR1; 
    39   float3 norm: COLOR2; 
     39  float4 norm: COLOR2; 
    4040}; 
    4141 
     
    6262 
    6363 
    64 pixel fragtex(fragin IN, uniform sampler2D tex, uniform float maxDepth, uniform float4 diffuse) 
     64pixel fragtex(fragin IN,  
     65              uniform sampler2D tex,  
     66              uniform float maxDepth,  
     67              uniform float4 ambient,  
     68              uniform float4 diffuse) 
    6569{ 
    6670  pixel pix; 
    6771       
    68   pix.col = diffuse * tex2D(tex, IN.texCoord.xy); 
     72  pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy); 
    6973  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 
    7178  pix.pos.w = IN.projPos.w; 
    7279 
     
    7582 
    7683 
    77 pixel frag(fragin IN, uniform float maxDepth, uniform float4 diffuse) 
     84pixel frag(fragin IN,  
     85           uniform float maxDepth,  
     86           uniform float4 ambient,  
     87           uniform float4 diffuse) 
    7888{ 
    7989  pixel pix; 
     
    8191  pix.col = diffuse; 
    8292  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; 
    8496  pix.pos.w = IN.projPos.w; 
    8597 
Note: See TracChangeset for help on using the changeset viewer.