#Unity Autodesk Shader with Vertex Colors
1 messages ยท Page 1 of 1 (latest)
How to implement vertex colors into the Unity Autodesk Interactive Shader
@warped hedge
I would be very happy if you could explain me how to adapt the shader to make this feature work ๐
(currently at the doc, will answer later)
Does it ship with one of the render pipeline in particular ?
The standard render pipeline I think
https://github.com/TwoTailsGames/Unity-Built-in-Shaders/tree/master/DefaultResourcesExtra
Here you can find the shader source
I'd be surprised if you could modify it directly, but you could replicate your own version and change the vertext input struct to have color, from there passing it directly to the vertex stage is the real trick (it's possible that just having a half4 color : COLOR field is enough, but that's unusually helpful of Unity)
Replicating and adapting was my idea, yes.
I am a very beginner at shader programming, so I would be glad if you could point out the lines to change, if it is not much work?
according to this post : https://answers.unity.com/questions/189584/how-to-get-vertex-color-in-a-cg-shader.html
Specifically using a field float4 color : COLOR should be enough actually
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
added to vertex input in this https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/CGIncludes/UnityStandardInput.cginc
I will try it out with the hints you gave me and would come back if I need more assistance ๐
Alright (godspeed)
Thanks man!
@warped hedge So you mean when I add float4 color : COLOR; to "struct VertexInput" in UnityStandardInput.cginc , it will be applied to all shaders, i.e. the autodesk variant?
I have no clue how the cginc interferes with the shader files.
I expected a change in the shader file itself
So, in all likelyhood, any change you make to UnityStandardInput.cginc will be overwritten next time unity refreshes packages, so I'd recomment also copying it in your own implementation
The shader itself as well
So you need to put the autodesk shader code in a fresh shader, and then also replace the includes until you have your custom definition of VertexInput. Don't know if that makes sense
let me see
After that you can use the vertex color in the new shader vertex stage
(if there is not a weird unity shenanigan that fails without giving an error, which is very likely unfortunately)
I see that the autodeskShader is not including the UnityStandardInput.cginc
that means I could simply add my own include?
or add the code raw
I remember the UnityStandardInput.cginc being in one of its include
there are a lot of passes for lightmaps and other stuff. I see no vertext stage. I would assume I need to add a new pass for vertext stage?
well it is not included directly. but it could be included indirectly / chained
probably in "UnityStandardCoreForward.cginc"
no each pass should have a vertex stage
nope
nope was reffered to probably in "UnityStandardCoreForward.cginc"
will UnityStandardInput.cginc be a strict requirement of a shader? so I can assume it is chained in the includes somewhere?
UnityStandardCore.cginc found it!
You will likely replace it by an almost identical file, except for the vertex color
I could do it this way yeah.
There is no way to overwrite it differently in the shader?
like overwriting the struct?
i.e. override struct VertexInput
{
float4 vertex : POSITION;
half3 normal : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
#if defined(DYNAMICLIGHTMAP_ON) || defined(UNITY_PASS_META)
float2 uv2 : TEXCOORD2;
#endif
#ifdef _TANGENT_TO_WORLD
half4 tangent : TANGENT;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
I don't think you are allowed to redefine structs. You can change the input type of the vertex function to you own with vertex color
ok thank you I will try out your way!
I am curious why something cool and easy as vertex colors are not implemented by default?
Does it come with a big performance draw or other downside?
Your guess is as good as mine. It does seems strange to not have it as an option
It has a cost but so does the tangents and such
I think having the option to save loads of textures by simply adding the color in the mesh is worth it ๐
Well save one texture at most. There must be another reason
depends on how many material colors you need in game, it can save a lot ๐
I'm not sure I can imagine the workflow for it , but I trust it does ^^
imagine having a single simple grey diffuse texture/material.
With vertex colors, you can colorize the whole model and create different kinds of metals, like copper, etc
Metal you can do with a uniform color and either a uniform metallicity value or a map. And colorizing, unless the model has big block of color , better have textures and uv to not have vertices on every little details
But if you want multiple colors on a mesh, with the same texture?
If you define a color, you define it for the whole material.
Were you speaking of assigning the same texture via multiple materials to the same model?
I'd replace the texture while keeping the material
Or do palette swap calculation in the fragment stage
But then we still need to define the parts we want to colorize
With a new texture you wouldn't. The uv mapping takes care of that
Not sure if we are on the same page. There might be multiple ways of achieving model colorizing.
But yeah, having repeated textures just with different colors was not what I hoped for
This would result in heavy RAM consumption
And of course the APK would be very big
You'd need multiple copies of the mesh to achieve that with vertex color wouldn't you ?
And I'd be surprised if meshes compress as well as textures
No, not really.
We want to colorize one mesh by using a single material/texture.
But now I think I know what you were speaking of.. Correct me if I am wrong:
You mean changing the colors of certain parts of the mesh programmatically?
That would indeed be a favorable feature.
If it's just color, and not detail in the texture, that's probably a better plan
Now the 1 million dollar question:
Is it possible to define vertex color "channels"
And colorize them afterwards programmatically?
One way I know of would be to apply multiple materials to a mesh (which could have the same texture, but with a color override)
Really depends on how you want to set it up and how much control over it you need. Do you have a concrete(visual) example of what you are trying to accomplish ?
But with one material?
So the first approach, which works well for a single time mesh colorization is what I asked in the first place.
The advanced goal would be to have the chance to override the colors of some mesh parts programmatically.
-
We could probably do that by changing the vertex colors of the prefab mesh, but not sure how precise we can do that in unity.
-
Or we would apply different material channels to the mesh and add a color override to the material shader.
What do you think of these approaches?
You can have the mesh broken down into submeshes and have separate materials for them I think, that should solve most of these issues, depending what you wanna do with the vertex colors
you could also have a second uv channel to categorize regions in your mesh I suppose
I remember material channels! No need to break down the mesh
Maybe it is called uv channel
I will talk to my 3D artist about these options.
You were a great help
Not sure how it is called now. Some years ago it was a multi material with multiple channels
You did found! This brainstorming round pointed out 2 possibilities. We now need to choose wisely^^
Just curious, what is your profession/job?
I'm was a generalist unity dev for a mobile company(B2B), looking to move to console, or premium mobile
Nice. I am working on a mobile multi platform multiplayer space sim, with focus on mobile in my freetime. We have the chance to use a well known IP
If our game design is convincing
Like a pitch opportunity ?
Do you like to chat about it? I couldn't send you a friend request.
Yeah, the CEO is quite endorsing our approach, but he demands a waterproof concept. So we are split between experimenting and finalizing this game design document
Sure why not
What we are missing is a unity pro. As I just started learning it 1,5 years ago I am still a beginner.
8 years of backend experience though in java.
Also do VFX and other visual stuff
sent you a request