Last active
December 15, 2021 10:29
-
-
Save Acrosicious/de5d5fd25347e866ca5e54c3182390b5 to your computer and use it in GitHub Desktop.
Modified version of Unity Mobile/Bumped Shader -- Supports 2x2 Atlas textures. -- Use x and y in inspector to change Tiling of each texture individually. -- Use z and w in inspector to change Offset of each texture individually.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/TextureAtlasSurfaceShader" | |
{ | |
// https://github.com/Acrosicious | |
// Modified version of Unity Mobile/Bumped Shader | |
// MIT License | |
// Supports 2x2 Atlas textures. | |
// | |
// Use x and y in inspector to change Tiling of each texture individually. | |
// Use z and w in inspector to change Offset of each texture individually. | |
// ------------------- Description from original Unity Bumbed Shader ---------------------------------- | |
// Unity built - in shader source.Copyright(c) 2016 Unity Technologies.MIT license(see license.txt) | |
// Simplified Bumped shader. Differences from regular Bumped one: | |
// - no Main Color | |
// - Normalmap uses Tiling/Offset of the Base texture | |
// - fully supports only 1 directional light. Other lights can affect it, but it will be per-vertex/SH. | |
Properties{ | |
[NoScaleOffset] _MainTex("Base (RGB)", 2D) = "white" {} | |
[NoScaleOffset] _BumpMap("Normalmap", 2D) = "bump" {} | |
_TilingBL("Tiling Texture Bottom Left", Vector) = (1,1,0,0) | |
_TilingBR("Tiling Texture Bottom Right", Vector) = (1,1,0,0) | |
_TilingTL("Tiling Texture Top Left", Vector) = (1,1,0,0) | |
_TilingTR("Tiling Texture Top Right", Vector) = (1,1,0,0) | |
} | |
SubShader{ | |
Tags { "RenderType" = "Opaque" } | |
LOD 250 | |
CGPROGRAM | |
#pragma surface surf Lambert noforwardadd | |
sampler2D _MainTex; | |
sampler2D _BumpMap; | |
float4 _MainTex_TexelSize; | |
float4 _TilingBL; | |
float4 _TilingBR; | |
float4 _TilingTL; | |
float4 _TilingTR; | |
struct Input { | |
float2 uv_MainTex; | |
float2 uv_BumpMap; | |
}; | |
void surf(Input IN, inout SurfaceOutput o) { | |
float format = 2; | |
float2 uv = IN.uv_BumpMap; | |
float2 uvTiled = IN.uv_MainTex; | |
float4 tiling; | |
// Supports only 2x2 textures for tiling | |
if (uv.x < 0.5f) { | |
if (uv.y < 0.5f) { | |
tiling = _TilingBL; | |
} | |
else { | |
tiling = _TilingTL; | |
} | |
} | |
else { | |
if (uv.y < 0.5f) { | |
tiling = _TilingBR; | |
} | |
else { | |
tiling = _TilingTR; | |
} | |
} | |
float border = _MainTex_TexelSize.x * 1; | |
uvTiled = uv * tiling.xy + tiling.zw; | |
uv = floor(uv * format) / format + (border + fmod(uvTiled, 1 / format) / 0.5f * (0.5f - 2 * border)); | |
fixed4 c = tex2D(_MainTex, uv, ddx(_MainTex_TexelSize.z / 2), ddy(_MainTex_TexelSize.w / 2)); | |
o.Albedo = c.rgb; | |
o.Alpha = c.a; | |
o.Normal = UnpackNormal(tex2D(_BumpMap, uv)); | |
} | |
ENDCG | |
} | |
FallBack "Mobile/Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment