Hi, I did simple shader which should ignore UVS and map topdown texture based on vertex position. All works except one thing normals. It seems that they are rotated by object rotation somewhere out of my code. Because normal before put into o.Normal looks without seems if put for debug into albedo and also o.Normals seems without seems… I also tried to make rotation clockwise the object rotation, result is better but not absolutely OK, and also scale started affecting it. So I am putting there code without that feature. If you have an idea how to make any trick to say do not rotate normals. I would be very glad :). (note it is not triplanar it is only for topdown surfaces and it is meant to have no seems between objects with different rotation)
Shader "Custom/TopDown Global Map" {
Properties
{
_Color("Color", Color) = (1,1,1,1)
[NoScaleOffset]_MainTex("Albedo", 2D) = "white" {}
[NoScaleOffset]_MetallicGlossMap("MetallicMap", 2D) = "white" {}
_Glossiness("Smoothness", float) = 0.5
_Metallic("Metallic", float) = 0.0
[NoScaleOffset]_BumpMap("Normal Map", 2D) = "bump" {}
_BumpScale("Scale NormalMap", Float) = 1.0
[NoScaleOffset]_OcclusionMap("Occlusion", 2D) = "white" {}
_OcclusionStrength("Occlusion Strength",float) = 1.0
_Repeatance("Repeatance",float) = 1.0
}
SubShader {
Tags { "RenderType"="Opaque" "DisableBatching" = "true"}
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard vertex:vert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex,_MetallicGlossMap,_BumpMap,_OcclusionMap;//,_EmissionMap;
struct vertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
};
struct Input {
float3 worldPos;
float4 vert;
};
half _Glossiness,_Metallic,_OcclusionStrength,_BumpScale,_Repeatance;
fixed4 _Color;
void vert (inout vertexInput v, out Input o) {
o.worldPos= mul(unity_ObjectToWorld,v.vertex).xyz;
o.vert = v.vertex;
}
void surf (Input IN, inout SurfaceOutputStandard o) {
float2 uv = IN.worldPos.xz*_Repeatance;
fixed4 c = tex2D (_MainTex, uv) * _Color;
o.Albedo = c.rgb;
fixed4 m =tex2D(_MetallicGlossMap, uv);
o.Occlusion=tex2D(_OcclusionMap, uv)*_OcclusionStrength;
half3 nrm =UnpackScaleNormal(tex2D(_BumpMap, uv),_BumpScale);
o.Normal=nrm;
o.Metallic =m.a*_Metallic;
o.Smoothness = _Glossiness*m.rgb;
}
ENDCG
}
FallBack "Diffuse"
}
There is how shader looks, you can see lighting comes from different dirrections as these 3 cubes have 3 different rotations.
There is unpacked Normal map as albedo - no visible problem
o.Normal as albedo - again no problems… so the problem has to be somewhere in any default shader pass…
Thank you for your advices in forward