So, the last couple of weeks have been busy, starting a company is more work than I thought. So much paperwork.
About development, I recently added normal mapping on the player and think it looks great. My friend has been talking about it for a while and I decided to see how I could do it and if it would take a while to implement. Turns out it was pretty easy to do. I didn't have much experience in Unity or gamedev until the past 8 months or so and I'm often trying to find solutions online to stuff I want to do. I've seen the question asked a couple of time about how to make normal map easy in Unity and I couldn't find a way to do it that pleased me.
After some research, I made a shader using bits of other shader I found to make one that had all the features I needed. I have no experience in shader writing so it might need some reviewing by someone who can write shaders, but for now it work well enough to see how normal mapping will work in InTheShadows.
So this is the sprite shader source code, for anyone who is interested. It let you have RGB, Bump, and intensity slider for the Bump and pixel snap.
Shader "Sprites/Bumped Diffuse with Shadows"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_BumpMap ("Normalmap", 2D) = "bump" {}
_BumpIntensity ("NormalMap Intensity", Range (-1, 2)) = 1
_BumpIntensity ("NormalMap Intensity", Float) = 1
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_Cutoff ("Alpha Cutoff", Range (0,1)) = 0.5
}
SubShader
{
Tags
{
"Queue"="AlphaTest"
"IgnoreProjector"="True"
"RenderType"="TransparentCutOut"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
LOD 300
Cull Off
Lighting On
ZWrite On
Fog { Mode Off }
CGPROGRAM
#pragma target 3.0
#pragma surface surf Lambert alpha vertex:vert alphatest:_Cutoff fullforwardshadows
#pragma multi_compile DUMMY PIXELSNAP_ON
#pragma exclude_renderers flash
sampler2D _MainTex;
sampler2D _BumpMap;
fixed _BumpIntensity;
fixed4 _Color;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
fixed4 color;
};
void vert (inout appdata_full v, out Input o)
{
#if defined(PIXELSNAP_ON) && !defined(SHADER_API_FLASH)
v.vertex = UnityPixelSnap (v.vertex);
#endif
v.normal = float3(0,0,-1);
v.tangent = float4(1, 0, 0, 1);
UNITY_INITIALIZE_OUTPUT(Input, o);
o.color = _Color;
}
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
_BumpIntensity = 1 / _BumpIntensity;
o.Normal.z = o.Normal.z * _BumpIntensity;
o.Normal = normalize((half3)o.Normal);
}
ENDCG
}
Fallback "Transparent/Cutout/Diffuse"
}
Save this as a .shader file and use this on your sprite renderer. As someone asked me before, if you want your sprite to cast shadows on other objects just enable shadow casting/receiving in debug mode in the inspector. I'm sharing it because I've seen the question asked a bunch of time when I searched for it myself and never found something similar.
The normal map are created using
Nvidia normal map filter tool for Photoshop, which is free, but if you are using gimp you can also use a
plug-in to achieve the same result.
I think explaining the whole process is maybe out of scope of a forum devlog, but I wrote about it a bit more on my blog. If you want to read the whole thing you can go on my website
www.6502b.comWhat do you guys think of the normal map on the player?