From a01c88707d7bc27c3ffa3a6d977e98a1f9c1f197 Mon Sep 17 00:00:00 2001 From: myT <> Date: Fri, 29 Mar 2024 04:05:35 +0100 Subject: [PATCH] parsing the q3map_sun[Ext] shader directives --- code/renderer/tr_bsp.cpp | 1 + code/renderer/tr_local.h | 7 +++++++ code/renderer/tr_shader.cpp | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/code/renderer/tr_bsp.cpp b/code/renderer/tr_bsp.cpp index d773783..b6f5d4d 100644 --- a/code/renderer/tr_bsp.cpp +++ b/code/renderer/tr_bsp.cpp @@ -1499,6 +1499,7 @@ static void R_LoadFogs( const lump_t* l, const lump_t* brushesLump, const lump_t // get information from the shader for fog parameters shader_t* shader = R_FindShader( fogs->shader, LIGHTMAP_NONE, FINDSHADER_MIPRAWIMAGE_BIT ); + shader->isFog = qtrue; out->parms = shader->fogParms; diff --git a/code/renderer/tr_local.h b/code/renderer/tr_local.h index 5e7d0cf..0812410 100644 --- a/code/renderer/tr_local.h +++ b/code/renderer/tr_local.h @@ -415,6 +415,12 @@ struct shader_t { float dfInvDist; float dfBias; + // Radiant sun information from the sky shader + qbool isSunDataValid; + vec3_t sunColor; + float sunAzimuth; + float sunInclination; + qbool greyscaleCTF; // extra info for /shaderinfo @@ -429,6 +435,7 @@ struct shader_t { qbool isAlphaTestedOpaque; // no alpha blending, first stage is alpha tested qbool isDynamic; // at least one vertex attribute must be generated on the fly qbool hasLightmapStage; + qbool isFog; pipeline_t pipelines[MAX_SHADER_STAGES]; int numPipelines; diff --git a/code/renderer/tr_shader.cpp b/code/renderer/tr_shader.cpp index b2b0e51..62dab03 100644 --- a/code/renderer/tr_shader.cpp +++ b/code/renderer/tr_shader.cpp @@ -1314,6 +1314,37 @@ static void ParseSurfaceParm( const char** text ) } +static qbool ParseFloat( float* out, const char** text, const char* commandName, int argIndex ) +{ + const char* const token = COM_ParseExt( text, qfalse ); + if ( token[0] == '\0' || sscanf( token, "%f", out ) != 1 ) { + ParserWarning( "invalid/missing %s argument #%d", commandName, argIndex ); + return qfalse; + } + + return qtrue; +} + + +// q3map_sun R G B intensity azimuth elevation +// q3map_sunExt R G B intensity azimuth elevation shadow_degrees samples + +static void ParseSun( const char** text ) +{ + float v[6]; + for ( int i = 0; i < ARRAY_LEN( v ); i++ ) { + if ( !ParseFloat( &v[i], text, "q3map_sun", i + 1 ) ) { + return; + } + } + + shader.isSunDataValid = qtrue; + VectorSet( shader.sunColor, v[0], v[1], v[2] ); + shader.sunAzimuth = v[4]; + shader.sunInclination = 90.0f - v[5]; +} + + // q3map_cnq3_depthFade static void ParseDepthFade( const char** text ) @@ -1407,6 +1438,10 @@ static qbool ParseShader( const char** text ) ParseDepthFade( text ); continue; } + else if ( !Q_stricmp( token, "q3map_sun" ) || !Q_stricmp( token, "q3map_sunExt" ) ) { + ParseSun( text ); + SkipRestOfLine( text ); + } // skip stuff that only the q3map needs else if ( !Q_stricmpn( token, "q3map", 5 ) ) { SkipRestOfLine( text );