Download presentation
Presentation is loading. Please wait.
Published byKallie Adwell Modified over 10 years ago
1
PCF,VSM,LISPSM…
2
Kezdeti teendők Letöltés: OgreLabShadowMappingBase.zip Kicsomagol.sln futtat Include, lib és working dir beállítása Fordítás Futtatás
3
Próba
4
OgreShadowMap.cpp void setupScene() { … sceneManager->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE); sceneManager->setShadowFarDistance(1000); … }
5
Próba
6
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.jpg filtering anisotropic } texture_unit shadowmap { content_type shadow tex_address_mode clamp filtering bilinear }
7
Phong.hlsl struct 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!
8
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; … }
9
Próba
10
ShadowMap.material material ShadowMap { technique { pass { vertex_program_ref ShadowMapVS { param_named_auto worldviewproj worldviewproj_matrix } fragment_program_ref ShadowMapPS { }
11
ShadowMap.program vertex_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 }
12
ShadowMap.hlsl void 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; }
13
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; }
14
OgreShadowMap.cpp void 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); … }
15
Próba
16
… 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);
17
Próba
18
ShadowMap.material material ShadowMap { technique { pass { vertex_program_ref ShadowMapVS { param_named_auto worldviewproj worldviewproj_matrix } fragment_program_ref ShadowMapPS { param_named_auto depthRangeParams scene_depth_range }
19
ShadowMap.hlsl float4 ps(float4 hPos : POSITION, float4 lPos : TEXCOORD0, uniform float4 depthRangeParams):COLOR { float z = lPos.w / depthRangeParams.y; return z; }
20
Phong.material material Phong { technique { pass { fragment_program_ref { … param_named_auto lightDepthParams shadow_scene_depth_range 0 } … }
21
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); } … }
22
Próba
23
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) };
24
Percentage Closer Filtering float 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); }
25
Próba
26
Variance Shadow Mapping #define EPSILON_VSM 0.001 float 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); }
27
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); }
28
Próba
29
VSM szűrés float 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;
30
Próba
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.