Ok maybe i'm missing something because its getting late and i've been programming now for about 72 hours straight (minus a nap or 2) ...
I'm trying to write a shader for unity that will apply triplanar texturing to a mesh, here's my shader code ...
Shader "My Shaders/TriPlanar" {
Properties {
Tex1 ("Texture 1", 2D) = "white" {}
Tex2 ("Texture 2", 2D) = "white" {}
Tex3 ("Texture 3", 2D) = "white" {}
}
SubShader {
Pass {
CGPROGRAM
#pragma target 3.0
#pragma glsl
#pragma vertex Vert
#pragma fragment Frag
#include "UnityCG.cginc"
sampler2D Tex1;
sampler2D Tex2;
sampler2D Tex3;
struct data
{
float4 position : POSITION;
float3 normal;
float4 uv : TEXCOORD0;
};
data Vert(appdata_base v)
{
data res;
res.position = mul( UNITY_MATRIX_MVP, v.vertex);
res.normal = v.normal;
res.uv = v.texcoord;
return res;
}
float4 Frag( data input ) : COLOR
{
float4 result;
float norX = abs(input.normal.x);
float norY = abs(input.normal.y);
float norZ = abs(input.normal.z);
float total = (norX + norY + norZ);
norX /= total;
norY /= total;
norZ /= total;
// get sample from tex1 and apply norX amount to pixel color
float4 texXZ = tex2D(Tex1, input.uv.xz);
float4 texXY = tex2D(Tex1, input.uv.xy);
float4 texYZ = tex2D(Tex1, input.uv.yz);
result = (texXZ * norX);
// get sample from tex2 and blend norY amount
texXZ = tex2D(Tex2, input.uv.xz);
texXY = tex2D(Tex2, input.uv.xy);
texYZ = tex2D(Tex2, input.uv.yz);
result += (texXY * norY);
// get sample from tex3 and blend norZ amount
texXZ = tex2D(Tex3, input.uv.xz);
texXY = tex2D(Tex3, input.uv.xy);
texYZ = tex2D(Tex3, input.uv.yz);
result += (texYZ * norZ);
return result;
}
ENDCG
}
}
}
The problem is that I only get 1 pixels worth of sample from the texture so I end up ultimately just "colouring" the verts instead of actually texturing them.
How do I tell my shader to build a colour that results in the texture being drawn not just 1 corner pixels worth of it?
EDIT:
The code in the shader is an implementation of a vertex and fragment but the fragment part came from a pixel shader ... i don't understand the difference there (my first problem)
I can't say i've ever written a fragment shader before (a second problem)
Also i'm not setting any uv's in my cpu code (a problem when I come to use my shader but i'll face that later) ... odd that I get anything at all to be honest, however I'm applying this to a cube game object generated by unity and I get strips of texture so i can't be that far off.