mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2024-11-10 23:02:01 +00:00
OpenGL2: Parallax corrected cubemap (cheaper trick)
This commit is contained in:
parent
d0d1883895
commit
375f6247d4
4 changed files with 32 additions and 4 deletions
|
@ -44,6 +44,12 @@ uniform vec4 u_NormalScale;
|
|||
uniform vec4 u_SpecularScale;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_CUBEMAP)
|
||||
uniform vec4 u_CubeMapInfo;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
varying vec4 var_TexCoords;
|
||||
|
||||
varying vec4 var_Color;
|
||||
|
@ -323,19 +329,20 @@ mat3 cotangent_frame( vec3 N, vec3 p, vec2 uv )
|
|||
|
||||
void main()
|
||||
{
|
||||
vec3 viewDir;
|
||||
vec3 L, N, E, H;
|
||||
float NL, NH, NE, EH;
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
mat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent.xyz, var_Normal.xyz);
|
||||
E = vec3(var_Normal.w, var_Tangent.w, var_Bitangent.w);
|
||||
viewDir = vec3(var_Normal.w, var_Tangent.w, var_Bitangent.w);
|
||||
#else
|
||||
mat3 tangentToWorld = cotangent_frame(var_Normal, -var_ViewDir, var_TexCoords.xy);
|
||||
E = var_ViewDir;
|
||||
viewDir = var_ViewDir;
|
||||
#endif
|
||||
|
||||
E = normalize(E);
|
||||
E = normalize(viewDir);
|
||||
|
||||
L = var_LightDir.xyz;
|
||||
#if defined(USE_DELUXEMAP)
|
||||
|
@ -497,6 +504,10 @@ void main()
|
|||
|
||||
vec3 R = reflect(E, N);
|
||||
|
||||
// parallax corrected cubemap (cheaper trick)
|
||||
// from http://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
|
||||
R += u_CubeMapInfo.xyz + u_CubeMapInfo.w * viewDir;
|
||||
|
||||
vec3 cubeLightColor = textureCubeLod(u_CubeMap, R, 7.0 - gloss * 7.0).rgb * u_EnableTextures.w;
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
|
|
|
@ -142,7 +142,9 @@ static uniformInfo_t uniformsInfo[] =
|
|||
{ "u_PrimaryLightOrigin", GLSL_VEC4 },
|
||||
{ "u_PrimaryLightColor", GLSL_VEC3 },
|
||||
{ "u_PrimaryLightAmbient", GLSL_VEC3 },
|
||||
{ "u_PrimaryLightRadius", GLSL_FLOAT }
|
||||
{ "u_PrimaryLightRadius", GLSL_FLOAT },
|
||||
|
||||
{ "u_CubeMapInfo", GLSL_VEC4 },
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -698,6 +698,8 @@ typedef enum
|
|||
UNIFORM_PRIMARYLIGHTAMBIENT,
|
||||
UNIFORM_PRIMARYLIGHTRADIUS,
|
||||
|
||||
UNIFORM_CUBEMAPINFO,
|
||||
|
||||
UNIFORM_COUNT
|
||||
} uniform_t;
|
||||
|
||||
|
|
|
@ -1378,8 +1378,21 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
// testing cube map
|
||||
//
|
||||
if (!(tr.viewParms.flags & VPF_NOCUBEMAPS) && input->cubemapIndex && r_cubeMapping->integer)
|
||||
{
|
||||
vec4_t vec;
|
||||
|
||||
GL_BindToTMU( tr.cubemaps[input->cubemapIndex - 1], TB_CUBEMAP);
|
||||
|
||||
vec[0] = tr.cubemapOrigins[input->cubemapIndex - 1][0] - backEnd.viewParms.or.origin[0];
|
||||
vec[1] = tr.cubemapOrigins[input->cubemapIndex - 1][1] - backEnd.viewParms.or.origin[1];
|
||||
vec[2] = tr.cubemapOrigins[input->cubemapIndex - 1][2] - backEnd.viewParms.or.origin[2];
|
||||
vec[3] = 1.0f;
|
||||
|
||||
VectorScale4(vec, 1.0f / 1000.0f, vec);
|
||||
|
||||
GLSL_SetUniformVec4(sp, UNIFORM_CUBEMAPINFO, vec);
|
||||
}
|
||||
|
||||
//
|
||||
// draw
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue