hi guys ive tried everything i can but my shader is just not reading any values i send to it. heres me shader below:
Shader "Custom/final_shader"{
properties{
_MainTex("MainTexture", 2D) = "white" {}
_Tint("Tint", Color) = (1,1,1,1)
// _uvposx ("uvposx", float) = 0
//_uvposy ("uvposy", float) = 0
_uvpos ("uvpos", Color ) = (0,0,0,0)
}
SubShader{
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _DETAIL_MULX2 //_UVPOS ON
#include "UnityCG.cginc"
float4 _Tint;
float _uvposx;
float _uvposy;
float4 _uvpos;
float4 vert( float4 position : POSITION, out float3 localPosition : TEXCOORD0 ) : SV_POSITION {
localPosition.xyz = position.xyz ;
_uvpos.x = _uvposx;
_uvpos.y = _uvposy;
return mul(UNITY_MATRIX_MVP, position);
}
float4 frag( float4 position : SV_POSITION, float3 localPosition : TEXCOORD0 ) : SV_TARGET {
return float4(localPosition.x , localPosition.y, localPosition.z , 1) * _Tint ;
}
ENDCG
}
}
}
and heres my c# code that sets the floats, ive tried messing around with keywords, global variables and floats vs vectors and i get nothing. please help.
Texture2D tex = rend.material.mainTexture as Texture2D;
Texture2D texrep = rend.material.mainTexture as Texture2D;
Vector2 pixelUV = hit.textureCoord;
pixelUV.x *= texrep.width;
pixelUV.y *= texrep.height;
cube = GameObject.FindObjectOfType(typeof (lightcontroller)) as lightcontroller;
// cube.mat.SetVector("_AltTex", new Vector2(pixelUV.x, pixelUV.y));
cube.mat.EnableKeyword("_uvpos_ON");
cube.mat.EnableKeyword("_UVPOSX");
cube.mat.EnableKeyword("_UVPOSY_ON");
Shader.SetGlobalFloat("_uvposx", pixelUV.x);
cube.mat.SetFloat("_uvposx", pixelUV.x);
cube.mat.SetFloat("_uvposy", pixelUV.y);
cube.mat.SetVector(" _uvpos", new Vector2(pixelUV.x , pixelUV.y));
cube.mat.SetVector(" _Tint", new Vector4(pixelUV.x, pixelUV.y, 0, 0));
// tex.SetPixel((int)pixelUV.x, (int)pixelUV.y,Color.black);
// tex.Apply();
Debug.Log(pixelUV.x);
Debug.Log(pixelUV.y);
}
}