Jump to content

  • Log In with Google      Sign In   
  • Create Account

DirectX9 and Pallete swaping ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 greenpig83   Members   -  Reputation: 326

Like
0Likes
Like

Posted 18 March 2013 - 04:34 AM

I'm making kind of a classic 2d rts game like starcraft, aoe1. cossack...

For team color (1->8). AOE1 use pallete color I think,  they only use 256 pallete bmp color!

 

I know many ppl asked about this. 

After 2 days searching I found only 1 way, is using Pixel Shader and look up table.  Pallete no more usable in today cards and direcx9.

But does Pixel Shader support quite old Computer that do not have hardware graphic card. I want my game to support as much ppl as it can. Because this is just a 2D game. One more problem is that with Pixel shader, you have to set Beginpass, before each sprite batch. If i draw team 1 player unit, then team 2 player unit, then team 1... -> many beginpass will have to draw, and it will kill the performance ! 

 

I tried to generate texture for each team color. But it seem too bad. with only 1 team, the game used 300-400mb texture, ( 1 sprite for attack may use a texture of 3000x200 image size, 1 unit used about 5 sprite, and the game have many units sad.png ). for 8 player, it will kill any high end comp. That's absurd.

 

Using maskColor in gSprite->draw   ( Then use a color sprite of gray color to draw over the real sprite ). Can help me a lot, but it's quite limited. Make the color look weird.  This is the method I'm using in the game now.

 

I'm running out of ideas. Can you give me a better Idea. I think this is a very simple thing, and games decades ago can solve it very well. I wish I can touch the genie engine or dmcr :(

 

I'm thinking of 2 direction :

  Use pixel shader : but make sure it call less BeginPass ass possible, Because my units are draw in order of relative depth. Cant draw blue units, then red units, then...

  Generated Units color, so must optimize the texture resource management...


Edited by greenpig83, 18 March 2013 - 04:38 AM.


Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2863

Like
0Likes
Like

Posted 18 March 2013 - 09:41 AM

You may limit yourself to something like Shader Model 2 or 3 (which are supported by the D3D9) level, and practically all usable hardware should support them. Even Shader Model 2 should give you enough of freedom. 

 

I don't think that there is a reason to use palette anymore. For the different unit coloring, you could make your sprite sets with white color and then have a gray scale mask texture to indicate the parts which needs coloring. You may pass the unit color in the instancing parameters for example. In the pixel shader then for each texel calculate the modulated color (ie. texture color modulated with the unit color) and then use the gray scale mask to lerp between the original color and the modulated color.

 

For sprite ordering, I think that you may use z-buffering for it or just putting the sprites in the buffer in correct order. For z-buffering you could have a instancing parameter and use it as a depth in the vertex shader output.

 

This way, you may draw all the sprites using the same sprite sheet with one draw call.

 

Cheers!



#3 mhagain   Crossbones+   -  Reputation: 8285

Like
0Likes
Like

Posted 18 March 2013 - 09:41 AM

But does Pixel Shader support quite old Computer that do not have hardware graphic card. I want my game to support as much ppl as it can.

 

Shader Model 2.0 is all that's required for this kind of lookup, and that's available on everything, including the likes of the Intel GMA900 - here's a review from 2004: http://www.anandtech.com/show/1413 - I think you don't need to be concerned about older hardware here.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 greenpig83   Members   -  Reputation: 326

Like
0Likes
Like

Posted 18 March 2013 - 11:57 AM

Thanks for comments. I think I will spend more time for the pixel shader techniques. 

I've already found this thread http://www.gamedev.net/topic/485555-lookup-table-using-pixel-shader/

 

The HLSL lang is strange, and I quite dont understand someplace. 

Do I have to use a Vertex Shader before the Pixel Shader. Because I'm doing a 2D game, I dont use any worldview matrix thing in the game... Just want to change the pixel color... And in my code, when I dont set the texture in the Sampler, the pixel shader still take effect. 

 

 

struct VS_OUTPUT
{
    float4 hposition : POSITION;
float2 texture0  : TEXCOORD0;
    //float4 color : COLOR0;
};

 

PS_OUTPUT myps( VS_OUTPUT IN )
{
    PS_OUTPUT OUT;
OUT.color = tex2D( Sampler, IN.texture0 );
//OUT.color = float4( 0.0, 0.0, 1.0, 1.0);
    return OUT;
}
 
In the code above. I dont know what the texture in the Sampler do. Event if i dont set it, or set to other texture. OUT.color still return the Input texture color.

 

However after some experiment. I found out that when I want to change state in the pixel Shader (use setInt, setTexture..., to tell the shader to choose other look up table, for other units). I must set it outside of the gsprite->begin / end. So there noway to change it one sprite by one. I'm drawing alot of sprites between 1 begin/end pair for performance.

 

As for the z-buffer Idea, now I'm sorting it myself and draw units in order, set z=0. If i use the directx to sort, i will have to set each unit a z value. it maybe 0.1, 0.2 ...

Because I'm doing a 2d Game, do you think it will make the sprites distort ?, it get zoomed or look weird ?


Edited by greenpig83, 18 March 2013 - 12:08 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS