mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Anti aliasing and some sort of depth of field but need to tweaks
This commit is contained in:
@ -144,10 +144,10 @@ vec3 pathtrace(Ray ray, inout uint rng_state)
|
||||
GPUMaterial mat = materials[obj.mat_index];
|
||||
|
||||
// RR
|
||||
// float p = max(color.r, max(color.g, color.b));
|
||||
// if (randomValue(rng_state) > p && i > 1)
|
||||
// break;
|
||||
// color /= p;
|
||||
float p = max(color.r, max(color.g, color.b));
|
||||
if (randomValue(rng_state) > p)
|
||||
break;
|
||||
color /= p;
|
||||
//
|
||||
|
||||
color *= mat.color;
|
||||
@ -167,19 +167,30 @@ void main()
|
||||
if (pixel_coords.x >= int(u_resolution.x) || pixel_coords.y >= int(u_resolution.y))
|
||||
return;
|
||||
|
||||
vec2 uv = (vec2(pixel_coords) / u_resolution) * 2.0 - 1.0;;
|
||||
uint rng_state = uint(u_resolution.x) * uint(pixel_coords.y) + pixel_coords.x;
|
||||
rng_state = rng_state + u_frameCount * 719393;
|
||||
|
||||
vec2 jitter = randomPointInCircle(rng_state);
|
||||
|
||||
vec2 uv = ((vec2(pixel_coords) + jitter) / u_resolution) * 2.0 - 1.0;;
|
||||
uv.x *= u_resolution.x / u_resolution.y;
|
||||
|
||||
float fov = 90.0;
|
||||
float focal_length = 1.0 / tan(radians(fov) / 2.0);
|
||||
vec3 view_space_ray = normalize(vec3(uv.x, uv.y, -focal_length));
|
||||
|
||||
|
||||
vec3 ray_direction = normalize((inverse(u_viewMatrix) * vec4(view_space_ray, 0.0)).xyz);
|
||||
Ray ray = Ray(u_cameraPosition, ray_direction);
|
||||
|
||||
float focal_distance = 0.0;
|
||||
float aperture_size = 0.0;
|
||||
|
||||
uint rng_state = uint(u_resolution.x) * uint(pixel_coords.y) + pixel_coords.x;
|
||||
rng_state = rng_state + u_frameCount * 719393;
|
||||
float theta = randomValue(rng_state) * 2.0 * M_PI;
|
||||
float radius = sqrt(randomValue(rng_state)) * aperture_size;
|
||||
vec2 aperture_point = vec2(cos(theta) * radius, sin(theta) * radius);
|
||||
|
||||
vec3 ray_origin = u_cameraPosition + vec3(aperture_point, 0.0);
|
||||
|
||||
Ray ray = Ray(ray_origin, ray_direction);
|
||||
vec3 color = pathtrace(ray, rng_state);
|
||||
|
||||
float blend = 1.0 / float(u_frameCount + 1);
|
||||
|
@ -23,6 +23,13 @@ vec3 randomDirection(inout uint rng_state)
|
||||
return normalize(vec3(x, y, z));
|
||||
}
|
||||
|
||||
vec2 randomPointInCircle(inout uint rng_state)
|
||||
{
|
||||
float angle = randomValue(rng_state) * 2 * M_PI;
|
||||
vec2 point_in_circle = vec2(cos(angle), sin(angle));
|
||||
return (point_in_circle * sqrt(randomValue(rng_state)));
|
||||
}
|
||||
|
||||
vec3 randomHemisphereDirection(vec3 normal, inout uint rng_state)
|
||||
{
|
||||
vec3 direction = randomDirection(rng_state);
|
||||
|
Reference in New Issue
Block a user