您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

85 行
2.2 KiB

Shader "Hidden/LightweightPipeline/Sampling"
{
Properties
{
_MainTex("Albedo", 2D) = "white" {}
}
HLSLINCLUDE
#include "LWRP/ShaderLibrary/Core.hlsl"
struct VertexInput
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Interpolators
{
float4 pos : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Interpolators Vertex(VertexInput i)
{
Interpolators o;
UNITY_SETUP_INSTANCE_ID(i);
UNITY_TRANSFER_INSTANCE_ID(i, o);
o.pos = TransformObjectToHClip(i.vertex.xyz);
o.texcoord.xy = i.texcoord;
return o;
}
half4 DownsampleBox4Tap(TEXTURE2D_ARGS(tex, samplerTex), float2 uv, float2 texelSize, float amount)
{
float4 d = texelSize.xyxy * float4(-amount, -amount, amount, amount);
half4 s;
s = (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xy));
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zy));
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xw));
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zw));
return s * 0.25h;
}
ENDHLSL
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline"}
LOD 100
// 0 - Downsample - Box filtering
Pass
{
Name "Default"
Tags { "LightMode" = "LightweightForward"}
ZTest Always
ZWrite Off
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma vertex Vertex
#pragma fragment FragBoxDownsample
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
float4 _MainTex_TexelSize;
float _SampleOffset;
half4 FragBoxDownsample(Interpolators i) : SV_Target
{
half4 col = DownsampleBox4Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), i.texcoord, _MainTex_TexelSize.xy, _SampleOffset);
return half4(col.rgb, 1);
}
ENDHLSL
}
}
}