Changeset 3146


Ignore:
Timestamp:
11/20/08 10:12:28 (16 years ago)
Author:
mattausch
Message:

normal mapping hack not working yet. found problems with ssao if the geometry is not tesselated enough (especially with smoothed
normals: one can see the underlying tesselation!

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

Legend:

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

    r3128 r3146  
    77 
    88using namespace std; 
     9 
     10//#define USE_TEXTURE 
    911 
    1012 
     
    1820                                                ) 
    1921{ 
    20         vector<char *> substrings; 
     22        vector<string> triples; 
    2123 
    2224        char *next_token; 
     
    2527        char *pch = strtok_s(str + 1, " ", &next_token); 
    2628 
    27         while (pch != NULL) 
    28         { 
    29                 substrings.push_back(pch); 
     29        while (pch) 
     30        { 
     31                string s(pch); 
     32                //s += "\n", 
     33                triples.push_back(s); 
     34                 
    3035                pch = strtok_s(NULL, " ", &next_token);    
    3136        } 
     
    3540        vector<int> tIndices; 
    3641 
    37         for (size_t i = 0; i < substrings.size(); ++ i) 
    38         { 
     42        char seps[] = " /\t\n"; 
     43 
     44        for (size_t i = 0; i < triples.size(); ++ i) 
     45        { 
     46                static int dummy = 0; 
     47 
     48                size_t found; 
     49                found = triples[i].find_first_of(seps); 
     50                size_t prevfound = 0; 
    3951                // vertex, normal, texture indices 
    40                 char *str = strtok_s(substrings[i], "/", &next_token);     
    41                 int index = (int)strtol(str, NULL, 10) - 1; 
     52                string str = triples[i].substr(prevfound, found); 
     53 
     54                int index = (int)strtol(str.c_str(), NULL, 10) - 1; 
    4255 
    4356                int tIndex = index; 
    44                 int nIndex = index; 
    45  
    46                 str = strtok_s(substrings[i], "/", &next_token);           
    47  
    48                 if (str != NULL) 
    49                 { 
    50                         int idx = (int)strtol(str, NULL, 10) - 1; 
    51                         if (idx) tIndex = idx; 
    52                 } 
    53                 str = strtok_s(substrings[i], "/", &next_token);           
    54  
    55                 if (str != NULL) 
    56                 { 
    57                         int idx = (int)strtol(str, NULL, 10) - 1; 
    58                         if (idx) nIndex = idx; 
     57                int nIndex = index;      
     58                 
     59                prevfound = found; 
     60                found = triples[i].find_first_of(seps, found + 1);   
     61 
     62                if (found != string::npos) 
     63                { 
     64                        str = triples[i].substr(prevfound, found); 
     65 
     66                        int idx = (int)strtol(str.c_str(), NULL, 10) - 1; 
     67                        if (idx > 0) tIndex = idx; 
     68                } 
     69 
     70                if ((found + 1) < triples[i].size()) 
     71                { 
     72                        str = triples[i].substr(found + 1); 
     73 
     74                        int idx = (int)strtol(str.c_str(), NULL, 10) - 1; 
     75                        if (idx > 0) nIndex = idx; 
    5976                } 
    6077 
     
    84101                        faceVertices.push_back(vertices[indices[idx3]]); 
    85102 
     103 
    86104                        if (!normals.empty()) 
    87105                        { 
     106                                //if (dummy < 3) cout << nIndices[idx1] << " " << nIndices[idx2] << " " << nIndices[idx3] << endl; 
    88107                                faceNormals.push_back(normals[nIndices[idx1]]); 
    89108                                faceNormals.push_back(normals[nIndices[idx2]]); 
     
    92111                        else 
    93112                        { 
    94                                 // no face normals? 
    95                                 const SimpleTri tri(vertices[indices[idx1]], vertices[indices[idx2]], vertices[indices[idx3]]); 
     113                                // no face normals? => create normals 
     114                                const SimpleTri tri(vertices[indices[idx1]], 
     115                                                        vertices[indices[idx2]],  
     116                                                                        vertices[indices[idx3]]); 
    96117                                const SimpleVec n = tri.GetNormal(); 
    97118 
     
    101122                        } 
    102123 
     124                        ++ dummy; 
    103125                        if (!texcoords.empty()) 
    104126                        { 
     
    150172        for (int i = 0; i < numElements; ++ i) 
    151173        { 
    152 #if 0 
     174#if 1 
    153175                // convert to our camera system: change y and z 
    154176                geom->mVertices[i].x = faceVertices[i].x; 
     
    159181                geom->mNormals[i].y = -faceNormals[i].z; 
    160182                geom->mNormals[i].z = faceNormals[i].y; 
     183 
    161184#else 
    162185                geom->mVertices[i].x = faceVertices[i].x; 
     
    169192 
    170193#endif 
    171                 geom->mVertices[i].x += 470.398f; 
    172                 geom->mVertices[i].y += 240.364f; 
    173                 geom->mVertices[i].z += 182.5f; 
    174194 
    175195                if (i < geom->mTexcoordCount) 
     
    236256 
    237257        int line = 0; 
    238  
    239258        const int len = 10000; 
    240259        char str[len]; 
     
    242261        while (fgets(str, len, file) != NULL) 
    243262        { 
    244 //              if (1)//(line % 100) == 0) 
    245 //                      cout << "read line " << line << " " << str; 
    246                 switch (str[0])  
     263                switch (str[0]) 
    247264                { 
    248265                case 'v': // vertex or normal 
     
    262279                                default: 
    263280                                        sscanf(str + 1, "%f %f %f", &x, &y, &z); 
    264                                         vertices.push_back(SimpleVec(x, y, z)); 
     281                                        const float scale = 5e-3f; 
     282                                        vertices.push_back(SimpleVec(x * scale, y * scale, z* scale)); 
    265283                                        //cout <<"v " << x << " " << y << " "<< z << " "; 
    266284                                } 
     
    305323                        break; 
    306324                default: 
     325                        // throw away line 
    307326                        break; 
    308327                } 
     
    346365        //-- texture 
    347366 
    348         //int texId = -1; 
     367#ifdef USE_TEXTURE 
    349368        int texId = 0; 
     369#else 
     370        int texId = -1; 
     371#endif 
     372 
    350373        str.write(reinterpret_cast<char *>(&texId), sizeof(int)); 
    351374 
    352375        bool alphaTestEnabled = false; 
    353         bool cullFaceEnabled = false; 
    354         //bool cullFaceEnabled = true; 
     376        //bool cullFaceEnabled = false; 
     377        bool cullFaceEnabled = true; 
    355378 
    356379        str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); 
     
    368391                ambient.x = ambient.y = ambient.z = 0.2f; 
    369392                diffuse.x = diffuse.y = diffuse.z = 1.0f; 
    370                 spec.x   = spec.y   = spec.z   =  .0f; 
     393                spec.x    = spec.y    = spec.z    =  .0f; 
    371394                emm = spec; 
    372395 
     
    391414        //-- write textures 
    392415 
     416#ifdef USE_TEXTURE 
    393417        int textureCount = 1; 
    394         //int textureCount = 0; 
    395  
     418#else 
     419        int textureCount = 0; 
     420#endif 
    396421        ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); 
    397422 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp

    r3076 r3146  
    2222                exit(0); 
    2323        } 
    24  
     24        //std::cin.get(); 
    2525        cout << "conversion successful" << endl; 
    2626 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp

    r3128 r3146  
    147147 
    148148        bool alphaTestEnabled = false; 
    149         bool cullFaceEnabled = false; 
    150         //bool cullFaceEnabled = true; 
     149        //bool cullFaceEnabled = false; 
     150        bool cullFaceEnabled = true; 
    151151 
    152152        str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

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

    r3145 r3146  
    114114                        // create shape 
    115115                        Shape *shape = new Shape(geom, mat); 
    116  
    117116                        mShapes.push_back(shape); 
    118117 
     
    226225} 
    227226 
    228  
     227// mtt todo_ split that up 
    229228void ResourceManager::LoadShapes(igzstream &str) 
    230229{ 
     
    295294        if (mUseNormalMapping) 
    296295        { 
    297                 deferred->SetFragmentProgram(sNormalMappingVertexProgramMrt); 
     296                deferred->SetFragmentProgram(sNormalMappingFragmentProgramMrt); 
    298297                deferred->SetVertexProgram(sNormalMappingVertexProgramMrt); 
    299298        } 
     
    310309        deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0); 
    311310         
    312  
    313311        deferred->GetVertexProgramParameters()->SetModelMatrixParam(1); 
    314312        deferred->GetVertexProgramParameters()->SetOldModelMatrixParam(2); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp

    r3144 r3146  
    130130 
    131131 
     132        // provide the current view matrix: 
     133        // this is an automatic parameter that is updated each frame 
     134        normalMappingFragmentMrt->AddParameter("viewMatrix", 0); 
     135 
     136        // vertex program 
     137        normalMappingVertexMrt->AddParameter("viewMatrix", 0); 
     138        // needed for for ssao 
     139        normalMappingVertexMrt->AddParameter("modelMatrix", 1); 
     140        normalMappingVertexMrt->AddParameter("oldModelMatrix", 2); 
     141 
     142 
    132143        cout << "cg initialization successful" << endl; 
    133144} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3144 r3146  
    471471        //-- load some dynamic stuff 
    472472 
    473         resourceManager->mUseNormalMapping = true; 
     473        //resourceManager->mUseNormalMapping = true; 
    474474        //resourceManager->mUseNormalMapping = false; 
    475475 
    476         LoadModel("fisch.dem", dynamicObjects); 
     476        //LoadModel("fisch.dem", dynamicObjects); 
    477477        //LoadModel("hbuddha.dem", dynamicObjects); 
     478        //LoadModel("venusm.dem", dynamicObjects); 
     479        //LoadModel("objects.dem", dynamicObjects); 
     480        //LoadModel("toyplane2.dem", dynamicObjects); 
     481        LoadModel("elephal.dem", dynamicObjects); 
    478482 
    479483        resourceManager->mUseNormalMapping = false; 
     
    481485        buddha = dynamicObjects.back(); 
    482486         
     487        cout << "here3 " << buddha->GetWorldCenter() << " " << buddha->GetBoundingBox().Center() << endl; 
     488 
    483489        const Vector3 sceneCenter(470.398f, 240.364f, 182.5f); 
    484490         
     
    804810        ambient[2] = sunAmbient.z; 
    805811 
    806         // no tone mapping => scale 
    807         if (0)//!useToneMapping) 
    808         { 
    809                 float maxComponent = sunDiffuse.MaxComponent(); 
    810                 sunDiffuse /= maxComponent; 
    811         } 
    812  
    813812        diffuse[0] = sunDiffuse.x; 
    814813        diffuse[1] = sunDiffuse.y; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg

    r3137 r3146  
    4949        const float ne = nd.x * nd.y *nd.z * nd.w * weights.x; 
    5050 
    51 #if 1 
     51 
    5252        //////////// 
    5353        // depth filter => compute gradient difference 
     
    6565        for (int i = 0; i < 4; ++ i) 
    6666        { 
    67                 dd[i] = float4(depthVals[i * 2] + depthVals[i * 2 + 1]); 
     67                dd[i] = depthVals[i * 2] + depthVals[i * 2 + 1]; 
    6868        } 
    6969 
     
    8989        float4 s2 = tex2Dlod(colors, float4(width + rt * w, 0, 0)); 
    9090        float4 s3 = tex2Dlod(colors, float4(width + lb * w, 0, 0)); 
    91 #endif 
     91 
    9292 
    9393        //float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f; 
     
    9696        //float4 col = float4(de.x, de.x, de.x, 0); 
    9797        //float4 col = float4(w, w, w, 0); 
    98         //float4 col = centerColor; 
     98        //float4 col = float4(centerNormal * 0.5f + float3(0.5f), 0); 
     99        //float4 col = float4(centerNormal, 0); 
    99100        // push through the current depth 
    100101        col.w = centerDepth.x; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg

    r3144 r3146  
    8686 
    8787 
    88 /**************************************************************/ 
    89 /* Shader computing the MRT output for normal mapped geoemtry */ 
    90 /**************************************************************/ 
     88/******************************************************************/ 
     89/*   Shader computing the MRT output for normal mapped geometry  */ 
     90/******************************************************************/ 
    9191 
    9292 
     
    126126        // compute tangent space - world space transform which is the transpose, 
    127127        // as it is the inverse of a rotation matrix  
    128         float3x3 tangToWorldTrafo = transpose(float3x3(IN.tangent, IN.bitangent, IN.normal)); 
     128        float3x3 tangToWorldTrafo = transpose(float3x3(IN.tangent.xyz, IN.bitangent.xyz, IN.normal.xyz)); 
    129129        const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz; 
    130130        pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm); 
     
    136136pixel frag(fragin IN, 
    137137                   uniform float4x4 viewMatrix, 
    138                    uniform sampler2D normalMap: TEXUNIT1) 
     138                   uniform sampler2D normalMap: TEXUNIT0) 
    139139{ 
    140140        pixel pix; 
    141141        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 
    142142        pix.color = glstate.material.diffuse + glstate.material.emission; 
    143         // save world space normal in rt => transform back into world space by 
    144         // multiplying with inverse view. since transforming normal with T means to  
    145         // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view) 
    146         pix.normal = mul(transpose(viewMatrix), IN.normal).xyz; 
     143         
    147144        // eye space depth 
    148145        pix.color.w = length(IN.eyePos.xyz); 
     
    165162        const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz; 
    166163        pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm); 
    167  
     164        pix.normal = tangentSpaceNorm; 
    168165        return pix; 
    169166} 
Note: See TracChangeset for help on using the changeset viewer.