mirror of
https://github.com/UberGames/lilium-voyager.git
synced 2025-01-31 11:20:32 +00:00
OpenGL2: Remove AGEN_FRESNEL(superceded by cubemap patch), and some small fixes and optimizations.
This commit is contained in:
parent
82be4e667f
commit
acbeca6042
8 changed files with 157 additions and 213 deletions
|
@ -85,13 +85,13 @@ float CalcFog(vec4 position)
|
|||
float s = dot(position, u_FogDistance) * 8.0;
|
||||
float t = dot(position, u_FogDepth);
|
||||
|
||||
bool eyeOutside = u_FogEyeT < 0.0;
|
||||
float t2 = float(t >= float(eyeOutside));
|
||||
float eyeOutside = step(0.0, -u_FogEyeT);
|
||||
float fogged = step(eyeOutside, t);
|
||||
|
||||
t = max(t, 1e-6);
|
||||
t *= fogged / (t - u_FogEyeT * eyeOutside);
|
||||
|
||||
if (eyeOutside)
|
||||
t2 *= t / (t - u_FogEyeT);
|
||||
|
||||
return s * t2;
|
||||
return s * t;
|
||||
}
|
||||
|
||||
void main()
|
||||
|
|
|
@ -93,7 +93,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
|||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||
{
|
||||
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
|
||||
func = 1.0 - abs(4.0 * fract(value + 0.25) - 2.0);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
||||
{
|
||||
|
@ -163,25 +163,20 @@ vec4 CalcColor(vec3 position, vec3 normal)
|
|||
color.rgb = clamp(u_DirectedLight * incoming + u_AmbientLight, 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 toView = u_ViewOrigin - position;
|
||||
vec3 viewer = normalize(u_ViewOrigin - position);
|
||||
vec3 viewer = u_ViewOrigin - position;
|
||||
|
||||
if (u_AlphaGen == AGEN_LIGHTING_SPECULAR)
|
||||
{
|
||||
vec3 lightDir = normalize(vec3(-960.0, -1980.0, 96.0) - position.xyz);
|
||||
vec3 halfangle = normalize(lightDir + viewer);
|
||||
vec3 lightDir = normalize(vec3(-960.0, 1980.0, 96.0) - position.xyz);
|
||||
vec3 reflected = -reflect(lightDir, normal);
|
||||
|
||||
color.a = pow(max(dot(normal, halfangle), 0.0), 8.0);
|
||||
color.a = clamp(dot(reflected, normalize(viewer)), 0.0, 1.0);
|
||||
color.a *= color.a;
|
||||
color.a *= color.a;
|
||||
}
|
||||
else if (u_AlphaGen == AGEN_PORTAL)
|
||||
{
|
||||
float alpha = length(toView) / u_PortalRange;
|
||||
|
||||
color.a = clamp(alpha, 0.0, 1.0);
|
||||
}
|
||||
else if (u_AlphaGen == AGEN_FRESNEL)
|
||||
{
|
||||
color.a = 0.10 + 0.90 * pow(1.0 - dot(normal, viewer), 5);
|
||||
color.a = clamp(length(viewer) / u_PortalRange, 0.0, 1.0);
|
||||
}
|
||||
|
||||
return color;
|
||||
|
@ -194,13 +189,13 @@ float CalcFog(vec4 position)
|
|||
float s = dot(position, u_FogDistance) * 8.0;
|
||||
float t = dot(position, u_FogDepth);
|
||||
|
||||
bool eyeOutside = u_FogEyeT < 0.0;
|
||||
float t2 = float(t >= float(eyeOutside));
|
||||
float eyeOutside = step(0.0, -u_FogEyeT);
|
||||
float fogged = step(eyeOutside, t);
|
||||
|
||||
t = max(t, 1e-6);
|
||||
t *= fogged / (t - u_FogEyeT * eyeOutside);
|
||||
|
||||
if (eyeOutside)
|
||||
t2 *= t / (t - u_FogEyeT);
|
||||
|
||||
return s * t2;
|
||||
return s * t;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -176,17 +176,21 @@ float CalcBlinn(float NH, float shininess)
|
|||
#endif
|
||||
}
|
||||
|
||||
float CalcGGX(float NH, float shininess)
|
||||
float CalcGGX(float NH, float gloss)
|
||||
{
|
||||
// from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes.pdf
|
||||
float m_sq = 2.0 / shininess;
|
||||
float d = ((NH * NH) * (m_sq - 1.0) + 1.0);
|
||||
return m_sq / (d * d);
|
||||
// from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
|
||||
float a_sq = exp2(gloss * -13.0 + 1.0);
|
||||
float d = ((NH * NH) * (a_sq - 1.0) + 1.0);
|
||||
return a_sq / (d * d);
|
||||
}
|
||||
|
||||
float CalcFresnel(float EH)
|
||||
{
|
||||
#if 1
|
||||
// From http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf
|
||||
// not accurate, but fast
|
||||
return exp2(-10.0 * EH);
|
||||
#elif 0
|
||||
// From http://seblagarde.wordpress.com/2012/06/03/spherical-gaussien-approximation-for-blinn-phong-phong-and-fresnel/
|
||||
return exp2((-5.55473 * EH - 6.98316) * EH);
|
||||
#elif 0
|
||||
|
@ -196,42 +200,48 @@ float CalcFresnel(float EH)
|
|||
|
||||
return blend;
|
||||
#else
|
||||
return pow(1.0 - NH, 5.0);
|
||||
return pow(1.0 - EH, 5.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
float CalcVisibility(float NH, float NL, float NE, float EH, float shininess)
|
||||
float CalcVisibility(float NH, float NL, float NE, float EH, float gloss)
|
||||
{
|
||||
#if 0
|
||||
float geo = 2.0 * NH * min(NE, NL);
|
||||
geo /= max(EH, geo);
|
||||
|
||||
return geo;
|
||||
#else
|
||||
// Modified from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes.pdf
|
||||
// NL, NE in numerator factored out from cook-torrance
|
||||
#if 1
|
||||
// From http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf
|
||||
float k = min(1.0, gloss + 0.545);
|
||||
return 1.0 / (k * EH * EH + (1.0 - k));
|
||||
#elif 0
|
||||
float roughness = exp2(gloss * -6.5);
|
||||
|
||||
#if defined(USE_GGX)
|
||||
float roughness = sqrt(2.0 / (shininess + 2.0));
|
||||
float k = (roughness + 1.0);
|
||||
// From http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
|
||||
float k = roughness + 1.0;
|
||||
k *= k * 0.125;
|
||||
#else
|
||||
float k = 2.0 / sqrt(3.1415926535 * (shininess + 2.0));
|
||||
float k = roughness;
|
||||
#endif
|
||||
// Modified from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
|
||||
// NL, NE in numerator factored out from cook-torrance
|
||||
float k2 = 1.0 - k;
|
||||
|
||||
float invGeo1 = NL * k2 + k;
|
||||
float invGeo2 = NE * k2 + k;
|
||||
|
||||
return 1.0 / (invGeo1 * invGeo2);
|
||||
#endif
|
||||
#else
|
||||
float geo = 2.0 * NH * min(NE, NL);
|
||||
geo /= max(EH, geo);
|
||||
|
||||
return geo;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
vec3 CalcSpecular(vec3 specular, float NH, float NL, float NE, float EH, float shininess)
|
||||
vec3 CalcSpecular(vec3 specular, float NH, float NL, float NE, float EH, float gloss, float shininess)
|
||||
{
|
||||
float blinn = CalcBlinn(NH, shininess);
|
||||
vec3 fSpecular = mix(specular, vec3(1.0), CalcFresnel(EH));
|
||||
float vis = CalcVisibility(NH, NL, NE, EH, shininess);
|
||||
float vis = CalcVisibility(NH, NL, NE, EH, gloss);
|
||||
|
||||
#if defined(USE_BLINN)
|
||||
// Normalized Blinn-Phong
|
||||
|
@ -330,13 +340,12 @@ void main()
|
|||
#endif
|
||||
|
||||
vec4 diffuse = texture2D(u_DiffuseMap, texCoords);
|
||||
#if defined(USE_GAMMA2_TEXTURES)
|
||||
diffuse.rgb *= diffuse.rgb;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
|
||||
#if defined(USE_LINEAR_LIGHT)
|
||||
diffuse.rgb *= diffuse.rgb;
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP)
|
||||
#if defined(SWIZZLE_NORMALMAP)
|
||||
N.xy = 2.0 * texture2D(u_NormalMap, texCoords).ag - vec2(1.0);
|
||||
|
@ -361,9 +370,9 @@ void main()
|
|||
|
||||
// surfaces not facing the light are always shadowed
|
||||
#if defined(USE_TANGENT_SPACE_LIGHT)
|
||||
shadowValue *= float(var_PrimaryLightDir.z > 0.0);
|
||||
shadowValue *= step(0.0, var_PrimaryLightDir.z);
|
||||
#else
|
||||
shadowValue *= float(dot(var_Normal.xyz, var_PrimaryLightDir.xyz) > 0.0);
|
||||
shadowValue *= step(0.0, dot(var_Normal.xyz, var_PrimaryLightDir.xyz));
|
||||
#endif
|
||||
|
||||
#if defined(SHADOWMAP_MODULATE)
|
||||
|
@ -403,9 +412,9 @@ void main()
|
|||
|
||||
#if defined(USE_SPECULARMAP)
|
||||
vec4 specular = texture2D(u_SpecularMap, texCoords);
|
||||
#if defined(USE_LINEAR_LIGHT)
|
||||
#if defined(USE_GAMMA2_TEXTURES)
|
||||
specular.rgb *= specular.rgb;
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
vec4 specular = vec4(1.0);
|
||||
#endif
|
||||
|
@ -414,7 +423,6 @@ void main()
|
|||
|
||||
float gloss = specular.a;
|
||||
float shininess = exp2(gloss * 13.0);
|
||||
float localOcclusion = clamp((diffuse.r + diffuse.g + diffuse.b) * 16.0f, 0.0, 1.0);
|
||||
|
||||
#if defined(SPECULAR_IS_METALLIC)
|
||||
// diffuse is actually base color, and red of specular is metallicness
|
||||
|
@ -431,10 +439,12 @@ void main()
|
|||
reflectance = CalcDiffuse(diffuse.rgb, N, L, E, NE, NL, shininess);
|
||||
|
||||
#if defined(r_deluxeSpecular) || defined(USE_LIGHT_VECTOR)
|
||||
float adjGloss = gloss;
|
||||
float adjShininess = shininess;
|
||||
|
||||
#if !defined(USE_LIGHT_VECTOR)
|
||||
adjShininess = exp2(gloss * r_deluxeSpecular * 13.0);
|
||||
adjGloss *= r_deluxeSpecular;
|
||||
adjShininess = exp2(adjGloss * 13.0);
|
||||
#endif
|
||||
|
||||
H = normalize(L + E);
|
||||
|
@ -443,9 +453,9 @@ void main()
|
|||
NH = clamp(dot(N, H), 0.0, 1.0);
|
||||
|
||||
#if !defined(USE_LIGHT_VECTOR)
|
||||
reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, adjShininess) * r_deluxeSpecular * localOcclusion;
|
||||
reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, adjGloss, adjShininess) * r_deluxeSpecular;
|
||||
#else
|
||||
reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, adjShininess) * localOcclusion;
|
||||
reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, adjGloss, adjShininess);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -462,10 +472,6 @@ void main()
|
|||
|
||||
vec3 cubeLightColor = textureCubeLod(u_CubeMap, R, 7.0 - gloss * 7.0).rgb;
|
||||
|
||||
#if defined(USE_LINEAR_LIGHT)
|
||||
cubeLightColor *= cubeLightColor;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
cubeLightColor *= lightSample.rgb;
|
||||
#elif defined (USE_LIGHT_VERTEX)
|
||||
|
@ -475,11 +481,11 @@ void main()
|
|||
#endif
|
||||
|
||||
//gl_FragColor.rgb += diffuse.rgb * textureCubeLod(u_CubeMap, N, 7.0).rgb;
|
||||
gl_FragColor.rgb += cubeLightColor * reflectance * localOcclusion;
|
||||
gl_FragColor.rgb += cubeLightColor * reflectance;
|
||||
#endif
|
||||
|
||||
#if defined(USE_PRIMARY_LIGHT)
|
||||
L = normalize(var_PrimaryLightDir.xyz);
|
||||
L = var_PrimaryLightDir.xyz; //normalize(var_PrimaryLightDir.xyz);
|
||||
NL = clamp(dot(N, L), 0.0, 1.0);
|
||||
|
||||
H = normalize(L + E);
|
||||
|
@ -487,7 +493,7 @@ void main()
|
|||
NH = clamp(dot(N, H), 0.0, 1.0);
|
||||
|
||||
reflectance = CalcDiffuse(diffuse.rgb, N, L, E, NE, NL, shininess);
|
||||
reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, shininess);
|
||||
reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, gloss, shininess);
|
||||
|
||||
lightColor = u_PrimaryLightColor; // * CalcLightAttenuation(L, u_PrimaryLightDir.w);
|
||||
|
||||
|
@ -497,10 +503,6 @@ void main()
|
|||
|
||||
gl_FragColor.rgb += lightColor * reflectance * NL;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LINEAR_LIGHT)
|
||||
gl_FragColor.rgb = sqrt(gl_FragColor.rgb);
|
||||
#endif
|
||||
|
||||
gl_FragColor.a = diffuse.a;
|
||||
#else
|
||||
|
|
|
@ -113,7 +113,7 @@ vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
|
|||
float phase = offTurb.w;
|
||||
vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy;
|
||||
|
||||
vec3 offsetPos = position * 0.0009765625;
|
||||
vec3 offsetPos = position / 1024.0;
|
||||
offsetPos.x += offsetPos.z;
|
||||
|
||||
vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI);
|
||||
|
@ -183,7 +183,7 @@ void main()
|
|||
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
vec3 L = u_LightOrigin.xyz - (position * u_LightOrigin.w);
|
||||
#elif defined(USE_LIGHT) && !defined(USE_LIGHT_VECTOR)
|
||||
#elif defined(USE_LIGHT) && !defined(USE_DELUXEMAP)
|
||||
vec3 L = attr_LightDirection;
|
||||
#if defined(USE_MODELMATRIX)
|
||||
L = (u_ModelMatrix * vec4(L, 0.0)).xyz;
|
||||
|
@ -194,12 +194,10 @@ void main()
|
|||
var_TexCoords.zw = attr_TexCoord1.st;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
var_LightColor = u_VertColor.rgb * attr_Color.rgb;
|
||||
var_Color.rgb = vec3(1.0);
|
||||
var_Color.a = u_VertColor.a * attr_Color.a + u_BaseColor.a;
|
||||
#else
|
||||
var_Color = u_VertColor * attr_Color + u_BaseColor;
|
||||
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
var_LightColor = var_Color.rgb;
|
||||
var_Color.rgb = vec3(1.0);
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT)
|
||||
|
@ -209,14 +207,8 @@ void main()
|
|||
var_Color.rgb *= u_DirectedLight * attenuation * NL + u_AmbientLight;
|
||||
#endif
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
var_Normal.xyz = normal;
|
||||
var_Tangent.xyz = tangent;
|
||||
var_Bitangent.xyz = bitangent;
|
||||
#endif
|
||||
|
||||
#if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP)
|
||||
var_PrimaryLightDir.xyz = (u_PrimaryLightOrigin.xyz - (position * u_PrimaryLightOrigin.w));
|
||||
var_PrimaryLightDir.xyz = u_PrimaryLightOrigin.xyz - (position * u_PrimaryLightOrigin.w);
|
||||
var_PrimaryLightDir.w = u_PrimaryLightRadius * u_PrimaryLightRadius;
|
||||
#endif
|
||||
|
||||
|
@ -229,7 +221,7 @@ void main()
|
|||
#endif
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
vec3 viewDir = (u_ViewOrigin - position);
|
||||
vec3 viewDir = u_ViewOrigin - position;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TANGENT_SPACE_LIGHT)
|
||||
|
@ -250,8 +242,8 @@ void main()
|
|||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
||||
// store view direction in tangent space to save on varyings
|
||||
var_Normal.w = viewDir.x;
|
||||
var_Tangent.w = viewDir.y;
|
||||
var_Bitangent.w = viewDir.z;
|
||||
var_Normal = vec4(normal, viewDir.x);
|
||||
var_Tangent = vec4(tangent, viewDir.y);
|
||||
var_Bitangent = vec4(bitangent, viewDir.z);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -294,11 +294,9 @@ static void GLSL_GetShaderHeader( GLenum shaderType, const GLcharARB *extra, cha
|
|||
"#define alphaGen_t\n"
|
||||
"#define AGEN_LIGHTING_SPECULAR %i\n"
|
||||
"#define AGEN_PORTAL %i\n"
|
||||
"#define AGEN_FRESNEL %i\n"
|
||||
"#endif\n",
|
||||
AGEN_LIGHTING_SPECULAR,
|
||||
AGEN_PORTAL,
|
||||
AGEN_FRESNEL));
|
||||
AGEN_PORTAL));
|
||||
|
||||
Q_strcat(dest, size,
|
||||
va("#ifndef texenv_t\n"
|
||||
|
@ -1829,7 +1827,6 @@ shaderProgram_t *GLSL_GetGenericShaderProgram(int stage)
|
|||
{
|
||||
case AGEN_LIGHTING_SPECULAR:
|
||||
case AGEN_PORTAL:
|
||||
case AGEN_FRESNEL:
|
||||
shaderAttribs |= GENERICDEF_USE_RGBAGEN;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -241,7 +241,6 @@ typedef enum {
|
|||
AGEN_WAVEFORM,
|
||||
AGEN_PORTAL,
|
||||
AGEN_CONST,
|
||||
AGEN_FRESNEL
|
||||
} alphaGen_t;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -423,44 +423,27 @@ static void ProjectDlightTexture( void ) {
|
|||
|
||||
static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t vertColor )
|
||||
{
|
||||
baseColor[0] =
|
||||
baseColor[1] =
|
||||
baseColor[2] =
|
||||
baseColor[3] = 1.0f;
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] =
|
||||
vertColor[3] = 0.0f;
|
||||
|
||||
//
|
||||
// rgbGen
|
||||
//
|
||||
switch ( pStage->rgbGen )
|
||||
{
|
||||
case CGEN_IDENTITY:
|
||||
baseColor[0] =
|
||||
baseColor[1] =
|
||||
baseColor[2] =
|
||||
baseColor[3] = 1.0f;
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] =
|
||||
vertColor[3] = 0.0f;
|
||||
break;
|
||||
case CGEN_IDENTITY_LIGHTING:
|
||||
baseColor[0] =
|
||||
baseColor[1] =
|
||||
baseColor[2] = tr.identityLight;
|
||||
baseColor[3] = 1.0f;
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] =
|
||||
vertColor[3] = 0.0f;
|
||||
break;
|
||||
case CGEN_EXACT_VERTEX:
|
||||
baseColor[0] =
|
||||
baseColor[1] =
|
||||
baseColor[2] =
|
||||
baseColor[3] = 0.0f;
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] =
|
||||
vertColor[3] = 1.0f;
|
||||
break;
|
||||
case CGEN_EXACT_VERTEX_LIT:
|
||||
baseColor[0] =
|
||||
baseColor[1] =
|
||||
|
@ -477,11 +460,6 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|
|||
baseColor[1] = pStage->constantColor[1] / 255.0f;
|
||||
baseColor[2] = pStage->constantColor[2] / 255.0f;
|
||||
baseColor[3] = pStage->constantColor[3] / 255.0f;
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] =
|
||||
vertColor[3] = 0.0f;
|
||||
break;
|
||||
case CGEN_VERTEX:
|
||||
baseColor[0] =
|
||||
|
@ -509,12 +487,10 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|
|||
baseColor[0] =
|
||||
baseColor[1] =
|
||||
baseColor[2] = tr.identityLight;
|
||||
baseColor[3] = 1.0f;
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] = -tr.identityLight;
|
||||
vertColor[3] = 0.0f;
|
||||
break;
|
||||
case CGEN_FOG:
|
||||
{
|
||||
|
@ -527,22 +503,11 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|
|||
baseColor[2] = ((unsigned char *)(&fog->colorInt))[2] / 255.0f;
|
||||
baseColor[3] = ((unsigned char *)(&fog->colorInt))[3] / 255.0f;
|
||||
}
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] =
|
||||
vertColor[3] = 0.0f;
|
||||
break;
|
||||
case CGEN_WAVEFORM:
|
||||
baseColor[0] =
|
||||
baseColor[1] =
|
||||
baseColor[2] = RB_CalcWaveColorSingle( &pStage->rgbWave );
|
||||
baseColor[3] = 1.0f;
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] =
|
||||
vertColor[3] = 0.0f;
|
||||
break;
|
||||
case CGEN_ENTITY:
|
||||
if (backEnd.currentEntity)
|
||||
|
@ -552,11 +517,6 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|
|||
baseColor[2] = ((unsigned char *)backEnd.currentEntity->e.shaderRGBA)[2] / 255.0f;
|
||||
baseColor[3] = ((unsigned char *)backEnd.currentEntity->e.shaderRGBA)[3] / 255.0f;
|
||||
}
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] =
|
||||
vertColor[3] = 0.0f;
|
||||
break;
|
||||
case CGEN_ONE_MINUS_ENTITY:
|
||||
if (backEnd.currentEntity)
|
||||
|
@ -566,23 +526,10 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|
|||
baseColor[2] = 1.0f - ((unsigned char *)backEnd.currentEntity->e.shaderRGBA)[2] / 255.0f;
|
||||
baseColor[3] = 1.0f - ((unsigned char *)backEnd.currentEntity->e.shaderRGBA)[3] / 255.0f;
|
||||
}
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] =
|
||||
vertColor[3] = 0.0f;
|
||||
break;
|
||||
case CGEN_IDENTITY:
|
||||
case CGEN_LIGHTING_DIFFUSE:
|
||||
case CGEN_BAD:
|
||||
baseColor[0] =
|
||||
baseColor[1] =
|
||||
baseColor[2] =
|
||||
baseColor[3] = 1.0f;
|
||||
|
||||
vertColor[0] =
|
||||
vertColor[1] =
|
||||
vertColor[2] =
|
||||
vertColor[3] = 0.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -593,10 +540,6 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|
|||
{
|
||||
case AGEN_SKIP:
|
||||
break;
|
||||
case AGEN_IDENTITY:
|
||||
baseColor[3] = 1.0f;
|
||||
vertColor[3] = 0.0f;
|
||||
break;
|
||||
case AGEN_CONST:
|
||||
baseColor[3] = pStage->constantColor[3] / 255.0f;
|
||||
vertColor[3] = 0.0f;
|
||||
|
@ -627,9 +570,9 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|
|||
baseColor[3] = 1.0f;
|
||||
vertColor[3] = -1.0f;
|
||||
break;
|
||||
case AGEN_IDENTITY:
|
||||
case AGEN_LIGHTING_SPECULAR:
|
||||
case AGEN_PORTAL:
|
||||
case AGEN_FRESNEL:
|
||||
// Done entirely in vertex program
|
||||
baseColor[3] = 1.0f;
|
||||
vertColor[3] = 0.0f;
|
||||
|
@ -1082,7 +1025,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
|
||||
if (backEnd.depthFill)
|
||||
{
|
||||
if (pStage->glslShaderGroup)
|
||||
if (pStage->glslShaderGroup == tr.lightallShader)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
|
@ -1120,7 +1063,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
sp = &tr.genericShader[shaderAttribs];
|
||||
}
|
||||
}
|
||||
else if (pStage->glslShaderGroup)
|
||||
else if (pStage->glslShaderGroup == tr.lightallShader)
|
||||
{
|
||||
int index = pStage->glslShaderIndex;
|
||||
|
||||
|
@ -1146,10 +1089,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
|
||||
sp = &pStage->glslShaderGroup[index];
|
||||
|
||||
if (pStage->glslShaderGroup == tr.lightallShader)
|
||||
{
|
||||
backEnd.pc.c_lightallDraws++;
|
||||
}
|
||||
backEnd.pc.c_lightallDraws++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1269,7 +1209,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
else if ( pStage->bundle[TB_COLORMAP].image[0] != 0 )
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_COLORMAP], TB_COLORMAP );
|
||||
}
|
||||
else if ( pStage->glslShaderGroup )
|
||||
else if ( pStage->glslShaderGroup == tr.lightallShader )
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -1285,13 +1225,29 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
{
|
||||
for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
|
||||
{
|
||||
if (i == TB_LIGHTMAP)
|
||||
image_t *img;
|
||||
|
||||
if (pStage->bundle[i].image[0])
|
||||
{
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[i], i);
|
||||
}
|
||||
else if (pStage->bundle[i].image[0])
|
||||
{
|
||||
GL_BindToTMU( tr.whiteImage, i);
|
||||
switch(i)
|
||||
{
|
||||
case TB_LIGHTMAP:
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_LIGHTMAP], i);
|
||||
break;
|
||||
|
||||
case TB_DIFFUSEMAP:
|
||||
case TB_SPECULARMAP:
|
||||
case TB_SHADOWMAP:
|
||||
case TB_CUBEMAP:
|
||||
default:
|
||||
GL_BindToTMU( tr.whiteImage, i);
|
||||
break;
|
||||
|
||||
case TB_NORMALMAP:
|
||||
case TB_DELUXEMAP:
|
||||
GL_BindToTMU( tr.greyImage, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1299,15 +1255,32 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
{
|
||||
for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
|
||||
{
|
||||
if (i == TB_LIGHTMAP)
|
||||
image_t *img;
|
||||
|
||||
if (pStage->bundle[i].image[0])
|
||||
{
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], i);
|
||||
}
|
||||
else if (pStage->bundle[i].image[0])
|
||||
{
|
||||
GL_BindToTMU( tr.whiteImage, i);
|
||||
switch(i)
|
||||
{
|
||||
case TB_LIGHTMAP:
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], i);
|
||||
break;
|
||||
|
||||
case TB_DIFFUSEMAP:
|
||||
case TB_SPECULARMAP:
|
||||
case TB_SHADOWMAP:
|
||||
case TB_CUBEMAP:
|
||||
default:
|
||||
GL_BindToTMU( tr.whiteImage, i);
|
||||
break;
|
||||
|
||||
case TB_NORMALMAP:
|
||||
case TB_DELUXEMAP:
|
||||
GL_BindToTMU( tr.greyImage, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1109,10 +1109,6 @@ static qboolean ParseStage( shaderStage_t *stage, char **text )
|
|||
shader.portalRange = atof( token );
|
||||
}
|
||||
}
|
||||
else if ( !Q_stricmp( token, "fresnel" ) )
|
||||
{
|
||||
stage->alphaGen = AGEN_FRESNEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ri.Printf( PRINT_WARNING, "WARNING: unknown alphaGen parameter '%s' in shader '%s'\n", token, shader.name );
|
||||
|
@ -2011,7 +2007,6 @@ static void ComputeVertexAttribs(void)
|
|||
switch(pStage->alphaGen)
|
||||
{
|
||||
case AGEN_LIGHTING_SPECULAR:
|
||||
case AGEN_FRESNEL:
|
||||
shader.vertexAttribs |= ATTR_NORMAL;
|
||||
break;
|
||||
|
||||
|
@ -2247,15 +2242,6 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse,
|
|||
defs |= LIGHTDEF_USE_PARALLAXMAP;
|
||||
}
|
||||
}
|
||||
|
||||
if (!diffuse->bundle[TB_NORMALMAP].image[0])
|
||||
{
|
||||
// use 0x80 image, shader will interpret as (0,0,1)
|
||||
diffuse->bundle[TB_NORMALMAP] = diffuse->bundle[0];
|
||||
diffuse->bundle[TB_NORMALMAP].numImageAnimations = 0;
|
||||
diffuse->bundle[TB_NORMALMAP].image[0] = tr.greyImage;
|
||||
//ri.Printf(PRINT_ALL, ", normalmap %s", diffuse->bundle[TB_NORMALMAP].image[0]->imgName);
|
||||
}
|
||||
}
|
||||
|
||||
if (r_specularMapping->integer)
|
||||
|
@ -2267,18 +2253,6 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse,
|
|||
diffuse->materialInfo[0] = specular->materialInfo[0];
|
||||
diffuse->materialInfo[1] = specular->materialInfo[1];
|
||||
}
|
||||
else if (lightmap || useLightVector || useLightVertex)
|
||||
{
|
||||
// use a white image, materialinfo will do the rest
|
||||
diffuse->bundle[TB_SPECULARMAP] = diffuse->bundle[0];
|
||||
diffuse->bundle[TB_SPECULARMAP].numImageAnimations = 0;
|
||||
diffuse->bundle[TB_SPECULARMAP].image[0] = tr.whiteImage;
|
||||
if (!diffuse->materialInfo[0])
|
||||
diffuse->materialInfo[0] = r_baseSpecular->value;
|
||||
if (!diffuse->materialInfo[1])
|
||||
diffuse->materialInfo[1] = r_baseGloss->value;
|
||||
//ri.Printf(PRINT_ALL, ", specularmap %s", diffuse->bundle[TB_SPECULARMAP].image[0]->imgName);
|
||||
}
|
||||
}
|
||||
|
||||
if (tcgen || diffuse->bundle[0].numTexMods)
|
||||
|
@ -2372,7 +2346,6 @@ static qboolean CollapseStagesToGLSL(void)
|
|||
{
|
||||
case AGEN_LIGHTING_SPECULAR:
|
||||
case AGEN_PORTAL:
|
||||
case AGEN_FRESNEL:
|
||||
skip = qtrue;
|
||||
break;
|
||||
default:
|
||||
|
@ -2581,7 +2554,7 @@ static qboolean CollapseStagesToGLSL(void)
|
|||
}
|
||||
}
|
||||
|
||||
// convert any remaining lightingdiffuse stages to a lighting pass
|
||||
// insert default normal and specular textures if necessary
|
||||
for (i = 0; i < MAX_SHADER_STAGES; i++)
|
||||
{
|
||||
shaderStage_t *pStage = &stages[i];
|
||||
|
@ -2589,14 +2562,27 @@ static qboolean CollapseStagesToGLSL(void)
|
|||
if (!pStage->active)
|
||||
continue;
|
||||
|
||||
if (pStage->rgbGen == CGEN_LIGHTING_DIFFUSE)
|
||||
if (pStage->glslShaderGroup != tr.lightallShader)
|
||||
continue;
|
||||
|
||||
if ((pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK) == 0)
|
||||
continue;
|
||||
|
||||
if (!pStage->bundle[TB_NORMALMAP].image[0] && r_normalMapping->integer)
|
||||
{
|
||||
pStage->glslShaderGroup = tr.lightallShader;
|
||||
pStage->glslShaderIndex = LIGHTDEF_USE_LIGHT_VECTOR;
|
||||
pStage->bundle[TB_NORMALMAP].image[0] = tr.greyImage;
|
||||
}
|
||||
|
||||
if (!pStage->bundle[TB_SPECULARMAP].image[0] && r_specularMapping->integer)
|
||||
{
|
||||
pStage->bundle[TB_SPECULARMAP].image[0] = tr.whiteImage;
|
||||
if (!pStage->materialInfo[0])
|
||||
pStage->materialInfo[0] = r_baseSpecular->value;
|
||||
if (!pStage->materialInfo[1])
|
||||
pStage->materialInfo[1] = r_baseGloss->value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return numStages;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue