Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void PS_Phong(in float3 inNormal : TEXCOORD,
- in float3 inCameraDir : TEXCOORD1,
- in float3 inWorldPos : TEXCOORD2,
- out float4 outColor : COLOR)
- {
- outColor = float4(0.0f, 0.0f, 0.0f, 0.0f);
- //renormalize interpolated vectors
- inNormal = normalize(inNormal);
- inCameraDir = normalize(inCameraDir);
- const float shininess = 2;
- const float4 material_ambient = float4(0.05f, 0.05f, 0.05f, 1.0f);
- const float4 material_diffuse = float4(0.30f, 0.30f, 0.30f, 1.0f);
- const float4 material_specular = float4(0.20f, 0.20f, 0.20f, 1.0f);
- int i;
- const float opacity = 0.01;
- const float3 direction = inWorldPos-cameraPos;
- const float distance_to_wall = length(direction);
- float alpha_sum = 0;
- const float3 rayDirection = normalize(direction);
- for (i=0; i<4; i++)
- {
- if (cameraId == i)
- continue;
- float3 position = cameraPos + normalize(direction)*0.1;
- int playerIndex = i;
- float3 value = float3(0, 0, 0);
- float alpha = 1;
- float distance_from_nearplane = 0;
- while(distance_from_nearplane < distance_to_wall)
- {
- //float3 distance_2 = length(lightPos[playerIndex] - position);
- //float lightAttenuation = 1 / pow(distance_2, cameraId+1);
- float3 distance = lightPos[playerIndex] - position;
- float lightAttenuation = 1 / dot(distance, distance);
- float shadow = 1.0f;
- float lightIntensity=1.1337f;
- alpha = pow(1-opacity, distance_from_nearplane);
- alpha_sum += alpha * opacity;
- value.rgb = (alpha * opacity)*(lightColors[playerIndex] * lightIntensity * lightAttenuation * shadow);
- distance_from_nearplane = length(position - cameraPos) - 0.1;
- outColor += float4(value, 0);
- float rayLength = length(lightPos[playerIndex] - position)/5;
- position += rayDirection*(rayLength + 0.1);
- }
- }
- for (i = 0; i < MaxLights; ++i)
- {
- float3 lightDirection = (lightPos[i] - inWorldPos);
- float atten = 1.0f / (length(lightDirection)*linearLightFactor + dot(lightDirection, lightDirection)*quadraticLightFactor + constantLightFactor);
- lightDirection = normalize(lightDirection);
- float3 h = normalize(lightDirection + inCameraDir);
- float nDotL = saturate(dot(inNormal, lightDirection));
- float nDotH = saturate(dot(inNormal, h));
- float power = (nDotL == 0.0f) ? 0.0f : pow(nDotH, shininess);
- float4 color = (material_ambient) + (material_diffuse * nDotL);// + (material_specular * power);
- color *= atten;
- color *= shadowBrightness(inWorldPos, i);
- //color *= lightRad[i];
- outColor += color*(1-alpha_sum)*float4(lightColors[i], 1);
- }
- outColor.a = 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement