void trexskl_vsAmbGEN(float4 position : POSITION, float3 normal : NORMAL, out float4 oPos: POSITION, uniform float4x4 wvpMat ) { oPos = mul(wvpMat, position); } float4 trexskl_fpAmbGEN(float4 position : POSITION, uniform float3 ambient, uniform float4 matAmb, uniform float4 matEmissive): COLOR0 { float4 retColor = max(matEmissive, float4(ambient, 1) * matAmb); return retColor; } void trexskl_vsLightGEN(float4 position : POSITION, float3 normal : NORMAL, out float4 oPos : POSITION, out float3 oNorm : TEXCOORD0, out float3 oSpDir : TEXCOORD1, out float4 oWp : TEXCOORD2, uniform float4x4 wMat, uniform float4x4 witMat, uniform float4x4 wvpMat, uniform float4 spotlightDir) { oWp = mul(wMat, position); oPos = mul(wvpMat, position); oNorm = normalize(mul((float3x3)witMat, normal)); oSpDir = mul(wMat, spotlightDir).xyz; } float4 trexskl_fpLightGEN(float4 position : POSITION, float3 norm : TEXCOORD0, float3 spDir : TEXCOORD1, float4 wp : TEXCOORD2, uniform float3 lightDif0, uniform float4 lightPos0, uniform float4 lightAtt0, uniform float3 lightSpec0, uniform float4 matDif, uniform float4 matSpec, uniform float matShininess, uniform float3 camPos, uniform float4 invSMSize, uniform float4 spotlightParams): COLOR0 { float3 ld0 = normalize(lightPos0.xyz - (lightPos0.w * wp.xyz)); // attenuation half lightDist = length(lightPos0.xyz - wp.xyz) / lightAtt0.r; half la = 1; if(lightAtt0.a > 0.0) { half ila = lightDist * lightDist; // quadratic falloff la = 1.0 / (lightAtt0.g + lightAtt0.b * lightDist + lightAtt0.a * ila); } float3 normal = normalize(norm); float3 diffuse = max(dot(ld0, normal), 0); // calculate the spotlight effect float spot = (spotlightParams.x == 1 && spotlightParams.y == 0 && spotlightParams.z == 0 && spotlightParams.w == 1 ? 1 : // if so, then it's not a spot light saturate((dot(ld0, normalize(-spDir)) - spotlightParams.y) / (spotlightParams.x - spotlightParams.y))); float3 camDir = normalize(camPos - wp.xyz); float3 halfVec = normalize(ld0 + camDir); float3 specular = pow(max(dot(normal, halfVec), 0), matShininess); float3 diffuseContrib = diffuse * lightDif0 * matDif.rgb; float3 specularContrib = specular * lightSpec0 * matSpec.rgb; float3 light0C = (diffuseContrib + specularContrib) * la * spot; float alpha = matDif.a; return float4(light0C, alpha); }