Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float4 PixelShaderFunction(float2 texCoord: TEXCOORD0) : COLOR0
- {
- float4 color = tex2D(ScreenS, texCoord);
- float4 ambient = {0.0f, 0.05f, 0.0f, 1.0f};
- float3 pixelPosition = {texCoord[0]-0.5f, texCoord[1]-0.5f, 0.0f};
- //Calculate Ray
- float3 ray = cameraPosition - pixelPosition;
- float3 origin = cameraPosition;
- //Look for intersection of Ray with one of the spheres
- for (int i=0; i<5; i++)
- {
- float a,b,c;
- a = dot(ray, ray);
- b = dot(2*ray, (origin - spheres[i]));
- c = dot(spheres[i],spheres[i]) + dot(origin, origin) - (2 * dot(spheres[i],origin)) - sphereRadiusSqr;
- float discriminant = (b * b) - (4 * a * c);
- if (discriminant > 0)
- {
- color = ambient;
- //Find coordinates of intersection on sphere surface
- float t1 = (-b + sqrt(discriminant)) / 2 * a;
- float3 intersection = origin + (t1 * ray);
- //Calculate light using flat shading (cos() of vectors calculated using dot product)
- color[1] = dot(normalize(intersection - spheres[i]), normalize(spheres[0] - intersection)); //spheres[0] is lightPos
- if (i == 0) { color = lightColor; } //default light location
- }
- }
- return color;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement