Sign in to follow this  
Carradine2

Final Color affects framerate in a HLSL Pixel Shader?

Recommended Posts

I am currently rendering several tree meshes through my HLSL shader on screen, as well as other meshes. I am getting a tremendous drop in my framerate when I look at one tree when it fills the entire screen. However, I will look at other objects full screen and get no noticable framerate drop. The tree mesh is not a terribly high poly mesh, and the textures on it are only 3 textures of 128x128 and maybe 200 polys for the leaves. However, if I just add the line: OUT.color = float4(1,1,1,1) at the very end of my pixel shader in HLSL to output the whole tree white, I get a considerably high framerate again. Keep in mind I have not removed any code, but added that one line, and the trees render much, much faster. I have tried removing my lighting, my alpha blending, and other code, but every time I just add that line my framerate improves tremendously. So I need these trees to render a little faster, so my question is why does adding that one line to override color on the pixel shader make the objects render so much more quickly? Is it an issue with texture size of the current mesh? Or how many times that texture needs to be rendered on X number of polys? Thanks for any help Carradine

Share this post


Link to post
Share on other sites
The shader program compiler is not stupid. If you override all the calculations at the end by just outputting a constant, none of the previous instructions are likely to be performed. You wont have to fetch textures etc, making the shader super-fast.

How much of a fps drop are you seeing? Could you post the shader code for the pixel shader?

Edit: what do these trees actually look like? A screenshot might help figuring out the problem.

For example, if you are viewing only that tree covering the whole screen it is likely that the bottleneck is the pixel shader, so if you speed it up 10 times or so, you might get a 10 times decrease in frame rendering time. Is your fps drop actually a drop from one insanely high fps, to another not-quite-as-insanely high fps?

Share this post


Link to post
Share on other sites
Well I believe I have solved most of the problem. I had a loop within my pixel shader that was only meant to be processed if a certain value was true. But even if the loop is skipped, it seemed that the pixel shader still processed it in some fashion even though the condition to enter the code was false. Also, I as able to move the loop out of my pixel shader into my vertex shader and completely solve that issue so now my pixel shader is nothing but bare bones again.

So you seem to be right, just overriding the color in the pixel shader will ignore all other code in the pixel shader. Its not what I was expecting to happen. So it wasn't a big issue of alpha blending or polys or textures.

What was happening was that I was attempting to render point lights within the pixel shader, when in fact it works just as well in the vertex shader. I thought point lighting in the vertex shader would only give me lighting per vertex in the vertex shader, but I was wrong.

Thanks for the info.

Share this post


Link to post
Share on other sites

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