mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
~ | Small modif
This commit is contained in:
@ -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);
|
||||
}
|
Reference in New Issue
Block a user