Vertex Normals Computed in Shader Program

Software: Away3D 4.x

Radiosatch2000, Newbie
Posted: 30 October 2012 03:49 AM   Total Posts: 6

I have set up a material method to manipulate vertex Y positions based on a height map.  It works similar to the Elevation class, but can be updated real time by inputting a bitmapData object with height map data.  The method is then attached to a mesh with plane geometry.  The only problem I’m having is that the normals are not being computed on the GPU based on the new vertex positions.  So the normals still appear as if the plane was flat.  See my attached image.  Does anyone know how I can compute the normals based on my vertex positions or height map data on the GPU.  Below is my current shader code that is in the getVertexCode function:

var code:String = “”;

var vertexConstant:ShaderRegisterElement = regCache.getFreeVertexConstant();//REFERS TO THE DATA IN initConstants();

vertexAttribute = regCache.getFreeVertexAttribute();
_heightMapIndex = vertexAttribute.index;

var temp:ShaderRegisterElement = regCache.getFreeVertexVectorTemp();
heightMapVarying = regCache.getFreeVarying();//HEIGHTMAP DATA TO BE MOVED TO FRAGMENT SHADER
heightSizeVarying = regCache.getFreeVarying();
normalVarying = regCache.getFreeVarying();

code += “mov ” + temp + “, va0” + “\n” +//COPY CURRENT VERTICES (IN REGISTER 0) TO TEMPORARY REGISTER
“add ” + temp + “.y, ” + temp + “.y, ” + vertexAttribute + “.x\n” + //ADD VERTEX REGISTER2 (BITMAP VECTOR DATA, I.E. HEIGHTMAPDATA) X VALUE TO TEMP Y VALUE (MOVES Y COORDS)
“mul ” + temp + “.y, ” + temp + “.y, ” + vertexConstant + “.x\n”+//MULTIPLY DATA BY HEIGHT CONSTANT
“m44 op, ” + temp + “, vc0\n” + //SEND NEW TEMP VALUES TO OUTPUT USING PROJECTION MATRIX (vc0)
“mov ” + temp + “, va1” + “\n” +
“mul ” + temp + “.y, ” + temp + “.y, ” + vertexAttribute + “.x\n” +
“mov ” + heightMapVarying + “, ” + vertexAttribute + “\n” + //COPY BITMAP HEIGHTS FOR USE IN FRAGMENT SHADER (LIGHTING)
“mov ” + heightSizeVarying + “, ” + vertexConstant + “\n”;// +

return code;

 

   

Avatar
GoroMatsumoto, Sr. Member
Posted: 28 November 2012 03:37 AM   Total Posts: 166   [ # 1 ]

You can use “updateVertexData()”.

http://wonderfl.net/c/7shx
http://wonderfl.net/c/1VjX
http://wonderfl.net/c/iytL

It’s not Vertex shading…
I don’t know about that performance.

   

Avatar
loth, Sr. Member
Posted: 28 November 2012 10:01 AM   Total Posts: 236   [ # 2 ]

look shallowwater demo

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X