Jump to content
  • Advertisement
Sign in to follow this  
Waaayoff

Passing arguments to vertex shader?

This topic is 2702 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm new to this shader stuff so bear with me.

Let's say i have a VS with these parameters :

float4 Pos : POSITION,
float3 Normal : NORMAL,
float2 TexCoord0 : TEXCOORD0,

To use it, in my c++ code i create my vertices using a suitable FVF (In this case, Position, normal and texture coords), store them in a vertex buffer and render them using DrawPrimitive for example.

But what if i want for example to add a paramter to the VS like:

uniform bool bTexture

How do i pass a boolean to the shader??

Share this post


Link to post
Share on other sites
Advertisement

[quote name='Waaayoff' timestamp='1298225159' post='4776737']
Isn't this how you set global variables?

Yep. Isn't that your question?
[/quote]

Nope, i meant how do i pass a parameter to the shader function. Like:

VS_OUTPUT VertexShader([color=#1C2837][size=2]float4 Pos : POSITION, uniform bool Whatever)
[color=#1C2837][size=2]

[color=#1C2837][size=2]I saw it in an SDK sample but couldn't figure out how they passed the boolean in the source code..

Share this post


Link to post
Share on other sites
Which SDK example are you looking at?

In any case, it's commonly done through a particular technique.

VS_OUTPUT RenderSceneVS( float4 pos: POSITION, uniform bool Whatever )
{
//...
}

technique RenderSceneWithWhatever
{
pass P0
{
VertexShader = compile vs_2_0 RenderSceneVS( true );
}
}
technique RenderSceneWithoutWhatever
{
pass P0
{
VertexShader = compile vs_2_0 RenderSceneVS( false );
}
}

Then set the technique depending on whether you want Whatever to be true or false. Whatever (either true or false) will then persist for the life of the technique.

Share this post


Link to post
Share on other sites

Oh! Thanks :)

[quote name='Buckeye' timestamp='1298302940' post='4777048']
Which SDK example are you looking at?

Basic HLSL
[/quote]
Good. Maybe you just missed the technique definitions at the end of the fx file. Actually, that's what I looked at to provide you the example. ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!