unity3d - 有没有办法在 Unity 3D 对象上重复纹理而不指定瓷砖数量?
问题描述
我正在尝试使用相同大小的纹理/相同材质制作两个不同的对象,这应该是重复的;无需为我创建的每个新对象制作新材料。下面是我想要实现的一个例子。
两个对象上的材料 A 看起来应该是一样的,右边的立方体代表它应该看起来的样子。
解决方案
这是固定的并且有效!
我必须制作一个 Unity 着色器,它使用世界空间而不是本地空间(默认)。这是我使用的着色器的代码:
Shader "Legacy Shaders/Diffuse - Worldspace" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Scale("Texture Scale", Float) = 1.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
fixed4 _Color;
float _Scale;
struct Input {
float3 worldNormal;
float3 worldPos;
};
void surf (Input IN, inout SurfaceOutput o) {
float2 UV;
fixed4 c;
if (abs(IN.worldNormal.x) > 0.5) {
UV = IN.worldPos.yz; // side
c = tex2D(_MainTex, UV* _Scale); // use WALLSIDE texture
}
else if (abs(IN.worldNormal.z) > 0.5) {
UV = IN.worldPos.xy; // front
c = tex2D(_MainTex, UV* _Scale); // use WALL texture
}
else {
UV = IN.worldPos.xz; // top
c = tex2D(_MainTex, UV* _Scale); // use FLR texture
}
o.Albedo = c.rgb * _Color;
}
ENDCG
}
Fallback "Legacy Shaders/VertexLit"
}
固定版本:
我使用的知识来源:
@derHugo 让我走上了正轨,谢谢!!
推荐阅读
- angular - Socket.io:总是无效的命名空间
- python - How can I display and download an image which is located outside of the static folder?
- ios - 如何在 Swift 中确认对 Identifiable 协议的枚举?
- ios - AppCenter for iOS 上缺少符号
- javascript - 在Angular中单击编辑时内联编辑表格行
- java - 将 txt 文件的重复列添加到 Java 中的列表中
- excel - How to just identify (and not remove) duplicates in excel column?
- java - 如何在 GSON 中支持多语言(在 Json 和 Java 对象之间)?
- laravel - Laravel Artisan 命令的 PHPUnit 测试,无需在内部实例中调用外部 API(依赖注入)
- c# - SSIS中for循环下的脚本任务每个容器都需要大量时间才能完成