XEffects - Reloaded - New Release (V 1.4)

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
wing64
Competition winner
Posts: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Post by wing64 »

1. If i have 2 or 3 light my game will pay with FPS slow down (1 light in my big scene FPS = 1 on geForce6100 :-( ).
BlindSide Can u suggest me the way of mod XEffect support far away objects ?
2. I founded article in gamedev.net Soft-Edged Shadows by Anirudh.S Shastry (http://www.gamedev.net/reference/articl ... le2193.asp)
but i try port to irrlicht in Step 1: Rendering the shadow map my result is a white canvas texture ??? but in example is a blue color

Image

vertex and pixel shader i copy and paste to irrlicht

vertex shader

Code: Select all

struct VSOUTPUT_SHADOW
{
   float4 vPosition    : POSITION;
   float  fDepth       : TEXCOORD0;
};

VSOUTPUT_SHADOW VS_Shadow( float4 inPosition : POSITION )
{
   // Output struct
   VSOUTPUT_SHADOW OUT = (VSOUTPUT_SHADOW)0;
   // Output the transformed position
   OUT.vPosition = mul( inPosition, g_matLightViewProj );
   // Output the scene depth
   OUT.fDepth = OUT.vPosition.z;
   return OUT;
}
pixel shader

Code: Select all

float4  PS_Shadow( VSOUTPUT_SHADOW IN ) : COLOR0
{
   // Output the scene depth
   return float4( IN.fDepth, IN.fDepth, IN.fDepth, 1.0f );
}
What's happend with my code ??? or irrlicht not support shader from that article ?
best regards
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

this is HLSL , meaning directX shader code. if you are running in openGL it wont work, plus check the console for compile errors AND,

g_matLightViewProj <- this needs to be set via OnSetShaderConstants?

are you setting the shader up code side as well?
wing64
Competition winner
Posts: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Post by wing64 »

I have been set to Direct3D9 and code In OnSetConstants function are

Code: Select all

		// View matrix
		vector3df vLightPos = vector3df(  10.0f, 20.0f, -40.0f );
		//vector3df vLightAim = vector3df(   -100.0f,  5.0f,   40.0f );
		vector3df vLightAim = vector3df(   0.0f,  0.0f,   0.0f );
		vector3df g_vUp		= vector3df(   0.0f,  1.0f,   0.0f );

		viewMat.buildCameraLookAtMatrixLH(vLightPos, vLightAim, g_vUp );
		projMat.buildProjectionMatrixPerspectiveFovLH(90*DEGTORAD, 1, 1.0f, 1024.0f );
		worldViewProj = projMat;
		worldViewProj *= viewMat;
		worldViewProj *= driver->getTransform(video::ETS_WORLD);
		services->setVertexShaderConstant("g_matLightViewProj", worldViewProj.pointer(), 16);
code vertex shader

Code: Select all

//--------------------------------------------
// Global variables
//--------------------------------------------
matrix	g_matLightViewProj	: LightViewProjection;

//--------------------------------------------
// Vertex shaders
//--------------------------------------------
struct VSOUTPUT_SHADOW
{
	float4 vPosition	: POSITION;
	float  fDepth		: TEXCOORD0;
};

// Shadow generation vertex shader
VSOUTPUT_SHADOW vertexMain( float4 inPosition : POSITION )
{
	// Output struct
	VSOUTPUT_SHADOW OUT = (VSOUTPUT_SHADOW)0;

	// Output the transformed position	
	OUT.vPosition = mul( inPosition, g_matLightViewProj );

	// Output the scene depth
	OUT.fDepth = OUT.vPosition.z;

	return OUT;
}
code pixel shader

Code: Select all

//--------------------------------------------
// Vertex shaders
//--------------------------------------------
struct VSOUTPUT_SHADOW
{
	float4 vPosition	: POSITION;
	float  fDepth		: TEXCOORD0;
};

//--------------------------------------------
// Pixel shaders
//--------------------------------------------
float4  pixelMain( VSOUTPUT_SHADOW IN ) : COLOR0
{
	// Output the scene depth
	return float4( IN.fDepth, IN.fDepth, IN.fDepth, 1.0 );
}	
but result in same old above post (white canvas texture) :?:
porcus
Posts: 149
Joined: Sun May 27, 2007 6:24 pm
Location: Germany

Post by porcus »

Hi BlindSide,

Sorry for the delay but I had no time in the last days.
The problem is that the shadows are not working with
a directional light. You told me that I have to divide the far and nearvalue
by 1000 but if I do this I get only a black screen (which looks evident with so small values).
BlindSide wrote:Directional light is kinda tricky. You may have to divide your near and far values by 1000 when using a directional light to see anything.
With the usual near and farvalues everything (except shadows)
seem to be correct. Why are no shadows visible with directional light ???
wing64
Competition winner
Posts: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Post by wing64 »

I founded another a shadow mapping technique:
Parallel-Split Shadow Maps
http://appsrv.cse.cuhk.edu.hk/~fzhang/pssm_project/
and
http://http.developer.nvidia.com/GPUGem ... _ch10.html
Could i port that technique to XEffect ? Please suggest me.
best regards,
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

And this is why you use a string instead of a char array in anything but the most time or size critical zone (and even then, a fixed buffer can still be bigger than a string if it isn't completely used.)
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

wing64 wrote:I founded another a shadow mapping technique:
Parallel-Split Shadow Maps
http://appsrv.cse.cuhk.edu.hk/~fzhang/pssm_project/
and
http://http.developer.nvidia.com/GPUGem ... _ch10.html
Could i port that technique to XEffect ? Please suggest me.
best regards,
Yes that should be possible without modifying XEffects, just create one light for each split, and you are free to set the light's view and projection matrices. (If they are not public just make them public, but there should be get/set functions for the matrices).
Dorth wrote:And this is why you use a string instead of a char array in anything but the most time or size critical zone (and even then, a fixed buffer can still be bigger than a string if it isn't completely used.)
I use core::stringc everywhere in this, I'm guessing this post was out of place? But to keep the healthy advice going I'll add that when using strings you should pass them by reference or const reference as much as possible (Be careful of temporary variables!).
porcus wrote:Hi BlindSide,

Sorry for the delay but I had no time in the last days.
The problem is that the shadows are not working with
a directional light. You told me that I have to divide the far and nearvalue
by 1000 but if I do this I get only a black screen (which looks evident with so small values).
Sorry for the late reply, I suggest you look at this tutorial for more information on orthogonal lights (It's for the older XEffects but the same principles can be applied). I hope that helps.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
wing64
Competition winner
Posts: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Post by wing64 »

BlindSide wrote:Yes that should be possible without modifying XEffects, just create one light for each split, and you are free to set the light's view and projection matrices. (If they are not public just make them public, but there should be get/set functions for the matrices).
OK but i confuse something for split shadow
1. First i calculate camera plane (with camera scenenode position and target ) this step return zFar plane
2. calculate split area with zFar from step 1
3. loop num of split
3.1 calculate frustum corners from position,target (from camera scenenode) near, far (from step2) this step return 8 point of corrners
3.2 calculate light frustum with 8 point (from step 3.1), light position, target, fov (from SShadowLight class) this step return a new view and projection matrix of light
3.3 render node with view projection matrix (from step 3.2) to shadowdepthRTT
3.4 calculate crop matrix with with view projection matrix (from step 3.2)
3.5 recalculate view and projection with position,target (from camera scenenode) and render it to RT[0] (i set shadowdepthRTT to material texture layer 0)
ok now the screen is
Image

I don't know why shadow not cast on floor or myself ? If somebody know this problem please suggest me :-( (i wrote this code over 1 week)

code & binary here
http://www.upload-thai.com/download.php ... 88f7c326ab
mirror http://us.share.geocities.com/zaros64/shadow200.zip

ps. geocities link u need manual copy url and paste to address bar or download manager program :-(

best regards,
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

The f... I did not post that post in this thread at all...
What's going on with those fora???
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

wing64 take it one step at a time, first focus on getting the crop matrix working, and then concentrate on splits only after you get it for one light. In the meantime I'll have a look through your code and see if I can spot anything wrong when I have some time.

Dorth, perhaps your reply was meant for this thread?
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

No, it was meant for the fast planet renderer's one, where he had buffer overflow.
wing64
Competition winner
Posts: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Post by wing64 »

BlindSide wrote:wing64 take it one step at a time, first focus on getting the crop matrix working, and then concentrate on splits only after you get it for one light. In the meantime I'll have a look through your code and see if I can spot anything wrong when I have some time.
I hope u have some time for check code. (Help me please....) :cry:
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

I have a question. After a decode the depth:

Code: Select all

vec4 eDepth = texture2D( DepthMapSampler, gl_TexCoord[0].st );
float dDepth = eDepth.x + ( eDepth.y / 256.0 );
What range is it in?

I've noticed the code:

Code: Select all

void main() 
{
	float depth = gl_TexCoord[0].z / gl_TexCoord[0].x;
	float mulDepth = depth * 256.0 + 2.0;
	float flooredDepth = floor(mulDepth);
		
    gl_FragColor = vec4(flooredDepth / 256.0, mulDepth - flooredDepth, 0.0, 0.0);
}
Where gl_TexCoord[0].z is the clip-space z position, right? So that should be in [0,1]. And then the gl_Texcoord[0].x value is the distance from the near to far clip plane. I'm not quite understanding how it is stored encoded, or how it is stored when it is decoded. Can anyone help me out there?

By the way, all I'm doing right now is trying to render the depth map in a post-processing shader to get an output similar to this gray-like look: http://scien.stanford.edu/class/psych22 ... sDepth.jpg
TheQuestion = 2B || !2B
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

You don't have to decode it fully. You can just output "eDepth.x" to get that gray look. Yeah it's in the range [0,1].
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

BlindSide wrote:You don't have to decode it fully. You can just output "eDepth.x" to get that gray look. Yeah it's in the range [0,1].
Ah okay, thanks BlindSide.

EDIT:

Okay, I tried that, but it appears as though I am receiving an error. First case code:

Code: Select all

uniform sampler2D ColorMapSampler;
uniform sampler2D ScreenMapSampler;
uniform sampler2D DepthMapSampler;

void main()
{
	vec4 color = texture2D( ColorMapSampler, gl_TexCoord[0].st );
	vec4 eDepth = texture2D( DepthMapSampler, gl_TexCoord[0].st );

	//gl_FragColor = vec4( eDepth.x, eDepth.x, eDepth.x, 1.0 );
	gl_FragColor = color;
}
Output:
Image
Second case code:

Code: Select all

uniform sampler2D ColorMapSampler;
uniform sampler2D ScreenMapSampler;
uniform sampler2D DepthMapSampler;

void main()
{
	vec4 color = texture2D( ColorMapSampler, gl_TexCoord[0].st );
	vec4 eDepth = texture2D( DepthMapSampler, gl_TexCoord[0].st );

	gl_FragColor = vec4( eDepth.x, eDepth.x, eDepth.x, 1.0 );
	//gl_FragColor = color;
}
Output:
Image

Can you see anything blantantly wrong with my code? I am calling enableDepthPass with true, and addNodeToDepthPass for all the nodes.
TheQuestion = 2B || !2B
Post Reply