Shaders

Software: Other

Avatar
Luca, Sr. Member
Posted: 27 May 2013 08:31 AM   Total Posts: 230

Solid wireframe ( AGALMacroAssembler ):

Vertex shader:
//attributes
alias va0, pos;
alias va1, distance;

//constants
alias vc0, TRANSFORM_MATRIX;

//temps

//varyings
alias v0, distanceOut; //for vertex a Vector.([da, 0, 0])

//shader
op =  mul4x4(pos, TRANSFORM_MATRIX);
distanceOut = distance;


Fragment shader:
//constants
alias fc0, LINE_COLOR;
alias fc1.x, ONE;
alias fc1.y, MINUS_TWO;
alias fc1.z, TWO;
alias fc1.w, POW;
alias fc2.x, THICKNESS_MINUS_ONE;
alias fc2.y, THICKNESS_PLUS_ONE;

//textures

//temps
alias ft0, d; //correct fragment distance
alias ft1, oneOrZero;
alias ft2, color;
alias ft3, smoothValue;
alias ft4, temp;

//varyings
alias v0, distanceIn;

//shader
color = LINE_COLOR;

min d.x, distanceIn.x, distanceIn.y;
min d.x, d.x, distanceIn.z;

//get smooth value - it’s a value in range [+1] -> [~0] on 2px interval
temp = THICKNESS_PLUS_ONE - d.x;
temp = TWO - temp;
pow temp temp POW;
temp *= MINUS_TWO;
exp smoothValue temp;

//if fragment distance [d] < [thickess - 1], then ‘temp’ set to 1 otherwise set to smooth value
slt oneOrZero d.x THICKNESS_MINUS_ONE;
temp = ONE * oneOrZero;  - oneOrZero;
smoothValue *= oneOrZero;
temp += smoothValue;

color.w *= temp;

//if fragment distance greater then max allowed thickness, then discard it (set alpha to 0)
slt oneOrZero d.x THICKNESS_PLUS_ONE;

temp = oneOrZero - ONE;

//if fragment outside line thicknes + smooth range - discard it
kill temp.x;

oc = color;

   

