Wireframe shader

Software: Away3D 4.x

Avatar
Luca, Sr. Member
Posted: 29 July 2013 07:22 AM   Total Posts: 230

Sundays do not know what to do so ...

This shader works on Stage3D only for now smile

But i must do some investigations of the code, and make some improvements.

Another question is: On Away can i overload all the material shader program and use this ... ?

Based on this article, SolidWireframe that can be foud here:
http://developer.download.nvidia.com/SDK/10/direct3d/samples.html

 

   

Avatar
Luca, Sr. Member
Posted: 29 July 2013 07:45 AM   Total Posts: 230   [ # 1 ]

Anyway the shader program are and the function to load it are:

// shader code
[Embed(source="shader1.macro"mimeType="application/octet-stream")]
protected const ASM:Class;

/**
* Creates the shader program from the embedded .macro file
*/
private function generateMacroProg():void
{
 
var asm:String String(new ASM());

 
// split the vertex and fragment shaders
 
var codeSplit:Array = asm.split("####");
 
trace(codeSplit);

 
vertexAssembly = new AGALMiniAssembler();
 
fragmentAssembly = new AGALMiniAssembler();

 
// Compile shaders
 
vertexAssembly.assembleContext3DProgramType.VERTEXcodeSplit[0]true );
 
fragmentAssembly.assembleContext3DProgramType.FRAGMENTcodeSplit[1]true );

// Upload programs to render context
// programPair = renderContext.createProgram();
// programPair.upload( vertexAssembly.agalcode, fragmentAssembly.agalcode );
// renderContext.setProgram( programPair );

 

 

File Attachments
Stage3DWireframe.zip  (File Size: 51KB - Downloads: 248)
   

