thx @bgolus
I tried many things, but can’t figure-out how to project screen-render to rasterized uvs on geometry.
So I just forgot the idea and the flexibility of playing with data-instance that is the vertex-color to simply filter-out my pixel-reduction by a mask properly edited (need a certain step in tones + by toning a certain minimal resolution [3232,6464,128*128]).
So I’ll create more duplicate of material to move the mask around.
I’m not using the text2lod to use mips, I prefer having the control of moving “underneath” the albedo that is “filtered” by the UV playing afterward.
the shader if someone would like to play with the idea.
Shader "DaPrato/Surface_PixelReduction"
{
Properties{
_Color("Main Color", Color) = (1,1,1,0.5)
_MainTex("Texture", 2D) = "white" {}
_OffetX_c("UVs Offset X", float) = 0
_OffetY_c("UVs Offset Y", float) = 0
[NoScaleOffset]_PixelUV("PixelUV Texture", 2D) = "white" {}
[MaterialToggle]_NoMask("No Pixel Mask Used", range(0,1)) = 0
_OffetX_m("UVs Offset X", float) = 0
_OffetY_m("UVs Offset Y", float) = 0
_ScalePixel("Pixel Scale (fit well ^2)", range(1,64)) = 2
[Toggle(ROUNDTO2)]_RoundToPow2("Round to ^2", float) = 0
[Header(Debug)]
[MaterialToggle]_DebugMask("Debug: Show Pixel Mask", range(0,1)) = 0
[MaterialToggle]_DebugSource("Debug: Show Albedo Original", range(0,1)) = 0
}
Subshader{
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
#pragma shader_feature ROUNDTO2
struct Input {
float4 vertcolor : COLOR; // Vertex Color
float2 uv_MainTex;
};
float4 _Color;
sampler2D _MainTex;
sampler2D _PixelUV;
float _ScalePixel;
float _DebugMask, _DebugSource;
float _RoundToPow2;
float _NoMask;
float _OffetX_c, _OffetY_c;
float _OffetX_m, _OffetY_m;
float scalePixel;
float round2(float scale)
{
if (scale >= 1 && scale < 4) { scale = 1; }
if (scale >= 2 && scale < 4) { scale = 2; }
if (scale >= 4 && scale < 8) { scale = 4; }
if (scale >= 8 && scale < 12) { scale = 8; }
if (scale >= 12 && scale < 24) { scale = 16; }
if (scale >= 24 && scale < 42) { scale = 32; }
if (scale >= 42) { scale = 64; }
return scale;
}
void surf(Input IN, inout SurfaceOutput o)
{
#ifdef ROUNDTO2
scalePixel = round2(_ScalePixel);
#else
scalePixel = _ScalePixel;
#endif
float2 uv;
float f;
float halfpixel;
float2 uvOffset_c = float2(_OffetX_c *0.1, _OffetY_c*0.1);
float2 uvOffset_m = float2(round(_OffetX_m *0.1*32)/32, round(_OffetY_m*0.1*32)/32);
float4 pixelUV = tex2D(_PixelUV, IN.uv_MainTex + uvOffset_m);
f = round(lerp(pixelUV.r, 1, _NoMask) * 8) * scalePixel;
halfpixel = (1 / f) * 0.5;
uv = (round((IN.uv_MainTex - halfpixel) * f) / f);
o.Albedo = lerp(lerp(tex2D(_MainTex, uv + uvOffset_c), pixelUV.r, _DebugMask), tex2D(_MainTex, IN.uv_MainTex),_DebugSource);
}
ENDCG
}
Fallback "Diffuse"
}
*** Yes I left a lerp in a lerp for debug, you can just clean it anyway.
textures used in demo.
https://drive.google.com/drive/folders/11WlTYPq-vB-MDz5-0E7vB2qXIx9CVZb8?usp=sharing