diff --git a/engine/d3d/d3d11_shader.c b/engine/d3d/d3d11_shader.c index 510e3f61f..9af39fc56 100644 --- a/engine/d3d/d3d11_shader.c +++ b/engine/d3d/d3d11_shader.c @@ -414,6 +414,7 @@ qboolean D3D11Shader_CreateProgram (program_t *prog, const char *name, unsigned char *dsformat = NULL; char *fsformat; char *gsformat = NULL; + char *tmp; D3D_SHADER_MACRO defines[64]; ID3DBlob *vcode = NULL, *hcode = NULL, *dcode = NULL, *gcode = NULL, *fcode = NULL, *errors = NULL; qboolean success = false; @@ -475,8 +476,10 @@ qboolean D3D11Shader_CreateProgram (program_t *prog, const char *name, unsigned defines[consts].Definition = __DATE__; consts++; + tmp = Z_Malloc(64); + Q_snprintfz(tmp, 64, "0x%x", d3dfeaturelevel); defines[consts].Name = Z_StrDup("LEVEL"); - defines[consts].Definition = Z_StrDup(va("0x%x", d3dfeaturelevel)); + defines[consts].Definition = tmp; consts++; for (; *precompilerconstants; precompilerconstants++) diff --git a/engine/d3d/d3d_shader.c b/engine/d3d/d3d_shader.c index 9562aafe0..046e1231f 100644 --- a/engine/d3d/d3d_shader.c +++ b/engine/d3d/d3d_shader.c @@ -394,6 +394,7 @@ static void D3D9Shader_ProgAutoFields(program_t *prog, const char *progname, cva struct programpermu_s *pp; unsigned int i, p; int uniformloc; + char tmpbuffer[256]; #define ALTLIGHTMAPSAMP 13 #define ALTDELUXMAPSAMP 16 @@ -436,7 +437,8 @@ static void D3D9Shader_ProgAutoFields(program_t *prog, const char *progname, cva //just directly sets uniforms. can't cope with cvars dynamically changing. cvarrefs[i]->flags |= CVAR_SHADERSYSTEM; - uniformloc = D3D9Shader_FindUniform(&prog->permu[p].h, 1, va("cvar_%s", cvarnames[i])); + Q_snprintfz(tmpbuffer, sizeof(tmpbuffer), "cvar_%s", cvarnames[i]); + uniformloc = D3D9Shader_FindUniform(&prog->permu[p].h, 1, tmpbuffer); if (uniformloc != -1) { if (cvartypes[i] == SP_CVARI) @@ -447,7 +449,7 @@ static void D3D9Shader_ProgAutoFields(program_t *prog, const char *progname, cva else IDirect3DDevice9_SetVertexShaderConstantF(pD3DDev9, 0, cvarrefs[i]->vec4, 1); } - uniformloc = D3D9Shader_FindUniform(&prog->permu[p].h, 2, va("cvar_%s", cvarnames[i])); + uniformloc = D3D9Shader_FindUniform(&prog->permu[p].h, 2, tmpbuffer); if (uniformloc != -1) { if (cvartypes[i] == SP_CVARI) @@ -463,7 +465,8 @@ static void D3D9Shader_ProgAutoFields(program_t *prog, const char *progname, cva /*set texture uniforms*/ for (i = 0; i < 8; i++) { - uniformloc = D3D9Shader_FindUniform(&pp->h, 2, va("s_t%i", i)); + Q_snprintfz(tmpbuffer, sizeof(tmpbuffer), "s_t%i", i); + uniformloc = D3D9Shader_FindUniform(&pp->h, 2, tmpbuffer); if (uniformloc != -1) { int v[4] = {i}; diff --git a/engine/gl/gl_shader.c b/engine/gl/gl_shader.c index 3f7ac3f82..2de6589c5 100644 --- a/engine/gl/gl_shader.c +++ b/engine/gl/gl_shader.c @@ -5831,7 +5831,7 @@ void Shader_DefaultSkybox(const char *shortname, shader_t *s, const void *args) } } -char *Shader_DefaultBSPWater(shader_t *s, const char *shortname) +char *Shader_DefaultBSPWater(shader_t *s, const char *shortname, char *buffer, size_t buffersize) { int wstyle; int type; @@ -5938,7 +5938,7 @@ char *Shader_DefaultBSPWater(shader_t *s, const char *shortname) ); default: case 1: //vanilla style - return va( + Q_snprintfz(buffer, buffersize, "{\n" "program defaultwarp%s\n" "{\n" @@ -5953,6 +5953,7 @@ char *Shader_DefaultBSPWater(shader_t *s, const char *shortname) "surfaceparm nomarks\n" "}\n" , explicitalpha?"":va("#ALPHA=%g",alpha), alpha, alpha); + return buffer; case 2: //refraction of the underwater surface, with a fresnel return ( "{\n" @@ -6038,7 +6039,8 @@ char *Shader_DefaultBSPWater(shader_t *s, const char *shortname) void Shader_DefaultWaterShader(const char *shortname, shader_t *s, const void *args) { - Shader_DefaultScript(shortname, s, Shader_DefaultBSPWater(s, shortname)); + char tmpbuffer[2048]; + Shader_DefaultScript(shortname, s, Shader_DefaultBSPWater(s, shortname, tmpbuffer, sizeof(tmpbuffer))); } void Shader_DefaultBSPQ2(const char *shortname, shader_t *s, const void *args) { @@ -6053,7 +6055,8 @@ void Shader_DefaultBSPQ2(const char *shortname, shader_t *s, const void *args) } else if (Shader_FloatArgument(s, "#WARP"))//!strncmp(shortname, "warp/", 5) || !strncmp(shortname, "warp33/", 7) || !strncmp(shortname, "warp66/", 7)) { - Shader_DefaultScript(shortname, s, Shader_DefaultBSPWater(s, shortname)); + char tmpbuffer[2048]; + Shader_DefaultScript(shortname, s, Shader_DefaultBSPWater(s, shortname, tmpbuffer, sizeof(tmpbuffer))); } else if (Shader_FloatArgument(s, "#ALPHA"))// !strncmp(shortname, "trans/", 6)) { @@ -6074,6 +6077,7 @@ void Shader_DefaultBSPQ2(const char *shortname, shader_t *s, const void *args) void Shader_DefaultBSPQ1(const char *shortname, shader_t *s, const void *args) { char *builtin = NULL; + char tmpbuffer[2048]; if (!strcmp(shortname, "mirror_portal")) { @@ -6113,7 +6117,7 @@ void Shader_DefaultBSPQ1(const char *shortname, shader_t *s, const void *args) if (!builtin && (*shortname == '*' || *shortname == '!')) { - builtin = Shader_DefaultBSPWater(s, shortname); + builtin = Shader_DefaultBSPWater(s, shortname, tmpbuffer, sizeof(tmpbuffer)); } if (!builtin && !strncmp(shortname, "sky", 3)) { diff --git a/engine/gl/r_bishaders.h b/engine/gl/r_bishaders.h index 27caa44a0..bb9a13ec2 100644 --- a/engine/gl/r_bishaders.h +++ b/engine/gl/r_bishaders.h @@ -7349,7 +7349,11 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND "ntc.y = inp.tc.y + sin(inp.tc.x+e_time)*0.125;\n" "float3 ts = tex2D(s_diffuse, ntc).xyz;\n" +"#ifdef ALPHA\n" +"return float4(ts, float(ALPHA));\n" +"#else\n" "return float4(ts, cvar_r_wateralpha);\n" +"#endif\n" "}\n" "#endif\n" }, @@ -7357,7 +7361,7 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND #ifdef D3D11QUAKE {QR_DIRECT3D11, 11, "defaultwarp", "!!samps diffuse\n" -"!!cvarf r_wateralpha\n" +//!!cvarf r_wateralpha "struct a2v\n" "{\n" @@ -7392,9 +7396,16 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND "float4 main (v2f inp) : SV_TARGET\n" "{\n" "float2 ntc;\n" +"float4 r;\n" "ntc.x = inp.tc.x + sin(inp.tc.y+e_time)*0.125;\n" "ntc.y = inp.tc.y + sin(inp.tc.x+e_time)*0.125;\n" -"return t_diffuse.Sample(s_diffuse, ntc);\n" +"r = t_diffuse.Sample(s_diffuse, ntc);\n" +"#ifdef ALPHA\n" +"r.a = float(ALPHA);\n" +"#else\n" +// r.a *= r_wateralpha; +"#endif\n" +"return r;\n" "}\n" "#endif\n" }, diff --git a/engine/shaders/hlsl11/defaultwarp.hlsl b/engine/shaders/hlsl11/defaultwarp.hlsl index cbc3c05ea..642c8e0ab 100644 --- a/engine/shaders/hlsl11/defaultwarp.hlsl +++ b/engine/shaders/hlsl11/defaultwarp.hlsl @@ -1,5 +1,5 @@ !!samps diffuse -!!cvarf r_wateralpha +//!!cvarf r_wateralpha struct a2v { @@ -34,8 +34,15 @@ struct v2f float4 main (v2f inp) : SV_TARGET { float2 ntc; + float4 r; ntc.x = inp.tc.x + sin(inp.tc.y+e_time)*0.125; ntc.y = inp.tc.y + sin(inp.tc.x+e_time)*0.125; - return t_diffuse.Sample(s_diffuse, ntc); + r = t_diffuse.Sample(s_diffuse, ntc); +#ifdef ALPHA + r.a = float(ALPHA); +#else +// r.a *= r_wateralpha; +#endif + return r; } #endif \ No newline at end of file diff --git a/engine/shaders/hlsl9/defaultwarp.hlsl b/engine/shaders/hlsl9/defaultwarp.hlsl index 6bc8cb09e..d2b8fcf70 100644 --- a/engine/shaders/hlsl9/defaultwarp.hlsl +++ b/engine/shaders/hlsl9/defaultwarp.hlsl @@ -31,6 +31,10 @@ struct v2f { ntc.y = inp.tc.y + sin(inp.tc.x+e_time)*0.125; float3 ts = tex2D(s_diffuse, ntc).xyz; +#ifdef ALPHA + return float4(ts, float(ALPHA)); +#else return float4(ts, cvar_r_wateralpha); +#endif } #endif