mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:23:54 +00:00
Add specular lighting for directional light to objects shader
This commit is contained in:
parent
3a82f8c193
commit
147bc447a5
2 changed files with 45 additions and 22 deletions
|
@ -1,7 +1,7 @@
|
||||||
material openmw_objects_base
|
material openmw_objects_base
|
||||||
{
|
{
|
||||||
diffuse 1.0 1.0 1.0 1.0
|
diffuse 1.0 1.0 1.0 1.0
|
||||||
specular 0 0 0 0
|
specular 0 0 0 0 1
|
||||||
ambient 1.0 1.0 1.0
|
ambient 1.0 1.0 1.0
|
||||||
emissive 0.0 0.0 0.0
|
emissive 0.0 0.0 0.0
|
||||||
vertmode 0
|
vertmode 0
|
||||||
|
|
|
@ -32,6 +32,10 @@
|
||||||
|
|
||||||
#define ENV_MAP @shPropertyBool(env_map)
|
#define ENV_MAP @shPropertyBool(env_map)
|
||||||
|
|
||||||
|
#define SPECULAR 1
|
||||||
|
|
||||||
|
#define NEED_NORMAL (!VERTEX_LIGHTING || ENV_MAP) || SPECULAR
|
||||||
|
|
||||||
#ifdef SH_VERTEX_SHADER
|
#ifdef SH_VERTEX_SHADER
|
||||||
|
|
||||||
// ------------------------------------- VERTEX ---------------------------------------
|
// ------------------------------------- VERTEX ---------------------------------------
|
||||||
|
@ -63,15 +67,12 @@
|
||||||
shOutput(float3, tangentPassthrough)
|
shOutput(float3, tangentPassthrough)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !VERTEX_LIGHTING || ENV_MAP
|
#if NEED_NORMAL
|
||||||
shOutput(float3, normalPassthrough)
|
shOutput(float3, normalPassthrough)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NEED_DEPTH
|
// Depth in w
|
||||||
shOutput(float, depthPassthrough)
|
shOutput(float4, objSpacePositionPassthrough)
|
||||||
#endif
|
|
||||||
|
|
||||||
shOutput(float3, objSpacePositionPassthrough)
|
|
||||||
|
|
||||||
#if VERTEXCOLOR_MODE != 0
|
#if VERTEXCOLOR_MODE != 0
|
||||||
shColourInput(float4)
|
shColourInput(float4)
|
||||||
|
@ -146,7 +147,7 @@
|
||||||
#if NORMAL_MAP
|
#if NORMAL_MAP
|
||||||
tangentPassthrough = tangent.xyz;
|
tangentPassthrough = tangent.xyz;
|
||||||
#endif
|
#endif
|
||||||
#if !VERTEX_LIGHTING || ENV_MAP
|
#if NEED_NORMAL
|
||||||
normalPassthrough = normal.xyz;
|
normalPassthrough = normal.xyz;
|
||||||
#endif
|
#endif
|
||||||
#if VERTEXCOLOR_MODE != 0 && !VERTEX_LIGHTING
|
#if VERTEXCOLOR_MODE != 0 && !VERTEX_LIGHTING
|
||||||
|
@ -169,14 +170,14 @@
|
||||||
|
|
||||||
float4x4 fixedWVP = shMatrixMult(vpFixed, worldMatrix);
|
float4x4 fixedWVP = shMatrixMult(vpFixed, worldMatrix);
|
||||||
|
|
||||||
depthPassthrough = shMatrixMult(fixedWVP, shInputPosition).z;
|
objSpacePositionPassthrough.w = shMatrixMult(fixedWVP, shInputPosition).z;
|
||||||
#else
|
#else
|
||||||
depthPassthrough = shOutputPosition.z;
|
objSpacePositionPassthrough.w = shOutputPosition.z;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
objSpacePositionPassthrough = shInputPosition.xyz;
|
objSpacePositionPassthrough.xyz = shInputPosition.xyz;
|
||||||
|
|
||||||
#if SHADOWS
|
#if SHADOWS
|
||||||
lightSpacePos0 = shMatrixMult(texViewProjMatrix0, shMatrixMult(worldMatrix, shInputPosition));
|
lightSpacePos0 = shMatrixMult(texViewProjMatrix0, shMatrixMult(worldMatrix, shInputPosition));
|
||||||
|
@ -262,7 +263,16 @@
|
||||||
#if ENV_MAP
|
#if ENV_MAP
|
||||||
shSampler2D(envMap)
|
shSampler2D(envMap)
|
||||||
shUniform(float3, env_map_color) @shUniformProperty3f(env_map_color, env_map_color)
|
shUniform(float3, env_map_color) @shUniformProperty3f(env_map_color, env_map_color)
|
||||||
shUniform(float3, cameraPosObjSpace) @shAutoConstant(cameraPosObjSpace, camera_position_object_space)
|
#endif
|
||||||
|
|
||||||
|
#if ENV_MAP || SPECULAR
|
||||||
|
shUniform(float3, cameraPosObjSpace) @shAutoConstant(cameraPosObjSpace, camera_position_object_space)
|
||||||
|
#endif
|
||||||
|
#if SPECULAR
|
||||||
|
shUniform(float3, lightSpec0) @shAutoConstant(lightSpec0, light_specular_colour, 0)
|
||||||
|
shUniform(float3, lightPosObjSpace0) @shAutoConstant(lightPosObjSpace0, light_position_object_space, 0)
|
||||||
|
shUniform(float, matShininess) @shAutoConstant(matShininess, surface_shininess)
|
||||||
|
shUniform(float3, matSpec) @shAutoConstant(matSpec, surface_specular_colour)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
shInput(float4, UV)
|
shInput(float4, UV)
|
||||||
|
@ -270,15 +280,11 @@
|
||||||
#if NORMAL_MAP
|
#if NORMAL_MAP
|
||||||
shInput(float3, tangentPassthrough)
|
shInput(float3, tangentPassthrough)
|
||||||
#endif
|
#endif
|
||||||
#if !VERTEX_LIGHTING || ENV_MAP
|
#if NEED_NORMAL
|
||||||
shInput(float3, normalPassthrough)
|
shInput(float3, normalPassthrough)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NEED_DEPTH
|
shInput(float4, objSpacePositionPassthrough)
|
||||||
shInput(float, depthPassthrough)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
shInput(float3, objSpacePositionPassthrough)
|
|
||||||
|
|
||||||
#if VERTEXCOLOR_MODE != 0 && !VERTEX_LIGHTING
|
#if VERTEXCOLOR_MODE != 0 && !VERTEX_LIGHTING
|
||||||
shInput(float4, colourPassthrough)
|
shInput(float4, colourPassthrough)
|
||||||
|
@ -340,6 +346,10 @@
|
||||||
|
|
||||||
SH_START_PROGRAM
|
SH_START_PROGRAM
|
||||||
{
|
{
|
||||||
|
#ifdef NEED_DEPTH
|
||||||
|
float depthPassthrough = objSpacePositionPassthrough.w;
|
||||||
|
#endif
|
||||||
|
|
||||||
shOutputColour(0) = shSample(diffuseMap, UV.xy);
|
shOutputColour(0) = shSample(diffuseMap, UV.xy);
|
||||||
|
|
||||||
#if DETAIL_MAP
|
#if DETAIL_MAP
|
||||||
|
@ -350,7 +360,7 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !VERTEX_LIGHTING || ENV_MAP
|
#if NEED_NORMAL
|
||||||
float3 normal = normalPassthrough;
|
float3 normal = normalPassthrough;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -368,7 +378,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !VERTEX_LIGHTING
|
#if !VERTEX_LIGHTING
|
||||||
float3 viewPos = shMatrixMult(worldView, float4(objSpacePositionPassthrough,1)).xyz;
|
float3 viewPos = shMatrixMult(worldView, float4(objSpacePositionPassthrough.xyz,1)).xyz;
|
||||||
float3 viewNormal = normalize(shMatrixMult(worldView, float4(normal.xyz, 0)).xyz);
|
float3 viewNormal = normalize(shMatrixMult(worldView, float4(normal.xyz, 0)).xyz);
|
||||||
|
|
||||||
float3 lightDir;
|
float3 lightDir;
|
||||||
|
@ -433,7 +443,7 @@
|
||||||
|
|
||||||
|
|
||||||
#if (UNDERWATER) || (FOG)
|
#if (UNDERWATER) || (FOG)
|
||||||
float3 worldPos = shMatrixMult(worldMatrix, float4(objSpacePositionPassthrough,1)).xyz;
|
float3 worldPos = shMatrixMult(worldMatrix, float4(objSpacePositionPassthrough.xyz,1)).xyz;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if UNDERWATER
|
#if UNDERWATER
|
||||||
|
@ -454,15 +464,28 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENV_MAP || SPECULAR
|
||||||
|
float3 eyeDir = normalize(cameraPosObjSpace.xyz - objSpacePositionPassthrough.xyz);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENV_MAP
|
#if ENV_MAP
|
||||||
// Everything looks better with fresnel
|
// Everything looks better with fresnel
|
||||||
float3 eyeDir = normalize(cameraPosObjSpace.xyz - objSpacePositionPassthrough.xyz);
|
|
||||||
float facing = 1.0 - max(abs(dot(-eyeDir, normal)), 0);
|
float facing = 1.0 - max(abs(dot(-eyeDir, normal)), 0);
|
||||||
float envFactor = shSaturate(0.25 + 0.75 * pow(facing, 1));
|
float envFactor = shSaturate(0.25 + 0.75 * pow(facing, 1));
|
||||||
|
|
||||||
shOutputColour(0).xyz += shSample(envMap, UV.zw).xyz * envFactor * env_map_color;
|
shOutputColour(0).xyz += shSample(envMap, UV.zw).xyz * envFactor * env_map_color;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if SPECULAR
|
||||||
|
float3 light0Dir = normalize(lightPosObjSpace0.xyz);
|
||||||
|
|
||||||
|
float NdotL = max(dot(normal, light0Dir), 0);
|
||||||
|
float3 halfVec = normalize (light0Dir + eyeDir);
|
||||||
|
|
||||||
|
float3 specular = pow(max(dot(normal, halfVec), 0), matShininess) * lightSpec0 * matSpec;
|
||||||
|
shOutputColour(0).xyz += specular * shadow;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FOG
|
#if FOG
|
||||||
float fogValue = shSaturate((depthPassthrough - fogParams.y) * fogParams.w);
|
float fogValue = shSaturate((depthPassthrough - fogParams.y) * fogParams.w);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue