Skip to content

Commit

Permalink
Merge pull request #978 from qw-ctf/skywind
Browse files Browse the repository at this point in the history
RENDERER: Add support for skywind.
  • Loading branch information
tcsabina authored Dec 29, 2024
2 parents 93e6660 + d7e91ef commit 9a79c98
Show file tree
Hide file tree
Showing 14 changed files with 382 additions and 7 deletions.
18 changes: 18 additions & 0 deletions help_commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,24 @@
"description": "In basics works same as mapgroup.",
"syntax": "skyboxname map1 [map2] ..."
},
"skywind": {
"description": "Sets the animation parameters of the skybox. Requires a skybox with some level of transparency.",
"syntax": "skywind [distance] [yaw] [period] [pitch]"
},
"skywind_save": {
"description": "Saves the current skywind configuration as gfx/env/$skybox_wind.cfg."
},
"skywind_load": {
"description": "Loads the skywind config for the loaded skymap. The file is expected to contain: skywind [distance] [yaw] [period] [pitch]."
},
"skywind_lookdir": {
"description": "Updates the skywind direction to current point of view with optional overrides of period and distance.",
"syntax": "skywind_lookdir [period] [distance]"
},
"skywind_rotate": {
"description": "Updates the skywind direction with yaw (horizontal) and pitch (vertical) adjustment.",
"syntax": "skywind_rotate [yaw] [pitch]"
},
"snap": {
"description": "Remote screenshot from a player.\n\nExample:\nsnap 1234\n - server requests remote screenshot from user 1234",
"syntax": "<userid>"
Expand Down
7 changes: 7 additions & 0 deletions help_variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -16590,6 +16590,13 @@
"remarks": "Specifying a value will disable loading of skyboxes specified by the map.\nSkyboxes should be placed in 'env' or 'gfx/env' folders",
"type": "string"
},
"r_skywind": {
"default": "1",
"desc": "Sets the scale factor of skybox animation if above 0, and skybox has an animation configuration.",
"group-id": "51",
"remarks": "Specifying a value above 1.0 will increase the pace of the configured animation.",
"type": "float"
},
"r_slimecolor": {
"default": "10 60 10",
"desc": "Changes color of slime when r_fastturb set to 1.",
Expand Down
2 changes: 2 additions & 0 deletions src/gl_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ static r_program_uniform_t program_uniforms[] = {
{ r_program_sky_glc, "skySpeedscale2", 1, false },
// r_program_uniform_sky_glc_skyTex,
{ r_program_sky_glc, "skyTex", 1, false },
// r_program_uniform_sky_glc_skyWind,
{ r_program_sky_glc, "skyWind", 1, false },
// r_program_uniform_sky_glc_skyDomeTex,
{ r_program_sky_glc, "skyDomeTex", 1, false },
// r_program_uniform_sky_glc_skyDomeCloudTex,
Expand Down
11 changes: 11 additions & 0 deletions src/glc_sky.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,24 @@ static qbool R_DetermineSkyLimits(qbool *ignore_z)
}

#define PROGRAMFLAGS_SKYBOX 1
#define PROGRAMFLAGS_SKYWIND 2

qbool GLC_SkyProgramCompile(void)
{
int flags = (r_skyboxloaded && R_UseCubeMapForSkyBox() ? PROGRAMFLAGS_SKYBOX : 0);
if (flags && Skywind_Active()) {
flags |= PROGRAMFLAGS_SKYWIND;
}

if (R_ProgramRecompileNeeded(r_program_sky_glc, flags)) {
static char included_definitions[512];

memset(included_definitions, 0, sizeof(included_definitions));
if (flags & PROGRAMFLAGS_SKYBOX) {
strlcat(included_definitions, "#define DRAW_SKYBOX\n", sizeof(included_definitions));
if (flags & PROGRAMFLAGS_SKYWIND) {
strlcat(included_definitions, "#define DRAW_SKYWIND\n", sizeof(included_definitions));
}
}

R_ProgramCompileWithInclude(r_program_sky_glc, included_definitions);
Expand All @@ -316,6 +323,7 @@ static void GLC_DrawSky_Program(void)
extern msurface_t *skychain;
float skySpeedscale = r_refdef2.time * 8;
float skySpeedscale2 = r_refdef2.time * 16;
float skyWind[4];

skySpeedscale -= (int)skySpeedscale & ~127;
skySpeedscale2 -= (int)skySpeedscale2 & ~127;
Expand All @@ -328,6 +336,9 @@ static void GLC_DrawSky_Program(void)
R_ProgramUniform1f(r_program_uniform_sky_glc_speedscale, skySpeedscale);
R_ProgramUniform1f(r_program_uniform_sky_glc_speedscale2, skySpeedscale2);
R_ProgramUniform3fv(r_program_uniform_sky_glc_cameraPosition, r_refdef.vieworg);
if (Skywind_GetDirectionAndPhase(skyWind, &skyWind[3])) {
R_ProgramUniform4fv(r_program_uniform_sky_glc_skyWind, skyWind);
}

if (r_skyboxloaded && R_UseCubeMapForSkyBox()) {
extern texture_ref skybox_cubeMap;
Expand Down
4 changes: 4 additions & 0 deletions src/glm_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ typedef struct uniform_block_frame_constants_s {
float r_farclip_unused; // NO LONGER USED, replace
float waterAlpha;

// animated skybox
vec3_t windDir;
float windPhase;

// drawflat toggles (combine into bitfield?)
int r_drawflat;
int r_fastturb;
Expand Down
3 changes: 3 additions & 0 deletions src/glm_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "glm_local.h"
#include "r_renderer.h"
#include "gl_texture.h"
#include "r_brushmodel_sky.h"

static uniform_block_frame_constants_t frameConstants;
static qbool frameConstantsUploaded = false;
Expand Down Expand Up @@ -162,6 +163,8 @@ void GLM_PreRenderView(void)
frameConstants.skyFogMix = r_refdef2.fog_sky;
frameConstants.fogDensity = r_refdef2.fog_density; // (r_refdef2.fog_calculation == fogcalc_exp2 ? r_refdef2.fog_density * r_refdef2.fog_density : r_refdef2.fog_density);

Skywind_GetDirectionAndPhase(frameConstants.windDir, &frameConstants.windPhase);

frameConstantsUploaded = false;
}

Expand Down
9 changes: 8 additions & 1 deletion src/glm_rsurf.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static void GLM_CheckDrawCallSize(void)
#define DRAW_DRAWFLAT_TINTED (1 << 11)
#define DRAW_DRAWFLAT_BRIGHT (1 << 12)
#define DRAW_ALPHATESTED (1 << 13)
#define DRAW_SKYWIND (1 << 14)

static int material_samplers_max;
static int TEXTURE_UNIT_MATERIAL; // Must always be the first non-standard texture unit
Expand All @@ -134,6 +135,7 @@ static qbool GLM_CompileDrawWorldProgramImpl(r_program_id program_id, qbool alph
qbool luma_textures = gl_lumatextures.integer && r_refdef2.allow_lumas;
qbool skybox = r_skyboxloaded && !r_fastsky.integer;
qbool skydome = !skybox && !r_fastsky.integer && R_TextureReferenceIsValid(solidskytexture);
qbool skywind = skybox && Skywind_Active();

int drawworld_desiredOptions =
(detail_textures ? DRAW_DETAIL_TEXTURES : 0) |
Expand All @@ -148,7 +150,8 @@ static qbool GLM_CompileDrawWorldProgramImpl(r_program_id program_id, qbool alph
(r_drawflat.integer == 1 || r_drawflat.integer == 3 ? DRAW_FLATWALLS : 0) |
(gl_textureless.integer ? DRAW_TEXTURELESS : 0) |
((gl_outline.integer & 2) ? DRAW_GEOMETRY : 0) |
(alpha_test ? DRAW_ALPHATESTED : 0);
(alpha_test ? DRAW_ALPHATESTED : 0) |
(skywind ? DRAW_SKYWIND : 0);

if (R_ProgramRecompileNeeded(program_id, drawworld_desiredOptions)) {
static char included_definitions[2048];
Expand Down Expand Up @@ -192,7 +195,11 @@ static qbool GLM_CompileDrawWorldProgramImpl(r_program_id program_id, qbool alph
TEXTURE_UNIT_SKYBOX = samplers++;

strlcat(included_definitions, "#define DRAW_SKYBOX\n", sizeof(included_definitions));
if (skywind) {
strlcat(included_definitions, "#define DRAW_SKYWIND\n", sizeof(included_definitions));
}
strlcat(included_definitions, va("#define SAMPLER_SKYBOX_TEXTURE %d\n", TEXTURE_UNIT_SKYBOX), sizeof(included_definitions));

}
else if (skydome) {
TEXTURE_UNIT_SKYDOME_TEXTURE = samplers++;
Expand Down
3 changes: 3 additions & 0 deletions src/glsl/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ layout(std140, binding=EZQ_GL_BINDINGPOINT_FRAMECONSTANTS) uniform GlobalState {
float r_farclip_unused; // Replace
float waterAlpha;

// animated skybox
vec4 skyWind;

// drawflat toggles
int r_drawflat;
int r_fastturb;
Expand Down
16 changes: 15 additions & 1 deletion src/glsl/draw_world.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ layout(binding=SAMPLER_DETAIL_TEXTURE) uniform sampler2D detailTex;
#ifdef DRAW_CAUSTIC_TEXTURES
layout(binding=SAMPLER_CAUSTIC_TEXTURE) uniform sampler2D causticsTex;
#endif
#ifdef DRAW_SKYBOX
#if defined(DRAW_SKYBOX)
layout(binding=SAMPLER_SKYBOX_TEXTURE) uniform samplerCube skyTex;
#elif defined(DRAW_SKYDOME)
layout(binding=SAMPLER_SKYDOME_TEXTURE) uniform sampler2D skyDomeTex;
Expand Down Expand Up @@ -169,6 +169,20 @@ void main()
else if (turbType == TEXTURE_TURB_SKY) {
#if defined(DRAW_SKYBOX)
frag_colour = texture(skyTex, Direction);
#if defined(DRAW_SKYWIND)
float t1 = skyWind.w;
float t2 = fract(t1) - 0.5;
float blend = abs(t1 * 2.0);
vec3 dir = normalize(Direction);
vec4 layer1 = texture(skyTex, dir + t1 * skyWind.xyz);
vec4 layer2 = texture(skyTex, dir + t2 * skyWind.xyz);
layer1.a *= 1.0 - blend;
layer2.a *= blend;
layer1.rgb *= layer1.a;
layer2.rgb *= layer2.a;
vec4 combined = layer1 + layer2;
frag_colour = vec4(frag_colour.rgb * (1.0 - combined.a) + combined.rgb, 1);
#endif
#elif defined(DRAW_SKYDOME)
const float len = 3.09375;
// Flatten it out
Expand Down
17 changes: 17 additions & 0 deletions src/glsl/glc/glc_sky.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#ifdef DRAW_SKYBOX
uniform samplerCube skyTex;
#ifdef DRAW_SKYWIND
uniform vec4 skyWind;
#endif
#else
uniform sampler2D skyDomeTex;
uniform sampler2D skyDomeCloudTex;
Expand All @@ -22,6 +25,20 @@ void main()
{
#if defined(DRAW_SKYBOX)
gl_FragColor = textureCube(skyTex, Direction);
#if defined(DRAW_SKYWIND)
float t1 = skyWind.w;
float t2 = fract(t1) - 0.5;
float blend = abs(t1 * 2.0);
vec3 dir = normalize(Direction);
vec4 layer1 = textureCube(skyTex, dir + t1 * skyWind.xyz);
vec4 layer2 = textureCube(skyTex, dir + t2 * skyWind.xyz);
layer1.a *= 1.0 - blend;
layer2.a *= blend;
layer1.rgb *= layer1.a;
layer2.rgb *= layer2.a;
vec4 combined = layer1 + layer2;
gl_FragColor = vec4(gl_FragColor.rgb * (1.0 - combined.a) + combined.rgb, 1);
#endif
#else
const float len = 3.09375;
// Flatten it out
Expand Down
Loading

0 comments on commit 9a79c98

Please sign in to comment.