Think about minecraft - all the textures in minecraft have a very nice crisp pixelated look. Well, I'm trying to write a shader that will do this but it appears "sampler2d" returns some sort of interpolation between pixels of the underlying texture. I'm pretty new to shader writing and I'm not even sure if it can be done - but I'm hoping to get a nice crisp blow up of small textures rather than a blurry one like this:
If anyone knows a way to make a shader crisp rather than interpolated like this (using Unity), I'd be thrilled to know as this hitch is pretty detrimental to what I'm trying to accomplish...
Here's the subshader as it is right now (it's skipping all the light calculations and just outputting the sampler as I'm just trying to resolve the blurry texture sampling):
SubShader
{
Pass
{
Tags { "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
//user
uniform float _BlendVal;
uniform sampler2D _DiffuseTex;
uniform sampler2D _NMTex;
uniform sampler2D _PixelMap;
uniform float4 _DiffuseTex_SV;
uniform float4 _SpecColor;
uniform float _SpecIntensity;
uniform float4 _RimColor;
uniform float _RimIntensity;
uniform float _RimCoefficient;
//unity
uniform float4 _LightColor0;
struct vI
{
float4 pos : POSITION;
float3 norm : NORMAL;
float4 uv : TEXCOORD0;
};
struct vO
{
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
float3 worldPos : TEXCOORD1;
float3 normDir : TEXCOORD2;
};
vO vert(vI i)
{
vO o;
o.uv = i.uv;
o.worldPos = mul(_Object2World, i.pos).xyz;
o.normDir = normalize(mul( float4(i.norm, 0.0), _World2Object).xyz);
o.pos = mul(UNITY_MATRIX_MVP, i.pos);
return o;
}
float4 frag(vO i) : COLOR
{
float3 lightDir;
float3 viewDir = normalize( i.worldPos - _WorldSpaceCameraPos.xyz);
float atten;
float3 normDir = normalize(i.normDir);
float4 RimLight;
float4 DiffuseLight;
float4 SpecularLight;
float2 UVCoord = i.uv.xy;
float4 test = tex2D(_PixelMap, UVCoord);
//float4 Clrx0 = lerp(
//Directional Light
if(_WorldSpaceLightPos0.w == 0)
{
lightDir = normalize(_WorldSpaceLightPos0.xyz);
atten = dot(lightDir, normDir);
}
//point light
else
{
float3 dist = i.worldPos.xyz - _WorldSpaceLightPos0.xyz;
lightDir = normalize(dist);
atten = (1/length(dist))*(dot(lightDir, normDir));
}
DiffuseLight = atten * _LightColor0;
SpecularLight = atten * _LightColor0 * _SpecColor * _SpecIntensity * pow(max(0.0,dot(reflect(lightDir, normDir), viewDir)), 1)*(1-tex2D(_DiffuseTex, i.uv.xy).w);
RimLight = atten * _LightColor0 * _RimColor * _RimCoefficient* pow((1-saturate(dot(-viewDir, normDir))),_RimIntensity)*saturate(dot(lightDir, normDir));
float4 totalLight = DiffuseLight + SpecularLight + RimLight;
float4 fin = float4(UVCoord.xy,0,0);
return test; ///Fin * totalLight;
}
ENDCG