mirror of https://github.com/OpenMW/openmw.git
Handle BSShader[PP/No]LightingProperty
parent
ded59c4858
commit
2fdbe9b3f6
@ -0,0 +1,106 @@
|
||||
#version 120
|
||||
|
||||
#if @useGPUShader4
|
||||
#extension GL_EXT_gpu_shader4: require
|
||||
#endif
|
||||
|
||||
#if @diffuseMap
|
||||
uniform sampler2D diffuseMap;
|
||||
varying vec2 diffuseMapUV;
|
||||
#endif
|
||||
|
||||
#if @emissiveMap
|
||||
uniform sampler2D emissiveMap;
|
||||
varying vec2 emissiveMapUV;
|
||||
#endif
|
||||
|
||||
#if @normalMap
|
||||
uniform sampler2D normalMap;
|
||||
varying vec2 normalMapUV;
|
||||
varying vec4 passTangent;
|
||||
#endif
|
||||
|
||||
uniform bool noAlpha;
|
||||
|
||||
varying float euclideanDepth;
|
||||
varying float linearDepth;
|
||||
|
||||
#define PER_PIXEL_LIGHTING 1
|
||||
|
||||
varying vec3 passViewPos;
|
||||
varying vec3 passNormal;
|
||||
|
||||
#include "vertexcolors.glsl"
|
||||
#include "shadows_fragment.glsl"
|
||||
#include "lighting.glsl"
|
||||
#include "alpha.glsl"
|
||||
|
||||
uniform float emissiveMult;
|
||||
|
||||
void main()
|
||||
{
|
||||
#if @diffuseMap
|
||||
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
|
||||
gl_FragData[0].a *= coveragePreservingAlphaScale(diffuseMap, adjustedDiffuseUV);
|
||||
#else
|
||||
gl_FragData[0] = vec4(1.0);
|
||||
#endif
|
||||
|
||||
vec4 diffuseColor = getDiffuseColor();
|
||||
gl_FragData[0].a *= diffuseColor.a;
|
||||
alphaTest();
|
||||
|
||||
#if @normalMap
|
||||
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
||||
// Must flip Y for DirectX format normal maps
|
||||
normalTex.y = 1.0 - normalTex.y;
|
||||
|
||||
vec3 normalizedNormal = normalize(passNormal);
|
||||
vec3 normalizedTangent = normalize(passTangent.xyz);
|
||||
vec3 binormal = cross(normalizedTangent, normalizedNormal) * passTangent.w;
|
||||
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
|
||||
|
||||
vec3 viewNormal = gl_NormalMatrix * normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
||||
#else
|
||||
vec3 viewNormal = gl_NormalMatrix * normalize(passNormal);
|
||||
#endif
|
||||
|
||||
float shadowing = unshadowedLightRatio(linearDepth);
|
||||
vec3 diffuseLight, ambientLight;
|
||||
doLighting(passViewPos, normalize(viewNormal), shadowing, diffuseLight, ambientLight);
|
||||
vec3 emission = getEmissionColor().xyz * emissiveMult;
|
||||
#if @emissiveMap
|
||||
emission *= texture2D(emissiveMap, emissiveMapUV).xyz;
|
||||
#endif
|
||||
vec3 lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
|
||||
|
||||
#if @clamp
|
||||
lighting = clamp(lighting, vec3(0.0), vec3(1.0));
|
||||
#else
|
||||
lighting = max(lighting, 0.0);
|
||||
#endif
|
||||
|
||||
gl_FragData[0].xyz *= lighting;
|
||||
|
||||
float shininess = gl_FrontMaterial.shininess;
|
||||
vec3 matSpec = getSpecularColor().xyz;
|
||||
#if @normalMap
|
||||
matSpec *= normalTex.a;
|
||||
#endif
|
||||
|
||||
if (matSpec != vec3(0.0))
|
||||
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos.xyz), shininess, matSpec) * shadowing;
|
||||
#if @radialFog
|
||||
float fogValue = clamp((euclideanDepth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
|
||||
#else
|
||||
float fogValue = clamp((linearDepth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
|
||||
#endif
|
||||
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, gl_Fog.color.xyz, fogValue);
|
||||
|
||||
#if @translucentFramebuffer
|
||||
if (noAlpha)
|
||||
gl_FragData[0].a = 1.0;
|
||||
#endif
|
||||
|
||||
applyShadowDebugOverlay();
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
#version 120
|
||||
|
||||
#if @diffuseMap
|
||||
varying vec2 diffuseMapUV;
|
||||
#endif
|
||||
|
||||
#if @emissiveMap
|
||||
varying vec2 emissiveMapUV;
|
||||
#endif
|
||||
|
||||
#if @normalMap
|
||||
varying vec2 normalMapUV;
|
||||
varying vec4 passTangent;
|
||||
#endif
|
||||
|
||||
varying float euclideanDepth;
|
||||
varying float linearDepth;
|
||||
|
||||
varying vec3 passViewPos;
|
||||
varying vec3 passNormal;
|
||||
|
||||
#define PER_PIXEL_LIGHTING 1
|
||||
|
||||
#include "vertexcolors.glsl"
|
||||
#include "shadows_vertex.glsl"
|
||||
#include "lighting.glsl"
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
|
||||
vec4 viewPos = (gl_ModelViewMatrix * gl_Vertex);
|
||||
gl_ClipVertex = viewPos;
|
||||
euclideanDepth = length(viewPos.xyz);
|
||||
linearDepth = gl_Position.z;
|
||||
|
||||
#if @diffuseMap
|
||||
diffuseMapUV = (gl_TextureMatrix[@diffuseMapUV] * gl_MultiTexCoord@diffuseMapUV).xy;
|
||||
#endif
|
||||
|
||||
#if @emissiveMap
|
||||
emissiveMapUV = (gl_TextureMatrix[@emissiveMapUV] * gl_MultiTexCoord@emissiveMapUV).xy;
|
||||
#endif
|
||||
|
||||
#if @normalMap
|
||||
normalMapUV = (gl_TextureMatrix[@normalMapUV] * gl_MultiTexCoord@normalMapUV).xy;
|
||||
passTangent = gl_MultiTexCoord7.xyzw;
|
||||
#endif
|
||||
|
||||
passColor = gl_Color;
|
||||
passViewPos = viewPos.xyz;
|
||||
passNormal = gl_Normal.xyz;
|
||||
|
||||
#if @shadows_enabled
|
||||
vec3 viewNormal = normalize((gl_NormalMatrix * gl_Normal).xyz);
|
||||
setupShadowCoords(viewPos, viewNormal);
|
||||
#endif
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
#version 120
|
||||
|
||||
#if @useGPUShader4
|
||||
#extension GL_EXT_gpu_shader4: require
|
||||
#endif
|
||||
|
||||
#if @diffuseMap
|
||||
uniform sampler2D diffuseMap;
|
||||
varying vec2 diffuseMapUV;
|
||||
#endif
|
||||
|
||||
uniform bool noAlpha;
|
||||
|
||||
#if @radialFog
|
||||
varying float euclideanDepth;
|
||||
#else
|
||||
varying float linearDepth;
|
||||
#endif
|
||||
|
||||
uniform bool useFalloff;
|
||||
|
||||
varying float passFalloff;
|
||||
|
||||
#include "vertexcolors.glsl"
|
||||
#include "alpha.glsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
#if @diffuseMap
|
||||
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
|
||||
gl_FragData[0].a *= coveragePreservingAlphaScale(diffuseMap, diffuseMapUV);
|
||||
#else
|
||||
gl_FragData[0] = vec4(1.0);
|
||||
#endif
|
||||
|
||||
gl_FragData[0] *= getDiffuseColor();
|
||||
|
||||
if (useFalloff)
|
||||
gl_FragData[0].a *= passFalloff;
|
||||
|
||||
alphaTest();
|
||||
|
||||
#if @radialFog
|
||||
float fogValue = clamp((euclideanDepth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
|
||||
#else
|
||||
float fogValue = clamp((linearDepth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
#if @translucentFramebuffer
|
||||
if (noAlpha)
|
||||
gl_FragData[0].a = 1.0;
|
||||
#endif
|
||||
|
||||
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, gl_Fog.color.xyz, fogValue);
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
#version 120
|
||||
|
||||
#if @diffuseMap
|
||||
varying vec2 diffuseMapUV;
|
||||
#endif
|
||||
|
||||
#if @radialFog
|
||||
varying float euclideanDepth;
|
||||
#else
|
||||
varying float linearDepth;
|
||||
#endif
|
||||
|
||||
uniform bool useFalloff;
|
||||
uniform vec4 falloffParams;
|
||||
|
||||
varying vec3 passViewPos;
|
||||
varying float passFalloff;
|
||||
|
||||
#include "vertexcolors.glsl"
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
|
||||
vec4 viewPos = (gl_ModelViewMatrix * gl_Vertex);
|
||||
gl_ClipVertex = viewPos;
|
||||
#if @radialFog
|
||||
euclideanDepth = length(viewPos.xyz);
|
||||
#else
|
||||
linearDepth = gl_Position.z;
|
||||
#endif
|
||||
|
||||
#if @diffuseMap
|
||||
diffuseMapUV = (gl_TextureMatrix[@diffuseMapUV] * gl_MultiTexCoord@diffuseMapUV).xy;
|
||||
#endif
|
||||
|
||||
passColor = gl_Color;
|
||||
if (useFalloff)
|
||||
{
|
||||
vec3 viewNormal = gl_NormalMatrix * normalize(gl_Normal.xyz);
|
||||
vec3 viewDir = normalize(viewPos.xyz);
|
||||
float viewAngle = abs(dot(viewNormal, viewDir));
|
||||
passFalloff = smoothstep(falloffParams.y, falloffParams.x, viewAngle);
|
||||
}
|
||||
else
|
||||
{
|
||||
passFalloff = 1.0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue