Files
ichni_Creator_Studio/Assets/ThemeBundles/DepartureToMultiverse/Shders/PixelatePass.hlsl
SoulliesOfficial e91f378989 像素化
2025-06-30 09:25:29 -04:00

50 lines
1.2 KiB
HLSL

#ifndef PIXELATE_PASS_INCLUDED
#define PIXELATE_PASS_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
TEXTURE2D(_SourceTexture);
SAMPLER(sampler_SourceTexture);
float4 _SourceTexture_TexelSize;
float _PixelateStrengthX;
float _PixelateStrengthY;
struct Varyings
{
float4 positionCS_SS : SV_POSITION;
float2 screenUV : VAR_SCREEN_UV;
};
Varyings PixelatePassVert(uint vertexID : SV_VertexID)
{
Varyings output;
output.positionCS_SS = float4(
vertexID <= 1 ? -1.0 : 3.0,
vertexID == 1 ? 3.0 : -1.0,
0.0, 1.0
);
output.screenUV = float2(
vertexID <= 1 ? 0.0 : 2.0,
vertexID == 1 ? 2.0 : 0.0
);
if (_ProjectionParams.x < 0.0)
{
output.screenUV.y = 1.0 - output.screenUV.y;
}
return output;
}
half4 PixelatePassFrag(Varyings input) : SV_Target
{
float2 screenUV = input.screenUV;
float2 strength = float2(_PixelateStrengthX, _PixelateStrengthY);
float2 uvScaled = screenUV * strength;
float2 uvFloor = floor(uvScaled);
float2 uvCenter = uvFloor + 0.5;
float2 uvPixelated = uvCenter / strength;
return SAMPLE_TEXTURE2D(_SourceTexture, sampler_SourceTexture, uvPixelated);
}
#endif