mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Better samplelighting
This commit is contained in:
@ -11,6 +11,6 @@ Pos=1648,220
|
|||||||
Size=266,285
|
Size=266,285
|
||||||
|
|
||||||
[Window][Fog settings]
|
[Window][Fog settings]
|
||||||
Pos=1654,508
|
Pos=1656,509
|
||||||
Size=247,157
|
Size=247,157
|
||||||
|
|
||||||
|
24003
obj/Model.obj
Normal file
24003
obj/Model.obj
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,4 @@
|
|||||||
CAM 1.43879 3.42554 1.94198 -44.6001 -139.599 0 4 90 5
|
CAM 10.2849 6.27579 9.45482 -0.600081 -128.999 0 4 90 5
|
||||||
|
|
||||||
|
|
||||||
MAT 200 200 200 0.0 0.0 0.0 //white
|
MAT 200 200 200 0.0 0.0 0.0 //white
|
||||||
MAT 255 50 50 0.0 1.0 0.05 //red
|
MAT 255 50 50 0.0 1.0 0.05 //red
|
||||||
@ -27,4 +26,4 @@ sp 0 1 5 1 7
|
|||||||
|
|
||||||
cy 0 1 2 0.5 2 -1.5 0 0.75 1
|
cy 0 1 2 0.5 2 -1.5 0 0.75 1
|
||||||
|
|
||||||
# OBJ obj/Lowpoly_tree_sample.obj
|
OBJ obj/Lowpoly_tree_sample.obj
|
||||||
|
@ -7,7 +7,7 @@ MAT 255 255 255 5.0 0.0 0.0 //light
|
|||||||
|
|
||||||
pl 0 0 0 0 1 0 1
|
pl 0 0 0 0 1 0 1
|
||||||
|
|
||||||
sp -10 10 -9 0.1 2
|
sp -10 10 -9 1 2
|
||||||
# qu -10 5 -12 0 6 0 0 0 6 2
|
# qu -10 5 -12 0 6 0 0 0 6 2
|
||||||
|
|
||||||
qu 0 0 0 0 6 0 18 0 0 0
|
qu 0 0 0 0 6 0 18 0 0 0
|
||||||
|
@ -19,7 +19,7 @@ vec3 GetEnvironmentLight(Ray ray)
|
|||||||
return composite;
|
return composite;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 sampleSphereLight(vec3 position, GPUObject obj, GPUMaterial mat, inout uint rng_state)
|
vec3 sampleSphereLight(vec3 position, GPUObject obj, int light_index, GPUMaterial mat, inout uint rng_state)
|
||||||
{
|
{
|
||||||
float theta = 2.0 * M_PI * randomValue(rng_state);
|
float theta = 2.0 * M_PI * randomValue(rng_state);
|
||||||
float phi = acos(2.0 * randomValue(rng_state) - 1.0);
|
float phi = acos(2.0 * randomValue(rng_state) - 1.0);
|
||||||
@ -36,14 +36,14 @@ vec3 sampleSphereLight(vec3 position, GPUObject obj, GPUMaterial mat, inout uint
|
|||||||
Ray shadow_ray = Ray(position + light_dir * 0.001, light_dir);
|
Ray shadow_ray = Ray(position + light_dir * 0.001, light_dir);
|
||||||
hitInfo shadow_hit = traceRay(shadow_ray);
|
hitInfo shadow_hit = traceRay(shadow_ray);
|
||||||
|
|
||||||
if (shadow_hit.obj_index != -1 && shadow_hit.t < light_dist)
|
if (shadow_hit.obj_index != light_index)
|
||||||
return vec3(0.0);
|
return vec3(0.0);
|
||||||
|
|
||||||
float cos_theta = max(0.0, -dot(light_dir, normalize(sample_point - obj.position)));
|
float cos_theta = max(0.0, -dot(light_dir, normalize(sample_point - obj.position)));
|
||||||
return mat.emission * mat.color / (light_dist);
|
return mat.emission * mat.color / (light_dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 sampleQuadLight(vec3 position, GPUObject obj, GPUMaterial mat, inout uint rng_state)
|
vec3 sampleQuadLight(vec3 position, GPUObject obj, int light_index, GPUMaterial mat, inout uint rng_state)
|
||||||
{
|
{
|
||||||
float u = randomValue(rng_state);
|
float u = randomValue(rng_state);
|
||||||
float v = randomValue(rng_state);
|
float v = randomValue(rng_state);
|
||||||
@ -55,7 +55,7 @@ vec3 sampleQuadLight(vec3 position, GPUObject obj, GPUMaterial mat, inout uint r
|
|||||||
Ray shadow_ray = Ray(position + light_dir * 0.001, light_dir);
|
Ray shadow_ray = Ray(position + light_dir * 0.001, light_dir);
|
||||||
hitInfo shadow_hit = traceRay(shadow_ray);
|
hitInfo shadow_hit = traceRay(shadow_ray);
|
||||||
|
|
||||||
if (shadow_hit.obj_index != -1 && shadow_hit.t < light_dist)
|
if (shadow_hit.obj_index != light_index)
|
||||||
return vec3(0.0);
|
return vec3(0.0);
|
||||||
|
|
||||||
vec3 crossQuad = cross(obj.vertex1, obj.vertex2);
|
vec3 crossQuad = cross(obj.vertex1, obj.vertex2);
|
||||||
@ -74,19 +74,18 @@ vec3 sampleLights(vec3 position, inout uint rng_state)
|
|||||||
for (int i = 0; i < u_lightsNum; i++)
|
for (int i = 0; i < u_lightsNum; i++)
|
||||||
{
|
{
|
||||||
int light_index = lightsIndex[i];
|
int light_index = lightsIndex[i];
|
||||||
|
|
||||||
GPUObject obj = objects[light_index];
|
GPUObject obj = objects[light_index];
|
||||||
GPUMaterial mat = materials[obj.mat_index];
|
GPUMaterial mat = materials[obj.mat_index];
|
||||||
if (mat.emission > 0.0)
|
|
||||||
{
|
|
||||||
vec3 light_dir = normalize(obj.position - position);
|
|
||||||
float light_dist = length(obj.position - position);
|
|
||||||
|
|
||||||
Ray shadow_ray = Ray(position + light_dir * 0.01, light_dir);
|
vec3 light_dir = normalize(obj.position - position);
|
||||||
hitInfo shadow_hit = traceRay(shadow_ray);
|
float light_dist = length(obj.position - position);
|
||||||
|
|
||||||
if (shadow_hit.obj_index == light_index)
|
Ray shadow_ray = Ray(position + light_dir * 0.01, light_dir);
|
||||||
light += mat.emission * mat.color / (light_dist);
|
hitInfo shadow_hit = traceRay(shadow_ray);
|
||||||
}
|
|
||||||
|
if (shadow_hit.obj_index == light_index)
|
||||||
|
light += mat.emission * mat.color / (light_dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (light);
|
return (light);
|
||||||
@ -96,19 +95,18 @@ vec3 sampleLights(vec3 position, inout uint rng_state)
|
|||||||
// {
|
// {
|
||||||
// vec3 light = vec3(0.0);
|
// vec3 light = vec3(0.0);
|
||||||
|
|
||||||
// for (int i = 0; i < u_objectsNum; i++)
|
// for (int i = 0; i < u_lightsNum; i++)
|
||||||
// {
|
// {
|
||||||
|
// int light_index = lightsIndex[i];
|
||||||
// GPUObject obj = objects[i];
|
|
||||||
|
// GPUObject obj = objects[light_index];
|
||||||
// GPUMaterial mat = materials[obj.mat_index];
|
// GPUMaterial mat = materials[obj.mat_index];
|
||||||
|
|
||||||
// if (mat.emission == 0.0)
|
|
||||||
// continue ;
|
|
||||||
|
|
||||||
// if (obj.type == 0)
|
// if (obj.type == 0)
|
||||||
// light = sampleSphereLight(position, obj, mat, rng_state);
|
// light += sampleSphereLight(position, obj, light_index, mat, rng_state);
|
||||||
// else if (obj.type == 2)
|
// else if (obj.type == 2)
|
||||||
// light = sampleQuadLight(position, obj, mat, rng_state);
|
// light += sampleQuadLight(position, obj, light_index, mat, rng_state);
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// return (light);
|
// return (light);
|
||||||
@ -117,6 +115,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)
|
void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inout vec3 light, inout uint rng_state)
|
||||||
{
|
{
|
||||||
color *= mat.color;
|
color *= mat.color;
|
||||||
// light += mat.emission * mat.color;
|
light += mat.emission * mat.color;
|
||||||
light += sampleLights(hit.position, rng_state);
|
// light += sampleLights(hit.position, rng_state);
|
||||||
}
|
}
|
Reference in New Issue
Block a user