HDRP PostProcessing Customize
Unity2019.3
Forum
プルリク : 使い方や説明はプルリクのドキュメント参照
URPについての話題。いずれはURPで使えるようになるハズ。
やり方
メニューからシェーダーテンプレを作成
https://gyazo.com/53f41eb4add193c633ba2cf35369daa7
マテリアルを作ってシェーダーを紐づける
https://gyazo.com/271dc50127b485f0bf949dff3fad32f9
シーンに空のゲームオブジェクトを作ってCustomPassVolumeをアタッチする。
CustomPassにFullScreen Passを追加し、マテリアルを設定する。
https://gyazo.com/3fa6594cc06df47eb2afdd7881bfd94d
シェーダーのFullScreenPassにエフェクトを描く。
https://gyazo.com/00095dbb5a0086c953eb0f847e2ead6a
Unity2019.2
Ref.
code:Glitch.HLSL
float4 Frag(Varyings input) : SV_Target0
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord.xy;
float time = _Time.y;
// ここにエフェクトを書く。
// 今回は適当にグリッチしてる
float4 outColor = LOAD_TEXTURE2D_X(_InputTexture, uv * _ScreenSize.xy);
float n = sin(floor(uv.y * 23. + time * 3.)) * sin(floor(uv.y * 17. + time * 39.));
if (frac(n * 170.) < _Threshold) {
uv.x = frac(uv.x + n * _Intensity);
uv.x = frac(uv.x + n * 3.);
uv.y = frac(uv.x + n * 9.);
uv.x += frac(4.*uv.y + n * 81.);
uv.y *= frac(16.*uv.y + n * 9.);
outColor = LOAD_TEXTURE2D_X(_InputTexture, uv * _ScreenSize.xy);
outColor += _OverlayColor * _OverlayColor.a;
}
return outColor;
}
code:Mosaic.HLSL
float4 Frag(Varyings input) : SV_Target0
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 m = _ScreenSize.xy / min(_ScreenSize.x, _ScreenSize.y);
float2 uv = input.texcoord.xy;
uv = floor(m * _Size * uv) / (m * _Size);
float4 outColor = LOAD_TEXTURE2D_X(_InputTexture, uv * _ScreenSize.xy);
return outColor;
}
code:RGBShift.HLSL
float4 Frag(Varyings input) : SV_Target0
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord.xy;
float time = _Time.y;
float4 outColor = LOAD_TEXTURE2D_X(_InputTexture, uv * _ScreenSize.xy);
float4 outColorL = LOAD_TEXTURE2D_X(_InputTexture, repUV(uv + float2(_Shift/1000., .0)) * _ScreenSize.xy);
float4 outColorR = LOAD_TEXTURE2D_X(_InputTexture, repUV(uv + float2(-_Shift/1000., .0)) * _ScreenSize.xy);
return float4(outColor.r, outColorL.g, outColorR.b, outColor.a);
}
code:Syuuchuusen.HLSL
float4 Frag(Varyings input) : SV_Target0
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord.xy;
float2 ruv = 2. * input.texcoord.xy - 1.;
float r = length(ruv);
r = 0.7 * r - 0.7;
float a = atan2(ruv.y, ruv.x);
a = abs(cos(50. * a) + sin(20. * a));
float d = a - r;
float n = smoothstep(0.1, 0.4, saturate(d));
float4 outColor = LOAD_TEXTURE2D_X(_InputTexture, uv * _ScreenSize.xy);
outColor.rgb *= n;
return outColor;
}
code:Gaussianblur.HLSL
Shader "Hidden/GaussianBlur"
{
SubShader
{
Tags{ "RenderPipeline" = "HDRenderPipeline" }
Pass
{
ZWrite On ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" TEXTURE2D_X(_InputTexture);
float4 _OverlayColor;
float _GaussLoopCount;
float _Bloom;
float _Radius;
struct Attributes
{
uint vertexID : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
Varyings Vert(Attributes input)
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID);
return output;
}
float4 Frag(Varyings input) : SV_Target0
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord.xy;
int count = int(_GaussLoopCount / 100.);
float e_step_x = 1.0 / _ScreenSize.x;
float e_step_y = 1.0 / _ScreenSize.y;
float bloom = _Bloom;
float radius = _Radius;
int steps = int(min(radius * 0.7, sqrt(radius) * PI));
float r = radius / steps;
float t = bloom / (steps * 2 + 1) / 2.;
float4 outColor = LOAD_TEXTURE2D_X(_InputTexture, uv * _ScreenSize.xy)*t;
float v = .0;
for (float j = 1; j <= count; j++) {
v = .5*(cos(j / (_GaussLoopCount + 1.) / PI) + 1.);
outColor += LOAD_TEXTURE2D_X(_InputTexture, float2(uv.x + j * e_step_x * r, uv.y)* _ScreenSize.xy) * v * t;
outColor += LOAD_TEXTURE2D_X(_InputTexture, float2(uv.x - j * e_step_x * r, uv.y)* _ScreenSize.xy) * v * t;
}
for (float k = 1; k <= count; k++) {
v = .5*(cos(k / (_GaussLoopCount + 1.) / PI) + 1.);
outColor += LOAD_TEXTURE2D_X(_InputTexture, float2(uv.x, uv.y + k * e_step_y * r)* _ScreenSize.xy) * v * t;
outColor += LOAD_TEXTURE2D_X(_InputTexture, float2(uv.x, uv.y - k * e_step_y * r)* _ScreenSize.xy) * v * t;
}
return outColor;
}
ENDHLSL
}
}
Fallback Off
}