About Store Forum Documentation Contact



Post Reply 
Particles and Custom Shaders
Author Message
fatcoder Offline
Member

Post: #1
Particles and Custom Shaders
I'm just wondering if there is a way to get particles to appear over the top of objects that use a custom shader.

I have modified the Shader Creation tutorial to illustrate the problem. I increased the alpha in the pixel shader to 1.0f to make it stand out more. Then I added the following code to the Render method.

Code:
case RM_BLEND:
{
   DrawParticle(*Images("../data/Obj/Particles/star.gfx"),0,RED,0.5f,0.3f,0.0f,
                Vec(1.2f,0.0f,0.0f),0.0f);
}break;

Here are the results. You can see the particle being drawn off to the side of the ball in the first shot.
   

Now in the second shot I moved the camera around a bit so that the particle goes in front of the ball, however you can see that it does not render in front of the ball.
   

If I change the ball to use the standard EE shaders, then the particle renders in front of the ball correctly, as can be seen here in the third shot.
   

How can I get particles to render correctly with objects using custom shaders?
(This post was last modified: 09-07-2012 05:36 AM by fatcoder.)
09-07-2012 05:33 AM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #2
RE: Particles and Custom Shaders
Is this a limitation or a bug, or is there something you need to add to an object's custom shader to make it work with particles.
09-14-2012 11:36 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #3
RE: Particles and Custom Shaders
Well I woke up this morning and had an epiphany! In case anyone else should ever run into this problem, the solution turns out to be so simple I don't know how I missed it.

You just need to draw your object in RM_BLEND using drawBlend(), and draw it before particles, like this.

Code:
case RM_BLEND:
{
    ball.drawBlend(MatrixIdentity);

    DrawParticle(*Images("../data/Obj/Particles/star.gfx"),0,RED,0.5f,0.3f,0.0f,
                 Vec(1.2f,0.0f,0.0f),0.0f);
}break;
09-18-2012 12:38 AM
Find all posts by this user Quote this message in a reply
Post Reply