How can I change the normals of my model so it will look less rounded

20 Views Asked by At

My AGAL code for creating the normals is this:

    "nrm ft1.xyz, v1.xyz\n" + // renormalize normal
    "dp3 ft1, fc2.xyz, ft1.xyz \n" + // directional light contribution

but I get a very rounded object, is there a way to generate the normals so that it will be more sharp at the edges.

Thanks

1

There are 1 best solutions below

0
Shai Quantz On

Found the solution: I export the model from 3DMax with my script (exporting script from http://not-so-stupid.com/), but select Sandy 3.0 format, which maks the "export vertex normal" valid, and then I copy the information from the as file created by the script. I put the normal in a new vertex buffer and upload them:

context.setVertexBufferAt( 2, normalBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);

then use them in the shaders code:

        private const VERTEX_SHADER_LIGHT:String = "" +
        "m44 op, va0, vc0\n" + // pos to clipspace
        "mov v0, va1 \n" +  // copy uv
        "mov vt1.xyz, va2.xyz\n"+
        "mov vt1.w, va2.w\n"+   
        "mov v1, vt1\n"; 

    private const FRAGMENT_SHADER_LIGHT:String = "" +
    "tex ft0, v0, fs0 <2d,linear,nomip>\n" + // read from texture
    "nrm ft1.xyz, v1.xyz\n" + // renormalize normal v1 contains the normals created in the vertex code
    "dp3 ft1, fc2.xyz, ft1.xyz \n" + // directional light contribution
    "neg ft1, ft1 \n" + // negation because we have a vector "from" light 
    "max ft1, ft1, fc0 \n"+ // clamp to [0, dot]

    "mul ft1, ft1, fc3 \n"+ // contribution from light
    "mul ft1, ft1, ft0 \n"+ // contribution from light + texture


    "add oc, ft1, fc1"; // final color as surface + ambient