mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-08 09:06:41 +00:00
converted shadow caster shader
This commit is contained in:
parent
81d30ff63a
commit
b803d0e949
10 changed files with 112 additions and 130 deletions
|
@ -229,7 +229,7 @@ void LocalMap::render(const float x, const float y,
|
||||||
vp->setVisibilityMask(RV_Map);
|
vp->setVisibilityMask(RV_Map);
|
||||||
|
|
||||||
// use fallback techniques without shadows and without mrt
|
// use fallback techniques without shadows and without mrt
|
||||||
//vp->setMaterialScheme("local_map");
|
vp->setMaterialScheme("local_map");
|
||||||
|
|
||||||
//rtt->update();
|
//rtt->update();
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ void Shadows::recreate()
|
||||||
|
|
||||||
mSceneMgr->setShadowTextureSelfShadow(true);
|
mSceneMgr->setShadowTextureSelfShadow(true);
|
||||||
mSceneMgr->setShadowCasterRenderBackFaces(true);
|
mSceneMgr->setShadowCasterRenderBackFaces(true);
|
||||||
// mSceneMgr->setShadowTextureCasterMaterial("openmw_shadowcaster_default");
|
mSceneMgr->setShadowTextureCasterMaterial("openmw_shadowcaster_default");
|
||||||
mSceneMgr->setShadowTexturePixelFormat(PF_FLOAT32_R);
|
mSceneMgr->setShadowTexturePixelFormat(PF_FLOAT32_R);
|
||||||
mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000000);
|
mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000000);
|
||||||
|
|
||||||
|
|
|
@ -336,7 +336,7 @@ void Water::applyRTT()
|
||||||
vp->setBackgroundColour(ColourValue(0.8f, 0.9f, 1.0f));
|
vp->setBackgroundColour(ColourValue(0.8f, 0.9f, 1.0f));
|
||||||
vp->setShadowsEnabled(false);
|
vp->setShadowsEnabled(false);
|
||||||
// use fallback techniques without shadows and without mrt (currently not implemented for sky and terrain)
|
// use fallback techniques without shadows and without mrt (currently not implemented for sky and terrain)
|
||||||
//vp->setMaterialScheme("water_reflection");
|
vp->setMaterialScheme("water_reflection");
|
||||||
rtt->addListener(this);
|
rtt->addListener(this);
|
||||||
rtt->setActive(true);
|
rtt->setActive(true);
|
||||||
|
|
||||||
|
|
|
@ -276,8 +276,8 @@ void NIFLoader::createMaterial(const String &name,
|
||||||
else
|
else
|
||||||
warn("Unhandled alpha setting for texture " + texName);
|
warn("Unhandled alpha setting for texture " + texName);
|
||||||
}
|
}
|
||||||
//else
|
else
|
||||||
//instance->getMaterial ()->setShadowCasterMaterial ("openmw_shadowcaster_noalpha");
|
instance->getMaterial ()->setShadowCasterMaterial ("openmw_shadowcaster_noalpha");
|
||||||
|
|
||||||
// As of yet UNTESTED code from Chris:
|
// As of yet UNTESTED code from Chris:
|
||||||
/*pass->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
|
/*pass->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
|
||||||
|
|
2
extern/shiny
vendored
2
extern/shiny
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit d25605ee3a2d67dc0b6367cd150cc6d0c6a3b661
|
Subproject commit a0b3020bdba4433c1e3f45a1d5188eab0172bd88
|
35
files/materials/shadowcaster.mat
Normal file
35
files/materials/shadowcaster.mat
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
|
||||||
|
|
||||||
|
material openmw_shadowcaster_default
|
||||||
|
{
|
||||||
|
create_configuration Default
|
||||||
|
pass
|
||||||
|
{
|
||||||
|
fog_override true
|
||||||
|
|
||||||
|
vertex_program openmw_shadowcaster_vertex
|
||||||
|
fragment_program openmw_shadowcaster_fragment
|
||||||
|
|
||||||
|
shader_properties
|
||||||
|
{
|
||||||
|
shadow_transparency true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
material openmw_shadowcaster_noalpha
|
||||||
|
{
|
||||||
|
create_configuration Default
|
||||||
|
pass
|
||||||
|
{
|
||||||
|
fog_override true
|
||||||
|
|
||||||
|
vertex_program openmw_shadowcaster_vertex
|
||||||
|
fragment_program openmw_shadowcaster_fragment
|
||||||
|
|
||||||
|
shader_properties
|
||||||
|
{
|
||||||
|
shadow_transparency false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
files/materials/shadowcaster.shader
Normal file
56
files/materials/shadowcaster.shader
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#include "core.h"
|
||||||
|
|
||||||
|
#define ALPHA @shPropertyBool(shadow_transparency)
|
||||||
|
|
||||||
|
#ifdef SH_VERTEX_SHADER
|
||||||
|
|
||||||
|
SH_BEGIN_PROGRAM
|
||||||
|
#if ALPHA
|
||||||
|
shInput(float2, uv0)
|
||||||
|
shOutput(float2, UV)
|
||||||
|
#endif
|
||||||
|
shUniform(float4x4 wvp) @shAutoConstant(wvp, worldviewproj_matrix)
|
||||||
|
shOutput(float2, depth)
|
||||||
|
SH_START_PROGRAM
|
||||||
|
{
|
||||||
|
// this is the view space position
|
||||||
|
shOutputPosition = shMatrixMult(wvp, shInputPosition);
|
||||||
|
|
||||||
|
// depth info for the fragment.
|
||||||
|
depth.x = shOutputPosition.z;
|
||||||
|
depth.y = shOutputPosition.w;
|
||||||
|
|
||||||
|
// clamp z to zero. seem to do the trick. :-/
|
||||||
|
shOutputPosition.z = max(shOutputPosition.z, 0);
|
||||||
|
|
||||||
|
#if ALPHA
|
||||||
|
UV = uv0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
SH_BEGIN_PROGRAM
|
||||||
|
#if ALPHA
|
||||||
|
shInput(float2, UV)
|
||||||
|
shSampler2D(texture1)
|
||||||
|
#endif
|
||||||
|
shInput(float2, depth)
|
||||||
|
SH_START_PROGRAM
|
||||||
|
{
|
||||||
|
float finalDepth = depth.x / depth.y;
|
||||||
|
|
||||||
|
|
||||||
|
#if ALPHA
|
||||||
|
// use alpha channel of the first texture
|
||||||
|
float alpha = shSample(texture1, UV).a;
|
||||||
|
|
||||||
|
// discard if alpha is less than 0.5
|
||||||
|
if (alpha < 1.0)
|
||||||
|
discard;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
shOutputColor(0) = float4(finalDepth, finalDepth, finalDepth, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
15
files/materials/shadowcaster.shaderset
Normal file
15
files/materials/shadowcaster.shaderset
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
shader_set openmw_shadowcaster_vertex
|
||||||
|
{
|
||||||
|
source shadowcaster.shader
|
||||||
|
type vertex
|
||||||
|
profiles_cg vs_2_0 arbvp1
|
||||||
|
profiles_hlsl vs_2_0
|
||||||
|
}
|
||||||
|
|
||||||
|
shader_set openmw_shadowcaster_fragment
|
||||||
|
{
|
||||||
|
source shadowcaster.shader
|
||||||
|
type fragment
|
||||||
|
profiles_cg ps_2_x ps_2_0 ps arbfp1
|
||||||
|
profiles_hlsl ps_2_0
|
||||||
|
}
|
|
@ -1,51 +0,0 @@
|
||||||
void main_vp(
|
|
||||||
float4 position : POSITION,
|
|
||||||
float2 uv : TEXCOORD0,
|
|
||||||
|
|
||||||
out float4 oPosition : POSITION,
|
|
||||||
out float2 oDepth : TEXCOORD0,
|
|
||||||
out float2 oUv : TEXCOORD1,
|
|
||||||
|
|
||||||
uniform float4x4 wvpMat)
|
|
||||||
{
|
|
||||||
// this is the view space position
|
|
||||||
oPosition = mul(wvpMat, position);
|
|
||||||
|
|
||||||
// depth info for the fragment.
|
|
||||||
oDepth.x = oPosition.z;
|
|
||||||
oDepth.y = oPosition.w;
|
|
||||||
|
|
||||||
// clamp z to zero. seem to do the trick. :-/
|
|
||||||
oPosition.z = max(oPosition.z, 0);
|
|
||||||
|
|
||||||
oUv = uv;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main_fp(
|
|
||||||
float2 depth : TEXCOORD0,
|
|
||||||
float2 uv : TEXCOORD1,
|
|
||||||
uniform sampler2D texture1 : register(s0),
|
|
||||||
|
|
||||||
out float4 oColour : COLOR)
|
|
||||||
{
|
|
||||||
float finalDepth = depth.x / depth.y;
|
|
||||||
|
|
||||||
// use alpha channel of the first texture
|
|
||||||
float alpha = tex2D(texture1, uv).a;
|
|
||||||
|
|
||||||
// discard if alpha is less than 0.5
|
|
||||||
clip((alpha >= 0.5) ? 1 : -1);
|
|
||||||
|
|
||||||
oColour = float4(finalDepth, finalDepth, finalDepth, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main_fp_noalpha(
|
|
||||||
float2 depth : TEXCOORD0,
|
|
||||||
float2 uv : TEXCOORD1,
|
|
||||||
|
|
||||||
out float4 oColour : COLOR)
|
|
||||||
{
|
|
||||||
float finalDepth = depth.x / depth.y;
|
|
||||||
|
|
||||||
oColour = float4(finalDepth, finalDepth, finalDepth, 1);
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
vertex_program depth_shadow_caster_vs cg
|
|
||||||
{
|
|
||||||
source depthshadowcaster.cg
|
|
||||||
profiles vs_1_1 arbvp1
|
|
||||||
entry_point main_vp
|
|
||||||
|
|
||||||
default_params
|
|
||||||
{
|
|
||||||
param_named_auto wvpMat worldviewproj_matrix
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fragment_program depth_shadow_caster_ps cg
|
|
||||||
{
|
|
||||||
source depthshadowcaster.cg
|
|
||||||
profiles ps_2_0 arbfp1
|
|
||||||
entry_point main_fp
|
|
||||||
|
|
||||||
default_params
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fragment_program depth_shadow_caster_ps_noalpha cg
|
|
||||||
{
|
|
||||||
source depthshadowcaster.cg
|
|
||||||
profiles ps_2_0 arbfp1
|
|
||||||
entry_point main_fp_noalpha
|
|
||||||
|
|
||||||
default_params
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
material depth_shadow_caster
|
|
||||||
{
|
|
||||||
technique
|
|
||||||
{
|
|
||||||
pass
|
|
||||||
{
|
|
||||||
// force-disable fog (relevant for DirectX profiles below SM3 that always apply fixed function fog)
|
|
||||||
fog_override true
|
|
||||||
|
|
||||||
vertex_program_ref depth_shadow_caster_vs
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
fragment_program_ref depth_shadow_caster_ps
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
material depth_shadow_caster_noalpha
|
|
||||||
{
|
|
||||||
technique
|
|
||||||
{
|
|
||||||
pass
|
|
||||||
{
|
|
||||||
// force-disable fog (relevant for DirectX profiles below SM3 that always apply fixed function fog)
|
|
||||||
fog_override true
|
|
||||||
|
|
||||||
vertex_program_ref depth_shadow_caster_vs
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
fragment_program_ref depth_shadow_caster_ps_noalpha
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue