mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-15 13:41:33 +01:00
rt: unify shadowed with shadowedSky
This commit is contained in:
parent
3ebfb72819
commit
8ec8502a53
@ -42,9 +42,9 @@ void computePointLights(vec3 P, vec3 N, uint cluster_index, vec3 throughput, vec
|
||||
const float stopdot = lights.m.point_lights[i].color_stopdot.a;
|
||||
const vec3 dir = lights.m.point_lights[i].dir_stopdot2.xyz;
|
||||
const float stopdot2 = lights.m.point_lights[i].dir_stopdot2.a;
|
||||
const bool not_environment = (lights.m.point_lights[i].environment == 0);
|
||||
const bool is_environment = (lights.m.point_lights[i].environment != 0);
|
||||
|
||||
const vec3 light_dir = not_environment ? (origin_r.xyz - P) : -dir; // TODO need to randomize sampling direction for environment soft shadow
|
||||
const vec3 light_dir = is_environment ? -dir : (origin_r.xyz - P); // TODO need to randomize sampling direction for environment soft shadow
|
||||
const float radius = origin_r.w;
|
||||
|
||||
const vec3 light_dir_norm = normalize(light_dir);
|
||||
@ -64,7 +64,9 @@ void computePointLights(vec3 P, vec3 N, uint cluster_index, vec3 throughput, vec
|
||||
float light_dist = 1e5; // TODO this is supposedly not the right way to do shadows for environment lights.m. qrad checks for hitting SURF_SKY, and maybe we should too?
|
||||
const float d2 = dot(light_dir, light_dir);
|
||||
const float r2 = origin_r.w * origin_r.w;
|
||||
if (not_environment) {
|
||||
if (is_environment) {
|
||||
color *= 2; // TODO WHY?
|
||||
} else {
|
||||
if (radius < 1e-3)
|
||||
continue;
|
||||
|
||||
@ -86,8 +88,6 @@ void computePointLights(vec3 P, vec3 N, uint cluster_index, vec3 throughput, vec
|
||||
//const float pdf = TWO_PI / asin(radius / dist);
|
||||
const float pdf = 1. / ((1. - sqrt(d2 - r2) / dist) * spot_attenuation);
|
||||
color /= pdf;
|
||||
} else {
|
||||
color *= 2;
|
||||
}
|
||||
|
||||
// if (dot(color,color) < color_culling_threshold)
|
||||
@ -104,14 +104,8 @@ void computePointLights(vec3 P, vec3 N, uint cluster_index, vec3 throughput, vec
|
||||
continue;
|
||||
|
||||
// FIXME split environment and other lights
|
||||
if (not_environment) {
|
||||
if (shadowed(P, light_dir_norm, light_dist + shadow_offset_fudge))
|
||||
continue;
|
||||
} else {
|
||||
// for environment light check that we've hit SURF_SKY
|
||||
if (shadowedSky(P, light_dir_norm, light_dist + shadow_offset_fudge))
|
||||
continue;
|
||||
}
|
||||
if (shadowed(P, light_dir_norm, light_dist + shadow_offset_fudge, is_environment))
|
||||
continue;
|
||||
|
||||
diffuse += ldiffuse;
|
||||
specular += lspecular;
|
||||
|
@ -66,7 +66,7 @@ void shadowRayQuery(rayQueryEXT rq, vec3 pos, vec3 dir, float dist, uint flags)
|
||||
}
|
||||
#endif
|
||||
|
||||
bool shadowed(vec3 pos, vec3 dir, float dist) {
|
||||
bool shadowed(vec3 pos, vec3 dir, float dist, bool check_sky) {
|
||||
#ifdef RAY_TRACE
|
||||
const uint flags = 0
|
||||
//| gl_RayFlagsCullFrontFacingTrianglesEXT
|
||||
@ -75,42 +75,19 @@ bool shadowed(vec3 pos, vec3 dir, float dist) {
|
||||
| gl_RayFlagsSkipClosestHitShaderEXT
|
||||
;
|
||||
const uint hit_type = traceShadowRay(pos, dir, dist, flags);
|
||||
return payload_shadow.hit_type == SHADOW_HIT;
|
||||
return check_sky ? payload_shadow.hit_type != SHADOW_SKY : payload_shadow.hit_type == SHADOW_HIT;
|
||||
#elif defined(RAY_QUERY)
|
||||
const uint flags = 0
|
||||
//| gl_RayFlagsCullFrontFacingTrianglesEXT
|
||||
//| gl_RayFlagsOpaqueEXT
|
||||
| gl_RayFlagsTerminateOnFirstHitEXT
|
||||
//| gl_RayFlagsSkipClosestHitShaderEXT
|
||||
;
|
||||
rayQueryEXT rq;
|
||||
shadowRayQuery(rq, pos, dir, dist, flags);
|
||||
return rayQueryGetIntersectionTypeEXT(rq, true) == gl_RayQueryCommittedIntersectionTriangleEXT;
|
||||
#else
|
||||
#error RAY_TRACE or RAY_QUERY
|
||||
#endif
|
||||
}
|
||||
|
||||
// TODO join with just shadowed()
|
||||
bool shadowedSky(vec3 pos, vec3 dir, float dist) {
|
||||
#ifdef RAY_TRACE
|
||||
const uint flags = 0
|
||||
//| gl_RayFlagsCullFrontFacingTrianglesEXT
|
||||
//| gl_RayFlagsOpaqueEXT
|
||||
//| gl_RayFlagsTerminateOnFirstHitEXT
|
||||
//| gl_RayFlagsSkipClosestHitShaderEXT
|
||||
;
|
||||
const uint hit_type = traceShadowRay(pos, dir, dist, flags);
|
||||
return payload_shadow.hit_type != SHADOW_SKY;
|
||||
#elif defined(RAY_QUERY)
|
||||
const uint flags = 0
|
||||
//| gl_RayFlagsCullFrontFacingTrianglesEXT
|
||||
//| gl_RayFlagsOpaqueEXT
|
||||
//| gl_RayFlagsTerminateOnFirstHitEXT
|
||||
//| gl_RayFlagsSkipClosestHitShaderEXT
|
||||
;
|
||||
rayQueryEXT rq;
|
||||
shadowRayQuery(rq, pos, dir, dist, flags);
|
||||
if (!check_sky) {
|
||||
return rayQueryGetIntersectionTypeEXT(rq, true) == gl_RayQueryCommittedIntersectionTriangleEXT;
|
||||
}
|
||||
|
||||
if (rayQueryGetIntersectionTypeEXT(rq, true) != gl_RayQueryCommittedIntersectionTriangleEXT)
|
||||
return true;
|
||||
|
@ -177,7 +177,7 @@ void sampleSinglePolygonLight(in vec3 P, in vec3 N, in vec3 view_dir, in SampleC
|
||||
|
||||
const float dist = - dot(vec4(P, 1.f), poly.plane) / dot(light_sample_dir.xyz, poly.plane.xyz);
|
||||
|
||||
if (shadowed(P, light_sample_dir.xyz, dist))
|
||||
if (shadowed(P, light_sample_dir.xyz, dist, false))
|
||||
return;
|
||||
|
||||
vec3 poly_diffuse = vec3(0.), poly_specular = vec3(0.);
|
||||
@ -244,7 +244,7 @@ void sampleEmissiveSurfaces(vec3 P, vec3 N, vec3 throughput, vec3 view_dir, Mate
|
||||
const float dist = - plane_dist / dot(light_sample_dir.xyz, poly.plane.xyz);
|
||||
const vec3 emissive = poly.emissive;
|
||||
|
||||
if (!shadowed(P, light_sample_dir.xyz, dist)) {
|
||||
if (!shadowed(P, light_sample_dir.xyz, dist, false)) {
|
||||
//const float estimate = total_contrib;
|
||||
const float estimate = light_sample_dir.w;
|
||||
vec3 poly_diffuse = vec3(0.), poly_specular = vec3(0.);
|
||||
@ -320,7 +320,7 @@ void sampleEmissiveSurfaces(vec3 P, vec3 N, vec3 throughput, vec3 view_dir, Mate
|
||||
const vec3 emissive = poly.emissive;
|
||||
|
||||
//if (true) {//!shadowed(P, light_sample_dir.xyz, dist)) {
|
||||
if (!shadowed(P, light_sample_dir.xyz, dist)) {
|
||||
if (!shadowed(P, light_sample_dir.xyz, dist, false)) {
|
||||
//const float estimate = total_contrib;
|
||||
const float estimate = light_sample_dir.w;
|
||||
vec3 poly_diffuse = vec3(0.), poly_specular = vec3(0.);
|
||||
|
Loading…
Reference in New Issue
Block a user