From 2ed9c6a968e35db45e894ae8ebf447cc8982f660 Mon Sep 17 00:00:00 2001 From: Spoike Date: Mon, 17 Jan 2022 09:13:05 +0000 Subject: [PATCH] Proper support for lit sprites. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6167 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/gl/gl_alias.c | 6 ++++++ engine/gl/gl_model.c | 19 +++++++++++-------- engine/gl/gl_model.h | 1 + engine/shaders/glsl/defaultsprite.glsl | 8 ++------ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/engine/gl/gl_alias.c b/engine/gl/gl_alias.c index f76ac2226..597cb310c 100644 --- a/engine/gl/gl_alias.c +++ b/engine/gl/gl_alias.c @@ -2733,6 +2733,12 @@ static void R_Sprite_GenerateTrisoup(entity_t *e, int bemode) } VectorScale(e->shaderRGBAf, lightmap, rgba[0]); + if (frame && frame->lit && !(r_refdef.flags & RDF_NOWORLDMODEL) && cl.worldmodel && cl.worldmodel->funcs.LightPointValues) + { + R_CalcModelLighting(e, e->model); + VectorMul(rgba[0], e->light_avg, rgba[0]); + VectorMA(rgba[0], 0.5, e->light_range, rgba[0]); + } rgba[0][3] = e->shaderRGBAf[3]; Vector4Copy(rgba[0], rgba[1]); Vector4Copy(rgba[0], rgba[2]); diff --git a/engine/gl/gl_model.c b/engine/gl/gl_model.c index 6c8845994..43deefd2d 100644 --- a/engine/gl/gl_model.c +++ b/engine/gl/gl_model.c @@ -5655,7 +5655,7 @@ void Mod_LoadDoomSprite (model_t *mod) //we need to override the rtlight shader for sprites so they get lit properly ignoring n+s+t dirs //so lets split the shader into parts to avoid too many dupes -#define SPRITE_SHADER_MAIN \ +#define SPRITE_SHADER_MAIN(extra) \ "{\n" \ "if gl_blendsprites\n" \ "program defaultsprite\n" \ @@ -5675,9 +5675,12 @@ void Mod_LoadDoomSprite (model_t *mod) "rgbgen vertex\n" \ "alphagen vertex\n" \ "}\n" \ - "surfaceparm noshadows\n" -#define SPRITE_SHADER_UNLIT "surfaceparm nodlight\n" -#define SPRITE_SHADER_LIT \ + "surfaceparm noshadows\n" \ + extra \ + "}\n" +#define SPRITE_SHADER_UNLIT SPRITE_SHADER_MAIN( \ + "surfaceparm nodlight\n") +#define SPRITE_SHADER_LIT SPRITE_SHADER_MAIN( \ "sort seethrough\n" \ "bemode rtlight\n" \ "{\n" \ @@ -5686,8 +5689,7 @@ void Mod_LoadDoomSprite (model_t *mod) "map $diffuse\n" \ "blendfunc add\n" \ "}\n" \ - "}\n" -#define SPRITE_SHADER_FOOTER "}\n" + "}\n") void Mod_LoadSpriteFrameShader(model_t *spr, int frame, int subframe, mspriteframe_t *frameinfo) { @@ -5733,9 +5735,10 @@ void Mod_LoadSpriteFrameShader(model_t *spr, int frame, int subframe, mspritefra #endif if (litsprite) // a ! in the filename makes it non-fullbright (and can also be lit by rtlights too). - shadertext = SPRITE_SHADER_MAIN SPRITE_SHADER_LIT SPRITE_SHADER_FOOTER; + shadertext = SPRITE_SHADER_LIT; else - shadertext = SPRITE_SHADER_MAIN SPRITE_SHADER_UNLIT SPRITE_SHADER_FOOTER; + shadertext = SPRITE_SHADER_UNLIT; + frameinfo->lit = litsprite; frameinfo->shader = R_RegisterShader(name, SUF_NONE, shadertext); frameinfo->shader->defaulttextures->base = frameinfo->image; frameinfo->shader->width = frameinfo->right-frameinfo->left; diff --git a/engine/gl/gl_model.h b/engine/gl/gl_model.h index 97413868b..18edb368d 100644 --- a/engine/gl/gl_model.h +++ b/engine/gl/gl_model.h @@ -627,6 +627,7 @@ typedef struct mspriteframe_s { float up, down, left, right; qboolean xmirror; + qboolean lit; shader_t *shader; image_t *image; } mspriteframe_t; diff --git a/engine/shaders/glsl/defaultsprite.glsl b/engine/shaders/glsl/defaultsprite.glsl index 3199554ba..edef05ea5 100644 --- a/engine/shaders/glsl/defaultsprite.glsl +++ b/engine/shaders/glsl/defaultsprite.glsl @@ -3,12 +3,11 @@ //used by both particles and sprites. //note the fog blending mode is all that differs from defaultadditivesprite +#include "sys/defs.h" #include "sys/fog.h" -#ifdef VERTEX_SHADER -attribute vec2 v_texcoord; -attribute vec4 v_colour; varying vec2 tc; varying vec4 vc; +#ifdef VERTEX_SHADER void main () { tc = v_texcoord; @@ -17,9 +16,6 @@ void main () } #endif #ifdef FRAGMENT_SHADER -varying vec2 tc; -varying vec4 vc; -uniform vec4 e_colourident; uniform vec4 e_vlscale; void main () {