|
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;
|
|
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??
|
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; // }
|
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 ); // P = new Mesh( new PlaneGeometry( 100, 100, 1, 1 ) ); var cubeMaterial:ColorMaterial = new ColorMaterial( 0xE65814, 1.0 );
// container3D.canvas3D.away3dView1.scene.addChild( P ); P.material = container3D.canvas3D.cubeMaterial; P.x = P.y = P.z = 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; i < _triangleVertsArr.length; ++i ) { _colorsArr.push( Math.cos( Math.random() * 3 ) ); } trace( _triangleVertsArr ); _vertexBuffer = _context3D.createVertexBuffer( _triangleVertsArr.length / 3, 3 ); _vertexBuffer.uploadFromVector( _triangleVertsArr, 0, _triangleVertsArr.length / 3 ); _indexBuffer =_context3D.createIndexBuffer( _triangleIndicesArr.length ); _indexBuffer.uploadFromVector( _triangleIndicesArr, 0, _triangleIndicesArr.length ); _vertexBuffer1 = _context3D.createVertexBuffer( _colorsArr.length / 3, 3 ); _vertexBuffer1.uploadFromVector( _colorsArr, 0, _colorsArr.length / 3 ); var vertexAssemby:AGALMiniAssembler = new AGALMiniAssembler(); vertexAssemby.assemble( Context3DProgramType.VERTEX, _vertexShader ); var fragmentAssembly:AGALMiniAssembler = new AGALMiniAssembler(); fragmentAssembly.assemble( Context3DProgramType.FRAGMENT, _fragmentShader); // _prog = _context3D.createProgram(); // _prog.upload( vertexAssemby.agalcode, fragmentAssembly.agalcode ); // _context3D.setProgram( _prog ); // _matr = new Matrix3D(); // _perspectiveMatr = new PerspectiveMatrix3D(); _perspectiveMatr.perspectiveFieldOfViewRH( 0.4, 4 / 3, 0.1, 1000 ); // //_context3D.setProgramConstantsFromMatrix( Context3DProgramType.VERTEX, 4, _perspectiveMatr, true ); // // stage3DProxy._context3D.setProgramConstantsFromVector(Context3DProgramType.VERTEX, vertexConstantOffset, _vectorFrame);
trace("Shader program added");
|
|
Luca, Sr. Member
Posted: 27 May 2013 07:19 PM Total Posts: 230
[ # 6 ]
Sry beers, hi
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 ?
|
Luca, Sr. Member
Posted: 27 May 2013 09:04 PM Total Posts: 230
[ # 7 ]
|
Luca, Sr. Member
Posted: 29 May 2013 06:45 AM Total Posts: 230
[ # 8 ]
OK you can’t see the grass that moves now but this grass use a custom shader material, so you can make a field of grass blowing in the wind.
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
( it’s not to difficult create new shader programs with away… )
Next the wireframe shader…
|
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
File Attachments
|
|
Luca, Sr. Member
Posted: 29 May 2013 03:27 PM Total Posts: 230
[ # 11 ]
Ops,
Hi John and thx
Archive file format changed to zip
A collection of materials - plug in style ?
|
Luca, Sr. Member
Posted: 29 May 2013 04:56 PM Total Posts: 230
[ # 12 ]
|
Luca, Sr. Member
Posted: 29 May 2013 06:33 PM Total Posts: 230
[ # 13 ]
|
|
Luca, Sr. Member
Posted: 31 May 2013 01:25 PM Total Posts: 230
[ # 15 ]
|