- Home /
 
Triplanar surface shader not responding to Mesh.Colors
Shader noob here. I'm using a simple triplanar shader on my procedural meshes
 Shader "iPhone Triplanar" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
     _SideScale("Side Scale", Float) = 1
 }
 SubShader 
 {
     Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="TransparentCutoff"}
 
     Cull Off
     ZWrite On
     Lighting Off
     
     CGPROGRAM
     #pragma surface surf Lambert
     #pragma exclude_renderers flash
 
     sampler2D _MainTex;
     float _SideScale;
     
     struct Input {
         float3 worldPos;
         float3 worldNormal;
     };
         
     void surf (Input IN, inout SurfaceOutput o) {
         float3 projNormal = saturate(pow(IN.worldNormal * 1.4, 4));
         
         // SIDE X
         float3 x = tex2D(_MainTex, frac(IN.worldPos.zy * _SideScale)) * abs(IN.worldNormal.x);
         
         // TOP / BOTTOM
         float3 y = 0;
         if (IN.worldNormal.y > 0) {
             y = tex2D(_MainTex, frac(IN.worldPos.zx * _SideScale)) * abs(IN.worldNormal.y);
         } else {
             y = tex2D(_MainTex, frac(IN.worldPos.zx * _SideScale)) * abs(IN.worldNormal.y);
         }
         
         // SIDE Z    
         float3 z = tex2D(_MainTex, frac(IN.worldPos.xy * _SideScale)) * abs(IN.worldNormal.z);
         
         o.Albedo = z;
         o.Albedo = lerp(o.Albedo, x, projNormal.x);
         o.Albedo = lerp(o.Albedo, y, projNormal.y);
     } 
     ENDCG
 }
 }
 
               Which works well, except I am using a custom lighting system, by setting vertex colours in my code (Mesh.colors32) This shader only seems to respond to Unity lighting.
Here is the previous shader I was using which worked with my lighting model but doesn't have the nice triplanar effect that I like:
 Shader "Unlit Diffuse Alpha" {
 Properties {
 _Color ("Main Color", Color) = (1,1,1,1)
 _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
 _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
 }
 SubShader {
 Cull Off
 Tags {"Queue"="Transparent" "IgnoreProjector"="True"     "RenderType"="TransparentCutoff"}
 Pass {
     Alphatest Greater [_Cutoff]
     AlphaToMask True
     Lighting Off
     ColorMaterial AmbientAndDiffuse
     ColorMask RGB
     SetTexture [_MainTex] {
         Combine texture * primary, texture * primary
     } 
     SetTexture [_MainTex] {
         constantColor [_Color]
         Combine previous * constant DOUBLE, previous * constant
     } 
 }
 }
 }
 
               I've tried combining the two but to no avail. Is there a way I can modify my triplanar shader to allow my custom vertex lighting?
Your answer
 
             Follow this Question
Related Questions
MODEL TURNS BLACK AFTER APPLYING TEXTURE PLS HELP 3 Answers
World coordinates for texture on procedural mesh 0 Answers
How can I prevent lights overlapping in intensity? 1 Answer
Reflective surface/texture bug in build only (works in play mode in editor) 1 Answer
How to get a sphere surface with a solid angle through script? 1 Answer