Skip to content

Commit

Permalink
rt: make emissive surfaces ignore external light
Browse files Browse the repository at this point in the history
this is not fully correct, but it fixes slightly off sprite colors for now
  • Loading branch information
w23 committed Feb 24, 2023
1 parent 41809b8 commit a5b977c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
32 changes: 10 additions & 22 deletions ref/vk/shaders/denoiser.comp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ layout(set = 0, binding = 17, rgba16f) uniform image2D prev_temporal_specular;

const int INDIRECT_SCALE = 2;

//layout(set = 0, binding = 2, rgba16f) uniform readonly image2D light_poly_diffuse;
/* layout(set = 0, binding = 3, rgba16f) uniform readonly image2D specular; */
/* layout(set = 0, binding = 4, rgba16f) uniform readonly image2D additive; */
/* layout(set = 0, binding = 5, rgba16f) uniform readonly image2D normals; */
/* layout(set = 0, binding = 6, rgba32f) uniform readonly image2D position_t; */
//#define DEBUG_TEXTURE normals_gs
//#define DEBUG_TEXTURE emissive
//#define DEBUG_TEXTURE light_point_diffuse

// Blatantly copypasted from https://www.shadertoy.com/view/XsGfWV
vec3 aces_tonemap(vec3 color){
Expand Down Expand Up @@ -192,26 +190,16 @@ void main() {
/* imageStore(out_dest, pix, vec4(sqrt(float(pix.x) / res.x))); return; */
/* } */

//const float material_index = imageLoad(light_poly, pix).a;

//imageStore(out_dest, pix, vec4(aces_tonemap(base_color_a.rgb), 0.)); return;
//imageStore(out_dest, pix, vec4((base_color_a.rgb), 0.)); return;
//imageStore(out_dest, pix, vec4(fract(imageLoad(position_t, pix).rgb / 10.), 0.)); return;
//imageStore(out_dest, pix, vec4((imageLoad(light_poly, pix).rgb), 0.)); return;
//imageStore(out_dest, pix, vec4((imageLoad(light_poly, pix).rgb * base_color_a.rgb), 0.)); return;
//imageStore(out_dest, pix, vec4(imageLoad(normals, pix)*.5 + .5f)); return;
//imageStore(out_dest, pix, vec4(imageLoad(specular, pix)*.5 + .5f)); return;
//imageStore(out_dest, pix, vec4(imageLoad(indirect_diffuse, pix)*.5 + .5f)); return;
//imageStore(out_dest, pix, vec4(aces_tonemap(imageLoad(light_poly, pix).rgb), 0.)); return;
//imageStore(out_dest, pix, vec4(aces_tonemap(imageLoad(specular, pix).rgb), 0.)); return;
//imageStore(out_dest, pix, vec4(aces_tonemap(imageLoad(indirect_diffuse, pix).rgb), 0.)); return;

/*
#if defined(DEBUG_TEXTURE)
imageStore(out_dest, pix, vec4(LINEARtoSRGB(imageLoad(DEBUG_TEXTURE, pix).rgb), 0.)); return;
#endif

#if 0
vec3 geometry_normal, shading_normal;
readNormals(pix, geometry_normal, shading_normal);
*/

//imageStore(out_dest, pix, vec4(.5 + geometry_normal * .5, 0.)); return;
imageStore(out_dest, pix, vec4(.5 + shading_normal * .5, 0.)); return;
#endif

/* const uint mi = uint(material_index); */
/* imageStore(out_dest, pix, vec4(rand3_f01(uvec3(mi,mi+1,mi+2)), 0.)); */
Expand Down
4 changes: 3 additions & 1 deletion ref/vk/shaders/ray_primary_hit.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void primaryRayHit(rayQueryEXT rq, inout RayPayloadPrimary payload) {
payload.emissive.rgb = SRGBtoLINEAR(texture(skybox, rayDirection).rgb);
return;
} else {
payload.base_color_a = sampleTexture(tex_base_color, geom.uv, geom.uv_lods) * kusok.color;
payload.base_color_a = sampleTexture(tex_base_color, geom.uv, geom.uv_lods);
payload.material_rmxx.r = (kusok.tex_roughness > 0) ? sampleTexture(kusok.tex_roughness, geom.uv, geom.uv_lods).r : kusok.roughness;
payload.material_rmxx.g = (kusok.tex_metalness > 0) ? sampleTexture(kusok.tex_metalness, geom.uv, geom.uv_lods).r : kusok.metalness;

Expand Down Expand Up @@ -63,6 +63,8 @@ void primaryRayHit(rayQueryEXT rq, inout RayPayloadPrimary payload) {
if (any(greaterThan(kusok.emissive, vec3(0.))))
payload.emissive.rgb = payload.base_color_a.rgb;
#endif

payload.base_color_a *= kusok.color;
}

#endif // ifndef RAY_PRIMARY_HIT_GLSL_INCLUDED
3 changes: 2 additions & 1 deletion ref/vk/vk_ray_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr
}

if (geom->material == kXVkMaterialEmissive) {
VectorCopy( geom->emissive, kusok->emissive );
VectorCopy(geom->emissive, kusok->emissive);
Vector4Set(kusok->color, 0, 0, 0, 0); // Do not accept light from outside
} else {
RT_GetEmissiveForTexture( kusok->emissive, geom->texture );
}
Expand Down

0 comments on commit a5b977c

Please sign in to comment.