Question by
DrunkBearzz · Feb 18, 2017 at 07:03 PM ·
shadertexture
How can I apply texture through shader on sprite without streching?
So I have my normal sprite with material component. My material is using my own "Image Effect Shader".
Shader "Entity/entity_eye"
{
Properties
{
_MainTex ("Main Texture", 2D) = "white" {}
_EyeTex ("Eye texture", 2D) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
sampler2D _EyeTex;
fixed4 frag (v2f i) : SV_Target
{
fixed4 noise = tex2D(_EyeTex, i.uv);
fixed4 fin = tex2D(_MainTex, i.uv);
return noise;
}
ENDCG
}
}
}
For now I only need to get my input texture to be the size of my sprite. What I get is on picture 3 and what I want is on picture 4. I'm not sure could I take sprite size as input parameter for shader and then inside shader adjust my texture nor how to achieve that.
I hope you understand what I want to do.
img.png
(24.9 kB)
Comment