Fixed shadow back projections
This commit is contained in:
parent
eaf76fd6e7
commit
26c39e9c67
3 changed files with 12 additions and 12 deletions
|
|
@ -12,6 +12,7 @@ layout (binding = 0, rgba8) uniform writeonly image2D resultImage;
|
||||||
#define MAXLEN 1000.0
|
#define MAXLEN 1000.0
|
||||||
#define SHADOW 0.5
|
#define SHADOW 0.5
|
||||||
#define RAYBOUNCES 2
|
#define RAYBOUNCES 2
|
||||||
|
#define REFLECTIONS true
|
||||||
#define REFLECTIONSTRENGTH 0.4
|
#define REFLECTIONSTRENGTH 0.4
|
||||||
#define REFLECTIONFALLOFF 0.5
|
#define REFLECTIONFALLOFF 0.5
|
||||||
|
|
||||||
|
|
@ -68,7 +69,7 @@ void reflectRay(inout vec3 rayD, in vec3 mormal)
|
||||||
|
|
||||||
float lightDiffuse(vec3 normal, vec3 lightDir)
|
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)
|
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;
|
return -1.0;
|
||||||
}
|
}
|
||||||
float t = (-b - sqrt(h)) / 2.0;
|
float t = (-b - sqrt(h)) / 2.0;
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,14 +146,16 @@ int intersect(in vec3 rayO, in vec3 rayD, inout float resT)
|
||||||
return id;
|
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++)
|
for (int i = 0; i < spheres.length(); i++)
|
||||||
{
|
{
|
||||||
|
if (spheres[i].id == objectId)
|
||||||
|
continue;
|
||||||
float tSphere = sphereIntersect(rayO, rayD, spheres[i]);
|
float tSphere = sphereIntersect(rayO, rayD, spheres[i]);
|
||||||
if (tSphere > EPSILON)
|
if ((tSphere > EPSILON) && (tSphere < t))
|
||||||
{
|
{
|
||||||
|
t = tSphere;
|
||||||
return SHADOW;
|
return SHADOW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -210,9 +214,10 @@ vec3 renderScene(inout vec3 rayO, inout vec3 rayD, inout int id)
|
||||||
return color;
|
return color;
|
||||||
|
|
||||||
id = objectID;
|
id = objectID;
|
||||||
|
|
||||||
// Shadows
|
// Shadows
|
||||||
color *= calcShadow(pos, lightVec, objectID);
|
t = length(ubo.lightPos - pos);
|
||||||
|
color *= calcShadow(pos, lightVec, id, t);
|
||||||
|
|
||||||
// Fog
|
// Fog
|
||||||
color = fog(t, color);
|
color = fog(t, color);
|
||||||
|
|
@ -236,9 +241,8 @@ void main()
|
||||||
int id = 0;
|
int id = 0;
|
||||||
vec3 finalColor = renderScene(rayO, rayD, id);
|
vec3 finalColor = renderScene(rayO, rayD, id);
|
||||||
|
|
||||||
const bool reflections = true;
|
|
||||||
// Reflection
|
// Reflection
|
||||||
if (reflections)
|
if (REFLECTIONS)
|
||||||
{
|
{
|
||||||
float reflectionStrength = REFLECTIONSTRENGTH;
|
float reflectionStrength = REFLECTIONSTRENGTH;
|
||||||
for (int i = 0; i < RAYBOUNCES; i++)
|
for (int i = 0; i < RAYBOUNCES; i++)
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -315,10 +315,6 @@ public:
|
||||||
spheres.push_back(newSphere(glm::vec3(1.75f, -0.5f, 0.0f), 1.0f, glm::vec3(0.0f, 1.0f, 0.0f), 32.0f));
|
spheres.push_back(newSphere(glm::vec3(1.75f, -0.5f, 0.0f), 1.0f, glm::vec3(0.0f, 1.0f, 0.0f), 32.0f));
|
||||||
spheres.push_back(newSphere(glm::vec3(0.0f, 1.0f, -0.5f), 1.0f, glm::vec3(0.65f, 0.77f, 0.97f), 32.0f));
|
spheres.push_back(newSphere(glm::vec3(0.0f, 1.0f, -0.5f), 1.0f, glm::vec3(0.65f, 0.77f, 0.97f), 32.0f));
|
||||||
spheres.push_back(newSphere(glm::vec3(-1.75f, -0.75f, -0.5f), 1.25f, glm::vec3(0.9f, 0.76f, 0.46f), 32.0f));
|
spheres.push_back(newSphere(glm::vec3(-1.75f, -0.75f, -0.5f), 1.25f, glm::vec3(0.9f, 0.76f, 0.46f), 32.0f));
|
||||||
// spheres.push_back(newSphere(glm::vec3(-2.25f, -1.0f, 0.5f), 1.0f, glm::vec3(1.0f, 0.32f, 0.36f), 32.0f));
|
|
||||||
//spheres.push_back(newSphere(glm::vec3(-2.25f, 1.0f, 0.0f), 1.0f, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(2.0f)));
|
|
||||||
//spheres.push_back(newSphere(glm::vec3(0.f, 2.5f, 0.0f), 1.0f, glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(2.0f)));
|
|
||||||
//spheres.push_back(newSphere(glm::vec3(2.25f, 1.0f, 0.0f), 1.0f, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(2.0f)));
|
|
||||||
VkDeviceSize storageBufferSize = spheres.size() * sizeof(Sphere);
|
VkDeviceSize storageBufferSize = spheres.size() * sizeof(Sphere);
|
||||||
|
|
||||||
// Stage
|
// Stage
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue