Code Bucket …

Example VSM impl

You can visit http://www.the-barn.org/codebucket.php?id=67 to view this snippet directly.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// implementation of a variance mapped shadow system
// (C) 2009 Christian Schladetsch, Blue Lion Software

Effect VarianceShadowMap
{
	Header
	[
		#include "Precompiled.h"
	]

	Fragments "Shaders/VarianceShadowMap.fx"

	Technique Shadowed
	{
		Fields
		[
			enum { ShadowMapDim = 500 };
			RenderTarget shadow_map;
			DirectX::PTexture spotlight_mask;
		]
		Create
		[
			shadow_map = device.CreateRenderTarget(ShadowMapDim, ShadowMapDim, D3DFMT_G32R32F).value;
		]
		Begin
		[
			device.EnableBlending(false);
		]
		End
		[
		]

		//------------------------------------------------------------------------------
		//		c r e a t e   s h a d o w    m a p
		//------------------------------------------------------------------------------
		Pass First
		{
			Fields
			[
			public:
				DirectX::PSurface orig_target;
				DirectX::PSurface orig_zbuffer;

				DirectX::PSurface zbuffer;
				bool render_to_screen;
			]

			Create
			[
				zbuffer = device.CreateZBuffer(ShadowMapDim, ShadowMapDim).value;
				render_to_screen = false;
			]

			Begin
			[
				device.EnableZwrites(true);
				device.EnableBlending(false);

				orig_target = device.GetRenderTarget().value;
				orig_zbuffer = device.GetZBuffer().value;

				if (!render_to_screen)
				{
					device.SetRenderTarget(Parent->shadow_map.Surface);
					device.SetZBuffer(zbuffer);
				}

				device.Textures(0) = 0;
				device.Clear(Color(1,1,1,0), 1);
			]
			End
			[
				device.SetRenderTarget(orig_target);
				device.SetZBuffer(orig_zbuffer);
			]

			VertexShader
			{
				Depth_VS_Fragment
			}
			PixelShader
			{
				Depth_PS_Fragment
			}
		}


		//------------------------------------------------------------------------------
		//		r e n d e r    w i t h    s h a d o w 
		//------------------------------------------------------------------------------
		Pass Second
		{
			Create
			[
				Disable();
			]
			Begin
			[
				device.EnableZwrites(true);
				device.AdditiveBlending(false);

				// TODO: cache this in a quasi-uniform
				device.SetShaderTexture(shader, "shadow_map_sampler", Parent->shadow_map.Texture);
			]
			VertexShader
			{
				VarianceShadowMap_VS_Fragment
			}

			PixelShader
			{
				VarianceShadowMap_PS_Fragment
			}
		}
		Uniforms
		{
			float4x4	g_WorldMatrix;
			float4x4	g_WorldViewProjMatrix;
			float4x4	g_WorldViewMatrix;

			float3		g_ViewPos;
			float4x4	g_LightViewMatrix;
			float4x4	g_LightWorldViewProjMatrix;
			float4x4	g_LightWorldViewMatrix;
			float4x4	g_LightViewProjMatrix;
			float4		g_LightLinNearFar;
			float4		g_LightPosition;
			float4		g_LightDirection;
			float		g_LightFOV;
			float4		g_LightDistFalloff;
			bool		g_LightingOnly;
			bool		g_LBR;
			float		g_LBRAmount;
			float		g_DistributePrecision;

			//texture texDiffuse;
			float		g_AmbientIntensity;
			float4		g_LightColor;
			float		g_SpecularPower;
			float4		g_SpecularColor;
		}
	}
}

//EOF
  • Posted on 02.06.2009 at 1:21 PM by spam
  • Language: C++

Snippets

 
36 Results
Page 1 of 3
TitleLanguagePosted ByPostedExpiresActions
Python first-class classes for KodenPythonstoffle04.07.2010 8:19 AM (64 days 3h 35m ago)-view
mLAN Activation ScriptPlain Textstoffle23.06.2010 6:42 AM (75 days 5h 11m ago)-view
areaC#stoffle27.02.2010 3:51 AM (191 days 9h 3m ago)-view
list extensionsC#stoffle09.02.2010 11:12 PM (208 days 13h 41m ago)-view
possible IComponent intererface version 95C#stoffle09.02.2010 11:04 PM (208 days 13h 50m ago)-view
Render SystemC++spam05.06.2009 12:14 PM (457 days 23h 40m ago)-view
Effect SampleC++spam03.06.2009 2:40 PM (459 days 21h 13m ago)-view
Rho LambdasC++spam03.06.2009 2:38 PM (459 days 21h 16m ago)-view
Example VSM implC++spam02.06.2009 1:21 PM (460 days 22h 33m ago)-view
Vector3 Interface (public)C++kalin11.02.2008 9:53 PM (937 days 15h 1m ago)-view
TimesTablesC++kalin09.02.2008 6:04 PM (939 days 18h 50m ago)-view
Skruje Account Search PagePHPstoffle03.02.2008 5:12 PM (945 days 19h 42m ago)-view
C++ is still bork...C++spam26.01.2008 5:58 PM (953 days 18h 56m ago)-view
C++ is bork #3C++spam26.01.2008 5:47 PM (953 days 19h 7m ago)-view
C++ is bork #2C++spam26.01.2008 5:46 PM (953 days 19h 8m ago)-view
36 Results
Page 1 of 3