Vertex Shaders Issues

Software: Away3D 4.x

Andrey, Newbie
Posted: 08 August 2011 10:24 PM   Total Posts: 5

Hello! Just started a new branch of my project to migrate to Away3D 4. And I faced some issues:
First of all, I have an object (Mesh) and I want to apply a transformation matrix to all of it’s vertices (on GPU). So I did the following: extended ShadingMethodBase and created my own simple shading method that should just affect vertex positions. Here is it’s AGAL code:

m44 <temp reg>, va0, <my matrix reg>
m44 op, <temp reg>, vc0

It’s pretty simple, but there is a problem: if my transformation matrix contains translation, and I move the object via object.x and object.y (my matrix stays the same), my object just dissapears at some point. If I don’t multiply vertex positons with my matrix, everything is fine. I’ve already checked camera.lens and so on, but no luck yet. Another important thing: I looked through the source of AGALProgram3DCache and found out that it already adds clipspace transformation (in the very beggining of each shader)... Why? If I want to compute vertex positions on GPU I may want to calculate resulting positions myself, without any dead code (like in my case). So maybe I’m missing something, but I haven’t found any better way to write vertex shaders (my project requires some heavy computations which better should be ran on GPU, it’s quite a common case for effects like water, particles, skeleton things an so on, I suppose). Any help or advise would be appreciated smile Thanks in advance smile

   

Avatar
Alexander Seifert, Moderator
Posted: 09 August 2011 07:19 PM   Total Posts: 129   [ # 1 ]

If i am not being completely drunk here, Broomstick does all transformation matrix calculations with shaders already. So, whenever you use any of the position / scale / rotation properties of a Object3D, it ultimately ends up in a Matrix3D being uploaded to the vertex shader.

I’m on my cell phone right now so can’t double check my statements here.
Cheers!
Alex

 Signature 
signature_image

http://www.deltastrike.org

   

Andrey, Newbie
Posted: 09 August 2011 08:13 PM   Total Posts: 5   [ # 2 ]

Yeah, I know, but thanks for the answer! smile I suppose it’s stored in vc0. But it seems like Away3D puts multiplication by vc0 to the very begining of the shader (before user’s vertex shader code, so I have to overwrite op register: apply my transformation to vertex buffer and after that multiply by vc0). It’s just a little bit strange) Also I noticed, that m44 gives visually slightly different results than action script Matrix3D.transformVector (I already know about transposed flag, it is set to true). Unfortunatelly I don’t know how to debug shader code when running from a browser, so I can not compare the results literally. Maybe I’m just doing something wrong, but I can’t understand what exactly smile

   

Andrey, Newbie
Posted: 10 August 2011 01:35 AM   Total Posts: 5   [ # 3 ]

Finally found the bug, it was in my skinning code red face Away3D works pretty well, but still writing custom shaders is quite tricky smile

   

Avatar
Alexander Seifert, Moderator
Posted: 10 August 2011 07:46 AM   Total Posts: 129   [ # 4 ]

cool smile that’s cool =)

 Signature 
signature_image

http://www.deltastrike.org

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X