Skip to content

Commit

Permalink
Merge branch 'master' into sdl2
Browse files Browse the repository at this point in the history
  • Loading branch information
zturtleman committed Mar 9, 2014
2 parents 1250b35 + e7f4354 commit 9ec7931
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 104 deletions.
6 changes: 3 additions & 3 deletions code/client/qal.c
Expand Up @@ -83,7 +83,7 @@ LPALBUFFERDATA qalBufferData;
LPALGETBUFFERF qalGetBufferf;
LPALGETBUFFERI qalGetBufferi;
LPALDOPPLERFACTOR qalDopplerFactor;
LPALDOPPLERVELOCITY qalDopplerVelocity;
LPALSPEEDOFSOUND qalSpeedOfSound;
LPALDISTANCEMODEL qalDistanceModel;

LPALCCREATECONTEXT qalcCreateContext;
Expand Down Expand Up @@ -201,7 +201,7 @@ qboolean QAL_Init(const char *libname)
qalGetBufferf = GPA("alGetBufferf");
qalGetBufferi = GPA("alGetBufferi");
qalDopplerFactor = GPA("alDopplerFactor");
qalDopplerVelocity = GPA("alDopplerVelocity");
qalSpeedOfSound = GPA("alSpeedOfSound");
qalDistanceModel = GPA("alDistanceModel");

qalcCreateContext = GPA("alcCreateContext");
Expand Down Expand Up @@ -300,7 +300,7 @@ void QAL_Shutdown( void )
qalGetBufferf = NULL;
qalGetBufferi = NULL;
qalDopplerFactor = NULL;
qalDopplerVelocity = NULL;
qalSpeedOfSound = NULL;
qalDistanceModel = NULL;

qalcCreateContext = NULL;
Expand Down
2 changes: 0 additions & 2 deletions code/client/qal.h
Expand Up @@ -125,7 +125,6 @@ extern LPALGETBUFFERI qalGetBufferi;
extern LPALGETBUFFER3I qalGetBuffer3i;
extern LPALGETBUFFERIV qalGetBufferiv;
extern LPALDOPPLERFACTOR qalDopplerFactor;
extern LPALDOPPLERVELOCITY qalDopplerVelocity;
extern LPALSPEEDOFSOUND qalSpeedOfSound;
extern LPALDISTANCEMODEL qalDistanceModel;

Expand Down Expand Up @@ -220,7 +219,6 @@ extern LPALCCAPTURESAMPLES qalcCaptureSamples;
#define qalGetBuffer3i alGetBuffer3i
#define qalGetBufferiv alGetBufferiv
#define qalDopplerFactor alDopplerFactor
#define qalDopplerVelocity alDopplerVelocity
#define qalSpeedOfSound alSpeedOfSound
#define qalDistanceModel alDistanceModel

Expand Down
6 changes: 3 additions & 3 deletions code/client/snd_openal.c
Expand Up @@ -2309,7 +2309,7 @@ void S_AL_Update( void )
}
if(s_alDopplerSpeed->modified)
{
qalDopplerVelocity(s_alDopplerSpeed->value);
qalSpeedOfSound(s_alDopplerSpeed->value);
s_alDopplerSpeed->modified = qfalse;
}

Expand Down Expand Up @@ -2506,7 +2506,7 @@ qboolean S_AL_Init( soundInterface_t *si )
s_alGain = Cvar_Get( "s_alGain", "1.0", CVAR_ARCHIVE );
s_alSources = Cvar_Get( "s_alSources", "96", CVAR_ARCHIVE );
s_alDopplerFactor = Cvar_Get( "s_alDopplerFactor", "1.0", CVAR_ARCHIVE );
s_alDopplerSpeed = Cvar_Get( "s_alDopplerSpeed", "2200", CVAR_ARCHIVE );
s_alDopplerSpeed = Cvar_Get( "s_alDopplerSpeed", "13512", CVAR_ARCHIVE );
s_alMinDistance = Cvar_Get( "s_alMinDistance", "120", CVAR_CHEAT );
s_alMaxDistance = Cvar_Get("s_alMaxDistance", "1024", CVAR_CHEAT);
s_alRolloff = Cvar_Get( "s_alRolloff", "2", CVAR_CHEAT);
Expand Down Expand Up @@ -2623,7 +2623,7 @@ qboolean S_AL_Init( soundInterface_t *si )
// Set up OpenAL parameters (doppler, etc)
qalDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
qalDopplerFactor( s_alDopplerFactor->value );
qalDopplerVelocity( s_alDopplerSpeed->value );
qalSpeedOfSound( s_alDopplerSpeed->value );

