mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
+ | Refraction index dieletric material
This commit is contained in:
@ -24,6 +24,7 @@ struct GPUMaterial
|
||||
float emission; // 4
|
||||
float roughness; // 4
|
||||
float metallic; // 4
|
||||
int type; // 4
|
||||
};
|
||||
|
||||
layout(std430, binding = 1) buffer ObjectBuffer
|
||||
|
@ -1,20 +1,68 @@
|
||||
|
||||
Ray newRay(hitInfo hit, Ray ray, inout uint rng_state)
|
||||
Ray lambertRay(hitInfo hit, Ray ray, GPUMaterial mat, uint rng_state)
|
||||
{
|
||||
GPUObject obj;
|
||||
GPUMaterial mat;
|
||||
Ray new_ray;
|
||||
|
||||
obj = objects[hit.obj_index];
|
||||
mat = materials[obj.mat_index];
|
||||
|
||||
vec3 diffuse_dir = normalize(hit.normal + randomDirection(rng_state));
|
||||
vec3 specular_dir = reflect(ray.direction, hit.normal);
|
||||
|
||||
bool is_specular = (mat.metallic >= randomValue(rng_state));
|
||||
|
||||
new_ray.origin = hit.position + hit.normal * 0.001;
|
||||
new_ray.direction = mix(diffuse_dir, specular_dir, mat.roughness * float(is_specular));
|
||||
ray.origin = hit.position + hit.normal * 0.001;
|
||||
ray.direction = mix(diffuse_dir, specular_dir, mat.roughness * float(is_specular));
|
||||
|
||||
return (new_ray);
|
||||
return (ray);
|
||||
}
|
||||
|
||||
// Ray dieletricRay(hitInfo hit, Ray ray, GPUMaterial mat)
|
||||
// {
|
||||
// float refraction_ratio;
|
||||
// vec3 unit_direction;
|
||||
|
||||
// refraction_ratio = 1.0f / mat.roughness; //mat.roughness = refraction (saving memory)
|
||||
|
||||
// if (dot(ray.direction, hit.normal) > 0.0f)
|
||||
// {
|
||||
// hit.normal = -hit.normal;
|
||||
// refraction_ratio = mat.roughness;
|
||||
// }
|
||||
|
||||
// unit_direction = normalize(ray.direction);
|
||||
// ray.origin = hit.position + hit.normal * -0.0001f;
|
||||
// ray.direction = refract(unit_direction, hit.normal, refraction_ratio);
|
||||
|
||||
// return (ray);
|
||||
// }
|
||||
|
||||
Ray dieletricRay(hitInfo hit, Ray ray, GPUMaterial mat)
|
||||
{
|
||||
float refraction_ratio;
|
||||
vec3 unit_direction;
|
||||
|
||||
refraction_ratio = 1.0f / mat.roughness; //mat.roughness = refraction (saving memory)
|
||||
|
||||
float d = dot(ray.direction, hit.normal);
|
||||
hit.normal *= sign(d);
|
||||
|
||||
if (d > 0.0f)
|
||||
refraction_ratio = mat.roughness;
|
||||
|
||||
unit_direction = normalize(ray.direction);
|
||||
ray.origin = hit.position + hit.normal * 0.0001f;
|
||||
ray.direction = refract(unit_direction, -hit.normal, refraction_ratio);
|
||||
|
||||
return (ray);
|
||||
}
|
||||
|
||||
Ray newRay(hitInfo hit, Ray ray, uint rng_state)
|
||||
{
|
||||
GPUObject obj;
|
||||
GPUMaterial mat;
|
||||
|
||||
obj = objects[hit.obj_index];
|
||||
mat = materials[obj.mat_index];
|
||||
|
||||
if (mat.type == 0)
|
||||
return (lambertRay(hit, ray, mat, rng_state));
|
||||
else if (mat.type == 1)
|
||||
return (dieletricRay(hit, ray, mat));
|
||||
return (ray);
|
||||
}
|
Reference in New Issue
Block a user