mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 08:53:50 +00:00
Add parallax mapping for objects
This commit is contained in:
parent
845bc5f7eb
commit
062ea627b3
4 changed files with 40 additions and 21 deletions
|
@ -334,6 +334,10 @@ Ogre::String NIFMaterialLoader::getMaterial(const Nif::ShapeData *shapedata,
|
||||||
instance->setProperty("detailMapUVSet", sh::makeProperty(new sh::IntValue(texprop->textures[Nif::NiTexturingProperty::DetailTexture].uvSet)));
|
instance->setProperty("detailMapUVSet", sh::makeProperty(new sh::IntValue(texprop->textures[Nif::NiTexturingProperty::DetailTexture].uvSet)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool useParallax = !texName[Nif::NiTexturingProperty::BumpTexture].empty()
|
||||||
|
&& texName[Nif::NiTexturingProperty::BumpTexture].find("_nh.") != std::string::npos;
|
||||||
|
instance->setProperty("use_parallax", sh::makeProperty(new sh::BooleanValue(useParallax)));
|
||||||
|
|
||||||
for(int i = 0;i < 7;i++)
|
for(int i = 0;i < 7;i++)
|
||||||
{
|
{
|
||||||
if(i == Nif::NiTexturingProperty::BaseTexture ||
|
if(i == Nif::NiTexturingProperty::BaseTexture ||
|
||||||
|
|
|
@ -91,7 +91,7 @@ precision mediump float;
|
||||||
|
|
||||||
#define shSamplerCube(name) uniform samplerCube name; @shUseSampler(name)
|
#define shSamplerCube(name) uniform samplerCube name; @shUseSampler(name)
|
||||||
|
|
||||||
#define shMatrixMult(m, v) (m * v)
|
#define shMatrixMult(m, v) ((m) * (v))
|
||||||
|
|
||||||
#define shOutputPosition gl_Position
|
#define shOutputPosition gl_Position
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ material openmw_objects_base
|
||||||
use_detail_map false
|
use_detail_map false
|
||||||
emissiveMapUVSet 0
|
emissiveMapUVSet 0
|
||||||
detailMapUVSet 0
|
detailMapUVSet 0
|
||||||
|
use_parallax false
|
||||||
|
|
||||||
scene_blend default
|
scene_blend default
|
||||||
depth_write default
|
depth_write default
|
||||||
|
@ -37,6 +38,7 @@ material openmw_objects_base
|
||||||
detailMap $detailMap
|
detailMap $detailMap
|
||||||
env_map $env_map
|
env_map $env_map
|
||||||
env_map_color $env_map_color
|
env_map_color $env_map_color
|
||||||
|
use_parallax $use_parallax
|
||||||
}
|
}
|
||||||
|
|
||||||
diffuse $diffuse
|
diffuse $diffuse
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
#define EMISSIVE_MAP @shPropertyHasValue(emissiveMap)
|
#define EMISSIVE_MAP @shPropertyHasValue(emissiveMap)
|
||||||
#define DETAIL_MAP @shPropertyHasValue(detailMap)
|
#define DETAIL_MAP @shPropertyHasValue(detailMap)
|
||||||
|
|
||||||
|
#define PARALLAX @shPropertyBool(use_parallax)
|
||||||
|
#define PARALLAX_SCALE 0.04
|
||||||
|
#define PARALLAX_BIAS -0.02
|
||||||
|
|
||||||
// right now we support 2 UV sets max. implementing them is tedious, and we're probably not going to need more
|
// right now we support 2 UV sets max. implementing them is tedious, and we're probably not going to need more
|
||||||
#define SECOND_UV_SET (@shPropertyString(emissiveMapUVSet) || @shPropertyString(detailMapUVSet))
|
#define SECOND_UV_SET (@shPropertyString(emissiveMapUVSet) || @shPropertyString(detailMapUVSet))
|
||||||
|
|
||||||
|
@ -265,7 +269,7 @@
|
||||||
shUniform(float3, env_map_color) @shUniformProperty3f(env_map_color, env_map_color)
|
shUniform(float3, env_map_color) @shUniformProperty3f(env_map_color, env_map_color)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENV_MAP || SPECULAR
|
#if ENV_MAP || SPECULAR || PARALLAX
|
||||||
shUniform(float3, cameraPosObjSpace) @shAutoConstant(cameraPosObjSpace, camera_position_object_space)
|
shUniform(float3, cameraPosObjSpace) @shAutoConstant(cameraPosObjSpace, camera_position_object_space)
|
||||||
#endif
|
#endif
|
||||||
#if SPECULAR
|
#if SPECULAR
|
||||||
|
@ -345,21 +349,12 @@
|
||||||
|
|
||||||
SH_START_PROGRAM
|
SH_START_PROGRAM
|
||||||
{
|
{
|
||||||
|
float4 newUV = UV;
|
||||||
|
|
||||||
#ifdef NEED_DEPTH
|
#ifdef NEED_DEPTH
|
||||||
float depthPassthrough = objSpacePositionPassthrough.w;
|
float depthPassthrough = objSpacePositionPassthrough.w;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float4 diffuse = shSample(diffuseMap, UV.xy);
|
|
||||||
shOutputColour(0) = diffuse;
|
|
||||||
|
|
||||||
#if DETAIL_MAP
|
|
||||||
#if @shPropertyString(detailMapUVSet)
|
|
||||||
shOutputColour(0) *= shSample(detailMap, UV.zw)*2;
|
|
||||||
#else
|
|
||||||
shOutputColour(0) *= shSample(detailMap, UV.xy)*2;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if NEED_NORMAL
|
#if NEED_NORMAL
|
||||||
float3 normal = normalPassthrough;
|
float3 normal = normalPassthrough;
|
||||||
#endif
|
#endif
|
||||||
|
@ -372,11 +367,33 @@
|
||||||
tbn = transpose(tbn);
|
tbn = transpose(tbn);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float3 TSnormal = shSample(normalMap, UV.xy).xyz * 2 - 1;
|
float4 normalTex = shSample(normalMap, UV.xy);
|
||||||
|
|
||||||
normal = normalize (shMatrixMult( transpose(tbn), TSnormal ));
|
normal = normalize (shMatrixMult( transpose(tbn), normalTex.xyz * 2 - 1 ));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENV_MAP || SPECULAR || PARALLAX
|
||||||
|
float3 eyeDir = normalize(cameraPosObjSpace.xyz - objSpacePositionPassthrough.xyz);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if PARALLAX
|
||||||
|
float3 TSeyeDir = normalize(shMatrixMult(tbn, eyeDir));
|
||||||
|
|
||||||
|
newUV += (TSeyeDir.xyxy * ( normalTex.a * PARALLAX_SCALE + PARALLAX_BIAS )).xyxy;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float4 diffuse = shSample(diffuseMap, newUV.xy);
|
||||||
|
shOutputColour(0) = diffuse;
|
||||||
|
|
||||||
|
#if DETAIL_MAP
|
||||||
|
#if @shPropertyString(detailMapUVSet)
|
||||||
|
shOutputColour(0) *= shSample(detailMap, newUV.zw)*2;
|
||||||
|
#else
|
||||||
|
shOutputColour(0) *= shSample(detailMap, newUV.xy)*2;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if !VERTEX_LIGHTING
|
#if !VERTEX_LIGHTING
|
||||||
float3 viewPos = shMatrixMult(worldView, float4(objSpacePositionPassthrough.xyz,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);
|
||||||
|
@ -458,16 +475,12 @@
|
||||||
|
|
||||||
#if EMISSIVE_MAP
|
#if EMISSIVE_MAP
|
||||||
#if @shPropertyString(emissiveMapUVSet)
|
#if @shPropertyString(emissiveMapUVSet)
|
||||||
shOutputColour(0).xyz += shSample(emissiveMap, UV.zw).xyz;
|
shOutputColour(0).xyz += shSample(emissiveMap, newUV.zw).xyz;
|
||||||
#else
|
#else
|
||||||
shOutputColour(0).xyz += shSample(emissiveMap, UV.xy).xyz;
|
shOutputColour(0).xyz += shSample(emissiveMap, newUV.xy).xyz;
|
||||||
#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
|
||||||
float facing = 1.0 - max(abs(dot(-eyeDir, normal)), 0);
|
float facing = 1.0 - max(abs(dot(-eyeDir, normal)), 0);
|
||||||
|
|
Loading…
Reference in a new issue