Avatar
Luca, Sr. Member
Posted: 29 July 2013 07:07 PM   Total Posts: 230   [ # 2 ]

The complete source. More code investigations are needed !!!
This code works on Stage3D only, for now, but works !

Now I can drink a nice cold beer smile !

And encoding scene data ... GamesMaker smile

 

File Attachments
Stage3DWireframe.zip  (File Size: 51KB - Downloads: 238)
   

Avatar
Luca, Sr. Member
Posted: 29 July 2013 07:54 PM   Total Posts: 230   [ # 3 ]

First code patch smile

In the Stage3DWireframe class change the color value conversion and assignment so:

// Red, Gree, Blue, Alpha
var value:uint = 0xff0000ff;
// DEC: 4278190335
// BIN: 11111111 00000000 00000000 11111111
// Bit shift right 24 = >> 24
// BIN: 11111111
// MASK BYTE: & 0xff DEC: 255
// 11111111
// &
// 11111111
// =
// 11111111

//
fc0[0] = ( value >> 24 ) & 0xff;  // red
fc0[1] = ( value >> 16 ) & 0xff;  // green
fc0[2] = ( value >> 8 ) & 0xff;  // blue
fc0[3] = value & 0xff;    // alpha
//
renderContext.setProgramConstantsFromVector( Context3DProgramType.FRAGMENT, 0, fc0, 1 );

in the shader.AGAL shader program file change the Alpha value correction so:

mul ft2.w, ft2.w, ft4   // color.w *= temp;

sorry… smile

 

   

John Brookes, Moderator
Posted: 30 July 2013 10:03 AM   Total Posts: 732   [ # 4 ]

Bit confused.
Are a0,b0 and c0 supposed to be the shortest distance from the vertice to the opposite edge?

edit
Shouldn’t a0 and c0 be the same size in that example?

 

   

Avatar
Luca, Sr. Member
Posted: 30 July 2013 11:15 AM   Total Posts: 230   [ # 5 ]

Hi john, yes in this case may be ...

I have used this reference image to figure out what distance are needed

If have a triangle rectangle with 1 angle of 90 deg and two with 45,
90 + ( 45 * 2 ) = 180 smile

Now, if i pass these tree distances to the shader program ( in ClipSpace or Screen Space ):

The vertex shader got:
mov v0, va1   // distance

va1 are passed to the fragment shader trough v0:

min ft0.x, v0.x, v0.y   // min d.x, distanceIn.x, distanceIn.y;
min ft0.x, ft0.x, v0.z   // min d.x, d.x, distanceIn.z;

the shortest distance are selected… right ?

In a real mesh i don’t know what kind of triangle i can found…
but if you have other ideas, try your code and share them with us smile

It’s ok for you ?

 

   

Avatar
Luca, Sr. Member
Posted: 30 July 2013 11:32 AM   Total Posts: 230   [ # 6 ]

For example John, becouse Geometry shader cannot be used with stage3d these distances must be calculated out of the shader program and added the vertex buffer, then passed to the shader:

// x,y,z Distance a, Distance b, Distance c
var vertexData:Vector.<Number> = Vector.<Number>([
Vertex1.x, Vertex1.y, Vertex1.z,  a0, 0, 0,
Vertex2.x, Vertex2.y, Vertex2.z,  0, b0, 0,
Vertex3.x, Vertex3.y, Vertex3.z,  0, 0, c0
]);

//
vertexes = renderContext.createVertexBuffer( vertexData.length / dataPerVertex, dataPerVertex );
//
vertexes.uploadFromVector( vertexData, 0, vertexData.length / dataPerVertex );

// va0 POSITION
renderContext.setVertexBufferAt( 0, vertexes, 0, Context3DVertexBufferFormat.FLOAT_3 );
// va1 DISTANCE
renderContext.setVertexBufferAt( 1, vertexes, 3, Context3DVertexBufferFormat.FLOAT_3 );

but AGAL have this inst, add, sub, mul, div
and in this case we have more than one free vertex constant register
( if we need to pass Matrix to the shader )

do you think adding distance to the vertex buffer are really needed ?

 

   

Avatar
Luca, Sr. Member
Posted: 30 July 2013 11:40 AM   Total Posts: 230   [ # 7 ]

and ... smile

If you like work with the geometry, then try look here:

http://79.31.103.76:8086/

wink

 

   

John Brookes, Moderator
Posted: 30 July 2013 11:56 AM   Total Posts: 732   [ # 8 ]

Well after finding the original source (volgogradetzzz) wink

The image in the pic that gives the calculation
That x is a cross product not multiplication.

Your calculating the distance wrong.

But even then passing the correct distances, the line width seems wrong.
eg add a very thick line width to a triangle and you will see they are not the same.

 

   

Avatar
Luca, Sr. Member
Posted: 30 July 2013 12:15 PM   Total Posts: 230   [ # 9 ]

va1 are passed to the fragment shader trough v0:

min ft0.x, v0.x, v0.y   // min d.x, distanceIn.x, distanceIn.y;
min ft0.x, ft0.x, v0.z   // min d.x, d.x, distanceIn.z;

means vertex by vertex ?
can i pass a Matrix to the fragment ?

//  Vertex Constant 128 vc0 – vc1 Context3D.setProgramConstants Vertex shader   Constants across the whole Context3D.drawTriangles call for vertex shader use
//  Fragment Constant 28 fc0 – fc27 Context3D.setProgramConstants Fragment shader   Constants across the whole Context3D.drawTriangles call for fragment shader use

 

   

Avatar
Luca, Sr. Member
Posted: 30 July 2013 12:28 PM   Total Posts: 230   [ # 10 ]

But cross product means:

It results in a vector which is perpendicular to both and therefore normal to the plane containing them. It has many applications in mathematics, physics, and engineering.

So a are from vertex a to da ?

 

   

Avatar
Luca, Sr. Member
Posted: 30 July 2013 12:30 PM   Total Posts: 230   [ # 11 ]

and cross product between vector lenght ...

i’m woking on ... thx

 

   


Avatar
Luca, Sr. Member
Posted: 30 July 2013 12:41 PM   Total Posts: 230   [ # 13 ]

| ( Seg b - Seg a )

| = Lenght or wrong ?

every time I look at here: raspberry

http://en.wikipedia.org/wiki/List_of_mathematical_symbols

 

   

Avatar
Luca, Sr. Member
Posted: 30 July 2013 12:49 PM   Total Posts: 230   [ # 14 ]

Oh John, you are spoken about the trace a0, b0, c0 ?

Hey you’re right, stand by…

 

   

Avatar
Luca, Sr. Member
Posted: 30 July 2013 12:53 PM   Total Posts: 230   [ # 15 ]

trace:

a2: Vector3D(400, 207.39455223083496, 0)
b2: Vector3D(492.6054382324219, 392.60544776916504, 0)
c2: Vector3D(307.3945617675781, 392.60544776916504, 0)

mmmmm, ops ...

what you think ?

 

   
   
‹‹ CrystalAtf

X

Away3D Forum

Member Login

Username

Password

Remember_me



X