- Home /
custom vertex shader that works with skinned mesh
The two Mainquestions:
Can I - in the vertex shader - access the ORIGINAL, UNTRANSFORMED vertex position of a skinned mesh? (additionally to the already skinned vertex position, which is streamed in vertex : POSITION)
How can I access the blendweights of a vertex in the vertexshader, and are these also accessible if the game object has a normal mesh renderer applied instead of a skinned mesh renderer?
background:
I need to write a custom shader that works with a skinned mesh on mobile platforms. It wouldn't be actually a very complex shader, just calculating some texture coorinates in the vertex shader, and displaying a texture in the fragment shader.
The problem: The calculated texture coordinates depend upon the original vertex position BEFORE the skinning transformation is applied. They are also not constant for each vertex, as they also depend on camera position (in particular, the texture coordinates represent a flat camera projection onto the untransformed mesh).
I read (https://docs.unity3d.com/Documentation/Components/class-SkinnedMeshRenderer.html) that on mobile devices the Skinning transformation happens on the cpu or on the floatingpoint coprocessor respectively - so I assume that the position sream that the vertexshader receives already contains the transformed vertex coordinates instead of the original positions.
So - how can I achieve what I need? How can I access in the vertex shader the original vertex position?
If this is not possible I will try to do the skinning transformation myself in the vertex shader - in this case, how can I access the skinning weights of the vertices in the vertexshader and circumvent the transformation on the coprocessor?
thank you for the help!
Answer by pcpc33 · Oct 02, 2014 at 08:07 PM
For your second question.
2) I don't think you do have access in shaders. BUT, you can write a c# script to that generates textures from the skin weights. You could do this a number of ways, but I'm currently working on this: skin weights are stored as a 1channel texture where value 1.500 encodes joint 1 at 50% weight, and 2.1 encodes joint 2 at 10% weight.
Your answer
Follow this Question
Related Questions
Changing skin weights in maya destroys character prefab 0 Answers
Skin weights in build being set to 100 on single bones 3 Answers
Skinned models look different when building the game to both Oculus&HTC Vive 0 Answers
How to calculate nearest bones, weights and bindposes programmatically? 0 Answers
Problem with exporting skinning-data from 3ds Max to Unity 1 Answer