Advertisement
annapuppet

MapReveal

Sep 8th, 2021
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/MapReveal" {
  2.  
  3. Properties{
  4. _MainTex("Explored Texture", 2D) = "white" {}
  5. _PaintMap("RevealMap", 2D) = "white" {} // texture to paint on
  6. }
  7. SubShader{
  8. Tags{ "RenderType" = "Opaque" "LightMode" = "ForwardBase" }
  9.  
  10. Pass{
  11. Lighting Off
  12.  
  13. CGPROGRAM
  14.  
  15. #pragma vertex vert
  16. #pragma fragment frag
  17.  
  18.  
  19. #include "UnityCG.cginc"
  20. #include "AutoLight.cginc"
  21.  
  22. struct v2f {
  23. float4 pos : SV_POSITION;
  24. float2 uv0 : TEXCOORD0;
  25. float2 uv1 : TEXCOORD1;
  26.  
  27. };
  28.  
  29. struct appdata {
  30. float4 vertex : POSITION;
  31. float2 texcoord : TEXCOORD0;
  32. float2 texcoord1 : TEXCOORD1;
  33.  
  34. };
  35.  
  36. sampler2D _PaintMap;
  37. sampler2D _MainTex;
  38. float4 _MainTex_ST;
  39. v2f vert(appdata v) {
  40. v2f o;
  41. o.pos = UnityObjectToClipPos(v.vertex);
  42. o.uv0 = TRANSFORM_TEX(v.texcoord, _MainTex);
  43. o.uv1 = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;// lightmap uvs
  44. return o;
  45. }
  46.  
  47. half4 frag(v2f o) : COLOR{
  48. half4 main_color = tex2D(_MainTex, o.uv0); // main texture
  49. half4 paint = (tex2D(_PaintMap, o.uv1)); // painted on texture
  50. float4 endresult = (1-paint.r) * main_color; // reveal main texture where painted black
  51. return endresult;
  52. }
  53. ENDCG
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement