Sign in to follow this  

HLSL Shader in engine issue ..

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

Hey all After a lot of forum searching I still have a engine-shader issue which costs me many nights of sleep: Now, I have a small engine running which loads a 3dmax scenes/levels and place all the geometry in an Octree structure. But now I would like to integrate HLSL shaders in order to do some dynamic light stuff (and other effects). In HLSL you set the technique to use by calling: pEffect->setTechnique("light"); and ALL the triangles rendered from there on will appear according to the technique just set ... this is fine, but what if I only what some of the triangles to be rendered according to the technique ?? – I guess I would need some kind of shader system which sets the technique to use depending on the sector/portal that the camera is in (octree-independent) ?? Any help ?

Share this post


Link to post
Share on other sites
There is no easy way of accomplishing that using your technique.
You should add an additional data structure that holds your models and sub-models, which need different shaders.
Maybe you've already done that as different materials and texture setups need state-switches for submeshes anyway (or are you just using gouraud-shaded polys?).

Share this post


Link to post
Share on other sites
I can see from your syntax (pEffect->setTechnique("light")) that you're using direct3D so maybe this should actually have been posted in the directX forum.

Anyway, first you need to understand the difference between an effect and a technique. An effect is a generalization. For example our lighting effects. This effect can be implemented in several ways. Each implementation is called a technique. Usually you make several techniques per effect. One that take advantage of the most current graphics hardware, one a little simpler (and therefore slower), and so on. Then you choose the most advanced technique capable of running on the current hardware and use that. This is done with the function setTechnique. This means that when you use the effect it is the technique chosen by setTechnique that will be used. To actually draw something with the technique you have to encapsulate your drawing statements in begin calls and end calls, like this:

pEffect->Begin(&cPasses, 0);

for (iPass = 0; iPass < cPasses; iPass++)
{
draw stuff ...
}

pEffect->End();

Only then your polygons will be rendered with the effects. For more information look at the sample in the DirectX 9.0c SDK (Summer 2004) called BasicHLSL.

My suggestion to you would be to make a render queue for all your renderable objects, and then sort them by texture, shader, etc..

Share this post


Link to post
Share on other sites
Quote:
Original post by perrs
My suggestion to you would be to make a render queue for all your renderable objects, and then sort them by texture, shader, etc..

It doesn't sound like he's using any renderable objects but feeding all polys into an octree structure instead. I see this as the major problem so your last advice is propably exactly what he needs to implement first - some kind of scene-graph containing seperate renderable objects.

Cheers,
Pat.

Share this post


Link to post
Share on other sites
Thanks guys for your input, guess I got some of it now. I need to build a shader queue for the renderable objects = nodes on the Octree. It could work like this:

1)Camera in node with ID=74, use shader no 5 and render primes
2)Camera can also see into node with ID=23, use shader no 8 and render primes
:

so it comes down to building a shader structure attached to the Octree. Many nodes may share the same shader with multi lightsources etc.

Well I can always try ... please tell me if I’m heading in the wrong direction!

I just love dynamic shader light :)

Share this post


Link to post
Share on other sites

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