Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- vertexProgSource =
- "void main( \n"
- " float4 iPosition : POSITION, \n"
- " float3 normal : NORMAL, \n"
- " out float4 oPosition : POSITION, \n";
- if (subBatch->vertexData->vertexDeclaration->findElementBySemantic(VES_DIFFUSE) != NULL) vertexProgSource +=
- " float4 iColor : COLOR, \n";
- unsigned texNum = 0;
- for (unsigned short i = 0; i < subBatch->vertexData->vertexDeclaration->getElementCount(); ++i) {
- const VertexElement *el = subBatch->vertexData->vertexDeclaration->getElement(i);
- if (el->getSemantic() == VES_TEXTURE_COORDINATES) {
- String uvType = "";
- switch (el->getType()) {
- case VET_FLOAT1: uvType = "float"; break;
- case VET_FLOAT2: uvType = "float2"; break;
- case VET_FLOAT3: uvType = "float3"; break;
- case VET_FLOAT4: uvType = "float4"; break;
- }
- vertexProgSource +=
- " " + uvType + " iUV" + StringConverter::toString(texNum) + " : TEXCOORD" + StringConverter::toString(texNum) + ", \n"
- " out " + uvType + " oUV" + StringConverter::toString(texNum) + " : TEXCOORD" + StringConverter::toString(texNum) + ", \n";
- ++texNum;
- }
- }
- vertexProgSource +=
- " out float oFog : FOG, \n"
- " out float4 oColor : COLOR, \n";
- if (lightingEnabled) vertexProgSource +=
- " uniform float4 objSpaceLight, \n"
- " uniform float4 lightDiffuse, \n"
- " uniform float4 lightAmbient, \n";
- if (fadeEnabled) vertexProgSource +=
- " uniform float3 camPos, \n";
- vertexProgSource +=
- " uniform float4x4 worldViewProj, \n"
- " uniform float fadeGap, \n"
- " uniform float invisibleDist )\n"
- "{ \n";
- if (lightingEnabled) {
- //Perform lighting calculations (no specular)
- vertexProgSource +=
- " float3 light = normalize(objSpaceLight.xyz - (iPosition.xyz * objSpaceLight.w)); \n"
- " float diffuseFactor = max(dot(normal, light), 0); \n";
- if (subBatch->vertexData->vertexDeclaration->findElementBySemantic(VES_DIFFUSE) != NULL)
- vertexProgSource += "oColor = (lightAmbient + diffuseFactor * lightDiffuse) * iColor; \n";
- else
- vertexProgSource += "oColor = (lightAmbient + diffuseFactor * lightDiffuse); \n";
- } else {
- if (subBatch->vertexData->vertexDeclaration->findElementBySemantic(VES_DIFFUSE) != NULL)
- vertexProgSource += "oColor = iColor; \n";
- else
- vertexProgSource += "oColor = float4(1, 1, 1, 1); \n";
- }
- if (fadeEnabled) vertexProgSource +=
- //Fade out in the distance
- " float dist = distance(camPos.xz, iPosition.xz); \n"
- " oColor.a *= (invisibleDist - dist) / fadeGap; \n";
- texNum = 0;
- for (unsigned short i = 0; i < subBatch->vertexData->vertexDeclaration->getElementCount(); ++i) {
- const VertexElement *el = subBatch->vertexData->vertexDeclaration->getElement(i);
- if (el->getSemantic() == VES_TEXTURE_COORDINATES) {
- vertexProgSource +=
- " oUV" + StringConverter::toString(texNum) + " = iUV" + StringConverter::toString(texNum) + "; \n";
- ++texNum;
- }
- }
- vertexProgSource +=
- " oPosition = mul(worldViewProj, iPosition); \n"
- " oFog = oPosition.z; \n"
- "}";
- }
Advertisement
Add Comment
Please, Sign In to add comment