Custom shader. Activate vertex buffer in index 1

Software: Away3D 4.x

nikitablack, Newbie
Posted: 15 November 2013 05:00 PM   Total Posts: 15

Hello. I’m following Writing Custom Materials tutorials. This is code fragment:

m44 opva0vc0
renderable
.activateVertexBuffer(0stage3DProxy); 

This works fine. Now I change code a little:

m44 opva1vc0
renderable
.activateVertexBuffer(1stage3DProxy); 

And my screen is empty. Why?

P.S.: This construction works

m44 opva1vc0
renderable
.activateVertexBuffer(0stage3DProxy);
renderable.activateVertexBuffer(1stage3DProxy); 
   

Avatar
SharpEdge, Member
Posted: 19 November 2013 09:17 AM   Total Posts: 94   [ # 1 ]

Maybe because you should activate vertex buffer sequentially

   

nikitablack, Newbie
Posted: 19 November 2013 11:23 AM   Total Posts: 15   [ # 2 ]

What does it mean - sequentially? I have one buffer and just interesting - why I can’t assign it to 2nd register (va1)?

   

Avatar
SharpEdge, Member
Posted: 19 November 2013 11:30 AM   Total Posts: 94   [ # 3 ]

i think it’s like an array, why you should use array[1] instead of array[0] ?
What you should do is activate VertexBuffers sequentially.
If you need only one VertexBuffer use the 0.

I’m not sure i’ve been clear.

   

nikitablack, Newbie
Posted: 19 November 2013 11:36 AM   Total Posts: 15   [ # 4 ]

Yeah, I understand you, thank you. I’m just curious - in activateVertexBuffer I need to specify register index. In AGAL I need to specify register too. In raw application (without any 3D engines) it’s absolutely legal to assign stream to, say 5th index and all works fine. In away3D it doesn’t work. So why do it needed to specify these index in activateVertexBuffer then?

   

Avatar
SharpEdge, Member
Posted: 19 November 2013 11:47 AM   Total Posts: 94   [ # 5 ]

Oh i’m not sure of what i said, i’m just following a logical reasoning.
I’ll check.

   

Avatar
SharpEdge, Member
Posted: 19 November 2013 12:03 PM   Total Posts: 94   [ # 6 ]

Ok i’ve searched a little bit and that’s what i’ve found:
I followed the activateVertexBuffer method and i’ve found that multiple classes implements it (IRenderable), i choose SubGeometry for example and that’s what i’ve found:

public function activateVertexBuffer(index:intstage3DProxy:Stage3DProxy):void
                {
                        
var contextIndex:int stage3DProxy._stage3DIndex;
                        var 
context:Context3D stage3DProxy._context3D;
                        if (!
_vertexBuffer[contextIndex] || _vertexBufferContext[contextIndex] != context{
                                _vertexBuffer[contextIndex] 
context.createVertexBuffer(_numVertices3);
                                
_vertexBufferContext[contextIndex] context;
                                
_verticesInvalid[contextIndex] true;
                        
}
                        
if (_verticesInvalid[contextIndex]{
                                _vertexBuffer[contextIndex]
.uploadFromVector(_vertexData0_numVertices);
                                
_verticesInvalid[contextIndex] false;
                        
}
                        
                        context
.setVertexBufferAt(index_vertexBuffer[contextIndex]0Context3DVertexBufferFormat.FLOAT_3);
                

It seems that it doesn’t take in account the index passed but asks directly to stage3dProxy what’s the next free index.
That’s why if you use index 1 you don’t see anything, because it’s activating the first buffer free ( in this case the 0)

   

nikitablack, Newbie
Posted: 19 November 2013 12:50 PM   Total Posts: 15   [ # 7 ]

Yeah, I saw this code. Actually, it takes passed index into account (index:int field). All things happens in MaterialPassBase.updateProgram method. I don’t know why, but away3D adds some shader code. My vertex string was

m44 op, va1, vc0

and after some inside magic it becomes

mov vt0, va0
m44 op, va1, vc0

As you can see - now shader contains va0. But since it’s empty, geometry not drawn.

P.S.: actually I forgot to enable context.enableErrorChecking. That’s why It was difficult to realize real propblem.

   

Avatar
SharpEdge, Member
Posted: 19 November 2013 01:16 PM   Total Posts: 94   [ # 8 ]

ehm yes the method receive the index but never use it….if you look carefully you’ll see that index it’s not used

   

nikitablack, Newbie
Posted: 19 November 2013 01:30 PM   Total Posts: 15   [ # 9 ]

No no. It used in

context.setVertexBufferAt(index, _vertexBuffer[contextIndex], 0, Context3DVertexBufferFormat.FLOAT_3);

My problem is solved (actually, not solved, but now it’s clear there’s it from) - it’s all about autogenerated shader in MaterialPassBase.updateProgram()

   

Avatar
SharpEdge, Member
Posted: 19 November 2013 01:35 PM   Total Posts: 94   [ # 10 ]

oh sh*t i’ve missed it!!!

   

Avatar
SharpEdge, Member
Posted: 19 November 2013 01:41 PM   Total Posts: 94   [ # 11 ]

Ok i’m looking at updateprogram, yes it adds code for animation and UVanimation:

vertexCode animatorCode UVAnimatorCode vertexCode

vertexCode it’s your original code.

   

Avatar
SharpEdge, Member
Posted: 19 November 2013 01:44 PM   Total Posts: 94   [ # 12 ]

found!!!!!
if you don’t have animationsets assigned it uses the default vector that’s animatableattributes, it’s initialized like this:

protected var _animatableAttributes:Vector.<String> = Vector.<String>["va0"]);
protected var 
_animationTargetRegisters:Vector.<String> = Vector.<String>(["vt0"]); 

this is at the top of MaterialPassBase

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X