Changeset 2818


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

worked on deferred shading

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
4 deleted
9 edited

Legend:

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

    r2795 r2818  
    119119                                        } 
    120120 
    121                                          
    122121                                        // always traverse a node if it was visible 
    123122                                        if (wasVisible) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp

    r2795 r2818  
    2222        mAmbientColor = RgbaColor(0.2f, 0.2f, 0.2f, 1.0f); 
    2323        mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f); 
    24         //mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f); 
    25         mSpecularColor = RgbaColor(0.5f, 0.5f, 0.5f, 1.0f); 
     24        mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f); 
    2625        mEmmisiveColor = RgbaColor(.0f, .0f, .0f, 1.0f); 
    2726} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r2816 r2818  
    11#include "RenderState.h" 
    2 #include "glInterface.h" 
    32#include "Geometry.h" 
    43#include "Material.h" 
     
    76namespace CHCDemoEngine  
    87{ 
     8 
     9CGprofile RenderState::sCgFragmentProfile; 
     10CGprofile RenderState::sCgVertexProfile;  
    911 
    1012 
     
    3436                        glDisable(GL_LIGHTING); 
    3537                        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
     38 
     39                        cgGLDisableProfile(sCgFragmentProfile); 
     40                        cgGLDisableProfile(sCgVertexProfile); 
    3641                } 
    3742 
     
    4954                        glEnable(GL_LIGHTING); 
    5055                        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     56 
     57                        cgGLEnableProfile(sCgFragmentProfile); 
     58                        cgGLEnableProfile(sCgVertexProfile); 
    5159                } 
    5260 
     
    6876        { 
    6977                mAlphaTestEnabled = true; 
    70                 //glEnable(GL_ALPHA_TEST); 
     78                glEnable(GL_ALPHA_TEST); 
    7179        } 
    7280 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h

    r2801 r2818  
    44 
    55#include "common.h" 
     6#include "glInterface.h" 
     7#include <Cg/cg.h> 
     8#include <Cg/cgGL.h> 
    69 
    710 
     
    5154        bool IsDepthPass() { return mIsDepthPass; } 
    5255 
     56        static CGprofile sCgFragmentProfile; 
     57        static CGprofile sCgVertexProfile;  
     58 
     59 
    5360protected: 
    5461 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp

    r2802 r2818  
    44#include "Material.h" 
    55#include "RenderState.h" 
     6#include <Cg/cg.h> 
     7#include <Cg/cgGL.h> 
    68 
    79 
     
    911{ 
    1012 
     13CGparameter SceneEntity::sModelMatrixParam; 
    1114 
    1215SceneEntity::SceneEntity(Geometry *geometry,  
     
    2932        if (mTransform) 
    3033        { 
    31                 glPushMatrix(); 
    32                 glMultMatrixf((float *)mTransform->x); 
     34                cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mTransform->x); 
     35                //glPushMatrix(); 
     36                //glMultMatrixf((float *)mTransform->x); 
    3337                mGeometry->Render(state); 
    3438 
    35                 glPopMatrix(); 
     39                //glPopMatrix(); 
    3640        } 
    3741        else 
    3842        { 
     43                static Matrix4x4 identity = IdentityMatrix(); 
     44 
     45                cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x); 
    3946                mGeometry->Render(state); 
    4047        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h

    r2802 r2818  
    22#define __SCENEENTITY_H 
    33 
     4#include "glInterface.h" 
    45#include "common.h" 
    56#include "AxisAlignedBox3.h" 
    67#include "Triangle3.h" 
    7  
     8#include <Cg/cg.h> 
     9#include <Cg/cgGL.h> 
    810 
    911namespace CHCDemoEngine  
    1012{ 
     13 
     14 
    1115 
    1216class Material; 
     
    2327 
    2428public: 
     29        static CGparameter sModelMatrixParam; 
    2530        /** Creates a scene entity. 
    2631        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2817 r2818  
    11// occquery.cpp : Defines the entry point for the console application. 
    22// 
     3#include "glInterface.h" 
    34#include <math.h> 
    45#include <time.h> 
    56#include "common.h" 
    6 #include "glInterface.h" 
    77#include "RenderTraverser.h" 
    88#include "SceneEntity.h" 
     
    209209static CGprogram sCgMrtFragmentProgram = NULL; 
    210210 
    211 static CGprofile sCgFragmentProfile; 
    212 static CGprofile sCgVertexProfile;  
    213  
    214211static CGparameter sColorsTexParam; 
    215212static CGparameter sPositionsTexParam; 
     
    217214static CGparameter sNoiseTexParam; 
    218215 
    219 /*static CGparameter sTexSizeParam;  
    220 static CGparameter sSamplesParam;  
    221 static CGparameter sEyeVecParam;  
    222 static CGparameter sRadiusParam;  
    223 */ 
    224 static CGparameter sProjectionMatrixParam; 
    225 static CGparameter sModelViewMatrixParam;        
     216static CGparameter sModelViewProjMatrixParam; 
     217//static CGparameter sModelMatrixParam; 
    226218static CGparameter sMaxDepthParam; 
    227219 
     
    276268 
    277269        glutCreateWindow("FriendlyCulling"); 
     270 
     271        //glutGameModeString( "1024x768:32@75" ); //the settings for fullscreen mode 
     272        //glutEnterGameMode(); //set glut to fullscreen using the settings in the line above 
    278273 
    279274        glutDisplayFunc(Display); 
     
    333328        //bvh = bvhLoader.Load("data/city/model/city.bvh", sceneEntities); 
    334329 
    335         myfar = 1.0f * Magnitude(bvh->GetBox().Diagonal()); 
     330        myfar = 10.0f * Magnitude(bvh->GetBox().Diagonal()); 
    336331 
    337332        if (!bvh) 
     
    353348        visualization = new Visualization(bvh, camera, NULL, &state); 
    354349 
    355         sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 
     350        //sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 
    356351 
    357352 
     
    376371 
    377372        // get the best profile for this hardware 
    378         sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); 
     373        RenderState::sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); 
    379374        //assert(sCgFragmentProfile != CG_PROFILE_UNKNOWN); 
    380         cgGLSetOptimalOptions(sCgFragmentProfile); 
    381  
    382         sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); 
    383         cgGLSetOptimalOptions(sCgVertexProfile); 
     375        cgGLSetOptimalOptions(RenderState::sCgFragmentProfile); 
     376 
     377        RenderState::sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); 
     378        cgGLSetOptimalOptions(RenderState::sCgVertexProfile); 
    384379 
    385380        sCgMrtVertexProgram =  
     
    387382                                                                CG_SOURCE, 
    388383                                                                "src/shaders/mrt.cg",  
    389                                                                 sCgVertexProfile, 
     384                                                                RenderState::sCgVertexProfile, 
    390385                                                                "vtx", 
    391386                                                                NULL); 
     
    394389        { 
    395390                cgGLLoadProgram(sCgMrtVertexProgram); 
    396          
    397                 sModelViewMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj"); 
     391 
     392                SceneEntity::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelMatrix"); 
     393                sModelViewProjMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj"); 
    398394        } 
    399395 
     
    402398                                                                CG_SOURCE, 
    403399                                                                "src/shaders/mrt.cg",  
    404                                                                 sCgFragmentProfile, 
     400                                                                RenderState::sCgFragmentProfile, 
    405401                                                                "frag", 
    406402                                                                NULL); 
     
    411407 
    412408                sMaxDepthParam = cgGetNamedParameter(sCgMrtFragmentProgram, "maxDepth"); 
    413                 cgGLSetParameter1f(sMaxDepthParam, 1.0f / myfar); 
     409 
     410                cgGLSetParameter1f(sMaxDepthParam, 10.0f / myfar); 
    414411        } 
    415412        else 
     
    426423                                                                "src/shaders/deferred.cg",  
    427424                                                                //"src/test.cg",  
    428                                                                 sCgFragmentProfile, 
     425                                                                RenderState::sCgFragmentProfile, 
    429426                                                                NULL, 
    430427                                                                NULL); 
     
    438435                sColorsTexParam = cgGetNamedParameter(sCgSSAOProgram, "colors");   
    439436                sNormalsTexParam = cgGetNamedParameter(sCgSSAOProgram, "normals");   
    440                 sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture");   
    441  
    442                 sProjectionMatrixParam = cgGetNamedParameter(sCgSSAOProgram, "ProjTrafo"); 
    443  
    444                 /*sTexSizeParam = cgGetNamedParameter(sCgSSAOProgram, "invTexSize"); 
    445                 sRadiusParam = cgGetNamedParameter(sCgSSAOProgram, "radius"); 
    446                 sEyeVecParam = cgGetNamedParameter(sCgSSAOProgram, "eyevec"); 
    447                 sSamplesParam = cgGetNamedParameter(sCgSSAOProgram, "samples"); 
    448  
    449                 cgGLSetParameter1f(sTexSizeParam, 1.0f / (float)texWidth); 
    450                 cgGLSetParameter1f(sRadiusParam, radius); 
    451                 cgGLSetParameterArray3f(sSamplesParam, 0, 32, (const float *)samples);*/ 
     437                sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture"); 
    452438        } 
    453439        else 
     
    455441 
    456442        PrintGLerror("init"); 
     443 
     444        cout << "cg initialised" << endl; 
    457445} 
    458446 
     
    584572        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
    585573 
    586  
    587         //////////////// 
    588         //-- second fbo 
    589  
    590         /*glGenFramebuffersEXT(1, &fbo2); 
    591         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2); 
    592  
    593         // create color buffer 
    594         glGenRenderbuffersEXT(1, &occlusionbuffer); 
    595         //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 
    596         glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_FLOAT_RGBA_NV, texWidth2, texHeight2); 
    597         glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, occlusionbuffer); 
    598         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, occlusionbuffer); 
    599  
    600         glGenTextures(1, &occlusionTex); 
    601         glBindTexture(GL_TEXTURE_2D, occlusionTex); 
    602         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  texWidth2, texHeight2, 0, GL_RGBA, GL_FLOAT, NULL); 
    603         glGenerateMipmapEXT(GL_TEXTURE_2D); 
    604         glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorTex, 0); 
    605  
    606         PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 
    607  
    608         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);*/ 
    609574        PrintGLerror("fbo"); 
    610575} 
     
    882847        glViewport(0, 0, texWidth, texHeight); 
    883848 
    884         cgGLEnableProfile(sCgFragmentProfile); 
     849        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    885850        cgGLBindProgram(sCgMrtFragmentProgram); 
    886851 
    887         cgGLEnableProfile(sCgVertexProfile); 
     852        cgGLEnableProfile(RenderState::sCgVertexProfile); 
    888853        cgGLBindProgram(sCgMrtVertexProgram); 
    889854 
     
    896861        glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
    897862 
     863        // set modelview matrix for shaders 
     864        cgGLSetStateMatrixParameter(sModelViewProjMatrixParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); 
     865 
    898866        // render without shading 
    899867        if (depthPass)  
     
    907875                glEnable(GL_LIGHTING); 
    908876        } 
    909  
     877         
     878        static Matrix4x4 identity = IdentityMatrix(); 
     879 
     880        cgGLSetMatrixParameterfc(SceneEntity::sModelMatrixParam, (const float *)identity.x); 
    910881        // bring eye modelview matrix up-to-date 
    911882        SetupEyeView(); 
    912883 
    913         Vector3 dir = camera->GetDirection(); 
    914         //cgGLSetParameter3f(sEyeVecParam, dir.x, dir.y, dir.z); 
    915  
    916         // set modelview matrix for shaders 
    917         cgGLSetStateMatrixParameter(sModelViewMatrixParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); 
    918         cgGLEnableProfile(sCgVertexProfile); 
    919  
    920884        // actually render the scene geometry using one of the specified algorithms 
    921885        traverser->RenderScene(); 
     
    947911         
    948912         
    949         cgGLDisableProfile(sCgVertexProfile); 
    950         cgGLDisableProfile(sCgFragmentProfile); 
     913        cgGLDisableProfile(RenderState::sCgVertexProfile); 
     914        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    951915 
    952916        glPopAttrib(); 
    953917 
    954         cgGLSetStateMatrixParameter(sProjectionMatrixParam, CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); 
    955          
    956918        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
    957919 
     
    14971459        static char msg[7][300]; 
    14981460 
    1499         static double renderTime = algTime; 
    1500         const float expFactor = 0.5f; 
     1461        static double renderTime = elapsedTime;//algTime; 
     1462        const float expFactor = 0.1f; 
    15011463 
    15021464        // if some strange render time spike happened in this frame => don't count 
     
    16291591{ 
    16301592        glDisable(GL_TEXTURE_2D); 
    1631         //glEnable(GL_TEXTURE_2D); 
     1593         
    16321594        glDisable(GL_LIGHTING); 
    1633         //glBindTexture(GL_TEXTURE_2D, noiseTex); 
     1595         
    16341596        glMatrixMode(GL_PROJECTION); 
    16351597        glPushMatrix(); 
     
    16411603 
    16421604        const float offs = 0.5f; 
    1643         //glPushAttrib(GL_VIEWPORT_BIT); 
    1644         //glViewport(-offs, texHeight); 
     1605         
    16451606        glOrtho(-offs, offs, -offs, offs, 0, 1); 
    16461607         
    16471608        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    16481609 
    1649         cgGLEnableProfile(sCgFragmentProfile); 
     1610        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    16501611        cgGLBindProgram(sCgSSAOProgram); 
    16511612 
     
    16681629 
    16691630        glBegin(GL_QUADS); 
    1670 #if 1 
     1631 
    16711632        // slightly larger than screen size in order to hide ambient occlusion errors 
    1672         float offs2 = 0.55f; 
    1673         //float offs2 = 0.5f; 
     1633        //float offs2 = 0.55f; 
     1634        float offs2 = 0.5f; 
    16741635 
    16751636        glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f); 
     
    16771638        glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( offs2,  offs2, -0.5f); 
    16781639        glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-offs2,  offs2, -0.5f); 
    1679 #else 
    1680         glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 
    1681         glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f); 
    1682         glTexCoord2f(1, 1); glVertex3f( 1,  1, -0.5f); 
    1683         glTexCoord2f(0, 1); glVertex3f(-1,  1, -0.5f); 
    1684 #endif 
     1640 
    16851641        glEnd(); 
    16861642 
     
    16901646        cgGLDisableTextureParameter(sNoiseTexParam); 
    16911647 
    1692         cgGLDisableProfile(sCgFragmentProfile); 
     1648        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    16931649         
    16941650        glEnable(GL_LIGHTING); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2817 r2818  
    6060           uniform sampler2D positions, 
    6161           uniform sampler2D normals, 
    62            const uniform float4x4 ProjTrafo, 
    6362           uniform sampler2D noiseTexture                                
    6463           ) 
    6564{ 
    6665  // the current world position 
    67   float4 centerPositionW = tex2D(positions, IN.texCoord.xy); 
    68   float3 centerPosition = centerPositionW.xyz; 
     66  float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
     67  // the w coordinate from the persp. projection 
     68  float w = centerPosition.w; 
    6969 
    7070  // the normal on the current position 
     
    8787    //sample noisetex; r stores costheta, g stores sintheta 
    8888    float3 noise = tex2D(noiseTexture, IN.texCoord.xy).xyz * 2.0f - 1.0f; 
    89  
    90     //float2 offsetTransformed = offset;//reflect(offset, noise.xy); 
     89         
     90    // rotation 
     91    //float2 offsetTransformed = offset; 
    9192    float2 offsetTransformed; 
    9293    offsetTransformed.x = noise.r * offset.x - noise.g * offset.y; 
     
    9495                 
    9596    // weight with projected coordinate to reach similar kernel size for near and far 
    96     float2 texcoord = IN.texCoord.xy + offsetTransformed * areaSize * centerPositionW.w; 
     97    float2 texcoord = IN.texCoord.xy + offsetTransformed * areaSize * w; 
    9798     
    9899    float3 sample_position = tex2D(positions, texcoord).xyz; 
    99100     
    100     float3 vector_to_sample = sample_position - centerPosition; 
     101    float3 vector_to_sample = sample_position - centerPosition.xyz; 
    101102    float length_to_sample = length(vector_to_sample); 
    102103    float3 direction_to_sample = vector_to_sample / (length_to_sample + 1e-9f); 
     
    125126           uniform sampler2D positions, 
    126127           uniform sampler2D normals, 
    127            const uniform float4x4 ProjTrafo, 
    128128           uniform sampler2D noiseTexture) 
    129129{ 
     
    137137 
    138138  // expand normal 
    139   normal = normal * 2.0f - 1.0f; 
     139  normal = normalize(normal * 2.0f - 1.0f); 
    140140 
    141141  float4 position = tex2D(positions, IN.texCoord.xy); 
     
    146146  float3 light = normalize(lightDir.xyz); 
    147147  float3 light2 = normalize(lightDir2.xyz); 
    148  
     148  
    149149  float diffuseLight = max(dot(normal, light), 0.0f); 
    150150  float diffuseLight2 = max(dot(normal, light2), 0.0f); 
     
    152152  float diffuse = diffuseLight + diffuseLight2; 
    153153 
    154   float ao = ssao(IN, positions, normals, ProjTrafo, noiseTexture); 
     154  float ao = ssao(IN, positions, normals, noiseTexture); 
    155155  //OUT.color = ao;  
    156156  OUT.color = ao * (ambient + diffuse) * color; 
    157 //OUT.color = (ambient + diffuse) * color; 
    158  
    159   //float4 currentPos = tex2D(normals, IN.texCoord.xy) * 0.5f + 0.5f; 
    160   //float4 currentPos = tex2D(normals, IN.texCoord.xy); 
    161   //OUT.color = currentPos; 
     157  //OUT.color = (ambient + diffuse) * color; 
    162158       
    163159  return OUT; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2813 r2818  
    4141 
    4242 
    43 vtxout vtx(vtxin IN, uniform float4x4 ModelViewProj) 
     43vtxout vtx(vtxin IN,  
     44           const uniform float4x4 ModelViewProj, 
     45           uniform float4x4 ModelMatrix) 
    4446{ 
    4547   vtxout OUT; 
    4648   
    4749   // transform the vertex position into eye space 
    48    OUT.position = mul(ModelViewProj, IN.position); 
    49  
    5050   OUT.color = IN.color; 
    5151 
    5252   OUT.texCoord = IN.texCoord; 
     53   OUT.worldPos = mul(ModelMatrix, IN.position); 
     54 
     55   // transform the vertex position into eye space 
     56   OUT.position = mul(ModelViewProj, OUT.worldPos); 
     57 
    5358   OUT.worldPos = IN.position; 
    54    // eye pos with linear depth 
    55    //OUT.worldPos = OUT.position; 
     59 
    5660   OUT.normal = IN.normal; 
    5761 
     
    6670  pix.col = tex2D(tex, IN.texCoord.xy); 
    6771  pix.pos = IN.worldPos * maxDepth; 
     72  pix.norm = IN.normal; 
    6873  pix.pos.w = IN.projPos.w; 
    69   pix.norm = IN.normal; 
    7074 
    7175  return pix; 
Note: See TracChangeset for help on using the changeset viewer.