Changeset 3126


Ignore:
Timestamp:
11/13/08 18:48:41 (16 years ago)
Author:
mattausch
Message:

started to include normal mapping

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

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj

    r3110 r3126  
    764764                        </File> 
    765765                        <File 
     766                                RelativePath=".\src\shaders\normalMapping.cg" 
     767                                > 
     768                        </File> 
     769                        <File 
    766770                                RelativePath=".\src\shaderenv.h" 
    767771                                > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp

    r3021 r3126  
    2323                                   Texcoord2 *texcoords, 
    2424                                   int numVertices, 
    25                                    bool delData): 
     25                                   bool delData, 
     26                                   Vector3 *tangents): 
    2627mVertices(vertices),  
    2728mNormals(normals),  
    2829mTexCoords(texcoords), 
     30mTangents(tangents), 
    2931mNumVertices(numVertices),  
    3032mVboId(-1) 
    3133{ 
    3234        mHasTexture = (mTexCoords != NULL); 
     35        mHasTangents = (mTangents != NULL); 
    3336 
    3437        Prepare(); 
     
    3942                DEL_ARRAY_PTR(mNormals); 
    4043                DEL_ARRAY_PTR(mTexCoords); 
     44                DEL_ARRAY_PTR(mTangents); 
    4145        } 
    4246} 
     
    4852        DEL_ARRAY_PTR(mNormals); 
    4953        DEL_ARRAY_PTR(mTexCoords); 
     54        DEL_ARRAY_PTR(mTangents); 
    5055 
    5156        // delete vbo 
     
    6065        int dataSize = mNumVertices * 6; 
    6166 
    62         if (mTexCoords) 
    63                 dataSize += mNumVertices * 2; 
     67        if (mTexCoords) dataSize += mNumVertices * 2; 
    6468         
     69        if (mTangents) dataSize += mNumVertices * 3; 
     70 
    6571        float *data = new float[dataSize]; 
    6672 
     
    7177        } 
    7278 
     79        float *currentPData = data + mNumVertices * 6; 
     80 
     81        if (mTangents) 
     82        { 
     83                for (int i = 0; i < mNumVertices; ++ i) 
     84                        ((Vector3 *)data)[mNumVertices * 3 + i] = mTangents[i]; 
     85 
     86                currentPData += mNumVertices * 3; 
     87        } 
     88 
    7389        if (mTexCoords) 
    7490        { 
    7591                for (int i = 0; i < mNumVertices; ++ i) 
    76                         ((Texcoord2 *)data)[mNumVertices * 3 + i] = mTexCoords[i]; 
     92                        ((Texcoord2 *)currentPData)[i] = mTexCoords[i]; 
    7793        } 
     94 
    7895 
    7996        glGenBuffersARB(1, &mVboId); 
    8097        glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 
    8198 
     99        int currentPVbo = 0; 
     100 
    82101        glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 
    83         glNormalPointer(GL_FLOAT, 0, (char *)NULL + mNumVertices * sizeof(Vector3)); 
     102 
     103        currentPVbo += mNumVertices * sizeof(Vector3); 
     104        glNormalPointer(GL_FLOAT, 0, (char *)NULL + currentPVbo); 
     105 
     106        currentPVbo += mNumVertices * 2 * sizeof(Vector3); 
     107 
     108        if (mTangents) 
     109        { 
     110                glColorPointer(3, GL_FLOAT, 0, (char *)NULL + currentPVbo); 
     111                currentPVbo += mNumVertices * sizeof(Vector3); 
     112        } 
    84113 
    85114        if (mTexCoords) 
    86115        { 
    87                 glTexCoordPointer(2, GL_FLOAT, 0, (char *)NULL + 2 * mNumVertices * sizeof(Vector3)); 
     116                glTexCoordPointer(2, GL_FLOAT, 0, (char *)NULL + currentPVbo); 
    88117        } 
    89118 
    90         glBufferDataARB(GL_ARRAY_BUFFER_ARB,  
    91                             dataSize * sizeof(float),  
    92                             (float *)data,  
    93                                         GL_STATIC_DRAW_ARB); 
     119        glBufferDataARB(GL_ARRAY_BUFFER_ARB, dataSize * sizeof(float),  
     120                            (float *)data, GL_STATIC_DRAW_ARB); 
    94121 
    95122        glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.h

    r2980 r3126  
    2121 
    2222public: 
    23         /** Constructs a geometry from the given data.  
    24                 The vertices are interpreted as triangles. 
    25  
    26                 If delData is true, the vertex / normal / texture is deleted when 
    27                 after it was transferred into a vbo 
     23        /** Constructs a geometry from the given data. The vertices are  
     24                interpreted as triangles. If delData is true, the  
     25                vertex / normal / texture is deleted when after it was  
     26                transferred into a vbo 
    2827        */ 
    2928        Geometry(Vector3 *vertices,  
     
    3130                         Texcoord2 *texcoords,  
    3231                         int numVertices,  
    33                          bool delData); 
    34  
     32                         bool delData, 
     33                         Vector3 *tangents); 
     34        /** Detructor destroying the opengl resources. 
     35        */ 
    3536        ~Geometry(); 
    3637        /** Render the geometry 
    3738        */ 
    3839        void Render(RenderState *state); 
    39  
    40         int GetNumTriangles() const { return mNumVertices / 3; } 
    41  
     40        /** Return bounding box. 
     41        */ 
     42        const AxisAlignedBox3& GetBoundingBox() const; 
     43        /** Returns the number of triangles in this geometry. 
     44        */ 
     45        inline int GetNumTriangles() const { return mNumVertices / 3; } 
     46        /** Returns true if this geometry has a texture 
     47        */ 
    4248        inline bool HasTexture() const { return mHasTexture; } 
    4349         
    44         const AxisAlignedBox3& GetBoundingBox() const; 
    4550 
    4651protected: 
    47  
     52        /** Calculates the bounding box from the vertices. 
     53        */ 
    4854        void CalcBoundingBox(); 
    4955        /** Prepare vbos for rendering 
     
    5864        Vector3 *mNormals; 
    5965 
     66        Vector3 *mTangents; 
     67 
    6068        Texcoord2 *mTexCoords; 
    6169 
     
    6775 
    6876        bool mHasTexture; 
     77 
     78        bool mHasTangents; 
    6979}; 
    7080 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r3117 r3126  
    236236 
    237237 
     238        // set texture for fixed function rendering 
     239        if (tex) 
     240        { 
     241                if (mCurrentTexId != tex->GetId()) 
     242                { 
     243                        tex->Bind(); 
     244                        mCurrentTexId = tex->GetId(); 
     245                } 
     246        } 
     247        else 
     248        { 
     249                mCurrentTexId = -1; 
     250                glBindTexture(GL_TEXTURE_2D, 0); 
     251        } 
     252 
     253 
    238254        ////////////////// 
    239255        //-- fragment and vertex programs 
     
    292308                } 
    293309        } 
    294  
    295         if (!mFragmentProgramEnabled) 
    296         { 
    297                 // set texture for fixed function rendering 
    298                 if (tex) 
    299                 { 
    300                         if (mCurrentTexId != tex->GetId()) 
    301                         { 
    302                                 tex->Bind(); 
    303                                 mCurrentTexId = tex->GetId(); 
    304                         } 
    305                 } 
    306                 else 
    307                 { 
    308                         mCurrentTexId = -1; 
    309                         glBindTexture(GL_TEXTURE_2D, 0); 
    310                 } 
    311         } 
    312310} 
    313311 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3115 r3126  
    292292 
    293293        if (deferred->GetTexture()) 
    294         { 
    295294                deferred->SetFragmentProgram(sDefaultFragmentTexProgramMrt); 
    296                 deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0); 
    297                 deferred->GetFragmentProgramParameters()->SetTexture(1, tech->GetTexture()->GetId()); 
    298         }        
    299295        else 
    300         { 
    301296                deferred->SetFragmentProgram(sDefaultFragmentProgramMrt); 
    302                 deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0); 
    303         } 
     297 
     298        deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0); 
    304299 
    305300        deferred->SetVertexProgram(sDefaultVertexProgramMrt); 
     
    361356        } 
    362357 
    363         return new Geometry(vertices, normals, texcoords, vertexCount, true); 
     358        return new Geometry(vertices, normals, texcoords, vertexCount, true, NULL); 
    364359        //return new Geometry(vertices, normals, texcoords, vertexCount, false); 
    365360} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp

    r3071 r3126  
    4141        cout << "number of triangles in box: " << (int)triangles.size() << endl; 
    4242 
    43         Geometry *geom = new Geometry(vertices, normals, NULL, 36, false); 
     43        Geometry *geom = new Geometry(vertices, normals, NULL, 36, false, NULL); 
    4444 
    4545        Shape *shape = new Shape(geom, mat); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp

    r3116 r3126  
    100100 
    101101        // add a texture parameter 
    102         fragmentProgMrtTex->AddParameter("tex", 1); 
     102        //fragmentProgMrtTex->AddParameter("tex", 1); 
    103103 
    104104 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3123 r3126  
    124124                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    125125                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 
    126                 ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y)); 
    127                 //ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f); 
     126                //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y)); 
     127                ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f); 
    128128        } 
    129129 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r3118 r3126  
    7575 
    7676pixel fragtex(fragin IN,  
    77                           uniform sampler2D tex, 
     77                          uniform sampler2D tex: TEXUNIT0, 
    7878                          uniform float4x4 viewMatrix 
    7979                          ) 
Note: See TracChangeset for help on using the changeset viewer.