Changeset 3153


Ignore:
Timestamp:
11/21/08 17:43:49 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
8 edited

Legend:

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

    r3152 r3153  
    8282        // convert the triangles to geometry 
    8383        geom->mVertexCount = numElements; 
     84        geom->mTexcoordCount = numElements; 
     85 
    8486        geom->mVertices = new SimpleVec[numElements]; 
    8587        geom->mNormals = new SimpleVec[numElements]; 
     
    9496        { 
    9597                sscanf(str, "%f %f %f %f %f %f %f %f %f %f %f",  
    96                        &vtx.x, &vtx.z, &vtx.y,  
    97                            &normal.x, &normal.z, &normal.y,  
     98                       &vtx.x, &vtx.y, &vtx.z,  
     99                           &normal.x, &normal.y, &normal.z,  
    98100                           &tex.first, &tex.second, 
    99101                           &tangent.x, &tangent.y, &tangent.z); 
    100102 
    101103                const float scale = 0.05f; 
    102                 vtx.x *= scale; 
    103                 vtx.y *= scale; 
    104                 vtx.z *= scale; 
    105  
    106                 geom->mVertices[line] = vtx; 
    107                 geom->mNormals[line] = normal; 
     104                 
     105                geom->mVertices[line].x = vtx.x * scale; 
     106                geom->mVertices[line].y = vtx.z * scale; 
     107                geom->mVertices[line].z = vtx.y * scale; 
     108         
     109                geom->mNormals[line].x = normal.x; 
     110                geom->mNormals[line].y = normal.z; 
     111                geom->mNormals[line].z = normal.y; 
     112 
     113                geom->mTangents[line].x = tangent.x; 
     114                geom->mTangents[line].y = tangent.z; 
     115                geom->mTangents[line].z = tangent.y; 
     116 
    108117                geom->mTexcoords[line] = tex; 
    109                 geom->mTangents[line] = tangent; 
    110  
     118 
     119                static int dummy = 0; 
     120 
     121                if (dummy ++ < 5) cout << "tangent: " << geom->mTangents[line] << endl; 
    111122                ++ line; 
    112123        } 
     
    134145 
    135146        if (texCoordCount) 
     147        { 
    136148                str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2); 
    137          
     149        } 
     150 
    138151 
    139152        /////// 
     
    163176 
    164177                ambient.x = ambient.y = ambient.z = 0.2f; 
    165                 diffuse.x = diffuse.y = diffuse.z = 1.0f; 
     178                diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f; 
    166179                spec.x   = spec.y   = spec.z   =  .0f; 
    167180                emm = spec; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/main.cpp

    r3107 r3153  
    2222                exit(0); 
    2323        } 
    24  
     24         
     25        std::cin.get(); 
    2526        cout << "conversion successful" << endl; 
    2627 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp

    r3127 r3153  
    8282        { 
    8383                for (int i = 0; i < mNumVertices; ++ i) 
     84                { 
     85                        Vector3 tangent = Normalize(mTangents[i]); 
     86                        Vector3 normal =  Normalize(mNormals[i]); 
     87 
     88                        float dotProd = DotProd(tangent,normal); 
     89 
     90                        tangent -= normal * dotProd; 
     91                        tangent = Normalize(tangent); 
     92 
     93                        //mTangents[i] = tangent; 
     94                        mTangents[i] = Vector3(0,1,0);//tangent * 0.5f + Vector3(0.5f); 
     95                } 
     96 
     97                for (int i = 0; i < mNumVertices; ++ i) 
    8498                        ((Vector3 *)data)[mNumVertices * 2 + i] = mTangents[i]; 
    8599 
     
    111125        if (mTangents) 
    112126        { 
     127                cout << "dotprods: " << endl; 
     128 
     129                for (int i = 0; i < 1000; ++ i) 
     130                { 
     131                        //cout << mTangents[i] << " " << mNormals[i] << " " << DotProd(Normalize(mTangents[i]), Normalize(mNormals[i])) << endl; 
     132                        float d = fabs(DotProd(Normalize(mTangents[i]), Normalize(mNormals[i]))); 
     133                        if (d > 0.01) cout << d << " "; 
     134                        //cout << d << " "; 
     135                } 
     136                cout << endl; 
     137         
    113138                glColorPointer(3, GL_FLOAT, 0, (char *)NULL + currentPVbo); 
    114139                currentPVbo += mNumVertices * sizeof(Vector3); 
     
    133158{ 
    134159        if (mHasTangents) 
     160        { 
     161                cout<<"x"; 
    135162                glEnableClientState(GL_COLOR_ARRAY); 
    136  
     163        } 
    137164        if (state->GetCurrentVboId() != mVboId) 
    138165        { 
     
    145172                if (mHasTangents) 
    146173                { 
    147                         glColorPointer(3, GL_FLOAT, 0, (char *)NULL + mNumVertices * sizeof(Vector3)); 
     174                        //glClientActiveTextureARB(GL_TEXTURE1_ARB); 
     175                        //glTexCoordPointer(2, GL_FLOAT, (char *)NULL + mNumVertices * sizeof(Vector3)); 
     176 
     177                        glColorPointer(3, GL_FLOAT, 0, (char *)NULL + mNumVertices * 2 * sizeof(Vector3)); 
    148178                        currentPointer = mNumVertices * 3 * sizeof(Vector3); 
     179                        //glClientActiveTextureARB(GL_TEXTURE0_ARB); 
     180 
    149181                } 
    150182                else 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r3146 r3153  
    267267                } 
    268268 
    269                 if (1)//frag != mCurrentFragmentProgram) 
     269                if (frag != mCurrentFragmentProgram) 
    270270                {                        
    271271                        mCurrentFragmentProgram = frag; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3152 r3153  
    344344        if (str.eof()) return NULL; 
    345345 
    346         //cout << "vertexcount: " << vertexCount << endl; 
    347  
    348346        vertices = new Vector3[vertexCount]; 
    349347    str.read(reinterpret_cast<char *>(vertices), sizeof(Vector3) * vertexCount); 
     
    367365        str.read(reinterpret_cast<char *>(&texCoordCount), sizeof(int)); 
    368366 
    369         cout<<"here3" << texCoordCount << endl; 
     367 
    370368        if (texCoordCount) 
    371369        { 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3152 r3153  
    477477        //LoadModel("hbuddha.dem", dynamicObjects); 
    478478        //LoadModel("venusm.dem", dynamicObjects); 
    479         LoadModel("camel.dem", dynamicObjects); 
     479        //LoadModel("camel.dem", dynamicObjects); 
    480480        //LoadModel("toyplane2.dem", dynamicObjects); 
    481481        //LoadModel("elephal.dem", dynamicObjects); 
     
    485485        buddha = dynamicObjects.back(); 
    486486         
    487         cout << "here3 " << buddha->GetWorldCenter() << " " << buddha->GetBoundingBox().Center() << endl; 
    488  
    489487        const Vector3 sceneCenter(470.398f, 240.364f, 182.5f); 
    490488         
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3137 r3153  
    7474        // store scaled view vector so wie don't have to normalize for e.g., ssao 
    7575        OUT.color.w = color.w;// / length(IN.view); 
    76          
     76        OUT.color = color; 
    7777        return OUT; 
    7878} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg

    r3152 r3153  
    1919        float4 texCoord: TEXCOORD0;     
    2020 
    21         float4 tangent: TEXCOORD6;   
    2221         // eye position 
    2322        float4 eyePos: TEXCOORD1; 
     
    2625        float4 worldPos: TEXCOORD3; 
    2726        float4 oldWorldPos: TEXCOORD4; 
    28         float4 bitangent: TEXCOORD5; 
     27        float4 tangent: TEXCOORD5;   
     28        float4 bitangent: TEXCOORD6; 
    2929}; 
    3030 
     
    3333struct fragin 
    3434{ 
    35         float4 tangent: TEXCOORD6;   
    3635        float4 texCoord: TEXCOORD0;     
    3736 
     
    4241        float4 worldPos: TEXCOORD3; 
    4342        float4 oldWorldPos: TEXCOORD4; 
    44         float4 bitangent: TEXCOORD5; 
     43        float4 tangent: TEXCOORD5;   
     44        float4 bitangent: TEXCOORD6; 
    4545}; 
    4646 
     
    6464        vtxout OUT; 
    6565 
    66         OUT.tangent = IN.color; 
     66        //float4 tangent =  float4(IN.color.xyz * 2.0f - 1.0f, 1.0f); 
     67        //float4 tangent = float4(1,0,0,1); 
     68        float4 tangent = IN.color; 
     69 
     70        //float4 tangent = IN.color; 
    6771        OUT.texCoord = IN.texCoord; 
    6872 
     
    7781        // the normal has to be correctly transformed with the inverse transpose 
    7882        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 
    79         OUT.tangent = mul(glstate.matrix.invtrans.modelview[0], IN.color);  
     83        OUT.tangent = tangent;//mul(glstate.matrix.invtrans.modelview[0], tangent);  
    8084 
    81         OUT.bitangent = float4(cross(IN.color.xyz, IN.normal.xyz), 1); 
     85        //OUT.bitangent = float4(cross(IN.color.xyz, IN.normal.xyz), 1); 
     86        //OUT.bitangent = float4(cross(OUT.tangent.xyz, OUT.normal.xyz), 1); 
     87        OUT.bitangent = float4(cross(OUT.normal.xyz, tangent.xyz), 1); 
    8288 
    8389        return OUT; 
     
    8995/*   Shader computing the MRT output for normal mapped geometry   */ 
    9096/******************************************************************/ 
     97 
     98pixel frag(fragin IN, 
     99                   uniform float4x4 viewMatrix, 
     100                   uniform sampler2D normalMap: TEXUNIT0) 
     101{ 
     102        pixel pix; 
     103        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 
     104        pix.color = glstate.material.diffuse + glstate.material.emission; 
     105         
     106        // eye space depth 
     107        pix.color.w = length(IN.eyePos.xyz); 
     108        // the scene entity id 
     109        //pix.id = glstate.fog.color.xyz; 
     110        // the offset to the world pos from old frame 
     111        pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz; 
     112 
     113        // compute tanget space in world space => transform basis vectors back into world space by 
     114        // multiplying with inverse view. since transforming normal with T means to  
     115        // multiply with the inverse transpose of T, we multiple with  
     116        // Transp(Inv(Inv(view))) = Transp(view) 
     117        float3 normal = mul(transpose(viewMatrix), IN.normal).xyz; 
     118        float3 tangent = mul(transpose(viewMatrix), IN.tangent).xyz; 
     119        float3 bitangent = mul(transpose(viewMatrix), IN.bitangent).xyz; 
     120 
     121        // compute tangent space - world space transform which is the transpose, 
     122        // as it is the inverse of a rotation matrix  
     123        float3x3 tangToWorldTrafo = transpose(float3x3(IN.tangent.xyz, IN.bitangent.xyz, IN.normal.xyz)); 
     124        const float3 tangentSpaceNorm = normalize(tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz); 
     125        //const float3 tangentSpaceNorm = tex2D(normalMap, IN.texCoord.xy).xyz; 
     126 
     127        pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm); 
     128        //pix.color.xyz = float3(abs(dot(tangent.xyz, normal.xyz))); 
     129        //pix.color.xyz = float3(abs(dot(normalize(IN.normal.xyz), normalize(IN.tangent.xyz)))); 
     130        pix.color.xyz = float3(abs(dot(IN.normal.xyz, IN.tangent.xyz))); 
     131        //pix.color.xyz = normal.xyz; 
     132        pix.color.xyz = IN.tangent.xyz; 
     133 
     134        return pix; 
     135} 
     136 
    91137 
    92138 
     
    133179} 
    134180 
    135  
    136 pixel frag(fragin IN, 
    137                    uniform float4x4 viewMatrix, 
    138                    uniform sampler2D normalMap: TEXUNIT0) 
    139 { 
    140         pixel pix; 
    141         // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 
    142         pix.color = glstate.material.diffuse + glstate.material.emission; 
    143          
    144         // eye space depth 
    145         pix.color.w = length(IN.eyePos.xyz); 
    146         // the scene entity id 
    147         //pix.id = glstate.fog.color.xyz; 
    148         // the offset to the world pos from old frame 
    149         pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz; 
    150  
    151         // compute tanget space in world space => transform basis vectors back into world space by 
    152         // multiplying with inverse view. since transforming normal with T means to  
    153         // multiply with the inverse transpose of T, we multiple with  
    154         // Transp(Inv(Inv(view))) = Transp(view) 
    155         float3 normal = mul(transpose(viewMatrix), IN.normal).xyz; 
    156         float3 tangent = mul(transpose(viewMatrix), IN.tangent).xyz; 
    157         float3 bitangent = mul(transpose(viewMatrix), IN.bitangent).xyz; 
    158  
    159         // compute tangent space - world space transform which is the transpose, 
    160         // as it is the inverse of a rotation matrix  
    161         float3x3 tangToWorldTrafo = transpose(float3x3(IN.tangent.xyz, IN.bitangent.xyz, IN.normal.xyz)); 
    162         const float3 tangentSpaceNorm = normalize(tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz); 
    163         //const float3 tangentSpaceNorm = tex2D(normalMap, IN.texCoord.xy).xyz; 
    164  
    165         pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm); 
    166         //pix.color.xyz = tangentSpaceNorm; 
    167  
    168         return pix; 
    169 } 
Note: See TracChangeset for help on using the changeset viewer.