unity3d - 如何使用 MixedRealityToolkit 着色器和圆角平铺纹理?
问题描述
我正在尝试使用 Unity 中的 MRTK 制作动画材料。目标是使效果看起来像从一个圆圈开始并将纹理传播到平面的其余部分。
现在我使用 MixedRealityToolkit 标准着色器并使用圆角选项。我制作了一个动画:
我的问题是我无法平铺纹理以减小纹理的大小并重复它。同样对于非方形物体,纹理被拉伸并且不是很好。
如果我尝试更改平铺设置,则不会重复纹理(纹理在“重复模式”中很好,当我取消选中圆角选项时它可以工作)
(如果我显示 Unity 选择轮廓,我得到了重复的纹理,但它没有显示......)
有没有人有一个好主意来使用 MRTK 着色器或如何为此效果编写特定的着色器?
解决方案
我找到了一个解决方案,编写自己的着色器:
Shader "Custom/testShader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_ForegroundMask("Foreground Mask", 2D) = "white" {}
_RadiusSize("Radius size", Range(0,2)) = 0
_BorderWidth("Smooth Edge width", Range(0,1)) = 0.5
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags {"Queue"="Transparent" "RenderType"="Transparent" }
LOD 200
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows alpha:fade
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _ForegroundMask;
struct Input
{
float2 uv_MainTex;
float2 uv_ForegroundMask;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
float _RadiusSize;
float _BorderWidth;
// 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)
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed2 dist;
dist.x = IN.uv_ForegroundMask.x - 0.5;
dist.y = IN.uv_ForegroundMask.y - 0.5;
fixed circle= 1.0 - smoothstep(_RadiusSize-(_RadiusSize * _BorderWidth),_RadiusSize+(_RadiusSize * _BorderWidth), dot(dist,dist)*4.0);
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a * circle;
}
ENDCG
}
FallBack "Diffuse"
}
推荐阅读
- javascript - 带规则的递增数字输入到步骤
- node.js - 查找帐户用户已登录 - Mongoose
- git - 如何使用 git 将代码更改为子模块?
- python - 使用堆积在 Json、Python 和 Postgresql 中的第二行更新表的一行
- java - 如何巧妙地绕过 NullPointerException
- typescript - 如何从 Typescript 模块中的子命名空间导入单个类型、类、常量或枚举?
- html - 如何在弹性项目行内制作弹性列?
- c - 如何有效地将位位置提取为C中的值
- mysql - MySQL 基于 information_schema 的动态行哈希
- mysql - 您如何将 pandas 列中的所有值转换为 MySQL 数据库中的值