rtx: add a bunch of ray bounces

while fps dips below 1, it still looks like modern art
This commit is contained in:
Ivan 'provod' Avdeev 2021-03-13 17:04:45 -08:00
parent 379f6ee409
commit f85a174d8b
2 changed files with 29 additions and 15 deletions

View File

@ -4,9 +4,11 @@
- [x] rtx: make projection matrix independent render global/current/static state
- [x] rtx: model matrices
- [x] rtx: light entities -- still not enough to enlight maps :(
- [x] rtx: path tracing
# Next
- [ ] rtx: path tracing
- [ ] rtx: control bounces with cvars
- [ ] rtx: lower resolution framebuffer + upscale
- [ ] rtx: textures
- [ ] rtx: add fps
- [ ] better AS structure (fewer blases, etc)
@ -15,7 +17,6 @@
- [ ] rtx: some studio models have glitchy geometry
# Planned
- [ ] rtx: lower resolution framebuffer + upscale
- [ ] dlight for flashlight seems to be broken
- [ ] restore render debug labels
- [ ] make 2nd commad buffer for resource upload

View File

@ -66,14 +66,18 @@ void main() {
vec3 C = vec3(0.);
vec3 O = origin.xyz, D=direction.xyz;
vec3 kc = vec3(1.);
const float L = 10000.;
rayQueryEXT rayQuery;
rayQueryInitializeEXT(rayQuery, tlas, gl_RayFlagsOpaqueEXT, 0xff, O, 0., D, L);
while(rayQueryProceedEXT(rayQuery)) {}
const float l = rayQueryGetIntersectionTEXT(rayQuery, true);
if (rayQueryGetIntersectionTypeEXT(rayQuery, true) != gl_RayQueryCommittedIntersectionTriangleEXT) {
C = vec3(1., 0., 1.);
} else {
for (int bounce = 0; bounce < 4; ++bounce) {
rayQueryEXT rayQuery;
rayQueryInitializeEXT(rayQuery, tlas, gl_RayFlagsOpaqueEXT, 0xff, O, 0., D, L);
while(rayQueryProceedEXT(rayQuery)) {}
const float l = rayQueryGetIntersectionTEXT(rayQuery, true);
if (rayQueryGetIntersectionTypeEXT(rayQuery, true) != gl_RayQueryCommittedIntersectionTriangleEXT) {
C += kc * vec3(1., 0., 1.);
break;
}
vec3 pos = O+D*l;
//const int instance_index = rayQueryGetIntersectionInstanceIdEXT(rayQuery, true);
@ -95,7 +99,6 @@ void main() {
const vec3 normal = normalize(transpose(inverse(mat3(transform))) * (n1 * (1. - bary.x - bary.y) + n2 * bary.x + n3 * bary.y));
// TODO rotate normal accroding to model matrix
const vec3 baseColor = vec3(1.);
rand01_state = fract((pos.x + pos.y + pos.z)/100.) + uv.x + uv.y + pc.t;
for (uint i = 0; i < num_lights; ++i) {
@ -107,11 +110,11 @@ void main() {
// Find random point on a sphere
// TODO proper BRDF importance sampling and correct random point distribution
vec3 rnd = normalize(vec3(rand01()*2.-1., rand01()*2.-1., rand01()*2.-1.));
vec3 rnd = normalize(vec3(rand01(), rand01(), rand01())*2.-1.);
if (dot(rnd, pos - light_pos_r.xyz) < 0.) rnd = -rnd;
// TODO fudge this
const float light_r_scaler = 10.;
const float light_r_scaler = 2.;
const vec3 light_dir = light_pos_r.xyz - pos + rnd * light_pos_r.w / light_r_scaler;
const vec3 light_dir_norm = normalize(light_dir);
const float dot_ld_norm = dot(light_dir_norm, normal);
@ -133,9 +136,19 @@ void main() {
const float r2 = light_pos_r.w * light_pos_r.w;
// TODO this is a bad approximation
const float attenuation = dlight_attenuation_const / (d2 + r2 * .5);
C += baseColor.rgb * light_color * dot_ld_norm * attenuation;
}
}
C += kc * baseColor.rgb * light_color * dot_ld_norm * attenuation;
} // for all lights
kc *= .9;
const float rough = .4;
O = pos + .01 * normal;
// TODO this is totally not correct
D = normalize(mix(
reflect(D, normal),
vec3(rand01(), rand01(), rand01())*2.-1.,
rough
));
} // for all bounces
imageStore(image, ivec2(gl_GlobalInvocationID.xy), vec4(C, 1.));
}