Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/GreedyMaterial" {
- Properties{
- _Color("Color", Color) = (1,1,1,1)
- _MainTex("Albedo (RGB)", 2D) = "white" {}
- }
- SubShader{
- Tags{ "RenderType" = "Opaque" }
- LOD 200
- CGPROGRAM
- // Physically based Standard lighting model, and enable shadows on all light types
- //#pragma surface surf Standard fullforwardshadows
- #pragma surface surf Lambert //fullforwardshadows
- #pragma target 2.0
- sampler2D _MainTex;
- struct Input
- {
- float4 color : COLOR;
- float3 worldNormal;
- float3 worldPos;
- float2 uv_MainTex;
- };
- half _Glossiness;
- half _Metallic;
- fixed4 _Color;
- void surf(Input i, inout SurfaceOutput o) {
- const float gridSize = 16; //How many cells are in a row
- const float margin = 0; //(1 / gridSize) / 16; //Margin for preventing bleeding
- const float cellSize = (1 / gridSize) - (margin * 2); //Size of one cell
- //float blockId = int(i.color.a * gridSize * gridSize) / gridSize; //Get tile id from alpha channel, and transform it so that fraction is horizontal position [0, 1] and integer part points vertical position [0, gridSize]
- //float blockId= int(i.uv_MainTex.y*gridSize) +int(i.uv_MainTex.x/cellSize);
- fixed4 c = tex2D(_MainTex, frac(float2(
- i.worldPos.x * (1 - i.worldNormal.x) + i.worldPos.z * i.worldNormal.x, //Figure out texel location inside a cell.
- i.worldPos.y * (1 - i.worldNormal.y) + i.worldPos.z * i.worldNormal.y)) * cellSize //Take in account face normal
- //+ float2(blockId + margin, floor(blockId) / gridSize + margin)); //Choose the actual tile
- + float2(int(i.uv_MainTex.x / cellSize)*cellSize, int(i.uv_MainTex.y / cellSize)*cellSize));
- //+i.uv_MainTex);
- o.Albedo = c.rgb*_Color;
- o.Alpha = c.a;
- }
- ENDCG
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement