Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 972 guests, and 3 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
how to create camera facing model shader #454427
09/08/15 07:27
09/08/15 07:27
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline OP
Expert
sivan  Offline OP
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
hi,
I just saw Superku's great forest shader, and it reminded me that a while ago I wanted to create a camera facing lod model shader to apply sprite-like 4 vertex models, instead of the current ugly cross-shaped double-faced models I use in MapBuilder.
(they are static models, and I don't want to adjust their rotation from a lite-c loop, to save performance.)
any help welcome laugh
thanks.


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: how to create camera facing model shader [Re: sivan] #454429
09/08/15 11:24
09/08/15 11:24
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
I never faced this issue but I can imagine a path.

Compute on the cpu and save on mateial skills a 2d rotation matrix related to camera inverse pan and apply to every tree sprite xz members before converting to clip space into the vertex shader.

EDITED
I just realized this method will not work with trees merged in a single entity, as they should be if you look for performance optimitation. The solution could go around saving the rotation axe in object space for each vertex into the buffer.

EDITED 2
Since I am interested in these things I did a test workaround.

I created a model procedurally of 126^2 face trees. I added the center of rotation for each vertex to the vertex buffer. Secondary uv coords or x3-y3. Both worked.

I compute the sine and cosine of the camera pan in the main loop and save into material skills. The faces all look to the -X axe so rotating them by the camera pan makes them visible parallel to the projection plane.

Code:
mtlTreeSprites->skill1 = floatv ( sinv ( camera->pan ) );
mtlTreeSprites->skill2 = floatv ( cosv ( camera->pan ) );



Code:
void TreesVS (
	in float4 InPos	: POSITION,
	in float2 InTex	: TEXCOORD0,
	in float2 InOffset: TEXCOORD1,
	out float4 OutPos	: POSITION,
	out float2 OutTex	: TEXCOORD0 )
	{
		float2 pos = InPos.xz - InOffset.xy;
		InPos.xz = float2 ( pos.x * vecSkill1.y - pos.y * vecSkill1.x, pos.x * vecSkill1.x + pos.y * vecSkill1.y ) + InOffset.xy;
		OutPos = mul ( InPos, matViewProj );
		OutTex = InTex.xy;
	}



It works well.



Salud!

Last edited by txesmi; 09/08/15 13:58.
Re: how to create camera facing model shader [Re: txesmi] #454443
09/08/15 14:06
09/08/15 14:06
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Maybe a reply would be better than editing...
bump!

Re: how to create camera facing model shader [Re: txesmi] #454450
09/08/15 19:32
09/08/15 19:32
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline OP
Expert
sivan  Offline OP
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
hey, you made a crazy fast good job grin
I don't fully know yet how to store the centre of rotation of model vertices... by the way currently I use no merged models for trees as I keep them destructible.


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: how to create camera facing model shader [Re: sivan] #454460
09/08/15 23:43
09/08/15 23:43
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Faster cause no lighting grin

Using single entities for each tree lets you rotate around their origin so no extra data is needed.

Code:
InPos.xz = float2 ( InPos.x * vecSkill1.y - InPos.z * vecSkill1.x, InPos.x * vecSkill1.x + InPos.z * vecSkill1.y );



Salud!

Re: how to create camera facing model shader [Re: txesmi] #454468
09/09/15 06:51
09/09/15 06:51
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline OP
Expert
sivan  Offline OP
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
thanks!


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: how to create camera facing model shader [Re: sivan] #454478
09/09/15 09:32
09/09/15 09:32
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline OP
Expert
sivan  Offline OP
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
I think matWorldViewProj is needed for OutPos, and entity rotation must be 0. probably entity.pan could be added by an entity skill to handle it too...

Last edited by sivan; 09/09/15 09:33.

Free world editor for 3D Gamestudio: MapBuilder Editor
Re: how to create camera facing model shader [Re: sivan] #454482
09/09/15 10:34
09/09/15 10:34
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Yes, I used matViewProj because world and object spaces were coincident in the test I built (0,0,0 origin plus no rotation). I can see the inconvenience of sharing as it was crazy

Re: how to create camera facing model shader [Re: txesmi] #454915
09/29/15 09:54
09/29/15 09:54
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline OP
Expert
sivan  Offline OP
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
one more question:
is there a way to compensate entity pan within the vertex shader? maybe by storing their pan is an entity skill...
because trees look better when they are randomly rotated, but their billboard lod has an angle offset currently.


Free world editor for 3D Gamestudio: MapBuilder Editor

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