Working on fixing colors

This commit is contained in:
Jack Christensen 2023-12-07 17:27:17 -05:00
parent 5e2ae73649
commit e154f33849
1 changed files with 35 additions and 2 deletions

View File

@ -297,6 +297,38 @@ vec4 RayMarch(vec2 coords, vec2 offset)
calcDist(ray_pos.xyz, minDist);
vec3 color1 = vec3(0.0), color2 = vec3(0.0);
float closestDist = 999999.0, secondClosestDist = 999999.0;
int closestIndex = -1, secondClosestIndex = -1;
for (int i = 0; i < primitives.length(); i++) {
float dist = sdf(ray_pos.xyz, primitives[i]);
// Update closest and second closest distances and indices
if (dist < closestDist) {
secondClosestDist = closestDist;
secondClosestIndex = closestIndex;
closestDist = dist;
closestIndex = i;
}
else if (dist < secondClosestDist) {
secondClosestDist = dist;
secondClosestIndex = i;
}
}
if (closestIndex != -1) {
color1 = primitives[closestIndex].diffuse_color.rgb;
}
if (secondClosestIndex != -1) {
color2 = primitives[secondClosestIndex].diffuse_color.rgb;
}
// Calculate weight based on distances
float weight = weightFunction(closestDist, secondClosestDist, smoothing);
// Blend colors based on weight
vec3 finalColor = mix(color1, color2, weight);
for (int i = 0; i < primitives.length(); i++)
{
float weight = weightFunction(minDist, smoothing, epsilon);
@ -323,7 +355,8 @@ vec4 RayMarch(vec2 coords, vec2 offset)
float distLight;
vec3 lw;
ambient_color = vec4(accumulatedAmbient.rgb, 1.0);
diffuse_color = vec4(accumulatedDiffuse.rgb, 1.0);
//diffuse_color = vec4(accumulatedDiffuse.rgb, 1.0);
diffuse_color.rgb = finalColor;
normals = estimateNormals(ray_pos.xyz, epsilon);
for (int i = 0; i < lights.length(); i++)
@ -353,7 +386,7 @@ vec4 RayMarch(vec2 coords, vec2 offset)
}
for (int i = 0; i < lights.length(); i++) lightColor += renderLight(lights[i].position);
return vec4(mix(color, lightColor, lightColor.a).rgb, 0.0);
return mix(color, lightColor, lightColor.a);
}
void main(void)