- Home /
Making specific shader for texture transition effect
Greetings, people. I'm beginner in making shaders, so I can't manage with one thing at the moment. The deal is about realization some extraordinary texture transition effect, kinda in attached animation. I'd like to have two different textures using in a shader, then one texture starts appearing in random pixels which, in a turn, combining in growing areas and without any blend effects, just appears at once by zones. This is a snag for me, I would be glad of any help, please forward me on the way. Thank you in advance.
for the animated graphic clearly showing what you're trying to achieve :) For reference, what you're describing is a "dissolve shader", and if Professor Snake's answer doesn't do it for you, there's several examples on the wiki and here on UA.
Answer by Professor Snake · Nov 05, 2013 at 02:05 PM
I don't think this can be done completely randomly, but you can certainly do it with a texture guide. If the average of the Guide texture's RGB values for a pixel are above the threshold, that pixel will sample the colour of the detail texture. Otherwise it will sample the main texture.
Shader "Custom/Transition" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_DetailTex ("Detail (RGB)", 2D) = "white" {}
_Guide ("Guide (RGB)", 2D) = "white" {}
_Threshold("Threshold",Range(0,1))=0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _DetailTex;
sampler2D _Guide;
float _Threshold;
struct Input {
float2 uv_MainTex;
float2 uv_DetailTex;
float2 uv_Guide;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
half4 d = tex2D (_DetailTex, IN.uv_DetailTex);
half4 g = tex2D (_Guide, IN.uv_Guide);
if((g.r+g.g+g.b)*0.33333f<_Threshold)
o.Albedo = d.rgb;
else
o.Albedo = c.rgb
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Example images:
You can use your own texture guide to achieve exactly the kind of effect you want.
Your answer

Follow this Question
Related Questions
Shader's BlendOp Min Question 1 Answer
Need to know when a transition starts in mecanim. 1 Answer
Shader: Normal Angle 1 Answer
alpha adjustable additive blender 1 Answer
How to smoothen/sharpen edges while using alphatest 0 Answers