Hello guys!
I was just watching the Theresa Latzko’s class and the “mini tutorial” Unity made about the shader she made, but I’m struggling a bit on trying to replicate it.
First of all, she used Vertex Coloring for all the models in her scene, so she didn’t need to uv map anything, she just painted everything on the model.
Second, she handled light in a very particular way: she ignored the normals directions and only took account the distance of the light source from the objects.
I’ve found a great Vertex Coloring shader and Unity provided the code she used to handle the light, but I’m struggling a bit to put them together.
Here is the Vertex Coloring Shader:
Shader "Custom/NewSurfaceShader" {
Properties
{
_Color ("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// BlinnPhong lighting model, and enable shadows on all light types
#pragma surface surf BlinnPhong fullforwardshadows
// Use shader model 3.0 target, for no particular reason
#pragma target 3.0
struct Input
{
float4 color : COLOR;
};
fixed4 _Color;
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = IN.color.rgb * _Color.rgb;
}
ENDCG
}
FallBack "Diffuse"
}
And here is the function she made to handle lighting:
float3 ShadeVertexLightsAtten (
float4 lightPosX, float4 lightPosY, float4 lightPosZ,
float3 lightColor0, float3 lightColor1, float3 lightColor2, float3 lightColor3,
float4 lightAttenSq,
float3 pos)
{
// to light vectors
float4 toLightX = lightPosX - pos.x;
float4 toLightY = lightPosY - pos.y;
float4 toLightZ = lightPosZ - pos.z;
// squared lengths
float4 lengthSq = 0;
lengthSq += toLightX * toLightX;
lengthSq += toLightY * toLightY;
lengthSq += toLightZ * toLightZ;
// attenuation
float4 atten = 1.0 / (1.0 + lengthSq * lightAttenSq);
float4 diff = atten;
//light color reverses
lightColor0 = (1-lightColor0);
lightColor1 = (1-lightColor1);
lightColor2 = (1-lightColor2);
lightColor3 = (1-lightColor3);
// final color
float3 col = 0;
col += lightColor0 * diff.x;
col += lightColor1 * diff.y;
col += lightColor2 * diff.z;
col += lightColor3 * diff.w;
return col;
}
So, how did she put these two things together? Here is the Unity “mini tutorial” I mentioned".
I would like to have a result similar or equal to the one in the link above… There is also a video about her work in the Unity Youtube Channel.
Sorry if this is too simple, and thanks in advance!