Created
July 7, 2020 22:29
-
-
Save Xevion/b84e240df80f654f1b24206e0531bd77 to your computer and use it in GitHub Desktop.
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
// Upgrade NOTE: upgraded instancing buffer 'Props' to new syntax. | |
Shader "PDT Shaders/TestGrid" { | |
Properties { | |
_LineColor ("Line Color", Color) = (1,1,1,1) | |
_InactiveColor ("Cell Color", Color) = (0,1,0,1) | |
_ActiveColor ("Selected Color", Color) = (1,0,0,1) | |
[PerRendererData] _MainTex ("Albedo (RGB)", 2D) = "white" {} | |
[IntRange] _GridSize("Grid Size", Range(1,100)) = 10 | |
_LineSize("Line Size", Range(0,1)) = 0.15 | |
[IntRange] _SelectCell("Select Cell Toggle ( 0 = False , 1 = True )", Range(0,1)) = 0.0 | |
[IntRange] _SelectedCellX("Selected Cell X", Range(0,100)) = 0.0 | |
[IntRange] _SelectedCellY("Selected Cell Y", Range(0,100)) = 0.0 | |
} | |
SubShader { | |
Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" } | |
LOD 200 | |
CGPROGRAM | |
// Physically based Standard lighting model, and enable shadows on all light types | |
#pragma surface surf Standard fullforwardshadows | |
// Use shader model 3.0 target, to get nicer looking lighting | |
#pragma target 3.0 | |
sampler2D _MainTex; | |
struct Input { | |
float2 uv_MainTex; | |
}; | |
half _Glossiness = 0.0; | |
half _Metallic = 0.0; | |
float4 _LineColor; | |
float4 _InactiveColor; | |
float4 _ActiveColor; | |
float _GridSize; | |
float _LineSize; | |
float _SelectCell; | |
float _SelectedCellX; | |
float _SelectedCellY; | |
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. | |
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. | |
// #pragma instancing_options assumeuniformscaling | |
UNITY_INSTANCING_BUFFER_START(Props) | |
// put more per-instance properties here | |
UNITY_INSTANCING_BUFFER_END(Props) | |
void surf (Input IN, inout SurfaceOutputStandard o) { | |
// Albedo comes from a texture tinted by color | |
float2 uv = IN.uv_MainTex; | |
_SelectedCellX = floor(_SelectedCellX); | |
_SelectedCellY = floor(_SelectedCellY); | |
fixed4 c = float4(0.0,0.0,0.0,0.0); | |
float gsize = floor(_GridSize) + _LineSize; | |
float2 id = float2(floor(uv.x/(1.0/gsize)), floor(uv.y/(1.0/gsize))); | |
float4 color = _InactiveColor; | |
float brightness = _InactiveColor.w; | |
if (frac(uv.x*gsize) <= _LineSize || frac(uv.y*gsize) <= _LineSize) | |
{ | |
brightness = _LineColor.w; | |
color = _LineColor; | |
} //This checks that the cell is currently selected if the Select Cell slider is set to 1 ( True ) | |
else if (id.x == _SelectedCellX && id.y == _SelectedCellY) | |
{ | |
brightness = _ActiveColor.w; | |
color = _ActiveColor; | |
} | |
//Clip transparent spots using alpha cutout | |
if (brightness == 0.0) | |
clip(c.a - 1.0); | |
o.Albedo = float4( color.x*brightness,color.y*brightness,color.z*brightness,brightness); | |
// Metallic and smoothness come from slider variables | |
o.Metallic = 0.0; | |
o.Smoothness = 0.0; | |
o.Alpha = 0.0; | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment