Flat color quad

Started by
3 comments, last by Jams007 21 years ago
I'm making a GUI frontend and I'm having problem making a simple colored quad. I don't want to use vertex color since the entire quad is to be the same color. So I though using the diffuse color of a DX material in Flat shading mode, it should make it ? Actually my quad is always fully white Is there a way to do it without using vertex color ? Thanks. www.mpw2002.fr.st [edited by - Jams007 on March 26, 2003 7:45:07 AM]
www.mpw2002.fr.st
Advertisement
no
submit or die
Nope I don''t think that is going to work. Unfortunatly Direct3D doesn''t have its own version the immediate mode commands that OpenGL has such as glColor3f().

A vertex shader would pull that off quite nicely for you. Though it would probably just be easier to use the diffuse color parameters for your vertex.

Materials are part of the lighting engine. So without vertex normals and lights, they are not going to work properly.

You could probably have Direct3D automatically generate normals for your object (Not sure how to do this. Look it up in the SDK Docs). Then enable lighting and set the ambient light to the color you wish the quad to have. Or use white ambient light and set the object''s material to the color you wish to use.

Make sure that flat shading is set for both of these modes.


I am a signature virus. Please add me to your signature so that I may multiply.
Jams007: Since everyone seems to be suggesting that you can''t do it without shaders I''ll suggest 3 ways you CAN do it without shaders :

1)
...
SetTSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 );
SetTSS( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR );
SetTSS( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );

SetTSS( 0, D3DTSS_ALPHARARG1, D3DTA_TEXTURE );
SetTSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 );
SetTSS( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );
SetTSS( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

SetRS( D3DRS_TEXTUREFACTOR, 0xAARRGGBB );

DrawBlahPrimitiveBlah()...
...

Change the op to MODULATE if you want to modulate with the base texture. Enable alpha blending if you want transparency.


2) You could also use D3D materials to achieve this if you wanted:

a. D3DRS_LIGHTING must be enabled

b. The diffuse part of your material controls the diffuse interaction with light sources, you instead want a constant colour so you shouldn''t be using diffuse.

c. Set the ambient part of your material to 0,0,0

d. Set the diffuse part of your material to 0,0,0

e. Set the specular part of your material to 0,0,0

f. Set the emissive part of your material to the quad colour

g. Don''t play with the COLORVERTEX or MATERIALSOURCE renderstates.

h. D3DRS_SPECULARENABLE to false

i. Fogging disabled

j. Copy the TextureStageState setup from 1) and change "TFACTOR" to "DIFFUSE"

k. You don''t need any normals for this if you''re using >= DX8.0


3) If you DID decide to use vertex colours, if the colour at each vertex was the SAME, then the whole quad would have the SAME colour, so I don''t see the problem with that apart from having to lock the vertex buffer to modify the colour. No need to set flat shading either (bilinear interpolation from the same colour to the same colour results in umm, the same colour...)


#1 IMO is simplest and is the most correct match with what you want to do (i.e. better than making the lighting engine not do any actual lighting and add on a constant colour).


reaptide: D3D cannot automatically generate normals. I''ve seen quite a few people suggest this in the past after they discovered D3DRS_NORMALIZENORMALS, however that renderstate only normalises **existing** normals, doesn''t generate them.

I think other people assume it''s possible when they''re trying to figure out how D3D (or more correctly, the hardware) is performing backface culling for vertices without normals. In reality the screen space winding order is usually used - i.e. a partial cross product in 2D rather than a full 3D cross product and subsequent normalise.


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Thanks every one for your help.
S1CA : Your method works perfectly, I''m going to use it in my engine, thanks again !

www.mpw2002.fr.st
www.mpw2002.fr.st

This topic is closed to new replies.

Advertisement