Avatar
Luca, Sr. Member
Posted: 27 May 2013 08:53 AM   Total Posts: 230   [ # 1 ]

this link are “http://wonderfl.net/tag/agal,” including comma !

http://wonderfl.net/tag/agal,

and

http://wonderfl.net/tag/agal

 

   

beers, Member
Posted: 27 May 2013 03:51 PM   Total Posts: 53   [ # 2 ]

Has anyone got this wireframe agal code to work with away3d 4.x??

 

   

Avatar
Luca, Sr. Member
Posted: 27 May 2013 06:24 PM   Total Posts: 230   [ # 3 ]

I’m working on… but not only on shaders, so:

import away3d.Away3D;
 
import away3d.arcane;
 
import away3d.cameras.Camera3D;
 
import away3d.core.base.IRenderable;
 
import away3d.core.managers.Stage3DProxy;
 
import away3d.errors.*;
 
import away3d.library.assets.*;
 
import away3d.materials.compilation.*;
 
import away3d.textures.CubeTextureBase;
 
import away3d.textures.Texture2DBase;


 use namespace 
arcane;

 
 
/**
  * BasicAmbientMethod provides the default shading method for uniform ambient lighting.
  * 
  * BasicDiffuseMethod provides the default shading method for Lambert (dot3) diffuse lighting.
  * 
  * BasicNormalMethod
  * 
  * BasicSpecularMethod provides the default shading method for Blinn-Phong specular highlights.
  */
 
 
 /**
  * EffectMethodBase forms an abstract base class for shader methods that are not dependent on light sources,
  * and are in essence post-process effects on the materials.
  * 
  * LightingMethodBase provides an abstract base method for shading methods that uses lights.
  * Used for diffuse and specular shaders only.
  */
 
 
import flash.display3D.VertexBuffer3D;
 
import flash.geom.ColorTransform;
 
import mx.containers.VBox;


 
 
/* http://winxalex.blogspot.it/2012/11/glsl-to-agal-convertor-tool.html */
 
 
 
 
public class ShaderEditorClass extends VBox
 {
  
  
var vb:VertexBuffer3D = new VertexBuffer3D();
  
  public function 
ShaderEditorClass()
  
{
   
   
// vb.uploadFromByteArray();
   // ColorTransformMethod.as
   
   // ShaderCompiler
   // SuperShaderCompiler
   // ShaderRegisterCache
   // ShaderRegisterData
   // ShaderRegisterElement
   
   // FROM EFFECT METHOD BASE
//   /**
//    * Get the fragment shader code that should be added after all per-light code. Usually composits everything to the target register.
//    * @param regCache The register cache used during the compilation.
//    * @private
//    */
//   arcane function getFragmentCode(vo : MethodVO, regCache : ShaderRegisterCache, targetReg : ShaderRegisterElement) : String
//   {
//    throw new AbstractMethodError();
//    vo=vo;regCache=regCache;targetReg=targetReg;
//    return "";
//   }
   
   // ShaderMethodSetup
   
   /**
    * ShadingMethodBase provides an abstract base method for shading methods, used by DefaultScreenPass
    * to compile the final shading program.
    */
   // ShadingMethodBase
   
   // ShadowMapMethodBase
   // SimpleShadowMapMethodBase
   
   // MethodVO
   // MethodVOSet
   
   // var Method:MethodVO = new MethodVO();
   
   // Method.fragmentConstantsIndex
   // Method.fragmentData

   // NamedAssetBase -> MaterialBase -> SinglePassMaterial -> ColorMaterial
   
   //
   //private var ModelVertexAnimationSet:VertexAnimationSet;
   //
   //private var ModelSkeletonAnimator:SkeletonAnimator;
   //
   //private var ModelSkeletonAnimationSet:SkeletonAnimationSet;
   
   // AnimationSetBase -> VertexAnimationSet
   
  
}
  
  
// FROM EnvironmentMapMethod
  
//  arcane override function activate(vo : MethodVO, stage3DProxy : Stage3DProxy) : void
//  {
//   var context : Context3D = stage3DProxy._context3D;
//   vo.fragmentData[vo.fragmentConstantsIndex] = _alpha;
//   context.setTextureAt(vo.texturesIndex, _cubeTexture.getTextureForStage3D(stage3DProxy));
//   if (_mask)
//    context.setTextureAt(vo.texturesIndex+1, _mask.getTextureForStage3D(stage3DProxy));
//  }
//  
//  arcane override function getFragmentCode(vo : MethodVO, regCache : ShaderRegisterCache, targetReg : ShaderRegisterElement) : String
//  {
//   var dataRegister : ShaderRegisterElement = regCache.getFreeFragmentConstant();
//   var temp : ShaderRegisterElement = regCache.getFreeFragmentVectorTemp();
//   var code : String = "";
//   var cubeMapReg : ShaderRegisterElement = regCache.getFreeTextureReg();
//   vo.texturesIndex = cubeMapReg.index;
//   vo.fragmentConstantsIndex = dataRegister.index*4;
//   
//   regCache.addFragmentTempUsages(temp, 1);
//   var temp2 : ShaderRegisterElement = regCache.getFreeFragmentVectorTemp();
//   
//   // r = I - 2(I.N)*N
//   code += "dp3 " + temp + ".w, " + _sharedRegisters.viewDirFragment + ".xyz, " + _sharedRegisters.normalFragment + ".xyz  \n" +
//    "add " + temp + ".w, " + temp + ".w, " + temp + ".w           \n" +
//    "mul " + temp + ".xyz, " + _sharedRegisters.normalFragment + ".xyz, " + temp + ".w      \n" +
//    "sub " + temp + ".xyz, " + temp + ".xyz, " + _sharedRegisters.viewDirFragment + ".xyz     \n" +
//    getTexCubeSampleCode(vo, temp, cubeMapReg, _cubeTexture, temp) +
//    "sub " + temp2 + ".w, " + temp + ".w, fc0.x         \n" +                // -.5
//    "kil " + temp2 + ".w\n" + // used for real time reflection mapping - if alpha is not 1 (mock texture) kil output
//    "sub " + temp + ", " + temp + ", " + targetReg + "           \n";
//   
//   if (_mask) {
//    var maskReg : ShaderRegisterElement = regCache.getFreeTextureReg();
//    code += getTex2DSampleCode(vo, temp2, maskReg, _mask, _sharedRegisters.uvVarying) +
//     "mul " + temp + ", " + temp2 + ", " + temp + "\n";
//   }
//   code += "mul " + temp + ", " + temp + ", " + dataRegister + ".x          \n" +
//    "add " + targetReg + ", " + targetReg+", " + temp + "          \n";
//   
//   regCache.removeFragmentTempUsage(temp);
//   
//   return code;
//  } 

 

   

Avatar
Luca, Sr. Member
Posted: 27 May 2013 06:24 PM   Total Posts: 230   [ # 4 ]

and:

// TODO Auto-generated method stub
    //
    
_context3D container3D.canvas3D.stage3DProxy.context3D;
    
//
    
trace("Context3D: " _context3D );
    
    
//
    
= new Mesh( new PlaneGeometry1001001) );
    var 
cubeMaterial:ColorMaterial = new ColorMaterial0xE658141.0 );

    
    
//
    
container3D.canvas3D.away3dView1.scene.addChild);
    
P.material container3D.canvas3D.cubeMaterial;
    
P.P.P.0;
    
P.rotationX 90;
    
    
P.geometry.subGeometries[0].autoDeriveVertexNormals false;
    
P.geometry.subGeometries[0].autoDeriveVertexTangents false;
    
    
_triangleVertsArr P.geometry.subGeometries[0].vertexPositionData;
    
// _triangleVertsArr = P.geometry.subGeometries[0].vertexData;
    
_triangleIndicesArr P.geometry.subGeometries[0].indexData
    
    
for( var i:int 0_triangleVertsArr.length; ++)
    
{
     _colorsArr
.pushMath.cosMath.random() * ) );
    
}
    
    trace
