Hi, I've just started to work with shaders and I am completely lost.
I've now created a vertex shader (?) that uses world coordinates, but they only work in one direction and appear streched when viewed from the side ([video][1])
I've done some research already and this code should fix the issue
float3 Pos = IN.worldPos / (-1.0 * abs(_UVs));
float3 c1 = tex2D(_MainTex, Pos.yz).rgb;
float3 c2 = tex2D(_MainTex, Pos.xz).rgb;
float3 c3 = tex2D(_MainTex, Pos.xy).rgb;
float alpha21 = abs(IN.worldNormal.x);
float alpha23 = abs(IN.worldNormal.z);
float3 c21 = lerp(c2, c1, alpha21).rgb;
float3 c23 = lerp(c21, c3, alpha23).rgb;
But I can't find a way to implement this in my code.
This is what my code looks this far:
Shader "Custom/TextureMask"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_UVs("UV Scale", float) = 1.0
_CutOff("CutOff", Range(0,1)) = 0
}
SubShader
{
LOD 100
Blend One OneMinusSrcAlpha
Tags { "Queue" = "Geometry-1" } // Write to the stencil buffer before drawing any geometry to the screen
ColorMask 0 // Don't write to any colour channels
ZWrite Off // Don't write to the Depth buffer
// Write the value 1 to the stencil buffer
Stencil
{
Ref 1
Comp Always
Pass Replace
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float2 uv : TEXCOORD0;
float4 position : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 position : SV_POSITION;
float3 worldSpacePos : TEXCOORD1;
float3 normal : NORMAL;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _CutOff;
float _UVs;
v2f vert(appdata v)
{
v2f o;
o.position = UnityObjectToClipPos(v.position);
o.worldSpacePos = mul(unity_ObjectToWorld, v.position);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.worldSpacePos);
float dissolve = step(col, _CutOff);
clip(_CutOff - dissolve);
return float4(1, 1, 1, 1) * dissolve;
}
ENDCG
}
}
Also I've just realized that I get a warning "Output value 'vert' is not completely initialized at line 82 (on d3d11)" that I don't know how to fix.
Any help would be greatly appreciated!
[1]: https://www.youtube.com/watch?v=Xa56KHAACtM
↧