View Full Version : Flexible vertex formats
I'm currently creating a 2d engine using dx8.1 d3d and Visual basic. Basically I'm bringing the old overhead 8 way scrolling classics of the 80s up to date. Having opted to use D3D for lighting effects etc I'm now running into a few problems that I'm not sure how to approach. The graphical part of the engine is pretty much split between two areas or vertex buffers to be more precise. The first buffer is used to store the visible tiles of the map. I render this and then utilise a 2nd buffer to render sprites within the scene. Each frame I load the relevant buffers with the pre-computed verts and simply use .drawprimitive to blast them to the screen. I've since added ray tracing light calculations do determine which tiles are lit and I’m about to add player 360 degree view ray tracing to determine which of those you can actually see. This enables me to create walled and roomed sections within the map. However, imagine the scenario of travelling down a corridor. The only tiles visible are those along the corridors walls. Approaching a junction however would then reveal the tiles viewable from the junction. Continuing past the junction however would then mean you can no longer actually still see the tiles revealed when standing next to the junction. As opposed to suddenly not render a tile and cause what I think would look like a chequered and quite crude effect I wanted to simply alpha blend (fade) the now no longer visible tiles to a varying degree based on a decaying value. This should hopefully create a smooth transition between seeing and not seeing tiles. Unfortunately this would appear to require me to either render each tile separately so I can set a varying material value or use pre-calculated textures that simulate a pre alpha-blended state. I didn't really like the idea of using pre-calculated textures as I'd ultimately like to have a “tron/matrix” style map blueprint background which is only visible when the tiles have decayed completely. I'm hoping I've basically overlooked a method of including the alpha blending properties within the FVF and as such would then be able to apply differing values within one vertex buffer?
Any help or feedback would be gratefully appreciated?
Thanks in advance and apologies for the long post.
: )
darkblu
09-May-2003, 16:11
not really sure on the requirements and goals of your project, but couldn't you drop lighting altogether and assign whatever ARGB values you want to the each vertex?
Set diffuse material source to color1.
Put a diffuse color in every vertex with the RGB component being white and alpha component being the per-vertex blend value.
If you worry about updating your entire vertex buffer use a separate buffer for diffuse colors only and use two streams when rendering.
IF your card support multi streams.
IF your card support multi streams.
Which card has HW T&L, without multiple streams support?
not really sure on the requirements and goals of your project, but couldn't you drop lighting altogether and assign whatever ARGB values you want to the each vertex?
Well the lighting really adds to the feeling of the game so I'd rather keep it. I could use the 9700's pixel shading abilities but MS in their wisdom dropped VB support in DX9 :( I considered switching to .net as well but I'd rather learn the 3D basics using a known quantity i.e. VB
Set diffuse material source to color1.
Put a diffuse color in every vertex with the RGB component being white and alpha component being the per-vertex blend value.
If you worry about updating your entire vertex buffer use a separate buffer for diffuse colors only and use two streams when rendering.
Could you please elaborate on this idae a little further?
IF your card support multi streams.
Which card has HW T&L, without multiple streams support?
not sure but I think I reember my original Radeon support only 1 stream.
not sure but I think I reember my original Radeon support only 1 stream.
It supports up to 8 streams.
Really ?
Really, really ?
(Shrek)
uh uh... maybe it depended on drivers releases... dunno why I did remember only 1... bah...
I VB.net really different from previous VB versions that you can't use it? (I really have no idea about VB.) Besides, you should be able to use shader even in DX8.1. Just up to VS1.1 and PS1.4, but this should be enough.
Assuming you don't have a lot of geometry, I'd even suggest using vertex shaders in software, on hardware that doesn't support it. It should give you the flexibility you need.
Guys,
Having switched to try and use a diffuse colour setting within my vertex buffer I now seem to lose the texture and end up with a simple colour square? Here's the basics
My FVF
cFVFb = D3DFVF_XYZ Or D3DFVF_NORMAL Or D3DFVF_TEX1 Or D3DFVF_DIFFUSE
My structure for the verts
Public Type TLVERTEXB
X As Single
Y As Single
Z As Single
nx As Single
ny As Single
nz As Single
tu As Single
tv As Single
diffuse As Long
End Type
Note: I've tried defining the diffuse colour property as a D3DCOLORVALUE
also but that didn't work either?
My relating render states
.SetRenderState D3DRS_ALPHABLENDENABLE, 1
.SetRenderState D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL
Note: I've tried using D3DMCS_COLOR1
but all have the same problem, I appear to loose the texture and end up with a completely dark or greenish tile?
Could someone please confirm that I've understood this correctly? By utilising a diffuse colour per vertex I can still render the texture but the lighting properties will utilise the current material settings and diffuse colour setting of the vertex. In order to do this I should set the above and set the diffuse colour to white? BTW, with an alpha component too just what is white?
Also, I can render the tiles using a per vertex alpha setting all in a single drawprimitive call?
If I'm on the correct track can someone please suggest a suitable way forward. I still think it may me a combination of an incorrect vertex structure and the wrong use of DIFFUSEMATERIALSOURCE although I have experimented with that and tried Material and Color1.
Please can some one help as I've spent the last two evenings going around in circles. I either see a completely black screen i.e. no map tiles although my sprites using the old vertex structure still render fine? OR I end up with a greenish map with no texture details?
Thanks in advance,
darkblu
12-May-2003, 14:56
Well the lighting really adds to the feeling of the game so I'd rather keep it. I could use the 9700's pixel shading abilities but MS in their wisdom dropped VB support in DX9 I considered switching to .net as well but I'd rather learn the 3D basics using a known quantity i.e. VB
ok, so you actually use the API lighting functionality. let's take it on from here.
Guys,
Having switched to try and use a diffuse colour setting within my vertex buffer I now seem to lose the texture and end up with a simple colour square? Here's the basics
My FVF
cFVFb = D3DFVF_XYZ Or D3DFVF_NORMAL Or D3DFVF_TEX1 Or D3DFVF_DIFFUSE
so far so good.
My structure for the verts
Public Type TLVERTEXB
X As Single
Y As Single
Z As Single
nx As Single
ny As Single
nz As Single
tu As Single
tv As Single
diffuse As Long
End Type
Note: I've tried defining the diffuse colour property as a D3DCOLORVALUE
also but that didn't work either?
D3D uses R:8 G:8 B:8 A:8 when specifying a color component to a vertex. D3DCOLORVALUE (which has the channels as floats) is used elsewhere (e.g. in the render state)
oops, re your vertex structure - put the diffuse *before* the texcoord set. FVF is flexible but not that much as to know which component comes after which, so it expects a particticular order, namely:
position
rhw
blending weight(s)
normal
diffuse (color1)
specular (color2)
texcoord set(s)
My relating render states
.SetRenderState D3DRS_ALPHABLENDENABLE, 1
.SetRenderState D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL
Note: I've tried using D3DMCS_COLOR1
yep, as Hyp-x noted, that's what you'll be using.
but all have the same problem, I appear to loose the texture and end up with a completely dark or greenish tile?
let's reiterate on the render state once again (given that you've got your FVF *and* texturing setup correct). you'd need to:
set D3DRS_LIGHTING to TRUE
set D3DRS_COLORVERTEX to TRUE
set D3DRS_DIFFUSEMATERIALSOURCE to D3DMCS_COLOR1
set D3DRS_SPECULARMATERIALSOURCE to D3DMCS_MATERIAL
set D3DRS_AMBIENTMATERIALSOURCE to D3DMCS_MATERIAL
set D3DRS_EMISSIVEMATERIALSOURCE to D3DMCS_MATERIAL
set D3DRS_ALPHABLENDENABLE to TRUE
set D3DRS_SRCBLEND to D3DBLEND_SRCALPHA
set D3DRS_DESTBLEND to D3DBLEND_INVSRCALPHA
Could someone please confirm that I've understood this correctly? By utilising a diffuse colour per vertex I can still render the texture but the lighting properties will utilise the current material settings and diffuse colour setting of the vertex. In order to do this I should set the above and set the diffuse colour to white? BTW, with an alpha component too just what is white?
white is (in C notation): (DWORD) 0xffffffzz (remember, R:8 G:8 B:8 A:8), where zz is your arbitrary alpha (a byte). using white you'd preserve the color coming from the texturing when doing a MODULATE stage blending op.
Also, I can render the tiles using a per vertex alpha setting all in a single drawprimitive call?
absolutely.
Well the lighting really adds to the feeling of the game so I'd rather keep it. I could use the 9700's pixel shading abilities but MS in their wisdom dropped VB support in DX9 I considered switching to .net as well but I'd rather learn the 3D basics using a known quantity i.e. VB
ok, so you actually use the API lighting functionality. let's take it on from here.
Guys,
Having switched to try and use a diffuse colour setting within my vertex buffer I now seem to lose the texture and end up with a simple colour square? Here's the basics
My FVF
cFVFb = D3DFVF_XYZ Or D3DFVF_NORMAL Or D3DFVF_TEX1 Or D3DFVF_DIFFUSE
so far so good.
My structure for the verts
Public Type TLVERTEXB
X As Single
Y As Single
Z As Single
nx As Single
ny As Single
nz As Single
tu As Single
tv As Single
diffuse As Long
End Type
Note: I've tried defining the diffuse colour property as a D3DCOLORVALUE
also but that didn't work either?
D3D uses R:8 G:8 B:8 A:8 when specifying a color component to a vertex. D3DCOLORVALUE (which has the channels as floats) is used elsewhere (e.g. in the render state)
oops, re your vertex structure - put the diffuse *before* the texcoord set. FVF is flexible but not that much as to know which component comes after which, so it expects a particticular order, namely:
position
rhw
blending weight(s)
normal
diffuse (color1)
specular (color2)
texcoord set(s)
My relating render states
.SetRenderState D3DRS_ALPHABLENDENABLE, 1
.SetRenderState D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL
Note: I've tried using D3DMCS_COLOR1
yep, as Hyp-x noted, that's what you'll be using.
but all have the same problem, I appear to loose the texture and end up with a completely dark or greenish tile?
let's reiterate on the render state once again (given that you've got your FVF *and* texturing setup correct). you'd need to:
set D3DRS_LIGHTING to TRUE
set D3DRS_COLORVERTEX to TRUE
set D3DRS_DIFFUSEMATERIALSOURCE to D3DMCS_COLOR1
set D3DRS_SPECULARMATERIALSOURCE to D3DMCS_MATERIAL
set D3DRS_AMBIENTMATERIALSOURCE to D3DMCS_MATERIAL
set D3DRS_EMISSIVEMATERIALSOURCE to D3DMCS_MATERIAL
set D3DRS_ALPHABLENDENABLE to TRUE
set D3DRS_SRCBLEND to D3DBLEND_SRCALPHA
set D3DRS_DESTBLEND to D3DBLEND_INVSRCALPHA
Could someone please confirm that I've understood this correctly? By utilising a diffuse colour per vertex I can still render the texture but the lighting properties will utilise the current material settings and diffuse colour setting of the vertex. In order to do this I should set the above and set the diffuse colour to white? BTW, with an alpha component too just what is white?
white is (in C notation): (DWORD) 0xffffffzz (remember, R:8 G:8 B:8 A:8), where zz is your arbitrary alpha (a byte). using white you'd preserve the color coming from the texturing when doing a MODULATE stage blending op.
Also, I can render the tiles using a per vertex alpha setting all in a single drawprimitive call?
absolutely.
Thank you very much, I will go thrugh this tonight, I had actually tried repositioning the diffuse within the UDT and did notice a different set of results although none worked. I can see a couple of renderstates I'm missing although I would have expected the defaults to have aligned anyway?
Actually this one might be the key - set D3DRS_COLORVERTEX to TRUE
Thanks once again for your time and input, I'll play some more and hopefully get past this stall!
:)
OpenGL is so much more user friendly...
(Need I say I express my opinion ?)
OpenGL is so much more user friendly...
I didn't know it has a VB wrapper.
BTW, make sure you're setting the right texture stage states.
Well having had a little time to code having upgraded to my P4 2.8 hyperthreadhing machine :) (sorry couldn't resist) I've almost got it working perfectly.
I'm just having trouble with VBs signed long values when trying to set the alpha component. It's more often than not I end up with a green tinge as opposed to faded tile?
Anyway, just wanted to thank you guys for taking the time and helping me out.
Thanks again although I'm sure I'll come up with many more newbie D3D questions.
:)
vBulletin® v3.8.6, Copyright ©2000-2013, Jelsoft Enterprises Ltd.