- Home /
How to get the real color of the vertices in a mesh modified by a shader? [C#]
Hi all,
First of all, I have a mesh with a material and a diffuse shader attached to it. My aim is to know in each moment what is the color assigned to the vertices of the mesh, once it is illuminated by a directional light (e.g., To know in real time how the color of the vertices changes as the light changes)
How can I access (by C# code) the color values for all the vertices in my mesh once the material is being illuminated by the light.
I think I should access to a struct in the diffuse shader, like this:
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR;
};
Is this correct? Thank you!
Pretty sure it's not possible to get the vertex colours computed by a shader.
I'm pretty sure aswell that this isn't possible. What are you trying to achieve? $$anonymous$$aybe if you tell us this we can come up with a solution.
Surely by the time they've been modified by a shader, they're not really vertex colours any more? Vertex colours are attributes assigned to the mesh, which can be considered inputs to a shader operation, rather than outputs from it.
If you want to apply game logic based on the colour value of certain elements in a scene after having accounted for lighting etc. then you could write the result to a rendertexture and then read that in again?
Take a look at this $$anonymous$$ayelGee :
http://answers.unity3d.com/questions/810541/how-to-obtain-the-brightnesscolor-of-a-triangle.html
It should answer your question.
So the 4th question on the same topic? You didn't reply to your last question. Are you going to post a new question each day?
The information you're after doesn't exist at any time. The lighting is done in the fragment shader. The fragment shader works on pixels on your screen. At this point there are no vertices anymore, only rasterized fragments of interpolated vertex attributes. At this stage the GPU doesn't even know to which triangle a certain pixel belongs. It just has the interpolated attributes (screen space position, normal vector, vertex color) and out of those it calculates the final color for this pixel. Further more realtime shadows are usually calculated in a seperate pass which just darkens certain areas on the screen.
Again at no point in this pipeline the original vertices are "lit". And once more, This is a render engine to produce an image for you to watch, not to do scientific calculations.