Upload
kallie-adwell
View
215
Download
1
Embed Size (px)
Citation preview
PCF,VSM,LISPSM…
Kezdeti teendőkLetöltés: OgreLabShadowMappingBase.zipKicsomagol.sln futtatInclude, lib és working dir beállításaFordításFuttatás
Próba
OgreShadowMap.cpp
void setupScene(){…
sceneManager->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);sceneManager->setShadowFarDistance(1000);
…}
Próba
sceneManager->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
material Phong{
technique{
pass{
vertex_program_ref {
… param_named_auto lightMatrix texture_worldviewproj_matrix 0}
…texture_unit normal{
texture unitNormal.jpgfiltering anisotropic
} texture_unit shadowmap{
content_type shadowtex_address_mode clampfiltering bilinear
} }
}}
Phong.hlslstruct VERTEX_OUT
{
float4 hPos : POSITION;
float3 N : TEXCOORD0;
float3 L : TEXCOORD1;
float3 V : TEXCOORD2;
float2 texCoord : TEXCOORD3;
float2 texCoord2 : TEXCOORD4;
float4 lPos :TEXCOORD5;
};
VERTEX_OUT vsStatic (VERTEX_IN In,
uniform float4x4 worldViewProj,
uniform float4x4 worldView,
uniform float4x4 worldViewIT,
uniform float4 lightPos,
uniform float4x4 lightMatrix)
{
…
Out.lPos = mul(lightMatrix, In.position);
vsDynamic-ra is!
float4 ps(VERTEX_OUT In,…uniform sampler2D shadowMap : register(s3),…):COLOR
{…
diffuseLightColor *= spot; specularLightColor *= spot;
float shadow = 1;if(In.lPos.z > 0){
In.lPos /= In.lPos.w;shadow = tex2D(shadowMap, In.lPos.xy);
}diffuseLightColor *= shadow; specularLightColor *= shadow;
float4 ambient = amientLightColor * ambientColor;…}
Próba
ShadowMap.materialmaterial ShadowMap{
technique{
pass{
vertex_program_ref ShadowMapVS { param_named_auto worldviewproj
worldviewproj_matrix} fragment_program_ref ShadowMapPS
{}
}}
}
ShadowMap.programvertex_program ShadowMapVS hlsl{ source ShadowMap.hlsl entry_point vs target vs_2_0}
fragment_program ShadowMapPS hlsl{ source ShadowMap.hlsl entry_point ps target ps_2_0}
ShadowMap.hlslvoid vs(float4 position : POSITION,
uniform float4x4 worldviewproj,uniform float4x4 worldview,out float4 hPos:POSITION,out float4 lPos:TEXCOORD0)
{hPos = mul(worldviewproj, position);lPos = mul(worldviewproj, position);
}
float4 ps(float4 hPos : POSITION, float4 lPos : TEXCOORD0):COLOR
{lPos /= lPos.w;return lPos.z;
}
Phong.hlsl#define BIAS 0.0007
float simpleShadow(float3 coord, sampler2D sm)
{
float zs = tex2D(sm,coord.xy).r;
return coord.z < zs + BIAS;
}
float4 ps …{
float shadow = 1;
if(In.lPos.z > 0)
{In.lPos /= In.lPos.w;
shadow = simpleShadow(In.lPos.xyz, shadowMap);
}
diffuseLightColor *= shadow; specularLightColor *= shadow;
}
OgreShadowMap.cppvoid setupScene(){…
level->setCastShadows(true);…
sceneManager->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
sceneManager->setShadowFarDistance(1000);sceneManager->setShadowTextureCasterMaterial("ShadowMap");sceneManager->setShadowTextureConfig(0,500,500,PixelFormat::PF_FLOAT16_RGBA);sceneManager->setShadowCasterRenderBackFaces(false);sceneManager->setShadowTextureSelfShadow(true);
…}
Próba
…sceneManager-
>setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
FocusedShadowCameraSetup* camsetup = new FocusedShadowCameraSetup();ShadowCameraSetupPtr csp(camsetup);sceneManager->setShadowCameraSetup(csp);
vagy
LiSPSMShadowCameraSetup* camsetup = new LiSPSMShadowCameraSetup();camsetup->setCameraLightDirectionThreshold(Degree(20));camsetup->setUseSimpleOptimalAdjust(false);camsetup->setOptimalAdjustFactor(0.9);ShadowCameraSetupPtr csp(camsetup);sceneManager->setShadowCameraSetup(csp);
Próba
ShadowMap.materialmaterial ShadowMap{
technique{
pass{
vertex_program_ref ShadowMapVS {
param_named_auto worldviewproj worldviewproj_matrix
} fragment_program_ref ShadowMapPS
{param_named_auto depthRangeParams scene_depth_range
}}
}}
ShadowMap.hlslfloat4 ps(float4 hPos : POSITION,
float4 lPos : TEXCOORD0, uniform float4 depthRangeParams):COLOR
{float z = lPos.w / depthRangeParams.y;return z;
}
Phong.material
material Phong{
technique{
pass{
fragment_program_ref {
… param_named_auto lightDepthParams shadow_scene_depth_range 0
}…
}}
}
Phong.hlsl#define BIAS 0.01…float4 ps(… uniform float4 lightDepthParams):COLOR{…
float shadow = 1;if(In.lPos.z > 0){
float z = In.lPos.w / lightDepthParams.y;In.lPos /= In.lPos.w;shadow = simpleShadow (float3(In.lPos.xy,z), shadowMap);
}…}
Próba
Phong.hlsl#define BIAS 0.01
static const float2 RAND[] = {float2(-0.613392, 0.617481),float2(0.170019, -0.0402539),float2(-0.299417, 0.791925),float2(0.64568, 0.49321),float2(-0.651784, 0.717887),float2(0.421003, 0.0270699),float2(-0.817194, -0.271096),float2(-0.705374, -0.668203),float2(0.97705, -0.108615),float2(0.0633259, 0.142369),float2(0.203528, 0.214332),float2(-0.667531, 0.32609),float2(-0.0984222, -0.295755),float2(-0.885922, 0.215369),float2(0.566637, 0.605213),float2(0.0397656, -0.3961),float2(0.751945, 0.453352),
float2(0.0787072, -0.715323),float2(-0.0758385, -0.529344),float2(0.724479, -0.580798),float2(0.559313, 0.687307),float2(0.222999, -0.215125),float2(-0.467574, -0.405438),float2(-0.248268, -0.814753),float2(0.354411, -0.88757),float2(-0.448225, -0.454207),float2(0.175817, 0.382366),float2(0.675222, 0.452986),float2(-0.0301217, -0.589282),float2(0.487472, -0.0630817),float2(-0.0840785, 0.898312),float2(0.488876, -0.783441)};
Percentage Closer Filteringfloat PCFShadow(float3 coord, sampler2D sm){
float s = 0;float zs;static const float samplecount = 12;for(int i = 0; i < samplecount; i++){
zs = tex2D(sm,coord.xy + RAND[i] * 0.003).r;s += coord.z < zs + BIAS;
}s /= samplecount;return s;
}
float4 ps(…if(In.lPos.z > 0){
float z = In.lPos.w / lightDepthParams.y;In.lPos /= In.lPos.w;shadow = PCFShadow(float3(In.lPos.xy,z), shadowMap);
}
Próba
Variance Shadow Mapping#define EPSILON_VSM 0.001float VSMShadow(float3 coord, sampler2D sm){
float2 zs = tex2D(sm,coord.xy).xy;float M1 = zs.x;float M2 = zs.y;float lit_factor = coord.z < M1 + BIAS;
float v2 = min(max(M2 - M1 * M1, 0.0) + EPSILON_VSM, 1.0);float m_d = M1 - coord.z;
float pmax = v2 / (v2 + m_d * m_d);
return max(lit_factor, pmax); }
float4 ps(…if(In.lPos.z > 0){
float z = In.lPos.w / lightDepthParams.y;In.lPos /= In.lPos.w;shadow = VSMShadow(float3(In.lPos.xy,z), shadowMap);
}
ShadowMap.hlsl
float4 ps(float4 hPos : POSITION,float4 lPos:TEXCOORD0,uniform float4
depthRangeParams):COLOR{
float z = lPos.w / depthRangeParams.y;return float4(z,z*z,0,0);
}
Próba
VSM szűrésfloat VSMShadow(float3 coord, sampler2D sm){
float2 zs = tex2D(sm,coord.xy).xy;for(int i = 0; i < 4; i++){
zs += tex2D(sm,coord.xy + RAND[i] * 0.005).xy;}zs /= 5;
float M1 = zs.x;float M2 = zs.y;
Próba