Accessing ClipSpace Results from Vertex Code in Shader Method

Software: Away3D 4.x

LunarRaid, Newbie
Posted: 31 December 2012 07:45 PM   Total Posts: 3

Hey guys,

I’ve been crawling the net trying to find the answer to this problem, and only found one other thread that I’ve noticed even touches on vertex shaders. What I am attempting to do is apply a vertex translation along the Y axis depending on the distance from the camera (along the lines of this). To do this, I need to know the position of each vertex in ClipSpace. How do I access this from a shader method? From what I can see (and what the old forum thread confirmed), it seems that this value is multiplied directly into the output position register.

Is there any way to pull this off using a shader method, or do I need to create a new screen pass / material?  I really wish there was an option to simply append projection code to a screen pass, unless I am missing it somewhere.

   

LunarRaid, Newbie
Posted: 25 January 2013 06:28 PM   Total Posts: 3   [ # 1 ]

...anyone?

   

_kihu, Jr. Member
Posted: 28 January 2013 08:50 AM   Total Posts: 43   [ # 2 ]

Ok, I’m not sure if this is correct, but consider this example:
http://blog.norbz.net/2012/01/stage3d-agal-from-scratch-part-iii-hello-triangle/

Vertex shader looks like this:

mov opva0
mov v0
va1 

In the example va0 holds vertex position and va1 holds it’s color (it may be different in your program, depending on how you’ve uploaded vertex buffers).This means vertex position is moved to output point (op) and vertex color is moved to varying register v0. Now, I think you can pass positions into another varying register like this:

mov opva0
mov v0
va1
mov v1
va0 

Then you should be able to access v1 in your fragment shader, available for manipulation etc smile

If your effect is post-processing, you might have to use a depth buffer and then recalculate your clipSpace (viewSpace) positions manually inside the fragment shader.

edit:
I forgot: to have positions converted to clipSpace you need to multiply them in the vertex shader by projectionMatrix (http://away3d.com/livedocs/away3d/4.0/away3d/cameras/lenses/LensBase.html#matrix)
Upload this matrix as vertex shader constants and perform:

m44 vt0 v0vc0 

Where vc0 is first row of uploaded matrix, v0 is vertex position and vt0 is the temporary register you can manipulate later. Remember the matrix is 4 rows so it will fill vc0, vc1, vc2 and vc3.

   

LunarRaid, Newbie
Posted: 28 January 2013 07:13 PM   Total Posts: 3   [ # 3 ]

That’s just the thing though. If I were handling the buffers and all that myself, this would be easy. The problem is that Away3D is managing them and I am not the one setting them, so I need to get the information from Away3D’s managers, and I am uncertain of how to do this. My shader code will need to be the final vertex position processing step, appended the the end of Away3D’s rendering AGAL code.

   

_kihu, Jr. Member
Posted: 29 January 2013 08:27 AM   Total Posts: 43   [ # 4 ]

Oh. Yeah, you probably gonna have to alter Away3d classes. I’m a little lost myself in all of the dependencies in Away3D rendering process. It’s a pity cause while Flare3D and Minko provides tools to create custom shaders, Away3D requires digging deep into the source code.

I’d start looking in View3D->render method. Should you find solution to your problem, please share it, cause as you know, there’s little info on this topic on the web.

Good luck:)

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X