Skip to content

Commit

Permalink
rt: rename traceAdditive to traceSimpleBlending
Browse files Browse the repository at this point in the history
This is to more clearly distinguish between simple blended things that
don't participate in lighting, and future more involved blending with
refraction and being affected by light
  • Loading branch information
w23 committed Apr 27, 2023
1 parent 847777f commit 8ac1a76
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ref/vk/shaders/bounce.comp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ layout(set=0, binding=21, rgba16f) uniform writeonly image2D out_indirect_specul
#define BINDING_LIGHT_CLUSTERS 18
#include "light.glsl"

#include "trace_additive.glsl"
#include "trace_simple_blending.glsl"

void readNormals(ivec2 uv, out vec3 geometry_normal, out vec3 shading_normal) {
const vec4 n = imageLoad(normals_gs, uv);
Expand Down Expand Up @@ -169,7 +169,7 @@ void computeBounce(ivec2 pix, vec3 direction, out vec3 diffuse, out vec3 specula

vec3 background = ldiffuse + lspecular;
vec3 emissive = vec3(0.);
traceAdditive(pos, bounce_direction, payload.hit_t.w, emissive, background);
traceSimpleBlending(pos, bounce_direction, payload.hit_t.w, emissive, background);
const vec3 final_color = emissive + background;

if (brdf_type == DIFFUSE_TYPE)
Expand Down
4 changes: 2 additions & 2 deletions ref/vk/shaders/ray_primary.comp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RAY_PRIMARY_OUTPUTS(X)

layout(set = 0, binding = 1) uniform accelerationStructureEXT tlas;

#include "trace_additive.glsl"
#include "trace_simple_blending.glsl"

struct Ray {
vec3 origin, direction;
Expand Down Expand Up @@ -102,7 +102,7 @@ void main() {
L = rayQueryGetIntersectionTEXT(rq, true);
}

traceAdditive(ray.origin, ray.direction, L, payload.emissive.rgb, payload.base_color_a.rgb);
traceSimpleBlending(ray.origin, ray.direction, L, payload.emissive.rgb, payload.base_color_a.rgb);

imageStore(out_position_t, pix, payload.hit_t);
imageStore(out_base_color_a, pix, payload.base_color_a);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef TRACE_ADDITIVE_GLSL_INCLUDED
#define TRACE_ADDITIVE_GLSL_INCLUDED
#ifndef TRACE_SIMPLE_BLENDING_GLSL_INCLUDED
#define TRACE_SIMPLE_BLENDING_GLSL_INCLUDED

void traceAdditive(vec3 pos, vec3 dir, float L, inout vec3 emissive, inout vec3 background) {
const float additive_soft_overshoot = 16.;
// Traces geometry with simple blending. Simple means that it's only additive or mix/coverage, and it doesn't participate in lighting, and it doesn't reflect/refract rays.
void traceSimpleBlending(vec3 pos, vec3 dir, float L, inout vec3 emissive, inout vec3 background) {
const float glow_soft_overshoot = 16.;

// TODO probably a better way would be to sort only MIX entries.
// ADD/GLOW are order-independent relative to each other, but not to MIX
Expand All @@ -23,7 +24,7 @@ void traceAdditive(vec3 pos, vec3 dir, float L, inout vec3 emissive, inout vec3
//| gl_RayFlagsSkipClosestHitShaderEXT
| gl_RayFlagsNoOpaqueEXT // force all to be non-opaque
;
rayQueryInitializeEXT(rq, tlas, flags, GEOMETRY_BIT_BLEND, pos, 0., dir, L + additive_soft_overshoot);
rayQueryInitializeEXT(rq, tlas, flags, GEOMETRY_BIT_BLEND, pos, 0., dir, L + glow_soft_overshoot);
while (rayQueryProceedEXT(rq)) {
const MiniGeometry geom = readCandidateMiniGeometry(rq);
const Kusok kusok = getKusok(geom.kusok_index);
Expand All @@ -36,7 +37,7 @@ void traceAdditive(vec3 pos, vec3 dir, float L, inout vec3 emissive, inout vec3
#ifdef DEBUG_BLEND_MODES
if (kusok.material.mode == MATERIAL_MODE_BLEND_GLOW) {
emissive += vec3(1., 0., 0.);
//ret += color * smoothstep(additive_soft_overshoot, 0., overshoot);
//ret += color * smoothstep(glow_soft_overshoot, 0., overshoot);
} else if (kusok.material.mode == MATERIAL_MODE_BLEND_ADD) {
emissive += vec3(0., 1., 0.);
} else if (kusok.material.mode == MATERIAL_MODE_BLEND_MIX) {
Expand All @@ -53,7 +54,7 @@ void traceAdditive(vec3 pos, vec3 dir, float L, inout vec3 emissive, inout vec3

if (kusok.material.mode == MATERIAL_MODE_BLEND_GLOW) {
// Glow is additive + small overshoot
const float overshoot_factor = smoothstep(additive_soft_overshoot, 0., overshoot);
const float overshoot_factor = smoothstep(glow_soft_overshoot, 0., overshoot);
color *= overshoot_factor;
alpha = 0.;
} else if (kusok.material.mode == MATERIAL_MODE_BLEND_ADD) {
Expand Down Expand Up @@ -111,4 +112,4 @@ void traceAdditive(vec3 pos, vec3 dir, float L, inout vec3 emissive, inout vec3
background *= revealage;
}

#endif //ifndef TRACE_ADDITIVE_GLSL_INCLUDED
#endif //ifndef TRACE_SIMPLE_BLENDING_GLSL_INCLUDED

0 comments on commit 8ac1a76

Please sign in to comment.