Best way for shaders

Started by
2 comments, last by JasonBlochowiak 17 years, 5 months ago
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.
Marco Tapia
Advertisement
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?
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:

EffectEffectTechniqueEffectConstant


All these would just go through ID3DXEffect, but they could make it much easier to use.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
"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.

This topic is closed to new replies.

Advertisement