I have a texture which is wrapped around a model with the proper UV data and what I want to do is sample another texture using the world space coordinates of the point that is being textured and multiply the resulting rgb value by the texture value.
Is this possible on iOS/android or am I reaching too far? The shader syntax in unity is very unfamiliar to me, this is what I have so far which I assume would work but it isn’t as evidenced by the screenshot to follow:
Shader "Custom/CloudShader"{
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_CloudTex("Cloud", 2D) = "white" {}
_TextureScale ("Texture Scale", Float) = 1
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float2 texcoord : TEXCOORD0;
float3 uv_pos : TEXCOORD1;
};
uniform float4 _MainTex_ST;
uniform float _TextureScale;
v2f vert (appdata_base v) {
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
o.texcoord = v.texcoord;
o.uv_pos = mul (_Object2World, v.vertex).xyz * 1.0f/_TextureScale;
return o;
}
uniform sampler2D _MainTex;
uniform sampler2D _CloudTex;
float4 frag(v2f i) : COLOR
{
float4 baseCol = tex2D(_MainTex, i.texcoord);
float4 cloudCol = tex2D(_CloudTex, i.uv_pos.xy);
return baseCol * cloudCol;//tex2D(_MainTex, i.texcoord);
}
ENDCG
}
}
}
I’m using a grass texture which is overlayed by the grid texture as the ‘cloud’ texture.
The bent lines you see should all be uniform in size and parallel, they shouldn’t be at angles the way they are.