Jump to content
  • Advertisement
Sign in to follow this  
Stormtrooper

[SlimDX] Is this how shaders work?

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

Ok, I want to have to methods for shaders to work. First, to individual sprites, second to the whole scene(post processing effects). I've never used DirectX, SlimDX or shaders for that matter and I want to know if my idea of the implementation is correct along with a question at the end. For a sprite:
Begin scene
  if object has a shader
     effect.begin
     render object
     effect.end
  else
     render object

  render objects w/o shaders
end scene
For the whole scene:
Begin scene
  if doing post processing effect
     setRenderTarget(newSurface)
     effect.begin
     render scene
     effect.end
     render new surface to the buffer
  end if
    render scene normally
end scene
My question is, after I render the scene to the new surface to apply the shader, how do I render the surface to the main buffer? Simply draw a quad, with the surface applied as the texture? EDIT: I just saw in the DirectX 9 docs that the setRenderTarget sets the viewport to the surface. [Edited by - Eeyore on July 14, 2008 10:50:49 PM]

Share this post


Link to post
Share on other sites
Advertisement
Exactly. Just draw a quad and set your previous render surface as a texture and draw it on the original render target (the back buffer).
All you posted seems to be just OK to me :)

Share this post


Link to post
Share on other sites
Would like to comment a small thing. Your block:
Begin scene
if object has a shader
effect.begin
render object
effect.end
else
render object

render objects w/o shaders
end scene

Should be changed to:
Begin scene
for each object
effect.begin
render object
effect.end
end for
end scene

Meaning, allow every object to have a shader even when the shader defaults to the basic rendering pipeline. It wont break your performance at all.

A better approach should be to group the objects by shader so you can setup a shader and render all related sprites in a single block, like:

Begin scene
GroupObjectsByEffect
for each effect
effect.begin
for each object
render object
end for
effect.end
end for
end scene


Luck!
Guimo

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!