o.uv[4] = uv + _MainTex_TexelSize.xy * half2(0, 0); o.uv[5] = uv + _MainTex_TexelSize.xy * half2(1, 0); o.uv[6] = uv + _MainTex_TexelSize.xy * half2(-1, 1); o.uv[7] = uv + _MainTex_TexelSize.xy * half2(0, 1); o.uv[8] = uv + _MainTex_TexelSize.xy ...
#if UNITY_UV_STARTS_AT_TOP if (_MainTex_TexelSize.y < 0) uv.y = 1 - uv.y; #endif o.uv[1] = uv + _MainTex_TexelSize.xy * half2(1,1) * _SampleDistance; o.uv[2] = uv + _MainTex_TexelSize.xy * half2(-1,-1) * _SampleDistance; o.uv[3] = uv + _MainTex_TexelSize....
o.left = o.uv + half2(-1, 0) * _MainTex_TexelSize.xy * _OutlineWidth; o.right = o.uv + half2(1, 0) * _MainTex_TexelSize.xy * _OutlineWidth; o.up = o.uv + half2(0, 1) * _MainTex_TexelSize.xy * _OutlineWidth; o.down = o.uv + half2(0, -1) * _MainTex_TexelSize....
sampler2D _MainTex; //内置的变量,纹理中的单像素尺寸 float4 _MainTex_TexelSize; //主颜色 float4 _Color; //描边强度 float _power; //描边颜色 float4 _lineColor; // ---【背面-顶点着色器】--- v2f vert_back (appdata v) { v2f o; //法线方向 v.normal = normalize(v.normal); //顶...
CGPROGRAM#include"UnityCG.cginc"#pragmavertex vert#pragmafragment fragsampler2D _MainTex; uniform half4 _MainTex_TexelSize;//fixed _EdgeOnly;fixed4 _EdgeColor;//fixed4 _BackgroundColor;fixed _Gradient;structv2f{float4 pos : SV_POSITION;
float2 _MainTex_TexelSize; sampler2D _SceneTex; fixed4 _Color; float _Width; int _Iterations; #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; };
就可以判断是否是DX系列平台,正常的OpenGL从下到上的纹素为正,但是到DX下改成从下到上,如果主纹理的uv值y方向反了,那么这个_MainTex_TexelSize.y就小于0。我们通过这样一个判断语句,就可以自己处理平台之间的差异了。上面的shader中就是增加了这样一句判断,就解决了在PC上出现反向的问题。
_MainTex ("Base (RGB)", 2D) = "white" {} //模糊图像时使用的参数 _BlurSize ("Blur Size", Float) = 1.0 } SubShader { CGINCLUDE #include "UnityCG.cginc" sampler2D _MainTex; half4 _MainTex_TexelSize; sampler2D _CameraDepthTexture; ...
if (_MainTex_TexelSize.y < 0) uv.y = 1 - uv.y; #endif 其中UNITY_UV_STARTS_AT_TOP 用于判断当前平台是否是DirectX 类型的平台,而当在这样的平台下卡其了抗锯齿后,主纹理的纹素大小在竖直方向上会变成负值,以便我们对主纹理进行正确的采样。因此,我们可以通过判断_MainTex_TexelSize.y 是否小于 0 来校...
(_MainTex,uv_changed);#ifUNITY_TEXTURE_ALPHASPLIT_ALLOWEDif(_AlphaSplitEnabled)color.a=tex2D(_AlphaTex,uv).r;#endif//UNITY_TEXTURE_ALPHASPLIT_ALLOWEDreturncolor;}boolCheckOriginalSpriteTexture(float2 uv,bool ifZero){float thicknessX=_Thickness/_MainTex_TexelSize.z;float thicknessY=_Thickness/_...