Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

PyroBoy

D3DTOP_BLENDDIFFUSEALPHA ate my brain

This topic is 6125 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''m having some trouble blending textures across my geometry on a per-vertex basis... Here''s the situation: My engine uses D3D lighting and materials to define object color, then applies textures to that base color. This means the diffuse color available to the texture cascade is a result of the current lighting situation and the material of the object I''m rendering. Same goes for alpha values. This works great, but the time has come to place a texture over some geometry whose effect(blended "strength") is determined by the interpolation of individual vertex alpha values. What I want to do is to have an alpha value supplied for each vertex. This is easy enough to do with FVFs, despite the fact that I''d have to add a whole diffuse color component just to get at the alpha (I don''t need the rest of the per-vertex color, since my materials and lights are going to take care of the diffuse color situation), and blend my texture in using the D3DTOP_BLENDDIFFUSEALPHA color operation, resulting in per-vertex texture blending. But the problem with that is if I enable per-vertex color, the color values in the vertices are going to start affecting the color of the final poly, and the vertex alpha components will affect the final alpha. I don''t want it to look at the per-vertex color at all, ever, and I don''t want it to look at the per-vertex alpha except to use as a texture blending factor during my D3DTOP_BLENDDIFFUSEALPHA texture stage. I''m sure I could get this happening if I set up my code to isolate any texture stages of this type, set a truckload of render states, do the operation in its own seperate rendering pass, and set the truckload of states back to normal, but that''s gonna be slow as hell, not to mention a big pain in the ass to set up properly. I want to get this happening as part of a single multitexture pass. Any thoughts?

Share this post


Link to post
Share on other sites
Advertisement
How about bunging the alpha in per-vertex specular (assuming you''re not using specular in your lighting) and using that for the blend...


- Make your vertex format something like:

typedef struct
{
float x, y, z;
DWORD specular;
float u, v;
}
MyVertex;

- and the FVF to have SPECULAR rather than DIFFUSE.

- in your multitexture cascade, for the alpha pipe select it from D3DTA_SPECULAR then use D3DTOP_BLENDCURRENTALPHA instead of BLENDDIFFUSEALPHA.


- Alternatively use the MATERIALSOURCE states to put the diffuse component of the D3DMATERIAL into a per vertex COLOR, so you essentially have a different D3DMATERIAL for **every** vertex. The idea is the r,g,b of each material stays the same for every vertex, but you can vary the alpha value.


Issues:

- With SPECULAR alpha you may have a few issues if you try to use fogging.

- You may also have issues signalling your intent to the driver - always ValidateDevice once (but never per frame) to test the combination of states.

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

Share this post


Link to post
Share on other sites
I had considered using specular alpha, but I''m also planning on using specular light in my materials/lights. I looked into D3DTOP_BLENDCURRENTALPHA too, and that takes the alpha value from the previous texture stage as it''s factor, which will be incorrect since that''ll be determined by the light/material, and/or any textures in the pipe before it.
I''ve played around with MATERIALSOURCE as well, but that requires per-vertex color enabled, and it won''t work if I''m trying to do other stages in the same pass who need the MATERIALSOURCE set to MATERIAL and not VERTEX.

I haven''t got as far as even checking ValidateDevice, since I can''t even find a set of texture stage states that would work in *theory*. It''d be another story if I had a solution I thought should be working and it wasn''t! :-) The states all do what the docs say, there just isn''t the right combination available to do what I need...

Any OpenGL-ers out there know if this is possible in GL?

Share this post


Link to post
Share on other sites
So you''re changing your D3DMATERIAL lots per frame? if not, I don''t see any reason not to use the MATERIALSOURCE to move D3DMaterial.Diffuse to a per vertex value.

Failing that vertex shaders are the next best bet - full flexibility at decent speed (even with the PSGP).

More unusual idea: make a 1D 1x256 texture in an alpha format with a smooth gradient of alpha values ranging from 0 to 255. Add a 1D coordinate to the vertex format and pull in the texture alpha in a texture stage (assuming you have one available). Tradeoff - lose a texture stage, gain floating point alpha control.

I doubt OpenGL would help any either (apart from maybe emulating it in software) - for T&L hardware it''s just the way the silicon works - 2 colour iterators per polygon and n texture units - if you want an iterated alpha value with per vertex control, it''s got to be in one of those sources (unless you''re after a card specific implementation, in which case one of the vendor extensions may do it).

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

Share this post


Link to post
Share on other sites
Yeah, every object being rendered has it''s own material. It''s set a lot throughout the frame.
I suppose vertex shaders would do the trick... I''m reluctant to use them however, since I''d like this to run on crappy hardware too.
a 1D texture is a neat idea too, but I''m really trying to get this done in a single stage...

Share this post


Link to post
Share on other sites

  • 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!