Sign in to follow this  

[SlimDX] Shaders and 2-D

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

Before I begin, I want to confess that my chosen path has more or less circumvented shader programming. I'm from the Outcast age; I used to do real-time effects in software, but now I'm ready to push my hardware to its knees. Or at least take advantage of some of its handy features. I'm developing a 2-D engine. Right now it's got all the features it needs to be fully functional, and I am in fact putting it to use. One thing I'd really like to have is spectacular 2-D shader-driven effects. I'm using SlimDX, DirectX 9.0c, and the Sprite batch because it makes things so much easier (and it seems to work extremely well as I have it set up right now). First question: is it even possible to mix shaders with the sprite batch? If so, how is this achieved? Blending modes are more or less automatic: you set them and watch the renderer do its magic. For shaders, I have no idea how they're applied. Add to that the fact that some of the effects I want entail having light sources and you bump into theoretical issues. Because I know I'm going to need at least one light source, let's assume I need to integrate a vertex renderer. (I can do this on top of the existing Sprite batch renderer, so it's not a problem.) Second question: am I able to use TnL vertices with a light source, or does D3D need real spatial coordinates to take into account lighting? I know you can specify a Z-coordinate even with TnL verts, so I'm hoping that will be enough and I don't have to do any viewport transformation magic to line up the vertex sprites with my screen-coordinate-friendly Sprite batch sprites. A quick pointer or two will get me started, if it pleases you. I appreciate any help.

Share this post


Link to post
Share on other sites
Just wanted to let you know that this isn't really a SlimDX question, and you may get more replies and information if you direct it at all of the DirectX users here. Also, break things down and provide more information on what the problem is. Your last paragraph, in particular, was very confusing to me and I'm not sure what you're actually asking here.

Share this post


Link to post
Share on other sites
Assuming SlimDX has a pretty lightweight wrapper over Sprite/SpriteBatch then you should be able to apply shaders. The last time I actually tried it didn't work due to the API overwriting render state, but from looking at the docs the D3DXSPRITE_DONOTMODIFY_RENDERSTATE flag used in ::Begin() should do the job:
Quote:
The device render state is not to be changed when ID3DXSprite::Begin is called. The device is assumed to be in a valid state to draw vertices containing UsageIndex = 0 in the D3DDECLUSAGE_POSITION, D3DDECLUSAGE_TEXCOORD, and D3DDECLUSAGE_COLOR data.


As for your latter paragraph, like Mike I don't fully understand where you're going, but to try and answer...

You can't apply a vertex shader with POSITIONT or FVF_XYZRHW declarations. The whole point of those flags is they bypass the VS. But that's a moot point as the above quote indicates sprites uses regular 3D positions which are fair game for a VS.

If you want to go down the shader route then most of these questions are up to you to define. The above quote along with your code defines the source data you can operate on, so you simply design your shader algorithm to work within those constraints. It is pretty much as complex or as simple as you want to make it [smile]

hth
Jack

Share this post


Link to post
Share on other sites
Thanks for the feedback.

Here's what I would like to do: I want to have background and GUI sprites with normal maps, with the cursor acting as a light source. It's purely a visual effect and has no impact on game play, but I think it would really enhance the look and polish of the game. I've seen this done in 2-D with other projects presented here on GDNet (there was an IotD not long ago showing off this effect with lots of colored lights), but I don't know if the developers used D3DSprite or their own home-brewed engine with raw vertices.

What I ought to do first is look at a normal mapping example and then try to apply the technique to my sprites. If D3DSprite is indeed simply a wrapper for some sort of internal, vertex-based renderer (which doesn't surprise me in the least considering graphics cards are built to operate on vertex data), and it doesn't disable any shader operations, then the limits of what you could do even with sprites are pretty far out.

Thanks for the tip. I'll post back when I run into more problems.

Share this post


Link to post
Share on other sites

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