Presentation is loading. Please wait.

Presentation is loading. Please wait.

PCF,VSM,LISPSM…. 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.

Similar presentations


Presentation on theme: "PCF,VSM,LISPSM…. 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."— Presentation transcript:

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 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( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ), float2( , ) };

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 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


Download ppt "PCF,VSM,LISPSM…. 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."

Similar presentations


Ads by Google