- Timestamp:
- 11/21/08 17:43:49 (16 years ago)
- 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 82 82 // convert the triangles to geometry 83 83 geom->mVertexCount = numElements; 84 geom->mTexcoordCount = numElements; 85 84 86 geom->mVertices = new SimpleVec[numElements]; 85 87 geom->mNormals = new SimpleVec[numElements]; … … 94 96 { 95 97 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, 98 100 &tex.first, &tex.second, 99 101 &tangent.x, &tangent.y, &tangent.z); 100 102 101 103 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 108 117 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; 111 122 ++ line; 112 123 } … … 134 145 135 146 if (texCoordCount) 147 { 136 148 str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2); 137 149 } 150 138 151 139 152 /////// … … 163 176 164 177 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; 166 179 spec.x = spec.y = spec.z = .0f; 167 180 emm = spec; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/main.cpp
r3107 r3153 22 22 exit(0); 23 23 } 24 24 25 std::cin.get(); 25 26 cout << "conversion successful" << endl; 26 27 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp
r3127 r3153 82 82 { 83 83 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) 84 98 ((Vector3 *)data)[mNumVertices * 2 + i] = mTangents[i]; 85 99 … … 111 125 if (mTangents) 112 126 { 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 113 138 glColorPointer(3, GL_FLOAT, 0, (char *)NULL + currentPVbo); 114 139 currentPVbo += mNumVertices * sizeof(Vector3); … … 133 158 { 134 159 if (mHasTangents) 160 { 161 cout<<"x"; 135 162 glEnableClientState(GL_COLOR_ARRAY); 136 163 } 137 164 if (state->GetCurrentVboId() != mVboId) 138 165 { … … 145 172 if (mHasTangents) 146 173 { 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)); 148 178 currentPointer = mNumVertices * 3 * sizeof(Vector3); 179 //glClientActiveTextureARB(GL_TEXTURE0_ARB); 180 149 181 } 150 182 else -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r3146 r3153 267 267 } 268 268 269 if ( 1)//frag != mCurrentFragmentProgram)269 if (frag != mCurrentFragmentProgram) 270 270 { 271 271 mCurrentFragmentProgram = frag; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3152 r3153 344 344 if (str.eof()) return NULL; 345 345 346 //cout << "vertexcount: " << vertexCount << endl;347 348 346 vertices = new Vector3[vertexCount]; 349 347 str.read(reinterpret_cast<char *>(vertices), sizeof(Vector3) * vertexCount); … … 367 365 str.read(reinterpret_cast<char *>(&texCoordCount), sizeof(int)); 368 366 369 cout<<"here3" << texCoordCount << endl; 367 370 368 if (texCoordCount) 371 369 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3152 r3153 477 477 //LoadModel("hbuddha.dem", dynamicObjects); 478 478 //LoadModel("venusm.dem", dynamicObjects); 479 LoadModel("camel.dem", dynamicObjects);479 //LoadModel("camel.dem", dynamicObjects); 480 480 //LoadModel("toyplane2.dem", dynamicObjects); 481 481 //LoadModel("elephal.dem", dynamicObjects); … … 485 485 buddha = dynamicObjects.back(); 486 486 487 cout << "here3 " << buddha->GetWorldCenter() << " " << buddha->GetBoundingBox().Center() << endl;488 489 487 const Vector3 sceneCenter(470.398f, 240.364f, 182.5f); 490 488 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3137 r3153 74 74 // store scaled view vector so wie don't have to normalize for e.g., ssao 75 75 OUT.color.w = color.w;// / length(IN.view); 76 76 OUT.color = color; 77 77 return OUT; 78 78 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg
r3152 r3153 19 19 float4 texCoord: TEXCOORD0; 20 20 21 float4 tangent: TEXCOORD6;22 21 // eye position 23 22 float4 eyePos: TEXCOORD1; … … 26 25 float4 worldPos: TEXCOORD3; 27 26 float4 oldWorldPos: TEXCOORD4; 28 float4 bitangent: TEXCOORD5; 27 float4 tangent: TEXCOORD5; 28 float4 bitangent: TEXCOORD6; 29 29 }; 30 30 … … 33 33 struct fragin 34 34 { 35 float4 tangent: TEXCOORD6;36 35 float4 texCoord: TEXCOORD0; 37 36 … … 42 41 float4 worldPos: TEXCOORD3; 43 42 float4 oldWorldPos: TEXCOORD4; 44 float4 bitangent: TEXCOORD5; 43 float4 tangent: TEXCOORD5; 44 float4 bitangent: TEXCOORD6; 45 45 }; 46 46 … … 64 64 vtxout OUT; 65 65 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; 67 71 OUT.texCoord = IN.texCoord; 68 72 … … 77 81 // the normal has to be correctly transformed with the inverse transpose 78 82 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); 80 84 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); 82 88 83 89 return OUT; … … 89 95 /* Shader computing the MRT output for normal mapped geometry */ 90 96 /******************************************************************/ 97 98 pixel 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 91 137 92 138 … … 133 179 } 134 180 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 depth145 pix.color.w = length(IN.eyePos.xyz);146 // the scene entity id147 //pix.id = glstate.fog.color.xyz;148 // the offset to the world pos from old frame149 pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz;150 151 // compute tanget space in world space => transform basis vectors back into world space by152 // multiplying with inverse view. since transforming normal with T means to153 // multiply with the inverse transpose of T, we multiple with154 // 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 matrix161 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.