shadow mesh vertex alpha probem

Blitz3D Forums/Blitz3D Programming/shadow mesh vertex alpha probem

Kalisme(Posted 2006) [#1]
Hi all... I'm having a problem with my little shadow engine I'm doing... Here is my conundrem:
I need the shadow meshes to fade as they go out of distance.... so I figure that means they must use entityfx mesh, 2+32
And I'm using the vertexcolor command, changing the alpha with the Alpha# part of the command...
And I ot it working with normal meshes...
But I have to use entityblend mode 2 and I'm using textureblend mode 5... and entityblend mode 2 (what I need to hide the white backgrounds of my shadow textures) seems to stop the vertex alpha from working...
I'm very confused... can someone help me?
Thank you for reading,
-Kev


jfk EO-11110(Posted 2006) [#2]
Did you try to use entityAutofade instead?


Kalisme(Posted 2006) [#3]
dosn't that just fade depending on it's distance from the camera? and it's not per vertex... I don't think...

(I could be wrong... I haven't used the command much)
When I said I want the shadow mesh to fade as it goes out of distance, I meant I want it to fade as it goes out of distance from the light source... and it really has to be per vertex because it copys the required vertecies from the meshes it covers... so the vertecies can be really far apart... so each verticies distance from the light source can be very diffarent...

But thank you very much Jfk... I really like your work :D


jfk EO-11110(Posted 2006) [#4]
ok I see. There are some problems with some cards when mixing alpha and additional blending. see versions.txt about the reimplementation of the feature to mix them at all.

It doesn't matter if it's vertex alpha, texture alpha, entityalpha, basicly it's alpha with all its troubles (z-sort, the mentioned mixing problem)

I think you seriously need to use an other shadow blend mode. IMHO there's no need for blendmode 2. I suggest to do it this way: Blendmode default, 1(alpha). Use a texture that is completely black on the RGB channel and has the shape of the shadow tored in the alpha channel only. You may use Photoshop to do such a shadow. Save as TGA 32 Bit.

Alternatilvely do it this way: (Assuming your shadow texture is dark shadow on bright "background")

tex=loadtexture("shade.bmp")
setbuffer texturebuffer(tex)
lockbuffer()
for j=0 to textureheight(tex)-1
 for i=0 to texturewidth(tex)-1
  rgb=readpixelfast(i,j) and $FFFFFF
  grey=int (255.0-(((rgb shr 16)+((rgb shr 8) and $FF) + (rgb and $FF))/3.0)) shl 24
  writepixelfast i,j,grey
 next
next
unlockbuffer()


Not sure if it works, just typed it. What it does: inverting the brightness, so black will be white and white will be black, then it will shift the brightness to the alpha channel and paint the RGB channels black.

when you use med. grey on white, it should look about nice.


jfk EO-11110(Posted 2006) [#5]
Ehrm, I just realize you need to update the textures dynamicly (do you?) so using readpixelfast like this would be too slow.

I take it you are rendering the shadow caster from the lights viewpoint, with the background white and the caster black and this forces you to use blendmode 2? In this case I'd suggest to simply swap the colors and use mode 1. EntityColor m,0,0,0 won't work for the shadow caster, but you may paintmesh it with a brush that is made of a white texture with fx 1 etc. Then use the black color for the background instead.

All you need to do is to store the old brush(es), using GetSurfaceBrush(mesh). Although the command is creating a copy of the original brush, I think the original brush will be removed as soon as you are painting the meshes with an other brush. So don't worry too much about ram.