Sign in to follow this  

Best way for shaders

This topic is 4069 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

Hello everyone, I have a couple of simple questions that I hope they will get simple answers. What is the best way to use shaders in directX, using Effects or CreateVertexShader or Pixel? What if I want to have may effects (in Effects you can have techniques); can I use many files and pass the resulting of one shader to another? I have only seen the Effects API so I don't know what is the sacrifice of using this method. I would like to know the best way no the easy way, I really don't care if it takes me a long time to render a ball on the screen. Thanks everyone.

Share this post


Link to post
Share on other sites
The concept of Shader is not a common language,but something like call-back-function.If you want to do sth like "make a vertex buffer by one shader and pass it to another", it is not supported.
The best way for passing data is that only to pass data from VS to PS(pixel shader).

the basic process is:

SetStreamSource(),DrawPrimitive():N vertex input to VSVS(vertex shader).
VS:N pixel input to PS
PS:
return color to each render target or discard.

you can make many(if may = many) effect in one .fx file.like that:

technique T0
{
pass Pass_0
{
VertexShader = compile vs_2_0 Position_Pass_0_Vertex_Shader_vs_main();
PixelShader = compile ps_2_0 Position_Pass_0_Pixel_Shader_ps_main();
}

}

technique T1
{
pass Pass_0
{
VertexShader = compile vs_2_0 Position2_Pass_0_Vertex_Shader_vs_main();
PixelShader = compile ps_2_0 Position_Pass_0_Pixel_Shader_ps_main();
}

}

If you do not need porting your code to glsl,I think to use Effect will be good enough.It is not a sample but weak file format,but an extension file format.
For more shader knowledage and sample:
http://download.developer.nvidia.com/developer/SDK/Individual_Samples/featured_samples.html

want more?

Share this post


Link to post
Share on other sites
Quote:
Original post by mvtapia
I have only seen the Effects API so I don't know what is the sacrifice of using this method. I would like to know the best way no the easy way, I really don't care if it takes me a long time to render a ball on the screen.

I think that using ID3DXEffect is the best way to go. Otherwise, you have to compile the vertex & pixel shaders yourself, find the registers of constants yourself, and set them manually (through the Set[Vertex|Pixel]ShaderConstant*() functions.

In short, what you would probably end up doing is developing a library that worked like Effect does anyways. So I would recommend just going with effect, and perhaps writing a little wrapper around it to avoid having to use handles everywhere. For example, maybe you could have classes like:

Effect
EffectTechnique
EffectConstant


All these would just go through ID3DXEffect, but they could make it much easier to use.

Share this post


Link to post
Share on other sites
"best" is a subjective thing. If you're starting out, then "best" probably means "simplest", in which case using the FX framework makes sense.

The FX framework is slow and memory consumptive by comparison to some other approaches, but if you're just starting out, it's not at all worth worrying about.

Share this post


Link to post
Share on other sites

This topic is 4069 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this