mirror of
https://github.com/UberGames/ioef.git
synced 2024-11-30 16:01:46 +00:00
OpenGL2: Remove some rendering options for simplicity.
This commit is contained in:
parent
2954bdfa65
commit
e5aabdaff6
5 changed files with 40 additions and 248 deletions
|
@ -150,156 +150,35 @@ float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
|
|||
}
|
||||
#endif
|
||||
|
||||
vec3 CalcDiffuse(vec3 diffuseAlbedo, vec3 N, vec3 L, vec3 E, float NE, float NL, float shininess)
|
||||
vec3 CalcDiffuse(vec3 diffuseAlbedo, float EH, float NH, float r)
|
||||
{
|
||||
#if defined(USE_OREN_NAYAR) || defined(USE_TRIACE_OREN_NAYAR)
|
||||
float gamma = dot(E, L) - NE * NL;
|
||||
float B = 2.22222 + 0.1 * shininess;
|
||||
|
||||
#if defined(USE_OREN_NAYAR)
|
||||
float A = 1.0 - 1.0 / (2.0 + 0.33 * shininess);
|
||||
gamma = clamp(gamma, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
#if defined(USE_TRIACE_OREN_NAYAR)
|
||||
float A = 1.0 - 1.0 / (2.0 + 0.65 * shininess);
|
||||
|
||||
if (gamma >= 0.0)
|
||||
#endif
|
||||
{
|
||||
B = max(B * max(NL, NE), EPSILON);
|
||||
}
|
||||
|
||||
return diffuseAlbedo * (A + gamma / B);
|
||||
#else
|
||||
#if defined(USE_BURLEY)
|
||||
// modified from https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf
|
||||
float fd90 = -0.5 + EH * EH * r;
|
||||
float burley = 1.0 + fd90 * 0.04 / NH;
|
||||
burley *= burley;
|
||||
return diffuseAlbedo * burley;
|
||||
#else
|
||||
return diffuseAlbedo;
|
||||
#endif
|
||||
}
|
||||
|
||||
vec3 EnvironmentBRDF(float gloss, float NE, vec3 specular)
|
||||
{
|
||||
#if 1
|
||||
// from http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf
|
||||
vec4 t = vec4( 1.0/0.96, 0.475, (0.0275 - 0.25 * 0.04)/0.96,0.25 ) * gloss;
|
||||
t += vec4( 0.0, 0.0, (0.015 - 0.75 * 0.04)/0.96,0.75 );
|
||||
float a0 = t.x * min( t.y, exp2( -9.28 * NE ) ) + t.z;
|
||||
float a1 = t.w;
|
||||
return clamp( a0 + specular * ( a1 - a0 ), 0.0, 1.0 );
|
||||
#elif 0
|
||||
// from http://seblagarde.wordpress.com/2011/08/17/hello-world/
|
||||
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));
|
||||
#endif
|
||||
}
|
||||
|
||||
float CalcBlinn(float NH, float shininess)
|
||||
{
|
||||
#if defined(USE_BLINN) || defined(USE_BLINN_FRESNEL)
|
||||
// Normalized Blinn-Phong
|
||||
float norm = shininess * 0.125 + 1.0;
|
||||
#elif defined(USE_MCAULEY)
|
||||
// Cook-Torrance as done by Stephen McAuley
|
||||
// http://blog.selfshadow.com/publications/s2012-shading-course/mcauley/s2012_pbs_farcry3_notes_v2.pdf
|
||||
float norm = shininess * 0.25 + 0.125;
|
||||
#elif defined(USE_GOTANDA)
|
||||
// Neumann-Neumann as done by Yoshiharu Gotanda
|
||||
// http://research.tri-ace.com/Data/s2012_beyond_CourseNotes.pdf
|
||||
float norm = shininess * 0.124858 + 0.269182;
|
||||
#elif defined(USE_LAZAROV)
|
||||
// Cook-Torrance as done by Dimitar Lazarov
|
||||
// http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf
|
||||
float norm = shininess * 0.125 + 0.25;
|
||||
#else
|
||||
float norm = 1.0;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// from http://seblagarde.wordpress.com/2012/06/03/spherical-gaussien-approximation-for-blinn-phong-phong-and-fresnel/
|
||||
float a = shininess + 0.775;
|
||||
return norm * exp(a * NH - a);
|
||||
#else
|
||||
return norm * pow(NH, shininess);
|
||||
#endif
|
||||
}
|
||||
|
||||
float CalcGGX(float NH, float gloss)
|
||||
vec3 EnvironmentBRDF(float r, float NE, vec3 specular)
|
||||
{
|
||||
// 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);
|
||||
// from http://community.arm.com/servlet/JiveServlet/download/96891546-19496/siggraph2015-mmg-renaldas-slides.pdf
|
||||
float v = 1.0 - max(r, NE);
|
||||
v *= v * v;
|
||||
return vec3(v) + specular;
|
||||
}
|
||||
|
||||
float CalcFresnel(float EH)
|
||||
vec3 CalcSpecular(vec3 specular, float NH, float NL, float NE, float EH, float r)
|
||||
{
|
||||
#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
|
||||
float blend = 1.0 - EH;
|
||||
float blend2 = blend * blend;
|
||||
blend *= blend2 * blend2;
|
||||
|
||||
return blend;
|
||||
#else
|
||||
return pow(1.0 - EH, 5.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
float CalcVisibility(float NH, float NL, float NE, float EH, float gloss)
|
||||
{
|
||||
#if defined(USE_GOTANDA)
|
||||
// Neumann-Neumann as done by Yoshiharu Gotanda
|
||||
// http://research.tri-ace.com/Data/s2012_beyond_CourseNotes.pdf
|
||||
return 1.0 / max(max(NL, NE), EPSILON);
|
||||
#elif defined(USE_LAZAROV)
|
||||
// Cook-Torrance as done by Dimitar Lazarov
|
||||
// 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) + 1.0);
|
||||
#elif defined(USE_GGX)
|
||||
float roughness = exp2(gloss * -6.5);
|
||||
|
||||
// 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 k = roughness + 1.0;
|
||||
k *= k * 0.125;
|
||||
|
||||
float k2 = 1.0 - k;
|
||||
|
||||
float invGeo1 = NL * k2 + k;
|
||||
float invGeo2 = NE * k2 + k;
|
||||
|
||||
return 1.0 / (invGeo1 * invGeo2);
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
vec3 CalcSpecular(vec3 specular, float NH, float NL, float NE, float EH, float gloss, float shininess)
|
||||
{
|
||||
#if defined(USE_GGX)
|
||||
float distrib = CalcGGX(NH, gloss);
|
||||
#else
|
||||
float distrib = CalcBlinn(NH, shininess);
|
||||
#endif
|
||||
|
||||
#if defined(USE_BLINN)
|
||||
vec3 fSpecular = specular;
|
||||
#else
|
||||
vec3 fSpecular = mix(specular, vec3(1.0), CalcFresnel(EH));
|
||||
#endif
|
||||
|
||||
float vis = CalcVisibility(NH, NL, NE, EH, gloss);
|
||||
|
||||
return fSpecular * (distrib * vis);
|
||||
// from http://community.arm.com/servlet/JiveServlet/download/96891546-19496/siggraph2015-mmg-renaldas-slides.pdf
|
||||
float rr = r*r;
|
||||
float rrrr = rr*rr;
|
||||
float d = (NH * NH) * (rrrr - 1.0) + 1.0;
|
||||
float v = (EH * EH) * (r + 0.5);
|
||||
return specular * (rrrr / (4.0 * d * d * v));
|
||||
}
|
||||
|
||||
|
||||
|
@ -421,14 +300,7 @@ void main()
|
|||
shadowValue *= float(dot(var_Normal.xyz, var_PrimaryLightDir.xyz) > 0.0);
|
||||
|
||||
#if defined(SHADOWMAP_MODULATE)
|
||||
//vec3 shadowColor = min(u_PrimaryLightAmbient, lightColor);
|
||||
vec3 shadowColor = u_PrimaryLightAmbient * lightColor;
|
||||
|
||||
#if 0
|
||||
// Only shadow when the world light is parallel to the primary light
|
||||
shadowValue = 1.0 + (shadowValue - 1.0) * clamp(dot(L, var_PrimaryLightDir.xyz), 0.0, 1.0);
|
||||
#endif
|
||||
lightColor = mix(shadowColor, lightColor, shadowValue);
|
||||
lightColor *= shadowValue * (1.0 - u_PrimaryLightAmbient.r) + u_PrimaryLightAmbient.r;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -465,65 +337,39 @@ void main()
|
|||
|
||||
#if defined(r_materialGamma)
|
||||
diffuse.rgb = pow(diffuse.rgb, vec3(r_materialGamma));
|
||||
#if !defined(SPECULAR_IS_METALLIC)
|
||||
specular.rgb = pow(specular.rgb, vec3(r_materialGamma));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
float gloss = specular.a;
|
||||
float shininess = exp2(gloss * 13.0);
|
||||
float r = exp2(-3.0 * gloss);
|
||||
|
||||
#if defined(SPECULAR_IS_METALLIC)
|
||||
// diffuse is actually base color, and red of specular is metallicness
|
||||
float metallic = specular.r;
|
||||
// diffuse is actually base color, and green of specular is metallicness
|
||||
float metallic = specular.g;
|
||||
|
||||
specular.rgb = (0.96 * metallic) * diffuse.rgb + vec3(0.04);
|
||||
specular.rgb = metallic * diffuse.rgb + vec3(0.04 - 0.04 * metallic);
|
||||
diffuse.rgb *= 1.0 - metallic;
|
||||
#else
|
||||
// adjust diffuse by specular reflectance, to maintain energy conservation
|
||||
diffuse.rgb *= vec3(1.0) - specular.rgb;
|
||||
#endif
|
||||
|
||||
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)
|
||||
adjGloss *= r_deluxeSpecular;
|
||||
adjShininess = exp2(adjGloss * 13.0);
|
||||
#endif
|
||||
|
||||
H = normalize(L + E);
|
||||
|
||||
reflectance = CalcDiffuse(diffuse.rgb, EH, NH, r);
|
||||
#if defined(USE_SHADOWMAP) && defined(SHADOWMAP_MODULATE)
|
||||
// bit of a hack, with modulated shadowmaps, add specular to sunlight
|
||||
H = normalize(var_PrimaryLightDir.xyz + E);
|
||||
EH = clamp(dot(E, H), 0.0, 1.0);
|
||||
NH = clamp(dot(N, H), 0.0, 1.0);
|
||||
|
||||
#if !defined(USE_LIGHT_VECTOR)
|
||||
reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, adjGloss, adjShininess) * r_deluxeSpecular;
|
||||
#else
|
||||
reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, adjGloss, adjShininess);
|
||||
#endif
|
||||
reflectance += shadowValue * CalcSpecular(specular.rgb, NH, NL, NE, EH, r);
|
||||
#endif
|
||||
|
||||
gl_FragColor.rgb = lightColor * reflectance * (attenuation * 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);
|
||||
reflectance = EnvironmentBRDF(r, NE, specular.rgb);
|
||||
|
||||
vec3 R = reflect(E, N);
|
||||
|
||||
|
@ -565,8 +411,8 @@ void main()
|
|||
EH2 = clamp(dot(E, H2), 0.0, 1.0);
|
||||
NH2 = clamp(dot(N, H2), 0.0, 1.0);
|
||||
|
||||
reflectance = CalcDiffuse(diffuse.rgb, N, L2, E, NE, NL2, shininess);
|
||||
reflectance += CalcSpecular(specular.rgb, NH2, NL2, NE, EH2, gloss, shininess);
|
||||
reflectance = CalcDiffuse(diffuse.rgb, EH2, NH2, r);
|
||||
reflectance += CalcSpecular(specular.rgb, NH2, NL2, NE, EH2, r);
|
||||
|
||||
lightColor = u_PrimaryLightColor * var_Color.rgb;
|
||||
|
||||
|
|
|
@ -1022,9 +1022,6 @@ void GLSL_InitGPUShaders(void)
|
|||
|
||||
extradefines[0] = '\0';
|
||||
|
||||
if (r_deluxeSpecular->value > 0.000001f)
|
||||
Q_strcat(extradefines, 1024, va("#define r_deluxeSpecular %f\n", r_deluxeSpecular->value));
|
||||
|
||||
if (r_specularIsMetallic->value)
|
||||
Q_strcat(extradefines, 1024, "#define SPECULAR_IS_METALLIC\n");
|
||||
|
||||
|
@ -1067,12 +1064,6 @@ void GLSL_InitGPUShaders(void)
|
|||
{
|
||||
Q_strcat(extradefines, 1024, "#define USE_NORMALMAP\n");
|
||||
|
||||
if (r_normalMapping->integer == 2)
|
||||
Q_strcat(extradefines, 1024, "#define USE_OREN_NAYAR\n");
|
||||
|
||||
if (r_normalMapping->integer == 3)
|
||||
Q_strcat(extradefines, 1024, "#define USE_TRIACE_OREN_NAYAR\n");
|
||||
|
||||
#ifdef USE_VERT_TANGENT_SPACE
|
||||
Q_strcat(extradefines, 1024, "#define USE_VERT_TANGENT_SPACE\n");
|
||||
attribs |= ATTR_TANGENT;
|
||||
|
@ -1087,34 +1078,8 @@ void GLSL_InitGPUShaders(void)
|
|||
}
|
||||
|
||||
if (r_specularMapping->integer)
|
||||
{
|
||||
Q_strcat(extradefines, 1024, "#define USE_SPECULARMAP\n");
|
||||
|
||||
switch (r_specularMapping->integer)
|
||||
{
|
||||
case 1:
|
||||
default:
|
||||
Q_strcat(extradefines, 1024, "#define USE_BLINN\n");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
Q_strcat(extradefines, 1024, "#define USE_BLINN_FRESNEL\n");
|
||||
break;
|
||||
|
||||
case 3:
|
||||
Q_strcat(extradefines, 1024, "#define USE_MCAULEY\n");
|
||||
break;
|
||||
|
||||
case 4:
|
||||
Q_strcat(extradefines, 1024, "#define USE_GOTANDA\n");
|
||||
break;
|
||||
|
||||
case 5:
|
||||
Q_strcat(extradefines, 1024, "#define USE_LAZAROV\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (r_cubeMapping->integer)
|
||||
Q_strcat(extradefines, 1024, "#define USE_CUBEMAP\n");
|
||||
}
|
||||
|
|
|
@ -142,7 +142,6 @@ cvar_t *r_specularMapping;
|
|||
cvar_t *r_deluxeMapping;
|
||||
cvar_t *r_parallaxMapping;
|
||||
cvar_t *r_cubeMapping;
|
||||
cvar_t *r_deluxeSpecular;
|
||||
cvar_t *r_specularIsMetallic;
|
||||
cvar_t *r_baseNormalX;
|
||||
cvar_t *r_baseNormalY;
|
||||
|
@ -1213,7 +1212,6 @@ void R_Register( void )
|
|||
r_deluxeMapping = ri.Cvar_Get( "r_deluxeMapping", "1", CVAR_ARCHIVE | CVAR_LATCH );
|
||||
r_parallaxMapping = ri.Cvar_Get( "r_parallaxMapping", "0", CVAR_ARCHIVE | CVAR_LATCH );
|
||||
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 );
|
||||
|
|
|
@ -1784,7 +1784,6 @@ extern cvar_t *r_specularMapping;
|
|||
extern cvar_t *r_deluxeMapping;
|
||||
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;
|
||||
|
|
|
@ -160,24 +160,15 @@ Cvars for HDR and tonemapping:
|
|||
|
||||
Cvars for advanced material usage:
|
||||
|
||||
* `r_normalMapping` - Enable normal mapping for materials that
|
||||
support it, and also specify advanced
|
||||
shading techniques.
|
||||
* `r_normalMapping` - Enable normal maps for materials that
|
||||
support it.
|
||||
0 - No.
|
||||
1 - Yes. (default)
|
||||
2 - Yes, and use Oren-Nayar reflectance
|
||||
model.
|
||||
3 - Yes, and use tri-Ace's Oren-Nayar
|
||||
reflectance model.
|
||||
|
||||
* `r_specularMapping` - Enable specular mapping for materials that
|
||||
support it, and also specify advanced
|
||||
specular techniques.
|
||||
* `r_specularMapping` - Enable specular maps for materials that
|
||||
support it.
|
||||
0 - No.
|
||||
1 - Yes, and use tri-Ace. (default)
|
||||
2 - Yes, and use Blinn-Phong.
|
||||
3 - Yes, and use Cook-Torrance.
|
||||
4 - Yes, and use Torrance-Sparrow.
|
||||
1 - Yes. (default)
|
||||
|
||||
* `r_deluxeMapping` - Enable deluxe mapping. (Map is compiled
|
||||
with light directions.) Even if the map
|
||||
|
@ -333,13 +324,6 @@ Cvars that you probably don't care about or shouldn't mess with:
|
|||
0 - No.
|
||||
1 - Yes. (default)
|
||||
|
||||
* `r_normalAmbient` - Split map light into ambient and directed
|
||||
portions when doing deluxe mapping. Not
|
||||
very useful.
|
||||
0 - Don't. (default).
|
||||
0.3 - 30% ambient, 70% directed.
|
||||
1.0 - 100% ambient.
|
||||
|
||||
* `r_mergeLightmaps` - Merge the small (128x128) lightmaps into
|
||||
2 or fewer giant (4096x4096) lightmaps.
|
||||
Easy speedup.
|
||||
|
|
Loading…
Reference in a new issue