Hello everyone,
I am playing around with a Shader that blends from one texture to another. I do this using the distance between two object as the blend factor. Right now it blends the whole texture at once, however I would like it if it checked per pixel how much it should blend. So when you walk towards something, it will blend, starting with the parts closest to you (this would create a much better effect).
How could I go about implementing this?
This is the Shader I’m using:
Shader "Custom/testShader" {
Properties{
_Tint("Tint Color", Color) = (.9, .9, .9, 1.0)
_TexMat1("Base (RGB)", 2D) = "white" {}
_TexMat2("Base (RGB)", 2D) = "white" {}
_Blend("Blend", Range(0.0,1.0)) = 0.0
}
Category{
ZWrite On
Alphatest Greater 0
Tags{ Queue = Transparent RenderType = Transparent }
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
SubShader{
Pass{
Material{
Diffuse[_Tint]
Ambient[_Tint]
}
Lighting On
SetTexture[_TexMat1]{ combine texture }
SetTexture[_TexMat2]{ constantColor(0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture[_TexMat2]{ combine previous + -primary, previous * primary }
}
}
FallBack " Diffuse", 1
}
}
And this is the Code I use to blend using distance:
using UnityEngine;
using System.Collections;
public class RenderWhileClose : MonoBehaviour {
public GameObject target;
public float minDistance = 5.0f;
public float maxDistance = 10.0f;
Renderer render;
float distance;
void Start () {
render = GetComponent<Renderer>();
}
void Update () {
distance = Vector3.Distance(transform.position, target.transform.position);
float lerp = Mathf.Clamp((distance - minDistance) / (maxDistance - minDistance), 0, 1);
render.material.SetFloat("_Blend", lerp);
}
}
Thanks in advance!