阶段性完成
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f51589a19ab9f8f46834348da6cf70d0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
#include "./common.hlsl"
|
||||
#include "./fullscreen.hlsl"
|
||||
|
||||
float2 _Offset;
|
||||
float2 _TargetSize;
|
||||
float4 _CropRegion;
|
||||
half3 _BackgroundColor;
|
||||
|
||||
int _IsLast;
|
||||
// int _IsUp;
|
||||
|
||||
#define BlurVertexInput FullScreenVertexInput
|
||||
|
||||
struct BlurVertexOutput
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
BlurVertexOutput VertBlur(BlurVertexInput v)
|
||||
{
|
||||
BlurVertexOutput o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
float4 posCS;
|
||||
float2 screenUV;
|
||||
GetFullScreenVertexData(v, posCS, screenUV);
|
||||
|
||||
o.position = half4(posCS.xy, 0.0, 1.0);
|
||||
|
||||
o.texcoord = UnCropUV(screenUV, _CropRegion);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 FragBlur(BlurVertexOutput i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
|
||||
half2 dirs[] = {
|
||||
half2(-1, -1),
|
||||
half2(1, -1),
|
||||
half2(1, 1),
|
||||
half2(-1, 1),
|
||||
};
|
||||
#if !USE_EXTRA_SAMPLE
|
||||
half weight0 = 1.0h / 4.0h;
|
||||
#else
|
||||
half weight1 = 1.0h / 5.0h;
|
||||
half weight0 = (1.0h - weight1) / 4.0h;
|
||||
#endif
|
||||
|
||||
half4 o = 0;
|
||||
for (int j = 0; j < 4; ++j)
|
||||
o += SAMPLE_SCREEN_TEX(_MainTex, i.texcoord + dirs[j] * _Offset) * weight0;
|
||||
|
||||
#if USE_EXTRA_SAMPLE
|
||||
o += SAMPLE_SCREEN_TEX(_MainTex, i.texcoord) * weight1;
|
||||
#endif
|
||||
|
||||
#if BACKGROUND_FILL_COLOR
|
||||
o.rgb = lerp(_BackgroundColor, o.rgb, o.a);
|
||||
o.a = 1.0h;
|
||||
#endif
|
||||
|
||||
// dithering every pass is more correct, but combined with the low sample rate and cheap pattern introduces too much error
|
||||
if (_IsLast)
|
||||
o = dither(o, i.texcoord * _TargetSize);
|
||||
|
||||
return o;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ba876e9f43e4360a9d4ee63c412ce07
|
||||
timeCreated: 1729669244
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Shaders/EfficientBlur.hlsl
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
Shader "Hidden/EfficientBlur"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Cull Off ZWrite Off ZTest Always Blend Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
#pragma vertex VertBlur
|
||||
#pragma fragment FragBlur
|
||||
#pragma multi_compile_local BACKGROUND_FILL_NONE BACKGROUND_FILL_COLOR
|
||||
#pragma multi_compile_local _ USE_EXTRA_SAMPLE
|
||||
|
||||
#include "interop_birp.cginc"
|
||||
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
|
||||
#include "EfficientBlur.hlsl"
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
FallBack Off
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12e87e7c7fde8e74db9f75172456c5c3
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Shaders/EfficientBlur.shader
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
Shader "Hidden/FillCrop"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
// No culling or depth
|
||||
Cull Off ZWrite Off ZTest Always
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "interop_birp.cginc"
|
||||
#include "common.hlsl"
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
VertexOutput vert(VertexInput v)
|
||||
{
|
||||
VertexOutput o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = v.uv;
|
||||
return o;
|
||||
}
|
||||
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
float4 _CropRegion;
|
||||
|
||||
half4 frag(VertexOutput i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i)
|
||||
float2 uv = CropUV(i.uv, _CropRegion);
|
||||
return all(uv == saturate(uv)) ? SAMPLE_SCREEN_TEX(_MainTex, uv) : half4(0, 0, 0, 1);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d996ab4381100014d99e25e68e9aac84
|
||||
timeCreated: 1540802700
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Shaders/FillCrop.shader
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,199 @@
|
||||
#pragma once
|
||||
|
||||
#include "UnityUI.cginc"
|
||||
// UI shaders still use birp texture convention
|
||||
#include "interop_birp.cginc"
|
||||
#include "common.hlsl"
|
||||
#include "packing.hlsl"
|
||||
#include "blending.hlsl"
|
||||
|
||||
uniform sampler2D _MainTex;
|
||||
uniform fixed4 _TextureSampleAdd;
|
||||
uniform float4 _ClipRect;
|
||||
uniform float4 _MainTex_ST;
|
||||
uniform float _UIMaskSoftnessX;
|
||||
uniform float _UIMaskSoftnessY;
|
||||
uniform int _UIVertexColorAlwaysGammaSpace;
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_BlurTex);
|
||||
|
||||
uniform float4 _CropRegion; //xMin, yMin, xMax, yMax
|
||||
|
||||
uniform half4 _Debug;
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
half4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
float4 packedData1 : TEXCOORD1;
|
||||
#ifdef _USE_PARAFORM
|
||||
float4 packedData2 : TEXCOORD2;
|
||||
float4 packedData3 : TEXCOORD3;
|
||||
#endif
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
half4 color : COLOR;
|
||||
float4 mask : TEXCOORD0;
|
||||
float2 texcoord : TEXCOORD1;
|
||||
float4 worldPosition : TEXCOORD2;
|
||||
float4 screenPos : TEXCOORD3;
|
||||
float4 transfer1 : TEXCOORD4;
|
||||
#ifdef _USE_PARAFORM
|
||||
float4 transfer2 : TEXCOORD5; // need float for hq derivative on some opengl driver
|
||||
half4 transfer3 : TEXCOORD6;
|
||||
half4 transfer4 : TEXCOORD7;
|
||||
half transfer5 : TEXCOORD8;
|
||||
#endif
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
struct Appearance
|
||||
{
|
||||
half foregroundOpacity;
|
||||
half vibrancy;
|
||||
half brightness;
|
||||
half flatten;
|
||||
};
|
||||
|
||||
void unpackVertexData(VertexInput i, inout VertexOutput o)
|
||||
{
|
||||
FloatUnpacker upk0 = CreateUnpacker(i.packedData1[0], 8);
|
||||
FloatUnpacker upk1 = CreateUnpacker(i.packedData1[1], 10);
|
||||
o.transfer1 = float4(
|
||||
DequeueNonNegative(upk0, 1),
|
||||
Dequeue(upk1, -1, 2),
|
||||
Dequeue(upk1, -1, 1),
|
||||
DequeueNonNegative(upk0, 1)
|
||||
);
|
||||
}
|
||||
|
||||
Appearance createAppearance(float4 transfer1)
|
||||
{
|
||||
Appearance appearance;
|
||||
appearance.foregroundOpacity = transfer1[0];
|
||||
appearance.vibrancy = transfer1[1];
|
||||
appearance.brightness = transfer1[2];
|
||||
appearance.flatten = transfer1[3];
|
||||
return appearance;
|
||||
}
|
||||
|
||||
VertexOutput vert(VertexInput IN)
|
||||
{
|
||||
VertexOutput OUT = (VertexOutput)0;
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(IN);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
|
||||
|
||||
OUT.worldPosition = IN.vertex;
|
||||
|
||||
float4 clipPos = UnityObjectToClipPos(IN.vertex);
|
||||
OUT.vertex = clipPos;
|
||||
|
||||
float2 pixelSize = clipPos.w;
|
||||
pixelSize /= float2(1, 1) * abs(mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy));
|
||||
float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
|
||||
OUT.mask = float4(IN.vertex.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_UIMaskSoftnessX, _UIMaskSoftnessY) + abs(pixelSize.xy)));
|
||||
|
||||
if (_UIVertexColorAlwaysGammaSpace && !IsGammaSpace())
|
||||
{
|
||||
IN.color.rgb = UIGammaToLinearShim(IN.color.rgb);
|
||||
}
|
||||
OUT.color = IN.color;
|
||||
|
||||
OUT.texcoord = IN.texcoord;
|
||||
|
||||
OUT.screenPos = ComputeNonStereoScreenPos(OUT.vertex);
|
||||
#if UNITY_VERSION >= 202120 && UNITY_UV_STARTS_AT_TOP
|
||||
if (_ProjectionParams.x > 0 && unity_MatrixVP[1][1] < 0)
|
||||
OUT.screenPos.y = OUT.screenPos.w - OUT.screenPos.y;
|
||||
#endif
|
||||
|
||||
unpackVertexData(IN, OUT);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
void fragSetup(inout VertexOutput IN, out half2 screenPos, out half4 foregroundColor, out Appearance appearance)
|
||||
{
|
||||
//Round up the alpha color coming from the interpolator (to 1.0/256.0 steps)
|
||||
//The incoming alpha could have numerical instability, which makes it very sensible to
|
||||
//HDR color transparency blend, when it blends with the world's texture.
|
||||
const half alphaPrecision = half(0xff);
|
||||
const half invAlphaPrecision = half(1.0 / alphaPrecision);
|
||||
IN.color.a = round(IN.color.a * alphaPrecision) * invAlphaPrecision;
|
||||
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
|
||||
|
||||
screenPos = IN.screenPos.xy / IN.screenPos.w;
|
||||
foregroundColor = tex2D(_MainTex, IN.texcoord.xy) + _TextureSampleAdd;
|
||||
foregroundColor *= IN.color;
|
||||
|
||||
appearance = createAppearance(IN.transfer1);
|
||||
}
|
||||
|
||||
void fragFinish(VertexOutput IN, half2 screenPos, inout half4 color)
|
||||
{
|
||||
// TODO: fix Shadow and Outline tinting somehow
|
||||
// Multiplying last so glints work
|
||||
// color *= IN.color;
|
||||
|
||||
#ifdef UNITY_UI_CLIP_RECT
|
||||
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw);
|
||||
color.a *= m.x * m.y;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef UNITY_UI_ALPHACLIP
|
||||
clip(color.a - 0.001);
|
||||
#endif
|
||||
|
||||
color.rgb *= color.a;
|
||||
color = dither(color, (screenPos.xy + 0) * _ScreenParams.xy);
|
||||
}
|
||||
|
||||
half3 sampleBackground(float2 screenPos)
|
||||
{
|
||||
half2 blurTexcoord = CropUV(screenPos, _CropRegion);
|
||||
half3 backgroundColor = SAMPLE_SCREEN_TEX(_BlurTex, blurTexcoord).rgb;
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
half4 blendBackground(half4 foregroundColor, half3 backgroundColor, Appearance appearance)
|
||||
{
|
||||
half4 color;
|
||||
color.a = foregroundColor.a;
|
||||
|
||||
#if _BACKGROUND_MODE_NORMAL
|
||||
|
||||
backgroundColor = saturate(backgroundColor + (.5 - backgroundColor) * appearance.flatten);
|
||||
backgroundColor = saturate(lerp(LinearRgbToLuminance(backgroundColor), backgroundColor, appearance.vibrancy));
|
||||
half brightness = isGammaShim()
|
||||
? appearance.brightness
|
||||
: appearance.brightness * appearance.brightness * sign(appearance.brightness);
|
||||
backgroundColor = saturate(backgroundColor + brightness);
|
||||
|
||||
color.rgb = lerp(backgroundColor, foregroundColor.rgb, appearance.foregroundOpacity);
|
||||
|
||||
#else //#elif _BACKGROUND_MODE_COLORFUL
|
||||
|
||||
half targetL = appearance.brightness / 2. + .5;
|
||||
if (!isGammaShim())
|
||||
targetL = targetL * targetL;
|
||||
|
||||
backgroundColor = /*saturate*/(lerp(LinearRgbToLuminance(backgroundColor), backgroundColor, appearance.vibrancy));
|
||||
backgroundColor = /*saturate*/(backgroundColor + (targetL - backgroundColor) * appearance.flatten);
|
||||
backgroundColor = lerp(
|
||||
backgroundColor,
|
||||
setL(backgroundColor, LinearRgbToLuminance(backgroundColor), targetL),
|
||||
appearance.foregroundOpacity
|
||||
);
|
||||
color.rgb = gamutClip(backgroundColor * foregroundColor.rgb);
|
||||
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b01fb1ca47c849279f7a0d19d1f20e7a
|
||||
timeCreated: 1752043759
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Shaders/TranslucentImage.hlsl
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,106 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
Shader "UI/TranslucentImage"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
|
||||
|
||||
[Header(Appearance)][Space]
|
||||
[KeywordEnum(Normal, Colorful)] _BACKGROUND_MODE("Background Mode", int) = 0
|
||||
|
||||
[Header(Refraction)][Space]
|
||||
[KeywordEnum(Off,On,Chromatic)] _REFRACTION_MODE("Refraction Mode", int) = 1
|
||||
// Singularity prevent reconstructions of control properties from _RefractiveIndexRatios
|
||||
// so they need to be stored in the material
|
||||
[PowerSlider(20)] _RefractiveIndex("Refractive Index", Range(1, 4.5)) = 1.5
|
||||
[PowerSlider(2)] _ChromaticDispersion("Chromatic Dispersion", Range(0, 2)) = 0.5
|
||||
_RefractiveIndexRatios("Refractive Index Ratio", Vector) = (0.666666, 0.666666, 0.666666, 0)
|
||||
|
||||
[Header(Edge Glint)][Space]
|
||||
[Toggle(_USE_EDGE_GLINT)] _USE_EDGE_GLINT("Enable Edge Glint", Float) = 0
|
||||
_EdgeGlintDirections("Edge Glint Directions", Vector) = (-0.258819, 0.9659259, 0.2588191, -0.9659258)
|
||||
_EdgeGlint1Strength("Edge Glint 1 Strength", Range(0, 1)) = .25
|
||||
_EdgeGlint2Strength("Edge Glint 2 Strength", Range(0, 1)) = .1
|
||||
_EdgeGlintWrap("Edge Glint Wrap", Float) = 1
|
||||
_EdgeGlintSharpness("Edge Glint Sharpness", Float) = 512
|
||||
|
||||
//_Debug("Debug", Vector) = (0,0,0,0)
|
||||
|
||||
[Header(Other)][Space]
|
||||
_StencilComp("Stencil Comparison", Float) = 8
|
||||
_Stencil("Stencil ID", Float) = 0
|
||||
_StencilOp("Stencil Operation", Float) = 0
|
||||
_StencilWriteMask("Stencil Write Mask", Float) = 255
|
||||
_StencilReadMask("Stencil Read Mask", Float) = 255
|
||||
|
||||
_ColorMask("Color Mask", Float) = 15
|
||||
[HideInInspector]_Color ("Dummy Color", Color) = (1,1,1,1)
|
||||
|
||||
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"= "Transparent"
|
||||
"IgnoreProjector"= "True"
|
||||
"RenderType"= "Transparent"
|
||||
"PreviewType"= "Plane"
|
||||
"CanUseSpriteAtlas"= "True"
|
||||
}
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref[_Stencil]
|
||||
Comp[_StencilComp]
|
||||
Pass[_StencilOp]
|
||||
ReadMask[_StencilReadMask]
|
||||
WriteMask[_StencilWriteMask]
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest[unity_GUIZTestMode]
|
||||
Blend One OneMinusSrcAlpha
|
||||
ColorMask[_ColorMask]
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
#pragma target 3.0
|
||||
#pragma exclude_renderers d3d11_9x gles
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "TranslucentImage.hlsl"
|
||||
|
||||
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT
|
||||
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP
|
||||
|
||||
#pragma shader_feature_local_fragment _BACKGROUND_MODE_NORMAL _BACKGROUND_MODE_COLORFUL
|
||||
|
||||
half4 frag(VertexOutput IN) : SV_Target
|
||||
{
|
||||
half2 screenPos;
|
||||
half4 foregroundColor;
|
||||
Appearance appearance;
|
||||
fragSetup(IN, screenPos, foregroundColor, appearance);
|
||||
|
||||
half3 backgroundColor = sampleBackground(screenPos);
|
||||
half4 color = blendBackground(foregroundColor, backgroundColor, appearance);
|
||||
|
||||
fragFinish(IN, screenPos, color);
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
CustomEditor "LeTai.Asset.TranslucentImage.Editor.TranslucentImageShaderGUI"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1115addd36579a429d5e6b4ffae668d
|
||||
timeCreated: 1539852404
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Shaders/TranslucentImage.shader
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
#include <UnityCG.cginc>
|
||||
|
||||
half3 blendOverlay(half3 a, half3 b)
|
||||
{
|
||||
return a < .5 ? 2 * a * b : 1 - 2 * (1 - a) * (1 - b);
|
||||
}
|
||||
|
||||
half3 blendScreen(half3 a, half3 b)
|
||||
{
|
||||
return 1 - (1 - a) * (1 - b);
|
||||
}
|
||||
|
||||
half3 setL(half3 a, half lumA, half lumB)
|
||||
{
|
||||
return a + (lumB - lumA);
|
||||
}
|
||||
|
||||
half3 gamutClip(half3 color)
|
||||
{
|
||||
half L = LinearRgbToLuminance(color);
|
||||
half minComp = min(min(color.r, color.g), color.b);
|
||||
half maxComp = max(max(color.r, color.g), color.b);
|
||||
|
||||
// branches are never entered when the denom is 0
|
||||
|
||||
// if (minComp < 0)
|
||||
// // color = L + (color - L) * L / (L - minComp);
|
||||
// result = L * (result - minComp) / (L - minComp);
|
||||
// if (maxComp > 1)
|
||||
// result = L + (result - L) * (1 - L) / (maxComp - L);
|
||||
|
||||
|
||||
// Assumption: under blurring, branches are more likely to be coherence than not
|
||||
|
||||
// fully scalar
|
||||
half scale = 1;
|
||||
if (minComp < 0)
|
||||
scale = L / (L - minComp);
|
||||
if (maxComp > 1)
|
||||
scale = min(scale, (1 - L) / (maxComp - L));
|
||||
|
||||
// skipping the vector path should be worth the branch
|
||||
// if (scale < 1)
|
||||
if (scale < 1)
|
||||
color = L + (color - L) * scale;
|
||||
|
||||
return color;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15df69990d05474f9845874424d84acf
|
||||
timeCreated: 1750414240
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Shaders/blending.hlsl
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
#ifndef _TRANSLUCENTIMAGE_COMMON
|
||||
#define _TRANSLUCENTIMAGE_COMMON
|
||||
|
||||
float2 UnCropUV(float2 uvRelativeToCropped, float4 cropRegion)
|
||||
{
|
||||
return lerp(cropRegion.xy, cropRegion.zw, uvRelativeToCropped);
|
||||
}
|
||||
|
||||
float2 CropUV(float2 uvRelativeToUnCropped, float4 cropRegion)
|
||||
{
|
||||
return (uvRelativeToUnCropped - cropRegion.xy) / (cropRegion.zw - cropRegion.xy);
|
||||
}
|
||||
|
||||
// https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h
|
||||
float sqrtApprox01(float inX)
|
||||
{
|
||||
int x = asint(inX);
|
||||
x = 0x1FBD1DF5 + (x >> 1);
|
||||
return asfloat(x);
|
||||
}
|
||||
|
||||
// https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h
|
||||
float rsqrtApprox01(float inX)
|
||||
{
|
||||
int x = asint(inX);
|
||||
x = 0x5F341A43 - (x >> 1);
|
||||
return asfloat(x);
|
||||
}
|
||||
|
||||
// https://en.wikibooks.org/wiki/Algorithms/Distance_approximations
|
||||
float lengthApproxOctagon(float2 v)
|
||||
{
|
||||
float ax = abs(v.x);
|
||||
float ay = abs(v.y);
|
||||
float l = max(ax, ay);
|
||||
float s = min(ax, ay);
|
||||
|
||||
return .41 * s + .941246 * l;
|
||||
}
|
||||
|
||||
// https://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
|
||||
inline float ggr21(float2 n)
|
||||
{
|
||||
static const float g = 1.32471795724474602596;
|
||||
static const float a1 = 1.0 / g;
|
||||
static const float a2 = 1.0 / (g * g);
|
||||
return frac(a1 * n.x + a2 * n.y);
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/4djSRW
|
||||
float hash12(float2 p)
|
||||
{
|
||||
float3 p3 = frac(float3(p.xyx) * .1031);
|
||||
p3 += dot(p3, p3.yzx + 33.33);
|
||||
return frac((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
|
||||
half3 sdfViz(float d)
|
||||
{
|
||||
half3 col = (d > 0.0) ? half3(0.9, 0.6, 0.3) : half3(0.65, 0.85, 1.0);
|
||||
col *= 1.0 - exp(-12.0 * abs(d));
|
||||
col *= 0.8 + 0.2 * cos(150.0 * d);
|
||||
return lerp(col, 1.0, 1.0 - smoothstep(0.0, 0.01, abs(d)));
|
||||
}
|
||||
|
||||
bool isGammaShim()
|
||||
{
|
||||
#ifdef UNITY_COLORSPACE_GAMMA
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
half3 toPerceptual(half3 color)
|
||||
{
|
||||
return isGammaShim() ? color : sqrt(color);
|
||||
}
|
||||
|
||||
half3 fromPerceptual(half3 color)
|
||||
{
|
||||
return isGammaShim() ? color : color * color;
|
||||
}
|
||||
|
||||
half4 dither(half4 color, float2 coord)
|
||||
{
|
||||
half noise = ggr21(coord) * 1. / 255. - .5 / 255.;
|
||||
half4 result = color;
|
||||
|
||||
result.rgb = toPerceptual(result);
|
||||
result += noise;
|
||||
result.rgb = fromPerceptual(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0f93ce7a1dcd4341947566d67947b0d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Shaders/common.hlsl
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
struct FullScreenVertexInput
|
||||
{
|
||||
#if !SHADER_API_GLES
|
||||
uint vertexID : SV_VertexID;
|
||||
#else
|
||||
float4 position : POSITION;
|
||||
#endif
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct FullScreenVertexOutput
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
|
||||
float2 VertexToUV(float2 vertex)
|
||||
{
|
||||
float2 texcoord = (vertex + 1.0) * 0.5; // triangle vert to uv
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
texcoord = texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
|
||||
#endif
|
||||
return texcoord;
|
||||
}
|
||||
|
||||
|
||||
// BiRP do not have these methods, so copy here and namespaced to avoid collision in URP
|
||||
|
||||
// Generates a triangle in homogeneous clip space, s.t.
|
||||
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).
|
||||
float2 tai_GetFullScreenTriangleTexCoord(uint vertexID)
|
||||
{
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
return float2((vertexID << 1) & 2, 1.0 - (vertexID & 2));
|
||||
#else
|
||||
return float2((vertexID << 1) & 2, vertexID & 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
float4 tai_GetFullScreenTriangleVertexPosition(uint vertexID, float z)
|
||||
{
|
||||
// note: the triangle vertex position coordinates are x2 so the returned UV coordinates are in range -1, 1 on the screen.
|
||||
float2 uv = float2((vertexID << 1) & 2, vertexID & 2);
|
||||
float4 pos = float4(uv * 2.0 - 1.0, z, 1.0);
|
||||
return pos;
|
||||
}
|
||||
|
||||
void GetFullScreenVertexData(FullScreenVertexInput v, out float4 posCS, out float2 screenUV)
|
||||
{
|
||||
#if !SHADER_API_GLES
|
||||
posCS = tai_GetFullScreenTriangleVertexPosition(v.vertexID, UNITY_NEAR_CLIP_VALUE);
|
||||
screenUV = tai_GetFullScreenTriangleTexCoord(v.vertexID);
|
||||
#else
|
||||
posCS = v.position;
|
||||
screenUV = VertexToUV(v.position.xy);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1a79371c15c4beab2c91aa6e7f4c13e
|
||||
timeCreated: 1729673279
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Shaders/fullscreen.hlsl
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
#include <UnityCG.cginc>
|
||||
|
||||
// This need to be a macro since the type of tex can change :(
|
||||
#define SAMPLE_SCREEN_TEX(tex, uv) UNITY_SAMPLE_SCREENSPACE_TEXTURE(tex, UnityStereoTransformScreenSpaceTex(uv))
|
||||
|
||||
// This piecewise approximation has a precision better than 0.5 / 255 in gamma space over the [0..255] range
|
||||
// i.e. abs(l2g_exact(g2l_approx(value)) - value) < 0.5 / 255
|
||||
// It is much more precise than GammaToLinearSpace but remains relatively cheap
|
||||
half3 UIGammaToLinearShim(half3 value)
|
||||
{
|
||||
half3 low = 0.0849710 * value - 0.000163029;
|
||||
half3 high = value * (value * (value * 0.265885 + 0.736584) - 0.00980184) + 0.00319697;
|
||||
|
||||
// We should be 0.5 away from any actual gamma value stored in an 8 bit channel
|
||||
const half3 split = (half3)0.0725490; // Equals 18.5 / 255
|
||||
return (value < split) ? low : high;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8c68a14f2a58eb4eb95978229e5db5e
|
||||
labels:
|
||||
- TranslucentImageEditorResources
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Shaders/interop_birp.cginc
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
#ifndef LETAI_PACKING
|
||||
#define LETAI_PACKING
|
||||
|
||||
struct FloatUnpacker
|
||||
{
|
||||
uint payload;
|
||||
uint nBitsConsumed;
|
||||
uint bitsPerFloat;
|
||||
};
|
||||
|
||||
FloatUnpacker CreateUnpacker(float packed, int bitsPerFloat = 0)
|
||||
{
|
||||
uint bits = asuint(packed);
|
||||
uint exponent = (bits >> 23) & 0xFFu;
|
||||
uint mantissa = bits & 0x7FFFFFu;
|
||||
|
||||
FloatUnpacker u;
|
||||
u.payload = ((exponent - 1u) << 23) | mantissa;
|
||||
u.nBitsConsumed = 0;
|
||||
u.bitsPerFloat = bitsPerFloat;
|
||||
return u;
|
||||
}
|
||||
|
||||
float Dequeue(inout FloatUnpacker u, float minVal, float maxVal, uint nBits = 0)
|
||||
{
|
||||
if (nBits == 0) nBits = u.bitsPerFloat;
|
||||
|
||||
uint mask = (1u << nBits) - 1u;
|
||||
uint value = (u.payload >> u.nBitsConsumed) & mask;
|
||||
u.nBitsConsumed += nBits;
|
||||
|
||||
float norm = value * (1.0 / mask);
|
||||
return norm * (maxVal - minVal) + minVal;
|
||||
}
|
||||
|
||||
float DequeueNonNegative(inout FloatUnpacker u, float maxVal, uint nBits = 0)
|
||||
{
|
||||
return Dequeue(u, 0, maxVal, nBits);
|
||||
}
|
||||
|
||||
|
||||
void UnpackTwoFloatsSafe(
|
||||
float packed,
|
||||
float minA, float maxA, uint nBitsA,
|
||||
float minB, float maxB, uint nBitsB,
|
||||
out float a, out float b)
|
||||
{
|
||||
uint bits = asuint(packed);
|
||||
|
||||
uint exponent = (bits >> 23) & 0xFFu;
|
||||
uint mantissa = bits & 0x7FFFFFu;
|
||||
|
||||
uint payload = ((exponent - 1u) << 23) | mantissa;
|
||||
|
||||
uint maskB = (1u << nBitsB) - 1u;
|
||||
float aQuantized = payload >> nBitsB;
|
||||
float bQuantized = payload & maskB;
|
||||
|
||||
float maxAQuantized = (1u << nBitsA) - 1u;
|
||||
float maxBQuantized = maskB;
|
||||
|
||||
float aNormalized = aQuantized * (1. / maxAQuantized);
|
||||
float bNormalized = bQuantized * (1. / maxBQuantized);
|
||||
|
||||
a = aNormalized * (maxA - minA) + minA;
|
||||
b = bNormalized * (maxB - minB) + minB;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1513fde2dd7f474a803858cd7ae75356
|
||||
timeCreated: 1750650448
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Shaders/packing.hlsl
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,16 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c98b4a46667547b294b1c048ab4fc355, type: 3}
|
||||
m_Name: Translucent Image Default Resources
|
||||
m_EditorClassIdentifier:
|
||||
material: {fileID: 2100000, guid: 96c5704d0681e35408630c488fc0c234, type: 2}
|
||||
paraformMaterial: {fileID: 2100000, guid: c2c99768271516e4b8f434b56fc1cea0, type: 2}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06adab3c1d7cfaf4e8386d06623484fa
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/TranslucentImage/Resources/Translucent Image Default
|
||||
Resources.asset
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf78a7acb2cf96c468f81fe121a3301f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
Shader "Hidden/EfficientBlur_UniversalRP"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Cull Off ZWrite Off ZTest Always Blend Off
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
#pragma target 3.0
|
||||
//HLSLcc is not used by default on gles
|
||||
#pragma prefer_hlslcc gles
|
||||
//SRP don't support dx9
|
||||
#pragma exclude_renderers d3d11_9x
|
||||
|
||||
#pragma vertex VertBlur
|
||||
#pragma fragment FragBlur
|
||||
#pragma multi_compile_local BACKGROUND_FILL_NONE BACKGROUND_FILL_COLOR
|
||||
#pragma multi_compile_local _ USE_EXTRA_SAMPLE
|
||||
|
||||
#include "interop_urp.hlsl"
|
||||
|
||||
TEXTURE2D_X(_MainTex);
|
||||
SAMPLER(sampler_MainTex);
|
||||
|
||||
#include "../Shaders/EfficientBlur.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
FallBack Off
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a1d960bb7429ed49a23391385e9ca1b
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,58 @@
|
||||
Shader "Hidden/FillCrop_UniversalRP"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
// No culling or depth
|
||||
Cull Off ZWrite Off ZTest Always
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma target 3.0
|
||||
//HLSLcc is not used by default on gles
|
||||
#pragma prefer_hlslcc gles
|
||||
//SRP don't support dx9
|
||||
#pragma exclude_renderers d3d11_9x
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "./interop_urp.hlsl"
|
||||
#include "../Shaders/fullscreen.hlsl"
|
||||
#include "../Shaders/common.hlsl"
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
v2f vert(FullScreenVertexInput v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
float4 posCS;
|
||||
float2 screenUV;
|
||||
GetFullScreenVertexData(v, posCS, screenUV);
|
||||
|
||||
o.vertex = half4(posCS.xy, 0.0, 1.0);
|
||||
o.uv = screenUV;
|
||||
return o;
|
||||
}
|
||||
|
||||
TEXTURE2D_X(_MainTex);
|
||||
float4 _CropRegion;
|
||||
|
||||
half4 frag(v2f i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i)
|
||||
float2 uv = CropUV(i.uv, _CropRegion);
|
||||
return all(uv == saturate(uv)) ? SAMPLE_SCREEN_TEX(_MainTex, uv) : half4(0, 0, 0, 1);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be9460e8089353c42b6ec727f6fc3140
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
#if UNITY_VERSION < 600000
|
||||
SAMPLER(sampler_LinearClamp);
|
||||
#endif
|
||||
#define SAMPLE_SCREEN_TEX(tex, uv) SAMPLE_TEXTURE2D_X(tex, sampler_LinearClamp, UnityStereoTransformScreenSpaceTex(uv))
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 005bb204b9b54cb7868e1aa065f00838
|
||||
timeCreated: 1562251098
|
||||
Reference in New Issue
Block a user