• Advertisement
Sign in to follow this  

Sprite Programming question

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

I have a question. It might seem ridiculously easy for some but I can't find any information on how to do it. I'm builing a 2-D RPG and I want my sprites to flash a bright white but I can't figure out how I'm going to do it. If I set D3DColor parameters any higher than 255 it will go to black and if I set it to 255, It only displays the sprite how it looks on the bitmap.

Share this post


Link to post
Share on other sites
Advertisement
Going for values higher than 255 and less than 0 will produce some wierd effects since the range of a D3DCOLOR component is 0 - 255,

If you really want a brighter sprite you will move to HDR (High dynamic range) lighting which will add some complexity. It all depends on what effect you want to achieve. If you are using sprites as your particle system then the range of 0 - 255 is fine. It all depends.

I hope this helps.

Share this post


Link to post
Share on other sites
I take it you are rendering quads to the screen?

If so, I'm thinking you could make use of the specular lighting system. This essentially adds brightness on after the texture/diffuse modulation, and can make your sprite completely white - either that or blend another totally white sprite over the top using the original sprite as the alpha information.

...Or do the same thing in a pixel/fragment shader.

Share this post


Link to post
Share on other sites
Internally, all colors are kept in some floating point format, so it wouldn't matter if you exceed the 255 (actually, 1.0). The only problem would be to pass the parameters to the driver as BYTE (or DWORD).

I think you could get away with using D3DTOP_MODULATE2X (or even 4X).

Basically, when you start the brightening process, you set D3DTOP_MODULATE2X instead of D3DTOP_MODULATE, and color channels to 128, instead of 255. Then you gradually increase the color channels from 128 to 255, being able to control the process.

Share this post


Link to post
Share on other sites
I personally think the easier way would be to use the emissive component of a d3d material...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
These answers are ridiculous. Don't listen to any of that. HDR and floating point color.... you are building a 2D sprite game. The easiest way to do this is to render your sprite a second time with different blending effects. Look at SetRenderState(D3DRS_SRCBLEND,

Think of it this way: render full color instance, first. The render the same with just the alpha channel and a blend color (like 255, 255, 255) and it will light up your sprite.

Share this post


Link to post
Share on other sites
It isn't working so I'm guessing I didn't fully understand what was said
The setup I have right now is:

Sprite->Draw();
id3dd8->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCCOLOR);//???????????
Sprite->Draw();

The question marks are there because I'm not sure what parameters are supposed to be there or if my setup is completely wrong to begin with.

Share this post


Link to post
Share on other sites
To detail AP's post:

The first render is done normally. The second is simply a quad of the same size as the original image in the same position as the original image with three properties:

1: only one color. Don't use any textures. Just a solid color -in your case full-white (alpha,255,255,255)

2: an alpha value -try 50% for starters(128,color,color,color)

3: set the render-states needed to perform additive blending to the backbuffer.

Share this post


Link to post
Share on other sites
You don't need any special render states or multiple passes or anything for this. Like somebody said, you just need to set the SPECULAR component of your vertices. Any color values in specular will BRIGHTEN your sprite. (The other choice, as you've discovered, is to reduce your diffuse values, which will fade the sprite toward black.)

Using multiple passes with alpha/renderstates is definitely NOT called for here.

Share this post


Link to post
Share on other sites
Could it have anything to do with the Sprite->Begin() and Sprite->End()
functions cause I'm not using them and the light thing isn't working.

Share this post


Link to post
Share on other sites
From what I know, if you use ID3DXSprite version of sprite, then it automatically bypasses render states and enables bilinear filters etc. That is because these sprites are rhw based, based on pure 2D. By using them, you are able to bypass most of, if not all, Transform and Lighting (T&L) pipeline. That means if you apply matrix calculations, they wont have any effect on sprites, they will continue to draw on their specified x,y position; similarly, lighting that applies every where else wont have any effect on sprites.

This might sound old-fashioned, but you can do the following:

- Have two copies of each bitmap on which you wish to apply this white-glowing effect.
- One would be the original, say bmp1, other would be the white version of exactly the same bitmap, say bmp2.
- When ever you need the white effect, you can draw bmp2 with some grey-effect color on top of bmp1.
- When you dont need that effect, either: dont draw bmp2 at all, or, draw it with color 0x00000000 (or was it 0xff000000 for transparency effect?) on top of bmp1.

If your rendering doesnt get very heavy, above solution should work fine, else the other solution would be to write your own customized sprite class, that supports T&L pipeline. But, personally, latter option is kind of more work to do.. :)

Share this post


Link to post
Share on other sites
Thanks I believe that will work, I just got home from my 3rd shift job and plan to go to sleep when I wake up I'll try that and tell you guys if it works or not but I'm pretty sure that will work.
GoodNight!!

Share this post


Link to post
Share on other sites
That worked wonders, it does the flashes that I wanted it to do.
Thanx to everyone else too, It gave me something to look up and find more info
on DirectX.

Share this post


Link to post
Share on other sites
I don't know about D3DXSprite but you don't need a T&L pipeline to have flashing/brightened sprites. When you work with transformed and lit vertices, you can add a specular component to the FVF (and to each vertex for the quad, or only some of them if you want!) and it will brighten accordingly, including using the alpha information. I use this ALL the time so I'm sure it works... I'm sure your solution is fine for low sprite counts but doesn't it require twice as much work? Just FYI if you want to optimize in the future...

Share this post


Link to post
Share on other sites
Are you talking about textured quads or the D3DXSprite, I want to use the sprites because of ease of working with 2D objects. When I looked at the code for setting up stuff it looked far too complicated for me at this point, so I'm going to take it slow, and work my way up.

Share this post


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

  • Advertisement