_triangleVertsArr );
    
_vertexBuffer _context3D.createVertexBuffer_triangleVertsArr.length 3);
    
_vertexBuffer.uploadFromVector_triangleVertsArr0_triangleVertsArr.length );
    
    
_indexBuffer =_context3D.createIndexBuffer_triangleIndicesArr.length );
    
_indexBuffer.uploadFromVector_triangleIndicesArr0_triangleIndicesArr.length );
    
    
_vertexBuffer1 _context3D.createVertexBuffer_colorsArr.length 3);
    
_vertexBuffer1.uploadFromVector_colorsArr0_colorsArr.length );
    
    var 
vertexAssemby:AGALMiniAssembler = new AGALMiniAssembler();
    
vertexAssemby.assembleContext3DProgramType.VERTEX_vertexShader );
    
    var 
fragmentAssembly:AGALMiniAssembler = new AGALMiniAssembler();
    
fragmentAssembly.assembleContext3DProgramType.FRAGMENT_fragmentShader);
    
    
//
    
_prog _context3D.createProgram();
    
    
//
    
_prog.uploadvertexAssemby.agalcodefragmentAssembly.agalcode );
    
    
//
    
_context3D.setProgram_prog );
    
//
    
_matr = new Matrix3D();
    
//
    
_perspectiveMatr = new PerspectiveMatrix3D();
    
    
_perspectiveMatr.perspectiveFieldOfViewRH0.430.11000 );
    
    
//
    //_context3D.setProgramConstantsFromMatrix( Context3DProgramType.VERTEX, 4, _perspectiveMatr, true );
    //
    // stage3DProxy._context3D.setProgramConstantsFromVector(Context3DProgramType.VERTEX, vertexConstantOffset, _vectorFrame);

    
trace("Shader program added"); 

 

   

