Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, TedMar), 1,007 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: looking for "Z Buffer" Shadow [Re: Oxy] #360574
02/25/11 02:26
02/25/11 02:26
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
That's fair enough.

Consider this: an entity only needs to be rendered in a wider shadow-view if it is not completely enclosed in a narrower one. Using view_check you could (and should if using CSM in a proper game) have entities that are completely within the frustum of narrower views be ignored in wider views. In many situations this will probably improve your framerate quite a bit.

I don't use CSM yet in KarBOOM, but I will make it an option in the near future when levels are complex enough to warrant it.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: looking for "Z Buffer" Shadow [Re: JibbSmart] #360575
02/25/11 02:43
02/25/11 02:43
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
I will try to fuzz around with the code,
thanks for your help.

Re: looking for "Z Buffer" Shadow [Re: Oxy] #360577
02/25/11 02:56
02/25/11 02:56
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
Ok, this is quite good looking now in my eyes,
and still very fast

Code:
////////////////////////////////////////////////////
// Simple shadow mapping shader
// Copyright (c) 2007 Conitec.
// (with reduced darkness..)
// based on modifications by Jibb Smart 
////////////////////////////////////////////////////

#define USE_PCF // use percentage closer filtering

//Tweakables
static const float fDark = 0.6;
static const float fDarkDiffuse = 0.2;
static const float fBright = 1.4;
static const float fDepthOffset = 0.99;
static const float fPCF = 0.9;

// Application fed data:
const float4x4 matWorldViewProj;	// World*view*projection matrix.
const float4x4 matWorld; // World matrix.
const float4x4 matMtl;   // Precalculated texture projection matrix
const float4 vecSunDir;	// Sun direction vector.

texture TargetMap;
texture entSkin1;
sampler DepthSampler = sampler_state { Texture = <TargetMap>; };
sampler TexSampler = sampler_state { Texture = <entSkin1>; Mipfilter = Linear; };

// Shadow mapping vertex shader
void ShadowVS (in float4 inPos: POSITION,
		in float2 inTex: TEXCOORD0,
		in float3 inNormal: NORMAL,
		out float4 outPos: POSITION,
		out float2 outTex: TEXCOORD0,
		out float3 outNormal: TEXCOORD1,
		out float4 outDepth: TEXCOORD2)
{
// Transform the vertex from object space to clip space:
	outPos = mul(inPos, matWorldViewProj);
	
// Transform the normal from object space to world space:
	outNormal = normalize(mul(inNormal,matWorld));
	
// Pass the texture coordinate to the pixel shader:
	outTex = inTex;
	
// Output the projective texture coordinates
	outDepth = mul( mul(inPos,matWorld), matMtl );
}

// distance comparison function
float fDist(float4 DepthCoord,float fDepth)
{
	return 
		tex2Dproj(DepthSampler,DepthCoord).r < (fDepth*fDepthOffset)? fDark : fBright;
}

#ifdef USE_PCF
static const float4 fTaps_PCF[9] = {
	{-1.0,-1.0, 0.0, 0.0},
	{-1.0, 0.0, 0.0, 0.0},
	{-1.0, 1.0, 0.0, 0.0},
	{ 0.0,-1.0, 0.0, 0.0},
	{ 0.0, 0.0, 0.0, 0.0},
	{ 0.0, 1.0, 0.0, 0.0},
	{ 1.0,-1.0, 0.0, 0.0},
	{ 1.0, 0.0, 0.0, 0.0},
	{ 1.0, 1.0, 0.0, 0.0}};
#endif

// Shadow mapping pixel shader
float4 ShadowPS (in float4 inPos: POSITION,
					in float2 inTex: TEXCOORD0,
					in float3 inNormal: TEXCOORD1,
					in float4 inDepth: TEXCOORD2) : COLOR0
{
// Calculate the diffuse term:

	float fDiffuse = lerp(fDarkDiffuse, fBright, saturate(dot(-vecSunDir, normalize(inNormal))));


// Calculate the shadow term
#ifdef USE_PCF
	float fShadow = 0.0;
	for (int i=0; i < 9; i++)
	{
		float4 fTap = inDepth + fPCF*fTaps_PCF[i];
		fShadow += fDist(fTap,inDepth.z)/9;
	}
#else
	float fShadow = fDist(inDepth,inDepth.z);
#endif		


		return tex2D(TexSampler,inTex) * min(fShadow, fDiffuse);
}

technique techShadow
{
	pass p0
	{
		VertexShader = compile vs_2_0 ShadowVS();
		PixelShader  = compile ps_2_0 ShadowPS();
	}
}



Re: looking for "Z Buffer" Shadow [Re: Oxy] #360578
02/25/11 03:12
02/25/11 03:12
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Looks good to me. I actually prefer without PCF usually, as I think it takes too many samples to look nice. If you were had PCF enabled in the CSM example, that might explain the relatively low framerate.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Page 2 of 2 1 2

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1