Fixed shadow back projections

This commit is contained in:
saschawillems 2016-09-02 14:53:44 +02:00
parent eaf76fd6e7
commit 26c39e9c67
3 changed files with 12 additions and 12 deletions

View file

@ -12,6 +12,7 @@ layout (binding = 0, rgba8) uniform writeonly image2D resultImage;
#define MAXLEN 1000.0
#define SHADOW 0.5
#define RAYBOUNCES 2
#define REFLECTIONS true
#define REFLECTIONSTRENGTH 0.4
#define REFLECTIONFALLOFF 0.5
@ -68,7 +69,7 @@ void reflectRay(inout vec3 rayD, in vec3 mormal)
float lightDiffuse(vec3 normal, vec3 lightDir)
{
return clamp(dot(normal, lightDir), 0.25, 1.0);
return clamp(dot(normal, lightDir), 0.1, 1.0);
}
float lightSpecular(vec3 normal, vec3 lightDir, float specularFactor)
@ -91,6 +92,7 @@ float sphereIntersect(in vec3 rayO, in vec3 rayD, in Sphere sphere)
return -1.0;
}
float t = (-b - sqrt(h)) / 2.0;
return t;
}
@ -144,14 +146,16 @@ int intersect(in vec3 rayO, in vec3 rayD, inout float resT)
return id;
}
float calcShadow(in vec3 rayO, in vec3 rayD, in int id)
float calcShadow(in vec3 rayO, in vec3 rayD, in int objectId, inout float t)
{
//todo: avoid backprojection
for (int i = 0; i < spheres.length(); i++)
{
if (spheres[i].id == objectId)
continue;
float tSphere = sphereIntersect(rayO, rayD, spheres[i]);
if (tSphere > EPSILON)
if ((tSphere > EPSILON) && (tSphere < t))
{
t = tSphere;
return SHADOW;
}
}
@ -210,9 +214,10 @@ vec3 renderScene(inout vec3 rayO, inout vec3 rayD, inout int id)
return color;
id = objectID;
// Shadows
color *= calcShadow(pos, lightVec, objectID);
t = length(ubo.lightPos - pos);
color *= calcShadow(pos, lightVec, id, t);
// Fog
color = fog(t, color);
@ -236,9 +241,8 @@ void main()
int id = 0;
vec3 finalColor = renderScene(rayO, rayD, id);
const bool reflections = true;
// Reflection
if (reflections)
if (REFLECTIONS)
{
float reflectionStrength = REFLECTIONSTRENGTH;
for (int i = 0; i < RAYBOUNCES; i++)