- Home /
Make a sprite black and white.
How to make a black and white sprite in unity4.3 without storing black and white copy of sprite and without runtime copying and modifying texture pixels.
In other words is it possible to set a custom shader for a SpriteRenderer? Or there is some other way.
Could it be the whole scene? $$anonymous$$aybe a post render effect is what you are after
No, I need to make b/w some specific sprites. There is a library of cards in my game. Some of them should be b/w if they are not available for a player yet.
Answer by tanoshimi · Dec 02, 2013 at 03:16 PM
You can do this in the shader. Keeping the apparent brightness the same but reducing to greyscale (which is what I assume you mean by B+W) would be something like:
Shader "Custom/Greyscale" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
// Get the original texture colour
half4 tex = tex2D (_MainTex, IN.uv_MainTex);
// Get the apparent brightness
half brightness = dot(tex.rgb, half3(0.3, 0.59, 0.11));
// Set RGB values equal to brightness
o.Albedo = brightness;
}
ENDCG
}
FallBack "Diffuse"
}
Answer by yatagarasu · Dec 03, 2013 at 02:55 PM
Finally I found it is possible to set a sprite renderer shader through
GetComponent().material.shader
property
Your answer
Follow this Question
Related Questions
Unity 4.3 - Animating SpriteRenderer.Sprite With Legacy Animation 2 Answers
Unity 5.4 - Sprite Shadow 0 Answers
Sprite renderer scaling 0 Answers
keep sprite same size when changing 1 Answer
Sprite cutoff/altered in game view but not scene view 0 Answers