- Home /
Vertex Color Shader
Hey guys,
for my game I created all assets with Qubicle and exported them with color as fbx. At the moment I use I custom shader I downloaded to get access to this colors. Now I want to overlay a dirt texture on these colors but I can't get it to work.
I found some of Unitys expamples and tried to modify them.
I got it kind of working but the texture is moving when moving the camera:
Shader "Custom/CustomShader" { Properties { _Color ("Color", Color) = (1,1,1,1) _Detail("Detail", 2D) = "white" {} } SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM
#pragma surface surf Lambert
struct Input
{
float4 color: COLOR;
float2 uv_Detail;
float4 screenPos;
};
fixed4 _Color;
sampler2D _Detail;
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = IN.color.rgb * _Color.rgb;
float2 screenUV = IN.screenPos.xy / IN.screenPos.w;
screenUV *= float2(8,6);
o.Albedo *= tex2D (_Detail, screenUV).rgb * 2;
}
ENDCG
}
Fallback "Diffuse"
}
I found another solution, using a bumpmap but that doesn't work on the house, on a cube it works perfectly...
Shader "Custom/CustomShader" { Properties { _Color ("Color", Color) = (1,1,1,1) _Detail("Detail", 2D) = "white" {} } SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM
#pragma surface surf Lambert
struct Input
{
float4 color: COLOR;
float2 uv_Detail;
float4 screenPos;
};
fixed4 _Color;
sampler2D _Detail;
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = IN.color.rgb * _Color.rgb;
float2 screenUV = IN.screenPos.xy / IN.screenPos.w;
screenUV *= float2(8,6);
o.Albedo *= tex2D (_Detail, screenUV).rgb * 2;
}
ENDCG
}
Fallback "Diffuse"
}
Shader "Custom/CustomShader" { Properties { _Color ("Color", Color) = (1,1,1,1) _BumpMap ("Bumpmap", 2D) = "bump" {} _Detail("Detail", 2D) = "white" {} } SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM
#pragma surface surf Lambert
struct Input
{
float4 color: COLOR;
float2 uv_Detail;
float2 uv_BumpMap;
};
fixed4 _Color;
sampler2D _BumpMap;
sampler2D _Detail;
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = IN.color.rgb * _Color.rgb;
o.Albedo *= tex2D (_Detail, IN.uv_Detail).rgb * 2;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
Fallback "Diffuse"
}
The textures I'm using are just some random textures I found in my project.
Can someone explain what I'm doing wrong? Please help! Thanks!