GrabPass point filtering

Hello everyone. When I make a shader with GrabPass, resulting _GrabTexture has a bilinear filtering and I can’t make what I want. How to change texture filtering inside the shader?
I haven’t found the answer in the internet and in unity documentation. Hope you can help me. :frowning:

My code:

Properties {
_Brightness ("_Brightness", Float) = 1.0
}

SubShader {

Tags { "LIGHTMODE"="Vertex" "RenderType"="Opaque" }

// Grab the screen behind the object into _GrabTexture
GrabPass {
Tags { "LIGHTMODE"="Vertex" "RenderType"="Opaque"}
}

CGPROGRAM
#pragma surface surf BlinnPhong nolightmap

uniform half4 newtex;
uniform fixed _Brightness;

sampler2D _GrabTexture;

struct Input {
half2 uv_GrabTexture;
};

You unfortunately can’t, unless you’re fine with limiting yourself to shader model 4.0+ and using Texture2D.Load(int3 location)
Your other options are replacing grab pass with the more customizable Command Buffers or simply making sure your sample locations fall on the exact center of texels, which can be best done by offseting the pixel’s position only by integer multiplies of the texel size.

I would imagine you can - but it would likely be HLSL and DirectX only, and maybe SM4.0+, but I’m not sure.

The grab texture is probably uploaded regardless, so you should be able to reference it as;

Texture2D _GrabTexture;
Texture2D _SomeOtherTexture; SamplerState sampler_SomeOtherTexture;

And use a sampler from a different texture, with the appropriate type -

_GrabTexture.Sample(sampler_SomeOtherTexture, TRANSFORM_TEX(uv_GrabTexture, _GrabTexture));

No guarantees on this! But it’s an idea to try. On the other texture, set the settings to Point filtering. If it doesn’t work, you should be able to do the same with just sampler2D _GrabTexture, but as far as I remember, it’s defined that way…

in HLSLSupport.cginc;

struct sampler2D { Texture2D t; SamplerState s; };

float4 tex2D(sampler2D x, float2 v)                { return x.t.Sample(x.s, v); }

It should be compiled into that by default, so you’d just be bypassing the support structures that imitate Nvidia’s CG language.