Avatar
Luca, Sr. Member
Posted: 27 May 2013 06:32 PM   Total Posts: 230   [ # 5 ]

result here ( but not now ) time to time… so be patience… please smile

http://www.awaygamemake.altervista.org

 

   

Avatar
Luca, Sr. Member
Posted: 27 May 2013 07:19 PM   Total Posts: 230   [ # 6 ]

Sry beers, hi smile

Do you like this sample ?

I think away are made for semplicity. Away give you all you need, animation, material basic shader, fog, shadow ecc ecc because “i know what i need to do”, and these guys are not joking ! ( but are a little closed… )

What do you think ?

 

   

Avatar
Luca, Sr. Member
Posted: 27 May 2013 09:04 PM   Total Posts: 230   [ # 7 ]

and… have you see here ? raspberry

http://away3d.com/tutorials/Writing_Custom_Materials_1:_Getting_Started

 

   

Avatar
Luca, Sr. Member
Posted: 29 May 2013 06:45 AM   Total Posts: 230   [ # 8 ]

OK you can’t see the grass that moves now raspberry but this grass use a custom shader material, so you can make a field of grass blowing in the wind.
smile

The final result is visible here, by downloading the demo grass.zip:
http://www.ati.com/developer/Samples/Grass.html

I think i have some errore in my HLSL -> AGAL tranlation wink

( it’s not to difficult create new shader programs with away… )
smile

Next the wireframe shader… smile

 

   

Avatar
Luca, Sr. Member
Posted: 29 May 2013 10:58 AM   Total Posts: 230   [ # 9 ]

If you want to try the Grass material and eventually make changes:

// The normals ( bump ) map texture are not used by the shader program for now…
var NormalTexture:BitmapTexture = Cast.bitmapTexture( NormalMap );
var DiffuseTexture:BitmapTexture = Cast.bitmapTexture( DiffuseMap );
 
var M:GrassMaterial = new GrassMaterial( DiffuseTexture, NormalTexture );

P =  new Mesh( new PlaneGeometry( 100, 100, 10, 10 ), M ); away3dView1.scene.addChild( P );

//
P.rotationX = -90;

the program is not 100% correct and complete. I need to do some investigations, about passes and… but wink

 

File Attachments
CustomMaterial.zip  (File Size: 4KB - Downloads: 240)
   

John Brookes, Moderator
Posted: 29 May 2013 01:07 PM   Total Posts: 732   [ # 10 ]

Luca forum doesnt do .7z

 

   

Avatar
Luca, Sr. Member
Posted: 29 May 2013 03:27 PM   Total Posts: 230   [ # 11 ]

Ops,raspberry

Hi John and thx smile

Archive file format changed to zip smile

A collection of materials - plug in style ?

 

   

Avatar
Luca, Sr. Member
Posted: 29 May 2013 04:56 PM   Total Posts: 230   [ # 12 ]

And now we also have:

http://volgogradetzzz.blogspot.it/2012/12/agal-condition-operators-in-flash.html

 

   

Avatar
Luca, Sr. Member
Posted: 29 May 2013 06:33 PM   Total Posts: 230   [ # 13 ]

Other ( very interesting for me ) shader programs here:

http://www.awaygamesmaker.altervista.org/shader/shaderhlslprog/index.php

 

   

Avatar
Luca, Sr. Member
Posted: 31 May 2013 08:25 AM   Total Posts: 230   [ # 14 ]

http://www.realtimerendering.com/

“http://read.pudn.com/downloads10/ebook/40087/Real-Time Shader Programming .pdf”

Ok space character ( url format spec ) are tranlated to ” “
http://en.wikipedia.org/wiki/Uniform_resource_locator
http://en.wikipedia.org/wiki/Percent-encoding

wink

so, you need to chage the string “space” double quotes included, with the relative Percent encoding:

http://read.pudn.com/downloads10/ebook/40087/Real-Time"space"Shader"space"Programming"space”.pdf

 

   

Avatar
Luca, Sr. Member
Posted: 31 May 2013 01:25 PM   Total Posts: 230   [ # 15 ]

and, is possible test the stencil buffer to draw decals ?

mmm smile

http://www.glprogramming.com/red/index.html
http://www.glprogramming.com/red/chapter10.html#name6

http://www.opengl.org/sdk/docs/man/

 

   
   
‹‹ WOW

X

Away3D Forum

Member Login

Username

Password

Remember_me



X