~ | Small modif

This commit is contained in:
RedShip
2025-01-15 19:53:00 +01:00
parent 7d81da012e
commit a892d5e7e6
9 changed files with 25390 additions and 25 deletions

View File

@ -70,24 +70,26 @@ vec3 sampleQuadLight(vec3 position, GPUObject obj, GPUMaterial mat, inout uint r
vec3 sampleLights(vec3 position, inout uint rng_state)
{
vec3 light = vec3(0.0);
int emissive_count = 0;
for (int i = 0; i < u_objectsNum; i++)
if (materials[objects[i].mat_index].emission > 0.0)
emissive_count++;
for (int i = 0; i < u_objectsNum; i++)
{
GPUObject obj = objects[i];
GPUMaterial mat = materials[obj.mat_index];
int target_light = int(floor(randomValue(rng_state) * float(emissive_count)));
if (mat.emission > 0.0)
{
vec3 light_dir = normalize(obj.position - position);
float light_dist = length(obj.position - position);
GPUObject obj = objects[target_light];
GPUMaterial mat = materials[obj.mat_index];
Ray shadow_ray = Ray(position + light_dir * 0.01, light_dir);
hitInfo shadow_hit = traceRay(shadow_ray);
vec3 light_dir = normalize(obj.position - position);
float light_dist = length(obj.position - position);
if (shadow_hit.obj_index == i)
light += mat.emission * mat.color / (light_dist);
}
}
Ray shadow_ray = Ray(position + light_dir * 0.01, light_dir);
hitInfo shadow_hit = traceRay(shadow_ray);
if (shadow_hit.obj_index == target_light)
light += mat.emission * mat.color / (light_dist);
return (light);
}
@ -121,6 +123,6 @@ vec3 sampleLights(vec3 position, inout uint rng_state)
void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inout vec3 light, inout uint rng_state)
{
color *= mat.color;
// light += mat.emission * mat.color;
light += sampleLights(hit.position, rng_state);
light += mat.emission * mat.color;
// light += sampleLights(hit.position, rng_state);
}