3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Vertex shader question
#56681
10/01/05 14:59
10/01/05 14:59
|
Joined: Mar 2005
Posts: 80
SirSven
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2005
Posts: 80
|
Is it possible to make a shader (i think vertex shader is needed - but i'm a shader noob) which turns all vertices of an modell to the camera? Like an sprite with facing=on and oriented=off but for every vertex of a modell.
Thanks
Last edited by SirSven; 10/01/05 14:59.
|
|
|
Re: Vertex shader question
[Re: SirSven]
#56682
10/03/05 18:17
10/03/05 18:17
|
Joined: Aug 2002
Posts: 44 Panama City, FL
Specterdragon
Newbie
|
Newbie
Joined: Aug 2002
Posts: 44
Panama City, FL
|
If I'm understanding you correctly, you're trying to flatten the model into a plane and then have that plane facing the camera? If so, does the model recalculate and reflatten itself on every frame, or once flattened does this fixed image face the camera?
Depending on your aplication, you may or may not need a vertex shader vs. a different model. Any chance of getting a more in-depth explination of the effect you're trying to achieve?
Just thinking out loud,
Specterdragon
|
|
|
Re: Vertex shader question
[Re: Rigoletto]
#56685
10/05/05 11:58
10/05/05 11:58
|
Joined: Mar 2005
Posts: 80
SirSven
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2005
Posts: 80
|
Thank you, but I'm so bad in shader programming (shame on me). I can't get it work. If tried Rhuarc's code, but I get errors. Maybe someone can have a look at this code. Code:
DELETED -> IT WAS DAMN BAD, SORRY
Last edited by SirSven; 10/05/05 17:45.
|
|
|
Re: Vertex shader question
[Re: Rigoletto]
#56687
10/05/05 17:41
10/05/05 17:41
|
Joined: Mar 2005
Posts: 80
SirSven
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2005
Posts: 80
|
Thanks Rigoletto (you must excuse because thats the first shader I'm triing to program and it's very hard to learn with my bad english ) So here is my 2nd try Code:
material material_test { effect " float4x4 matWorldViewProj; texture entSkin1; sampler ScreenProjSampler = sampler_state { texture = <entSkin1>; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; }; float3 mainVS(float4 Pos : POSITION0) : TEXCOORD0 { float4 toScreen = mul(float4(Pos.xyz,1),matWorldViewProj); float3 tex0; tex0.x = 0.5f * (toScreen.z+toScreen.x); tex0.y = 0.5f * (toScreen.z-toScreen.y); tex0.z = 1.0f * toScreen.w; return tex0; } float4 mainPS(float3 tex0 : TEXCOORD0) : COLOR0 { float2 screenCoords; screenCoords.x = tex0.x/tex0.z; screenCoords.y = tex0.y/tex0.z; float4 ScreenSpaceSample = tex2D(ScreenProjSampler,screenCoords.xy); return ScreenSpaceSample; } technique test { pass p0 { VertexShader = compile vs_2_0 mainVS(); PixelShader = compile ps_2_0 mainPS(); } } "; }
Now I get an error with the position in the vs and i can't understand why.
Last edited by SirSven; 10/05/05 17:49.
|
|
|
Re: Vertex shader question
[Re: SirSven]
#56688
10/05/05 17:54
10/05/05 17:54
|
Joined: Mar 2001
Posts: 3,298 Beverly, Massachusetts
Rhuarc
Expert
|
Expert
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
|
Quote:
Thanks Rigoletto (you must excuse because thats the first shader I'm triing to program and it's very hard to learn with my bad english )
So here is my 2nd try
<code omitted>
Now I get an error with the position in the vs and i can't understand why.
You need to do just that, write out the position coordinates.
Code:
material material_test { effect " float4x4 matWorldViewProj; texture entSkin1; sampler ScreenProjSampler = sampler_state { texture = <entSkin1>; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; }; struct VS_OUT { float4 pos : POSITION; float3 tex0 : TEXCOORD0; }; VS_OUT mainVS(float4 Pos : POSITION0) { VS_OUT outStruct; outStruct.pos = mul(Pos,matWorldViewProj); float4 toScreen = mul(float4(Pos.xyz,1),matWorldViewProj); outStruct.tex0.x = 0.5f * (toScreen.z+toScreen.x); outStruct.tex0.y = 0.5f * (toScreen.z-toScreen.y); outStruct.tex0.z = 1.0f * toScreen.w; return outStruct; } float4 mainPS(float3 tex0 : TEXCOORD0) : COLOR0 { float2 screenCoords; screenCoords.x = tex0.x/tex0.z; screenCoords.y = tex0.y/tex0.z; float4 ScreenSpaceSample = tex2D(ScreenProjSampler,screenCoords.xy); return ScreenSpaceSample; } technique test { pass p0 { VertexShader = compile vs_2_0 mainVS(); PixelShader = compile ps_2_0 mainPS(); } } "; }
This shader however, transforms the texture to be displayed flat on a 3d object, not flatten out the polys of a 3d object (alike to a sprite) and face it to the camera, that would be a bit different.
-Rhuarc
|
|
|
Re: Vertex shader question
[Re: Rhuarc]
#56689
10/05/05 18:28
10/05/05 18:28
|
Joined: Mar 2005
Posts: 80
SirSven
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2005
Posts: 80
|
Thank you Rhuarc
Now it works without errors, but I just see a black object!
Last edited by SirSven; 10/05/05 18:28.
|
|
|
|