Advertisement
dnnkeeper

Bumped Atlas

May 18th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2.  
  3. Shader "Custom/BumpedLambert" {
  4. Properties{
  5. _Color("Color", Color) = (1,1,1,1)
  6. _MainTex("Albedo (RGB)", 2D) = "white" {}
  7. _BumpMap("Bumpmap", 2D) = "bump" {}
  8.  
  9. _CellSize("Сell Size (See Same On VoxelSettings)", Float) = 0.03125
  10. }
  11. SubShader {
  12. Tags { "RenderType"="Opaque" }
  13. LOD 200
  14.  
  15. CGPROGRAM
  16.  
  17. #pragma surface surf Lambert vertex:vert
  18.  
  19. // Use shader model 3.0 target, to get nicer looking lighting
  20. #pragma target 3.0
  21.  
  22. sampler2D _MainTex;
  23. sampler2D _BumpMap;
  24.  
  25. struct Input {
  26. float2 uv_MainTex;
  27. float2 uv_BumpMap;
  28. float3 wNormal;
  29. float3 wPos;
  30. };
  31.  
  32. fixed4 _Color;
  33. fixed4 _ColorOffset;
  34. float _CellSize;
  35.  
  36. void vert(inout appdata_full v, out Input data)
  37. {
  38. UNITY_INITIALIZE_OUTPUT(Input, data);
  39. //data.uv_MainTex = TRANSFORM_TEX(v.texcoord1, _MainTex);
  40. //data.uv_BumpMap = TRANSFORM_TEX(v.texcoord2, _BumpMap);
  41. data.wPos = mul(unity_ObjectToWorld, v.vertex).xyz;
  42. data.wNormal = mul((float3x3)unity_ObjectToWorld, v.normal);
  43. }
  44.  
  45. void surf (Input i, inout SurfaceOutput o) {
  46.  
  47. float2 pos = frac(float2(
  48. i.wPos.x * (1.0 - i.wNormal.x) + i.wPos.z * i.wNormal.x, //Figure out texel location inside a cell.
  49. i.wPos.y * (1.0 - i.wNormal.y) + i.wPos.z * i.wNormal.y)) * _CellSize //Take in account face normal
  50. //+ float2(blockId + margin, floor(blockId) / gridSize + margin)); //Choose the actual tile
  51. + float2(floor(i.uv_MainTex.x / _CellSize)*_CellSize,
  52. floor(i.uv_MainTex.y / _CellSize)*_CellSize);
  53.  
  54. fixed4 c = tex2D (_MainTex, pos) * _Color;
  55.  
  56. o.Albedo = c.rgb;
  57.  
  58. o.Normal = UnpackNormal(tex2D(_BumpMap, pos));
  59.  
  60. o.Alpha = c.a;
  61. }
  62. ENDCG
  63. }
  64. FallBack "Diffuse"
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement