- Home /
Question by
LTonon · May 18, 2019 at 08:53 PM ·
2d gameshader programmingshaderlabart
How to implement Normal Mapping with a Sprite on Vertex Shader?
Hello, I've started to learn how to program shaders for a 2D project but I'm having some problems. This is the goal of the shader I'm working on:
Take an sprite with transparent parts as texture
Can change its color
Has a normal map that deals with lighting with as few draw calls as possible
The first two goals were achieved as far as I can see, but the last one is giving me problems, does somebody know how to implement normal mapping for 2D lighting? Here is the current shader I've done:
Shader "Custom/TestShader"
{
Properties
{
_MainTex("Albedo (RGB)", 2D) = "white" {}
_NormalTex("Normal Map", 2D) = "bump" {}
_Color ("Tint", Color) = (1, 1, 1, 1)
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"LightMode" = "ForwardBase"
"RenderType" = "Transparent"
}
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 _Color;
sampler2D _MainTex;
struct appdata
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv) * _Color;
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
Thanks for the help!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612201649im_/https://answers.unity.com/themes/thub/images/avi.jpg)