#ifdef USE_VOIP
// !!! FIXME: some of these alcCaptureOpenDevice() values should be cvars.
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_syscalls.c
Expand Up @@ -688,7 +688,7 @@ void trap_BotSaveGoalFuzzyLogic(int goalstate, char *filename) {
}

void trap_BotMutateGoalFuzzyLogic(int goalstate, float range) {
syscall( BOTLIB_AI_MUTATE_GOAL_FUZZY_LOGIC, goalstate, range );
syscall( BOTLIB_AI_MUTATE_GOAL_FUZZY_LOGIC, goalstate, PASSFLOAT(range) );
}

int trap_BotAllocGoalState(int state) {
Expand Down
35 changes: 26 additions & 9 deletions code/renderergl2/glsl/lightall_fp.glsl
Expand Up @@ -25,7 +25,8 @@ uniform samplerCube u_CubeMap;
#endif

#if defined(USE_NORMALMAP) || defined(USE_DELUXEMAP) || defined(USE_SPECULARMAP) || defined(USE_CUBEMAP)
uniform vec4 u_EnableTextures; // x = normal, y = deluxe, z = specular, w = cube
// y = deluxe, w = cube
uniform vec4 u_EnableTextures;
#endif

#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT)
Expand All @@ -39,7 +40,8 @@ uniform vec3 u_PrimaryLightAmbient;
#endif

#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
uniform vec2 u_MaterialInfo;
uniform vec4 u_NormalScale;
uniform vec4 u_SpecularScale;
#endif

varying vec4 var_TexCoords;
Expand Down Expand Up @@ -167,7 +169,7 @@ vec3 EnvironmentBRDF(float gloss, float NE, vec3 specular)
return clamp( a0 + specular * ( a1 - a0 ), 0.0, 1.0 );
#elif 0
// from http://seblagarde.wordpress.com/2011/08/17/hello-world/
return mix(specular.rgb, max(specular.rgb, vec3(gloss)), CalcFresnel(NE));
return specular + CalcFresnel(NE) * clamp(vec3(gloss) - specular, 0.0, 1.0);
#else
// from http://advances.realtimerendering.com/s2011/Lazarov-Physically-Based-Lighting-in-Black-Ops%20%28Siggraph%202011%20Advances%20in%20Real-Time%20Rendering%20Course%29.pptx
return mix(specular.rgb, vec3(1.0), CalcFresnel(NE) / (4.0 - 3.0 * gloss));
Expand Down Expand Up @@ -360,7 +362,7 @@ void main()
#if defined(USE_PARALLAXMAP)
vec3 offsetDir = normalize(E * tangentToWorld);

offsetDir.xy *= -0.05 / offsetDir.z;
offsetDir.xy *= -u_NormalScale.a / offsetDir.z;

texCoords += offsetDir.xy * RayIntersectDisplaceMap(texCoords, offsetDir.xy, u_NormalMap);
#endif
Expand All @@ -378,8 +380,8 @@ void main()
#else
N.xy = texture2D(u_NormalMap, texCoords).rg - vec2(0.5);
#endif
N.xy *= u_EnableTextures.x;
N.z = sqrt((0.25 - N.x * N.x) - N.y * N.y);
N.xy *= u_NormalScale.xy;
N.z = sqrt(clamp((0.25 - N.x * N.x) - N.y * N.y, 0.0, 1.0));
N = tangentToWorld * N;
#else
N = var_Normal.xyz;
Expand Down Expand Up @@ -425,15 +427,16 @@ void main()
NL = clamp(dot(N, L), 0.0, 1.0);
NE = clamp(dot(N, E), 0.0, 1.0);

vec4 specular = vec4(1.0);
#if defined(USE_SPECULARMAP)
specular += texture2D(u_SpecularMap, texCoords) * u_EnableTextures.z - u_EnableTextures.zzzz;
vec4 specular = texture2D(u_SpecularMap, texCoords);
#if defined(USE_GAMMA2_TEXTURES)
specular.rgb *= specular.rgb;
#endif
#else
vec4 specular = vec4(1.0);
#endif

specular *= u_MaterialInfo.xxxy;
specular *= u_SpecularScale;

float gloss = specular.a;
float shininess = exp2(gloss * 13.0);
Expand Down Expand Up @@ -473,7 +476,21 @@ void main()
#endif

gl_FragColor.rgb = lightColor * reflectance * NL;

#if 0
vec3 aSpecular = EnvironmentBRDF(gloss, NE, specular.rgb);

// do ambient as two hemisphere lights, one straight up one straight down
float hemiDiffuseUp = N.z * 0.5 + 0.5;
float hemiDiffuseDown = 1.0 - hemiDiffuseUp;
float hemiSpecularUp = mix(hemiDiffuseUp, float(N.z >= 0.0), gloss);
float hemiSpecularDown = 1.0 - hemiSpecularUp;

gl_FragColor.rgb += ambientColor * 0.75 * (diffuse.rgb * hemiDiffuseUp + aSpecular * hemiSpecularUp);
gl_FragColor.rgb += ambientColor * 0.25 * (diffuse.rgb * hemiDiffuseDown + aSpecular * hemiSpecularDown);
#else
gl_FragColor.rgb += ambientColor * (diffuse.rgb + specular.rgb);
#endif

#if defined(USE_CUBEMAP)
reflectance = EnvironmentBRDF(gloss, NE, specular.rgb);
Expand Down
9 changes: 7 additions & 2 deletions code/renderergl2/glsl/shadowmask_fp.glsl
Expand Up @@ -18,6 +18,10 @@ uniform vec4 u_ViewInfo; // zfar / znear, zfar
varying vec2 var_DepthTex;
varying vec3 var_ViewDir;

// depth is GL_DEPTH_COMPONENT24
// so the maximum error is 1.0 / 2^24
#define DEPTH_MAX_ERROR 0.000000059604644775390625

// Input: It uses texture coords as the random number seed.
// Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive.
// Author: Michael Pohoreski
Expand All @@ -39,7 +43,7 @@ float PCF(const sampler2D shadowmap, const vec2 st, const float dist)
{
float mult;
float scale = 2.0 / r_shadowMapSize;

#if defined(USE_SHADOW_FILTER)
float r = random(var_DepthTex.xy);
float sinr = sin(r) * scale;
Expand Down Expand Up @@ -71,6 +75,7 @@ float PCF(const sampler2D shadowmap, const vec2 st, const float dist)
float getLinearDepth(sampler2D depthMap, vec2 tex, float zFarDivZNear)
{
float sampleZDivW = texture2D(depthMap, tex).r;
sampleZDivW -= DEPTH_MAX_ERROR;
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
}

Expand All @@ -81,7 +86,7 @@ void main()
float depth = getLinearDepth(u_ScreenDepthMap, var_DepthTex, u_ViewInfo.x);
float sampleZ = u_ViewInfo.y * depth;

vec4 biasPos = vec4(u_ViewOrigin + var_ViewDir * depth * 0.99, 1.0);
vec4 biasPos = vec4(u_ViewOrigin + var_ViewDir * (depth - 0.5 / u_ViewInfo.x), 1.0);

vec4 shadowpos = u_ShadowMvp * biasPos;

Expand Down
3 changes: 2 additions & 1 deletion code/renderergl2/tr_animation.c
Expand Up @@ -193,7 +193,8 @@ void R_MDRAddAnimSurfaces( trRefEntity_t *ent ) {

header = (mdrHeader_t *) tr.currentModel->modelData;

personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal;
personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !(tr.viewParms.isPortal
|| (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW)));

if ( ent->e.renderfx & RF_WRAP_FRAMES )
{
Expand Down
2 changes: 1 addition & 1 deletion code/renderergl2/tr_bsp.c
Expand Up @@ -143,7 +143,7 @@ static void R_ColorShiftLightingFloats(float in[4], float out[4], float scale )
b = in[2] * scale;

// normalize by color instead of saturating to white
if ( !r_hdr->integer && ( r > 1 || g > 1 || b > 1 ) ) {
if ( r > 1 || g > 1 || b > 1 ) {
float max;

max = r > g ? r : g;
Expand Down
7 changes: 4 additions & 3 deletions code/renderergl2/tr_glsl.c
Expand Up @@ -123,9 +123,10 @@ static uniformInfo_t uniformsInfo[] =
{ "u_ModelMatrix", GLSL_MAT16 },
{ "u_ModelViewProjectionMatrix", GLSL_MAT16 },

{ "u_Time", GLSL_FLOAT },
{ "u_VertexLerp" , GLSL_FLOAT },
{ "u_MaterialInfo", GLSL_VEC2 },
{ "u_Time", GLSL_FLOAT },
{ "u_VertexLerp" , GLSL_FLOAT },
{ "u_NormalScale", GLSL_VEC4 },
{ "u_SpecularScale", GLSL_VEC4 },

{ "u_ViewInfo", GLSL_VEC4 },
{ "u_ViewOrigin", GLSL_VEC3 },
Expand Down
41 changes: 5 additions & 36 deletions code/renderergl2/tr_image.c
Expand Up @@ -3013,37 +3013,14 @@ void R_SetColorMappings( void ) {
int i, j;
float g;
int inf;
int shift;

// setup the overbright lighting
tr.overbrightBits = r_overBrightBits->integer;
if ( !glConfig.deviceSupportsGamma ) {
tr.overbrightBits = 0; // need hardware gamma for overbright
}

// never overbright in windowed mode without soft overbright
if ( !glConfig.isFullscreen && !r_softOverbright->integer )
{
tr.overbrightBits = 0;
}

// never overbright with tonemapping
if ( r_toneMap->integer && r_hdr->integer )
{
tr.overbrightBits = 0;
}

// allow 2 overbright bits in 24 bit, but only 1 in 16 bit
if ( glConfig.colorBits > 16 ) {
if ( tr.overbrightBits > 2 ) {
tr.overbrightBits = 2;
}
} else {
if ( tr.overbrightBits > 1 ) {
tr.overbrightBits = 1;
}
}
if ( tr.overbrightBits < 0 ) {
// allow 2 overbright bits
if ( tr.overbrightBits > 2 ) {
tr.overbrightBits = 2;
} else if ( tr.overbrightBits < 0 ) {
tr.overbrightBits = 0;
}

Expand All @@ -3063,14 +3040,6 @@ void R_SetColorMappings( void ) {

g = r_gamma->value;

shift = tr.overbrightBits;

// no shift with soft overbright
if (r_softOverbright->integer)
{
shift = 0;
}

for ( i = 0; i < 256; i++ ) {
int i2;

Expand All @@ -3088,7 +3057,7 @@ void R_SetColorMappings( void ) {
} else {
inf = 255 * pow ( i2/255.0f, 1.0f / g ) + 0.5f;
}
inf <<= shift;

if (inf < 0) {
inf = 0;
}
Expand Down
10 changes: 6 additions & 4 deletions code/renderergl2/tr_init.c
Expand Up @@ -110,8 +110,6 @@ cvar_t *r_mergeLeafSurfaces;

cvar_t *r_cameraExposure;

cvar_t *r_softOverbright;

cvar_t *r_hdr;
cvar_t *r_floatLightmap;
cvar_t *r_postProcess;
Expand Down Expand Up @@ -139,6 +137,9 @@ cvar_t *r_parallaxMapping;
cvar_t *r_cubeMapping;
cvar_t *r_deluxeSpecular;
cvar_t *r_specularIsMetallic;
cvar_t *r_baseNormalX;
cvar_t *r_baseNormalY;
cvar_t *r_baseParallax;
cvar_t *r_baseSpecular;
cvar_t *r_baseGloss;
cvar_t *r_recalcMD3Normals;
Expand Down Expand Up @@ -1163,8 +1164,6 @@ void R_Register( void )
r_greyscale = ri.Cvar_Get("r_greyscale", "0", CVAR_ARCHIVE | CVAR_LATCH);
ri.Cvar_CheckRange(r_greyscale, 0, 1, qfalse);

r_softOverbright = ri.Cvar_Get( "r_softOverbright", "1", CVAR_ARCHIVE | CVAR_LATCH );

r_hdr = ri.Cvar_Get( "r_hdr", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_floatLightmap = ri.Cvar_Get( "r_floatLightmap", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_postProcess = ri.Cvar_Get( "r_postProcess", "1", CVAR_ARCHIVE );
Expand Down Expand Up @@ -1194,6 +1193,9 @@ void R_Register( void )
r_cubeMapping = ri.Cvar_Get( "r_cubeMapping", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_deluxeSpecular = ri.Cvar_Get( "r_deluxeSpecular", "0.3", CVAR_ARCHIVE | CVAR_LATCH );
r_specularIsMetallic = ri.Cvar_Get( "r_specularIsMetallic", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_baseNormalX = ri.Cvar_Get( "r_baseNormalX", "1.0", CVAR_ARCHIVE | CVAR_LATCH );
r_baseNormalY = ri.Cvar_Get( "r_baseNormalY", "1.0", CVAR_ARCHIVE | CVAR_LATCH );
r_baseParallax = ri.Cvar_Get( "r_baseParallax", "0.05", CVAR_ARCHIVE | CVAR_LATCH );
r_baseSpecular = ri.Cvar_Get( "r_baseSpecular", "0.04", CVAR_ARCHIVE | CVAR_LATCH );
r_baseGloss = ri.Cvar_Get( "r_baseGloss", "0.3", CVAR_ARCHIVE | CVAR_LATCH );
r_dlightMode = ri.Cvar_Get( "r_dlightMode", "0", CVAR_ARCHIVE | CVAR_LATCH );
Expand Down
13 changes: 9 additions & 4 deletions code/renderergl2/tr_local.h
Expand Up @@ -400,7 +400,10 @@ typedef struct {
stageType_t type;
struct shaderProgram_s *glslShaderGroup;
int glslShaderIndex;
vec2_t materialInfo;

vec4_t normalScale;
vec4_t specularScale;

} shaderStage_t;

struct shaderCommands_s;
Expand Down Expand Up @@ -676,7 +679,8 @@ typedef enum

UNIFORM_TIME,
UNIFORM_VERTEXLERP,
UNIFORM_MATERIALINFO,
UNIFORM_NORMALSCALE,
UNIFORM_SPECULARSCALE,

UNIFORM_VIEWINFO, // znear, zfar, width/2, height/2
UNIFORM_VIEWORIGIN,
Expand Down Expand Up @@ -1766,8 +1770,6 @@ extern cvar_t *r_anaglyphMode;
extern cvar_t *r_mergeMultidraws;
extern cvar_t *r_mergeLeafSurfaces;

extern cvar_t *r_softOverbright;

extern cvar_t *r_hdr;
extern cvar_t *r_floatLightmap;
extern cvar_t *r_postProcess;
Expand Down Expand Up @@ -1797,6 +1799,9 @@ extern cvar_t *r_parallaxMapping;
extern cvar_t *r_cubeMapping;
extern cvar_t *r_deluxeSpecular;
extern cvar_t *r_specularIsMetallic;
extern cvar_t *r_baseNormalX;
extern cvar_t *r_baseNormalY;
extern cvar_t *r_baseParallax;
extern cvar_t *r_baseSpecular;
extern cvar_t *r_baseGloss;
extern cvar_t *r_dlightMode;
Expand Down

0 comments on commit 9ec7931

Please sign in to comment.