Hi to community,
I am working on a similar game like sims and I want to make wall textures with changing color capabilities.I am not using shader graphs cause I had some issues with batching so I desided to write my own shader. I am using below to pick colors via script
var propBlock = new MaterialPropertyBlock();
this.gameObject.GetComponent<Renderer>().GetPropertyBlock(propBlock);
// Assign our new value.
_propBlock.SetColor("_Color", OrigColor);
// Apply the edited values to the renderer.
GetComponent<Renderer>().SetPropertyBlock(_propBlock);
Let me explain what I need to achieve. In below picture I have a wall paint made in photoshop and I have made two textures : One for red , and one for white
Shader "Custom/FloorBlock_settedProp" {
Properties{
_Color("Color", Color) = (1,1,1,1)
_ColorOverlay("ColorOverlay", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_SecondaryTex("Overlay Texture Color (RGB) Alpha (A)", 2D) = "white" {}
[NoScaleOffset] _NormalMap("Normals", 2D) = "bump" {}
_Glossiness("Smoothness", Range(0,1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
}
SubShader{
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use Shader model 3.0 target
#pragma target 3.0
sampler2D _MainTex;
sampler2D _NormalMap;
//additional
sampler2D _SecondaryTex;
struct Input {
float2 uv_MainTex;
//float2 uv_SecondTex;
float2 uv_NormalMap;
};
//additional
//fixed4 _Color;
half _Glossiness;
half _Metallic;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _ColorOverlay)
UNITY_INSTANCING_BUFFER_END(Props)
void surf(Input IN, inout SurfaceOutputStandard o) {
//additional
float4 mainTex = tex2D(_MainTex, IN.uv_MainTex);
float4 overlayTex = tex2D(_SecondaryTex, IN.uv_MainTex);
half3 mainTexVisible = mainTex.rgb * (1 - overlayTex.a);
half3 overlayTexVisible = overlayTex.rgb * (overlayTex.a);
//float3 finalColor = (mainTexVisible + overlayTexVisible) * _Color;
//Main
//fixed4 c = (tex2D(_MainTex, IN.uv_MainTex) * UNITY_ACCESS_INSTANCED_PROP(Props, _Color) + tex2D(_SecondaryTex, IN.uv_MainTex) * UNITY_ACCESS_INSTANCED_PROP(Props, _ColorOverlay));
//o.Albedo = c.rgb;
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = lerp(UNITY_ACCESS_INSTANCED_PROP(Props, _Color), UNITY_ACCESS_INSTANCED_PROP(Props, _ColorOverlay), c.r);
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap));
}
ENDCG
}
FallBack "Diffuse"
}



