Ember

adsf

Nov 29th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. {
  2.  
  3. vertexProgSource =
  4. "void main( \n"
  5. " float4 iPosition : POSITION, \n"
  6. " float3 normal : NORMAL, \n"
  7. " out float4 oPosition : POSITION, \n";
  8.  
  9. if (subBatch->vertexData->vertexDeclaration->findElementBySemantic(VES_DIFFUSE) != NULL) vertexProgSource +=
  10. " float4 iColor : COLOR, \n";
  11.  
  12. unsigned texNum = 0;
  13. for (unsigned short i = 0; i < subBatch->vertexData->vertexDeclaration->getElementCount(); ++i) {
  14. const VertexElement *el = subBatch->vertexData->vertexDeclaration->getElement(i);
  15. if (el->getSemantic() == VES_TEXTURE_COORDINATES) {
  16. String uvType = "";
  17. switch (el->getType()) {
  18. case VET_FLOAT1: uvType = "float"; break;
  19. case VET_FLOAT2: uvType = "float2"; break;
  20. case VET_FLOAT3: uvType = "float3"; break;
  21. case VET_FLOAT4: uvType = "float4"; break;
  22. }
  23.  
  24. vertexProgSource +=
  25. " " + uvType + " iUV" + StringConverter::toString(texNum) + " : TEXCOORD" + StringConverter::toString(texNum) + ", \n"
  26. " out " + uvType + " oUV" + StringConverter::toString(texNum) + " : TEXCOORD" + StringConverter::toString(texNum) + ", \n";
  27.  
  28. ++texNum;
  29. }
  30. }
  31.  
  32. vertexProgSource +=
  33. " out float oFog : FOG, \n"
  34. " out float4 oColor : COLOR, \n";
  35.  
  36. if (lightingEnabled) vertexProgSource +=
  37. " uniform float4 objSpaceLight, \n"
  38. " uniform float4 lightDiffuse, \n"
  39. " uniform float4 lightAmbient, \n";
  40.  
  41. if (fadeEnabled) vertexProgSource +=
  42. " uniform float3 camPos, \n";
  43.  
  44. vertexProgSource +=
  45. " uniform float4x4 worldViewProj, \n"
  46. " uniform float fadeGap, \n"
  47. " uniform float invisibleDist )\n"
  48. "{ \n";
  49.  
  50. if (lightingEnabled) {
  51. //Perform lighting calculations (no specular)
  52. vertexProgSource +=
  53. " float3 light = normalize(objSpaceLight.xyz - (iPosition.xyz * objSpaceLight.w)); \n"
  54. " float diffuseFactor = max(dot(normal, light), 0); \n";
  55. if (subBatch->vertexData->vertexDeclaration->findElementBySemantic(VES_DIFFUSE) != NULL)
  56. vertexProgSource += "oColor = (lightAmbient + diffuseFactor * lightDiffuse) * iColor; \n";
  57. else
  58. vertexProgSource += "oColor = (lightAmbient + diffuseFactor * lightDiffuse); \n";
  59. } else {
  60. if (subBatch->vertexData->vertexDeclaration->findElementBySemantic(VES_DIFFUSE) != NULL)
  61. vertexProgSource += "oColor = iColor; \n";
  62. else
  63. vertexProgSource += "oColor = float4(1, 1, 1, 1); \n";
  64. }
  65.  
  66. if (fadeEnabled) vertexProgSource +=
  67. //Fade out in the distance
  68. " float dist = distance(camPos.xz, iPosition.xz); \n"
  69. " oColor.a *= (invisibleDist - dist) / fadeGap; \n";
  70.  
  71. texNum = 0;
  72. for (unsigned short i = 0; i < subBatch->vertexData->vertexDeclaration->getElementCount(); ++i) {
  73. const VertexElement *el = subBatch->vertexData->vertexDeclaration->getElement(i);
  74. if (el->getSemantic() == VES_TEXTURE_COORDINATES) {
  75. vertexProgSource +=
  76. " oUV" + StringConverter::toString(texNum) + " = iUV" + StringConverter::toString(texNum) + "; \n";
  77. ++texNum;
  78. }
  79. }
  80.  
  81. vertexProgSource +=
  82. " oPosition = mul(worldViewProj, iPosition); \n"
  83. " oFog = oPosition.z; \n"
  84. "}";
  85. }
Advertisement
Add Comment
Please, Sign In to add comment