Set VertexRGB, render VertexRGB+Textured (Ambient Occlusion)

Software: Away3D 4.x

Rayen123, Member
Posted: 16 August 2012 08:46 AM   Total Posts: 70

Hi,
I am trying create Ambient Occlusion.

I have created big “terrain mesh”, created manualy from vertices,normals,uvs and indexes. Everything works great.

But I dont know how set manualy VertexRGB to my “terrain mesh” to every vertex, and then render shader: “VertexRGB+Textured” ? Is it possible in Away3D ? (i use gold version, downloaded from away3D site)

How I can set color to vertex? I have to change VertexShader and Fragment shader too ?

I search for this few days and nothing :/

Please help
Rayen

   

Richard Olsson, Administrator
Posted: 16 August 2012 09:46 AM   Total Posts: 1192   [ # 1 ]

There is no support for “vertex colors” in Away3D. You could of course create your own buffers, or generate per-vertex colors in the vertex shader, pass it over to the fragment shader using a varying register and use it however you want in the fragment shader.

But I’m not quite sure what you’re trying to achieve. Do you want to render dynamic AO? Based on what ruleset?

   

Rayen123, Member
Posted: 16 August 2012 10:02 AM   Total Posts: 70   [ # 2 ]

Hi,
I want create terrain from cubes, and then once calculate for every vertex VertexRGB to create (static) AO in terrain (my presentation project).

Btw,color from point lights are not created by VertexRGB ?

   

Richard Olsson, Administrator
Posted: 16 August 2012 10:04 AM   Total Posts: 1192   [ # 3 ]

If you just want to calculate it once then what you need is definitely a color buffer on SubGeometry. You will have to add that (e.g. by extending SubGeometry) and make sure it is uploaded and made available to the shader program.

You’ll then have to create a vertex shader that moves the color attribute to a varying register (available to the fragment shader) and in the fragment shader you can do whatever you want with it, e.g. multiply the output color with it.

Point lights are irrelevant here, because anything that is calculated in the vertex shader has to be done procedurally, as opposed to calculated once and stored in a vertex attribute buffer.

   

Rayen123, Member
Posted: 16 August 2012 10:30 AM   Total Posts: 70   [ # 4 ]

Okey, thanks !
Is in Away3D any function to change vertex shader and fragment shader ? Or I have to rewrite away3D sources manualy ?

   

Richard Olsson, Administrator
Posted: 16 August 2012 10:35 AM   Total Posts: 1192   [ # 5 ]

Since this is a very simple feature, the easiest thing you can do for the fragment shader is to write your own shader method. Look at one of the simpler shader methods, like FogMethod for an example of what a shader method should look like. You can then just add it to your material using addMethod().

https://github.com/away3d/away3d-core-fp11/blob/master/src/away3d/materials/methods/FogMethod.as

The vertex shader is slightly more complicated. Here you are probably best off either modifying Away3D’s existing code, or extending it. The relevant class should be the DefaultScreenPass, where you could add code to move the color vertex attribute to a varying register. Look at how this is done in compileUVCode() for example.

You could also modify vertex shaders by creating an animation class, but that’s probably overkill for this tiny (and unrelated to animation) change.

   
   
‹‹ Hexahedron

X

Away3D Forum

Member Login

Username

Password

Remember_me



X