// global relevant parameters float4x4 view : View; float4x4 proj : Projection; float4x4 world : World; float4x4 wvp : WorldViewProjection; float4x4 viewInverse : ViewInverse; float3 pLightPos[16]; bool pLightOn[16]; float3 pLightDiffuse[16]; float3 pLightSpecular[16]; float pLightNear[16]; float pLightFar[16]; float4 ambientColor : Ambient = { 0.1f, 0.1f, 0.1f, 1.0f }; float4 diffuseColor : Diffuse = { 0.5f, 0.5f, 0.5f, 1.0f }; float4 specularColor : Specular = { 1.0f, 1.0f, 1.0f, 1.0f }; float shininess : SpecularPower = 24.0f; texture diffuseTexture : Diffuse <...>; sampler DiffuseTextureSampler = sampler_state {...}; texture bumpTexture : Specular <...>; sampler BumpTextureSampler = sampler_state {...}; //local relevant variables: float4 diffuseTex = tex2D(DiffuseTextureSampler,input.texCoord); float3 normalVector = (2.0 * tex2D(BumpTextureSampler, input.texCoord).rgb) - 1.0; normalVector = normalize(normalVector); float4 ambientCol = ambientColor; float4 diffuseCol = { 0, 0, 0, 1 }; float4 specularCol = { 0, 0, 0, 1 }; // variable "input" is of type: struct EngineVertexToPixel { float4 pos : POSITION; //transformed vertex pos float2 texCoord : TEXCOORD0; // tex uv float3 wPos : TEXCOORD1; // untransformed "naked" pos float3 viewVec : TEXCOORD2; // view vector (bumpmapping) float3x3 tangentMatrix : TEXCOORD3; // worldspace-to-tangentspace matrix }; //BROKEN CODE: //inside the pixel shader for(int i=0;i<16;i+=1) //pLights { if(pLightOn[i]) // if the light is activated { float dist = sqrt( pow(pLightPos[i].x-input.wPos.x,2)+pow(pLightPos[i].y-input.wPos.y,2)+pow(pLightPos[i].z-input.wPos.z,2) ); // light-to-pixel distance if(dist < pLightFar[i]) // <<--PROBLEM--<< checks to see if the distance is smaller than the max fadeout for the light { //bunch of light stuff float3 pLightDir = pLightPos[i]-input.wPos; float3 pLightVector = normalize(mul(input.tangentMatrix, pLightDir)); float bump = saturate(dot(normalVector, pLightVector)); float3 reflect = normalize(2 * bump * normalVector - pLightVector); float spec = pow(saturate(dot(reflect, viewVector)), shininess); diffuseCol += (saturate(dot(float3(0,0,1), pLightVector))*diffuseColor); specularCol += saturate(bump*spec*specularColor); } } }