mirror of
https://github.com/w23/xash3d-fwgs
synced 2025-01-18 23:00:01 +01:00
rt: linearize alpha value for blending
This makes transparent brushes look more correct. But also makes sprites look a bit dull. Fixes #528
This commit is contained in:
parent
8ac1a76259
commit
3447dfc5d6
@ -1,4 +1,4 @@
|
||||
#define SRGB_FAST_APPROXIMATION 0
|
||||
#define SRGB_FAST_APPROXIMATION
|
||||
|
||||
#ifdef SRGB_FAST_APPROXIMATION
|
||||
#define LINEARtoSRGB OECF_sRGBFast
|
||||
@ -32,6 +32,9 @@ vec4 sRGB_OECF(const vec4 sRGB)
|
||||
vec3 sRGB_OECFFast(const vec3 sRGB) {
|
||||
return pow(sRGB, vec3(2.2));
|
||||
}
|
||||
float sRGB_OECFFast(const float sRGB) {
|
||||
return pow(sRGB, 2.2);
|
||||
}
|
||||
vec4 sRGB_OECFFast(const vec4 sRGB) {
|
||||
return vec4(pow(sRGB.rgb, vec3(2.2)), sRGB.w);
|
||||
}
|
||||
|
@ -49,8 +49,12 @@ void traceSimpleBlending(vec3 pos, vec3 dir, float L, inout vec3 emissive, inout
|
||||
}
|
||||
#else
|
||||
const vec4 texture_color = texture(textures[nonuniformEXT(kusok.material.tex_base_color)], geom.uv);
|
||||
float alpha = texture_color.a * kusok.model.color.a * geom.vertex_color.a;
|
||||
vec3 color = kusok.model.color.rgb * texture_color.rgb * SRGBtoLINEAR(geom.vertex_color.rgb) * alpha;
|
||||
|
||||
// "Linearizing" alpha, while looking weird conceptually in the code, is necessary to make it look close to the original.
|
||||
// TODO figure out whether texture alpha needs to be linearized too. Don't have good examples to look at.
|
||||
// TODO this also makes sprites look dull, so likely kusok.model.color linearization should only apply to brush models, not sprites. This is better done when passing brush model to ray tracer.
|
||||
float alpha = SRGBtoLINEAR(texture_color.a * kusok.model.color.a) * geom.vertex_color.a;
|
||||
vec3 color = kusok.model.color.rgb * SRGBtoLINEAR(texture_color.rgb) * geom.vertex_color.rgb * alpha;
|
||||
|
||||
if (kusok.material.mode == MATERIAL_MODE_BLEND_GLOW) {
|
||||
// Glow is additive + small overshoot
|
||||
|
Loading…
x
Reference in New Issue
Block a user