AnimTree shader and PSSM shadows

Posted By: oliver2s

AnimTree shader and PSSM shadows - 01/23/14 17:30

In 3DGS shader folder there's a AnimTree.fx shader which makes vegetation move in the wind. As this is done in the vertex shader it doesn't effect PSSM shadows. This means the trees move but the shadow doesn't.

Is there any way to combine both shaders (I don't need code. Just looking for an explenation how it's done)?
Posted By: HeelX

Re: AnimTree shader and PSSM shadows - 01/23/14 18:56

You would have to write a special vp_pssm.fx and vp_depth.fx shader just for the trees. In detail, you need to bring the vertex transformation of the AnimTree.fx shader into the vertex shaders of the pssm fx files. You have to do this because the tree has to waive in the depth view, too, to cast the waived silhouette to the ground. And to reiceive it, of course wink

The tricky thing is to bring this kind of "pssm shaded tree waiving" logic as addition into <shadows.c>. There, the shaders are applied as view materials to each and every entity as far as I can see. You would have to write something like an interceptor - a view event - that switches the shaders dependent if it is a tree or not.
Posted By: Steempipe

Re: AnimTree shader and PSSM shadows - 01/23/14 20:50

I like your ideas HeelX. And, I hope Oliver2s will make it work, somehow.
Posted By: oliver2s

Re: AnimTree shader and PSSM shadows - 01/23/14 21:36

Originally Posted By: HeelX
You would have to write a special vp_pssm.fx and vp_depth.fx shader just for the trees. In detail, you need to bring the vertex transformation of the AnimTree.fx shader into the vertex shaders of the pssm fx files. You have to do this because the tree has to waive in the depth view, too, to cast the waived silhouette to the ground. And to reiceive it, of course wink

The tricky thing is to bring this kind of "pssm shaded tree waiving" logic as addition into <shadows.c>. There, the shaders are applied as view materials to each and every entity as far as I can see. You would have to write something like an interceptor - a view event - that switches the shaders dependent if it is a tree or not.


Thank you. But that's the things I already know. You gave an explenation why the shadow doesn't move with the trees. But I looking for an explenation how to bring the vertex transformation from the tree shader into the pssm shader.
Posted By: Slin

Re: AnimTree shader and PSSM shadows - 01/23/14 22:39

Whats the problem with that? You could just take the animtree vertex shader together with the depthmap pixelshader as well as with the pssm pixelshader. You may need to add some needed calculations to the vertex shader and could remove some that arenīt.

I donīt have the files here right now but from a google search and the animtree shader I found, Iīd say you have to take the following parts of the tree shader:
Code:
float3 P = DoPos(inPos); //this might already be there, so just reuse it if it is
	
	float force_x = DoDefault(vecSkill41.x*(0.1/50),0.1); 
	float force_y = DoDefault(vecSkill41.y*(0.1/50),0.1);
	float offs = vecTime.w+0.2*(P.x+P.y+P.z);
	float speed = sin(offs * DoDefault(vecSkill41.z*(0.05/50),0.05));
	
	if(inPos.y > 0 ) // move only upper part of tree
	{
		inPos.x += speed * force_x * inPos.y;
		inPos.z += speed * force_y * inPos.y;
		inPos.y -= 0.1*abs(speed*(force_x+force_y)) * inPos.y;
	}
	Out.Pos = DoTransform(inPos); //this should already be in the other shaders, just make sure to put the code above in front of it

Posted By: sivan

Re: AnimTree shader and PSSM shadows - 01/24/14 08:47

in current MapBuilder it is already solved. I use a modified depth and shadow shader, probably the depth is the key elelmtent, I don't rememebr exactly. but I use no self shadows on trees in case of pssm.
Posted By: oliver2s

Re: AnimTree shader and PSSM shadows - 01/24/14 11:19

Didn't you say you don't use PSSM in Map Builder?
Posted By: sivan

Re: AnimTree shader and PSSM shadows - 01/24/14 13:54

I personally don't use but made it optional. in startup settings menu you can select shadow_stencil value: -1 means shade-c shadowmapping, 8 means PSSM, and 0,1 are also available for decal and stencil shadows.
Posted By: oliver2s

Re: AnimTree shader and PSSM shadows - 01/24/14 16:23

Thank you all. It's now working laugh
Posted By: BoH_Havoc

Re: AnimTree shader and PSSM shadows - 01/27/14 23:38

Not sure if you are using Shade-C for this, but if you do, then have a look at 05_livingBloomShadow.fx in the examples/fx folder. Its a shadowmap-replacement shader for an object which has vertex movement in it's main shader.
Just kick out the wiggle vertex movement stuff and add the tree wind animation instead laugh
Then use sc_skill(entity, SC_OBJECT_MATERIAL_SHADOWMAP, yourCustomVertexAnimationMaterial); to set a shadowmap-replacement shader for this object.

[edit] Eh, just saw you already found a fix, sorry crazy
© 2024 lite-C Forums