theres any way to make a shader that make a tileable texture with normal map applied on it too? without using triplanar… i have the albedo already working, but i need the normal map working in the same way too:
Shader "Custom/SurfaceShaderWithNormalTexture" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_NormalMap ("Normal Map", 2D) = "bump" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _NormalMap;
struct Input {
float2 uv_MainTex;
float3 worldNormal;
float3 worldPos;
};
void surf (Input IN, inout SurfaceOutput o) {
// Sample the textures
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
// Use normal map to modify the normal
float3 normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex));
normal = normalize(normal * 2.0 - 1.0); // Transform from [0,1] to [-1,1]
normal = normalize(mul(normal, (float3x3)unity_WorldToObject)); // Convert to object space
// Calculate projected UV
float3 worldNormal = normalize(IN.worldNormal);
float3 worldPos = IN.worldPos;
float3 projectedPos = worldPos + worldNormal * 0.1; // Adjust projection factor as needed
float2 projectedUV;
if (abs(worldNormal.x) > abs(worldNormal.y) && abs(worldNormal.x) > abs(worldNormal.z)) {
// If the normal is primarily in the X axis
projectedUV = float2(projectedPos.z, projectedPos.y);
} else if (abs(worldNormal.y) > abs(worldNormal.x) && abs(worldNormal.y) > abs(worldNormal.z)) {
// If the normal is primarily in the Y axis
projectedUV = float2(projectedPos.x, projectedPos.z);
} else {
// If the normal is primarily in the Z axis
projectedUV = float2(projectedPos.x, projectedPos.y);
}
// Apply the final color
c = tex2D (_MainTex, projectedUV);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}