//Pixel Shader
float4 ps_lighting(VS_OUTPUT IN) : COLOR0
{
//float4 color = tex2D(DiffuseSampler, IN.tex0);
//opacity
float opacity = GlobalOpacity; //default is global opacity
//diffuse
float4 color = float4(diffuseColor); //default diffusecolor
color = lerp(color, color*IN.color, VertexDiffuse);
//Create Light Calculations
CreateLights( IN.worldSpacePos ); // fill lightstruct array DOES NOT WORK IN VERTEX SHADER, MUST HAPPEN IN PIXEL SHADER! ~0_o>
float3 normal = IN.worldNormal; //default worldspace vertex normal
normal = normalize( normal );
//Diffuse Fresnel
float diffusefresnel = saturate(diffuseFresnelMult*fresnel(normal, IN.eyeVec, diffuseFresnelPower, 0));
color = lerp(color, diffusefresnelColor, diffusefresnel);
//Light Loop
float4 ambient = { 1.0f, 1.0f, 1.0f, 1.0f };
ambient = float4(ambientcolor, 1.0f);
float4 totaldiffuse = ambient; //start off with ambient color
for(int i = 0; i < numberOfActiveLights; ++i) //for loop to iterate over our 3 lights
{
// float4 emissive = lightsarray[i].ke;
float diffuse;
//ambient = lightsarray[i].ka*ambientcolor;
float3 L = normalize(-lightDirection);
// Spot light
diffuse = diffuselight(normal,lightsarray[i].LightVec);
// Directional light
//diffuse = diffuselight(normal,L);
totaldiffuse += (diffuse*lightsarray[i].LightColor);
}
//Apply Lighting
float4 ret = color; // our final returned color starts as unlit diffuse color
ret = float4(pow(ret.x,Gamma),pow(ret.y,Gamma),pow(ret.z,Gamma),ret.a);
ret.a = opacity; // finally set opacity
ret.rgb*=(totaldiffuse); //multiply diffuse with color
ret = pow(ret,1.0/Gamma);
return ret; //all done, return result :)
}
The logic is this.
1) Setting global opacity to 1.0
2) Interpolate the color from the vertex shader (IN.color) with the global material color(diffuseColor)
3) Create lights and normal for each vertex
4) Calculate total diffuse by multiplying the normal of the vertex with the light direction
5) Multiply the interpolated color with the total diffuse value(light)
6) Output the pixel
It looks real dumb like this, and the image is really jagged
How do I improve it? Any good ideas?
Thanks
Jack