#Unity Autodesk Shader with Vertex Colors

1 messages ยท Page 1 of 1 (latest)

vital sorrel
#

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)

warped hedge
#

Does it ship with one of the render pipeline in particular ?

vital sorrel
#

The standard render pipeline I think

warped hedge
#

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)

vital sorrel
#

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?

warped hedge
vital sorrel
#

I will try it out with the hints you gave me and would come back if I need more assistance ๐Ÿ™‚

warped hedge
#

Alright (godspeed)

vital sorrel
#

Thanks man!

vital sorrel
#

@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

warped hedge
#

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

vital sorrel
#

let me see

warped hedge
#

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)

vital sorrel
#

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

warped hedge
#

I remember the UnityStandardInput.cginc being in one of its include

vital sorrel
#

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

warped hedge
#

probably in "UnityStandardCoreForward.cginc"

#

no each pass should have a vertex stage

vital sorrel
#

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!

warped hedge
#

You will likely replace it by an almost identical file, except for the vertex color

vital sorrel
#

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
};

warped hedge
#

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

vital sorrel
#

ok thank you I will try out your way!

vital sorrel
#

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?

warped hedge
#

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

vital sorrel
#

I think having the option to save loads of textures by simply adding the color in the mesh is worth it ๐Ÿ™‚

warped hedge
#

Well save one texture at most. There must be another reason

vital sorrel
#

depends on how many material colors you need in game, it can save a lot ๐Ÿ™‚

warped hedge
#

I'm not sure I can imagine the workflow for it , but I trust it does ^^

vital sorrel
#

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

warped hedge
#

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

vital sorrel
#

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?

warped hedge
#

I'd replace the texture while keeping the material

#

Or do palette swap calculation in the fragment stage

vital sorrel
#

But then we still need to define the parts we want to colorize

warped hedge
#

With a new texture you wouldn't. The uv mapping takes care of that

vital sorrel
#

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

warped hedge
#

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

vital sorrel
#

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.

warped hedge
#

If it's just color, and not detail in the texture, that's probably a better plan

vital sorrel
#

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)

warped hedge
#

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 ?

vital sorrel
#

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.

  1. 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.

  2. 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?

warped hedge
#

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

vital sorrel
#

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

warped hedge
#

Do you mean material properties ?

#

Happy to help, wish we'd found you a solution X)

vital sorrel
#

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?

warped hedge
#

I'm was a generalist unity dev for a mobile company(B2B), looking to move to console, or premium mobile

vital sorrel
#

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

warped hedge
#

Like a pitch opportunity ?

vital sorrel
#

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

warped hedge
#

Sure why not

vital sorrel
#

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

warped hedge
#

sent you a request