light: fix wrong opacity of trans33/trans66 translucent shadows

- support _light_alpha key in q2 mode
- add q2 translucent shadows testmap
This commit is contained in:
Eric Wasylishen 2022-10-19 00:00:47 -06:00
parent 2a9393cc54
commit c78b0396a9
2 changed files with 155 additions and 12 deletions

View File

@ -38,19 +38,36 @@ sceneinfo filtergeom; // conditional occluders.. needs to run ray intersection f
/**
* Returns 1.0 unless a custom alpha value is set.
* The priority is: "_light_alpha" (read from extended_texinfo_flags), then "alpha"
* The priority is: "_light_alpha" (read from extended_texinfo_flags), then "alpha", then Q2 surface flags
*/
static float Face_Alpha(const modelinfo_t *modelinfo, const mface_t *face)
static float Face_Alpha(const mbsp_t *bsp, const modelinfo_t *modelinfo, const mface_t *face)
{
const surfflags_t &extended_flags = extended_texinfo_flags[face->texinfo];
const int surf_flags = Face_ContentsOrSurfaceFlags(bsp, face);
const bool is_q2 = bsp->loadversion->game->id == GAME_QUAKE_II;
// for _light_alpha, 0 is considered unset
// for "_light_alpha", 0 is considered unset
if (extended_flags.light_alpha) {
return extended_flags.light_alpha;
}
// next check modelinfo alpha (defaults to 1.0)
return modelinfo->alpha.value();
// next check "alpha" key (q1)
if (modelinfo->alpha.isChanged()) {
return modelinfo->alpha.value();
}
// next handle q2 surface flags
if (is_q2) {
if (surf_flags & Q2_SURF_TRANS33) {
return 0.33f;
}
if (surf_flags & Q2_SURF_TRANS66) {
return 0.66f;
}
}
// no alpha requested
return 1.0f;
}
sceneinfo CreateGeometry(
@ -129,16 +146,13 @@ sceneinfo CreateGeometry(
info.switchableshadow = modelinfo->switchableshadow.boolValue();
info.switchshadstyle = modelinfo->switchshadstyle.value();
info.alpha = Face_Alpha(modelinfo, face);
info.alpha = Face_Alpha(bsp, modelinfo, face);
// mxd
if (bsp->loadversion->game->id == GAME_QUAKE_II) {
const int surf_flags = Face_ContentsOrSurfaceFlags(bsp, face);
info.is_fence = surf_flags & Q2_SURF_ALPHATEST;
info.is_glass = !info.is_fence && (surf_flags & (Q2_SURF_TRANS33 | Q2_SURF_TRANS66));
if (info.is_glass) {
info.alpha = (surf_flags & Q2_SURF_TRANS33 ? 0.33f : 0.66f);
}
} else {
const char *name = Face_TextureName(bsp, face);
info.is_fence = (name[0] == '{');
@ -490,7 +504,7 @@ void Embree_TraceInit(const mbsp_t *bsp)
continue;
// handle glass / water
const float alpha = Face_Alpha(model, face);
const float alpha = Face_Alpha(bsp, model, face);
if (alpha < 1.0f ||
(is_q2 && (contents_or_surf_flags & (Q2_SURF_ALPHATEST | Q2_SURF_TRANS33 | Q2_SURF_TRANS66)))) {
filterfaces.push_back(face);
@ -652,8 +666,8 @@ static void AddGlassToRay(RTCIntersectContext *context, unsigned rayIndex, float
// multiply ray color by glass color
qvec3d tinted = rs->_ray_colors[rayIndex] * glasscolor;
// use the lerped color between original ray color and fully tinted, based on opacity
rs->_ray_colors[rayIndex] = mix(tinted, rs->_ray_colors[rayIndex], opacity);
// lerp ray color between original ray color and fully tinted by the glass texture color, based on the glass opacity
rs->_ray_colors[rayIndex] = mix(rs->_ray_colors[rayIndex], tinted, opacity);
}
static void AddDynamicOccluderToRay(RTCIntersectContext *context, unsigned rayIndex, int style)

View File

@ -0,0 +1,129 @@
// Game: Quake 2
// Format: Quake2
// entity 0
{
"classname" "worldspawn"
"_tb_textures" "textures/e1u2;textures/e3u3"
// brush 0
{
( 320 256 192 ) ( 320 32 192 ) ( 320 256 16 ) e1u2/metal4_2 0 32 0 1 1 0 0 0
( 336 -768 16 ) ( 320 -768 16 ) ( 336 -768 192 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( 336 256 16 ) ( 320 256 16 ) ( 336 32 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( 336 32 480 ) ( 320 32 480 ) ( 336 256 480 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( 336 256 192 ) ( 320 256 192 ) ( 336 256 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( 336 32 192 ) ( 336 256 192 ) ( 336 32 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
}
// brush 1
{
( -656 32 16 ) ( -656 256 16 ) ( -656 32 192 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -656 -768 192 ) ( -640 -768 192 ) ( -656 -768 16 ) e1u2/metal4_2 -32 0 0 1 1 0 0 0
( -656 32 16 ) ( -640 32 16 ) ( -656 256 16 ) e1u2/metal4_2 -32 0 0 1 1 0 0 0
( -656 256 480 ) ( -640 256 480 ) ( -656 32 480 ) e1u2/metal4_2 -32 0 0 1 1 0 0 0
( -656 256 16 ) ( -640 256 16 ) ( -656 256 192 ) e1u2/metal4_2 -32 0 0 1 1 0 0 0
( -640 32 16 ) ( -640 32 192 ) ( -640 256 16 ) e1u2/metal4_2 0 32 0 1 1 0 0 0
}
// brush 2
{
( -640 256 192 ) ( -640 240 192 ) ( -640 256 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -64 240 192 ) ( -64 240 16 ) ( -288 240 192 ) e1u2/metal4_2 0 32 0 1 1 0 0 0
( -288 256 16 ) ( -288 240 16 ) ( -64 256 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -64 256 480 ) ( -64 240 480 ) ( -288 256 480 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -64 256 192 ) ( -288 256 192 ) ( -64 256 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( 320 256 16 ) ( 320 240 16 ) ( 320 256 192 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
}
// brush 3
{
( -640 -768 16 ) ( -640 -752 16 ) ( -640 -768 192 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -64 -768 16 ) ( -288 -768 16 ) ( -64 -768 192 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -64 -768 16 ) ( -64 -752 16 ) ( -288 -768 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -288 -768 480 ) ( -288 -752 480 ) ( -64 -768 480 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -288 -752 16 ) ( -64 -752 16 ) ( -288 -752 192 ) e1u2/metal4_2 0 32 0 1 1 0 0 0
( 320 -768 192 ) ( 320 -752 192 ) ( 320 -768 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
}
// brush 4
{
( -640 48 480 ) ( -640 48 464 ) ( -640 240 480 ) e1u2/metal4_2 0 32 0 1 1 0 0 0
( -64 -768 480 ) ( -64 -768 464 ) ( -288 -768 480 ) e1u2/metal4_2 0 32 0 1 1 0 0 0
( -64 240 464 ) ( -288 240 464 ) ( -64 48 464 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -64 240 480 ) ( -64 48 480 ) ( -288 240 480 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -288 240 480 ) ( -288 240 464 ) ( -64 240 480 ) e1u2/metal4_2 0 32 0 1 1 0 0 0
( 320 240 480 ) ( 320 240 464 ) ( 320 48 480 ) e1u2/metal4_2 0 32 0 1 1 0 0 0
}
// brush 5
{
( -640 240 16 ) ( -640 240 32 ) ( -640 48 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -288 -768 16 ) ( -288 -768 32 ) ( -64 -768 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -288 240 16 ) ( -288 48 16 ) ( -64 240 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -288 48 32 ) ( -288 240 32 ) ( -64 48 32 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( -64 240 16 ) ( -64 240 32 ) ( -288 240 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
( 320 48 16 ) ( 320 48 32 ) ( 320 240 16 ) e1u2/metal4_2 0 0 0 1 1 0 0 0
}
// brush 6
{
( -24 -416 32 ) ( -24 -415 32 ) ( -24 -416 33 ) e3u3/color1_2 16 0 0 1 1 64 16 0
( -40 -384 32 ) ( -40 -384 33 ) ( -39 -384 32 ) e3u3/color1_2 -56 0 0 1 1 64 16 0
( -40 -416 32 ) ( -39 -416 32 ) ( -40 -415 32 ) e3u3/color1_2 -56 -16 0 1 1 64 16 0
( -8 -352 128 ) ( -8 -351 128 ) ( -7 -352 128 ) e3u3/color1_2 -56 -16 0 1 1 64 16 0
( -8 -352 64 ) ( -7 -352 64 ) ( -8 -352 65 ) e3u3/color1_2 -56 0 0 1 1 64 16 0
( -8 -352 64 ) ( -8 -352 65 ) ( -8 -351 64 ) e3u3/color1_2 16 0 0 1 1 64 16 0
}
// brush 7
{
( -288 -368 52 ) ( -288 -368 51 ) ( -288 -367 52 ) e1u2/pillar1_1 48 12 0 1 -1
( -288 -368 52 ) ( -287 -368 52 ) ( -288 -368 51 ) e1u2/pillar1_1 0 12 0 1 -1
( -256 -304 32 ) ( -255 -304 32 ) ( -256 -303 32 ) e1u2/pillar1_1 0 -48 0 1 1
( -288 -368 52 ) ( -288 -367 52 ) ( -287 -368 52 ) e1u2/pillar1_1 0 -48 0 1 1
( -256 -304 20 ) ( -256 -304 19 ) ( -255 -304 20 ) e1u2/pillar1_1 0 12 0 1 -1
( -256 -304 20 ) ( -256 -303 20 ) ( -256 -304 19 ) e1u2/pillar1_2 48 12 0 1 -1
}
// brush 8
{
( -24 -480 32 ) ( -24 -479 32 ) ( -24 -480 33 ) e3u3/color1_2 16 0 0 1 1 64 32 0
( -40 -448 32 ) ( -40 -448 33 ) ( -39 -448 32 ) e3u3/color1_2 -56 0 0 1 1 64 32 0
( -40 -480 32 ) ( -39 -480 32 ) ( -40 -479 32 ) e3u3/color1_2 -56 -16 0 1 1 64 32 0
( -8 -416 128 ) ( -8 -415 128 ) ( -7 -416 128 ) e3u3/color1_2 -56 -16 0 1 1 64 32 0
( -8 -416 64 ) ( -7 -416 64 ) ( -8 -416 65 ) e3u3/color1_2 -56 0 0 1 1 64 32 0
( -8 -416 64 ) ( -8 -416 65 ) ( -8 -415 64 ) e3u3/color1_2 16 0 0 1 1 64 32 0
}
}
// entity 1
{
"classname" "info_player_start"
"origin" "-448 -336 56"
}
// entity 2
{
"classname" "light"
"origin" "-248 -336 44"
"angle" "60"
"mangle" "0 5 0"
"light" "750"
}
// entity 3
{
"classname" "func_group"
"_shadow" "-1"
// brush 0
{
( -24 -288 32 ) ( -24 -287 32 ) ( -24 -288 33 ) e3u3/color1_2 16 0 0 1 1 64 16 0
( -40 -256 32 ) ( -40 -256 33 ) ( -39 -256 32 ) e3u3/color1_2 -56 0 0 1 1 64 16 0
( -40 -288 32 ) ( -39 -288 32 ) ( -40 -287 32 ) e3u3/color1_2 -56 -16 0 1 1 64 16 0
( -8 -224 128 ) ( -8 -223 128 ) ( -7 -224 128 ) e3u3/color1_2 -56 -16 0 1 1 64 16 0
( -8 -224 64 ) ( -7 -224 64 ) ( -8 -224 65 ) e3u3/color1_2 -56 0 0 1 1 64 16 0
( -8 -224 64 ) ( -8 -224 65 ) ( -8 -223 64 ) e3u3/color1_2 16 0 0 1 1 64 16 0
}
}
// entity 4
{
"classname" "func_group"
"_light_alpha" "0.15"
// brush 0
{
( -24 -352 32 ) ( -24 -351 32 ) ( -24 -352 33 ) e3u3/color1_2 16 0 0 1 1 64 16 0
( -40 -320 32 ) ( -40 -320 33 ) ( -39 -320 32 ) e3u3/color1_2 -56 0 0 1 1 64 16 0
( -40 -352 32 ) ( -39 -352 32 ) ( -40 -351 32 ) e3u3/color1_2 -56 -16 0 1 1 64 16 0
( -8 -288 128 ) ( -8 -287 128 ) ( -7 -288 128 ) e3u3/color1_2 -56 -16 0 1 1 64 16 0
( -8 -288 64 ) ( -7 -288 64 ) ( -8 -288 65 ) e3u3/color1_2 -56 0 0 1 1 64 16 0
( -8 -288 64 ) ( -8 -288 65 ) ( -8 -287 64 ) e3u3/color1_2 16 0 0 1 1 64 16 0
}
}