Skip to content

Commit d426ea8

Browse files
committed
Done #713
1 parent b33d6e0 commit d426ea8

File tree

3 files changed

+141
-12
lines changed

3 files changed

+141
-12
lines changed

Build/svencoop/renderer/shader/wsurf_shader.frag.glsl

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,10 @@ vec2 ParallaxMapping(vec3 T, vec3 B, vec3 N, vec3 viewDirWorld, vec2 baseTexcoor
203203

204204
#endif
205205

206-
void main()
206+
vec4 SampleDiffuseTexture(vec2 baseTexcoord)
207207
{
208-
ClipPlaneTest(v_worldpos.xyz, v_normal.xyz);
209-
210-
vec2 baseTexcoord = vec2(0.0, 0.0);
211-
212-
#if defined(DIFFUSE_ENABLED)
213-
214-
baseTexcoord = v_diffusetexcoord.xy;
215208

216-
#if defined(PARALLAXTEXTURE_ENABLED)
209+
#if defined(PARALLAXTEXTURE_ENABLED)
217210

218211
vec3 viewDir = normalize(v_worldpos.xyz - GetCameraViewPos(GetCameraViewIndex()));
219212

@@ -238,6 +231,19 @@ void main()
238231

239232
#endif
240233

234+
return diffuseColor;
235+
}
236+
237+
void main()
238+
{
239+
ClipPlaneTest(v_worldpos.xyz, v_normal.xyz);
240+
241+
vec2 baseTexcoord = v_diffusetexcoord.xy;
242+
243+
#if defined(DIFFUSE_ENABLED)
244+
245+
vec4 diffuseColor = SampleDiffuseTexture(baseTexcoord);
246+
241247
diffuseColor = ProcessDiffuseColor(diffuseColor);
242248

243249
#else
@@ -343,6 +349,17 @@ void main()
343349

344350
out_Diffuse = vec4(flDistanceToFragment, 0.0, 0.0, 1.0);
345351

352+
#elif defined(GLOW_COLOR_ENABLED)
353+
354+
#if defined(ALPHA_SOLID_ENABLED)
355+
vec4 diffuseColor = SampleDiffuseTexture(v_texcoord);
356+
357+
if(diffuseColor.a < 0.5)
358+
discard;
359+
#endif
360+
361+
out_Diffuse = vec4(EntityUBO.r_color.xyz, 1.0);
362+
346363
#else
347364

348365
#if defined(GBUFFER_ENABLED)

Plugins/Renderer/gl_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ class CIndirectDrawAttrib
309309
#define WSURF_REVERT_NORMAL_ENABLED 0x10000000ull
310310
#define WSURF_MULTIVIEW_ENABLED 0x20000000ull
311311
#define WSURF_LINEAR_DEPTH_ENABLED 0x40000000ull
312+
#define WSURF_GLOW_COLOR_ENABLED 0x80000000ull
313+
#define WSURF_STENCIL_NO_GLOW_BLUR_ENABLED 0x100000000ull
314+
#define WSURF_STENCIL_NO_GLOW_COLOR_ENABLED 0x200000000ull
315+
#define WSURF_DOUBLE_FACE_ENABLED 0x400000000ull
316+
312317

313318
#define STUDIO_VBO_BASE 0
314319
#define STUDIO_VBO_TBN 1

Plugins/Renderer/gl_wsurf.cpp

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,6 +2857,34 @@ void R_DrawWorldSurfaceLeafStatic(CWorldSurfaceModel* pModel, CWorldSurfaceLeaf*
28572857
WSurfProgramState |= WSURF_SHADOW_CASTER_ENABLED;
28582858
}
28592859

2860+
else if (R_ShouldDrawGlowStencilEnableDepthTest())
2861+
{
2862+
//Don't draw color, double side
2863+
WSurfProgramState |= WSURF_STENCIL_NO_GLOW_COLOR_ENABLED | WSURF_DOUBLE_FACE_ENABLED | WSURF_SHADOW_CASTER_ENABLED;
2864+
}
2865+
else if (R_ShouldDrawGlowStencilWallHackBehindWallOnly())
2866+
{
2867+
//Don't draw color
2868+
WSurfProgramState |= WSURF_STENCIL_NO_GLOW_COLOR_ENABLED | WSURF_STENCIL_NO_GLOW_BLUR_ENABLED | WSURF_SHADOW_CASTER_ENABLED;
2869+
}
2870+
else if (R_ShouldDrawGlowStencilWallHack())
2871+
{
2872+
//Don't draw color
2873+
WSurfProgramState |= WSURF_STENCIL_NO_GLOW_BLUR_ENABLED | WSURF_SHADOW_CASTER_ENABLED;
2874+
}
2875+
else if (R_ShouldDrawGlowStencil())
2876+
{
2877+
WSurfProgramState |= WSURF_STENCIL_NO_GLOW_BLUR_ENABLED;
2878+
}
2879+
else if (R_ShouldDrawGlowColor() || R_ShouldDrawGlowColorWallHack())
2880+
{
2881+
WSurfProgramState |= WSURF_GLOW_COLOR_ENABLED;
2882+
}
2883+
else if (R_ShouldDrawGlowColorWallHackBehindWallOnly())
2884+
{
2885+
WSurfProgramState |= WSURF_GLOW_COLOR_ENABLED | WSURF_DOUBLE_FACE_ENABLED;
2886+
}
2887+
28602888
if (R_IsRenderingMultiView())
28612889
{
28622890
WSurfProgramState |= WSURF_MULTIVIEW_ENABLED;
@@ -2933,13 +2961,57 @@ void R_DrawWorldSurfaceLeafStatic(CWorldSurfaceModel* pModel, CWorldSurfaceLeaf*
29332961

29342962
R_DrawWorldSurfaceLeafBegin(pLeaf);
29352963

2936-
if (r_draw_opaque)
2964+
if (R_ShouldDrawGlowColorWallHackBehindWallOnly())
29372965
{
2938-
GL_BeginStencilWrite(STENCIL_MASK_HAS_DECAL, STENCIL_MASK_ALL);
2966+
GL_BeginStencilCompareNotEqual(STENCIL_MASK_NO_GLOW_COLOR, STENCIL_MASK_NO_GLOW_COLOR);
2967+
}
2968+
else if (R_ShouldDrawGlowColorWallHack())
2969+
{
2970+
2971+
}
2972+
else if (R_ShouldDrawGlowColor())
2973+
{
2974+
29392975
}
29402976
else
29412977
{
2942-
GL_BeginStencilWrite(STENCIL_MASK_HAS_DECAL, STENCIL_MASK_HAS_DECAL);
2978+
if (r_draw_opaque)
2979+
{
2980+
int iStencilRef = STENCIL_MASK_HAS_DECAL;
2981+
int iStencilMask = STENCIL_MASK_ALL;
2982+
2983+
if (WSurfProgramState & WSURF_STENCIL_NO_GLOW_BLUR_ENABLED)
2984+
iStencilRef |= STENCIL_MASK_NO_GLOW_BLUR;
2985+
2986+
if (WSurfProgramState & WSURF_STENCIL_NO_GLOW_COLOR_ENABLED)
2987+
iStencilRef |= STENCIL_MASK_NO_GLOW_COLOR;
2988+
2989+
GL_BeginStencilWrite(iStencilRef, iStencilMask);
2990+
}
2991+
else
2992+
{
2993+
int iStencilRef = STENCIL_MASK_HAS_DECAL;
2994+
int iStencilMask = STENCIL_MASK_HAS_DECAL;
2995+
2996+
if (WSurfProgramState & WSURF_STENCIL_NO_GLOW_BLUR_ENABLED)
2997+
{
2998+
iStencilRef |= STENCIL_MASK_NO_GLOW_BLUR;
2999+
iStencilMask |= STENCIL_MASK_NO_GLOW_BLUR;
3000+
}
3001+
3002+
if (WSurfProgramState & WSURF_STENCIL_NO_GLOW_COLOR_ENABLED)
3003+
{
3004+
iStencilRef |= STENCIL_MASK_NO_GLOW_COLOR;
3005+
iStencilMask |= STENCIL_MASK_NO_GLOW_COLOR;
3006+
}
3007+
3008+
GL_BeginStencilWrite(iStencilRef, iStencilMask);
3009+
}
3010+
}
3011+
3012+
if (WSurfProgramState & WSURF_DOUBLE_FACE_ENABLED)
3013+
{
3014+
glDisable(GL_CULL_FACE);
29433015
}
29443016

29453017
wsurf_program_t prog = { 0 };
@@ -2953,6 +3025,8 @@ void R_DrawWorldSurfaceLeafStatic(CWorldSurfaceModel* pModel, CWorldSurfaceLeaf*
29533025

29543026
GL_UseProgram(0);
29553027

3028+
glEnable(GL_CULL_FACE);
3029+
29563030
R_DrawWorldSurfaceLeafEnd();
29573031
}
29583032

@@ -3366,6 +3440,9 @@ void R_DrawWorldSurfaceModel(const std::shared_ptr<CWorldSurfaceModel>& pModel,
33663440
{
33673441
GL_BeginDebugGroupFormat("R_DrawWorldSurfaceModel - %s", ent->model ? ent->model->name : "<empty>");
33683442

3443+
bool bOriginalDiffuseTexture = g_WorldSurfaceRenderer.bDiffuseTexture;
3444+
bool bOriginalLightmapTexture = g_WorldSurfaceRenderer.bLightmapTexture;
3445+
33693446
entity_ubo_t EntityUBO;
33703447
Matrix4x4_Transpose(EntityUBO.r_entityMatrix, r_entity_matrix);
33713448
memcpy(EntityUBO.r_color, r_entity_color, sizeof(vec4));
@@ -3380,6 +3457,8 @@ void R_DrawWorldSurfaceModel(const std::shared_ptr<CWorldSurfaceModel>& pModel,
33803457
EntityUBO.r_color[3] = 1;
33813458

33823459
EntityUBO.r_scale = max((*currententity)->curstate.renderamt * 0.05f, 0.05f);
3460+
3461+
//TODO bind shellchrome?
33833462
}
33843463
else if (
33853464
R_ShouldDrawGlowColor() ||
@@ -3392,11 +3471,17 @@ void R_DrawWorldSurfaceModel(const std::shared_ptr<CWorldSurfaceModel>& pModel,
33923471
EntityUBO.r_color[3] = (*r_blend);
33933472

33943473
EntityUBO.r_scale = max((*currententity)->curstate.renderamt * 0.05f, 0.05f);
3474+
3475+
g_WorldSurfaceRenderer.bDiffuseTexture = false;
3476+
g_WorldSurfaceRenderer.bLightmapTexture = false;
33953477
}
33963478
else if (R_ShouldDrawGlowStencilEnableDepthTest())
33973479
{
33983480
//Same size as DrawGlowColor
33993481
EntityUBO.r_scale = max((*currententity)->curstate.renderamt * 0.05f, 0.05f) + 0.05f;
3482+
3483+
g_WorldSurfaceRenderer.bDiffuseTexture = false;
3484+
g_WorldSurfaceRenderer.bLightmapTexture = false;
34003485
}
34013486

34023487
GL_UploadSubDataToUBO(g_WorldSurfaceRenderer.hEntityUBO, 0, sizeof(EntityUBO), &EntityUBO);
@@ -3541,6 +3626,25 @@ void R_DrawWorldSurfaceModel(const std::shared_ptr<CWorldSurfaceModel>& pModel,
35413626
R_DrawWorldSurfaceLeafAnim(pModel.get(), pLeaf.get());
35423627
}
35433628
}
3629+
3630+
if (!R_IsRenderingGlowColor() && !R_IsRenderingGlowStencil() && !R_IsRenderingGlowStencilEnableDepthTest())
3631+
{
3632+
if ((*currententity)->curstate.renderfx == kRenderFxPostProcessGlow)
3633+
{
3634+
g_PostProcessGlowColorEntities.emplace_back((*currententity));
3635+
}
3636+
else if ((*currententity)->curstate.renderfx == kRenderFxPostProcessGlowWallHack)
3637+
{
3638+
g_PostProcessGlowStencilEntities.emplace_back((*currententity));
3639+
g_PostProcessGlowColorEntities.emplace_back((*currententity));
3640+
}
3641+
else if ((*currententity)->curstate.renderfx == kRenderFxPostProcessGlowWallHackBehindWallOnly)
3642+
{
3643+
g_PostProcessGlowStencilEntities.emplace_back((*currententity));
3644+
g_PostProcessGlowEnableDepthTestStencilEntities.emplace_back((*currententity));
3645+
g_PostProcessGlowColorEntities.emplace_back((*currententity));
3646+
}
3647+
}
35443648
}
35453649

35463650
R_DrawDecals(ent);
@@ -3556,6 +3660,9 @@ void R_DrawWorldSurfaceModel(const std::shared_ptr<CWorldSurfaceModel>& pModel,
35563660
}
35573661
}
35583662

3663+
g_WorldSurfaceRenderer.bDiffuseTexture = bOriginalDiffuseTexture;
3664+
g_WorldSurfaceRenderer.bLightmapTexture = bOriginalLightmapTexture;
3665+
35593666
if (pLeaf)
35603667
{
35613668
R_DrawWaters(pModel.get(), pLeaf.get(), ent);

0 commit comments

Comments
 (0)