- Home /
Question by
mofselvi · Aug 08, 2016 at 01:09 PM ·
shadermaterialnormalmapmesh renderer
Different wall meshes which have same material look different
Hi there
This is a corner of a room. Those walls both have the same material (Triplanar Shader). And also there is a point light reflecting on the walls differently.
What I don't get: 1) It's triplanar shader. It uses world coordinates. Why does second wall look rotated? 2) Although the walls have the same material, why the shininess is different?
Here is the shader:
Shader "Custom/Triplanar PBS Ori"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo", 2D) = "white" {}
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
[Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
_BumpMap("Normal Map", 2D) = "bump" {}
_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
_MapScale("Mapping Scale", Float) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Standard vertex:vert fullforwardshadows
#pragma shader_feature _NORMALMAP
#pragma shader_feature _OCCLUSIONMAP
#pragma target 3.0
half4 _Color;
sampler2D _MainTex;
half _Glossiness;
half _Metallic;
sampler2D _BumpMap;
half _OcclusionStrength;
sampler2D _OcclusionMap;
half _MapScale;
struct Input {
float3 localCoord;
float3 localNormal;
};
void vert(inout appdata_full v, out Input data)
{
UNITY_INITIALIZE_OUTPUT(Input, data);
data.localCoord = v.vertex.xyz;
data.localNormal = v.normal.xyz;
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Calculate a blend factor for triplanar mapping.
float3 bf = normalize(abs(IN.localNormal));
bf /= dot(bf, (float3)1);
// Get texture coordinates.
float2 tx = IN.localCoord.yz * _MapScale;
float2 ty = IN.localCoord.zx * _MapScale;
float2 tz = IN.localCoord.xy * _MapScale;
// Base color
half4 cx = tex2D(_MainTex, tx) * bf.x;
half4 cy = tex2D(_MainTex, ty) * bf.y;
half4 cz = tex2D(_MainTex, tz) * bf.z;
half4 color = (cx + cy + cz) * _Color;
o.Albedo = color.rgb;
o.Alpha = color.a;
#ifdef _NORMALMAP
// Normal map
half4 nx = tex2D(_BumpMap, tx) * bf.x;
half4 ny = tex2D(_BumpMap, ty) * bf.y;
half4 nz = tex2D(_BumpMap, tz) * bf.z;
o.Normal = UnpackNormal(nx + ny + nz);
#endif
#ifdef _OCCLUSIONMAP
// Occlusion map
half ox = tex2D(_OcclusionMap, tx).g * bf.x;
half oy = tex2D(_OcclusionMap, ty).g * bf.y;
half oz = tex2D(_OcclusionMap, tz).g * bf.z;
o.Occlusion = lerp((half4)1, ox + oy + oz, _OcclusionStrength);
#endif
// Pass through the other parameters.
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "TriplanarPBSGUIOri"
}
By the way, the room model has been exported from sweethome3d.
unity-same-mat-dif-mesh-render.jpg
(376.5 kB)
Comment
I was having similar problems when doing the same thing. I spent a while working on it, and ended up fixing the rotation by moving around some of the projection axis', but I couldn't get the normals fixed.