How to project shadows using a vertex shader

Subscribe to How to project shadows using a vertex shader 2 posts

avatar for qwerber qwerber 4717 posts
Flag Post

This is the basic logic, you upload 2 sets of 2 points, start and end. Along with each set you upload a different “Bool” value that is represented with 1 or 0. Multiply the projected normal but the Bool. 1 will project a ray, 0 will remain at original shadow caster vertex.

here is some code I found from this link: http://ryanspeets.com/flash/how-i-did-my-2d-shadow-rendering-with-stage3d-tutorial/

alias vc0.xy, CONST_0( 0, 1 )
alias vc0.z, shadowDistance
alias va0, vertexPosition
alias vc1, lightPosition

vt0.xy = vertexPosition.xy - lightPosition.xy
vt0.xy *= vertexPosition.z
vt0.xy *= shadowDistance
vt1.xy = vertexPosition.xy + vt0.xy
vt1.z = 0
vt1.w = 1
op = mul4x4(vt1, vc2)

this is AGALMacro, so treat it like pseudocode if you are using MiniAssembler or HXSL.

Hope you guys can make something out of it, enjoy!

 
avatar for alecz127 alecz127 817 posts
Flag Post

thats effing cool qwerber!
I DLed the source so I could play the app. Its really sweet and really easy to imagine it fitting into a zombie||nuclear apoc||haunted house game.

I think I’m going to try to combine it with this collision detection I made so that the light is emanating from a flash light beam, and it knows when/when it can’t go around corners and such.