Choose a level...
struct a2v { float4 position : POSITION; float3 normal : NORMAL; float2 texCoord : TEXCOORD0; }; struct v2f { float4 position : POSITION; float3 worldPosition : TEXCOORD0; float2 texCoord : TEXCOORD1; float3 n : TEXCOORD2; float3 l : TEXCOORD3; }; float4x4 worldViewProj : WorldViewProjection; float4x4 world : World; float4x4 worldIT : WorldInverseTranspose; uniform float4 ambientLightColor; uniform float3 sunlightDirection; uniform float4 sunlightColor; uniform float3 cameraEye; uniform float3 cameraTarget; uniform float3 light0_location; uniform float3 light1_location; uniform float3 light2_location; uniform float3 light3_location; uniform float3 light4_location; uniform float4 light0_color; uniform float4 light1_color; uniform float4 light2_color; uniform float4 light3_color; uniform float4 light4_color; uniform float4 fog_color; // The texture from a sketchup6 file // A diffuseTexture and a diffuse color (when there isn't a texture) uniform float4 diffuse; // The color, unless texture sampler2D diffuseSampler; v2f vsMain(a2v IN) { v2f OUT; OUT.position = mul(IN.position, worldViewProj); OUT.worldPosition = mul(IN.position, world).xyz; OUT.texCoord = IN.texCoord; OUT.n = mul(float4(IN.normal,0), worldIT).xyz; OUT.l = IN.normal; return OUT; } float4 fsMain(v2f IN): COLOR { float4 textureColor = tex2D(diffuseSampler, IN.texCoord); float3 normalDirection = normalize(IN.n); float3 viewDirection = normalize(cameraEye - IN.worldPosition.xyz); // Only diffuse light until we can get better than face normals. float4 litWorld = lit(dot(normalDirection.xyz, sunlightDirection), 0, 0); float4 total_color = ambientLightColor + litWorld.yyyy * sunlightColor; float3 light_direction = light0_location - IN.worldPosition.xyz; float attenuation = light0_color.a / length(light_direction); light_direction = normalize(light_direction); float4 litLight = lit(dot(normalDirection.xyz, light_direction), 0, 0); litLight.y *= clamp(attenuation * attenuation, 0, 1); total_color.rgb += litLight.yyy * light0_color.rgb; light_direction = light1_location - IN.worldPosition.xyz; attenuation = light1_color.a / length(light_direction); light_direction = normalize(light_direction); litLight = lit(dot(normalDirection.xyz, light_direction), 0, 0); litLight.y *= clamp(attenuation * attenuation, 0, 1); total_color.rgb += litLight.yyy * light1_color.rgb; light_direction = light2_location - IN.worldPosition.xyz; attenuation = light2_color.a / length(light_direction); light_direction = normalize(light_direction); litLight = lit(dot(normalDirection.xyz, light_direction), 0, 0); litLight.y *= clamp(attenuation * attenuation, 0, 1); total_color.rgb += litLight.yyy * light2_color.rgb; light_direction = light3_location - IN.worldPosition.xyz; attenuation = light3_color.a / length(light_direction); light_direction = normalize(light_direction); litLight = lit(dot(normalDirection.xyz, light_direction), 0, 0); litLight.y *= clamp(attenuation * attenuation, 0, 1); total_color.rgb += litLight.yyy * light3_color.rgb; textureColor.rgb += diffuse.rgb; total_color *= textureColor; // Fog float fog = saturate(pow(2.718, -.005 * (length(cameraEye - IN.worldPosition.xyz) - 300))); return lerp(fog_color, total_color, fog); } // #o3d VertexShaderEntryPoint vsMain // #o3d PixelShaderEntryPoint fsMain // #o3d MatrixLoadOrder RowMajor