Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/Triplanar"
- {
- Properties
- {
- _HighlightedColor ("Circle Highlighed Color", Color) = (1,1,1,1)
- _NormalColor("Circle Color", Color) = (1,1,1,1)
- _WallTex ("Wall texture", 2D) = "white" {}
- _FloorTex ("Floor texture", 2D) = "white" {}
- _Glossiness ("Smoothness", Range(0,1)) = 0.5
- _Metallic ("Metallic", Range(0,1)) = 0.0
- }
- SubShader
- {
- Tags { "RenderType"="Opaque" }
- LOD 200
- CGPROGRAM
- // Upgrade NOTE: excluded shader from DX11, OpenGL ES 2.0 because it uses unsized arrays
- #pragma exclude_renderers d3d11 gles
- // 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 _WallTex;
- sampler2D _FloorTex;
- struct Input
- {
- float3 worldPos;
- float3 worldNormal;
- };
- half _Glossiness;
- half _Metallic;
- fixed4 _HighlightedColor;
- fixed4 _NormalColor;
- //int _ArgCount = 0;
- //float4 _Positions[100];
- //float _Radii[100];
- // 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)
- //credit to @minionsart on twitter for her triplanar shading implementation
- void surf (Input IN, inout SurfaceOutputStandard o)
- {
- float3 xCol = tex2D(_WallTex, IN.worldPos.yz);
- float3 yCol = tex2D(_FloorTex, IN.worldPos.xz);
- float3 zCol = tex2D(_WallTex, IN.worldPos.xy);
- //for (int i = 0; i < _ArgCount; i++)
- //{
- // float distanceToCircle = length(IN.worldPos.xz - _Positions[i].xz);
- // yCol += (distanceToCircle < _Radii[i]) * _NormalColor * distanceToCircle / _Radii[i];
- //}
- float3 blendedNormal = saturate(pow(IN.worldNormal*1.4, 4.));
- fixed3 endColor = lerp(zCol, yCol, blendedNormal.y);
- endColor = lerp(endColor, xCol, blendedNormal.x);
- o.Albedo = float3(1.0f,1.0f,1.0f);
- o.Metallic = _Metallic;
- o.Smoothness = _Glossiness;
- o.Alpha = 1.0;
- }
- ENDCG
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement