diff --git a/engine/client/cl_demo.c b/engine/client/cl_demo.c index 186fe2457..a39aabbe5 100644 --- a/engine/client/cl_demo.c +++ b/engine/client/cl_demo.c @@ -2272,7 +2272,7 @@ void CL_PlayDemoFile(vfsfile_t *f, char *demoname, qboolean issyspath) break; len--; VFS_READ(f, &type, sizeof(type)); - while (len >= 2 && (type == svcq2_stufftext) || (type == svcq2_print)) + while (len >= 2 && (type == svcq2_stufftext || type == svcq2_print)) { while (len > 0) { diff --git a/engine/client/m_download.c b/engine/client/m_download.c index b5a3d9bd1..a70c6939e 100644 --- a/engine/client/m_download.c +++ b/engine/client/m_download.c @@ -1344,8 +1344,6 @@ typedef struct { qboolean populated; } dlmenu_t; -static int autoupdatesetting = UPD_UNSUPPORTED; - static void COM_QuotedConcat(const char *cat, char *buf, size_t bufsize) { const unsigned char *gah; @@ -2192,6 +2190,7 @@ void PM_Shutdown(void) #endif #ifdef DOWNLOADMENU +static int autoupdatesetting = UPD_UNSUPPORTED; static void MD_Draw (int x, int y, struct menucustom_s *c, struct menu_s *m) { package_t *p; diff --git a/engine/gl/gl_rlight.c b/engine/gl/gl_rlight.c index 22f6fd27e..7ad9514d2 100644 --- a/engine/gl/gl_rlight.c +++ b/engine/gl/gl_rlight.c @@ -529,6 +529,7 @@ void R_GenDlightMesh(struct batch_s *batch) int lightflags = batch->surf_count; BE_SelectDLight(l, l->color, l->axis, lightflags); +#ifdef RTLIGHTS if (lightflags & LSHADER_SMAP) { if (!Sh_GenerateShadowMap(l)) @@ -539,6 +540,7 @@ void R_GenDlightMesh(struct batch_s *batch) BE_SelectEntity(&r_worldentity); BE_SelectMode(BEM_STANDARD); } +#endif if (!R_BuildDlightMesh (l, 2, 1, 2)) { @@ -582,6 +584,7 @@ void R_GenDlightBatches(batch_t *batches[]) "lpp_light\n" "}\n" ); +#ifdef RTLIGHTS lpplight_shader[LSHADER_SMAP] = R_RegisterShader("lpp_light#PCF", SUF_NONE, "{\n" "program lpp_light\n" @@ -594,6 +597,7 @@ void R_GenDlightBatches(batch_t *batches[]) "lpp_light\n" "}\n" ); +#endif } l = cl_dlights+rtlights_first; @@ -606,8 +610,10 @@ void R_GenDlightBatches(batch_t *batches[]) continue; lmode = 0; +#ifdef RTLIGHTS if (!(((i >= RTL_FIRST)?!r_shadow_realtime_world_shadows.ival:!r_shadow_realtime_dlight_shadows.ival) || l->flags & LFLAG_NOSHADOWS)) lmode |= LSHADER_SMAP; +#endif // if (TEXLOADED(l->cubetexture)) // lmode |= LSHADER_CUBE; diff --git a/engine/shaders/glsl/lpp_depthnorm.glsl b/engine/shaders/glsl/lpp_depthnorm.glsl index bff3982f4..e88cdb864 100644 --- a/engine/shaders/glsl/lpp_depthnorm.glsl +++ b/engine/shaders/glsl/lpp_depthnorm.glsl @@ -1,16 +1,23 @@ !!permu BUMP !!permu SKELETAL +!!cvarf r_glsl_offsetmapping_scale //light pre-pass rendering (defered lighting) //this is the initial pass, that draws the surface normals and depth to the initial colour buffer +#include "sys/defs.h" + +#if defined(OFFSETMAPPING) +varying vec3 eyevector; +#endif + varying vec3 norm, tang, bitang; #if defined(BUMP) varying vec2 tc; #endif #ifdef VERTEX_SHADER #include "sys/skeletal.h" -attribute vec2 v_texcoord; + void main() { #if defined(BUMP) @@ -19,21 +26,34 @@ void main() #else gl_Position = skeletaltransform_n(norm); #endif + +#if defined(OFFSETMAPPING) + vec3 eyeminusvertex = e_eyepos - v_position.xyz; + eyevector.x = dot(eyeminusvertex, v_svector.xyz); + eyevector.y = dot(eyeminusvertex, v_tvector.xyz); + eyevector.z = dot(eyeminusvertex, v_normal.xyz); +#endif } #endif #ifdef FRAGMENT_SHADER -#if defined(BUMP) -uniform sampler2D s_t0; +#ifdef OFFSETMAPPING +#include "sys/offsetmapping.h" #endif void main() { +//adjust texture coords for offsetmapping +#ifdef OFFSETMAPPING + vec2 tcoffsetmap = offsetmap(s_normalmap, tc, eyevector); +#define tc tcoffsetmap +#endif + vec3 onorm; #if defined(BUMP) - vec3 bm = 2.0*texture2D(s_t0, tc).xyz - 1.0; + vec3 bm = 2.0*texture2D(s_normalmap, tc).xyz - 1.0; onorm = normalize(bm.x * tang + bm.y * bitang + bm.z * norm); #else onorm = norm; #endif - gl_FragColor = vec4(onorm.xyz, gl_FragCoord.z / gl_FragCoord.w); + gl_FragColor = vec4(onorm.xyz, gl_FragCoord.z); } #endif diff --git a/engine/shaders/glsl/lpp_light.glsl b/engine/shaders/glsl/lpp_light.glsl index 9b6cb796a..b3d2bb87d 100644 --- a/engine/shaders/glsl/lpp_light.glsl +++ b/engine/shaders/glsl/lpp_light.glsl @@ -3,6 +3,9 @@ //you can blame Electro for much of the maths in here. //fixme: no fog +//s_t0 is the normals and depth +//output should be amount of light hitting the surface. + varying vec4 tf; #ifdef VERTEX_SHADER void main() @@ -12,27 +15,147 @@ void main() } #endif #ifdef FRAGMENT_SHADER -uniform sampler2D s_t0; +uniform sampler2D s_t0; //norm.xyz, depth uniform vec3 l_lightposition; uniform mat4 m_invviewprojection; uniform vec3 l_lightcolour; uniform float l_lightradius; +uniform mat4 l_cubematrix; + + + + + +#ifdef PCF +#define USE_ARB_SHADOW +#ifndef USE_ARB_SHADOW +//fall back on regular samplers if we must +#define sampler2DShadow sampler2D +#endif +uniform sampler2DShadow s_shadowmap; + +uniform vec4 l_shadowmapproj; //light projection matrix info +uniform vec2 l_shadowmapscale; //xy are the texture scale, z is 1, w is the scale. +vec3 ShadowmapCoord(vec4 cubeproj) +{ +#ifdef SPOT + //bias it. don't bother figuring out which side or anything, its not needed + //l_projmatrix contains the light's projection matrix so no other magic needed + return ((cubeproj.xyz-vec3(0.0,0.0,0.015))/cubeproj.w + vec3(1.0, 1.0, 1.0)) * vec3(0.5, 0.5, 0.5); +//#elif defined(CUBESHADOW) +// vec3 shadowcoord = vshadowcoord.xyz / vshadowcoord.w; +// #define dosamp(x,y) shadowCube(s_shadowmap, shadowcoord + vec2(x,y)*texscale.xy).r +#else + //figure out which axis to use + //texture is arranged thusly: + //forward left up + //back right down + vec3 dir = abs(cubeproj.xyz); + //assume z is the major axis (ie: forward from the light) + vec3 t = cubeproj.xyz; + float ma = dir.z; + vec3 axis = vec3(0.5/3.0, 0.5/2.0, 0.5); + if (dir.x > ma) + { + ma = dir.x; + t = cubeproj.zyx; + axis.x = 0.5; + } + if (dir.y > ma) + { + ma = dir.y; + t = cubeproj.xzy; + axis.x = 2.5/3.0; + } + //if the axis is negative, flip it. + if (t.z > 0.0) + { + axis.y = 1.5/2.0; + t.z = -t.z; + } + + //we also need to pass the result through the light's projection matrix too + //the 'matrix' we need only contains 5 actual values. and one of them is a -1. So we might as well just use a vec4. + //note: the projection matrix also includes scalers to pinch the image inwards to avoid sampling over borders, as well as to cope with non-square source image + //the resulting z is prescaled to result in a value between -0.5 and 0.5. + //also make sure we're in the right quadrant type thing + return axis + ((l_shadowmapproj.xyz*t.xyz + vec3(0.0, 0.0, l_shadowmapproj.w)) / -t.z); +#endif +} + +float ShadowmapFilter(vec4 vtexprojcoord) +{ + vec3 shadowcoord = ShadowmapCoord(vtexprojcoord); + + #if 0//def GL_ARB_texture_gather + vec2 ipart, fpart; + #define dosamp(x,y) textureGatherOffset(s_shadowmap, ipart.xy, vec2(x,y))) + vec4 tl = step(shadowcoord.z, dosamp(-1.0, -1.0)); + vec4 bl = step(shadowcoord.z, dosamp(-1.0, 1.0)); + vec4 tr = step(shadowcoord.z, dosamp(1.0, -1.0)); + vec4 br = step(shadowcoord.z, dosamp(1.0, 1.0)); + //we now have 4*4 results, woo + //we can just average them for 1/16th precision, but that's still limited graduations + //the middle four pixels are 'full strength', but we interpolate the sides to effectively give 3*3 + vec4 col = vec4(tl.ba, tr.ba) + vec4(bl.rg, br.rg) + //middle two rows are full strength + mix(vec4(tl.rg, tr.rg), vec4(bl.ba, br.ba), fpart.y); //top+bottom rows + return dot(mix(col.rgb, col.agb, fpart.x), vec3(1.0/9.0)); //blend r+a, gb are mixed because its pretty much free and gives a nicer dot instruction instead of lots of adds. + + #else +#ifdef USE_ARB_SHADOW + //with arb_shadow, we can benefit from hardware acclerated pcf, for smoother shadows + #define dosamp(x,y) shadow2D(s_shadowmap, shadowcoord.xyz + (vec3(x,y,0.0)*l_shadowmapscale.xyx)).r +#else + //this will probably be a bit blocky. + #define dosamp(x,y) float(texture2D(s_shadowmap, shadowcoord.xy + (vec2(x,y)*l_shadowmapscale.xy)).r >= shadowcoord.z) +#endif + float s = 0.0; + #if r_glsl_pcf >= 1 && r_glsl_pcf < 5 + s += dosamp(0.0, 0.0); + return s; + #elif r_glsl_pcf >= 5 && r_glsl_pcf < 9 + s += dosamp(-1.0, 0.0); + s += dosamp(0.0, -1.0); + s += dosamp(0.0, 0.0); + s += dosamp(0.0, 1.0); + s += dosamp(1.0, 0.0); + return s/5.0; + #else + s += dosamp(-1.0, -1.0); + s += dosamp(-1.0, 0.0); + s += dosamp(-1.0, 1.0); + s += dosamp(0.0, -1.0); + s += dosamp(0.0, 0.0); + s += dosamp(0.0, 1.0); + s += dosamp(1.0, -1.0); + s += dosamp(1.0, 0.0); + s += dosamp(1.0, 1.0); + return s/9.0; + #endif + #endif +} +#else +float ShadowmapFilter(vec4 vtexprojcoord) +{ + return 1.0; +} +#endif + + + + + vec3 calcLightWorldPos(vec2 screenPos, float depth) { - vec4 pos; - pos.x = screenPos.x; - pos.y = screenPos.y; - pos.z = depth; - pos.w = 1.0; - pos = m_invviewprojection * pos; + vec4 pos = m_invviewprojection * vec4(screenPos.xy, (depth*2.0)-1.0, 1.0); return pos.xyz / pos.w; } void main () { vec3 lightColour = l_lightcolour.rgb; - float lightIntensity = 1.0; + float lightIntensity = 1.0; float lightAttenuation = l_lightradius; // fixme: just use the light radius for now, use better near/far att math separately once working - float radiusFar = l_lightradius; + float radiusFar = l_lightradius; float radiusNear = l_lightradius*0.5; vec2 fc; @@ -44,15 +167,22 @@ void main () /* calc where the wall that generated this sample came from */ vec3 worldPos = calcLightWorldPos(fc, depth); + /*we need to know the cube projection (for both cubemaps+shadows)*/ + vec4 cubeaxis = l_cubematrix*vec4(worldPos.xyz, 1.0); + /*calc diffuse lighting term*/ vec3 lightDir = l_lightposition - worldPos; float zdiff = 1.0 - clamp(length(lightDir) / lightAttenuation, 0.0, 1.0); float atten = (radiusFar * zdiff) / (radiusFar - radiusNear); atten = pow(atten, 2.0); lightDir = normalize(lightDir); - float nDotL = dot(norm, lightDir) * atten; - float lightDiffuse = max(0.0, nDotL); + float nDotL = dot(norm, lightDir); + float lightDiffuse = max(0.0, nDotL) * atten; - gl_FragColor = vec4(lightDiffuse * (lightColour * lightIntensity), 1.0); + //fixme: apply fog + //fixme: output a specular term + //fixme: cubemap filters + + gl_FragColor = vec4(lightDiffuse * (lightColour * lightIntensity) * ShadowmapFilter(cubeaxis), 1.0); } #endif diff --git a/engine/shaders/glsl/lpp_wall.glsl b/engine/shaders/glsl/lpp_wall.glsl index 7a715671d..cadbecf6f 100644 --- a/engine/shaders/glsl/lpp_wall.glsl +++ b/engine/shaders/glsl/lpp_wall.glsl @@ -1,34 +1,59 @@ +!!permu BUMP //for offsetmapping rather than bumpmapping (real bumps are handled elsewhere) +!!cvarf r_glsl_offsetmapping_scale + //the final defered lighting pass. //the lighting values were written to some render target, which is fed into this shader, and now we draw all the wall textures with it. +#include "sys/defs.h" + +#if defined(OFFSETMAPPING) +varying vec3 eyevector; +#endif + + varying vec2 tc, lm; varying vec4 tf; #ifdef VERTEX_SHADER -attribute vec2 v_texcoord; -attribute vec2 v_lmcoord; void main () { tc = v_texcoord; lm = v_lmcoord; gl_Position = tf = ftetransform(); + +#if defined(OFFSETMAPPING) + vec3 eyeminusvertex = e_eyepos - v_position.xyz; + eyevector.x = dot(eyeminusvertex, v_svector.xyz); + eyevector.y = dot(eyeminusvertex, v_tvector.xyz); + eyevector.z = dot(eyeminusvertex, v_normal.xyz); +#endif } #endif #ifdef FRAGMENT_SHADER -uniform sampler2D s_t0; -uniform sampler2D s_t1; -uniform sampler2D s_t2; -uniform vec4 e_lmscale; +uniform sampler2D s_t0; //light gbuffer +#ifdef OFFSETMAPPING +#include "sys/offsetmapping.h" +#endif void main () { +//adjust texture coords for offsetmapping +#ifdef OFFSETMAPPING + vec2 tcoffsetmap = offsetmap(s_normalmap, tc, eyevector); +#define tc tcoffsetmap +#endif + vec2 nst; nst = tf.xy / tf.w; nst = (1.0 + nst) / 2.0; - vec4 l = texture2D(s_t0, nst)*5.0; - vec4 c = texture2D(s_t1, tc); - vec3 lmsamp = texture2D(s_t2, lm).rgb*e_lmscale.rgb; + vec4 l = texture2D(s_t0, nst); + vec4 c = texture2D(s_diffuse, tc); +//fixme: top+bottom should add upper+lower colours to c here + vec3 lmsamp = texture2D(s_lightmap, lm).rgb*e_lmscale.rgb; +//fixme: fog the legacy lightmap data vec3 diff = l.rgb; - vec3 chrom = diff / (0.001 + dot(diff, vec3(0.3, 0.59, 0.11))); - vec3 spec = chrom * l.a; +// vec3 chrom = diff / (0.001 + dot(diff, vec3(0.3, 0.59, 0.11))); +// vec3 spec = chrom * l.a; +//fixme: do specular somehow gl_FragColor = vec4((diff + lmsamp) * c.xyz, 1.0); +//fixme: fullbrights should add to the rgb value } #endif