yes
This commit is contained in:
17
modules/wallpaper-engine/shaders/HLSL/dx11fallback.frag
Normal file
17
modules/wallpaper-engine/shaders/HLSL/dx11fallback.frag
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
struct PS_OUTPUT
|
||||
{
|
||||
float4 gl_FragColor : SV_TARGET;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 gl_Position : SV_POSITION;
|
||||
};
|
||||
|
||||
PS_OUTPUT main(VS_OUTPUT IN)
|
||||
{
|
||||
PS_OUTPUT OUT;
|
||||
OUT.gl_FragColor = float4(0.5, 0, 0, 1);
|
||||
return OUT;
|
||||
}
|
||||
24
modules/wallpaper-engine/shaders/HLSL/dx11fallback.vert
Normal file
24
modules/wallpaper-engine/shaders/HLSL/dx11fallback.vert
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
float3 a_Position : POSITION;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 gl_Position : SV_POSITION;
|
||||
};
|
||||
|
||||
cbuffer g_bufDynamic:register(b1)
|
||||
{
|
||||
const float4x4 g_ModelViewProjectionMatrix;
|
||||
}
|
||||
|
||||
VS_OUTPUT main(VS_INPUT IN)
|
||||
{
|
||||
VS_OUTPUT OUT;
|
||||
|
||||
OUT.gl_Position = mul(float4(IN.a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
struct PS_OUTPUT
|
||||
{
|
||||
float4 gl_FragColor : SV_TARGET;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 gl_Position : SV_POSITION;
|
||||
float2 v_TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
Texture2D g_Texture0:register(t0);
|
||||
SamplerState g_Texture0SamplerState:register(s0);
|
||||
|
||||
static float weight[3][3] = {{21.0 / 256.0, 31.0 / 256.0, 21.0 / 256.0},
|
||||
{31.0 / 256.0, 48.0 / 256.0, 31.0 / 256.0},
|
||||
{21.0 / 256.0, 31.0 / 256.0, 21.0 / 256.0}};
|
||||
|
||||
PS_OUTPUT main(VS_OUTPUT IN)
|
||||
{
|
||||
float3 color = (float3)0.0;
|
||||
|
||||
float w;
|
||||
float h;
|
||||
g_Texture0.GetDimensions(w, h);
|
||||
float2 uvd = 3.333 / float2(w, h);
|
||||
|
||||
for (int x = 0; x < 3; ++x)
|
||||
{
|
||||
for (int y = 0; y < 3; ++y)
|
||||
{
|
||||
color += g_Texture0.SampleLevel(g_Texture0SamplerState, IN.v_TexCoord + float2(x - 1, y - 1) * uvd, 0.0).rgb * weight[x][y];
|
||||
}
|
||||
}
|
||||
|
||||
PS_OUTPUT OUT;
|
||||
OUT.gl_FragColor.rgb = color;
|
||||
OUT.gl_FragColor.a = 1.0;
|
||||
return OUT;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
struct VS_INPUT
|
||||
{
|
||||
float3 a_Position : POSITION;
|
||||
float2 v_TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 a_Position : SV_POSITION;
|
||||
float2 v_TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
VS_OUTPUT main(VS_INPUT IN)
|
||||
{
|
||||
VS_OUTPUT OUT;
|
||||
|
||||
OUT.a_Position = float4(IN.a_Position, 1.0);
|
||||
OUT.v_TexCoord = IN.v_TexCoord;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
@@ -0,0 +1,810 @@
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 v_Position : SV_POSITION;
|
||||
float2 v_TexCoord : TEXCOORD0;
|
||||
#if FADEEFFECT == 23
|
||||
float2 v_TexCoordBase : TEXCOORD1;
|
||||
float3 v_WorldPos : TEXCOORD2;
|
||||
float3 v_WorldNormal : TEXCOORD3;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct PS_OUTPUT
|
||||
{
|
||||
float4 p_FragColor : SV_TARGET;
|
||||
};
|
||||
|
||||
Texture2D g_Texture0:register(t0);
|
||||
Texture2D g_Texture0MipMapped:register(t0);
|
||||
Texture2D g_Texture1Noise:register(t1);
|
||||
Texture2D g_Texture2Clouds:register(t2);
|
||||
|
||||
SamplerState g_Texture0SamplerState:register(s0);
|
||||
SamplerState g_Texture0SamplerStateWrap:register(s1);
|
||||
|
||||
cbuffer g_bufDynamic:register(b0)
|
||||
{
|
||||
const float g_Progress;
|
||||
const float g_Hash;
|
||||
const float g_Hash2;
|
||||
const float g_Random;
|
||||
|
||||
const float g_AspectRatio;
|
||||
const float g_Width;
|
||||
const float g_Height;
|
||||
|
||||
const float4x4 g_ViewProjection;
|
||||
const float4x4 g_ViewProjectionInv;
|
||||
}
|
||||
|
||||
float2 rotateFloat2(float2 v, float r)
|
||||
{
|
||||
float2 cs = float2(cos(r), sin(r));
|
||||
return float2(v.x * cs.x - v.y * cs.y, v.x * cs.y + v.y * cs.x);
|
||||
}
|
||||
|
||||
float3 mod289(float3 x) {
|
||||
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
||||
}
|
||||
|
||||
float2 mod289(float2 x) {
|
||||
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
||||
}
|
||||
|
||||
float3 permute(float3 x) {
|
||||
return mod289(((x*34.0)+10.0)*x);
|
||||
}
|
||||
|
||||
float snoise(float2 v)
|
||||
{
|
||||
const float4 C = float4(0.211324865405187,
|
||||
0.366025403784439,
|
||||
-0.577350269189626,
|
||||
0.024390243902439);
|
||||
float2 i = floor(v + dot(v, C.yy) );
|
||||
float2 x0 = v - i + dot(i, C.xx);
|
||||
|
||||
float2 i1;
|
||||
i1 = (x0.x > x0.y) ? float2(1.0, 0.0) : float2(0.0, 1.0);
|
||||
float4 x12 = x0.xyxy + C.xxzz;
|
||||
x12.xy -= i1;
|
||||
|
||||
i = mod289(i);
|
||||
float3 p = permute( permute( i.y + float3(0.0, i1.y, 1.0 ))
|
||||
+ i.x + float3(0.0, i1.x, 1.0 ));
|
||||
|
||||
float3 m = max(0.5 - float3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
|
||||
m = m*m ;
|
||||
m = m*m ;
|
||||
|
||||
float3 x = 2.0 * frac(p * C.www) - 1.0;
|
||||
float3 h = abs(x) - 0.5;
|
||||
float3 ox = floor(x + 0.5);
|
||||
float3 a0 = x - ox;
|
||||
|
||||
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
|
||||
|
||||
float3 g;
|
||||
g.x = a0.x * x0.x + h.x * x0.y;
|
||||
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
|
||||
return 127.0 * dot(m, g);
|
||||
}
|
||||
|
||||
float4 mod289(float4 x) {
|
||||
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
||||
}
|
||||
|
||||
float4 permute(float4 x) {
|
||||
return mod289(((x*34.0)+10.0)*x);
|
||||
}
|
||||
|
||||
float4 taylorInvSqrt(float4 r)
|
||||
{
|
||||
return 1.79284291400159 - 0.85373472095314 * r;
|
||||
}
|
||||
|
||||
float snoise(float3 v)
|
||||
{
|
||||
const float2 C = float2(1.0/6.0, 1.0/3.0) ;
|
||||
const float4 D = float4(0.0, 0.5, 1.0, 2.0);
|
||||
|
||||
float3 i = floor(v + dot(v, C.yyy) );
|
||||
float3 x0 = v - i + dot(i, C.xxx) ;
|
||||
|
||||
float3 g = step(x0.yzx, x0.xyz);
|
||||
float3 l = 1.0 - g;
|
||||
float3 i1 = min( g.xyz, l.zxy );
|
||||
float3 i2 = max( g.xyz, l.zxy );
|
||||
float3 x1 = x0 - i1 + C.xxx;
|
||||
float3 x2 = x0 - i2 + C.yyy;
|
||||
float3 x3 = x0 - D.yyy;
|
||||
|
||||
i = mod289(i);
|
||||
float4 p = permute(permute(permute(
|
||||
i.z + float4(0.0, i1.z, i2.z, 1.0 ))
|
||||
+ i.y + float4(0.0, i1.y, i2.y, 1.0 ))
|
||||
+ i.x + float4(0.0, i1.x, i2.x, 1.0 ));
|
||||
|
||||
float n_ = 0.142857142857;
|
||||
float3 ns = n_ * D.wyz - D.xzx;
|
||||
|
||||
float4 j = p - 49.0 * floor(p * ns.z * ns.z);
|
||||
|
||||
float4 x_ = floor(j * ns.z);
|
||||
float4 y_ = floor(j - 7.0 * x_ );
|
||||
|
||||
float4 x = x_ *ns.x + ns.yyyy;
|
||||
float4 y = y_ *ns.x + ns.yyyy;
|
||||
float4 h = 1.0 - abs(x) - abs(y);
|
||||
|
||||
float4 b0 = float4( x.xy, y.xy );
|
||||
float4 b1 = float4( x.zw, y.zw );
|
||||
|
||||
float4 s0 = floor(b0)*2.0 + 1.0;
|
||||
float4 s1 = floor(b1)*2.0 + 1.0;
|
||||
float4 sh = -step(h, (float4)0.0);
|
||||
|
||||
float4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
|
||||
float4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
|
||||
|
||||
float3 p0 = float3(a0.xy,h.x);
|
||||
float3 p1 = float3(a0.zw,h.y);
|
||||
float3 p2 = float3(a1.xy,h.z);
|
||||
float3 p3 = float3(a1.zw,h.w);
|
||||
|
||||
float4 norm = taylorInvSqrt(float4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
|
||||
p0 *= norm.x;
|
||||
p1 *= norm.y;
|
||||
p2 *= norm.z;
|
||||
p3 *= norm.w;
|
||||
|
||||
float4 m = max(0.5 - float4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
|
||||
m = m * m;
|
||||
return 105.0 * dot( m*m, float4( dot(p0,x0), dot(p1,x1),
|
||||
dot(p2,x2), dot(p3,x3)));
|
||||
}
|
||||
|
||||
float fbm(in float2 st, const in int octaves)
|
||||
{
|
||||
float value = 0.0;
|
||||
float amplitude = .5;
|
||||
float frequency = 0.;
|
||||
for (int i = 0; i < octaves; i++)
|
||||
{
|
||||
value += amplitude * snoise(st);
|
||||
st *= 2.;
|
||||
amplitude *= .5;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
float nrand(float2 uv)
|
||||
{
|
||||
return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453);
|
||||
}
|
||||
|
||||
float nrandFloorAspect(float2 uv, float scale)
|
||||
{
|
||||
float2 aspectScale = scale * float2(g_AspectRatio, 1.0);
|
||||
return nrand(floor(frac(uv + g_Hash) * aspectScale) / aspectScale);
|
||||
}
|
||||
|
||||
float3 blur13(float2 u, float2 d)
|
||||
{
|
||||
float2 o1 = (float2)(1.4091998770852122) * d;
|
||||
float2 o2 = (float2)(3.2979348079914822) * d;
|
||||
float2 o3 = (float2)(5.2062900776825969) * d;
|
||||
return g_Texture0.SampleLevel(g_Texture0SamplerState, u, 0.0).rgb * 0.1976406528809576
|
||||
+ g_Texture0.SampleLevel(g_Texture0SamplerState, u + o1, 0.0).rgb * 0.2959855056006557
|
||||
+ g_Texture0.SampleLevel(g_Texture0SamplerState, u - o1, 0.0).rgb * 0.2959855056006557
|
||||
+ g_Texture0.SampleLevel(g_Texture0SamplerState, u + o2, 0.0).rgb * 0.0935333619980593
|
||||
+ g_Texture0.SampleLevel(g_Texture0SamplerState, u - o2, 0.0).rgb * 0.0935333619980593
|
||||
+ g_Texture0.SampleLevel(g_Texture0SamplerState, u + o3, 0.0).rgb * 0.0116608059608062
|
||||
+ g_Texture0.SampleLevel(g_Texture0SamplerState, u - o3, 0.0).rgb * 0.0116608059608062;
|
||||
}
|
||||
|
||||
float drawGradient(float2 uvs, float2 start, float2 end, inout float distFromRay)
|
||||
{
|
||||
float2 dir = end - start;
|
||||
float2 delta = uvs - start;
|
||||
float len = length(dir);
|
||||
dir /= len;
|
||||
|
||||
float distAlongRay = dot(dir, delta) / len;
|
||||
distFromRay = abs(dot(float2(dir.y, -dir.x), delta));
|
||||
return distAlongRay;
|
||||
}
|
||||
|
||||
float4 PerformEffect(VS_OUTPUT IN, float2 texCoord, float progress)
|
||||
{
|
||||
float4 color = float4(g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord, 0.0).rgb, 1.0);
|
||||
|
||||
#if FADEEFFECT == 0
|
||||
// Fade
|
||||
color.a = 1.0 - progress;
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 1
|
||||
// Mosaic
|
||||
float r = nrandFloorAspect(texCoord, 50.0);
|
||||
float smooth = 0.5;
|
||||
color.a = 1.0 - smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - r));
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 2
|
||||
// Diffuse
|
||||
float r = nrandFloorAspect(texCoord, 1000.0);
|
||||
float smooth = 0.5;
|
||||
color.a = 1.0 - smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - r));
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 3
|
||||
// Horizontal slide
|
||||
texCoord.x -= progress;
|
||||
color = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord, 0.0);
|
||||
color.a = step(0.0, texCoord.x);
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 4
|
||||
// Vertical slide
|
||||
texCoord.y -= progress;
|
||||
color = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord, 0.0);
|
||||
color.a = step(0.0, texCoord.y);
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 5
|
||||
// Horizontal fade
|
||||
float smooth = 0.5;
|
||||
color.a = 1.0 - smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - texCoord.x));
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 6
|
||||
// Vertical fade
|
||||
float smooth = 0.5;
|
||||
color.a = 1.0 - smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - texCoord.y));
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 7
|
||||
// Cloud blend
|
||||
float2 noiseUV = texCoord * float2(g_AspectRatio, 1.0);
|
||||
float r = fbm(noiseUV + g_Hash, 6);
|
||||
r = smoothstep(-0.5, 0.5, r);
|
||||
float smooth = 0.333;
|
||||
color.a = 1.0 - smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - r));
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 8
|
||||
// Burnt paper
|
||||
float2 noiseUV = texCoord * float2(g_AspectRatio, 1.0);
|
||||
float r = fbm(noiseUV + g_Hash, 6);
|
||||
r = smoothstep(-0.8, 1.0, r);
|
||||
float rNoise = snoise(noiseUV * 55.333 * (0.5 + g_Progress) + g_Hash + g_Progress * 50.0);
|
||||
rNoise = smoothstep(-1.5, 1.0, rNoise);
|
||||
|
||||
float smooth = 0.00001;
|
||||
float smoothDistort = 0.666;
|
||||
float smoothDistortColor = 0.05;
|
||||
float smoothDistortBurn = 0.5;
|
||||
float smoothShadow = 0.1;
|
||||
float rp = smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - r));
|
||||
float rpOffset = smoothstep(0.0, smoothDistort * progress, progress * (1.0 + smoothDistort) - r);
|
||||
|
||||
float2 offset = float2(ddx(r), ddy(r)) * pow(rpOffset, 2.0) * -30.0;
|
||||
color = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord + offset, 0.0);
|
||||
|
||||
color.a = 1.0 - rp;
|
||||
float shadow = (1.0 - step(0.01, color.a)) * smoothstep(smoothShadow * 2, smoothShadow, progress * (1.0 + smoothShadow) - r);
|
||||
float colorOrangeAmt = smoothstep(0.0, smoothDistortColor * progress, progress * (1.0 + smoothDistortColor) - r) * step(shadow, 0.0);
|
||||
float darkenSrc = smoothstep(smoothDistortBurn * (progress * 0.5), smoothDistortBurn * (progress * 0.8), progress * (1.0 + smoothDistortBurn) - r);
|
||||
|
||||
color.rgb = lerp(color.rgb, color.rgb * 0.1 * float3(0.4, 0.03, 0.01), darkenSrc);
|
||||
color.rgb = lerp(color.rgb, float3(1, 0.333, 0) * rNoise * 1.5, colorOrangeAmt);
|
||||
color.a *= pow(1.0 - smoothstep(0.9, 1.0, progress), 0.5);
|
||||
|
||||
color.rgb = lerp(color.rgb, (float3)0.0, step(0.001, shadow));
|
||||
color.a = max(color.a, pow(shadow, 2.0) * 0.5);
|
||||
|
||||
float smoothDistortGlow = 0.05;
|
||||
float glowAmt = smoothstep(0.0, smoothDistortGlow * progress, progress * (1.0 + smoothDistortGlow) - r) *
|
||||
smoothstep(smoothDistortGlow * progress, 0.0, progress * (1.0 - smoothDistortGlow) - r);
|
||||
glowAmt *= 1.0 - progress;
|
||||
|
||||
glowAmt = max(0.0, glowAmt - colorOrangeAmt);
|
||||
glowAmt = pow(glowAmt, 2.0);
|
||||
color.a = max(glowAmt, color.a);
|
||||
color.rgb += 2.0 * glowAmt * float3(1, 0.333, 0);
|
||||
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 9
|
||||
// Circular blend
|
||||
float2 delta = texCoord - float2(0.5, 0.5);
|
||||
delta.x *= g_AspectRatio;
|
||||
float dist = length(delta);
|
||||
float smooth = 0.1;
|
||||
color.a = 1.0 - smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - dist));
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 10
|
||||
// Zipper
|
||||
float delta = texCoord.x - 0.5;
|
||||
float offset = step(delta, 0.0) * 2.0 - 1.0;
|
||||
float smoothY = 0.5;
|
||||
float smooth = 0.333;
|
||||
float side = step(0.5, texCoord.x);
|
||||
float progressZipper = max(0.0, progress * (1.0 + smoothY) - texCoord.y * smoothY);
|
||||
progressZipper = smoothstep(0.0, 1.0, pow(progressZipper, 2.0));
|
||||
|
||||
float2 uvs = texCoord;
|
||||
uvs.x += offset * progressZipper * (0.5 + smooth);
|
||||
|
||||
color = g_Texture0.SampleLevel(g_Texture0SamplerState, uvs, 0.0);
|
||||
color.a = lerp(step(uvs.x, 0.5), step(0.5, uvs.x), side);
|
||||
|
||||
float shadow = 1.0 - lerp(smoothstep(0.5, 0.5 + smooth, uvs.x), smoothstep(0.5, 0.5 - smooth, uvs.x), side);
|
||||
color.rgb = lerp(color.rgb, (float3)0.0, step(shadow, 0.9999));
|
||||
color.a = max(color.a, shadow * 0.5);
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 11
|
||||
// Door
|
||||
float delta = texCoord.x - 0.5;
|
||||
float offset = step(delta, 0.0) * 2.0 - 1.0;
|
||||
float smooth = 0.333;
|
||||
float side = step(0.5, texCoord.x);
|
||||
|
||||
float2 uvs = texCoord;
|
||||
uvs.x += offset * progress * (0.5 + smooth);
|
||||
|
||||
color = g_Texture0.SampleLevel(g_Texture0SamplerState, uvs, 0.0);
|
||||
color.a = lerp(step(uvs.x, 0.5), step(0.5, uvs.x), side);
|
||||
|
||||
float shadow = 1.0 - lerp(smoothstep(0.5, 0.5 + smooth, uvs.x), smoothstep(0.5, 0.5 - smooth, uvs.x), side);
|
||||
color.rgb = lerp(color.rgb, (float3)0.0, step(shadow, 0.9999));
|
||||
color.a = max(color.a, shadow * 0.5);
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 12
|
||||
// Lines
|
||||
float r = nrandFloorAspect(float2(0.0, texCoord.y), 100.0);
|
||||
float smooth = 0.2;
|
||||
color.a = 1.0 - smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - r));
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 13
|
||||
// Zoom
|
||||
float2 deltaC = texCoord - float2(0.5, 0.5);
|
||||
deltaC.x *= g_AspectRatio;
|
||||
float dist = length(deltaC);
|
||||
float smooth = 1.0;
|
||||
float distortUVAmt = smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - dist));
|
||||
|
||||
float2 delta = texCoord - float2(0.5, 0.5);
|
||||
delta.x *= g_AspectRatio;
|
||||
texCoord -= (float2)0.5;
|
||||
//texCoord *= 1.0 - distortUVAmt;
|
||||
texCoord *= 1.0 - progress * 0.5 * distortUVAmt * 2.0;
|
||||
texCoord += (float2)0.5;
|
||||
color.rgb = (blur13(texCoord, progress * 50.0 * delta / g_Height) + blur13(texCoord, progress * 33.0 * delta / g_Height)) * 0.5;
|
||||
color.a = 1.0 - progress;
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 14
|
||||
// Drip vertical
|
||||
float r = smoothstep(-0.5, 0.5, fbm(float2(texCoord.x * 10.0 + g_Hash, 0.0), 2));
|
||||
float2 uvs = texCoord;
|
||||
|
||||
float smooth = 0.2;
|
||||
uvs.y -= max(0.0, progress * (1.0 + smooth) - r * smooth);
|
||||
uvs.y -= texCoord.y * progress;
|
||||
color = g_Texture0.SampleLevel(g_Texture0SamplerState, uvs, 0.0);
|
||||
//float r = nrandFloorAspect(float2(0.0, texCoord.y), 100.0);
|
||||
color.a = step(0.0, uvs.y); // - smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - r));
|
||||
|
||||
float shadow = smoothstep(-0.1333, 0.0, uvs.y);
|
||||
color.rgb = lerp(color.rgb, (float)0.0, step(uvs.y, 0.0));
|
||||
color.a = max(color.a, shadow * (1.0 - progress));
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 15
|
||||
// Pixelate
|
||||
float2 scale = floor((10.0 + g_Height * (1.0 - pow(abs(progress), 0.1))) * float2(g_AspectRatio, 1.0));
|
||||
color.a = 1.0 - smoothstep(0.7, 1.0, progress);
|
||||
texCoord -= (float2)0.5;
|
||||
texCoord *= scale;
|
||||
texCoord = floor(texCoord);
|
||||
texCoord /= scale;
|
||||
texCoord += (float2)0.5;
|
||||
color.rgb = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord, 0.0).rgb;
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 16
|
||||
// Bricks
|
||||
color.a = 1.0;
|
||||
#elif FADEEFFECT == 17
|
||||
// Paint
|
||||
float2 noiseUV = texCoord * float2(g_AspectRatio, 1.0);
|
||||
float h = (g_Hash - 0.5) * 0.1;
|
||||
|
||||
float rayDist0;
|
||||
float grad0 = drawGradient(texCoord, float2(-1, -0.2 + h), float2(1, 0.15 + h), rayDist0);
|
||||
grad0 *= step(rayDist0, 0.4);
|
||||
|
||||
float rayDist1;
|
||||
float grad1 = drawGradient(texCoord, float2(1.5, 0.1 + h), float2(0, 0.53 + h), rayDist1);
|
||||
grad1 *= step(rayDist1, 0.4);
|
||||
|
||||
float rayDist2;
|
||||
float grad2 = drawGradient(texCoord, float2(-0.5, 0.6 + h), float2(1.2, 0.8 + h), rayDist2);
|
||||
grad2 *= step(rayDist2, 0.4);
|
||||
|
||||
grad0 = saturate(grad0);
|
||||
grad1 = saturate(grad1);
|
||||
grad2 = saturate(grad2);
|
||||
|
||||
float v0 = grad0 * 0.25;
|
||||
v0 = step(0.001, v0);
|
||||
float v1 = grad1 * 0.25;
|
||||
v1 = step(0.001, v1);
|
||||
float v2 = grad2 * 0.25;
|
||||
v2 = step(0.001, v2);
|
||||
|
||||
float l0 = grad0 * 0.25;
|
||||
float l1 = (0.333 + grad1 * 0.25);
|
||||
float l2 = (0.666 + grad2 * 0.333);
|
||||
|
||||
float r = fbm(noiseUV * 10.0 + g_Hash, 8);
|
||||
r = smoothstep(-1.0, 1.0, r);
|
||||
float rs = fbm(noiseUV * 10.0 + g_Hash, 3);
|
||||
rs = smoothstep(-1.0, 1.0, rs);
|
||||
progress += r * 0.02;
|
||||
|
||||
float mask0 = step(rayDist0, 0.4 - r * 0.1);
|
||||
float mask1 = step(rayDist1, 0.4 - r * 0.1);
|
||||
float mask2 = step(rayDist2, 0.4 - r * 0.1);
|
||||
|
||||
float shadowMask0 = max(0.0, smoothstep(0.03, 0.0, max(0.0, rayDist0 - (0.4 - rs * 0.1))) - mask0);
|
||||
float shadowMask1 = max(0.0, smoothstep(0.03, 0.0, max(0.0, rayDist1 - (0.4 - rs * 0.1))) - mask1);
|
||||
float shadowMask2 = max(0.0, smoothstep(0.03, 0.0, max(0.0, rayDist2 - (0.4 - rs * 0.1))) - mask2);
|
||||
|
||||
float f0 = v0 * step(l0, progress) * mask0;
|
||||
float f0S = v0 * step(l0, progress) * shadowMask0;
|
||||
float f1 = v1 * step(l1, progress) * mask1;
|
||||
float f1S = v1 * step(l1, progress) * shadowMask1;
|
||||
float f2 = v2 * step(l2, progress) * mask2;
|
||||
float f2S = v2 * step(l2, progress) * shadowMask2;
|
||||
|
||||
float v = max(f0, max(f1, f2));
|
||||
float vS = max(f0S, max(f1S, f2S));
|
||||
vS = lerp(vS, 0.0, f1);
|
||||
vS = lerp(vS, 0.0, f2);
|
||||
|
||||
color.rgb = lerp(color.rgb, color.rgb * 0.333, vS);
|
||||
color.a = 1.0 - v;
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 18
|
||||
// Fade to black
|
||||
color.rgb *= smoothstep(0.5, 0.0, progress);
|
||||
color.a = smoothstep(1.0, 0.5, progress);
|
||||
#elif FADEEFFECT == 19
|
||||
// Twister
|
||||
float2 delta = texCoord - float2(0.5, 0.5);
|
||||
delta.x *= g_AspectRatio;
|
||||
float dist = length(delta);
|
||||
float smooth = 0.1;
|
||||
color.a = 1.0 - smoothstep(0.0, smooth, max(0.0, progress * (1.0 + smooth) - dist));
|
||||
|
||||
delta.x /= g_AspectRatio;
|
||||
float smoothTwist = 0.5;
|
||||
float twistAmt = smoothstep(0.0, smoothTwist, max(0.0, progress * (1.0 + smoothTwist) - dist));
|
||||
delta /= 1.0 + twistAmt;
|
||||
texCoord = float2(0.5, 0.5) + rotateFloat2(delta, progress * 20.0 * twistAmt);
|
||||
color.rgb = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord, 0.0).rgb;
|
||||
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 20
|
||||
// Black hole
|
||||
float holeSize = smoothstep(0, 0.8, progress) * smoothstep(1.0, 0.8, progress);
|
||||
float noiseAmt = 0.01 * smoothstep(0.95, 0.8, progress);
|
||||
float2 noiseOffset = float2(snoise((float2)progress * 100), g_AspectRatio * snoise((float2)(progress * 100 + g_Hash)));
|
||||
float2 center = float2(0.5, 0.5) + holeSize * noiseAmt * noiseOffset;
|
||||
float2 delta = texCoord - center;
|
||||
|
||||
float dist = length(delta * float2(g_AspectRatio, 1.0));
|
||||
float holeAmt = smoothstep(holeSize * 0.05, holeSize * 0.04, dist);
|
||||
|
||||
// Sample distorted frame
|
||||
texCoord -= float2(0.5, 0.5);
|
||||
float smoothDistort = 1.0;
|
||||
float distortAmt = pow(smoothstep(0.0, smoothDistort, max(0.0, (progress * 0.97) * (smoothDistort))), 2.0);
|
||||
texCoord *= (1.0 + (1.0 / length(delta)) * distortAmt);
|
||||
|
||||
float angle = progress * 4 * pow(smoothstep(holeSize * 0.2, 0.0, dist), 2.0);
|
||||
angle = lerp(angle, -angle, step(0.5, g_Hash));
|
||||
texCoord = rotateFloat2(texCoord, angle);
|
||||
|
||||
texCoord += float2(0.5, 0.5);
|
||||
color.r = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord, 0.0).r;
|
||||
color.g = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord - angle * 0.04, 0.0).g;
|
||||
color.b = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord + angle * 0.04, 0.0).b;
|
||||
|
||||
float2 shadowDelta = texCoord - float2(0.5, 0.5);
|
||||
float shadowAngle = atan2(shadowDelta.y, -shadowDelta.x);
|
||||
float shadowAmt = abs(dot(float2(1.0, 0.0), shadowDelta)) * sin(shadowAngle * 6.0);
|
||||
color.rgb = lerp(color.rgb, (float3)0.0, pow(shadowAmt, 2.0) * distortAmt * 4.0);
|
||||
|
||||
color.a = step(0.0, texCoord.x) * step(texCoord.x, 1.0) *
|
||||
step(0.0, texCoord.y) * step(texCoord.y, 1.0);
|
||||
delta = texCoord - center;
|
||||
color.a *= step(dot(delta, delta), 0.5);
|
||||
color.a *= step(progress, 0.9);
|
||||
color.rgb *= color.a;
|
||||
|
||||
// Apply hole color
|
||||
float holeCornea = smoothstep(holeSize * 0.03, holeSize * 0.05, dist);
|
||||
float3 colorOuter = color.rgb;
|
||||
color.rgb = lerp(color.rgb, (float3)0.0, holeAmt);
|
||||
color.rgb = lerp(color.rgb, pow(colorOuter, (float3)2.0), holeAmt * holeCornea);
|
||||
color.a = max(color.a, holeAmt);
|
||||
#elif FADEEFFECT == 21
|
||||
// CRT
|
||||
float2 texCoordOrig = texCoord;
|
||||
texCoord -= (float2)0.5;
|
||||
texCoord.y *= (1.0 + pow(smoothstep(0.2, 0.6, progress), 2.0) * g_Height * 0.5);
|
||||
texCoord.x *= (1.0 - pow(smoothstep(0.05, 0.25, progress), 2.0) * 0.8);
|
||||
texCoord.x *= (1.0 + pow(smoothstep(0.4, 0.8, progress), 2.0) * g_Width * 0.25);
|
||||
texCoord += (float2)0.5;
|
||||
|
||||
float scroll = smoothstep(0.0, 0.1, progress) * smoothstep(0.2, 0.1, progress) * 0.2;
|
||||
scroll -= pow(smoothstep(0.1, 0.4, progress), 1.4) * 5.0;
|
||||
float amtGlowWhite = smoothstep(0.1, 0.4, progress);
|
||||
float fadeBlack = smoothstep(0.7, 0.81, progress);
|
||||
float amtOutsideBounds = saturate(step(texCoord.y, 0.0) + step(1.0, texCoord.y) +
|
||||
step(texCoord.x, 0.0) + step(1.0, texCoord.x) +
|
||||
fadeBlack);
|
||||
|
||||
float2 texCoordPreScroll = texCoord;
|
||||
texCoord.y = frac(texCoord.y + scroll);
|
||||
float chroma = pow(smoothstep(0.07, 0.2, progress), 2.0);
|
||||
float chromaMax = 0.04; //0.02;
|
||||
float mip = smoothstep(0.1, 0.3, progress) * 4.0;
|
||||
color.rgb = float3(g_Texture0MipMapped.SampleLevel(g_Texture0SamplerState, texCoord, mip).r,
|
||||
g_Texture0MipMapped.SampleLevel(g_Texture0SamplerState, texCoord + float2(0, chromaMax * chroma), mip).g,
|
||||
g_Texture0MipMapped.SampleLevel(g_Texture0SamplerState, texCoord + float2(0, -chromaMax * chroma), mip).b);
|
||||
color.a = smoothstep(1.0, 0.7, progress);
|
||||
|
||||
float smoothFade = 15.0;
|
||||
float amtOutsideGlow = amtOutsideBounds * (smoothstep(smoothFade, 1.0, texCoordPreScroll.y) * smoothstep(-smoothFade, 0.0, texCoordPreScroll.y));
|
||||
amtOutsideGlow *= smoothstep(smoothFade, 1.0, texCoordPreScroll.x) * smoothstep(-smoothFade, 0.0, texCoordPreScroll.x);
|
||||
amtOutsideGlow = pow(amtOutsideGlow, 4.0);
|
||||
|
||||
float3 outsideColor = snoise(float3(texCoordOrig * float2(g_AspectRatio, 1.0) * 100.0, progress * 10.0));
|
||||
outsideColor = smoothstep((float3)-1.0, (float3)1.0, outsideColor) * smoothstep(0.5, 0.4, progress) * 0.1 *
|
||||
smoothstep(0.5, 0.0, abs(texCoordOrig.y - 0.5));
|
||||
|
||||
color.rgb = lerp(color.rgb, (float3)0.666, amtGlowWhite);
|
||||
color.rgb = lerp(color.rgb, outsideColor, amtOutsideBounds);
|
||||
color.rgb = lerp(color.rgb, float3(0.25, 0.27, 0.33), amtOutsideGlow * (1.0 - fadeBlack));
|
||||
color.rgb *= color.a;
|
||||
|
||||
//color = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoordOrig, 4.0);
|
||||
#elif FADEEFFECT == 22
|
||||
// Radial wipe
|
||||
float2 delta = texCoord - float2(0.5, 0.5);
|
||||
float angle = (atan2(-delta.x, delta.y) + 3.141) / 6.283;
|
||||
float smooth = 0.02;
|
||||
float shadowSmooth = 0.1;
|
||||
|
||||
progress *= 1.0 + smooth;
|
||||
color.a = smoothstep(progress - smooth, progress, angle);
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 23
|
||||
// Glass shatter
|
||||
color.r = g_Texture0.SampleLevel(g_Texture0SamplerState, frac(texCoord), 0.0).r;
|
||||
color.g = g_Texture0.SampleLevel(g_Texture0SamplerState, frac(IN.v_TexCoordBase), 0.0).g;
|
||||
color.b = g_Texture0.SampleLevel(g_Texture0SamplerState, frac(texCoord - (IN.v_TexCoordBase - texCoord)), 0.0).b;
|
||||
|
||||
float3 lightDir = float3(0.707, -0.707, 0.0);
|
||||
float3 worldNormal = normalize(IN.v_WorldNormal);
|
||||
float3 eyeVector = float3(0, 0, 0) - IN.v_WorldPos;
|
||||
float specular = max(0.0, dot(normalize(eyeVector + lightDir), worldNormal));
|
||||
specular = pow(specular, 4.0);
|
||||
|
||||
float light = dot(lightDir, worldNormal) + 1.0;
|
||||
light = pow(light, 1.0);
|
||||
color.rgb *= light;
|
||||
color.rgb += (float3)specular * 2.0;
|
||||
|
||||
color.a = smoothstep(1.0, 0.9, g_Progress);
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 24
|
||||
// Bullets
|
||||
float2 center = float2(0.25 + 0.5 * g_Hash, 0.25 + 0.5 * g_Hash2);
|
||||
|
||||
float shakeTimer = smoothstep(0.05, 0.2, progress);
|
||||
float shakeTimerOct = smoothstep(0.05, 0.5, progress);
|
||||
float motionTimer = smoothstep(0.4, 1.0, progress);
|
||||
float impactTimer = smoothstep(0.0, 0.1, progress);
|
||||
float blackBlendTimer = smoothstep(0.8, 0.7, progress);
|
||||
float alphaTimer = smoothstep(1.0, 0.9, progress);
|
||||
float shakeTranslationBlend = smoothstep(0.05, 0.1, progress) * smoothstep(0.4, 0.05, progress) + smoothstep(0.6, 0.8, progress) * smoothstep(0.9, 0.8, progress);
|
||||
|
||||
shakeTimerOct = pow(shakeTimerOct, 0.2);
|
||||
|
||||
float2 zoomDelta = texCoord - center;
|
||||
float2 zoomDeltaReference = zoomDelta;
|
||||
zoomDelta.x *= g_AspectRatio;
|
||||
zoomDelta = rotateFloat2(zoomDelta, shakeTimerOct * 0.4 * g_Hash2 * lerp(1,-1,step(0.5, g_Hash)) + shakeTimer * (1.0 - shakeTimer) * 0.3 * sin(shakeTimer * 4));
|
||||
zoomDelta.x /= g_AspectRatio;
|
||||
|
||||
float2 shakeNoise = float2(snoise(float2(progress * 10.0, 0.0)), snoise(float2(progress * 10.0, 10.0))) * 0.02 * shakeTranslationBlend;
|
||||
zoomDelta *= 1.0 - motionTimer;
|
||||
zoomDelta *= 1.0 - shakeTimerOct * 0.05;
|
||||
zoomDelta += shakeNoise;
|
||||
|
||||
zoomDeltaReference *= 1.0 - motionTimer;
|
||||
zoomDeltaReference *= 1.0 - shakeTimerOct * 0.05;
|
||||
zoomDeltaReference += shakeNoise;
|
||||
float2 centerMotion = (center - float2(0.5, 0.5)) * (motionTimer) * (1.0 - motionTimer);
|
||||
texCoord = center + zoomDelta + centerMotion;
|
||||
float2 texCoordUnrotated = center + zoomDeltaReference + centerMotion;
|
||||
|
||||
float2 texCoordSkewed = texCoord;
|
||||
texCoordSkewed = texCoordSkewed * (fbm(texCoord * float2(g_AspectRatio, 1.0) * 7.0 + g_Hash, 4) * 0.02 + 1.0);
|
||||
|
||||
float2 delta = texCoordSkewed - center;
|
||||
delta.x *= g_AspectRatio;
|
||||
|
||||
float distance = length(delta);
|
||||
float distanceOriginal = distance;
|
||||
distance = pow(distance, 0.3);
|
||||
float angle = atan2(delta.x, -delta.y) + g_Hash * 99;
|
||||
|
||||
float y = distance * 10.0;
|
||||
|
||||
angle = angle * 10.0;
|
||||
float testOffset1 = snoise(float2(floor(angle), y * 0.4));
|
||||
float testOffset2 = snoise(float2(floor(angle) + 1.0, y * 0.4));
|
||||
float testOffset = lerp(testOffset1, testOffset2, frac(angle));
|
||||
|
||||
float blend1 = snoise(float2(floor(angle), 0.0));
|
||||
float blend2 = snoise(float2(floor(angle) + 1.0, 0.0));
|
||||
float blend = lerp(blend1, blend2, frac(angle));
|
||||
blend = smoothstep(0.5, 0.2, blend);
|
||||
|
||||
float patternDistance = pow(max(0.0, distance - 0.25), 0.1) * 3.0;
|
||||
float test = sin(patternDistance * 40.0 + testOffset * distance * 2.0);
|
||||
float origFlow = test;
|
||||
test = abs(test);
|
||||
test = pow(test, 8.0 + 10.0 * testOffset);
|
||||
test = smoothstep(0.0, 0.2 + 0.8 * testOffset, test);
|
||||
|
||||
float baseOpacity = smoothstep(0.01, 0.017, distanceOriginal) *
|
||||
smoothstep(0.2, 0.01, distanceOriginal);
|
||||
baseOpacity = pow(baseOpacity, 4.0) * impactTimer;
|
||||
|
||||
// Fade out
|
||||
blend *= smoothstep(0.6 * impactTimer, 0.3 * impactTimer, distance - saturate(1.0 - testOffset) * 0.2);
|
||||
|
||||
// Fade in
|
||||
blend *= smoothstep(0.25, 0.3, distance);
|
||||
|
||||
baseOpacity *= 1.0 - snoise(texCoordSkewed * 10.0 + g_Hash) * (1.0 - abs(origFlow * 2.0 - 1.0)) * 2;
|
||||
|
||||
float gradx = ddx(test + testOffset);
|
||||
float grady = ddy(test + testOffset);
|
||||
|
||||
float r = fbm(float2(angle * 0.3, y * 0.4), 3);
|
||||
r = smoothstep(-0.5, 0.5, r);
|
||||
|
||||
float blackCenter = smoothstep(0.017, 0.01, distanceOriginal) * impactTimer;
|
||||
color.a = alphaTimer * lerp(1.0, blackBlendTimer, blackCenter);
|
||||
|
||||
color.rgb = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord + float2(gradx, -grady) * blend, 0.0).rgb;
|
||||
color.rgb = lerp(color.rgb, (0.7 + r) * float3(0.8, 0.85, 1.0), (pow(test * blend * r, 2.0) + baseOpacity - blend * (abs(gradx) - abs(grady))));
|
||||
color.rgb = lerp(color.rgb, (float3)0.0, blackCenter);
|
||||
|
||||
float2 flareDelta = texCoordUnrotated - center;
|
||||
flareDelta.x *= g_AspectRatio;
|
||||
float flareTimerFade = smoothstep(0.0, 0.1, progress);
|
||||
flareDelta.x *= pow(flareTimerFade, 0.1);
|
||||
flareTimerFade = flareTimerFade * (1.0 - flareTimerFade);
|
||||
flareDelta.y /= pow(flareTimerFade, 0.5) + 0.00001;
|
||||
float flare = 1.0 - length(flareDelta);
|
||||
flare *= flareTimerFade;
|
||||
flare = saturate(flare);
|
||||
flare = pow(flare * 4.0, 2.0);
|
||||
color.rgb *= (float3)(1.0) + flare * float3(1.0, 0.7, 0.2);
|
||||
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 25
|
||||
// Ice
|
||||
float freezeOutTimer = pow(smoothstep(1.0, 0.5, progress), 2);
|
||||
float freezeTimer = (smoothstep(0.0, 0.2, progress) * 0.333 + smoothstep(0.25, 0.5, progress) * 0.667) * freezeOutTimer;
|
||||
float fadeTimer = smoothstep(1.0, 0.95, progress);
|
||||
|
||||
float2 center = (float2)0.5;
|
||||
float2 delta = texCoord - center;
|
||||
delta.x *= g_AspectRatio;
|
||||
float distance = length(delta) / max(g_AspectRatio, 1.0);
|
||||
|
||||
float noise = fbm(texCoord * float2(g_AspectRatio, 1.0) * 2.0 + g_Hash, 8) * 0.5 + 0.5;
|
||||
float rift = fbm(texCoord * float2(g_AspectRatio, 1.0) * 3.0 + g_Hash2, 8) * 0.5 + 0.5;
|
||||
rift = smoothstep(0.4, 0.5, rift) * smoothstep(0.55, 0.5, rift);
|
||||
|
||||
float blendTransition = 0.3;
|
||||
float blendDistance = 0.9 - distance;
|
||||
noise *= blendTransition + progress * 0.2 + smoothstep(0.3, 0.4, progress) * 0.1 + smoothstep(0.5, 0.6, progress) * 0.1;
|
||||
noise *= 1.0 + rift * (0.5 + 0.5 * progress) * 0.05;
|
||||
|
||||
float blendNoise = noise + rift * 0.1;
|
||||
float blend = smoothstep(blendDistance - blendNoise * 0.51, blendDistance - blendNoise * 0.5, freezeTimer * (1.0 + blendTransition));
|
||||
|
||||
float mip = blend * 3.0 + blend * rift * 3.0;
|
||||
float2 texCoordOffset = float2(ddx(noise), ddy(noise)) * 100.0;
|
||||
texCoordOffset = pow(abs(texCoordOffset), 2.0) * sign(texCoordOffset);
|
||||
texCoord += texCoordOffset * blend;
|
||||
color.rgb = g_Texture0MipMapped.SampleLevel(g_Texture0SamplerState, texCoord, mip).rgb;
|
||||
color.rgb *= 1.0 + length(texCoordOffset) * 3.0 * blend;
|
||||
color.rgb += float3(0.6, 0.65, 1.0) * blend * noise * 4.0 * pow(distance + rift * 0.1, 2.0);
|
||||
|
||||
texCoord += texCoordOffset * blend * 2.0;
|
||||
float flashLine = smoothstep(progress - 0.4, progress - 0.27, texCoord.x * 0.1 + 0.2 - texCoord.y * 0.005);
|
||||
flashLine = flashLine * (1.0 - flashLine) * 2.0;
|
||||
float flashVert = abs(texCoord.y * 2.0 - 1.0);
|
||||
flashLine *= flashVert;
|
||||
float flashBlend = flashLine;
|
||||
color.rgb += color.rgb * flashBlend * blend;
|
||||
|
||||
color.a = max(blend, step(0.99, freezeOutTimer)) * fadeTimer;
|
||||
color.rgb *= color.a;
|
||||
#elif FADEEFFECT == 26
|
||||
// Boilover
|
||||
//color = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord, 0.0);
|
||||
color.a = 1.0;
|
||||
float blendRipple = smoothstep(0.0, 0.1, progress);
|
||||
float blendUpscale = pow(smoothstep(0.8, 1.0, progress), 2.0);
|
||||
float light = 1.0;
|
||||
|
||||
for (int i = 0; i < 25; ++i)
|
||||
{
|
||||
//float2 centerOffset = float2(snoise(float2(i + g_Hash * 99, i * 99 + g_Hash2 * 33)),
|
||||
// snoise(float2(i * 17 + g_Hash * 71, i * 22 + g_Hash2 * 17)));
|
||||
float3 sharedNoise = g_Texture1Noise.SampleLevel(g_Texture0SamplerStateWrap, float2(i / 25.0 + g_Hash, i / 25.0 + g_Hash2), 0.0).rgb;
|
||||
float2 centerOffset = sharedNoise.rg * 2.0 - 1.0;
|
||||
float2 center = float2(0.5, 0.5) + centerOffset * 0.55;
|
||||
|
||||
//float maxDist = 0.1 + (fbm(center * 99, 2) * 0.5 + 0.5) * 0.33 * progress + 0.5 * blendUpscale;
|
||||
float maxDist = 0.1 + (g_Texture2Clouds.SampleLevel(g_Texture0SamplerStateWrap, center * 99, 0.0).r) * 0.33 * progress + 0.5 * blendUpscale;
|
||||
//float timerOffset = (snoise(float2(i + g_Hash * 54, i * 41 + g_Hash2 * 87)) * 0.5 + 0.5) * 0.9;
|
||||
float timerOffset = sharedNoise.b * 0.9;
|
||||
float animTimer = smoothstep(timerOffset, timerOffset + 0.0001 + 0.5 * smoothstep(1.0, 0.9, progress), progress);
|
||||
animTimer = pow(animTimer, 2.0);
|
||||
|
||||
float2 delta = texCoord - center;
|
||||
float2 deltaRef = delta;
|
||||
delta.x *= g_AspectRatio;
|
||||
float distance = length(delta);
|
||||
|
||||
float rippleTimer = smoothstep(timerOffset - 0.5, timerOffset + 0.5, progress);
|
||||
float ripplePos = distance;
|
||||
ripplePos = smoothstep(ripplePos, ripplePos + 0.1, rippleTimer) *
|
||||
smoothstep(ripplePos + 0.2, ripplePos + 0.1, rippleTimer);
|
||||
|
||||
float2 rippleOffset = normalize(deltaRef) * -0.01 * ripplePos * blendRipple;
|
||||
|
||||
float test = smoothstep(maxDist, 0.0, distance);
|
||||
float anim = test * animTimer * 20.0;
|
||||
|
||||
float angle = atan2(deltaRef.x, -deltaRef.y);
|
||||
float mask = g_Texture2Clouds.SampleLevel(g_Texture0SamplerStateWrap, float2(angle * 0.25, (anim + progress) * 0.1), 0.0).r;
|
||||
//float mask = fbm(float2(angle, anim + progress * 5.0), 3) * 0.5 + 0.5;
|
||||
color.a *= step(anim, mask * 2.0);
|
||||
|
||||
delta *= saturate(1.0 - anim);
|
||||
delta.x /= g_AspectRatio;
|
||||
float2 uvOffset = delta - deltaRef + rippleOffset;
|
||||
texCoord += uvOffset;
|
||||
|
||||
light += dot(normalize(float3(uvOffset, 1.0)), float3(-0.707, 0.707, 0.0)) * 10;
|
||||
}
|
||||
|
||||
color.a *= smoothstep(1.0, 0.9, progress);
|
||||
|
||||
color.rgb = g_Texture0.SampleLevel(g_Texture0SamplerState, texCoord, 0.0).rgb * light;
|
||||
//color.rgb = g_Texture2Clouds.SampleLevel(g_Texture0SamplerState, texCoord, 0.0).rgb;
|
||||
color.rgb *= color.a;
|
||||
#endif
|
||||
return color;
|
||||
}
|
||||
|
||||
PS_OUTPUT main(VS_OUTPUT IN)
|
||||
{
|
||||
PS_OUTPUT OUT;
|
||||
OUT.p_FragColor = PerformEffect(IN, IN.v_TexCoord, g_Progress);
|
||||
return OUT;
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
struct GS_INPUT
|
||||
{
|
||||
float4 a_Position : SV_POSITION;
|
||||
float2 a_TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct GS_OUTPUT
|
||||
{
|
||||
float4 v_Position : SV_POSITION;
|
||||
float2 v_TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
cbuffer g_bufDynamic:register(b0)
|
||||
{
|
||||
const float g_Progress;
|
||||
const float g_Hash;
|
||||
const float g_Hash2;
|
||||
const float g_Random;
|
||||
|
||||
const float g_AspectRatio;
|
||||
const float g_Width;
|
||||
const float g_Height;
|
||||
|
||||
const float4x4 g_ViewProjection;
|
||||
const float4x4 g_ViewProjectionInv;
|
||||
}
|
||||
|
||||
float2 rotateFloat2(float2 v, float r)
|
||||
{
|
||||
float2 cs = float2(cos(r), sin(r));
|
||||
return float2(v.x * cs.x - v.y * cs.y, v.x * cs.y + v.y * cs.x);
|
||||
}
|
||||
|
||||
#if FADEEFFECT == 16
|
||||
// Bricks
|
||||
#define BRICKS_PER_SET 7
|
||||
#define SET_COUNT 4
|
||||
float2 uvsFromInitialPosition(float2 initialPosition)
|
||||
{
|
||||
float2 uvs = initialPosition * 0.5 + float2(0.5, 0.5);
|
||||
uvs.y = 1.0 - uvs.y;
|
||||
return uvs;
|
||||
}
|
||||
|
||||
void makeBrickGeom(float2 origin, float angle, float2 size, float2 uvOrigin, inout TriangleStream<GS_OUTPUT> OutputStream)
|
||||
{
|
||||
float2 halfSize = size * 0.5;
|
||||
halfSize *= float2(g_AspectRatio, 1.0);
|
||||
float2 halfSizeAnimX = rotateFloat2(float2(halfSize.x, 0.0), angle);
|
||||
float2 halfSizeAnimY = rotateFloat2(float2(0.0, halfSize.y), angle);
|
||||
halfSizeAnimX /= float2(g_AspectRatio, 1.0);
|
||||
halfSizeAnimY /= float2(g_AspectRatio, 1.0);
|
||||
|
||||
float2 anim00 = float2(origin.x, origin.y) - halfSizeAnimX - halfSizeAnimY;
|
||||
float2 anim01 = float2(origin.x, origin.y) - halfSizeAnimX + halfSizeAnimY;
|
||||
float2 anim10 = float2(origin.x, origin.y) + halfSizeAnimX - halfSizeAnimY;
|
||||
float2 anim11 = float2(origin.x, origin.y) + halfSizeAnimX + halfSizeAnimY;
|
||||
|
||||
float2 halfSizeUVS = size * 0.5;
|
||||
float2 pos00 = float2(uvOrigin.x - halfSizeUVS.x, uvOrigin.y - halfSizeUVS.y);
|
||||
float2 pos01 = float2(uvOrigin.x - halfSizeUVS.x, uvOrigin.y + halfSizeUVS.y);
|
||||
float2 pos10 = float2(uvOrigin.x + halfSizeUVS.x, uvOrigin.y - halfSizeUVS.y);
|
||||
float2 pos11 = float2(uvOrigin.x + halfSizeUVS.x, uvOrigin.y + halfSizeUVS.y);
|
||||
|
||||
GS_OUTPUT OUT;
|
||||
OUT.v_Position = float4(anim00, 0, 1);
|
||||
OUT.v_TexCoord = uvsFromInitialPosition(pos00);
|
||||
OutputStream.Append(OUT);
|
||||
|
||||
OUT.v_Position = float4(anim01, 0, 1);
|
||||
OUT.v_TexCoord = uvsFromInitialPosition(pos01);
|
||||
OutputStream.Append(OUT);
|
||||
|
||||
OUT.v_Position = float4(anim10, 0, 1);
|
||||
OUT.v_TexCoord = uvsFromInitialPosition(pos10);
|
||||
OutputStream.Append(OUT);
|
||||
|
||||
OUT.v_Position = float4(anim11, 0, 1);
|
||||
OUT.v_TexCoord = uvsFromInitialPosition(pos11);
|
||||
OutputStream.Append(OUT);
|
||||
|
||||
OutputStream.RestartStrip();
|
||||
}
|
||||
|
||||
void makeBrick(float2 origin, float2 size, inout TriangleStream<GS_OUTPUT> OutputStream)
|
||||
{
|
||||
float animPosY = origin.y * 0.5 + 0.5;
|
||||
float animPosX = origin.x * 0.5 + 0.5;
|
||||
float fallDuration = 0.3;
|
||||
float fallOffset = smoothstep(0.0, fallDuration, g_Progress * (1.0 + fallDuration * 1.5) - animPosY - animPosX * 0.2);
|
||||
fallOffset = pow(fallOffset, 2.0);
|
||||
|
||||
float2 animOrigin = origin;
|
||||
animOrigin.y -= fallOffset * (animPosY + 0.2) * 2.6;
|
||||
animOrigin.x += fallOffset * origin.x * 0.333;
|
||||
|
||||
float angle = fallOffset * 3.0 * -origin.x;
|
||||
|
||||
makeBrickGeom(animOrigin, angle, size, origin, OutputStream);
|
||||
}
|
||||
|
||||
[maxvertexcount(4 * BRICKS_PER_SET * SET_COUNT)]
|
||||
void main(point GS_INPUT IN[1], inout TriangleStream<GS_OUTPUT> OutputStream)
|
||||
{
|
||||
float setHeight = 2.0 / (SET_COUNT);
|
||||
float brickHeight = setHeight * 0.5;
|
||||
float brickWidth = 2.0 * 0.333334;
|
||||
float brickWidthHalf = brickWidth * 0.5;
|
||||
float brickHeightHalf = brickHeight * 0.5;
|
||||
|
||||
float2 pos = float2(-1.0, -1.0);
|
||||
for (int set = 0; set < SET_COUNT; ++set)
|
||||
{
|
||||
// First row
|
||||
pos.x = -1.0;
|
||||
makeBrick(pos + float2(brickWidthHalf, brickHeightHalf), float2(brickWidth, brickHeight), OutputStream);
|
||||
|
||||
pos.x += brickWidth;
|
||||
makeBrick(pos + float2(brickWidthHalf, brickHeightHalf), float2(brickWidth, brickHeight), OutputStream);
|
||||
|
||||
pos.x += brickWidth;
|
||||
makeBrick(pos + float2(brickWidthHalf, brickHeightHalf), float2(brickWidth, brickHeight), OutputStream);
|
||||
|
||||
// Second row
|
||||
pos.x = -1.0 - brickWidthHalf;
|
||||
pos.y += brickHeight;
|
||||
makeBrick(pos + float2(brickWidthHalf, brickHeightHalf), float2(brickWidth, brickHeight), OutputStream);
|
||||
|
||||
pos.x += brickWidth;
|
||||
makeBrick(pos + float2(brickWidthHalf, brickHeightHalf), float2(brickWidth, brickHeight), OutputStream);
|
||||
|
||||
pos.x += brickWidth;
|
||||
makeBrick(pos + float2(brickWidthHalf, brickHeightHalf), float2(brickWidth, brickHeight), OutputStream);
|
||||
|
||||
pos.x += brickWidth;
|
||||
makeBrick(pos + float2(brickWidthHalf, brickHeightHalf), float2(brickWidth, brickHeight), OutputStream);
|
||||
|
||||
pos.y += brickHeight;
|
||||
}
|
||||
}
|
||||
#else
|
||||
[maxvertexcount(4)]
|
||||
void main(point GS_INPUT IN[1], inout TriangleStream<GS_OUTPUT> OutputStream)
|
||||
{
|
||||
GS_OUTPUT OUT;
|
||||
OUT.v_Position = float4(-1, -1, 0, 1);
|
||||
OUT.v_TexCoord = float2(0, 1);
|
||||
OutputStream.Append(OUT);
|
||||
|
||||
OUT.v_Position = float4(-1, 1, 0, 1);
|
||||
OUT.v_TexCoord = float2(0, 0);
|
||||
OutputStream.Append(OUT);
|
||||
|
||||
OUT.v_Position = float4(1, -1, 0, 1);
|
||||
OUT.v_TexCoord = float2(1, 1);
|
||||
OutputStream.Append(OUT);
|
||||
|
||||
OUT.v_Position = float4(1, 1, 0, 1);
|
||||
OUT.v_TexCoord = float2(1, 0);
|
||||
OutputStream.Append(OUT);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,125 @@
|
||||
struct VS_INPUT
|
||||
{
|
||||
float3 a_Position : POSITION;
|
||||
float2 a_TexCoord : TEXCOORD0;
|
||||
#if FADEEFFECT == 23
|
||||
float3 a_Center : TEXCOORD1;
|
||||
float3 a_Normal : NORMAL;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 v_Position : SV_POSITION;
|
||||
float2 v_TexCoord : TEXCOORD0;
|
||||
#if FADEEFFECT == 23
|
||||
float2 v_TexCoordBase : TEXCOORD1;
|
||||
float3 v_WorldPos : TEXCOORD2;
|
||||
float3 v_WorldNormal : TEXCOORD3;
|
||||
#endif
|
||||
};
|
||||
|
||||
cbuffer g_bufDynamic:register(b0)
|
||||
{
|
||||
const float g_Progress;
|
||||
const float g_Hash;
|
||||
const float g_Hash2;
|
||||
const float g_Random;
|
||||
|
||||
const float g_AspectRatio;
|
||||
const float g_Width;
|
||||
const float g_Height;
|
||||
|
||||
const float4x4 g_ViewProjection;
|
||||
const float4x4 g_ViewProjectionInv;
|
||||
}
|
||||
|
||||
float nrand(float2 uv)
|
||||
{
|
||||
return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453);
|
||||
}
|
||||
|
||||
float2 rotateFloat2(float2 v, float r)
|
||||
{
|
||||
float2 cs = float2(cos(r), sin(r));
|
||||
return float2(v.x * cs.x - v.y * cs.y, v.x * cs.y + v.y * cs.x);
|
||||
}
|
||||
|
||||
float4x4 rotation3d(float3 axis, float angle)
|
||||
{
|
||||
axis = normalize(axis);
|
||||
float s = sin(angle);
|
||||
float c = cos(angle);
|
||||
float oc = 1.0 - c;
|
||||
|
||||
return float4x4(
|
||||
oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
|
||||
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
|
||||
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
);
|
||||
}
|
||||
|
||||
VS_OUTPUT main(VS_INPUT IN)
|
||||
{
|
||||
VS_OUTPUT OUT;
|
||||
|
||||
OUT.v_Position = float4(IN.a_Position, 1.0);
|
||||
OUT.v_TexCoord = IN.a_TexCoord;
|
||||
|
||||
#if FADEEFFECT == 23
|
||||
// Glass shatter
|
||||
float3 axis = float3(nrand(IN.a_Center * 247.0), nrand(IN.a_Center * 115.0), nrand(IN.a_Center * 531.0));
|
||||
axis -= (float3)0.5;
|
||||
axis = normalize(axis);
|
||||
|
||||
float centerDistance = saturate(length(IN.a_Center));
|
||||
float animProgress = centerDistance * 0.05;
|
||||
animProgress = pow(smoothstep(0.4, 0.8, g_Progress - animProgress), 0.5);
|
||||
|
||||
float3 center = IN.a_Center;
|
||||
|
||||
float3 position = IN.a_Position - center;
|
||||
|
||||
// Move them out of the center
|
||||
center = center * (1.0 + saturate((g_Progress - 0.4) * (1.0 / 0.6)) * 4.0);
|
||||
|
||||
// Move pieaces up and down linearly
|
||||
center.y += pow(saturate((g_Progress - 0.4) * 2.5), 0.5) * 2.0 + saturate((g_Progress - 0.4)) * -5.0;
|
||||
|
||||
// Apply creak offset
|
||||
float creakTimer = smoothstep(0.0, 0.06, g_Progress) * 0.05 +
|
||||
smoothstep(0.1, 0.14, g_Progress) * 0.08 +
|
||||
smoothstep(0.3, 0.36, g_Progress) * 0.15;
|
||||
float creakAmt = max(abs(IN.a_TexCoord.x - 0.5), abs(IN.a_TexCoord.y - 0.5)) * 0.5;
|
||||
float creakSmooth = 0.1;
|
||||
creakAmt = smoothstep(creakAmt, creakAmt + creakSmooth, creakTimer);
|
||||
|
||||
float creakRand = nrand(position.xy * 100);
|
||||
float2 creakOffset = float2(0.02 / g_AspectRatio, 0.02) * (0.5 + creakRand * 1.0);
|
||||
position.xy *= lerp(1.0, max(step(IN.a_Position.z, -0.0001), 1.0 - creakOffset), creakAmt);
|
||||
|
||||
float4x4 anim = rotation3d(axis, animProgress * g_Progress * 10.0);
|
||||
float4x4 animLight = rotation3d(axis, animProgress * g_Progress * 10.0 + creakAmt * 0.25);
|
||||
position = mul(float4(position, 0.0), anim).xyz;
|
||||
|
||||
position += center;
|
||||
|
||||
float3 worldSpaceNormal = mul(float4(IN.a_Normal, 0.0), animLight).xyz;
|
||||
float4 screenSpaceNormal = mul(float4(worldSpaceNormal, 0.0), g_ViewProjection);
|
||||
|
||||
screenSpaceNormal.xyz = normalize(screenSpaceNormal.xyz);
|
||||
|
||||
OUT.v_TexCoordBase = OUT.v_TexCoord;
|
||||
OUT.v_TexCoord.x -= screenSpaceNormal.x * 0.1;
|
||||
OUT.v_TexCoord.y -= screenSpaceNormal.y * 0.1;
|
||||
|
||||
OUT.v_TexCoordBase = lerp(OUT.v_TexCoord, OUT.v_TexCoordBase, 0.1);
|
||||
|
||||
OUT.v_Position = mul(float4(position, 1.0), g_ViewProjection);
|
||||
OUT.v_WorldPos = position;
|
||||
OUT.v_WorldNormal = worldSpaceNormal;
|
||||
#endif
|
||||
|
||||
return OUT;
|
||||
}
|
||||
48
modules/wallpaper-engine/shaders/base/model_fragment_v1.h
Normal file
48
modules/wallpaper-engine/shaders/base/model_fragment_v1.h
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
#include "common_fragment.h"
|
||||
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
uniform vec3 g_Screen;
|
||||
|
||||
#if REFLECTION
|
||||
vec3 ApplyReflection(DECLARE_SAMPLER2D_PARAMETER(reflectionTexture), float reflectionTextureMipMapInfo, float reflectivity, float roughness, float metallic, vec3 screenPos, vec3 normal, vec3 normalizedViewVector)
|
||||
{
|
||||
#if REFLECTION_MAP
|
||||
reflectivity *= componentMaps.z;
|
||||
#endif
|
||||
vec2 screenUV = (screenPos.xy / screenPos.z) * 0.5 + 0.5;
|
||||
|
||||
float fresnelTerm = abs(dot(normal, normalizedViewVector));
|
||||
normal = normalize(mul(normal, CAST3X3(g_ViewProjectionMatrix)));
|
||||
|
||||
#ifdef HLSL
|
||||
normal.y = -normal.y;
|
||||
#endif
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
normal.xy = normal.xy * vec2(0.20 / g_Screen.z, 0.20);
|
||||
#else
|
||||
// Make consistent on X since the width is usually more variable (multi monitors) - bad for phones tho
|
||||
normal.xy = normal.xy * vec2(0.15, 0.15 * g_Screen.z);
|
||||
#endif
|
||||
screenUV += normal.xy * pow(fresnelTerm, 4.0) * 10;
|
||||
float clipReflection = smoothstep(1.3, 1.0, screenUV.x) * smoothstep(-0.3, 0.0, screenUV.x) *
|
||||
smoothstep(1.3, 1.0, screenUV.y) * smoothstep(-0.3, 0.0, screenUV.y);
|
||||
|
||||
vec3 reflectionColor = texSample2DLod(reflectionTexture, screenUV, roughness * reflectionTextureMipMapInfo).rgb * clipReflection;
|
||||
reflectionColor = reflectionColor * (1.0 - fresnelTerm) * reflectivity;
|
||||
reflectionColor = pow(max(CAST3(0.001), reflectionColor), CAST3(2.0 - metallic));
|
||||
|
||||
return saturate(reflectionColor);
|
||||
}
|
||||
#endif
|
||||
|
||||
void ApplyAlphaToCoverage(inout float alpha)
|
||||
{
|
||||
#if ALPHATOCOVERAGE
|
||||
alpha = (alpha - 0.5) / max(fwidth(alpha), 0.0001) + 0.5;
|
||||
#if GLSL
|
||||
if (alpha < 0.5) discard;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
227
modules/wallpaper-engine/shaders/base/model_vertex_v1.h
Normal file
227
modules/wallpaper-engine/shaders/base/model_vertex_v1.h
Normal file
@@ -0,0 +1,227 @@
|
||||
|
||||
#include "common_vertex.h"
|
||||
|
||||
uniform mat4 g_ModelMatrix;
|
||||
uniform mat3 g_NormalModelMatrix;
|
||||
uniform vec3 g_LightAmbientColor;
|
||||
uniform vec3 g_LightSkylightColor;
|
||||
|
||||
#if SKINNING
|
||||
uniform mat4x3 g_Bones[BONECOUNT];
|
||||
|
||||
attribute uvec4 a_BlendIndices;
|
||||
attribute vec4 a_BlendWeights;
|
||||
#endif
|
||||
|
||||
#if (LIGHTING || REFLECTION) && NORMALMAP
|
||||
attribute vec4 a_Tangent4;
|
||||
#endif
|
||||
|
||||
#if MORPHING
|
||||
#if HLSL
|
||||
in uint gl_VertexID;
|
||||
#endif
|
||||
|
||||
uniform uint g_MorphOffsets[12];
|
||||
uniform float g_MorphWeights[12];
|
||||
#endif
|
||||
|
||||
#if MORPHING
|
||||
void ApplyMorphPositionNormal(in uint vertexID, DECLARE_SAMPLER2D_PARAMETER(morphTexture), in vec4 morphTextureTexel, in uint morphOffsets[12], in float morphWeights[12], inout vec3 localPos, inout vec3 localNormal)
|
||||
{
|
||||
vec3 morphPos = CAST3(0.0);
|
||||
vec3 morphNormal = CAST3(0.0);
|
||||
for (uint morphTarget = 0u; morphTarget < morphOffsets[0] % 12u; ++morphTarget)
|
||||
{
|
||||
uint morphMapOffset = vertexID + morphOffsets[1u + morphTarget];
|
||||
vec2 offset = 0.5 * morphTextureTexel.xy;
|
||||
|
||||
#if MORPHING_NORMALS
|
||||
uint morphMapIndex = (morphMapOffset * 6u) / 4u;
|
||||
float morphMapFlip = CASTF((morphMapOffset * 6u) % 4u);
|
||||
|
||||
uint morphPixel1x = morphMapIndex % CASTU(morphTextureTexel.z);
|
||||
uint morphPixel1y = morphMapIndex / CASTU(morphTextureTexel.w);
|
||||
uint morphPixel2x = (morphMapIndex + 1u) % CASTU(morphTextureTexel.z);
|
||||
uint morphPixel2y = (morphMapIndex + 1u) / CASTU(morphTextureTexel.w);
|
||||
|
||||
vec4 morphCol1 = texSample2DLod(morphTexture, vec2(morphPixel1x, morphPixel1y) * morphTextureTexel.xy + offset, 0.0);
|
||||
vec4 morphCol2 = texSample2DLod(morphTexture, vec2(morphPixel2x, morphPixel2y) * morphTextureTexel.xy + offset, 0.0);
|
||||
|
||||
vec3 posDeltaV1 = morphCol1.xyz;
|
||||
vec3 posDeltaV2 = vec3(morphCol1.zw, morphCol2.x);
|
||||
|
||||
vec3 posDelta = mix(posDeltaV1, posDeltaV2, step(1.0, morphMapFlip));
|
||||
morphPos += posDelta.rgb * morphWeights[1u + morphTarget];
|
||||
|
||||
vec3 normalDeltaV1 = vec3(morphCol1.w, morphCol2.xy);
|
||||
vec3 normalDeltaV2 = morphCol2.yzw;
|
||||
|
||||
vec3 normalDelta = mix(normalDeltaV1, normalDeltaV2, step(1.0, morphMapFlip));
|
||||
morphNormal += normalDelta * morphWeights[1u + morphTarget];
|
||||
#else
|
||||
uint morphMapIndex = (morphMapOffset * 3u) / 4u;
|
||||
float morphMapFlip = CASTF((morphMapOffset * 3u) % 4u);
|
||||
|
||||
uint morphPixel1x = morphMapIndex % CASTU(morphTextureTexel.z);
|
||||
uint morphPixel1y = morphMapIndex / CASTU(morphTextureTexel.w);
|
||||
uint morphPixel2x = (morphMapIndex + 1u) % CASTU(morphTextureTexel.z);
|
||||
uint morphPixel2y = (morphMapIndex + 1u) / CASTU(morphTextureTexel.w);
|
||||
|
||||
vec4 morphCol1 = texSample2DLod(morphTexture, vec2(morphPixel1x, morphPixel1y) * morphTextureTexel.xy + offset, 0.0);
|
||||
vec4 morphCol2 = texSample2DLod(morphTexture, vec2(morphPixel2x, morphPixel2y) * morphTextureTexel.xy + offset, 0.0);
|
||||
|
||||
vec3 posDeltaV1 = morphCol1.xyz;
|
||||
vec3 posDeltaV2 = vec3(morphCol1.w, morphCol2.xy);
|
||||
vec3 posDeltaV3 = vec3(morphCol1.zw, morphCol2.x);
|
||||
vec3 posDeltaV4 = morphCol1.yzw;
|
||||
|
||||
vec3 posDelta = mix(posDeltaV1, mix(posDeltaV4, mix(posDeltaV3, posDeltaV2,
|
||||
step(2.5, morphMapFlip)), step(1.5, morphMapFlip)), step(0.5, morphMapFlip));
|
||||
morphPos += posDelta.rgb * morphWeights[1u + morphTarget];
|
||||
#endif
|
||||
}
|
||||
|
||||
localPos += morphPos * morphWeights[0];
|
||||
|
||||
#if MORPHING_NORMALS
|
||||
localNormal = normalize(localNormal + morphNormal * 3.465);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ApplyMorphPosition(in uint vertexID, DECLARE_SAMPLER2D_PARAMETER(morphTexture), in vec4 morphTextureTexel, in uint morphOffsets[12], in float morphWeights[12], inout vec3 localPos)
|
||||
{
|
||||
vec3 morphPos = CAST3(0.0);
|
||||
for (uint morphTarget = 0u; morphTarget < morphOffsets[0] % 12u; ++morphTarget)
|
||||
{
|
||||
uint morphMapOffset = vertexID + morphOffsets[1u + morphTarget];
|
||||
vec2 offset = 0.5 * morphTextureTexel.xy;
|
||||
|
||||
#if MORPHING_NORMALS
|
||||
uint morphMapIndex = (morphMapOffset * 6u) / 4u;
|
||||
float morphMapFlip = CASTF((morphMapOffset * 6u) % 4u);
|
||||
|
||||
uint morphPixel1x = morphMapIndex % CASTU(morphTextureTexel.z);
|
||||
uint morphPixel1y = morphMapIndex / CASTU(morphTextureTexel.w);
|
||||
uint morphPixel2x = (morphMapIndex + 1u) % CASTU(morphTextureTexel.z);
|
||||
uint morphPixel2y = (morphMapIndex + 1u) / CASTU(morphTextureTexel.w);
|
||||
|
||||
vec4 morphCol1 = texSample2DLod(morphTexture, vec2(morphPixel1x, morphPixel1y) * morphTextureTexel.xy + offset, 0.0);
|
||||
vec4 morphCol2 = texSample2DLod(morphTexture, vec2(morphPixel2x, morphPixel2y) * morphTextureTexel.xy + offset, 0.0);
|
||||
|
||||
vec3 posDeltaV1 = morphCol1.xyz;
|
||||
vec3 posDeltaV2 = vec3(morphCol1.zw, morphCol2.x);
|
||||
|
||||
vec3 posDelta = mix(posDeltaV1, posDeltaV2, step(1.0, morphMapFlip));
|
||||
morphPos += posDelta.rgb * morphWeights[1u + morphTarget];
|
||||
#else
|
||||
uint morphMapIndex = (morphMapOffset * 3u) / 4u;
|
||||
float morphMapFlip = CASTF((morphMapOffset * 3u) % 4u);
|
||||
|
||||
uint morphPixel1x = morphMapIndex % CASTU(morphTextureTexel.z);
|
||||
uint morphPixel1y = morphMapIndex / CASTU(morphTextureTexel.w);
|
||||
uint morphPixel2x = (morphMapIndex + 1u) % CASTU(morphTextureTexel.z);
|
||||
uint morphPixel2y = (morphMapIndex + 1u) / CASTU(morphTextureTexel.w);
|
||||
|
||||
vec4 morphCol1 = texSample2DLod(morphTexture, vec2(morphPixel1x, morphPixel1y) * morphTextureTexel.xy + offset, 0.0);
|
||||
vec4 morphCol2 = texSample2DLod(morphTexture, vec2(morphPixel2x, morphPixel2y) * morphTextureTexel.xy + offset, 0.0);
|
||||
|
||||
vec3 posDeltaV1 = morphCol1.xyz;
|
||||
vec3 posDeltaV2 = vec3(morphCol1.w, morphCol2.xy);
|
||||
vec3 posDeltaV3 = vec3(morphCol1.zw, morphCol2.x);
|
||||
vec3 posDeltaV4 = morphCol1.yzw;
|
||||
|
||||
vec3 posDelta = mix(posDeltaV1, mix(posDeltaV4, mix(posDeltaV3, posDeltaV2,
|
||||
step(2.5, morphMapFlip)), step(1.5, morphMapFlip)), step(0.5, morphMapFlip));
|
||||
morphPos += posDelta.rgb * morphWeights[1u + morphTarget];
|
||||
#endif
|
||||
}
|
||||
|
||||
localPos += morphPos * morphWeights[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
void ApplySkinningPositionNormal(in vec3 position, in vec3 normal, in uvec4 blendIndices, in vec4 blendWeights, out vec4 worldPosition, out vec3 worldNormal)
|
||||
{
|
||||
#if SKINNING
|
||||
position.xyz = mul(vec4(position, 1.0), g_Bones[blendIndices.x] * blendWeights.x +
|
||||
g_Bones[blendIndices.y] * blendWeights.y +
|
||||
g_Bones[blendIndices.z] * blendWeights.z +
|
||||
g_Bones[blendIndices.w] * blendWeights.w);
|
||||
#endif
|
||||
|
||||
worldPosition = mul(vec4(position, 1.0), g_ModelMatrix);
|
||||
|
||||
#if SKINNING
|
||||
normal = mul(normal, CAST3X3(g_Bones[blendIndices.x]) * blendWeights.x +
|
||||
CAST3X3(g_Bones[blendIndices.y]) * blendWeights.y +
|
||||
CAST3X3(g_Bones[blendIndices.z]) * blendWeights.z +
|
||||
CAST3X3(g_Bones[blendIndices.w]) * blendWeights.w);
|
||||
#endif
|
||||
|
||||
worldNormal = mul(normal, g_NormalModelMatrix);
|
||||
}
|
||||
|
||||
void ApplyPositionNormal(in vec3 position, in vec3 normal, out vec4 worldPosition, out vec3 worldNormal)
|
||||
{
|
||||
worldPosition = mul(vec4(position, 1.0), g_ModelMatrix);
|
||||
worldNormal = mul(normal, g_NormalModelMatrix);
|
||||
}
|
||||
|
||||
void ApplySkinningPosition(in vec3 position, in uvec4 blendIndices, in vec4 blendWeights, out vec4 worldPosition)
|
||||
{
|
||||
#if SKINNING
|
||||
position.xyz = mul(vec4(position, 1.0), g_Bones[blendIndices.x] * blendWeights.x +
|
||||
g_Bones[blendIndices.y] * blendWeights.y +
|
||||
g_Bones[blendIndices.z] * blendWeights.z +
|
||||
g_Bones[blendIndices.w] * blendWeights.w);
|
||||
#endif
|
||||
|
||||
worldPosition = mul(vec4(position, 1.0), g_ModelMatrix);
|
||||
}
|
||||
|
||||
void ApplyPosition(in vec3 position, out vec4 worldPosition)
|
||||
{
|
||||
worldPosition = mul(vec4(position, 1.0), g_ModelMatrix);
|
||||
}
|
||||
|
||||
#if (LIGHTING || REFLECTION) && NORMALMAP
|
||||
void ApplySkinningTangentSpace(in vec3 worldNormal, in vec4 modelTangent, in uvec4 blendIndices, in vec4 blendWeights, out mat3 tangentSpace)
|
||||
{
|
||||
#if SKINNING
|
||||
vec3 tangent = mul(modelTangent.xyz, CAST3X3(g_Bones[blendIndices.x]) * blendWeights.x +
|
||||
CAST3X3(g_Bones[blendIndices.y]) * blendWeights.y +
|
||||
CAST3X3(g_Bones[blendIndices.z]) * blendWeights.z +
|
||||
CAST3X3(g_Bones[blendIndices.w]) * blendWeights.w);
|
||||
#else
|
||||
vec3 tangent = modelTangent.xyz;
|
||||
#endif
|
||||
|
||||
tangentSpace = BuildTangentSpace(g_NormalModelMatrix, worldNormal, vec4(tangent, modelTangent.w));
|
||||
tangentSpace[0] = normalize(tangentSpace[0]);
|
||||
tangentSpace[1] = normalize(tangentSpace[1]);
|
||||
tangentSpace[2] = normalize(tangentSpace[2]);
|
||||
}
|
||||
|
||||
void ApplyTangentSpace(in vec3 worldNormal, in vec4 modelTangent, out mat3 tangentSpace)
|
||||
{
|
||||
vec3 tangent = modelTangent.xyz;
|
||||
tangentSpace = BuildTangentSpace(g_NormalModelMatrix, worldNormal, vec4(tangent, modelTangent.w));
|
||||
tangentSpace[0] = normalize(tangentSpace[0]);
|
||||
tangentSpace[1] = normalize(tangentSpace[1]);
|
||||
tangentSpace[2] = normalize(tangentSpace[2]);
|
||||
}
|
||||
#endif
|
||||
|
||||
vec3 ApplyAmbientLighting(in vec3 normal)
|
||||
{
|
||||
return mix(g_LightSkylightColor, g_LightAmbientColor, dot(normal, vec3(0, 1, 0)) * 0.5 + 0.5);
|
||||
}
|
||||
|
||||
void ClipSpaceToScreenSpace(in vec4 clipSpacePosition, out vec3 screenSpacePosition)
|
||||
{
|
||||
screenSpacePosition = clipSpacePosition.xyw;
|
||||
#ifdef HLSL
|
||||
screenSpacePosition.y = -screenSpacePosition.y;
|
||||
#endif
|
||||
}
|
||||
22
modules/wallpaper-engine/shaders/blur_h_bloom.frag
Normal file
22
modules/wallpaper-engine/shaders/blur_h_bloom.frag
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
varying vec2 v_TexCoord[13];
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
void main() {
|
||||
vec3 albedo = texSample2D(g_Texture0, v_TexCoord[0]).rgb * 0.006299 +
|
||||
texSample2D(g_Texture0, v_TexCoord[1]).rgb * 0.017298 +
|
||||
texSample2D(g_Texture0, v_TexCoord[2]).rgb * 0.039533 +
|
||||
texSample2D(g_Texture0, v_TexCoord[3]).rgb * 0.075189 +
|
||||
texSample2D(g_Texture0, v_TexCoord[4]).rgb * 0.119007 +
|
||||
texSample2D(g_Texture0, v_TexCoord[5]).rgb * 0.156756 +
|
||||
texSample2D(g_Texture0, v_TexCoord[6]).rgb * 0.171834 +
|
||||
texSample2D(g_Texture0, v_TexCoord[7]).rgb * 0.156756 +
|
||||
texSample2D(g_Texture0, v_TexCoord[8]).rgb * 0.119007 +
|
||||
texSample2D(g_Texture0, v_TexCoord[9]).rgb * 0.075189 +
|
||||
texSample2D(g_Texture0, v_TexCoord[10]).rgb * 0.039533 +
|
||||
texSample2D(g_Texture0, v_TexCoord[11]).rgb * 0.017298 +
|
||||
texSample2D(g_Texture0, v_TexCoord[12]).rgb * 0.006299;
|
||||
|
||||
gl_FragColor = vec4(albedo, 1.0);
|
||||
}
|
||||
26
modules/wallpaper-engine/shaders/blur_h_bloom.vert
Normal file
26
modules/wallpaper-engine/shaders/blur_h_bloom.vert
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
uniform vec2 g_TexelSize;
|
||||
|
||||
varying vec2 v_TexCoord[13];
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1);
|
||||
|
||||
float localTexel = g_TexelSize.y * 8.0;
|
||||
v_TexCoord[0] = vec2(a_TexCoord.x, a_TexCoord.y - localTexel * 6.0);
|
||||
v_TexCoord[1] = vec2(a_TexCoord.x, a_TexCoord.y - localTexel * 5.0);
|
||||
v_TexCoord[2] = vec2(a_TexCoord.x, a_TexCoord.y - localTexel * 4.0);
|
||||
v_TexCoord[3] = vec2(a_TexCoord.x, a_TexCoord.y - localTexel * 3.0);
|
||||
v_TexCoord[4] = vec2(a_TexCoord.x, a_TexCoord.y - localTexel * 2.0);
|
||||
v_TexCoord[5] = vec2(a_TexCoord.x, a_TexCoord.y - localTexel);
|
||||
v_TexCoord[6] = vec2(a_TexCoord.x, a_TexCoord.y);
|
||||
v_TexCoord[7] = vec2(a_TexCoord.x, a_TexCoord.y + localTexel * 1.0);
|
||||
v_TexCoord[8] = vec2(a_TexCoord.x, a_TexCoord.y + localTexel * 2.0);
|
||||
v_TexCoord[9] = vec2(a_TexCoord.x, a_TexCoord.y + localTexel * 3.0);
|
||||
v_TexCoord[10] = vec2(a_TexCoord.x, a_TexCoord.y + localTexel * 4.0);
|
||||
v_TexCoord[11] = vec2(a_TexCoord.x, a_TexCoord.y + localTexel * 5.0);
|
||||
v_TexCoord[12] = vec2(a_TexCoord.x, a_TexCoord.y + localTexel * 6.0);
|
||||
}
|
||||
14
modules/wallpaper-engine/shaders/blur_k3.frag
Normal file
14
modules/wallpaper-engine/shaders/blur_k3.frag
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
#include "common_blur.h"
|
||||
|
||||
varying vec4 v_TexCoord;
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
void main() {
|
||||
#if VERTICAL
|
||||
vec3 albedo = blur3(v_TexCoord.xy, vec2(0, v_TexCoord.w));
|
||||
#else
|
||||
vec3 albedo = blur3(v_TexCoord.xy, vec2(v_TexCoord.z, 0));
|
||||
#endif
|
||||
gl_FragColor = vec4(albedo, 1.0);
|
||||
}
|
||||
14
modules/wallpaper-engine/shaders/blur_k3.vert
Normal file
14
modules/wallpaper-engine/shaders/blur_k3.vert
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
uniform vec4 g_Texture0Resolution;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec4 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1);
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
v_TexCoord.zw = CAST2(1.0) / g_Texture0Resolution.xy;
|
||||
}
|
||||
16
modules/wallpaper-engine/shaders/brushinvert.frag
Normal file
16
modules/wallpaper-engine/shaders/brushinvert.frag
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
varying vec3 g_ScreenPosition;
|
||||
|
||||
void main() {
|
||||
|
||||
vec2 texCoords = g_ScreenPosition.xy / g_ScreenPosition.z;
|
||||
texCoords = texCoords * vec2(0.5, -0.5) + 0.5;
|
||||
vec4 sample = texSample2D(g_Texture0, texCoords);
|
||||
|
||||
float lightness = dot(sample.rgb, vec3(0.3, 0.59, 0.11));
|
||||
float color = step(lightness, 0.5);
|
||||
|
||||
gl_FragColor = vec4(vec3(1, 1, 1) * color, 1.0);
|
||||
}
|
||||
12
modules/wallpaper-engine/shaders/brushinvert.vert
Normal file
12
modules/wallpaper-engine/shaders/brushinvert.vert
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec3 g_ScreenPosition;
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
|
||||
g_ScreenPosition = gl_Position.xyw;
|
||||
}
|
||||
16
modules/wallpaper-engine/shaders/brushpreview.frag
Normal file
16
modules/wallpaper-engine/shaders/brushpreview.frag
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
uniform vec4 g_RenderVar0;
|
||||
|
||||
varying vec2 g_TexCoord;
|
||||
|
||||
void main() {
|
||||
float dist = length(g_TexCoord - CAST2(0.5)) / 0.5;
|
||||
|
||||
//dist = smoothstep(1 - 0.4999 * g_RenderVar0.y, 0.4999 * g_RenderVar0.y, dist);
|
||||
float delta = (1 - 0.4999 * g_RenderVar0.y) - (0.4999 * g_RenderVar0.y);
|
||||
dist = (dist - 0.4999 * g_RenderVar0.y) / delta;
|
||||
dist = 1.0 - max(0, min(1, dist));
|
||||
|
||||
dist = max(0, min(1, dist));
|
||||
gl_FragColor = vec4(vec3(1, 0, 0), dist * g_RenderVar0.x);
|
||||
}
|
||||
12
modules/wallpaper-engine/shaders/brushpreview.vert
Normal file
12
modules/wallpaper-engine/shaders/brushpreview.vert
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 g_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
g_TexCoord = a_TexCoord;
|
||||
}
|
||||
21
modules/wallpaper-engine/shaders/ccsimple.frag
Normal file
21
modules/wallpaper-engine/shaders/ccsimple.frag
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
uniform vec4 g_Params; // {"material":"params","default":"1 1 1 0"}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 albedo = texSample2D(g_Texture0, v_TexCoord);
|
||||
albedo.rgb = mix(CAST3(0.5), albedo.rgb, g_Params.y);
|
||||
|
||||
vec3 hsv = rgb2hsv(albedo.xyz);
|
||||
hsv.z *= g_Params.x;
|
||||
hsv.y *= g_Params.z;
|
||||
hsv.x += g_Params.w;
|
||||
albedo.rgb = hsv2rgb(hsv);
|
||||
|
||||
gl_FragColor = albedo;
|
||||
}
|
||||
10
modules/wallpaper-engine/shaders/ccsimple.vert
Normal file
10
modules/wallpaper-engine/shaders/ccsimple.vert
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1.0);
|
||||
v_TexCoord = a_TexCoord;
|
||||
}
|
||||
191
modules/wallpaper-engine/shaders/chroma4.frag
Normal file
191
modules/wallpaper-engine/shaders/chroma4.frag
Normal file
@@ -0,0 +1,191 @@
|
||||
|
||||
// [PASS] shadow shadowcaster
|
||||
// [COMBO] {"material":"ui_editor_properties_lighting","combo":"LIGHTING","default":1}
|
||||
// [COMBO] {"material":"ui_editor_properties_fog","combo":"FOG","default":1}
|
||||
// [COMBO] {"material":"ui_editor_properties_reflection","combo":"REFLECTION","default":0}
|
||||
// [COMBO] {"material":"ui_editor_properties_rim_lighting","combo":"RIMLIGHTING","default":0,"require":{"LIGHTING":1}}
|
||||
// [COMBO] {"material":"ui_editor_properties_toon_shading","combo":"SHADINGGRADIENT","default":0,"require":{"LIGHTING":1}}
|
||||
// [COMBO] {"material":"ui_editor_properties_tint_mask_in_alpha","combo":"TINTMASKALPHA","default":0}
|
||||
|
||||
#define RIM_LIGHTING_AMOUNT g_RimAmount
|
||||
#define RIM_LIGHTING_EXPONENT g_RimExponent
|
||||
|
||||
#if SHADINGGRADIENT
|
||||
#define GRADIENT_SAMPLER g_Texture4
|
||||
uniform sampler2D g_Texture4; // {"label":"ui_editor_properties_shading_gradient","default":"gradient/gradient_toon_smooth","formatcombo":true,"nonremovable":true,"require":{"SHADINGGRADIENT":1}}
|
||||
#endif
|
||||
uniform float g_RimAmount; // {"material":"rimamount","label":"ui_editor_properties_rim_lighting_amount","default":2.0,"range":[0,5],"group":"ui_editor_properties_rim_lighting"}
|
||||
uniform float g_RimExponent; // {"material":"rimexponent","label":"ui_editor_properties_rim_lighting_exponent","default":4.0,"range":[0.01,10],"group":"ui_editor_properties_rim_lighting"}
|
||||
|
||||
#if LIGHTS_SHADOW_MAPPING
|
||||
#define SHADOW_ATLAS_SAMPLER g_Texture6
|
||||
#define SHADOW_ATLAS_TEXEL g_Texture6Texel
|
||||
uniform sampler2DComparison g_Texture6; // {"hidden":true,"default":"_rt_shadowAtlas"}
|
||||
uniform vec4 g_Texture6Texel;
|
||||
#endif
|
||||
|
||||
#if LIGHTS_COOKIE
|
||||
#define COOKIE_SAMPLER g_Texture7
|
||||
uniform sampler2D g_Texture7; // {"hidden":true,"default":"_alias_lightCookie"}
|
||||
#endif
|
||||
|
||||
#include "base/model_fragment_v1.h"
|
||||
#include "common_pbr_2.h"
|
||||
#include "common_fog.h"
|
||||
|
||||
uniform float g_Brightness; // {"material":"brightness","label":"ui_editor_properties_hdr_brightness","default":1,"range":[0,10]}
|
||||
|
||||
uniform float g_TintAlpha; // {"material":"alpha","label":"ui_editor_properties_opacity","default":1,"range":[0,1]}
|
||||
|
||||
uniform sampler2D g_Texture0; // {"material":"albedo","label":"ui_editor_properties_albedo","default":"util/white"}
|
||||
uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal_map","format":"normalmap","formatcombo":true,"combo":"NORMALMAP"}
|
||||
uniform sampler2D g_Texture2; // {"combo":"PBRMASKS","components":[{"label":"ui_editor_properties_metallic_map","combo":"METALLIC_MAP"},{"label":"ui_editor_properties_roughness_map","combo":"ROUGHNESS_MAP"},{"label":"ui_editor_properties_reflection_map","combo":"REFLECTION_MAP"},{"label":"ui_editor_properties_emissive_map","combo":"EMISSIVE_MAP"}]}
|
||||
|
||||
uniform float g_Roughness; // {"material":"roughness","label":"ui_editor_properties_roughness","default":0.7,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Metallic; // {"material":"metallic","label":"ui_editor_properties_metallic","default":0,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
|
||||
varying vec3 v_WorldNormal;
|
||||
|
||||
#ifdef NORMALMAP
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
varying vec3 v_WorldPos;
|
||||
#endif
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
#if REFLECTION
|
||||
uniform sampler2D g_Texture3; // {"hidden":true,"default":"_rt_MipMappedFrameBuffer"}
|
||||
uniform float g_Reflectivity; // {"material":"reflectivity","label":"ui_editor_properties_reflectivity","default":1,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Texture3MipMapInfo;
|
||||
#endif
|
||||
|
||||
varying vec3 v_ScreenPos;
|
||||
|
||||
uniform vec3 g_EmissiveColor; // {"material":"emissivecolor", "label":"ui_editor_properties_emissive_color", "type": "color", "default":"1 1 1","group":"ui_editor_properties_material"}
|
||||
uniform float g_EmissiveBrightness; // {"material":"emissivebrightness", "label":"ui_editor_properties_emissive_brightness", "default":1.0,"range":[0,10],"group":"ui_editor_properties_material"}
|
||||
|
||||
// <Chroma additions
|
||||
uniform sampler2D g_Texture8; // {"material":"noise","label":"ui_editor_properties_noise","default":"util/noise"}
|
||||
uniform vec4 g_Texture8Resolution;
|
||||
|
||||
uniform vec3 g_SpecularTint; // {"material":"speculartint","label":"ui_editor_properties_specular_tint","type":"color","default":"1 1 1","group":"ui_editor_properties_chroma"}
|
||||
uniform vec3 g_TintColor; // {"material":"color","label":"ui_editor_properties_tint_color","type": "color", "default":"1 1 1"}
|
||||
uniform vec3 g_TintFront; // {"material":"tintfront","label":"ui_editor_properties_tint_front","type": "color", "default":"1 1 1","group":"ui_editor_properties_chroma"}
|
||||
uniform vec3 g_TintBack; // {"material":"tintback","label":"ui_editor_properties_tint_back","type": "color", "default":"1 1 1","group":"ui_editor_properties_chroma"}
|
||||
uniform float g_TintPigmentation; // {"material":"tintpigmentation","label":"ui_editor_properties_pigmentation","default":0.5,"range":[0.0, 1.0],"group":"ui_editor_properties_chroma"}
|
||||
uniform float g_TintExponent; // {"material":"tintwexponent","label":"ui_editor_properties_exponent","default":1.5,"range":[0.01, 4.0],"group":"ui_editor_properties_chroma"}
|
||||
// Chroma additions>
|
||||
|
||||
#require LightingV1
|
||||
|
||||
void main() {
|
||||
vec4 albedo = texSample2D(g_Texture0, v_TexCoord.xy);
|
||||
|
||||
//albedo.rgb *= g_TintColor;
|
||||
#if TINTMASKALPHA
|
||||
float tintMask = albedo.a;
|
||||
albedo.rgb = mix(albedo.rgb, CAST3(max(albedo.x, max(albedo.y, albedo.z))) * g_TintColor, albedo.a);
|
||||
albedo.a = 1.0;
|
||||
#endif
|
||||
|
||||
float metallic = g_Metallic;
|
||||
float roughness = g_Roughness;
|
||||
|
||||
#if PBRMASKS
|
||||
vec4 componentMaps = texSample2D(g_Texture2, v_TexCoord.xy);
|
||||
#endif
|
||||
|
||||
#if METALLIC_MAP
|
||||
metallic = componentMaps.x;
|
||||
#endif
|
||||
|
||||
#if ROUGHNESS_MAP
|
||||
roughness = componentMaps.y;
|
||||
#endif
|
||||
|
||||
float viewDist = length(v_ViewDir.xyz);
|
||||
vec3 normalizedViewVector = v_ViewDir.xyz / viewDist;
|
||||
|
||||
#if NORMALMAP
|
||||
vec3 normal = DecompressNormal(texSample2D(g_Texture1, v_TexCoord.xy));
|
||||
mat3 tangentSpace = mat3(v_Tangent, v_Bitangent, v_Normal);
|
||||
normal = mul(normal, tangentSpace);
|
||||
#else
|
||||
vec3 normal = normalize(v_WorldNormal.xyz);
|
||||
#endif
|
||||
|
||||
// <Chroma additions
|
||||
#if TINTMASKALPHA
|
||||
vec3 chromaTint = mix(g_TintBack, g_TintFront, pow(dot(normalizedViewVector, normal), g_TintExponent));
|
||||
albedo.rgb = mix(albedo.rgb, albedo.rgb * chromaTint, tintMask);
|
||||
#else
|
||||
albedo.rgb *= mix(g_TintBack, g_TintFront, dot(normalizedViewVector, normal));
|
||||
#endif
|
||||
|
||||
vec2 screenUV = (v_ScreenPos.xy / v_ScreenPos.z) * 0.5 + 0.5;
|
||||
screenUV *= g_Screen.xy / g_Texture8Resolution.xy;
|
||||
vec3 pigmentNoise = texSample2D(g_Texture8, screenUV).rgb;
|
||||
float pigmentFactor = abs(sin(9 * viewDist * dot(reflect(pigmentNoise * CAST3(2.0) - CAST3(1.0), normalizedViewVector), normal)));
|
||||
pigmentFactor *= pigmentFactor * pigmentFactor;
|
||||
// Chroma additions>
|
||||
|
||||
vec3 light = CAST3(0.0);
|
||||
|
||||
vec3 f0 = CAST3(0.04);
|
||||
f0 = mix(f0, albedo.rgb, metallic);
|
||||
|
||||
#if LIGHTING
|
||||
vec3 specularTint = g_SpecularTint;
|
||||
#if TINTMASKALPHA
|
||||
specularTint = mix(CAST3(1.0), specularTint, tintMask);
|
||||
#endif
|
||||
light = PerformLighting_V1(v_WorldPos, albedo.rgb, normal, normalizedViewVector, specularTint, f0, roughness, metallic);
|
||||
vec3 ambient = v_LightAmbientColor * albedo.rgb;
|
||||
#else
|
||||
vec3 ambient = albedo.rgb;
|
||||
#endif
|
||||
|
||||
#if EMISSIVE_MAP
|
||||
light = max(light, g_EmissiveColor * albedo.rgb * (componentMaps.a * g_EmissiveBrightness));
|
||||
#endif
|
||||
|
||||
light.rgb += (CAST3(pigmentFactor - 0.25)) * g_TintPigmentation * dot(light.rgb, vec3(0.299,0.587,0.114)); // * light.rgb;
|
||||
albedo.rgb = CombineLighting(light, ambient);
|
||||
|
||||
#if REFLECTION
|
||||
float reflectivity = g_Reflectivity;
|
||||
#if REFLECTION_MAP
|
||||
reflectivity *= componentMaps.z;
|
||||
#endif
|
||||
albedo.rgb += ApplyReflection(MAKE_SAMPLER2D_ARGUMENT(g_Texture3), g_Texture3MipMapInfo, reflectivity, roughness, metallic, v_ScreenPos.xyz, normal, normalizedViewVector);
|
||||
#endif
|
||||
|
||||
#if HDR
|
||||
albedo.rgb *= g_Brightness;
|
||||
|
||||
#if (LIGHTING || REFLECTION) && EMISSIVE_MAP
|
||||
float emissiveOverbright = max(0.0, componentMaps.a * (g_EmissiveBrightness - 1.0));
|
||||
albedo.rgb += g_EmissiveColor * albedo.rgb * emissiveOverbright;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if FOG_HEIGHT || FOG_DIST
|
||||
vec2 fogPixelState = CalculateFogPixelState(viewDist, v_ViewDir.w);
|
||||
albedo.rgb = ApplyFog(albedo.rgb, fogPixelState);
|
||||
#if ADDITIVE
|
||||
albedo.a = ApplyFogAlpha(albedo.a, fogPixelState);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gl_FragColor = albedo;
|
||||
|
||||
ApplyAlphaToCoverage(gl_FragColor.a);
|
||||
}
|
||||
81
modules/wallpaper-engine/shaders/chroma4.vert
Normal file
81
modules/wallpaper-engine/shaders/chroma4.vert
Normal file
@@ -0,0 +1,81 @@
|
||||
|
||||
#include "base/model_vertex_v1.h"
|
||||
|
||||
uniform vec3 g_EyePosition;
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec3 a_Normal;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec3 v_WorldNormal;
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if NORMALMAP
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
#else
|
||||
#endif
|
||||
varying vec3 v_WorldPos;
|
||||
#endif
|
||||
|
||||
varying vec3 v_ScreenPos;
|
||||
|
||||
#if MORPHING
|
||||
uniform sampler2D g_Texture5; // {"material":"morph","hidden":true}
|
||||
uniform vec4 g_Texture5Texel;
|
||||
#endif
|
||||
|
||||
uniform sampler2D g_Texture0; // {"material":"albedo","label":"ui_editor_properties_albedo","default":"util/white"}
|
||||
|
||||
void main() {
|
||||
vec3 localPos = a_Position;
|
||||
vec3 localNormal = a_Normal;
|
||||
|
||||
#if MORPHING
|
||||
ApplyMorphPositionNormal(gl_VertexID, MAKE_SAMPLER2D_ARGUMENT(g_Texture5), g_Texture5Texel, g_MorphOffsets, g_MorphWeights, localPos, localNormal);
|
||||
#endif
|
||||
|
||||
vec4 worldPos;
|
||||
vec3 worldNormal;
|
||||
|
||||
#if SKINNING
|
||||
ApplySkinningPositionNormal(localPos, localNormal, a_BlendIndices, a_BlendWeights, worldPos, worldNormal);
|
||||
#else
|
||||
ApplyPositionNormal(localPos, localNormal, worldPos, worldNormal);
|
||||
#endif
|
||||
|
||||
gl_Position = mul(worldPos, g_ViewProjectionMatrix);
|
||||
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
v_ViewDir.xyz = g_EyePosition - worldPos.xyz;
|
||||
v_ViewDir.w = worldPos.y;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
v_WorldPos = worldPos.xyz;
|
||||
#endif
|
||||
|
||||
#if NORMALMAP
|
||||
mat3 tangentSpace;
|
||||
#if SKINNING
|
||||
ApplySkinningTangentSpace(worldNormal, a_Tangent4, a_BlendIndices, a_BlendWeights, tangentSpace);
|
||||
#else
|
||||
ApplyTangentSpace(worldNormal, a_Tangent4, tangentSpace);
|
||||
#endif
|
||||
|
||||
v_Tangent = tangentSpace[0];
|
||||
v_Bitangent = tangentSpace[1];
|
||||
v_Normal = tangentSpace[2];
|
||||
#endif
|
||||
|
||||
v_WorldNormal.xyz = worldNormal;
|
||||
|
||||
ClipSpaceToScreenSpace(gl_Position, v_ScreenPos);
|
||||
|
||||
v_LightAmbientColor = ApplyAmbientLighting(worldNormal);
|
||||
}
|
||||
16
modules/wallpaper-engine/shaders/combine.frag
Normal file
16
modules/wallpaper-engine/shaders/combine.frag
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
uniform sampler2D g_Texture1;
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 albedo = texSample2D(g_Texture0, v_TexCoord).rgb;
|
||||
|
||||
vec3 bloom = texSample2D(g_Texture1, v_TexCoord).rgb;
|
||||
albedo += bloom;
|
||||
|
||||
gl_FragColor = vec4(albedo, 1.0);
|
||||
}
|
||||
10
modules/wallpaper-engine/shaders/combine.vert
Normal file
10
modules/wallpaper-engine/shaders/combine.vert
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1.0);
|
||||
v_TexCoord = a_TexCoord;
|
||||
}
|
||||
46
modules/wallpaper-engine/shaders/combine_hdr.frag
Normal file
46
modules/wallpaper-engine/shaders/combine_hdr.frag
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
uniform sampler2D g_Texture1;
|
||||
|
||||
uniform vec2 g_TexelSize;
|
||||
|
||||
uniform vec4 g_RenderVar0;
|
||||
|
||||
// Proper gamma conversion http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
|
||||
vec3 lin(vec3 v)
|
||||
{
|
||||
vec3 c = step(0.04045, v);
|
||||
return c * (pow((v + 0.055) / 1.055, CAST3(2.4))) + (1.0 - c) * (v / 12.92);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 albedo = texSample2D(g_Texture0, v_TexCoord).rgb;
|
||||
vec3 bloom1 = texSample2D(g_Texture1, v_TexCoord + g_TexelSize).rgb +
|
||||
texSample2D(g_Texture1, v_TexCoord - g_TexelSize).rgb +
|
||||
texSample2D(g_Texture1, v_TexCoord + vec2(g_TexelSize.x, -g_TexelSize.y)).rgb +
|
||||
texSample2D(g_Texture1, v_TexCoord + vec2(-g_TexelSize.x, g_TexelSize.y)).rgb;
|
||||
bloom1 *= 0.25;
|
||||
|
||||
#if DISPLAYHDR == 1
|
||||
albedo = saturate(albedo);
|
||||
albedo += bloom1;
|
||||
//vec3 hdrFactors = g_RenderVar0.y * smoothstep(CAST3(1.0), CAST3(5.0), albedo) + g_RenderVar0.x;
|
||||
float hdrFactors = g_RenderVar0.y * smoothstep(CAST3(1.0), CAST3(5.0), dot(vec3(0.299, 0.587, 0.114), albedo)) + g_RenderVar0.x;
|
||||
gl_FragColor = vec4(lin((max(CAST3(0.0), albedo))) * hdrFactors, 1.0);
|
||||
#else
|
||||
#if COMBINEDBG == 1
|
||||
albedo = mix(albedo + bloom1, bloom1, step(0.5, v_TexCoord.x) * step(v_TexCoord.y, 0.5));
|
||||
#else
|
||||
albedo += bloom1;
|
||||
#endif
|
||||
|
||||
#if LINEAR == 1
|
||||
gl_FragColor = vec4(saturate(albedo), 1.0);
|
||||
#else
|
||||
gl_FragColor = vec4(saturate(lin(albedo)) * g_RenderVar0.x, 1.0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
10
modules/wallpaper-engine/shaders/combine_hdr.vert
Normal file
10
modules/wallpaper-engine/shaders/combine_hdr.vert
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1.0);
|
||||
v_TexCoord = a_TexCoord;
|
||||
}
|
||||
19
modules/wallpaper-engine/shaders/combine_hdr_editor.frag
Normal file
19
modules/wallpaper-engine/shaders/combine_hdr_editor.frag
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
uniform vec2 g_TexelSize;
|
||||
|
||||
// Proper gamma conversion http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
|
||||
vec3 srgb(vec3 v)
|
||||
{
|
||||
vec3 c = step(0.04045, v);
|
||||
return c * (pow((v + 0.055) / 1.055, 2.4)) + (1 - c) * (v / 12.92);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 albedo = texSample2D(g_Texture0, v_TexCoord).rgb;
|
||||
gl_FragColor = vec4(srgb(saturate(albedo)), 1.0);
|
||||
}
|
||||
10
modules/wallpaper-engine/shaders/combine_hdr_editor.vert
Normal file
10
modules/wallpaper-engine/shaders/combine_hdr_editor.vert
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1.0);
|
||||
v_TexCoord = a_TexCoord;
|
||||
}
|
||||
37
modules/wallpaper-engine/shaders/common.h
Normal file
37
modules/wallpaper-engine/shaders/common.h
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
#define M_PI 3.14159265359
|
||||
#define M_PI_HALF 1.57079632679
|
||||
#define M_PI_2 6.28318530718
|
||||
|
||||
#define SQRT_2 1.41421356237
|
||||
#define SQRT_3 1.73205080756
|
||||
|
||||
vec3 hsv2rgb(vec3 c)
|
||||
{
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
vec3 rgb2hsv(vec3 RGB)
|
||||
{
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0/3.0) : vec4(RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx);
|
||||
float C = Q.x - min(Q.w, Q.y);
|
||||
float H = abs((Q.w - Q.y) / (6.0 * C + 1e-10) + Q.z);
|
||||
|
||||
vec3 HCV = vec3(H, C, Q.x);
|
||||
float S = HCV.y / (HCV.z + 1e-10);
|
||||
return vec3(HCV.x, S, HCV.z);
|
||||
}
|
||||
|
||||
vec2 rotateVec2(vec2 v, float r)
|
||||
{
|
||||
vec2 cs = vec2(cos(r), sin(r));
|
||||
return vec2(v.x * cs.x - v.y * cs.y, v.x * cs.y + v.y * cs.x);
|
||||
}
|
||||
|
||||
float greyscale(vec3 color)
|
||||
{
|
||||
return dot(color, vec3(0.11, 0.59, 0.3));
|
||||
}
|
||||
264
modules/wallpaper-engine/shaders/common_blending.h
Normal file
264
modules/wallpaper-engine/shaders/common_blending.h
Normal file
@@ -0,0 +1,264 @@
|
||||
|
||||
vec4 Desaturate(vec3 color, float Desaturation)
|
||||
{
|
||||
vec3 grayXfer = vec3(0.3, 0.59, 0.11);
|
||||
vec3 gray = CAST3(dot(grayXfer, color));
|
||||
return vec4(mix(color, gray, Desaturation), 1.0);
|
||||
}
|
||||
|
||||
vec3 RGBToHSL(vec3 color)
|
||||
{
|
||||
vec3 hsl;
|
||||
float fmin = min(min(color.r, color.g), color.b);
|
||||
float fmax = max(max(color.r, color.g), color.b);
|
||||
float delta = fmax - fmin;
|
||||
hsl.z = (fmax + fmin) / 2.0;
|
||||
|
||||
if (delta == 0.0)
|
||||
{
|
||||
hsl.x = 0.0;
|
||||
hsl.y = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hsl.z < 0.5)
|
||||
hsl.y = delta / (fmax + fmin);
|
||||
else
|
||||
hsl.y = delta / (2.0 - fmax - fmin);
|
||||
float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta;
|
||||
float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta;
|
||||
float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta;
|
||||
if (color.r == fmax )
|
||||
hsl.x = deltaB - deltaG;
|
||||
else if (color.g == fmax)
|
||||
hsl.x = (1.0 / 3.0) + deltaR - deltaB;
|
||||
else if (color.b == fmax)
|
||||
hsl.x = (2.0 / 3.0) + deltaG - deltaR;
|
||||
|
||||
if (hsl.x < 0.0)
|
||||
hsl.x += 1.0;
|
||||
else if (hsl.x > 1.0)
|
||||
hsl.x -= 1.0;
|
||||
}
|
||||
|
||||
return hsl;
|
||||
}
|
||||
|
||||
float HueToRGB(float f1, float f2, float hue)
|
||||
{
|
||||
if (hue < 0.0)
|
||||
hue += 1.0;
|
||||
else if (hue > 1.0)
|
||||
hue -= 1.0;
|
||||
float res;
|
||||
if ((6.0 * hue) < 1.0)
|
||||
res = f1 + (f2 - f1) * 6.0 * hue;
|
||||
else if ((2.0 * hue) < 1.0)
|
||||
res = f2;
|
||||
else if ((3.0 * hue) < 2.0)
|
||||
res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
|
||||
else
|
||||
res = f1;
|
||||
return res;
|
||||
}
|
||||
|
||||
vec3 HSLToRGB(vec3 hsl)
|
||||
{
|
||||
vec3 rgb;
|
||||
if (hsl.y == 0.0)
|
||||
rgb = CAST3(hsl.z);
|
||||
else
|
||||
{
|
||||
float f2;
|
||||
if (hsl.z < 0.5)
|
||||
f2 = hsl.z * (1.0 + hsl.y);
|
||||
else
|
||||
f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z);
|
||||
float f1 = 2.0 * hsl.z - f2;
|
||||
rgb.r = HueToRGB(f1, f2, hsl.x + (1.0/3.0));
|
||||
rgb.g = HueToRGB(f1, f2, hsl.x);
|
||||
rgb.b= HueToRGB(f1, f2, hsl.x - (1.0/3.0));
|
||||
}
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec3 ContrastSaturationBrightness(vec3 color, float brt, float sat, float con)
|
||||
{
|
||||
const float AvgLumR = 0.5;
|
||||
const float AvgLumG = 0.5;
|
||||
const float AvgLumB = 0.5;
|
||||
|
||||
const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
|
||||
|
||||
vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);
|
||||
vec3 brtColor = color * brt;
|
||||
vec3 intensity = CAST3(dot(brtColor, LumCoeff));
|
||||
vec3 satColor = mix(intensity, brtColor, sat);
|
||||
vec3 conColor = mix(AvgLumin, satColor, con);
|
||||
return conColor;
|
||||
}
|
||||
|
||||
#define BlendLinearDodgef(base, blend) (base + blend)
|
||||
#define BlendLinearBurnf(base, blend) max(base + blend - 1.0, 0.0)
|
||||
#define BlendLightenf(base, blend) max(blend, base)
|
||||
#define BlendDarkenf(base, blend) min(blend, base)
|
||||
#define BlendLinearLightf(base, blend) (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5))))
|
||||
#define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend)))
|
||||
#define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))
|
||||
#define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend)))
|
||||
#define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0))
|
||||
#define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0))
|
||||
#define BlendVividLightf(base, blend) ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5))))
|
||||
#define BlendPinLightf(base, blend) ((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5))))
|
||||
#define BlendHardMixf(base, blend) ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0)
|
||||
#define BlendReflectf(base, blend) ((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0))
|
||||
#define BlendNormal(base, blend) (blend)
|
||||
#define BlendLighten BlendLightenf
|
||||
#define BlendDarken BlendDarkenf
|
||||
#define BlendMultiply(base, blend) (base * blend)
|
||||
#define BlendAverage(base, blend) ((base + blend) / 2.0)
|
||||
#define BlendAdd(base, blend) min(base + blend, CAST3(1.0))
|
||||
#define BlendSubstract(base, blend) max(base + blend - CAST3(1.0), CAST3(0.0))
|
||||
#define BlendDifference(base, blend) abs(base - blend)
|
||||
#define BlendNegation(base, blend) (CAST3(1.0) - abs(CAST3(1.0) - base - blend))
|
||||
#define BlendExclusion(base, blend) (base + blend - 2.0 * base * blend)
|
||||
#define BlendScreen(base, blend) vec3(BlendScreenf(base.r, blend.r), BlendScreenf(base.g, blend.g), BlendScreenf(base.b, blend.b))
|
||||
#define BlendOverlay(base, blend) vec3(BlendOverlayf(base.r, blend.r), BlendOverlayf(base.g, blend.g), BlendOverlayf(base.b, blend.b))
|
||||
#define BlendSoftLight(base, blend) vec3(BlendSoftLightf(base.r, blend.r), BlendSoftLightf(base.g, blend.g), BlendSoftLightf(base.b, blend.b))
|
||||
#define BlendHardLight(base, blend) BlendOverlay(blend, base)
|
||||
#define BlendColorDodge(base, blend) vec3(BlendColorDodgef(base.r, blend.r), BlendColorDodgef(base.g, blend.g), BlendColorDodgef(base.b, blend.b))
|
||||
#define BlendColorBurn(base, blend) vec3(BlendColorBurnf(base.r, blend.r), BlendColorBurnf(base.g, blend.g), BlendColorBurnf(base.b, blend.b))
|
||||
#define BlendLinearLight(base, blend) vec3(BlendLinearLightf(base.r, blend.r), BlendLinearLightf(base.g, blend.g), BlendLinearLightf(base.b, blend.b))
|
||||
#define BlendVividLight(base, blend) vec3(BlendVividLightf(base.r, blend.r), BlendVividLightf(base.g, blend.g), BlendVividLightf(base.b, blend.b))
|
||||
#define BlendPinLight(base, blend) vec3(BlendPinLightf(base.r, blend.r), BlendPinLightf(base.g, blend.g), BlendPinLightf(base.b, blend.b))
|
||||
#define BlendHardMix(base, blend) vec3(BlendHardMixf(base.r, blend.r), BlendHardMixf(base.g, blend.g), BlendHardMixf(base.b, blend.b))
|
||||
#define BlendReflect(base, blend) vec3(BlendReflectf(base.r, blend.r), BlendReflectf(base.g, blend.g), BlendReflectf(base.b, blend.b))
|
||||
#define BlendGlow(base, blend) BlendReflect(blend, base)
|
||||
#define BlendPhoenix(base, blend) (min(base, blend) - max(base, blend) + CAST3(1.0))
|
||||
#define BlendOpacity(base, blend, F, O) mix(base, F(base, blend), O)
|
||||
#define BlendLinearDodge(base, blend) min(base + blend, CAST3(1.0))
|
||||
#define BlendLinearBurn(base, blend) max(base + blend - CAST3(1.0), CAST3(0.0))
|
||||
#define BlendTint(base, blend) (CAST3(max(base.x, max(base.y, base.z))) * blend)
|
||||
|
||||
vec3 BlendHue(vec3 base, vec3 blend)
|
||||
{
|
||||
vec3 baseHSL = RGBToHSL(base);
|
||||
return HSLToRGB(vec3(RGBToHSL(blend).r, baseHSL.g, baseHSL.b));
|
||||
}
|
||||
|
||||
vec3 BlendSaturation(vec3 base, vec3 blend)
|
||||
{
|
||||
vec3 baseHSL = RGBToHSL(base);
|
||||
return HSLToRGB(vec3(baseHSL.r, RGBToHSL(blend).g, baseHSL.b));
|
||||
}
|
||||
|
||||
vec3 BlendColor(vec3 base, vec3 blend)
|
||||
{
|
||||
vec3 blendHSL = RGBToHSL(blend);
|
||||
return HSLToRGB(vec3(blendHSL.r, blendHSL.g, RGBToHSL(base).b));
|
||||
}
|
||||
|
||||
vec3 BlendLuminosity(vec3 base, vec3 blend)
|
||||
{
|
||||
vec3 baseHSL = RGBToHSL(base);
|
||||
return HSLToRGB(vec3(baseHSL.r, baseHSL.g, RGBToHSL(blend).b));
|
||||
}
|
||||
|
||||
vec3 ApplyBlending(const int blendMode, in vec3 A, in vec3 B, in float opacity)
|
||||
{
|
||||
#if BLENDMODE == 1
|
||||
return mix(A,BlendDarken(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 2
|
||||
return mix(A,BlendMultiply(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 3
|
||||
return mix(A,BlendColorBurn(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 4
|
||||
return mix(A,BlendSubstract(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 5
|
||||
return min(A, B);
|
||||
#endif
|
||||
#if BLENDMODE == 6
|
||||
return mix(A,BlendLighten(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 7
|
||||
return mix(A,BlendScreen(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 8
|
||||
return mix(A,BlendColorDodge(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 9
|
||||
return mix(A,BlendAdd(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 10
|
||||
return max(A, B);
|
||||
#endif
|
||||
#if BLENDMODE == 11
|
||||
return mix(A,BlendOverlay(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 12
|
||||
return mix(A,BlendSoftLight(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 13
|
||||
return mix(A,BlendHardLight(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 14
|
||||
return mix(A,BlendVividLight(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 15
|
||||
return mix(A,BlendLinearLight(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 16
|
||||
return mix(A,BlendPinLight(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 17
|
||||
return mix(A,BlendHardMix(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 18
|
||||
return mix(A,BlendDifference(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 19
|
||||
return mix(A,BlendExclusion(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 20
|
||||
return mix(A,BlendSubstract(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 21
|
||||
return mix(A,BlendReflect(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 22
|
||||
return mix(A,BlendGlow(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 23
|
||||
return mix(A,BlendPhoenix(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 24
|
||||
return mix(A,BlendAverage(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 25
|
||||
return mix(A,BlendNegation(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 26
|
||||
return mix(A,BlendHue(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 27
|
||||
return mix(A,BlendSaturation(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 28
|
||||
return mix(A,BlendColor(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 29
|
||||
return mix(A,BlendLuminosity(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 30
|
||||
return mix(A,BlendTint(A,B),opacity);
|
||||
#endif
|
||||
#if BLENDMODE == 31
|
||||
return A + B * opacity;
|
||||
#endif
|
||||
return mix(A,BlendNormal(A,B),opacity);
|
||||
}
|
||||
112
modules/wallpaper-engine/shaders/common_blur.h
Normal file
112
modules/wallpaper-engine/shaders/common_blur.h
Normal file
@@ -0,0 +1,112 @@
|
||||
vec3 blur13(vec2 u, vec2 d)
|
||||
{
|
||||
vec2 o1 = CAST2(1.4091998770852122) * d;
|
||||
vec2 o2 = CAST2(3.2979348079914822) * d;
|
||||
vec2 o3 = CAST2(5.2062900776825969) * d;
|
||||
return texSample2D(g_Texture0, u).rgb * 0.1976406528809576
|
||||
+ texSample2D(g_Texture0, u + o1).rgb * 0.2959855056006557
|
||||
+ texSample2D(g_Texture0, u - o1).rgb * 0.2959855056006557
|
||||
+ texSample2D(g_Texture0, u + o2).rgb * 0.0935333619980593
|
||||
+ texSample2D(g_Texture0, u - o2).rgb * 0.0935333619980593
|
||||
+ texSample2D(g_Texture0, u + o3).rgb * 0.0116608059608062
|
||||
+ texSample2D(g_Texture0, u - o3).rgb * 0.0116608059608062;
|
||||
}
|
||||
vec3 blur7(vec2 u, vec2 d)
|
||||
{
|
||||
vec2 o1 = CAST2(2.3515644035337887) * d;
|
||||
vec2 o2 = CAST2(0.469433779698372) * d;
|
||||
vec2 o3 = CAST2(1.4091998770852121) * d;
|
||||
vec2 o4 = CAST2(3) * d;
|
||||
return texSample2D(g_Texture0, u + o1).rgb * 0.2028175528299753
|
||||
+ texSample2D(g_Texture0, u + o2).rgb * 0.4044856614512112
|
||||
+ texSample2D(g_Texture0, u - o3).rgb * 0.3213933537319605
|
||||
+ texSample2D(g_Texture0, u - o4).rgb * 0.0713034319868530;
|
||||
}
|
||||
vec3 blur3(vec2 u, vec2 d)
|
||||
{
|
||||
return texSample2D(g_Texture0, u + d).rgb * 0.25
|
||||
+ texSample2D(g_Texture0, u).rgb * 0.5
|
||||
+ texSample2D(g_Texture0, u - d).rgb * 0.25;
|
||||
}
|
||||
vec4 blur13a(vec2 u, vec2 d)
|
||||
{
|
||||
vec2 o1 = CAST2(1.4091998770852122) * d;
|
||||
vec2 o2 = CAST2(3.2979348079914822) * d;
|
||||
vec2 o3 = CAST2(5.2062900776825969) * d;
|
||||
return texSample2D(g_Texture0, u) * 0.1976406528809576
|
||||
+ texSample2D(g_Texture0, u + o1) * 0.2959855056006557
|
||||
+ texSample2D(g_Texture0, u - o1) * 0.2959855056006557
|
||||
+ texSample2D(g_Texture0, u + o2) * 0.0935333619980593
|
||||
+ texSample2D(g_Texture0, u - o2) * 0.0935333619980593
|
||||
+ texSample2D(g_Texture0, u + o3) * 0.0116608059608062
|
||||
+ texSample2D(g_Texture0, u - o3) * 0.0116608059608062;
|
||||
}
|
||||
vec4 blur7a(vec2 u, vec2 d)
|
||||
{
|
||||
vec2 o1 = CAST2(2.3515644035337887) * d;
|
||||
vec2 o2 = CAST2(0.469433779698372) * d;
|
||||
vec2 o3 = CAST2(1.4091998770852121) * d;
|
||||
vec2 o4 = CAST2(3) * d;
|
||||
return texSample2D(g_Texture0, u + o1) * 0.2028175528299753
|
||||
+ texSample2D(g_Texture0, u + o2) * 0.4044856614512112
|
||||
+ texSample2D(g_Texture0, u - o3) * 0.3213933537319605
|
||||
+ texSample2D(g_Texture0, u - o4) * 0.0713034319868530;
|
||||
}
|
||||
vec4 blur3a(vec2 u, vec2 d)
|
||||
{
|
||||
return texSample2D(g_Texture0, u + d) * 0.25
|
||||
+ texSample2D(g_Texture0, u) * 0.5
|
||||
+ texSample2D(g_Texture0, u - d) * 0.25;
|
||||
}
|
||||
vec2 blurRotateVec2(vec2 v, float r)
|
||||
{
|
||||
vec2 cs = vec2(cos(r), sin(r));
|
||||
return vec2(v.x * cs.x - v.y * cs.y, v.x * cs.y + v.y * cs.x);
|
||||
}
|
||||
vec4 blurRadial13a(vec2 u, vec2 center, float amt)
|
||||
{
|
||||
vec2 delta = u - center;
|
||||
amt = amt * 0.025;
|
||||
float o1 = 1.4091998770852122 * amt;
|
||||
float o2 = 3.2979348079914822 * amt;
|
||||
float o3 = 5.2062900776825969 * amt;
|
||||
vec2 r1 = blurRotateVec2(delta, o1) - delta;
|
||||
vec2 r2 = blurRotateVec2(delta, o2) - delta;
|
||||
vec2 r3 = blurRotateVec2(delta, o3) - delta;
|
||||
return texSample2D(g_Texture0, u) * 0.1976406528809576
|
||||
+ texSample2D(g_Texture0, center + r1 + delta) * 0.2959855056006557
|
||||
+ texSample2D(g_Texture0, center - r1 + delta) * 0.2959855056006557
|
||||
+ texSample2D(g_Texture0, center + r2 + delta) * 0.0935333619980593
|
||||
+ texSample2D(g_Texture0, center - r2 + delta) * 0.0935333619980593
|
||||
+ texSample2D(g_Texture0, center + r3 + delta) * 0.0116608059608062
|
||||
+ texSample2D(g_Texture0, center - r3 + delta) * 0.0116608059608062;
|
||||
}
|
||||
vec4 blurRadial7a(vec2 u, vec2 center, float amt)
|
||||
{
|
||||
vec2 delta = u - center;
|
||||
amt = amt * 0.025;
|
||||
float o1 = 2.3515644035337887 * amt;
|
||||
float o2 = 0.469433779698372 * amt;
|
||||
float o3 = 1.4091998770852121 * amt;
|
||||
float o4 = 3 * amt;
|
||||
vec2 r1 = blurRotateVec2(delta, o1) - delta;
|
||||
vec2 r2 = blurRotateVec2(delta, o2) - delta;
|
||||
vec2 r3 = blurRotateVec2(delta, -o3) - delta;
|
||||
vec2 r4 = blurRotateVec2(delta, -o4) - delta;
|
||||
|
||||
return texSample2D(g_Texture0, center + r1 + delta) * 0.2028175528299753
|
||||
+ texSample2D(g_Texture0, center + r2 + delta) * 0.4044856614512112
|
||||
+ texSample2D(g_Texture0, center + r3 + delta) * 0.3213933537319605
|
||||
+ texSample2D(g_Texture0, center + r4 + delta) * 0.0713034319868530;
|
||||
}
|
||||
vec4 blurRadial3a(vec2 u, vec2 center, float amt)
|
||||
{
|
||||
vec2 delta = u - center;
|
||||
amt = amt * 0.025;
|
||||
float o1 = amt;
|
||||
vec2 r1 = blurRotateVec2(delta, o1) - delta;
|
||||
|
||||
return texSample2D(g_Texture0, center + delta) * 0.5
|
||||
+ texSample2D(g_Texture0, center + r1 + delta) * 0.25
|
||||
+ texSample2D(g_Texture0, center - r1 + delta) * 0.25;
|
||||
}
|
||||
50
modules/wallpaper-engine/shaders/common_composite.h
Normal file
50
modules/wallpaper-engine/shaders/common_composite.h
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "common_blending.h"
|
||||
|
||||
uniform float g_CompositeAlpha; // {"material":"compositealpha","label":"ui_editor_properties_alpha","default":1,"range":[0.0, 2.0]}
|
||||
uniform vec2 g_CompositeOffset; // {"material":"compositeoffset","label":"ui_editor_properties_offset","default":"0 0","linked":true,"range":[-10.0, 10.0]}
|
||||
uniform vec3 g_CompositeColor; // {"material":"compositecolor","label":"ui_editor_properties_color","default":"1 1 1","type":"color"}
|
||||
|
||||
vec2 ApplyCompositeOffset(vec2 texCoords, vec2 textureResolution)
|
||||
{
|
||||
#if COMPOSITE != 0
|
||||
return texCoords + g_CompositeOffset / textureResolution;
|
||||
#else
|
||||
return texCoords;
|
||||
#endif
|
||||
}
|
||||
|
||||
vec4 ApplyComposite(vec4 original, vec4 effect)
|
||||
{
|
||||
#if COMPOSITEMONO == 1
|
||||
effect.rgb = CAST3(greyscale(effect.rgb));
|
||||
#endif
|
||||
|
||||
effect.rgb *= g_CompositeColor;
|
||||
|
||||
// Only return the effect
|
||||
#if COMPOSITE == 0
|
||||
return effect;
|
||||
#endif
|
||||
|
||||
// Overlay the effect with a blend mode
|
||||
#if COMPOSITE == 1
|
||||
effect.rgb = ApplyBlending(BLENDMODE, original.rgb, effect.rgb, effect.a * g_CompositeAlpha);
|
||||
effect.a = max(effect.a * saturate(g_CompositeAlpha), original.a);
|
||||
#endif
|
||||
|
||||
// Put the effect below the original
|
||||
#if COMPOSITE == 2
|
||||
effect.a *= saturate(g_CompositeAlpha);
|
||||
effect = mix(effect, original, original.a);
|
||||
#endif
|
||||
|
||||
// Turn the pixels where the original is invisible
|
||||
#if COMPOSITE == 3
|
||||
effect.a *= saturate(g_CompositeAlpha);
|
||||
effect.a *= 1.0 - original.a;
|
||||
#endif
|
||||
|
||||
return effect;
|
||||
}
|
||||
55
modules/wallpaper-engine/shaders/common_fog.h
Normal file
55
modules/wallpaper-engine/shaders/common_fog.h
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
#if FOG_DIST
|
||||
uniform vec3 g_FogDistanceColor;
|
||||
uniform vec4 g_FogDistanceParams;
|
||||
#endif
|
||||
|
||||
#if FOG_HEIGHT
|
||||
uniform vec3 g_FogHeightColor;
|
||||
uniform vec4 g_FogHeightParams;
|
||||
#endif
|
||||
|
||||
vec2 CalculateFogPixelState(float viewDirLength, float worldPosHeight)
|
||||
{
|
||||
vec2 result = CAST2(0);
|
||||
#if FOG_DIST
|
||||
result.x = (viewDirLength - g_FogDistanceParams.x) / g_FogDistanceParams.y;
|
||||
#endif
|
||||
#if FOG_HEIGHT
|
||||
result.y = (worldPosHeight - g_FogHeightParams.x) / g_FogHeightParams.y;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
vec3 ApplyFog(in vec3 color, in vec2 fogPixelState)
|
||||
{
|
||||
#if FOG_HEIGHT
|
||||
float fogHeight = saturate(fogPixelState.y);
|
||||
color.rgb = mix(color.rgb, g_FogHeightColor,
|
||||
g_FogHeightParams.z + g_FogHeightParams.w * fogHeight * fogHeight);
|
||||
#endif
|
||||
#if FOG_DIST
|
||||
float fogDistance = saturate(fogPixelState.x);
|
||||
color.rgb = mix(color.rgb, g_FogDistanceColor,
|
||||
g_FogDistanceParams.z + g_FogDistanceParams.w * fogDistance * fogDistance);
|
||||
#endif
|
||||
return color;
|
||||
}
|
||||
|
||||
float ApplyFogAlpha(in float alpha, in vec2 fogPixelState)
|
||||
{
|
||||
#if FOG_DIST
|
||||
float fogDistance = saturate(fogPixelState.x);
|
||||
fogDistance = g_FogDistanceParams.z + g_FogDistanceParams.w * fogDistance * fogDistance;
|
||||
#else
|
||||
float fogDistance = 0.0;
|
||||
#endif
|
||||
#if FOG_HEIGHT
|
||||
float fogHeight = saturate(fogPixelState.y);
|
||||
fogHeight = g_FogHeightParams.z + g_FogHeightParams.w * fogHeight * fogHeight;
|
||||
#else
|
||||
float fogHeight = 0.0;
|
||||
#endif
|
||||
float fogFactor = saturate(max(fogDistance, fogHeight));
|
||||
return alpha * (1.0 - (fogFactor * fogFactor));
|
||||
}
|
||||
40
modules/wallpaper-engine/shaders/common_foliage.h
Normal file
40
modules/wallpaper-engine/shaders/common_foliage.h
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
float CalcLeavesUVWeight(vec2 uvs, vec2 uvBounds)
|
||||
{
|
||||
#if LEAVESUVMODE == 1
|
||||
return saturate((1.0 - uvs.y - uvBounds.x) * uvBounds.y);
|
||||
#elif LEAVESUVMODE == 2
|
||||
return saturate((uvs.y - uvBounds.x) * uvBounds.y);
|
||||
#elif LEAVESUVMODE == 3
|
||||
return saturate((uvs.x - uvBounds.x) * uvBounds.y);
|
||||
#elif LEAVESUVMODE == 4
|
||||
return saturate((1.0 - uvs.x - uvBounds.x) * uvBounds.y);
|
||||
#endif
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
vec3 CalcFoliageAnimation(vec3 worldPos, vec3 localPos, vec2 uvs, float direction, float time, float speedLeaves, float speedBase, float strengthLeaves, float strengthBase, float phase, float scale, float cutoff, float treeHeight, float treeRadius, vec2 uvBounds)
|
||||
{
|
||||
vec3 foliageOffsetForward = vec3(cos(direction), 0, sin(direction));
|
||||
vec3 foliageOffsetUp = vec3(0, 1, 0);
|
||||
|
||||
vec4 fastSines = sin(phase + speedLeaves * time * vec4(1.71717171, -1.56161616, -1.9333, 1.041666666) + worldPos.xzzy * scale * 3.333);
|
||||
vec4 slowSines = sin(phase + speedBase * time * vec4(0.53333, -0.019841, -0.13888889, 0.0024801587) + worldPos.xyyx * scale);
|
||||
fastSines = smoothstep(CAST4(cutoff) + fastSines * 0.1, CAST4(1.0 - cutoff) - fastSines.zwyx * 0.1, fastSines * CAST4(0.5) + CAST4(0.5)) * CAST4(2.0) - CAST4(1.0);
|
||||
float cutoffBase = cutoff * 0.6666;
|
||||
slowSines = smoothstep(CAST4(cutoffBase) + slowSines * 0.1, CAST4(1.0 - cutoffBase) - slowSines.zwyx * 0.1, slowSines * CAST4(0.5) + CAST4(0.5)) * CAST4(2.0) - CAST4(1.0);
|
||||
|
||||
float leafMask = strengthLeaves * smoothstep(-1.2, -0.3, sin(dot(worldPos.xyz, foliageOffsetForward) + speedBase * time));
|
||||
float leafDistance = dot(localPos.xz, localPos.xz);
|
||||
float baseMask = smoothstep(0.0, treeHeight, localPos.y);
|
||||
|
||||
vec2 blendParamsA = vec2(treeRadius * treeRadius, treeRadius);
|
||||
vec2 blendParamsB = vec2(treeRadius, treeRadius * treeRadius);
|
||||
vec2 blendParams = mix(blendParamsA, blendParamsB, step(1.0, treeRadius));
|
||||
leafMask *= mix(smoothstep(blendParams.x, blendParams.y, leafDistance), baseMask, baseMask) * CalcLeavesUVWeight(uvs, uvBounds);
|
||||
baseMask *= strengthBase;
|
||||
|
||||
vec4 strengthMask = vec4(leafMask, leafMask, baseMask, baseMask);
|
||||
return dot(strengthMask, vec4(fastSines.xy, slowSines.xy)) * foliageOffsetForward +
|
||||
dot(strengthMask, vec4(fastSines.zw, slowSines.zw)) * foliageOffsetUp;
|
||||
}
|
||||
132
modules/wallpaper-engine/shaders/common_fragment.h
Normal file
132
modules/wallpaper-engine/shaders/common_fragment.h
Normal file
@@ -0,0 +1,132 @@
|
||||
|
||||
#define FORMAT_RGBA8888 0
|
||||
#define FORMAT_RGB888 1
|
||||
#define FORMAT_RGB565 2
|
||||
|
||||
#define FORMAT_ETC1_RGB8 3
|
||||
#define FORMAT_DXT5 4
|
||||
#define FORMAT_ETC2_RGBA8 5
|
||||
#define FORMAT_DXT3 6
|
||||
#define FORMAT_DXT1 7
|
||||
|
||||
#define FORMAT_RG88 8
|
||||
#define FORMAT_R8 9
|
||||
#define FORMAT_RG1616F 10
|
||||
#define FORMAT_R16F 11
|
||||
|
||||
#define FORMAT_BC7 12
|
||||
|
||||
vec3 DecompressNormal(vec4 normal)
|
||||
{
|
||||
#if TEX1FORMAT >= FORMAT_ETC1_RGB8 && TEX1FORMAT <= FORMAT_DXT1 || TEX1FORMAT == FORMAT_BC7
|
||||
normal.yx = normal.yw * 2.0 - vec2(0.965, 1.0);
|
||||
#else
|
||||
#if TEX1FORMAT == FORMAT_RG88
|
||||
normal.xy = normal.rg * 2.0 - 1.0;
|
||||
#else
|
||||
normal.xy = normal.wy * 2.0 - 1.0;
|
||||
#endif
|
||||
#endif
|
||||
normal.z = sqrt(saturate(1.0 - normal.x * normal.x - normal.y * normal.y));
|
||||
return normal.xyz;
|
||||
}
|
||||
|
||||
vec4 DecompressNormalWithMask(vec4 normal)
|
||||
{
|
||||
#if TEX1FORMAT >= FORMAT_ETC1_RGB8 && TEX1FORMAT <= FORMAT_DXT1 || TEX1FORMAT == FORMAT_BC7
|
||||
normal.xw = normal.wx;
|
||||
normal.xy = normal.xy * 2.0 - vec2(0.965, 1.0);
|
||||
#else
|
||||
#if TEX1FORMAT == FORMAT_RG88
|
||||
normal.xy = normal.gr * 2.0 - 1.0;
|
||||
#else
|
||||
normal.xw = normal.wx;
|
||||
normal.xy = normal.xy * 2.0 - 1.0;
|
||||
#endif
|
||||
#endif
|
||||
normal.z = sqrt(saturate(1.0 - normal.x * normal.x - normal.y * normal.y));
|
||||
return normal;
|
||||
}
|
||||
|
||||
float ComputeMaterialSpecularPower(const float roughness, const float metallic)
|
||||
{
|
||||
return (1.01 - roughness) * mix(400.0, 250.0, metallic);
|
||||
}
|
||||
|
||||
float ComputeMaterialSpecularStrength(const float roughness, const float metallic)
|
||||
{
|
||||
return (0.5 + metallic * 0.5) * (1.0 - roughness * 0.9);
|
||||
}
|
||||
|
||||
vec3 ComputeLight(const vec3 normal, const vec3 lightDelta, const vec3 color, const float radius)
|
||||
{
|
||||
float lightDistance = length(lightDelta);
|
||||
float lightAttn = saturate((radius - lightDistance) / radius);
|
||||
return color * (saturate(dot(lightDelta / lightDistance, normal))) * lightAttn * lightAttn;
|
||||
}
|
||||
|
||||
vec3 ComputeLightSpecular(const vec3 normal, const vec3 lightDelta, const vec3 color, const float radius, const vec3 viewDir, const float specularPower, const float specularStrength, const float halfLambert, const float metallicTerm, inout vec3 specularResult)
|
||||
{
|
||||
float lightDistance = length(lightDelta);
|
||||
float lightAttn = saturate((radius - lightDistance) / radius);
|
||||
vec3 lightDir = lightDelta / lightDistance;
|
||||
float specular = max(0.0, dot(normalize(viewDir + lightDir), normal));
|
||||
specularResult += pow(specular, specularPower) * specularStrength * lightAttn * color;
|
||||
float lightDot = dot(lightDir, normal);
|
||||
float halfLambertLight = lightDot * 0.5 + 0.5;
|
||||
lightDot = mix(lightDot, halfLambertLight, halfLambert);
|
||||
float rim = metallicTerm * 2.0;
|
||||
rim = pow((1.0 - saturate(dot(normal, viewDir))) * pow(halfLambertLight, 0.25), 6.0 - rim) * rim;
|
||||
return color * (saturate(lightDot) + rim) * lightAttn * lightAttn;
|
||||
}
|
||||
|
||||
float ConvertSampleR8(vec4 _sample)
|
||||
{
|
||||
#if HLSL_SM30
|
||||
return _sample.a;
|
||||
#else
|
||||
return _sample.r;
|
||||
#endif
|
||||
}
|
||||
|
||||
vec4 ConvertTexture0Format(vec4 _sample)
|
||||
{
|
||||
#if TEX0FORMAT == FORMAT_RG88 || TEX0FORMAT == FORMAT_RG1616F
|
||||
#if HLSL_SM30
|
||||
return _sample.rrra;
|
||||
#else
|
||||
return _sample.rrrg;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TEX0FORMAT == FORMAT_R8 || TEX0FORMAT == FORMAT_R16F
|
||||
#if HLSL_SM30
|
||||
return vec4(1, 1, 1, _sample.a);
|
||||
#else
|
||||
return vec4(1, 1, 1, _sample.r);
|
||||
#endif
|
||||
#endif
|
||||
return _sample;
|
||||
}
|
||||
|
||||
vec4 ConvertTextureFormat(const int format, vec4 _sample)
|
||||
{
|
||||
if (format == FORMAT_RG88 || format == FORMAT_RG1616F)
|
||||
{
|
||||
#if HLSL_SM30
|
||||
return _sample.rrra;
|
||||
#else
|
||||
return _sample.rrrg;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (format == FORMAT_R8 || format == FORMAT_R16F)
|
||||
{
|
||||
#if HLSL_SM30
|
||||
return vec4(1, 1, 1, _sample.a);
|
||||
#else
|
||||
return vec4(1, 1, 1, _sample.r);
|
||||
#endif
|
||||
}
|
||||
return _sample;
|
||||
}
|
||||
117
modules/wallpaper-engine/shaders/common_particles.h
Normal file
117
modules/wallpaper-engine/shaders/common_particles.h
Normal file
@@ -0,0 +1,117 @@
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
uniform mat4 g_ModelMatrixInverse;
|
||||
|
||||
uniform vec3 g_OrientationUp;
|
||||
uniform vec3 g_OrientationRight;
|
||||
uniform vec3 g_OrientationForward;
|
||||
|
||||
uniform vec3 g_ViewUp;
|
||||
uniform vec3 g_ViewRight;
|
||||
uniform vec3 g_EyePosition;
|
||||
|
||||
uniform vec4 g_RenderVar0;
|
||||
uniform vec4 g_RenderVar1;
|
||||
uniform vec4 g_Texture0Resolution;
|
||||
|
||||
#if REFRACT
|
||||
uniform float g_RefractAmount; // {"material":"ui_editor_properties_refract_amount","default":0.05,"range":[-1,1]}
|
||||
#endif
|
||||
|
||||
void ComputeParticleTangents(in vec3 rotation, inout mat3 mRotation, out vec3 right, out vec3 up)
|
||||
{
|
||||
vec3 rCos = cos(rotation);
|
||||
vec3 rSin = sin(rotation);
|
||||
// Apply particle rotation
|
||||
mRotation = mul(mul(
|
||||
mat3(rCos.z, -rSin.z, 0,
|
||||
rSin.z, rCos.z, 0,
|
||||
0, 0, 1),
|
||||
mat3(1, 0, 0,
|
||||
0, rCos.x, -rSin.x,
|
||||
0, rSin.x, rCos.x)),
|
||||
mat3(rCos.y, 0, rSin.y,
|
||||
0, 1, 0,
|
||||
-rSin.y, 0, rCos.y));
|
||||
// Apply screen orientation
|
||||
mRotation = mul(mRotation, mat3(g_OrientationRight, g_OrientationUp, g_OrientationForward));
|
||||
right = mul(vec3(1, 0, 0), mRotation);
|
||||
up = mul(vec3(0, 1, 0), mRotation);
|
||||
}
|
||||
|
||||
void ComputeParticleTrailTangents(vec3 localPosition, vec3 localVelocity, out vec3 right, out vec3 up)
|
||||
{
|
||||
//vec3 eyeDirection = mul(g_OrientationForward, CAST3X3(g_ModelMatrixInverse));
|
||||
vec3 eyeDirection = localPosition - mul(vec4(g_EyePosition, 1.0), g_ModelMatrixInverse).xyz;
|
||||
right = cross(localVelocity, eyeDirection);
|
||||
|
||||
right = normalize(right);
|
||||
float trailLength = length(localVelocity);
|
||||
localVelocity /= trailLength;
|
||||
up = localVelocity * min(trailLength * g_RenderVar0.x, g_RenderVar0.y);
|
||||
}
|
||||
|
||||
vec3 ComputeParticlePosition(vec2 uvs, float textureRatio, vec4 positionAndSize, vec3 right, vec3 up)
|
||||
{
|
||||
return positionAndSize.xyz +
|
||||
(positionAndSize.w * right * (uvs.x-0.5) -
|
||||
positionAndSize.w * up * (uvs.y-0.5) * textureRatio);
|
||||
}
|
||||
|
||||
void ComputeSpriteFrame(float lifetime, out vec4 uvs, out vec2 uvFrameSize, out float frameBlend)
|
||||
{
|
||||
float numFrames = g_RenderVar1.z;
|
||||
float frameWidth = g_RenderVar1.x;
|
||||
float frameHeight = g_RenderVar1.y;
|
||||
|
||||
float currentFrame = floor(lifetime * numFrames);
|
||||
float nextFrame = min(numFrames - 1.0, currentFrame + 1.0);
|
||||
|
||||
#if SPRITESHEETBLENDNPOT
|
||||
float unpaddedWidth = g_Texture0Resolution.z / g_Texture0Resolution.x;
|
||||
float scaledFrameWidth = frameWidth / unpaddedWidth;
|
||||
uvs.y = floor(currentFrame * scaledFrameWidth) * frameHeight;
|
||||
uvs.x = frac(currentFrame * scaledFrameWidth) * unpaddedWidth;
|
||||
uvs.w = floor(nextFrame * scaledFrameWidth) * frameHeight;
|
||||
uvs.z = frac(nextFrame * scaledFrameWidth) * unpaddedWidth;
|
||||
#else
|
||||
uvs.y = floor(currentFrame * frameWidth) * frameHeight;
|
||||
uvs.x = frac(currentFrame * frameWidth);
|
||||
uvs.w = floor(nextFrame * frameWidth) * frameHeight;
|
||||
uvs.z = frac(nextFrame * frameWidth);
|
||||
#endif
|
||||
|
||||
frameBlend = frac(lifetime * numFrames);
|
||||
uvFrameSize = vec2(frameWidth, frameHeight);
|
||||
}
|
||||
|
||||
void ComputeScreenRefractionTangents(in vec3 projectedPositionXYW, in mat3 matZRotation, out vec3 v_ScreenCoord, out vec4 v_ScreenTangents)
|
||||
{
|
||||
v_ScreenCoord = projectedPositionXYW;
|
||||
#ifdef HLSL
|
||||
v_ScreenCoord.y = -v_ScreenCoord.y;
|
||||
#endif
|
||||
|
||||
vec3 right = mul(matZRotation, g_ViewRight);
|
||||
vec3 up = mul(matZRotation, g_ViewUp);
|
||||
|
||||
|
||||
right = mul(right, CAST3X3(g_ModelMatrixInverse));
|
||||
up = mul(up, CAST3X3(g_ModelMatrixInverse));
|
||||
|
||||
right = normalize(right);
|
||||
up = normalize(up);
|
||||
|
||||
right.y = -right.y;
|
||||
up.y = -up.y;
|
||||
|
||||
v_ScreenTangents.xy = vec3(dot(right, g_ViewRight),
|
||||
dot(up, -g_ViewRight), 0).xy;
|
||||
v_ScreenTangents.zw = vec3(dot(right, g_ViewUp),
|
||||
dot(up, -g_ViewUp), 0).xy;
|
||||
|
||||
#if REFRACT
|
||||
v_ScreenTangents *= g_RefractAmount;
|
||||
#endif
|
||||
}
|
||||
|
||||
97
modules/wallpaper-engine/shaders/common_pbr.h
Normal file
97
modules/wallpaper-engine/shaders/common_pbr.h
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
vec3 FresnelSchlick(float lightTheta, vec3 baseReflectance)
|
||||
{
|
||||
return baseReflectance + (1.0 - baseReflectance) * pow(max(1.0 - lightTheta, 0.001), 5.0);
|
||||
}
|
||||
|
||||
vec3 PointSegmentDelta(vec3 pos, vec3 segmentA, vec3 segmentB)
|
||||
{
|
||||
vec3 delta = segmentB - segmentA;
|
||||
float v = dot(delta, delta);
|
||||
if (v == 0.0)
|
||||
return segmentA - pos;
|
||||
return segmentA + saturate(dot(pos - segmentA, segmentB - segmentA) / v) * (segmentB - segmentA) - pos;
|
||||
}
|
||||
|
||||
float Distribution_GGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float rSqr = roughness * roughness;
|
||||
float rSqr2 = rSqr * rSqr;
|
||||
float NH = max(dot(N, H), 0.0);
|
||||
float denominator = (NH * NH * (rSqr2 - 1.0) + 1.0);
|
||||
return rSqr2 / (M_PI * denominator * denominator);
|
||||
}
|
||||
|
||||
float Schlick_GGX(float NV, float roughness)
|
||||
{
|
||||
float roughnessBase = roughness + 1.0;
|
||||
float roughnessScaled = (roughnessBase * roughnessBase) / 8.0;
|
||||
return NV / (NV * (1.0 - roughnessScaled) + roughnessScaled);
|
||||
}
|
||||
|
||||
float GeoSmith(vec3 N, vec3 V, vec3 L, float roughness)
|
||||
{
|
||||
return Schlick_GGX(max(dot(N, V), 0.001), roughness) * Schlick_GGX(max(dot(N, L), 0.001), roughness);
|
||||
}
|
||||
|
||||
// L = worldToLightVector, N = normalVector, V = worldToViewVector
|
||||
vec3 ComputePBRLight(vec3 N, vec3 L, vec3 V,
|
||||
vec3 albedo, vec3 lightColor, vec3 baseReflectance, float roughness, float metallic)
|
||||
{
|
||||
float distance = length(L);
|
||||
L = L / distance;
|
||||
vec3 H = normalize(V + L);
|
||||
|
||||
float NDF = Distribution_GGX(N, H, roughness);
|
||||
float G = GeoSmith(N, V, L, roughness);
|
||||
vec3 F = FresnelSchlick(max(dot(H, V), 0.0), baseReflectance);
|
||||
vec3 numerator = NDF * G * F;
|
||||
|
||||
float dNL = dot(N, L);
|
||||
|
||||
#ifdef GRADIENT_SAMPLER
|
||||
vec3 NL = CAST3(max(dNL * 0.5 + 0.5, 0.0));
|
||||
#if TEX4FORMAT == FORMAT_R8 || TEX4FORMAT == FORMAT_RG88
|
||||
NL = texSample2D(GRADIENT_SAMPLER, vec2(NL.x, 0.0)).rrr;
|
||||
#else
|
||||
NL = texSample2D(GRADIENT_SAMPLER, vec2(NL.x, 0.0)).rgb;
|
||||
#endif
|
||||
|
||||
#if RIMLIGHTING
|
||||
float rimTerm = 1.0 - max(dot(N, V), 0.0);
|
||||
rimTerm = pow(rimTerm, RIM_LIGHTING_EXPONENT) * RIM_LIGHTING_AMOUNT * NL.x * step(0.01, lightColor.x + lightColor.y + lightColor.z);
|
||||
NL = max(NL, CAST3(rimTerm));
|
||||
metallic -= saturate(rimTerm);
|
||||
#endif
|
||||
vec3 denominator = 4.0 * max(dot(N, V), 0.0) * NL;
|
||||
vec3 specular = numerator / max(denominator, CAST3(0.001));
|
||||
#else
|
||||
float NL = max(dNL, 0.0);
|
||||
|
||||
#if RIMLIGHTING
|
||||
float rimTerm = 1.0 - max(dot(N, V), 0.0);
|
||||
rimTerm = pow(rimTerm, RIM_LIGHTING_EXPONENT) * RIM_LIGHTING_AMOUNT * NL * step(0.01, lightColor.x + lightColor.y + lightColor.z);
|
||||
NL = max(NL, rimTerm);
|
||||
metallic -= saturate(rimTerm);
|
||||
#endif
|
||||
float denominator = 4.0 * max(dot(N, V), 0.0) * NL;
|
||||
vec3 specular = numerator / max(denominator, 0.001);
|
||||
#endif
|
||||
|
||||
vec3 diffuse = (1.0 - metallic) * (CAST3(1.0) - F);
|
||||
vec3 radiance = lightColor.xyz / (distance * distance);
|
||||
return (diffuse * albedo / M_PI + specular) * radiance * NL;
|
||||
}
|
||||
|
||||
vec3 CombineLighting(vec3 light, vec3 ambient)
|
||||
{
|
||||
#if HDR
|
||||
float lightLen = length(light);
|
||||
float overbright = (saturate(lightLen - 2.0) * 0.5) / max(0.01, lightLen);
|
||||
return saturate(ambient + light) + (light * overbright);
|
||||
#else
|
||||
return ambient + light;
|
||||
#endif
|
||||
}
|
||||
381
modules/wallpaper-engine/shaders/common_pbr_2.h
Normal file
381
modules/wallpaper-engine/shaders/common_pbr_2.h
Normal file
@@ -0,0 +1,381 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
vec3 FresnelSchlick(float lightTheta, vec3 baseReflectance)
|
||||
{
|
||||
return baseReflectance + (1.0 - baseReflectance) * pow(max(1.0 - lightTheta, 0.001), 5.0);
|
||||
}
|
||||
|
||||
vec3 PointSegmentDelta(vec3 pos, vec3 segmentA, vec3 segmentB)
|
||||
{
|
||||
vec3 delta = segmentB - segmentA;
|
||||
float v = dot(delta, delta);
|
||||
if (v == 0.0)
|
||||
return segmentA - pos;
|
||||
return segmentA + saturate(dot(pos - segmentA, segmentB - segmentA) / v) * (segmentB - segmentA) - pos;
|
||||
}
|
||||
|
||||
float Distribution_GGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float rSqr = roughness * roughness;
|
||||
float rSqr2 = rSqr * rSqr;
|
||||
float NH = max(dot(N, H), 0.0);
|
||||
float denominator = (NH * NH * (rSqr2 - 1.0) + 1.0);
|
||||
return rSqr2 / (M_PI * denominator * denominator);
|
||||
}
|
||||
|
||||
float Schlick_GGX(float NV, float roughness)
|
||||
{
|
||||
float roughnessBase = roughness + 1.0;
|
||||
float roughnessScaled = (roughnessBase * roughnessBase) / 8.0;
|
||||
return NV / (NV * (1.0 - roughnessScaled) + roughnessScaled);
|
||||
}
|
||||
|
||||
float GeoSmith(vec3 N, vec3 V, vec3 L, float roughness)
|
||||
{
|
||||
return Schlick_GGX(max(dot(N, V), 0.001), roughness) * Schlick_GGX(max(dot(N, L), 0.001), roughness);
|
||||
}
|
||||
|
||||
#ifdef SHADOW_ATLAS_SAMPLER
|
||||
#define SHADOW_ATLAS_ANTIALIAS 0
|
||||
#if SHADOW_ATLAS_ANTIALIAS
|
||||
float random(vec2 p){return frac(cos(dot(p,vec2(23.14069263277926,2.665144142690225)))*12345.6789);}
|
||||
#endif
|
||||
float PerformShadowMapping(vec3 projectedCoords, vec4 atlasTransform)
|
||||
{
|
||||
projectedCoords.xy *= atlasTransform.zw;
|
||||
projectedCoords.xy += atlasTransform.xy;
|
||||
|
||||
#if SHADOW_ATLAS_ANTIALIAS
|
||||
vec2 scaled = projectedCoords.xy * SHADOW_ATLAS_TEXEL.zw;
|
||||
vec2 fr = frac(scaled);
|
||||
vec4 boundsLowHigh = vec4(scaled - fr, 0, 0);
|
||||
boundsLowHigh.zw = boundsLowHigh.xy + CAST2(1.0);
|
||||
|
||||
vec4 rands = vec4(random(boundsLowHigh.xy), random(boundsLowHigh.zy), random(boundsLowHigh.xw), random(boundsLowHigh.zw));
|
||||
vec2 interpRandX = mix(rands.xy, rands.zw, fr.y);
|
||||
float interpRand = mix(interpRandX.x, interpRandX.y, fr.x);
|
||||
|
||||
vec2 offsets = CAST2(interpRand) * SHADOW_ATLAS_TEXEL.xy;
|
||||
#else
|
||||
vec2 offsets = SHADOW_ATLAS_TEXEL.xy;
|
||||
#endif
|
||||
|
||||
//return texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy, projectedCoords.z).r;
|
||||
|
||||
//return (
|
||||
// texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy - offsets, projectedCoords.z).r +
|
||||
// texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy + vec2(offsets.x, -offsets.y), projectedCoords.z).r +
|
||||
// texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy + vec2(-offsets.x, offsets.y), projectedCoords.z).r +
|
||||
// texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy + offsets.x, projectedCoords.z).r
|
||||
// )
|
||||
// / 4.0;
|
||||
|
||||
#if LIGHTS_SHADOW_MAPPING_QUALITY == 1
|
||||
return texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy, projectedCoords.z).r;
|
||||
#else
|
||||
vec2 roundOffset = offsets * CAST2(0.81616);
|
||||
offsets *= CAST2(1.02323);
|
||||
return (
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy - roundOffset, projectedCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy + vec2(0, -offsets.y), projectedCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy + vec2(roundOffset.x, -roundOffset.y), projectedCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy + vec2(-offsets.x, 0), projectedCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy, projectedCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy + vec2(offsets.x, 0), projectedCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy + vec2(-roundOffset.x, roundOffset.y), projectedCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy + vec2(0, offsets.y), projectedCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, projectedCoords.xy + roundOffset, projectedCoords.z).r
|
||||
)
|
||||
/ 9.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
float PerformPointShadowMapping(vec4 shadowMapCoords)
|
||||
{
|
||||
#if LIGHTS_SHADOW_MAPPING_QUALITY == 1
|
||||
return texSample2DCompare(SHADOW_ATLAS_SAMPLER, shadowMapCoords.xy, shadowMapCoords.z).r;
|
||||
#else
|
||||
vec2 offsets = SHADOW_ATLAS_TEXEL.xy;
|
||||
vec2 roundOffset = offsets * CAST2(0.81616);
|
||||
offsets *= CAST2(1.02323);
|
||||
return (
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, shadowMapCoords.xy - roundOffset, shadowMapCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, shadowMapCoords.xy + vec2(0, -offsets.y), shadowMapCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, shadowMapCoords.xy + vec2(roundOffset.x, -roundOffset.y), shadowMapCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, shadowMapCoords.xy + vec2(-offsets.x, 0), shadowMapCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, shadowMapCoords.xy, shadowMapCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, shadowMapCoords.xy + vec2(offsets.x, 0), shadowMapCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, shadowMapCoords.xy + vec2(-roundOffset.x, roundOffset.y), shadowMapCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, shadowMapCoords.xy + vec2(0, offsets.y), shadowMapCoords.z).r +
|
||||
texSample2DCompare(SHADOW_ATLAS_SAMPLER, shadowMapCoords.xy + roundOffset, shadowMapCoords.z).r
|
||||
)
|
||||
/ 9.0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
vec3 CalculateProjectedCoords(vec3 worldPos, mat4 shadowViewProjection)
|
||||
{
|
||||
vec4 proj = mul(vec4(worldPos, 1.0), shadowViewProjection);
|
||||
proj.xyz /= proj.w;
|
||||
|
||||
proj.xy = proj.xy * vec2(0.5, -0.5) + CAST2(0.5);
|
||||
|
||||
// step(proj.w, 0.0) to identify behind projection
|
||||
proj.y = mix(proj.y, 2.0, step(proj.w, 0.0));
|
||||
|
||||
return proj.xyz;
|
||||
}
|
||||
|
||||
vec4 CalculateProjectedCoordsCascades(vec3 worldPos, mat4 shadowViewProjection)
|
||||
{
|
||||
vec4 proj = mul(vec4(worldPos, 1.0), shadowViewProjection);
|
||||
proj.xyz /= proj.w;
|
||||
|
||||
// Disable shadow outside bounds
|
||||
proj.w = step(1.0, dot(CAST3(1.0), step(0.99, abs(proj.xyz))));
|
||||
|
||||
proj.xy = proj.xy * CAST2(0.5) + CAST2(0.5);
|
||||
proj.y = 1.0 - proj.y;
|
||||
|
||||
return proj;
|
||||
}
|
||||
|
||||
vec4 CalculateProjectedCoordsPoint(vec3 worldPos, vec3 lightOrigin, vec4 projectionInfo, vec4 atlasTransform)
|
||||
{
|
||||
vec3 lightDelta = worldPos - lightOrigin;
|
||||
vec3 lightDeltaAbs = abs(lightDelta);
|
||||
vec2 viewportScale = vec2(0.5, 0.3333);
|
||||
|
||||
#if LIGHTS_SHADOW_MAPPING_QUALITY == 2 || LIGHTS_SHADOW_MAPPING_QUALITY == 1
|
||||
vec2 viewportPointCompensation = vec2(0.47, -0.47);
|
||||
#elif LIGHTS_SHADOW_MAPPING_QUALITY == 3
|
||||
vec2 viewportPointCompensation = vec2(0.48, -0.48);
|
||||
#else
|
||||
vec2 viewportPointCompensation = vec2(0.49, -0.49);
|
||||
#endif
|
||||
|
||||
vec2 viewportOffset;
|
||||
vec2 viewportOffsetSteps = atlasTransform.zw * viewportScale;
|
||||
mat4 viewMatrix;
|
||||
|
||||
if (lightDeltaAbs.x >= lightDeltaAbs.y && lightDeltaAbs.x >= lightDeltaAbs.z)
|
||||
{
|
||||
if (lightDelta.x >= 0.0)
|
||||
{
|
||||
viewMatrix = mat4(
|
||||
0, 0, -1, 0,
|
||||
0, 1, 0, 0,
|
||||
1, 0, 0, 0,
|
||||
-lightOrigin.z, -lightOrigin.y, lightOrigin.x, 1
|
||||
);
|
||||
viewportOffset = vec2(0.0, 0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
viewMatrix = mat4(
|
||||
0, 0, 1, 0,
|
||||
0, 1, 0, 0,
|
||||
-1, 0, 0, 0,
|
||||
lightOrigin.z, -lightOrigin.y, -lightOrigin.x, 1
|
||||
);
|
||||
viewportOffset = vec2(viewportOffsetSteps.x, 0.0);
|
||||
}
|
||||
}
|
||||
else if (lightDeltaAbs.y >= lightDeltaAbs.x && lightDeltaAbs.y >= lightDeltaAbs.z)
|
||||
{
|
||||
if (lightDelta.y >= 0.0)
|
||||
{
|
||||
viewMatrix = mat4(
|
||||
1, 0, 0, 0,
|
||||
0, 0, -1, 0,
|
||||
0, 1, 0, 0,
|
||||
-lightOrigin.x, -lightOrigin.z, lightOrigin.y, 1
|
||||
);
|
||||
viewportOffset = vec2(0.0, viewportOffsetSteps.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
viewMatrix = mat4(
|
||||
1, 0, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, -1, 0, 0,
|
||||
-lightOrigin.x, lightOrigin.z, -lightOrigin.y, 1
|
||||
);
|
||||
viewportOffset = vec2(viewportOffsetSteps.x, viewportOffsetSteps.y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lightDelta.z >= 0.0)
|
||||
{
|
||||
viewMatrix = mat4(
|
||||
-1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, -1, 0,
|
||||
lightOrigin.x, -lightOrigin.y, lightOrigin.z, 1
|
||||
);
|
||||
viewportOffset = vec2(0.0, viewportOffsetSteps.y * 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
viewMatrix = mat4(
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
-lightOrigin.x, -lightOrigin.y, -lightOrigin.z, 1
|
||||
);
|
||||
viewportOffset = vec2(viewportOffsetSteps.x, viewportOffsetSteps.y * 2);
|
||||
}
|
||||
}
|
||||
|
||||
mat4 project = mat4(
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, projectionInfo.x, projectionInfo.z,
|
||||
0, 0, projectionInfo.y, projectionInfo.w
|
||||
);
|
||||
|
||||
vec4 projectedCoords = mul(mul(vec4(worldPos, 1.0), viewMatrix), project);
|
||||
projectedCoords.xyz /= projectedCoords.w;
|
||||
|
||||
projectedCoords.xy = projectedCoords.xy * viewportPointCompensation + CAST2(0.5);
|
||||
projectedCoords.y = mix(projectedCoords.y, 2.0, step(projectedCoords.w, 0.0));
|
||||
|
||||
projectedCoords.xy *= atlasTransform.zw * viewportScale;
|
||||
projectedCoords.xy += atlasTransform.xy + viewportOffset;
|
||||
return projectedCoords;
|
||||
}
|
||||
|
||||
// L = worldToLightVector, N = normalVector, V = worldToViewVector
|
||||
vec3 ComputePBRLightShadow(vec3 N, vec3 L, vec3 V, vec3 albedo, vec3 lightColor,
|
||||
float radius, float exponent, vec3 specularTint, vec3 baseReflectance, float roughness, float metallic, float shadowFactor)
|
||||
{
|
||||
float distance = length(L);
|
||||
L = L / distance;
|
||||
vec3 H = normalize(V + L);
|
||||
|
||||
float falloff = saturate(1.0 - distance / radius);
|
||||
// Ensure x > 0 && y >= 0 to avoid undefined behavior
|
||||
#if HLSL
|
||||
vec3 radiance = lightColor * pow(falloff + 1.17549435e-38, exponent);
|
||||
#else
|
||||
float flt_min = 6.103515625e-5;
|
||||
vec3 radiance = lightColor * mix(0.0, pow(falloff + flt_min, exponent), step(0.0, falloff - flt_min));
|
||||
#endif
|
||||
|
||||
float NDF = shadowFactor * Distribution_GGX(N, H, roughness);
|
||||
float G = GeoSmith(N, V, L, roughness);
|
||||
vec3 F = FresnelSchlick(max(dot(H, V), 0.0), baseReflectance);
|
||||
vec3 numerator = NDF * G * F;
|
||||
|
||||
vec3 diffuse = (1.0 - metallic) * (CAST3(1.0) - F);
|
||||
float dNL = dot(N, L);
|
||||
|
||||
#if DOUBLESIDEDLIGHTING
|
||||
dNL = abs(dNL);
|
||||
#endif
|
||||
|
||||
#ifdef GRADIENT_SAMPLER
|
||||
vec3 NL = CAST3(max(min(shadowFactor, dNL) * 0.5 + 0.5, 0.0));
|
||||
#if TEX4FORMAT == FORMAT_R8 || TEX4FORMAT == FORMAT_RG88
|
||||
NL = texSample2D(GRADIENT_SAMPLER, vec2(NL.x, 0.0)).rrr;
|
||||
#else
|
||||
NL = texSample2D(GRADIENT_SAMPLER, vec2(NL.x, 0.0)).rgb;
|
||||
#endif
|
||||
|
||||
#if RIMLIGHTING
|
||||
float rimTerm = 1.0 - max(dot(N, V), 0.0);
|
||||
rimTerm = shadowFactor * pow(rimTerm, RIM_LIGHTING_EXPONENT) * RIM_LIGHTING_AMOUNT * NL.x * step(0.001, lightColor.x + lightColor.y + lightColor.z);
|
||||
NL = max(NL, CAST3(rimTerm));
|
||||
metallic -= saturate(rimTerm);
|
||||
#endif
|
||||
vec3 denominator = 4.0 * max(dot(N, V), 0.0) * NL;
|
||||
vec3 specular = numerator / max(denominator, CAST3(0.001));
|
||||
#else
|
||||
float NL = max(dNL * shadowFactor, 0.0);
|
||||
|
||||
#if RIMLIGHTING
|
||||
float rimTerm = 1.0 - max(dot(N, V), 0.0);
|
||||
rimTerm = shadowFactor * pow(rimTerm, RIM_LIGHTING_EXPONENT) * RIM_LIGHTING_AMOUNT * NL * step(0.001, lightColor.x + lightColor.y + lightColor.z);
|
||||
NL = max(NL, rimTerm);
|
||||
metallic -= saturate(rimTerm);
|
||||
#endif
|
||||
float denominator = 4.0 * max(dot(N, V), 0.0) * NL;
|
||||
vec3 specular = numerator / max(denominator, 0.001);
|
||||
#endif
|
||||
|
||||
return (diffuse * albedo / M_PI + specular * specularTint) * radiance * NL;
|
||||
}
|
||||
|
||||
// L = worldToLightVector, N = normalVector, V = worldToViewVector
|
||||
vec3 ComputePBRLightShadowInfinite(vec3 N, vec3 L, vec3 V, vec3 albedo, vec3 lightColor,
|
||||
vec3 specularTint, vec3 baseReflectance, float roughness, float metallic, float shadowFactor)
|
||||
{
|
||||
vec3 H = normalize(V + L);
|
||||
float NDF = shadowFactor * Distribution_GGX(N, H, roughness);
|
||||
float G = GeoSmith(N, V, L, roughness);
|
||||
vec3 F = FresnelSchlick(max(dot(H, V), 0.0), baseReflectance);
|
||||
vec3 numerator = NDF * G * F;
|
||||
|
||||
float dNL = dot(N, L);
|
||||
|
||||
#if DOUBLESIDEDLIGHTING
|
||||
dNL = abs(dNL);
|
||||
#endif
|
||||
|
||||
#ifdef GRADIENT_SAMPLER
|
||||
vec3 NL = CAST3(max(min(shadowFactor, dNL) * 0.5 + 0.5, 0.0));
|
||||
#if TEX4FORMAT == FORMAT_R8 || TEX4FORMAT == FORMAT_RG88
|
||||
NL = texSample2D(GRADIENT_SAMPLER, vec2(NL.x, 0.0)).rrr;
|
||||
#else
|
||||
NL = texSample2D(GRADIENT_SAMPLER, vec2(NL.x, 0.0)).rgb;
|
||||
#endif
|
||||
|
||||
#if RIMLIGHTING
|
||||
float rimTerm = 1.0 - max(dot(N, V), 0.0);
|
||||
rimTerm = shadowFactor * pow(rimTerm, RIM_LIGHTING_EXPONENT) * RIM_LIGHTING_AMOUNT * NL.x * step(0.001, lightColor.x + lightColor.y + lightColor.z);
|
||||
NL = max(NL, CAST3(rimTerm));
|
||||
metallic -= saturate(rimTerm);
|
||||
#endif
|
||||
vec3 denominator = 4.0 * max(dot(N, V), 0.0) * NL;
|
||||
vec3 specular = numerator / max(denominator, CAST3(0.001));
|
||||
#else
|
||||
float NL = max(dNL * shadowFactor, 0.0);
|
||||
|
||||
#if RIMLIGHTING
|
||||
float rimTerm = 1.0 - max(dot(N, V), 0.0);
|
||||
rimTerm = shadowFactor * pow(rimTerm, RIM_LIGHTING_EXPONENT) * RIM_LIGHTING_AMOUNT * NL * step(0.001, lightColor.x + lightColor.y + lightColor.z);
|
||||
NL = max(NL, rimTerm);
|
||||
metallic -= saturate(rimTerm);
|
||||
#endif
|
||||
float denominator = 4.0 * max(dot(N, V), 0.0) * NL;
|
||||
vec3 specular = numerator / max(denominator, 0.001);
|
||||
#endif
|
||||
|
||||
vec3 diffuse = (1.0 - metallic) * (CAST3(1.0) - F);
|
||||
return (diffuse * albedo / M_PI + specular * specularTint) * lightColor * NL;
|
||||
}
|
||||
|
||||
vec3 CombineLighting(vec3 light, vec3 ambient)
|
||||
{
|
||||
#if HDR
|
||||
float lightLen = length(light);
|
||||
float overbright = (saturate(lightLen - 2.0) * 0.5) / max(0.01, lightLen);
|
||||
return saturate(ambient + light) + (light * overbright);
|
||||
#else
|
||||
return ambient + light;
|
||||
#endif
|
||||
}
|
||||
|
||||
vec3 CombineLighting(vec3 light, vec3 baseAmbient, vec3 ambient)
|
||||
{
|
||||
#if HDR
|
||||
float lightLen = length(light);
|
||||
float overbright = (saturate(lightLen - 2.0) * 0.5) / max(0.01, lightLen);
|
||||
return max(baseAmbient, saturate(ambient + light)) + (light * overbright);
|
||||
#else
|
||||
return max(baseAmbient, ambient + light);
|
||||
#endif
|
||||
}
|
||||
65
modules/wallpaper-engine/shaders/common_perspective.h
Normal file
65
modules/wallpaper-engine/shaders/common_perspective.h
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
mat3 squareToQuad(vec2 p0, vec2 p1, vec2 p2, vec2 p3) {
|
||||
mat3 m = mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
|
||||
float dx0 = p0.x;
|
||||
float dy0 = p0.y;
|
||||
float dx1 = p1.x;
|
||||
float dy1 = p1.y;
|
||||
|
||||
float dx2 = p3.x;
|
||||
float dy2 = p3.y;
|
||||
float dx3 = p2.x;
|
||||
float dy3 = p2.y;
|
||||
|
||||
float diffx1 = dx1 - dx3;
|
||||
float diffy1 = dy1 - dy3;
|
||||
float diffx2 = dx2 - dx3;
|
||||
float diffy2 = dy2 - dy3;
|
||||
|
||||
float det = diffx1*diffy2 - diffx2*diffy1;
|
||||
float sumx = dx0 - dx1 + dx3 - dx2;
|
||||
float sumy = dy0 - dy1 + dy3 - dy2;
|
||||
|
||||
if (det == 0.0 || (sumx == 0.0 && sumy == 0.0)) {
|
||||
m[0][0] = dx1 - dx0;
|
||||
m[0][1] = dy1 - dy0;
|
||||
m[0][2] = 0.0;
|
||||
m[1][0] = dx3 - dx1;
|
||||
m[1][1] = dy3 - dy1;
|
||||
m[1][2] = 0.0;
|
||||
m[2][0] = dx0;
|
||||
m[2][1] = dy0;
|
||||
m[2][2] = 1.0;
|
||||
return m;
|
||||
} else {
|
||||
float ovdet = 1.0 / det;
|
||||
float g = (sumx * diffy2 - diffx2 * sumy) * ovdet;
|
||||
float h = (diffx1 * sumy - sumx * diffy1) * ovdet;
|
||||
|
||||
m[0][0] = dx1 - dx0 + g * dx1;
|
||||
m[0][1] = dy1 - dy0 + g * dy1;
|
||||
m[0][2] = g;
|
||||
m[1][0] = dx2 - dx0 + h * dx2;
|
||||
m[1][1] = dy2 - dy0 + h * dy2;
|
||||
m[1][2] = h;
|
||||
m[2][0] = dx0;
|
||||
m[2][1] = dy0;
|
||||
m[2][2] = 1.0;
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
#if HLSL
|
||||
mat3 inverse(mat3 m) {
|
||||
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||
float b01 = a22 * a11 - a12 * a21;
|
||||
float b11 = -a22 * a10 + a12 * a20;
|
||||
float b21 = a21 * a10 - a11 * a20;
|
||||
float det = a00 * b01 + a01 * b11 + a02 * b21;
|
||||
return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),
|
||||
b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),
|
||||
b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;
|
||||
}
|
||||
#endif
|
||||
15
modules/wallpaper-engine/shaders/common_vertex.h
Normal file
15
modules/wallpaper-engine/shaders/common_vertex.h
Normal file
@@ -0,0 +1,15 @@
|
||||
mat3 BuildTangentSpace(const vec3 normal, const vec4 signedTangent)
|
||||
{
|
||||
vec3 tangent = signedTangent.xyz;
|
||||
vec3 bitangent = cross(normal, tangent) * signedTangent.w;
|
||||
return mat3(tangent, bitangent, normal);
|
||||
}
|
||||
|
||||
mat3 BuildTangentSpace(const mat3 modelTransform, const vec3 normal, const vec4 signedTangent)
|
||||
{
|
||||
vec3 tangent = signedTangent.xyz;
|
||||
vec3 bitangent = cross(normal, tangent) * signedTangent.w;
|
||||
return mat3(mul(tangent, modelTransform),
|
||||
mul(bitangent, modelTransform),
|
||||
mul(normal, modelTransform));
|
||||
}
|
||||
9
modules/wallpaper-engine/shaders/compilerbackdrop.frag
Normal file
9
modules/wallpaper-engine/shaders/compilerbackdrop.frag
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
uniform float g_Alpha;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
float fade = smoothstep(0.2, 0.3, v_TexCoord.y) * smoothstep(0.8, 0.7, v_TexCoord.y);
|
||||
gl_FragColor = vec4(0, 0, 0, fade * g_Alpha);
|
||||
}
|
||||
12
modules/wallpaper-engine/shaders/compilerbackdrop.vert
Normal file
12
modules/wallpaper-engine/shaders/compilerbackdrop.vert
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
uniform mat4 g_ModelMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelMatrix);
|
||||
v_TexCoord = a_TexCoord;
|
||||
}
|
||||
14
modules/wallpaper-engine/shaders/composelayer.frag
Normal file
14
modules/wallpaper-engine/shaders/composelayer.frag
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec3 v_ScreenCoord;
|
||||
|
||||
uniform sampler2D g_Texture0; // {"hidden":true}
|
||||
|
||||
void main() {
|
||||
vec2 texCoord = v_ScreenCoord.xy / v_ScreenCoord.z * vec2(0.5, 0.5) + 0.5;
|
||||
gl_FragColor = texSample2D(g_Texture0, texCoord);
|
||||
|
||||
#if CLEARALPHA == 1
|
||||
gl_FragColor.a = 0;
|
||||
#endif
|
||||
}
|
||||
23
modules/wallpaper-engine/shaders/composelayer.vert
Normal file
23
modules/wallpaper-engine/shaders/composelayer.vert
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec3 v_ScreenCoord;
|
||||
|
||||
void main() {
|
||||
v_ScreenCoord = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix).xyw;
|
||||
vec3 position = vec3(a_TexCoord, 0.0);
|
||||
|
||||
#ifdef HLSL
|
||||
position.y = 1.0 - position.y;
|
||||
v_ScreenCoord.y = -v_ScreenCoord.y;
|
||||
#endif
|
||||
|
||||
position.xy = position.xy * 2.0 - 1.0;
|
||||
gl_Position = vec4(position, 1.0);
|
||||
|
||||
v_TexCoord = a_TexCoord;
|
||||
}
|
||||
167
modules/wallpaper-engine/shaders/declarations.json
Normal file
167
modules/wallpaper-engine/shaders/declarations.json
Normal file
@@ -0,0 +1,167 @@
|
||||
{
|
||||
"shaders": [{
|
||||
"value": "default",
|
||||
"shader": "generic4",
|
||||
"label": "Generic",
|
||||
"combos": {},
|
||||
"textures": [{
|
||||
"suffix": "",
|
||||
"formats": [{"value":"rgba8888", "label":"ui_editor_importer_texture_format_rgba8888"},
|
||||
{"value":"rg88", "label":"ui_editor_importer_texture_format_rg88"},
|
||||
{"value":"dxt5", "label":"ui_editor_importer_texture_format_dxt5"}],
|
||||
"config": {
|
||||
"format": "dxt5"
|
||||
}
|
||||
}]
|
||||
}],
|
||||
"imageshaders": [{
|
||||
"value": "imagegeneric",
|
||||
"shader": "genericimage4",
|
||||
"label": "Image",
|
||||
"blending": "translucent",
|
||||
"depthtest": "disabled",
|
||||
"depthwrite": "disabled",
|
||||
"cullmode": "nocull",
|
||||
"combos": {},
|
||||
"textures": [{
|
||||
"suffix": "",
|
||||
"formats": [{"value":"rgba8888", "label":"ui_editor_importer_texture_format_rgba8888"}, {"value":"dxt5", "label":"ui_editor_importer_texture_format_dxt5"}, {"value":"dxt1", "label":"ui_editor_importer_texture_format_dxt1"}],
|
||||
"config": {
|
||||
"clampuvs" : true,
|
||||
"nonpoweroftwo": true,
|
||||
"halfmip": true
|
||||
}
|
||||
}]
|
||||
}],
|
||||
"imageshadersrg88": [{
|
||||
"value": "imagegeneric",
|
||||
"shader": "genericimage4",
|
||||
"label": "Image",
|
||||
"blending": "translucent",
|
||||
"depthtest": "disabled",
|
||||
"depthwrite": "disabled",
|
||||
"cullmode": "nocull",
|
||||
"combos": {},
|
||||
"textures": [{
|
||||
"suffix": "",
|
||||
"formats": [{"value":"rg88", "label":"ui_editor_importer_texture_format_rg88"}],
|
||||
"config": {
|
||||
"clampuvs" : true,
|
||||
"nonpoweroftwo": true,
|
||||
"halfmip": true
|
||||
}
|
||||
}]
|
||||
}],
|
||||
"imageshadersr8": [{
|
||||
"value": "imagegeneric",
|
||||
"shader": "genericimage4",
|
||||
"label": "Image",
|
||||
"blending": "translucent",
|
||||
"depthtest": "disabled",
|
||||
"depthwrite": "disabled",
|
||||
"cullmode": "nocull",
|
||||
"combos": {},
|
||||
"textures": [{
|
||||
"suffix": "",
|
||||
"formats": [{"value":"r8", "label":"ui_editor_importer_texture_format_r8"}],
|
||||
"config": {
|
||||
"clampuvs" : true,
|
||||
"nonpoweroftwo": true,
|
||||
"nomip" : true,
|
||||
"halfmip": true,
|
||||
"format": "r8"
|
||||
}
|
||||
}]
|
||||
}],
|
||||
"imageshadersn": [{
|
||||
"value": "imagegeneric",
|
||||
"shader": "genericimage4",
|
||||
"label": "Image (normal map)",
|
||||
"blending": "translucent",
|
||||
"depthtest": "disabled",
|
||||
"depthwrite": "disabled",
|
||||
"cullmode": "nocull",
|
||||
"combos": {},
|
||||
"textures": [{
|
||||
"suffix": "",
|
||||
"formats": [{"value":"rg88n", "label":"ui_editor_importer_texture_format_rg88"}, {"value":"rgba8888n", "label":"ui_editor_importer_texture_format_rgba8888"}, {"value":"dxt5n", "label":"ui_editor_importer_texture_format_dxt5"}],
|
||||
"config": {
|
||||
"clampuvs" : true,
|
||||
"nonpoweroftwo": true,
|
||||
"halfmip": true,
|
||||
"format": "rg88n"
|
||||
}
|
||||
}]
|
||||
}],
|
||||
"animatedimageshaders": [{
|
||||
"value": "imagegenericspritesheet",
|
||||
"shader": "genericimage4",
|
||||
"label": "Image (animated)",
|
||||
"blending": "translucent",
|
||||
"depthtest": "disabled",
|
||||
"depthwrite": "disabled",
|
||||
"cullmode": "nocull",
|
||||
"combos": {
|
||||
"SPRITESHEET": 1
|
||||
},
|
||||
"textures": [{
|
||||
"suffix": "",
|
||||
"formats": [{"value":"rgba8888", "label":"ui_editor_importer_texture_format_rgba8888"}, {"value":"dxt5", "label":"ui_editor_importer_texture_format_dxt5"}, {"value":"dxt1", "label":"ui_editor_importer_texture_format_dxt1"}],
|
||||
"config": {
|
||||
"nonpoweroftwo": true,
|
||||
"nointerpolation" : true,
|
||||
"clampuvs" : true,
|
||||
"nomip" : true,
|
||||
"halfmip": true,
|
||||
"format": "rgba8888"
|
||||
}
|
||||
}]
|
||||
}],
|
||||
"animatedimageshaderssmooth": [{
|
||||
"value": "imagegenericspritesheet",
|
||||
"shader": "genericimage4",
|
||||
"label": "Image (animated)",
|
||||
"blending": "translucent",
|
||||
"depthtest": "disabled",
|
||||
"depthwrite": "disabled",
|
||||
"cullmode": "nocull",
|
||||
"combos": {
|
||||
"SPRITESHEET": 1
|
||||
},
|
||||
"textures": [{
|
||||
"suffix": "",
|
||||
"formats": [{"value":"rgba8888", "label":"ui_editor_importer_texture_format_rgba8888"}, {"value":"dxt5", "label":"ui_editor_importer_texture_format_dxt5"}],
|
||||
"config": {
|
||||
"nonpoweroftwo": true,
|
||||
"clampuvs" : true,
|
||||
"nomip" : true,
|
||||
"halfmip": true,
|
||||
"format": "rgba8888"
|
||||
}
|
||||
}]
|
||||
}],
|
||||
"animatedimageshadersn": [{
|
||||
"value": "imagegenericspritesheet",
|
||||
"shader": "genericimage4",
|
||||
"label": "Image (animated, normal map)",
|
||||
"blending": "translucent",
|
||||
"depthtest": "disabled",
|
||||
"depthwrite": "disabled",
|
||||
"cullmode": "nocull",
|
||||
"combos": {
|
||||
"SPRITESHEET": 1
|
||||
},
|
||||
"textures": [{
|
||||
"suffix": "",
|
||||
"formats": [{"value":"rgba8888n", "label":"ui_editor_importer_texture_format_rgba8888"}, {"value":"dxt5n", "label":"ui_editor_importer_texture_format_dxt5"}],
|
||||
"config": {
|
||||
"nonpoweroftwo": true,
|
||||
"nointerpolation" : true,
|
||||
"clampuvs" : true,
|
||||
"nomip" : true,
|
||||
"halfmip": true,
|
||||
"format": "rgba8888"
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
varying vec2 v_TexCoord[13];
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
void main() {
|
||||
vec3 albedo = texSample2D(g_Texture0, v_TexCoord[0]).rgb * 0.006299 +
|
||||
texSample2D(g_Texture0, v_TexCoord[1]).rgb * 0.017298 +
|
||||
texSample2D(g_Texture0, v_TexCoord[2]).rgb * 0.039533 +
|
||||
texSample2D(g_Texture0, v_TexCoord[3]).rgb * 0.075189 +
|
||||
texSample2D(g_Texture0, v_TexCoord[4]).rgb * 0.119007 +
|
||||
texSample2D(g_Texture0, v_TexCoord[5]).rgb * 0.156756 +
|
||||
texSample2D(g_Texture0, v_TexCoord[6]).rgb * 0.171834 +
|
||||
texSample2D(g_Texture0, v_TexCoord[7]).rgb * 0.156756 +
|
||||
texSample2D(g_Texture0, v_TexCoord[8]).rgb * 0.119007 +
|
||||
texSample2D(g_Texture0, v_TexCoord[9]).rgb * 0.075189 +
|
||||
texSample2D(g_Texture0, v_TexCoord[10]).rgb * 0.039533 +
|
||||
texSample2D(g_Texture0, v_TexCoord[11]).rgb * 0.017298 +
|
||||
texSample2D(g_Texture0, v_TexCoord[12]).rgb * 0.006299;
|
||||
|
||||
gl_FragColor = vec4(albedo, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
uniform vec2 g_TexelSize;
|
||||
|
||||
varying vec2 v_TexCoord[13];
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1);
|
||||
|
||||
float localTexel = g_TexelSize.x * 8.0;
|
||||
v_TexCoord[0] = vec2(a_TexCoord.x - localTexel * 6.0, a_TexCoord.y);
|
||||
v_TexCoord[1] = vec2(a_TexCoord.x - localTexel * 5.0, a_TexCoord.y);
|
||||
v_TexCoord[2] = vec2(a_TexCoord.x - localTexel * 4.0, a_TexCoord.y);
|
||||
v_TexCoord[3] = vec2(a_TexCoord.x - localTexel * 3.0, a_TexCoord.y);
|
||||
v_TexCoord[4] = vec2(a_TexCoord.x - localTexel * 2.0, a_TexCoord.y);
|
||||
v_TexCoord[5] = vec2(a_TexCoord.x - localTexel, a_TexCoord.y);
|
||||
v_TexCoord[6] = vec2(a_TexCoord.x, a_TexCoord.y);
|
||||
v_TexCoord[7] = vec2(a_TexCoord.x + localTexel, a_TexCoord.y);
|
||||
v_TexCoord[8] = vec2(a_TexCoord.x + localTexel * 2.0, a_TexCoord.y);
|
||||
v_TexCoord[9] = vec2(a_TexCoord.x + localTexel * 3.0, a_TexCoord.y);
|
||||
v_TexCoord[10] = vec2(a_TexCoord.x + localTexel * 4.0, a_TexCoord.y);
|
||||
v_TexCoord[11] = vec2(a_TexCoord.x + localTexel * 5.0, a_TexCoord.y);
|
||||
v_TexCoord[12] = vec2(a_TexCoord.x + localTexel * 6.0, a_TexCoord.y);
|
||||
}
|
||||
14
modules/wallpaper-engine/shaders/downsample_quarter.frag
Normal file
14
modules/wallpaper-engine/shaders/downsample_quarter.frag
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
varying vec2 v_TexCoord[4];
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
void main() {
|
||||
vec3 albedo = texSample2D(g_Texture0, v_TexCoord[0]).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord[1]).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord[2]).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord[3]).rgb;
|
||||
albedo *= 0.25;
|
||||
|
||||
gl_FragColor = vec4(albedo, 1.0);
|
||||
}
|
||||
15
modules/wallpaper-engine/shaders/downsample_quarter.vert
Normal file
15
modules/wallpaper-engine/shaders/downsample_quarter.vert
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
uniform vec2 g_TexelSize;
|
||||
|
||||
varying vec2 v_TexCoord[4];
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1.0);
|
||||
v_TexCoord[0] = a_TexCoord - g_TexelSize * 2;
|
||||
v_TexCoord[1] = a_TexCoord + g_TexelSize * 2;
|
||||
v_TexCoord[2] = a_TexCoord + vec2(-g_TexelSize.x, g_TexelSize.y) * 2;
|
||||
v_TexCoord[3] = a_TexCoord + vec2(g_TexelSize.x, -g_TexelSize.y) * 2;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
varying vec2 v_TexCoord[4];
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
uniform float g_BloomStrength; // {"material":"bloomstrength","default":2,"range":[0,4]}
|
||||
uniform float g_BloomThreshold; // {"material":"bloomthreshold","default":0.65,"range":[0,0.999]}
|
||||
uniform vec3 g_BloomTint; // {"material":"bloomtint","default":"1 1 1"}
|
||||
|
||||
void main() {
|
||||
vec3 albedo = texSample2D(g_Texture0, v_TexCoord[0]).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord[1]).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord[2]).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord[3]).rgb;
|
||||
albedo *= 0.25;
|
||||
|
||||
float scale = max(max(albedo.x, albedo.y), albedo.z);
|
||||
albedo *= saturate(scale - g_BloomThreshold);
|
||||
|
||||
// http://stackoverflow.com/a/34183839
|
||||
float grayscale = dot(vec3(0.2989, 0.5870, 0.1140), albedo);
|
||||
float sat = 1.0;
|
||||
albedo = -grayscale * sat + albedo * (1.0 + sat);
|
||||
|
||||
gl_FragColor = vec4(max(CAST3(0), albedo * g_BloomStrength * g_BloomTint), 1.0);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
uniform vec2 g_TexelSize;
|
||||
|
||||
varying vec2 v_TexCoord[4];
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1.0);
|
||||
v_TexCoord[0] = a_TexCoord - g_TexelSize;
|
||||
v_TexCoord[1] = a_TexCoord + g_TexelSize;
|
||||
v_TexCoord[2] = a_TexCoord + vec2(-g_TexelSize.x, g_TexelSize.y);
|
||||
v_TexCoord[3] = a_TexCoord + vec2(g_TexelSize.x, -g_TexelSize.y);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
varying vec2 v_TexCoord[4];
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
void main() {
|
||||
vec3 albedo = texSample2D(g_Texture0, v_TexCoord[0]).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord[1]).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord[2]).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord[3]).rgb;
|
||||
albedo *= 0.25;
|
||||
|
||||
gl_FragColor = vec4(pow(albedo, 1/2.2), 1.0);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
uniform vec2 g_TexelSize;
|
||||
|
||||
varying vec2 v_TexCoord[4];
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1.0);
|
||||
v_TexCoord[0] = a_TexCoord - g_TexelSize * 2;
|
||||
v_TexCoord[1] = a_TexCoord + g_TexelSize * 2;
|
||||
v_TexCoord[2] = a_TexCoord + vec2(-g_TexelSize.x, g_TexelSize.y) * 2;
|
||||
v_TexCoord[3] = a_TexCoord + vec2(g_TexelSize.x, -g_TexelSize.y) * 2;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
uniform mediump float g_Alpha;
|
||||
|
||||
varying vec4 v_ScreenPos;
|
||||
varying vec4 v_ScreenNorm;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = vec4(0, 0, 0, g_Alpha);
|
||||
|
||||
vec3 screenPos = v_ScreenPos.xyz / v_ScreenPos.w;
|
||||
vec3 screenNorm = normalize(v_ScreenNorm.xyz);
|
||||
|
||||
float light = dot(screenNorm, normalize(vec3(0.707, 0.707, 0.707)));
|
||||
|
||||
float lightPowd = light;
|
||||
lightPowd = pow(abs(lightPowd), 2.0) * sign(lightPowd);
|
||||
|
||||
light = light * 0.5 + 0.5;
|
||||
lightPowd = lightPowd * 0.5 + 0.5;
|
||||
|
||||
vec3 shadow = vec3(1, 1, 1);
|
||||
vec3 mid = vec3(1, 0.2, 0);
|
||||
vec3 high = vec3(0, 0, 1.5);
|
||||
|
||||
vec3 res = mix(mix(shadow, mid, smoothstep(0, 0.5, lightPowd)), high, smoothstep(0.5, 1.0, lightPowd));
|
||||
|
||||
//gl_FragColor.rgb = screenNorm.rgb * 0.5 + 0.5;
|
||||
//gl_FragColor.rgb = pow(gl_FragColor.rgb, 2.0);
|
||||
//gl_FragColor.b = -screenNorm.b;
|
||||
//gl_FragColor.a *= 0.9;
|
||||
|
||||
//light = light * 0.5 + 0.5;
|
||||
res = vec3(1, 1, 1);
|
||||
gl_FragColor.rgb = res * pow(light, 0.7);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
uniform mat4 g_ModelViewMatrix;
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec4 a_Color;
|
||||
|
||||
varying vec4 v_ScreenPos;
|
||||
varying vec4 v_ScreenNorm;
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
|
||||
vec3 normal = normalize(a_Color.rgb * 2.0 - 1.0);
|
||||
v_ScreenPos = gl_Position;
|
||||
v_ScreenNorm = mul(vec4(normal, 0.0), g_ModelViewProjectionMatrix);
|
||||
}
|
||||
96
modules/wallpaper-engine/shaders/editorpaintbrush.frag
Normal file
96
modules/wallpaper-engine/shaders/editorpaintbrush.frag
Normal file
@@ -0,0 +1,96 @@
|
||||
|
||||
#include "common_blur.h"
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec3 v_Position;
|
||||
|
||||
uniform vec4 g_BrushPosition; // {"material":"brushposition","default":"0 0"}
|
||||
uniform vec4 g_BrushSettings; // {"material":"brushsettings","default":"0 0 0 0"}
|
||||
uniform vec4 g_BrushColor; // {"material":"brushcolor","default":"0 0 0"}
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
uniform vec4 g_Texture0Resolution;
|
||||
|
||||
//uniform vec2 g_TexelSize;
|
||||
//uniform vec2 g_TexelSizeHalf;
|
||||
|
||||
#define BRUSHSIZE g_BrushSettings.x
|
||||
|
||||
void main() {
|
||||
vec4 albedo = CAST4(0);
|
||||
albedo.rgb = g_BrushColor;
|
||||
|
||||
vec2 adjusted = (v_Position.xy - g_BrushPosition.xy) * g_BrushPosition.zw + g_BrushPosition.xy;
|
||||
|
||||
vec2 texelSize = 1;
|
||||
vec4 multiSample = vec4(
|
||||
length(vec2(adjusted.x - texelSize.x, adjusted.y - texelSize.y) - g_BrushPosition.xy),
|
||||
length(vec2(adjusted.x + texelSize.x, adjusted.y - texelSize.y) - g_BrushPosition.xy),
|
||||
length(vec2(adjusted.x + texelSize.x, adjusted.y + texelSize.y) - g_BrushPosition.xy),
|
||||
length(vec2(adjusted.x - texelSize.x, adjusted.y + texelSize.y) - g_BrushPosition.xy)
|
||||
);
|
||||
|
||||
float feather = max(0.5f, BRUSHSIZE * 0.5f * (1.0f - g_BrushSettings.y));
|
||||
vec4 blend4 = smoothstep(multiSample - feather, multiSample + feather, CAST4(BRUSHSIZE * 0.5f));
|
||||
float blend = dot(blend4, CAST4(0.25));
|
||||
|
||||
float opacity = mix(0.0f, g_BrushSettings.z, blend);
|
||||
albedo.a = opacity;
|
||||
|
||||
#ifdef PINCH
|
||||
float pinchSign = albedo.g * 2.0 - 1.0;
|
||||
vec2 pinchDelta = ((adjusted - g_BrushPosition.xy) * pinchSign) / BRUSHSIZE;
|
||||
float pinchDistance = length(pinchDelta);
|
||||
pinchDelta /= pinchDistance;
|
||||
pinchDistance = saturate(pinchDistance);
|
||||
|
||||
vec2 pinchColor = pinchDelta * pinchDistance * 0.5 + 0.5;
|
||||
albedo.b = 0.0;
|
||||
albedo.rg = mix(vec2(0.5, 0.5), pinchColor, albedo.r);
|
||||
#endif
|
||||
|
||||
#if SPIN
|
||||
vec2 positionDelta = ((adjusted - g_BrushPosition.xy)) / BRUSHSIZE;
|
||||
positionDelta.y = -positionDelta.y;
|
||||
float temp = positionDelta.x;
|
||||
positionDelta.x = positionDelta.y;
|
||||
positionDelta.y = temp;
|
||||
vec2 spinColor = positionDelta * 0.5 + 0.5;
|
||||
|
||||
albedo.b = 0.0;
|
||||
albedo.rg = mix(vec2(0.5, 0.5), spinColor, albedo.r);
|
||||
#endif
|
||||
|
||||
gl_FragColor = albedo;
|
||||
|
||||
#if BLUR
|
||||
// sample weights 3
|
||||
// 0.14975490496277529 +
|
||||
// 0.23722688396633606 +
|
||||
// 0.23722688396633606 +
|
||||
// 0.37579132710455257
|
||||
// 0.72099
|
||||
// (0.27901 / 0.72099)
|
||||
// (0.44198 / 0.72099)
|
||||
|
||||
// ggrid distance
|
||||
// sum: 0.318663
|
||||
|
||||
|
||||
vec2 tmpTexel = g_BrushColor.r * 10.0 / g_Texture0Resolution.xy;
|
||||
|
||||
gl_FragColor.rgb = texSample2D(g_Texture0, v_TexCoord - tmpTexel * vec2((0.123317 / 0.318663), (0.123317 / 0.318663))).rgb * 0.37579132710455257 +
|
||||
texSample2D(g_Texture0, v_TexCoord + vec2(tmpTexel.x, -tmpTexel.y) * vec2((0.195346 / 0.318663), (0.123317 / 0.318663))).rgb * 0.23722688396633606 +
|
||||
texSample2D(g_Texture0, v_TexCoord + vec2(-tmpTexel.x, tmpTexel.y) * vec2((0.123317 / 0.318663), (0.195346 / 0.318663))).rgb * 0.23722688396633606 +
|
||||
texSample2D(g_Texture0, v_TexCoord + tmpTexel * vec2((0.195346 / 0.318663), (0.195346 / 0.318663))).rgb * 0.14975490496277529;
|
||||
|
||||
//gl_FragColor = texSample2D(g_Texture0, v_TexCoord - tmpTexel) +
|
||||
// texSample2D(g_Texture0, v_TexCoord + vec2(tmpTexel.x, -tmpTexel.y)) +
|
||||
// texSample2D(g_Texture0, v_TexCoord + vec2(-tmpTexel.x, tmpTexel.y)) +
|
||||
// texSample2D(g_Texture0, v_TexCoord + tmpTexel);
|
||||
//gl_FragColor *= 0.25;
|
||||
|
||||
//gl_FragColor.a = 1;
|
||||
#endif
|
||||
}
|
||||
15
modules/wallpaper-engine/shaders/editorpaintbrush.vert
Normal file
15
modules/wallpaper-engine/shaders/editorpaintbrush.vert
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec3 v_Position;
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
|
||||
v_Position = a_Position;
|
||||
v_TexCoord = a_TexCoord;
|
||||
}
|
||||
13
modules/wallpaper-engine/shaders/editorsprite.frag
Normal file
13
modules/wallpaper-engine/shaders/editorsprite.frag
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
uniform vec3 g_Color;
|
||||
uniform float g_Alpha;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
vec4 color = texSample2D(g_Texture0, v_TexCoord);
|
||||
color.rgb *= g_Color;
|
||||
color.a *= g_Alpha;
|
||||
gl_FragColor = color;
|
||||
}
|
||||
21
modules/wallpaper-engine/shaders/editorsprite.vert
Normal file
21
modules/wallpaper-engine/shaders/editorsprite.vert
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
//uniform mat4 g_ModelMatrix;
|
||||
//uniform mat4 g_ViewProjectionMatrix;
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
|
||||
uniform vec3 g_ViewUp;
|
||||
uniform vec3 g_ViewRight;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
vec3 position = a_Position +
|
||||
(g_ViewRight * -(a_TexCoord.x-0.5) +
|
||||
g_ViewUp * (a_TexCoord.y-0.5)) * -0.5;
|
||||
|
||||
gl_Position = mul(vec4(position, 1.0), g_ModelViewProjectionMatrix);
|
||||
v_TexCoord = a_TexCoord;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec3 v_ScreenCoord;
|
||||
|
||||
uniform sampler2D g_Texture0; // {"hidden":true}
|
||||
uniform sampler2D g_Texture1; // {"hidden":true,"default":"_rt_FullFrameBuffer"}
|
||||
|
||||
void main() {
|
||||
vec4 result = texSample2D(g_Texture0, v_TexCoord);
|
||||
|
||||
vec2 screenCoord = v_ScreenCoord.xy / v_ScreenCoord.z * CAST2(0.5) + 0.5;
|
||||
vec4 bg = texSample2D(g_Texture1, screenCoord.xy);
|
||||
|
||||
gl_FragColor.rgb = mix(bg.rgb, result.rgb, result.a);
|
||||
gl_FragColor.a = 1.0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
uniform mat4 g_EffectModelViewProjectionMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec3 v_ScreenCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
|
||||
v_TexCoord = a_TexCoord;
|
||||
v_ScreenCoord = mul(vec4((a_Position), 1.0), g_EffectModelViewProjectionMatrix).xyw;
|
||||
#if HLSL
|
||||
v_ScreenCoord.y = -v_ScreenCoord.y;
|
||||
#endif
|
||||
}
|
||||
8
modules/wallpaper-engine/shaders/error.frag
Normal file
8
modules/wallpaper-engine/shaders/error.frag
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texSample2D(g_Texture0, v_TexCoord);
|
||||
}
|
||||
12
modules/wallpaper-engine/shaders/error.vert
Normal file
12
modules/wallpaper-engine/shaders/error.vert
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
v_TexCoord = a_TexCoord;
|
||||
}
|
||||
10
modules/wallpaper-engine/shaders/fade.frag
Normal file
10
modules/wallpaper-engine/shaders/fade.frag
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
varying mediump vec2 v_TexCoord;
|
||||
|
||||
uniform mediump float g_Alpha;
|
||||
|
||||
uniform lowp vec3 color; // {"material":"tint","default":"0.315, 0.135, 0.1125"}
|
||||
|
||||
void main() {
|
||||
gl_FragColor = vec4(color * 0.7, g_Alpha);
|
||||
}
|
||||
7
modules/wallpaper-engine/shaders/fade.vert
Normal file
7
modules/wallpaper-engine/shaders/fade.vert
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute mediump vec2 a_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_Position, 1.0);
|
||||
}
|
||||
67
modules/wallpaper-engine/shaders/flag.frag
Normal file
67
modules/wallpaper-engine/shaders/flag.frag
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
#include "common_fragment.h"
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
uniform sampler2D g_Texture1;
|
||||
uniform sampler2D g_Texture2;
|
||||
|
||||
#if TINT
|
||||
uniform vec3 g_Color1; // {"material":"color1","default":"0 0 0"}
|
||||
uniform vec3 g_Color2; // {"material":"color2","default":"0 0 0"}
|
||||
uniform vec3 g_Color3; // {"material":"color3","default":"1 1 1"}
|
||||
#endif
|
||||
|
||||
uniform float g_WaveStrength; // {"material":"Strength","default":0.5}
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec4 v_NormalCoord;
|
||||
|
||||
void main() {
|
||||
vec2 normalCoords1 = v_NormalCoord.xy;
|
||||
vec2 normalCoords2 = v_NormalCoord.zw;
|
||||
|
||||
normalCoords1.x -= ((0.5 - v_TexCoord.x) * (1 - v_TexCoord.y)) * 3;
|
||||
normalCoords1.x += 2 * pow(v_TexCoord.y - 0.1, 3) * pow(v_TexCoord.x, 2);
|
||||
normalCoords2.x -= ((1.0 - v_TexCoord.x) * (1 - v_TexCoord.y)) * 2;
|
||||
|
||||
vec3 normal = DecompressNormal(texSample2D(g_Texture1, normalCoords1));
|
||||
normal *= DecompressNormal(texSample2D(g_Texture1, normalCoords2));
|
||||
//normal.xy += DecompressNormal(texSample2D(g_Texture1, normalCoords2)).xy;
|
||||
|
||||
normal = mix(vec3(0, 0, 1), normal, g_WaveStrength);
|
||||
normal = normalize(normal);
|
||||
|
||||
vec2 baseCoords = v_TexCoord.xy + normal.xy * 0.02;
|
||||
|
||||
//vec2 baseCoords2 = v_TexCoord.xy + normal.xy * 0.1;
|
||||
//clip(baseCoords2.y - 0.1);
|
||||
//clip(0.9 - baseCoords2.y);
|
||||
//clip(baseCoords2.x - 0.18);
|
||||
//clip(0.82 - baseCoords2.x);
|
||||
|
||||
vec3 albedo = texSample2D(g_Texture0, baseCoords.xy).rgb;
|
||||
float cloth = texSample2D(g_Texture2, baseCoords.xy * 4).r;
|
||||
|
||||
#if TINT
|
||||
vec3 color = mix(g_Color1, g_Color2, albedo.r);
|
||||
color = mix(color, g_Color3, albedo.g);
|
||||
color *= albedo.b * cloth;
|
||||
color += cloth * 0.1;
|
||||
#else
|
||||
vec3 color = albedo;
|
||||
#endif
|
||||
|
||||
float light = 0.2 + dot(vec3(0.707, 0.707, 0), normal) * 0.5 + 0.5;
|
||||
light += pow(light, 5) * 0.5;
|
||||
color *= light + light * saturate(cloth * 2 - 1);
|
||||
|
||||
// Vignette
|
||||
//float vignette = length(v_TexCoord.xy - 0.5);
|
||||
//color *= smoothstep(0.7, 0.2, vignette);
|
||||
|
||||
// gl_FragColor = albedo;
|
||||
gl_FragColor.rgb = color;
|
||||
gl_FragColor.a = 1;
|
||||
|
||||
//gl_FragColor.rgb = (normal * 0.5 + 0.5);
|
||||
}
|
||||
24
modules/wallpaper-engine/shaders/flag.vert
Normal file
24
modules/wallpaper-engine/shaders/flag.vert
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
#include "common_vertex.h"
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
uniform float g_Time;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec4 v_NormalCoord;
|
||||
|
||||
uniform float g_WaveSpeed; // {"material":"Speed","default":0.4}
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
|
||||
v_NormalCoord.xy = a_TexCoord * vec2(1, 0.3) * 0.7;
|
||||
v_NormalCoord.x -= g_Time * g_WaveSpeed;
|
||||
|
||||
v_NormalCoord.zw = a_TexCoord * vec2(1, 0.7) * 0.3;
|
||||
v_NormalCoord.z -= g_Time * g_WaveSpeed * 0.5;
|
||||
}
|
||||
13
modules/wallpaper-engine/shaders/flat.frag
Normal file
13
modules/wallpaper-engine/shaders/flat.frag
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
uniform mediump float g_Alpha;
|
||||
uniform mediump vec3 g_Color;
|
||||
|
||||
varying vec4 v_Color;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = vec4(g_Color, g_Alpha);
|
||||
|
||||
#ifdef VERTEXCOLOR
|
||||
gl_FragColor *= v_Color.rgba;
|
||||
#endif
|
||||
}
|
||||
16
modules/wallpaper-engine/shaders/flat.vert
Normal file
16
modules/wallpaper-engine/shaders/flat.vert
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec4 a_Color;
|
||||
|
||||
#ifdef VERTEXCOLOR
|
||||
varying vec4 v_Color;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
#ifdef VERTEXCOLOR
|
||||
v_Color = a_Color.rgba;
|
||||
#endif
|
||||
}
|
||||
10
modules/wallpaper-engine/shaders/flatpoint.frag
Normal file
10
modules/wallpaper-engine/shaders/flatpoint.frag
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
uniform mediump float g_Alpha;
|
||||
uniform mediump vec3 g_Color;
|
||||
|
||||
varying vec4 v_Color;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = vec4(g_Color, g_Alpha);
|
||||
gl_FragColor *= v_Color;
|
||||
}
|
||||
36
modules/wallpaper-engine/shaders/flatpoint.geom
Normal file
36
modules/wallpaper-engine/shaders/flatpoint.geom
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
uniform vec3 g_Screen;
|
||||
|
||||
in vec4 gl_Position;
|
||||
in vec4 v_Color;
|
||||
|
||||
out vec4 v_Color;
|
||||
out vec4 gl_Position;
|
||||
|
||||
PS_INPUT CreateParticleVertex(vec2 sprite, in VS_OUTPUT IN, vec3 right, vec3 up)
|
||||
{
|
||||
PS_INPUT v;
|
||||
|
||||
v.gl_Position = mul(vec4(IN.gl_Position.xyz, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.gl_Position.xyz /= v.gl_Position.w;
|
||||
v.gl_Position.w = 1;
|
||||
v.gl_Position.xyz += (sprite.x * right + sprite.y * up) * IN.gl_Position.w * 0.002;
|
||||
|
||||
v.v_Color = IN.v_Color;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
[maxvertexcount(4)]
|
||||
void main() {
|
||||
|
||||
float resFactor = min(1.0, 1080.0 / g_Screen.y);
|
||||
vec3 up = vec3(0, resFactor, 0);
|
||||
vec3 right = vec3(resFactor / g_Screen.z, 0, 0);
|
||||
|
||||
OUT.Append(CreateParticleVertex(vec2(-1, 1), IN[0], right, up));
|
||||
OUT.Append(CreateParticleVertex(vec2(-1, -1), IN[0], right, up));
|
||||
OUT.Append(CreateParticleVertex(vec2(1, 1), IN[0], right, up));
|
||||
OUT.Append(CreateParticleVertex(vec2(1, -1), IN[0], right, up));
|
||||
}
|
||||
10
modules/wallpaper-engine/shaders/flatpoint.vert
Normal file
10
modules/wallpaper-engine/shaders/flatpoint.vert
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
attribute vec4 a_PositionVec4;
|
||||
attribute vec4 a_Color;
|
||||
|
||||
varying vec4 v_Color;
|
||||
|
||||
void main() {
|
||||
gl_Position = a_PositionVec4;
|
||||
v_Color = a_Color;
|
||||
}
|
||||
162
modules/wallpaper-engine/shaders/foliage4.frag
Normal file
162
modules/wallpaper-engine/shaders/foliage4.frag
Normal file
@@ -0,0 +1,162 @@
|
||||
|
||||
// [PASS] shadow shadowcasterfoliage4
|
||||
// [COMBO] {"material":"ui_editor_properties_lighting","combo":"LIGHTING","default":1}
|
||||
// [COMBO] {"material":"ui_editor_properties_fog","combo":"FOG","default":1}
|
||||
// [COMBO] {"material":"ui_editor_properties_reflection","combo":"REFLECTION","default":0}
|
||||
// [COMBO] {"material":"ui_editor_properties_rim_lighting","combo":"RIMLIGHTING","default":0,"require":{"LIGHTING":1}}
|
||||
// [COMBO] {"material":"ui_editor_properties_toon_shading","combo":"SHADINGGRADIENT","default":0,"require":{"LIGHTING":1}}
|
||||
// [COMBO] {"material":"ui_editor_properties_double_sided_lighting","combo":"DOUBLESIDEDLIGHTING","default":0}
|
||||
// [COMBO] {"material":"ui_editor_properties_leaves_uv_direction","combo":"LEAVESUVMODE","default":0,"options":{"ui_editor_properties_none":0,"ui_editor_properties_up":1,"ui_editor_properties_down":2,"ui_editor_properties_right":3,"ui_editor_properties_left":4}}
|
||||
// [COMBO] {"material":"ui_editor_properties_animation_debug","combo":"FOLIAGEDEBUG","default":0,"options":{"ui_editor_properties_none":0,"ui_editor_properties_debug_size":1,"ui_editor_properties_debug_height":2,"ui_editor_properties_debug_radius":3,"ui_editor_properties_debug_uvs":4,"ui_editor_properties_debug_scale":5}}
|
||||
|
||||
#define RIM_LIGHTING_AMOUNT g_RimAmount
|
||||
#define RIM_LIGHTING_EXPONENT g_RimExponent
|
||||
|
||||
#if SHADINGGRADIENT
|
||||
#define GRADIENT_SAMPLER g_Texture4
|
||||
uniform sampler2D g_Texture4; // {"label":"ui_editor_properties_shading_gradient","default":"gradient/gradient_toon_smooth","formatcombo":true,"nonremovable":true,"require":{"SHADINGGRADIENT":1}}
|
||||
#endif
|
||||
uniform float g_RimAmount; // {"material":"rimamount","label":"ui_editor_properties_rim_lighting_amount","default":2.0,"range":[0,5],"group":"ui_editor_properties_rim_lighting"}
|
||||
uniform float g_RimExponent; // {"material":"rimexponent","label":"ui_editor_properties_rim_lighting_exponent","default":4.0,"range":[0.01,10],"group":"ui_editor_properties_rim_lighting"}
|
||||
|
||||
#if LIGHTS_SHADOW_MAPPING
|
||||
#define SHADOW_ATLAS_SAMPLER g_Texture6
|
||||
#define SHADOW_ATLAS_TEXEL g_Texture6Texel
|
||||
uniform sampler2DComparison g_Texture6; // {"hidden":true,"default":"_rt_shadowAtlas"}
|
||||
uniform vec4 g_Texture6Texel;
|
||||
#endif
|
||||
|
||||
#if LIGHTS_COOKIE
|
||||
#define COOKIE_SAMPLER g_Texture7
|
||||
uniform sampler2D g_Texture7; // {"hidden":true,"default":"_alias_lightCookie"}
|
||||
#endif
|
||||
|
||||
#include "base/model_fragment_v1.h"
|
||||
#include "common_pbr_2.h"
|
||||
#include "common_fog.h"
|
||||
|
||||
uniform float g_Brightness; // {"material":"brightness","label":"ui_editor_properties_hdr_brightness","default":1,"range":[0,10]}
|
||||
|
||||
uniform vec3 g_TintColor; // {"material":"color","label":"ui_editor_properties_tint_color","type": "color", "default":"1 1 1"}
|
||||
uniform float g_TintAlpha; // {"material":"alpha","label":"ui_editor_properties_opacity","default":1,"range":[0,1]}
|
||||
|
||||
uniform sampler2D g_Texture0; // {"material":"albedo","label":"ui_editor_properties_albedo","default":"util/white"}
|
||||
uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal_map","format":"normalmap","formatcombo":true,"combo":"NORMALMAP"}
|
||||
uniform sampler2D g_Texture2; // {"combo":"PBRMASKS","components":[{"label":"ui_editor_properties_metallic_map","combo":"METALLIC_MAP"},{"label":"ui_editor_properties_roughness_map","combo":"ROUGHNESS_MAP"},{"label":"ui_editor_properties_reflection_map","combo":"REFLECTION_MAP"},{"label":"ui_editor_properties_emissive_map","combo":"EMISSIVE_MAP"}]}
|
||||
|
||||
uniform float g_Roughness; // {"material":"roughness","label":"ui_editor_properties_roughness","default":0.7,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Metallic; // {"material":"metallic","label":"ui_editor_properties_metallic","default":0,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#ifdef NORMALMAP
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
#else
|
||||
varying vec3 v_WorldNormal;
|
||||
#endif
|
||||
varying vec3 v_WorldPos;
|
||||
#endif
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
#if REFLECTION
|
||||
uniform sampler2D g_Texture3; // {"hidden":true,"default":"_rt_MipMappedFrameBuffer"}
|
||||
uniform float g_Reflectivity; // {"material":"reflectivity","label":"ui_editor_properties_reflectivity","default":1,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Texture3MipMapInfo;
|
||||
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
uniform vec3 g_EmissiveColor; // {"material":"emissivecolor", "label":"ui_editor_properties_emissive_color", "type": "color", "default":"1 1 1","group":"ui_editor_properties_material"}
|
||||
uniform float g_EmissiveBrightness; // {"material":"emissivebrightness", "label":"ui_editor_properties_emissive_brightness", "default":1.0,"range":[0,10],"group":"ui_editor_properties_material"}
|
||||
|
||||
#require LightingV1
|
||||
|
||||
void main() {
|
||||
vec4 albedo = texSample2D(g_Texture0, v_TexCoord.xy);
|
||||
|
||||
albedo.rgb *= g_TintColor;
|
||||
albedo.a *= g_TintAlpha;
|
||||
|
||||
float metallic = g_Metallic;
|
||||
float roughness = g_Roughness;
|
||||
|
||||
#if PBRMASKS
|
||||
vec4 componentMaps = texSample2D(g_Texture2, v_TexCoord.xy);
|
||||
#endif
|
||||
|
||||
#if METALLIC_MAP
|
||||
metallic = componentMaps.x;
|
||||
#endif
|
||||
|
||||
#if ROUGHNESS_MAP
|
||||
roughness = componentMaps.y;
|
||||
#endif
|
||||
|
||||
vec3 f0 = CAST3(0.04);
|
||||
f0 = mix(f0, albedo.rgb, metallic);
|
||||
|
||||
float viewDist = length(v_ViewDir.xyz);
|
||||
vec3 normalizedViewVector = v_ViewDir.xyz / viewDist;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if NORMALMAP
|
||||
vec3 normal = DecompressNormal(texSample2D(g_Texture1, v_TexCoord.xy));
|
||||
mat3 tangentSpace = mat3(v_Tangent, v_Bitangent, v_Normal);
|
||||
normal = mul(normal, tangentSpace);
|
||||
#else
|
||||
vec3 normal = normalize(v_WorldNormal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec3 light = CAST3(0.0);
|
||||
|
||||
#if LIGHTING
|
||||
light = PerformLighting_V1(v_WorldPos, albedo.rgb, normal, normalizedViewVector, CAST3(1.0), f0, roughness, metallic);
|
||||
vec3 ambient = v_LightAmbientColor * albedo.rgb;
|
||||
#else
|
||||
vec3 ambient = albedo.rgb;
|
||||
#endif
|
||||
|
||||
#if EMISSIVE_MAP
|
||||
light = max(light, g_EmissiveColor * albedo.rgb * (componentMaps.a * g_EmissiveBrightness));
|
||||
#endif
|
||||
|
||||
albedo.rgb = CombineLighting(light, ambient);
|
||||
|
||||
#if REFLECTION
|
||||
float reflectivity = g_Reflectivity;
|
||||
#if REFLECTION_MAP
|
||||
reflectivity *= componentMaps.z;
|
||||
#endif
|
||||
albedo.rgb += ApplyReflection(MAKE_SAMPLER2D_ARGUMENT(g_Texture3), g_Texture3MipMapInfo, reflectivity, roughness, metallic, v_ScreenPos.xyz, normal, normalizedViewVector);
|
||||
#endif
|
||||
|
||||
#if HDR
|
||||
albedo.rgb *= g_Brightness;
|
||||
|
||||
#if (LIGHTING || REFLECTION) && EMISSIVE_MAP
|
||||
float emissiveOverbright = max(0.0, componentMaps.a * (g_EmissiveBrightness - 1.0));
|
||||
albedo.rgb += g_EmissiveColor * albedo.rgb * emissiveOverbright;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if FOG_HEIGHT || FOG_DIST
|
||||
vec2 fogPixelState = CalculateFogPixelState(viewDist, v_ViewDir.w);
|
||||
albedo.rgb = ApplyFog(albedo.rgb, fogPixelState);
|
||||
#if ADDITIVE
|
||||
albedo.a = ApplyFogAlpha(albedo.a, fogPixelState);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if FOLIAGEDEBUG
|
||||
albedo.rgb = v_LightAmbientColor.rgb;
|
||||
#endif
|
||||
|
||||
gl_FragColor = albedo;
|
||||
|
||||
ApplyAlphaToCoverage(gl_FragColor.a);
|
||||
}
|
||||
130
modules/wallpaper-engine/shaders/foliage4.vert
Normal file
130
modules/wallpaper-engine/shaders/foliage4.vert
Normal file
@@ -0,0 +1,130 @@
|
||||
|
||||
#include "base/model_vertex_v1.h"
|
||||
#include "common_foliage.h"
|
||||
|
||||
uniform vec3 g_EyePosition;
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec3 a_Normal;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if NORMALMAP
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
#else
|
||||
varying vec3 v_WorldNormal;
|
||||
#endif
|
||||
varying vec3 v_WorldPos;
|
||||
#endif
|
||||
|
||||
#if REFLECTION
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
#if MORPHING
|
||||
uniform sampler2D g_Texture5; // {"material":"morph","hidden":true}
|
||||
uniform vec4 g_Texture5Texel;
|
||||
#endif
|
||||
|
||||
uniform float g_Time;
|
||||
uniform float g_SpeedLeaves; // {"material":"foliagespeedleaves","label":"ui_editor_properties_speed_leaves","default":5,"range":[0.01, 10],"group":"ui_editor_properties_foliage"}
|
||||
uniform float g_SpeedBase; // {"material":"foliagespeedbase","label":"ui_editor_properties_speed_base","default":1,"range":[0.01, 10],"group":"ui_editor_properties_foliage"}
|
||||
uniform float g_StrengthLeaves; // {"material":"strengthleaves","label":"ui_editor_properties_strength_leaves","default":0.015,"range":[0, 0.1],"group":"ui_editor_properties_foliage"}
|
||||
uniform float g_StrengthBase; // {"material":"strengthbase","label":"ui_editor_properties_strength_base","default":0.04,"range":[0, 0.2],"group":"ui_editor_properties_foliage"}
|
||||
uniform float g_Phase; // {"material":"foliagephase","label":"ui_editor_properties_phase","default":0,"range":[0, 6.28],"group":"ui_editor_properties_foliage"}
|
||||
uniform float g_FoliageScale; // {"material":"foliagescale","label":"ui_editor_properties_scale","default":3,"range":[0, 10],"group":"ui_editor_properties_foliage"}
|
||||
uniform float g_Direction; // {"material":"scrolldirection","label":"ui_editor_properties_direction","default":0,"range":[1.571,6.28],"direction":true,"group":"ui_editor_properties_foliage"}
|
||||
uniform float g_CutOff; // {"material":"foliagecutoff","label":"ui_editor_properties_crunch","default":0.2,"range":[0.0, 0.39],"group":"ui_editor_properties_foliage"}
|
||||
uniform float g_TreeHeight; // {"material":"foliageheight","label":"ui_editor_properties_tree_height","default":5,"range":[0.0, 100],"group":"ui_editor_properties_foliage"}
|
||||
uniform float g_TreeRadius; // {"material":"foliageradius","label":"ui_editor_properties_tree_radius","default":0.5,"range":[0.0, 10],"group":"ui_editor_properties_foliage"}
|
||||
uniform vec2 g_FoliageUVBounds; // {"material":"foliageuvbounds","label":"ui_editor_properties_leaves_uv_mapping","default":"0 1","nobindings":true,"conversion":"startdelta","group":"ui_editor_properties_foliage"}
|
||||
|
||||
void main() {
|
||||
vec3 localPos = a_Position;
|
||||
vec3 localNormal = a_Normal;
|
||||
|
||||
#if MORPHING
|
||||
ApplyMorphPositionNormal(CASTU(gl_VertexID), MAKE_SAMPLER2D_ARGUMENT(g_Texture5), g_Texture5Texel, g_MorphOffsets, g_MorphWeights, localPos, localNormal);
|
||||
#endif
|
||||
|
||||
vec4 worldPos;
|
||||
vec3 worldNormal;
|
||||
#if SKINNING
|
||||
ApplySkinningPositionNormal(localPos, localNormal, a_BlendIndices, a_BlendWeights, worldPos, worldNormal);
|
||||
#else
|
||||
ApplyPositionNormal(localPos, localNormal, worldPos, worldNormal);
|
||||
#endif
|
||||
|
||||
// <Foliage additions
|
||||
#if LEAVESUVMODE
|
||||
vec2 leafUVs = a_TexCoord;
|
||||
#else
|
||||
vec2 leafUVs = CAST2(1);
|
||||
#endif
|
||||
|
||||
worldPos.xyz += CalcFoliageAnimation(worldPos.xyz, localPos, leafUVs, g_Direction, g_Time,
|
||||
g_SpeedLeaves, g_SpeedBase, g_StrengthLeaves, g_StrengthBase,
|
||||
g_Phase, g_FoliageScale, g_CutOff, g_TreeHeight, g_TreeRadius, g_FoliageUVBounds);
|
||||
// Foliage additions>
|
||||
|
||||
gl_Position = mul(worldPos, g_ViewProjectionMatrix);
|
||||
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
v_ViewDir.xyz = g_EyePosition - worldPos.xyz;
|
||||
v_ViewDir.w = worldPos.y;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
v_WorldPos = worldPos.xyz;
|
||||
#if NORMALMAP
|
||||
mat3 tangentSpace;
|
||||
#if SKINNING
|
||||
ApplySkinningTangentSpace(worldNormal, a_Tangent4, a_BlendIndices, a_BlendWeights, tangentSpace);
|
||||
#else
|
||||
ApplyTangentSpace(worldNormal, a_Tangent4, tangentSpace);
|
||||
#endif
|
||||
|
||||
v_Tangent = tangentSpace[0];
|
||||
v_Bitangent = tangentSpace[1];
|
||||
v_Normal = tangentSpace[2];
|
||||
#else
|
||||
v_WorldNormal = worldNormal;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if REFLECTION
|
||||
ClipSpaceToScreenSpace(gl_Position, v_ScreenPos);
|
||||
#endif
|
||||
|
||||
v_LightAmbientColor = ApplyAmbientLighting(worldNormal);
|
||||
|
||||
#if FOLIAGEDEBUG
|
||||
float heightBlend = smoothstep(0.0, g_TreeHeight, localPos.y);
|
||||
|
||||
float leafDistance = dot(localPos.xz, localPos.xz);
|
||||
vec2 blendParamsA = vec2(g_TreeRadius * g_TreeRadius, g_TreeRadius);
|
||||
vec2 blendParamsB = vec2(g_TreeRadius, g_TreeRadius * g_TreeRadius);
|
||||
vec2 blendParams = mix(blendParamsA, blendParamsB, step(1.0, g_TreeRadius));
|
||||
float radiusBlend = smoothstep(blendParams.x, blendParams.y, leafDistance);
|
||||
#endif
|
||||
#if FOLIAGEDEBUG == 1
|
||||
v_LightAmbientColor.rgb = vec3(radiusBlend, heightBlend, 0);
|
||||
#elif FOLIAGEDEBUG == 2
|
||||
v_LightAmbientColor.rgb = vec3(0,heightBlend,0);
|
||||
#elif FOLIAGEDEBUG == 3
|
||||
v_LightAmbientColor.rgb = vec3(radiusBlend, 0, 0);
|
||||
#elif FOLIAGEDEBUG == 4
|
||||
float uvWeight = CalcLeavesUVWeight(leafUVs, g_FoliageUVBounds);
|
||||
v_LightAmbientColor.rgb = CAST3(uvWeight);
|
||||
#elif FOLIAGEDEBUG == 5
|
||||
float colY = step(0.0, sin(worldPos.y * g_FoliageScale * 6.666));
|
||||
v_LightAmbientColor.rgb = CAST3(colY);
|
||||
#endif
|
||||
}
|
||||
18
modules/wallpaper-engine/shaders/font.frag
Normal file
18
modules/wallpaper-engine/shaders/font.frag
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
#include "common_fragment.h"
|
||||
|
||||
uniform vec4 g_Color4;
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
varying vec3 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
#if COLORFONT
|
||||
vec4 _sample = texSample2D(g_Texture0, v_TexCoord.xy);
|
||||
gl_FragColor = vec4(_sample.rgb * mix(CAST3(1.0), g_Color4.rgb, v_TexCoord.z), _sample.a * g_Color4.a);
|
||||
#else
|
||||
float _sample = ConvertSampleR8(texSample2D(g_Texture0, v_TexCoord.xy));
|
||||
gl_FragColor = vec4(g_Color4.rgb, _sample * g_Color4.a);
|
||||
#endif
|
||||
}
|
||||
14
modules/wallpaper-engine/shaders/font.vert
Normal file
14
modules/wallpaper-engine/shaders/font.vert
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
uniform mat4 g_ModelMatrix;
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec3 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position.xy, 0.0, 1.0), g_ModelViewProjectionMatrix);
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
v_TexCoord.z = a_Position.z;
|
||||
}
|
||||
172
modules/wallpaper-engine/shaders/fur4.frag
Normal file
172
modules/wallpaper-engine/shaders/fur4.frag
Normal file
@@ -0,0 +1,172 @@
|
||||
|
||||
// [PASS] shadow shadowcasterfur4
|
||||
// [COMBO] {"material":"ui_editor_properties_lighting","combo":"LIGHTING","default":1}
|
||||
// [COMBO] {"material":"ui_editor_properties_fog","combo":"FOG","default":1}
|
||||
// [COMBO] {"material":"ui_editor_properties_reflection","combo":"REFLECTION","default":0}
|
||||
// [COMBO] {"material":"ui_editor_properties_rim_lighting","combo":"RIMLIGHTING","default":0,"require":{"LIGHTING":1}}
|
||||
// [COMBO] {"material":"ui_editor_properties_toon_shading","combo":"SHADINGGRADIENT","default":0,"require":{"LIGHTING":1}}
|
||||
// [COMBO] {"material":"ui_editor_properties_fur_quality","combo":"INSTANCECOUNT","default":5,"options":{"ui_editor_properties_low":5,"ui_editor_properties_medium":9,"ui_editor_properties_high":13,"ui_editor_properties_ultra":21}}
|
||||
|
||||
#define RIM_LIGHTING_AMOUNT g_RimAmount
|
||||
#define RIM_LIGHTING_EXPONENT g_RimExponent
|
||||
|
||||
#if SHADINGGRADIENT
|
||||
#define GRADIENT_SAMPLER g_Texture4
|
||||
uniform sampler2D g_Texture4; // {"label":"ui_editor_properties_shading_gradient","default":"gradient/gradient_toon_smooth","formatcombo":true,"nonremovable":true,"require":{"SHADINGGRADIENT":1}}
|
||||
#endif
|
||||
uniform float g_RimAmount; // {"material":"rimamount","label":"ui_editor_properties_rim_lighting_amount","default":2.0,"range":[0,5],"group":"ui_editor_properties_rim_lighting"}
|
||||
uniform float g_RimExponent; // {"material":"rimexponent","label":"ui_editor_properties_rim_lighting_exponent","default":4.0,"range":[0.01,10],"group":"ui_editor_properties_rim_lighting"}
|
||||
|
||||
#if LIGHTS_SHADOW_MAPPING
|
||||
#define SHADOW_ATLAS_SAMPLER g_Texture6
|
||||
#define SHADOW_ATLAS_TEXEL g_Texture6Texel
|
||||
uniform sampler2DComparison g_Texture6; // {"hidden":true,"default":"_rt_shadowAtlas"}
|
||||
uniform vec4 g_Texture6Texel;
|
||||
#endif
|
||||
|
||||
#if LIGHTS_COOKIE
|
||||
#define COOKIE_SAMPLER g_Texture7
|
||||
uniform sampler2D g_Texture7; // {"hidden":true,"default":"_alias_lightCookie"}
|
||||
#endif
|
||||
|
||||
#include "base/model_fragment_v1.h"
|
||||
#include "common_pbr_2.h"
|
||||
#include "common_fog.h"
|
||||
|
||||
uniform float g_Brightness; // {"material":"brightness","label":"ui_editor_properties_hdr_brightness","default":1,"range":[0,10]}
|
||||
|
||||
uniform vec3 g_TintColor; // {"material":"color","label":"ui_editor_properties_tint_color","type": "color", "default":"1 1 1"}
|
||||
uniform float g_TintAlpha; // {"material":"alpha","label":"ui_editor_properties_opacity","default":1,"range":[0,1]}
|
||||
|
||||
uniform sampler2D g_Texture0; // {"material":"albedo","label":"ui_editor_properties_albedo","default":"util/white"}
|
||||
uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal_map","format":"normalmap","formatcombo":true,"combo":"NORMALMAP"}
|
||||
uniform sampler2D g_Texture2; // {"combo":"PBRMASKS","components":[{"label":"ui_editor_properties_metallic_map","combo":"METALLIC_MAP"},{"label":"ui_editor_properties_roughness_map","combo":"ROUGHNESS_MAP"},{"label":"ui_editor_properties_reflection_map","combo":"REFLECTION_MAP"},{"label":"ui_editor_properties_emissive_map","combo":"EMISSIVE_MAP"}]}
|
||||
|
||||
uniform float g_Roughness; // {"material":"roughness","label":"ui_editor_properties_roughness","default":0.7,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Metallic; // {"material":"metallic","label":"ui_editor_properties_metallic","default":0,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
|
||||
varying vec4 v_WorldNormal;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#ifdef NORMALMAP
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
#endif
|
||||
varying vec3 v_WorldPos;
|
||||
#endif
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
#if REFLECTION
|
||||
uniform sampler2D g_Texture3; // {"hidden":true,"default":"_rt_MipMappedFrameBuffer"}
|
||||
uniform float g_Reflectivity; // {"material":"reflectivity","label":"ui_editor_properties_reflectivity","default":1,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Texture3MipMapInfo;
|
||||
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
uniform vec3 g_EmissiveColor; // {"material":"emissivecolor", "label":"ui_editor_properties_emissive_color", "type": "color", "default":"1 1 1","group":"ui_editor_properties_material"}
|
||||
uniform float g_EmissiveBrightness; // {"material":"emissivebrightness", "label":"ui_editor_properties_emissive_brightness", "default":1.0,"range":[0,10],"group":"ui_editor_properties_material"}
|
||||
|
||||
// <Fur additions
|
||||
uniform sampler2D g_Texture8; // {"material":"fur","label":"ui_editor_properties_fur","default":"util/fur","formatcombo":true}
|
||||
|
||||
uniform float g_FurOcclusion; // {"material":"furocclusion","label":"ui_editor_properties_occlusion","default":0.1,"range":[0.0, 1.0],"group":"ui_editor_properties_fur"}
|
||||
uniform float g_FurDetail; // {"material":"furdetail","label":"ui_editor_properties_detail","default":10.0,"range":[1.0, 30.0],"group":"ui_editor_properties_fur"}
|
||||
// Fur additions>
|
||||
|
||||
#require LightingV1
|
||||
|
||||
void main() {
|
||||
vec4 albedo = texSample2D(g_Texture0, v_TexCoord.xy);
|
||||
|
||||
albedo.rgb *= g_TintColor;
|
||||
|
||||
float metallic = g_Metallic;
|
||||
float roughness = g_Roughness;
|
||||
|
||||
#if PBRMASKS
|
||||
vec4 componentMaps = texSample2D(g_Texture2, v_TexCoord.xy);
|
||||
#endif
|
||||
|
||||
#if METALLIC_MAP
|
||||
metallic = componentMaps.x;
|
||||
#endif
|
||||
|
||||
#if ROUGHNESS_MAP
|
||||
roughness = componentMaps.y;
|
||||
#endif
|
||||
|
||||
vec3 f0 = CAST3(0.04);
|
||||
f0 = mix(f0, albedo.rgb, metallic);
|
||||
|
||||
float viewDist = length(v_ViewDir.xyz);
|
||||
vec3 normalizedViewVector = v_ViewDir.xyz / viewDist;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if NORMALMAP
|
||||
vec3 normal = DecompressNormal(texSample2D(g_Texture1, v_TexCoord.xy));
|
||||
mat3 tangentSpace = mat3(v_Tangent, v_Bitangent, v_Normal);
|
||||
normal = mul(normal, tangentSpace);
|
||||
#else
|
||||
vec3 normal = normalize(v_WorldNormal.xyz);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec3 light = CAST3(0.0);
|
||||
|
||||
#if LIGHTING
|
||||
light = PerformLighting_V1(v_WorldPos, albedo.rgb, normal, normalizedViewVector, CAST3(1.0), f0, roughness, metallic);
|
||||
vec3 ambient = v_LightAmbientColor * albedo.rgb;
|
||||
#else
|
||||
vec3 ambient = albedo.rgb;
|
||||
#endif
|
||||
|
||||
#if EMISSIVE_MAP
|
||||
light = max(light, g_EmissiveColor * albedo.rgb * (componentMaps.a * g_EmissiveBrightness));
|
||||
#endif
|
||||
|
||||
albedo.rgb = CombineLighting(light, ambient);
|
||||
|
||||
#if REFLECTION
|
||||
float reflectivity = g_Reflectivity;
|
||||
#if REFLECTION_MAP
|
||||
reflectivity *= componentMaps.z;
|
||||
#endif
|
||||
albedo.rgb += ApplyReflection(MAKE_SAMPLER2D_ARGUMENT(g_Texture3), g_Texture3MipMapInfo, reflectivity, roughness, metallic, v_ScreenPos.xyz, normal, normalizedViewVector);
|
||||
#endif
|
||||
|
||||
#if HDR
|
||||
albedo.rgb *= g_Brightness;
|
||||
|
||||
#if (LIGHTING || REFLECTION) && EMISSIVE_MAP
|
||||
float emissiveOverbright = max(0.0, componentMaps.a * (g_EmissiveBrightness - 1.0));
|
||||
albedo.rgb += g_EmissiveColor * albedo.rgb * emissiveOverbright;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// <Fur additions
|
||||
float furDistance = v_WorldNormal.w;
|
||||
float furMask = ConvertTextureFormat(TEX8FORMAT, texSample2D(g_Texture8, v_TexCoord.xy * g_FurDetail)).a;
|
||||
float furOcclusion = max(1.0 - albedo.a, saturate(2.0 * furDistance));
|
||||
|
||||
albedo.rgb *= saturate(max(1.0 - (furDistance - furMask), 1.0 - albedo.a));
|
||||
albedo.a = step(furDistance, furMask) * g_TintAlpha;
|
||||
albedo.rgb *= (1.0 - g_FurOcclusion) + furOcclusion * g_FurOcclusion;
|
||||
// Fur additions>
|
||||
|
||||
#if FOG_HEIGHT || FOG_DIST
|
||||
vec2 fogPixelState = CalculateFogPixelState(viewDist, v_ViewDir.w);
|
||||
albedo.rgb = ApplyFog(albedo.rgb, fogPixelState);
|
||||
#if ADDITIVE
|
||||
albedo.a = ApplyFogAlpha(albedo.a, fogPixelState);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gl_FragColor = albedo;
|
||||
|
||||
ApplyAlphaToCoverage(gl_FragColor.a);
|
||||
}
|
||||
97
modules/wallpaper-engine/shaders/fur4.vert
Normal file
97
modules/wallpaper-engine/shaders/fur4.vert
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
#include "base/model_vertex_v1.h"
|
||||
|
||||
uniform vec3 g_EyePosition;
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec3 a_Normal;
|
||||
attribute vec2 a_TexCoord;
|
||||
#if HLSL
|
||||
in uint gl_InstanceID;
|
||||
#endif
|
||||
|
||||
varying vec4 v_WorldNormal;
|
||||
varying vec4 v_ViewDir;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if NORMALMAP
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
#else
|
||||
#endif
|
||||
varying vec3 v_WorldPos;
|
||||
#endif
|
||||
|
||||
#if REFLECTION
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
#if MORPHING
|
||||
uniform sampler2D g_Texture5; // {"material":"morph","hidden":true}
|
||||
uniform vec4 g_Texture5Texel;
|
||||
#endif
|
||||
|
||||
uniform sampler2D g_Texture0; // {"material":"albedo","label":"ui_editor_properties_albedo","default":"util/white"}
|
||||
|
||||
// <Fur additions
|
||||
uniform float g_FurDistance; // {"material":"furdistance","label":"ui_editor_properties_distance","default":0.1,"range":[0.001, 0.2],"group":"ui_editor_properties_fur"}
|
||||
// Fur additions>
|
||||
|
||||
void main() {
|
||||
vec3 localPos = a_Position;
|
||||
vec3 localNormal = a_Normal;
|
||||
|
||||
#if MORPHING
|
||||
ApplyMorphPositionNormal(CASTU(gl_VertexID), MAKE_SAMPLER2D_ARGUMENT(g_Texture5), g_Texture5Texel, g_MorphOffsets, g_MorphWeights, localPos, localNormal);
|
||||
#endif
|
||||
|
||||
vec4 worldPos;
|
||||
vec3 worldNormal;
|
||||
#if SKINNING
|
||||
ApplySkinningPositionNormal(localPos, localNormal, a_BlendIndices, a_BlendWeights, worldPos, worldNormal);
|
||||
#else
|
||||
ApplyPositionNormal(localPos, localNormal, worldPos, worldNormal);
|
||||
#endif
|
||||
|
||||
// <Fur additions
|
||||
float furDistance = texSample2DLod(g_Texture0, a_TexCoord.xy, 0.0).a;
|
||||
v_WorldNormal.w = CASTF(gl_InstanceID) / (CASTF(INSTANCECOUNT) - 1.0);
|
||||
worldPos.xyz += worldNormal * v_WorldNormal.w * g_FurDistance * furDistance;
|
||||
// Fur additions>
|
||||
|
||||
gl_Position = mul(worldPos, g_ViewProjectionMatrix);
|
||||
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
v_ViewDir.xyz = g_EyePosition - worldPos.xyz;
|
||||
v_ViewDir.w = worldPos.y;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
v_WorldPos = worldPos.xyz;
|
||||
#if NORMALMAP
|
||||
mat3 tangentSpace;
|
||||
#if SKINNING
|
||||
ApplySkinningTangentSpace(worldNormal, a_Tangent4, a_BlendIndices, a_BlendWeights, tangentSpace);
|
||||
#else
|
||||
ApplyTangentSpace(worldNormal, a_Tangent4, tangentSpace);
|
||||
#endif
|
||||
|
||||
v_Tangent = tangentSpace[0];
|
||||
v_Bitangent = tangentSpace[1];
|
||||
v_Normal = tangentSpace[2];
|
||||
#else
|
||||
#endif
|
||||
#endif
|
||||
|
||||
v_WorldNormal.xyz = worldNormal;
|
||||
|
||||
#if REFLECTION
|
||||
ClipSpaceToScreenSpace(gl_Position, v_ScreenPos);
|
||||
#endif
|
||||
|
||||
v_LightAmbientColor = ApplyAmbientLighting(worldNormal);
|
||||
}
|
||||
109
modules/wallpaper-engine/shaders/generic.frag
Normal file
109
modules/wallpaper-engine/shaders/generic.frag
Normal file
@@ -0,0 +1,109 @@
|
||||
|
||||
#include "common_fragment.h"
|
||||
|
||||
uniform vec4 g_LightsColorRadius[4];
|
||||
|
||||
uniform float g_Metallic; // {"material":"Metal","default":0,"range":[0,1]}
|
||||
uniform float g_Roughness; // {"material":"Rough","default":0,"range":[0,1]}
|
||||
uniform float g_Light; // {"material":"Light","default":0,"range":[0,1]}
|
||||
|
||||
#if DIFFUSETINT
|
||||
uniform vec3 g_TintColor; // {"material":"Color", "type": "color", "default":"1 1 1"}
|
||||
uniform float g_TintAlpha; // {"material":"Alpha","default":0,"range":[0,1]}
|
||||
#endif
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
#if NORMALMAP
|
||||
|
||||
uniform sampler2D g_Texture1;
|
||||
#define g_NormalMapSampler g_Texture1
|
||||
|
||||
#if LIGHTMAP
|
||||
uniform sampler2D g_Texture2;
|
||||
#define g_LightmapMapSampler g_Texture2
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if LIGHTMAP
|
||||
uniform sampler2D g_Texture1;
|
||||
#define g_LightmapMapSampler g_Texture1
|
||||
#endif
|
||||
|
||||
varying vec3 v_Normal;
|
||||
|
||||
#endif
|
||||
|
||||
#if REFLECTION
|
||||
uniform sampler2D g_Texture3;
|
||||
#define g_ReflectionSampler g_Texture3
|
||||
|
||||
varying vec3 v_ScreenPos;
|
||||
uniform vec2 g_TexelSizeHalf;
|
||||
#endif
|
||||
|
||||
#if LIGHTMAP
|
||||
varying vec4 v_TexCoord;
|
||||
#else
|
||||
varying vec2 v_TexCoord;
|
||||
#endif
|
||||
|
||||
varying vec3 v_ViewDir;
|
||||
varying vec4 v_Light0DirectionL3X;
|
||||
varying vec4 v_Light1DirectionL3Y;
|
||||
varying vec4 v_Light2DirectionL3Z;
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
void main() {
|
||||
// Vars
|
||||
vec4 albedo = texSample2D(g_Texture0, v_TexCoord.xy);
|
||||
vec3 specularResult = vec3(0, 0, 0);
|
||||
|
||||
#if DIFFUSETINT
|
||||
albedo.rgb *= g_TintColor;
|
||||
albedo.a *= g_TintAlpha;
|
||||
#endif
|
||||
|
||||
#if DETAILINALPHA
|
||||
albedo.rgb *= texSample2D(g_Texture0, v_TexCoord.xy * 3).a * 2.0;
|
||||
#endif
|
||||
|
||||
vec3 viewDir = normalize(v_ViewDir);
|
||||
float specularPower = ComputeMaterialSpecularPower(g_Roughness, g_Metallic);
|
||||
float specularStrength = ComputeMaterialSpecularStrength(g_Roughness, g_Metallic);
|
||||
|
||||
#if NORMALMAP
|
||||
vec3 normal = DecompressNormal(texSample2D(g_NormalMapSampler, v_TexCoord.xy));
|
||||
#else
|
||||
vec3 normal = normalize(v_Normal);
|
||||
#endif
|
||||
|
||||
// Compute fragment
|
||||
vec3 light = ComputeLightSpecular(normal, v_Light0DirectionL3X.xyz, g_LightsColorRadius[0].rgb, g_LightsColorRadius[0].w, viewDir, specularPower, specularStrength, g_Light, g_Metallic, specularResult);
|
||||
|
||||
#if LIGHTMAP
|
||||
vec3 lightmap = texSample2D(g_LightmapMapSampler, v_TexCoord.zw).rgb;
|
||||
light *= lightmap;
|
||||
specularResult *= lightmap;
|
||||
#endif
|
||||
|
||||
light += ComputeLightSpecular(normal, v_Light1DirectionL3Y.xyz, g_LightsColorRadius[1].rgb, g_LightsColorRadius[1].w, viewDir, specularPower, specularStrength, g_Light, g_Metallic, specularResult);
|
||||
|
||||
light += ComputeLightSpecular(normal, v_Light2DirectionL3Z.xyz, g_LightsColorRadius[2].rgb, g_LightsColorRadius[2].w, viewDir, specularPower, specularStrength, g_Light, g_Metallic, specularResult);
|
||||
|
||||
light += ComputeLightSpecular(normal, vec3(v_Light0DirectionL3X.w, v_Light1DirectionL3Y.w, v_Light2DirectionL3Z.w), g_LightsColorRadius[3].rgb, g_LightsColorRadius[3].w, viewDir, specularPower, specularStrength, g_Light, g_Metallic, specularResult);
|
||||
|
||||
light += v_LightAmbientColor;
|
||||
albedo.rgb = albedo.rgb * light + specularResult;
|
||||
|
||||
#if REFLECTION
|
||||
vec2 screenUV = (v_ScreenPos.xy / v_ScreenPos.z) * 0.5 + 0.5;
|
||||
#ifdef HLSL_SM30
|
||||
screenUV += g_TexelSizeHalf;
|
||||
#endif
|
||||
albedo.rgb += texSample2D(g_ReflectionSampler, screenUV + normal.xy * 0.01).rgb * 0.35;
|
||||
#endif
|
||||
|
||||
gl_FragColor = albedo;
|
||||
}
|
||||
78
modules/wallpaper-engine/shaders/generic.vert
Normal file
78
modules/wallpaper-engine/shaders/generic.vert
Normal file
@@ -0,0 +1,78 @@
|
||||
|
||||
#include "common_vertex.h"
|
||||
|
||||
uniform mat4 g_ModelMatrix;
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
uniform vec3 g_EyePosition;
|
||||
uniform vec3 g_LightsPosition[4];
|
||||
uniform vec3 g_LightAmbientColor;
|
||||
uniform vec3 g_LightSkylightColor;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec3 a_Normal;
|
||||
#if LIGHTMAP
|
||||
attribute vec4 a_TexCoordVec4;
|
||||
#else
|
||||
attribute vec2 a_TexCoord;
|
||||
#endif
|
||||
|
||||
#if NORMALMAP
|
||||
attribute vec4 a_Tangent4;
|
||||
#else
|
||||
varying vec3 v_Normal;
|
||||
#endif
|
||||
|
||||
varying vec3 v_ViewDir;
|
||||
#if LIGHTMAP
|
||||
varying vec4 v_TexCoord;
|
||||
#else
|
||||
varying vec2 v_TexCoord;
|
||||
#endif
|
||||
varying vec4 v_Light0DirectionL3X;
|
||||
varying vec4 v_Light1DirectionL3Y;
|
||||
varying vec4 v_Light2DirectionL3Z;
|
||||
|
||||
#if REFLECTION
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
void main() {
|
||||
vec4 worldPos = mul(vec4(a_Position, 1.0), g_ModelMatrix);
|
||||
gl_Position = mul(worldPos, g_ViewProjectionMatrix);
|
||||
vec3 normal = normalize(mul(a_Normal, CAST3X3(g_ModelMatrix)));
|
||||
#if LIGHTMAP
|
||||
v_TexCoord = a_TexCoordVec4;
|
||||
#else
|
||||
v_TexCoord = a_TexCoord;
|
||||
#endif
|
||||
|
||||
#if REFLECTION
|
||||
v_ScreenPos = gl_Position.xyw;
|
||||
#endif
|
||||
|
||||
v_ViewDir = g_EyePosition - worldPos.xyz;
|
||||
|
||||
v_Light0DirectionL3X.xyz = g_LightsPosition[0] - worldPos.xyz;
|
||||
v_Light1DirectionL3Y.xyz = g_LightsPosition[1] - worldPos.xyz;
|
||||
v_Light2DirectionL3Z.xyz = g_LightsPosition[2] - worldPos.xyz;
|
||||
|
||||
vec3 l3 = g_LightsPosition[3] - worldPos.xyz;
|
||||
|
||||
#if NORMALMAP
|
||||
mat3 tangentSpace = BuildTangentSpace(CAST3X3(g_ModelMatrix), a_Normal, a_Tangent4);
|
||||
v_Light0DirectionL3X.xyz = mul(tangentSpace, v_Light0DirectionL3X.xyz);
|
||||
v_Light1DirectionL3Y.xyz = mul(tangentSpace, v_Light1DirectionL3Y.xyz);
|
||||
v_Light2DirectionL3Z.xyz = mul(tangentSpace, v_Light2DirectionL3Z.xyz);
|
||||
l3 = mul(tangentSpace, l3);
|
||||
v_ViewDir = mul(tangentSpace, v_ViewDir);
|
||||
#else
|
||||
v_Normal = normal;
|
||||
#endif
|
||||
|
||||
v_Light0DirectionL3X.w = l3.x;
|
||||
v_Light1DirectionL3Y.w = l3.y;
|
||||
v_Light2DirectionL3Z.w = l3.z;
|
||||
v_LightAmbientColor = mix(g_LightSkylightColor, g_LightAmbientColor, dot(normal, vec3(0, 1, 0)) * 0.5 + 0.5);
|
||||
}
|
||||
84
modules/wallpaper-engine/shaders/generic2.frag
Normal file
84
modules/wallpaper-engine/shaders/generic2.frag
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
#include "common_fragment.h"
|
||||
|
||||
uniform vec4 g_LightsColorRadius[4];
|
||||
|
||||
uniform float g_Metallic; // {"material":"Metal","default":0,"range":[0,1]}
|
||||
uniform float g_Roughness; // {"material":"Rough","default":0,"range":[0,1]}
|
||||
uniform float g_Brightness; // {"material":"Brigtness","default":1,"range":[0,10]}
|
||||
uniform float g_Light; // {"material":"Light","default":0,"range":[0,1]}
|
||||
|
||||
uniform vec3 g_TintColor; // {"material":"Color", "type": "color", "default":"1 1 1"}
|
||||
uniform float g_TintAlpha; // {"material":"Alpha","default":1,"range":[0,1]}
|
||||
|
||||
|
||||
uniform sampler2D g_Texture0; // {"label":"ui_editor_properties_albedo","default":"util/white"}
|
||||
uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal_map","format":"normalmap","formatcombo":true,"combo":"NORMALMAP"}
|
||||
uniform sampler2D g_Texture2; // {"default":"_rt_Reflection","hidden":true}
|
||||
|
||||
#if NORMALMAP
|
||||
|
||||
#else
|
||||
varying vec3 v_Normal;
|
||||
#endif
|
||||
|
||||
#if REFLECTION
|
||||
varying vec3 v_ScreenPos;
|
||||
uniform vec2 g_TexelSizeHalf;
|
||||
#endif
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec3 v_ViewDir;
|
||||
varying vec4 v_Light0DirectionL3X;
|
||||
varying vec4 v_Light1DirectionL3Y;
|
||||
varying vec4 v_Light2DirectionL3Z;
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
void main() {
|
||||
// Vars
|
||||
vec4 albedo = texSample2D(g_Texture0, v_TexCoord.xy);
|
||||
vec3 specularResult = vec3(0, 0, 0);
|
||||
|
||||
albedo.rgb *= g_TintColor;
|
||||
albedo.a *= g_TintAlpha;
|
||||
|
||||
#if DETAILINALPHA
|
||||
albedo.rgb *= texSample2D(g_Texture0, v_TexCoord.xy * 3).a * 2.0;
|
||||
#endif
|
||||
|
||||
vec3 viewDir = normalize(v_ViewDir);
|
||||
float specularPower = ComputeMaterialSpecularPower(g_Roughness, g_Metallic);
|
||||
float specularStrength = ComputeMaterialSpecularStrength(g_Roughness, g_Metallic);
|
||||
|
||||
#if NORMALMAP
|
||||
vec3 normal = DecompressNormal(texSample2D(g_Texture1, v_TexCoord.xy));
|
||||
#else
|
||||
vec3 normal = normalize(v_Normal);
|
||||
#endif
|
||||
|
||||
// Compute fragment
|
||||
vec3 light = ComputeLightSpecular(normal, v_Light0DirectionL3X.xyz, g_LightsColorRadius[0].rgb, g_LightsColorRadius[0].w, viewDir, specularPower, specularStrength, g_Light, g_Metallic, specularResult);
|
||||
|
||||
light += ComputeLightSpecular(normal, v_Light1DirectionL3Y.xyz, g_LightsColorRadius[1].rgb, g_LightsColorRadius[1].w, viewDir, specularPower, specularStrength, g_Light, g_Metallic, specularResult);
|
||||
|
||||
light += ComputeLightSpecular(normal, v_Light2DirectionL3Z.xyz, g_LightsColorRadius[2].rgb, g_LightsColorRadius[2].w, viewDir, specularPower, specularStrength, g_Light, g_Metallic, specularResult);
|
||||
|
||||
light += ComputeLightSpecular(normal, vec3(v_Light0DirectionL3X.w, v_Light1DirectionL3Y.w, v_Light2DirectionL3Z.w), g_LightsColorRadius[3].rgb, g_LightsColorRadius[3].w, viewDir, specularPower, specularStrength, g_Light, g_Metallic, specularResult);
|
||||
|
||||
light += v_LightAmbientColor;
|
||||
albedo.rgb = albedo.rgb * light + specularResult;
|
||||
|
||||
#if REFLECTION
|
||||
vec2 screenUV = (v_ScreenPos.xy / v_ScreenPos.z) * 0.5 + 0.5;
|
||||
#ifdef HLSL_SM30
|
||||
screenUV += g_TexelSizeHalf;
|
||||
#endif
|
||||
albedo.rgb += texSample2D(g_Texture2, screenUV + normal.xy * 0.01).rgb * 0.35;
|
||||
#endif
|
||||
|
||||
#if HDR
|
||||
albedo.rgb *= g_Brightness;
|
||||
#endif
|
||||
|
||||
gl_FragColor = albedo;
|
||||
}
|
||||
74
modules/wallpaper-engine/shaders/generic2.vert
Normal file
74
modules/wallpaper-engine/shaders/generic2.vert
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
#include "common_vertex.h"
|
||||
|
||||
uniform mat4 g_ModelMatrix;
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
uniform vec3 g_EyePosition;
|
||||
uniform vec3 g_LightsPosition[4];
|
||||
uniform vec3 g_LightAmbientColor;
|
||||
uniform vec3 g_LightSkylightColor;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec3 a_Normal;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
#if NORMALMAP
|
||||
attribute vec4 a_Tangent4;
|
||||
#else
|
||||
varying vec3 v_Normal;
|
||||
#endif
|
||||
|
||||
varying vec3 v_ViewDir;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
varying vec4 v_Light0DirectionL3X;
|
||||
varying vec4 v_Light1DirectionL3Y;
|
||||
varying vec4 v_Light2DirectionL3Z;
|
||||
|
||||
#if REFLECTION
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
void main() {
|
||||
vec4 worldPos = mul(vec4(a_Position, 1.0), g_ModelMatrix);
|
||||
gl_Position = mul(worldPos, g_ViewProjectionMatrix);
|
||||
vec3 normal = normalize(mul(a_Normal, CAST3X3(g_ModelMatrix)));
|
||||
v_TexCoord = a_TexCoord;
|
||||
|
||||
#if REFLECTION
|
||||
v_ScreenPos = gl_Position.xyw;
|
||||
#endif
|
||||
|
||||
v_ViewDir = g_EyePosition - worldPos.xyz;
|
||||
|
||||
v_Light0DirectionL3X.xyz = g_LightsPosition[0] - worldPos.xyz;
|
||||
v_Light1DirectionL3Y.xyz = g_LightsPosition[1] - worldPos.xyz;
|
||||
v_Light2DirectionL3Z.xyz = g_LightsPosition[2] - worldPos.xyz;
|
||||
|
||||
vec3 l3 = g_LightsPosition[3] - worldPos.xyz;
|
||||
|
||||
#if NORMALMAP
|
||||
mat3 tangentSpace = BuildTangentSpace(CAST3X3(g_ModelMatrix), a_Normal, a_Tangent4);
|
||||
|
||||
#ifdef VERSION
|
||||
tangentSpace[0] = normalize(tangentSpace[0]);
|
||||
tangentSpace[1] = normalize(tangentSpace[1]);
|
||||
tangentSpace[2] = normalize(tangentSpace[2]);
|
||||
#endif
|
||||
|
||||
v_Light0DirectionL3X.xyz = mul(tangentSpace, v_Light0DirectionL3X.xyz);
|
||||
v_Light1DirectionL3Y.xyz = mul(tangentSpace, v_Light1DirectionL3Y.xyz);
|
||||
v_Light2DirectionL3Z.xyz = mul(tangentSpace, v_Light2DirectionL3Z.xyz);
|
||||
l3 = mul(tangentSpace, l3);
|
||||
v_ViewDir = mul(tangentSpace, v_ViewDir);
|
||||
#else
|
||||
v_Normal = normal;
|
||||
#endif
|
||||
|
||||
v_Light0DirectionL3X.w = l3.x;
|
||||
v_Light1DirectionL3Y.w = l3.y;
|
||||
v_Light2DirectionL3Z.w = l3.z;
|
||||
v_LightAmbientColor = mix(g_LightSkylightColor, g_LightAmbientColor, dot(normal, vec3(0, 1, 0)) * 0.5 + 0.5);
|
||||
}
|
||||
276
modules/wallpaper-engine/shaders/generic3.frag
Normal file
276
modules/wallpaper-engine/shaders/generic3.frag
Normal file
@@ -0,0 +1,276 @@
|
||||
|
||||
// [COMBO] {"material":"ui_editor_properties_lighting","combo":"LIGHTING","default":1}
|
||||
// [COMBO] {"material":"ui_editor_properties_reflection","combo":"REFLECTION","default":0}
|
||||
// [COMBO] {"material":"ui_editor_properties_rim_lighting","combo":"RIMLIGHTING","default":0,"require":{"LIGHTING":1}}
|
||||
// [COMBO] {"material":"ui_editor_properties_toon_shading","combo":"SHADINGGRADIENT","default":0,"require":{"LIGHTING":1}}
|
||||
// [COMBO] {"material":"ui_editor_properties_tint_mask_in_alpha","combo":"TINTMASKALPHA","default":0}
|
||||
// [COMBO_DISABLED] {"material":"ui_editor_properties_double_sided_lighting","combo":"DOUBLESIDEDLIGHTING","default":0}
|
||||
|
||||
#define RIM_LIGHTING_AMOUNT g_RimAmount
|
||||
#define RIM_LIGHTING_EXPONENT g_RimExponent
|
||||
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
|
||||
#if SHADINGGRADIENT
|
||||
#define GRADIENT_SAMPLER g_Texture4
|
||||
uniform sampler2D g_Texture4; // {"label":"ui_editor_properties_shading_gradient","default":"gradient/gradient_toon_smooth","formatcombo":true,"nonremovable":true,"require":{"SHADINGGRADIENT":1}}
|
||||
#endif
|
||||
uniform float g_RimAmount; // {"material":"rimamount","label":"ui_editor_properties_rim_lighting_amount","default":2.0,"range":[0,5],"group":"ui_editor_properties_rim_lighting"}
|
||||
uniform float g_RimExponent; // {"material":"rimexponent","label":"ui_editor_properties_rim_lighting_exponent","default":4.0,"range":[0.01,10],"group":"ui_editor_properties_rim_lighting"}
|
||||
|
||||
#include "common_fragment.h"
|
||||
#include "common_pbr.h"
|
||||
|
||||
uniform float g_Brightness; // {"material":"brightness","label":"ui_editor_properties_hdr_brightness","default":1,"range":[0,10]}
|
||||
|
||||
uniform vec3 g_TintColor; // {"material":"color","label":"ui_editor_properties_tint_color","type": "color", "default":"1 1 1"}
|
||||
uniform float g_TintAlpha; // {"material":"alpha","label":"ui_editor_properties_opacity","default":1,"range":[0,1]}
|
||||
|
||||
uniform sampler2D g_Texture0; // {"material":"albedo","label":"ui_editor_properties_albedo","default":"util/white"}
|
||||
uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal_map","format":"normalmap","formatcombo":true,"combo":"NORMALMAP"}
|
||||
uniform sampler2D g_Texture2; // {"combo":"PBRMASKS","components":[{"label":"ui_editor_properties_metallic_map","combo":"METALLIC_MAP"},{"label":"ui_editor_properties_roughness_map","combo":"ROUGHNESS_MAP"},{"label":"ui_editor_properties_reflection_map","combo":"REFLECTION_MAP"},{"label":"ui_editor_properties_emissive_map","combo":"EMISSIVE_MAP"}]}
|
||||
|
||||
uniform float g_Roughness; // {"material":"roughness","label":"ui_editor_properties_roughness","default":0.7,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Metallic; // {"material":"metallic","label":"ui_editor_properties_metallic","default":0,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#ifdef NORMALMAP
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
#else
|
||||
varying vec3 v_WorldNormal;
|
||||
#endif
|
||||
varying vec3 v_WorldPos;
|
||||
#endif
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
#if REFLECTION
|
||||
uniform vec3 g_Screen;
|
||||
uniform sampler2D g_Texture3; // {"hidden":true,"default":"_rt_MipMappedFrameBuffer"}
|
||||
uniform float g_Reflectivity; // {"material":"reflectivity","label":"ui_editor_properties_reflectivity","default":1,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Texture3MipMapInfo;
|
||||
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
uniform vec3 g_EmissiveColor; // {"material":"emissivecolor", "label":"ui_editor_properties_emissive_color", "type": "color", "default":"1 1 1","group":"ui_editor_properties_material"}
|
||||
uniform float g_EmissiveBrightness; // {"material":"emissivebrightness", "label":"ui_editor_properties_emissive_brightness", "default":1.0,"range":[0,10],"group":"ui_editor_properties_material"}
|
||||
|
||||
#if LIGHTS_POINT
|
||||
uniform vec4 g_LPoint_Color[LIGHTS_POINT];
|
||||
uniform vec4 g_LPoint_Origin[LIGHTS_POINT];
|
||||
#endif
|
||||
#if LIGHTS_SPOT
|
||||
uniform vec4 g_LSpot_Color[LIGHTS_SPOT];
|
||||
uniform vec4 g_LSpot_Origin[LIGHTS_SPOT];
|
||||
uniform vec4 g_LSpot_Direction[LIGHTS_SPOT];
|
||||
#endif
|
||||
#if LIGHTS_TUBE
|
||||
uniform vec4 g_LTube_Color[LIGHTS_TUBE];
|
||||
uniform vec4 g_LTube_OriginA[LIGHTS_TUBE];
|
||||
uniform vec4 g_LTube_OriginB[LIGHTS_TUBE];
|
||||
#endif
|
||||
#if LIGHTS_DIRECTIONAL
|
||||
uniform vec4 g_LDirectional_Color[LIGHTS_DIRECTIONAL];
|
||||
uniform vec4 g_LDirectional_Direction[LIGHTS_DIRECTIONAL];
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
#if SHADERVERSION < 62
|
||||
// DEPRECATION BSSSSS
|
||||
vec3 PerformLighting_Deprecated(vec3 worldPos, vec3 color, vec3 normal, vec3 viewVector, vec3 specularTint, vec3 ambient, float roughness, float metallic)
|
||||
{
|
||||
vec3 light = CAST3(0);
|
||||
|
||||
#if LIGHTS_POINT
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_POINT); ++l)
|
||||
{
|
||||
vec3 lightDelta = g_LPoint_Origin[l].xyz - worldPos;
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LPoint_Color[l].rgb, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_SPOT
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_SPOT); ++l)
|
||||
{
|
||||
vec3 lightDelta = g_LSpot_Origin[l].xyz - worldPos;
|
||||
float spotCookie = -dot(normalize(lightDelta), g_LSpot_Direction[l].xyz);
|
||||
spotCookie = smoothstep(g_LSpot_Direction[l].w, g_LSpot_Origin[l].w, spotCookie);
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LSpot_Color[l].rgb, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_TUBE
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_TUBE); ++l)
|
||||
{
|
||||
vec3 lightDelta = PointSegmentDelta(worldPos, g_LTube_OriginA[l].xyz, g_LTube_OriginB[l].xyz);
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LTube_Color[l].rgb, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_DIRECTIONAL
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_DIRECTIONAL); ++l)
|
||||
{
|
||||
light += ComputePBRLight(normal, g_LDirectional_Direction[l].xyz, viewVector, color, g_LDirectional_Color[l].rgb, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
vec3 PerformLighting_Deprecated(vec3 worldPos, vec3 color, vec3 normal, vec3 viewVector, vec3 specularTint, vec3 ambient, float roughness, float metallic)
|
||||
{
|
||||
vec3 light = CAST3(0);
|
||||
|
||||
#if LIGHTS_POINT
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_POINT); ++l)
|
||||
{
|
||||
vec3 lightDelta = g_LPoint_Origin[l].xyz - worldPos;
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LPoint_Color[l].rgb * g_LPoint_Color[l].w * g_LPoint_Color[l].w, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_SPOT
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_SPOT); ++l)
|
||||
{
|
||||
vec3 lightDelta = g_LSpot_Origin[l].xyz - worldPos;
|
||||
float spotCookie = -dot(normalize(lightDelta), g_LSpot_Direction[l].xyz);
|
||||
spotCookie = smoothstep(g_LSpot_Direction[l].w, g_LSpot_Origin[l].w, spotCookie);
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LSpot_Color[l].rgb * spotCookie * g_LSpot_Color[l].w * g_LSpot_Color[l].w, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_TUBE
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_TUBE); ++l)
|
||||
{
|
||||
vec3 lightDelta = PointSegmentDelta(worldPos, g_LTube_OriginA[l].xyz, g_LTube_OriginB[l].xyz);
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LTube_Color[l].rgb * g_LTube_Color[l].w * g_LTube_Color[l].w, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_DIRECTIONAL
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_DIRECTIONAL); ++l)
|
||||
{
|
||||
light += ComputePBRLight(normal, g_LDirectional_Direction[l].xyz, viewVector, color, g_LDirectional_Color[l].rgb * g_LDirectional_Color[l].w * g_LDirectional_Color[l].w, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec4 albedo = texSample2D(g_Texture0, v_TexCoord.xy);
|
||||
|
||||
#if TINTMASKALPHA
|
||||
albedo.rgb = mix(albedo.rgb, CAST3(max(albedo.x, max(albedo.y, albedo.z))) * g_TintColor, albedo.a);
|
||||
albedo.a = 1.0;
|
||||
#else
|
||||
albedo.rgb *= g_TintColor;
|
||||
#endif
|
||||
albedo.a *= g_TintAlpha;
|
||||
|
||||
float metallic = g_Metallic;
|
||||
float roughness = g_Roughness;
|
||||
|
||||
#if PBRMASKS
|
||||
vec4 componentMaps = texSample2D(g_Texture2, v_TexCoord.xy);
|
||||
#endif
|
||||
|
||||
#if METALLIC_MAP
|
||||
metallic = componentMaps.x;
|
||||
#endif
|
||||
|
||||
#if ROUGHNESS_MAP
|
||||
roughness = componentMaps.y;
|
||||
#endif
|
||||
|
||||
vec3 f0 = CAST3(0.04);
|
||||
f0 = mix(f0, albedo.rgb, metallic);
|
||||
|
||||
float viewDist = length(v_ViewDir.xyz);
|
||||
vec3 normalizedViewVector = v_ViewDir.xyz / viewDist;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if NORMALMAP
|
||||
vec3 normal = DecompressNormal(texSample2D(g_Texture1, v_TexCoord.xy));
|
||||
mat3 tangentSpace = mat3(v_Tangent, v_Bitangent, v_Normal);
|
||||
normal = mul(normal, tangentSpace);
|
||||
#else
|
||||
vec3 normal = normalize(v_WorldNormal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec3 light = CAST3(0.0);
|
||||
|
||||
#if LIGHTING
|
||||
light = PerformLighting_Deprecated(v_WorldPos, albedo.rgb, normal, normalizedViewVector, CAST3(1.0), f0, roughness, metallic);
|
||||
vec3 ambient = v_LightAmbientColor * albedo.rgb;
|
||||
#else
|
||||
vec3 ambient = albedo.rgb;
|
||||
#endif
|
||||
|
||||
#if EMISSIVE_MAP
|
||||
light = max(light, g_EmissiveColor * albedo.rgb * (componentMaps.a * g_EmissiveBrightness));
|
||||
#endif
|
||||
|
||||
albedo.rgb = CombineLighting(light, ambient);
|
||||
|
||||
#if REFLECTION
|
||||
float reflectivity = g_Reflectivity;
|
||||
|
||||
#if REFLECTION_MAP
|
||||
reflectivity *= componentMaps.z;
|
||||
#endif
|
||||
vec2 screenUV = (v_ScreenPos.xy / v_ScreenPos.z) * 0.5 + 0.5;
|
||||
|
||||
float fresnelTerm = abs(dot(normal, normalizedViewVector));
|
||||
normal = normalize(mul(normal, CAST3X3(g_ViewProjectionMatrix)));
|
||||
|
||||
#ifdef HLSL
|
||||
normal.y = -normal.y;
|
||||
#endif
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
normal.xy = normal.xy * vec2(0.20 / g_Screen.z, 0.20);
|
||||
#else
|
||||
// Make consistent on X since the width is usually more variable (multi monitors) - bad for phones tho
|
||||
normal.xy = normal.xy * vec2(0.15, 0.15 * g_Screen.z);
|
||||
#endif
|
||||
screenUV += normal.xy * pow(fresnelTerm, 4.0) * 10;
|
||||
float clipReflection = smoothstep(1.3, 1.0, screenUV.x) * smoothstep(-0.3, 0.0, screenUV.x) *
|
||||
smoothstep(1.3, 1.0, screenUV.y) * smoothstep(-0.3, 0.0, screenUV.y);
|
||||
|
||||
vec3 reflectionColor = texSample2DLod(g_Texture3, screenUV, roughness * g_Texture3MipMapInfo).rgb * clipReflection;
|
||||
reflectionColor = reflectionColor * (1.0 - fresnelTerm) * reflectivity;
|
||||
reflectionColor = pow(max(CAST3(0.001), reflectionColor), CAST3(2.0 - metallic));
|
||||
|
||||
albedo.rgb += saturate(reflectionColor);
|
||||
#endif
|
||||
|
||||
#if HDR
|
||||
albedo.rgb *= g_Brightness;
|
||||
|
||||
#if (LIGHTING || REFLECTION) && EMISSIVE_MAP
|
||||
float emissiveOverbright = max(0.0, componentMaps.a * (g_EmissiveBrightness - 1.0));
|
||||
albedo.rgb += g_EmissiveColor * albedo.rgb * emissiveOverbright;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gl_FragColor = albedo;
|
||||
|
||||
#if ALPHATOCOVERAGE
|
||||
gl_FragColor.a = (gl_FragColor.a - 0.5) / max(fwidth(gl_FragColor.a), 0.0001) + 0.5;
|
||||
#if GLSL
|
||||
if (gl_FragColor.a < 0.5) discard;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
172
modules/wallpaper-engine/shaders/generic3.vert
Normal file
172
modules/wallpaper-engine/shaders/generic3.vert
Normal file
@@ -0,0 +1,172 @@
|
||||
|
||||
#include "common_vertex.h"
|
||||
|
||||
uniform mat4 g_ModelMatrix;
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
uniform vec3 g_EyePosition;
|
||||
uniform vec3 g_LightAmbientColor;
|
||||
uniform vec3 g_LightSkylightColor;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec3 a_Normal;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
#if SKINNING
|
||||
uniform mat4x3 g_Bones[BONECOUNT];
|
||||
|
||||
attribute uvec4 a_BlendIndices;
|
||||
attribute vec4 a_BlendWeights;
|
||||
#endif
|
||||
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if NORMALMAP
|
||||
attribute vec4 a_Tangent4;
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
#else
|
||||
varying vec3 v_WorldNormal;
|
||||
#endif
|
||||
varying vec3 v_WorldPos;
|
||||
#endif
|
||||
|
||||
#if REFLECTION
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
#if MORPHING
|
||||
#if HLSL
|
||||
in uint gl_VertexID;
|
||||
#endif
|
||||
|
||||
uniform sampler2D g_Texture5; // {"material":"morph","hidden":true}
|
||||
uniform vec4 g_Texture5Resolution;
|
||||
|
||||
uniform uint g_MorphOffsets[12];
|
||||
uniform float g_MorphWeights[12];
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec3 localPos = a_Position;
|
||||
vec3 localNormal = a_Normal;
|
||||
|
||||
#if MORPHING
|
||||
vec2 texture5ResolutionInv = 1.0 / g_Texture5Resolution.xy;
|
||||
vec3 morphPos = CAST3(0.0);
|
||||
vec3 morphNormal = CAST3(0.0);
|
||||
for (uint morphTarget = 0u; morphTarget < g_MorphOffsets[0] % 12u; ++morphTarget)
|
||||
{
|
||||
uint morphMapOffset = CASTU(gl_VertexID) + g_MorphOffsets[1u + morphTarget];
|
||||
vec2 offset = 0.5 * texture5ResolutionInv;
|
||||
|
||||
#if MORPHING_NORMALS
|
||||
uint morphMapIndex = (morphMapOffset * 6u) / 4u;
|
||||
float morphMapFlip = CASTF((morphMapOffset * 6u) % 4u);
|
||||
|
||||
uint morphPixel1x = morphMapIndex % CASTU(g_Texture5Resolution.x);
|
||||
uint morphPixel1y = morphMapIndex / CASTU(g_Texture5Resolution.y);
|
||||
uint morphPixel2x = (morphMapIndex + 1u) % CASTU(g_Texture5Resolution.x);
|
||||
uint morphPixel2y = (morphMapIndex + 1u) / CASTU(g_Texture5Resolution.y);
|
||||
|
||||
vec4 morphCol1 = texSample2DLod(g_Texture5, vec2(morphPixel1x, morphPixel1y) * texture5ResolutionInv + offset, 0.0);
|
||||
vec4 morphCol2 = texSample2DLod(g_Texture5, vec2(morphPixel2x, morphPixel2y) * texture5ResolutionInv + offset, 0.0);
|
||||
|
||||
vec3 posDeltaV1 = morphCol1.xyz;
|
||||
vec3 posDeltaV2 = vec3(morphCol1.zw, morphCol2.x);
|
||||
|
||||
vec3 posDelta = mix(posDeltaV1, posDeltaV2, step(1.0, morphMapFlip));
|
||||
morphPos += posDelta.rgb * g_MorphWeights[1u + morphTarget];
|
||||
|
||||
vec3 normalDeltaV1 = vec3(morphCol1.w, morphCol2.xy);
|
||||
vec3 normalDeltaV2 = morphCol2.yzw;
|
||||
|
||||
vec3 normalDelta = mix(normalDeltaV1, normalDeltaV2, step(1.0, morphMapFlip));
|
||||
morphNormal += normalDelta * g_MorphWeights[1u + morphTarget];
|
||||
#else
|
||||
uint morphMapIndex = (morphMapOffset * 3u) / 4u;
|
||||
float morphMapFlip = CASTF((morphMapOffset * 3u) % 4u);
|
||||
|
||||
uint morphPixel1x = morphMapIndex % CASTU(g_Texture5Resolution.x);
|
||||
uint morphPixel1y = morphMapIndex / CASTU(g_Texture5Resolution.y);
|
||||
uint morphPixel2x = (morphMapIndex + 1u) % CASTU(g_Texture5Resolution.x);
|
||||
uint morphPixel2y = (morphMapIndex + 1u) / CASTU(g_Texture5Resolution.y);
|
||||
|
||||
vec4 morphCol1 = texSample2DLod(g_Texture5, vec2(morphPixel1x, morphPixel1y) * texture5ResolutionInv + offset, 0.0);
|
||||
vec4 morphCol2 = texSample2DLod(g_Texture5, vec2(morphPixel2x, morphPixel2y) * texture5ResolutionInv + offset, 0.0);
|
||||
|
||||
vec3 posDeltaV1 = morphCol1.xyz;
|
||||
vec3 posDeltaV2 = vec3(morphCol1.w, morphCol2.xy);
|
||||
vec3 posDeltaV3 = vec3(morphCol1.zw, morphCol2.x);
|
||||
vec3 posDeltaV4 = morphCol1.yzw;
|
||||
|
||||
vec3 posDelta = mix(posDeltaV1, mix(posDeltaV4, mix(posDeltaV3, posDeltaV2,
|
||||
step(2.5, morphMapFlip)), step(1.5, morphMapFlip)), step(0.5, morphMapFlip));
|
||||
morphPos += posDelta.rgb * g_MorphWeights[1u + morphTarget];
|
||||
#endif
|
||||
}
|
||||
|
||||
localPos += morphPos * g_MorphWeights[0];
|
||||
|
||||
#if MORPHING_NORMALS
|
||||
localNormal = normalize(localNormal + morphNormal * 3.465);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SKINNING
|
||||
localPos = mul(vec4(localPos, 1.0), g_Bones[a_BlendIndices.x] * a_BlendWeights.x +
|
||||
g_Bones[a_BlendIndices.y] * a_BlendWeights.y +
|
||||
g_Bones[a_BlendIndices.z] * a_BlendWeights.z +
|
||||
g_Bones[a_BlendIndices.w] * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
vec4 worldPos = mul(vec4(localPos, 1.0), g_ModelMatrix);
|
||||
gl_Position = mul(worldPos, g_ViewProjectionMatrix);
|
||||
|
||||
#if SKINNING
|
||||
localNormal = mul(localNormal, CAST3X3(g_Bones[a_BlendIndices.x]) * a_BlendWeights.x +
|
||||
CAST3X3(g_Bones[a_BlendIndices.y]) * a_BlendWeights.y +
|
||||
CAST3X3(g_Bones[a_BlendIndices.z]) * a_BlendWeights.z +
|
||||
CAST3X3(g_Bones[a_BlendIndices.w]) * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
vec3 normal = normalize(mul(localNormal, CAST3X3(g_ModelMatrix)));
|
||||
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
v_ViewDir.xyz = g_EyePosition - worldPos.xyz;
|
||||
v_ViewDir.w = worldPos.y;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
v_WorldPos = worldPos.xyz;
|
||||
#if NORMALMAP
|
||||
#if SKINNING
|
||||
vec3 tangent = mul(a_Tangent4.xyz, CAST3X3(g_Bones[a_BlendIndices.x]) * a_BlendWeights.x +
|
||||
CAST3X3(g_Bones[a_BlendIndices.y]) * a_BlendWeights.y +
|
||||
CAST3X3(g_Bones[a_BlendIndices.z]) * a_BlendWeights.z +
|
||||
CAST3X3(g_Bones[a_BlendIndices.w]) * a_BlendWeights.w);
|
||||
#else
|
||||
vec3 tangent = a_Tangent4.xyz;
|
||||
#endif
|
||||
|
||||
mat3 tangentSpace = BuildTangentSpace(CAST3X3(g_ModelMatrix), localNormal, vec4(tangent, a_Tangent4.w));
|
||||
|
||||
v_Tangent = normalize(tangentSpace[0]);
|
||||
v_Bitangent = normalize(tangentSpace[1]);
|
||||
v_Normal = normalize(tangentSpace[2]);
|
||||
#else
|
||||
v_WorldNormal = normal;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if REFLECTION
|
||||
v_ScreenPos = gl_Position.xyw;
|
||||
#ifdef HLSL
|
||||
v_ScreenPos.y = -v_ScreenPos.y;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
v_LightAmbientColor = mix(g_LightSkylightColor, g_LightAmbientColor, dot(normal, vec3(0, 1, 0)) * 0.5 + 0.5);
|
||||
}
|
||||
193
modules/wallpaper-engine/shaders/generic4.frag
Normal file
193
modules/wallpaper-engine/shaders/generic4.frag
Normal file
@@ -0,0 +1,193 @@
|
||||
|
||||
// [COMBO] {"material":"ui_editor_properties_lighting","combo":"LIGHTING","default":1}
|
||||
// [COMBO] {"material":"ui_editor_properties_fog","combo":"FOG","default":1}
|
||||
// [COMBO] {"material":"ui_editor_properties_reflection","combo":"REFLECTION","default":0}
|
||||
// [COMBO] {"material":"ui_editor_properties_rim_lighting","combo":"RIMLIGHTING","default":0,"require":{"LIGHTING":1}}
|
||||
// [COMBO] {"material":"ui_editor_properties_toon_shading","combo":"SHADINGGRADIENT","default":0,"require":{"LIGHTING":1}}
|
||||
// [COMBO] {"material":"ui_editor_properties_tint_mask_in_alpha","combo":"TINTMASKALPHA","default":0}
|
||||
|
||||
#define RIM_LIGHTING_AMOUNT g_RimAmount
|
||||
#define RIM_LIGHTING_EXPONENT g_RimExponent
|
||||
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
|
||||
#if SHADINGGRADIENT
|
||||
#define GRADIENT_SAMPLER g_Texture4
|
||||
uniform sampler2D g_Texture4; // {"label":"ui_editor_properties_shading_gradient","default":"gradient/gradient_toon_smooth","formatcombo":true,"nonremovable":true,"require":{"SHADINGGRADIENT":1}}
|
||||
#endif
|
||||
uniform float g_RimAmount; // {"material":"rimamount","label":"ui_editor_properties_rim_lighting_amount","default":2.0,"range":[0,5],"group":"ui_editor_properties_rim_lighting"}
|
||||
uniform float g_RimExponent; // {"material":"rimexponent","label":"ui_editor_properties_rim_lighting_exponent","default":4.0,"range":[0.01,10],"group":"ui_editor_properties_rim_lighting"}
|
||||
|
||||
#if LIGHTS_SHADOW_MAPPING
|
||||
#define SHADOW_ATLAS_SAMPLER g_Texture6
|
||||
#define SHADOW_ATLAS_TEXEL g_Texture6Texel
|
||||
uniform sampler2DComparison g_Texture6; // {"hidden":true,"default":"_rt_shadowAtlas"}
|
||||
uniform vec4 g_Texture6Texel;
|
||||
#endif
|
||||
|
||||
#if LIGHTS_COOKIE
|
||||
#define COOKIE_SAMPLER g_Texture7
|
||||
uniform sampler2D g_Texture7; // {"hidden":true,"default":"_alias_lightCookie"}
|
||||
#endif
|
||||
|
||||
#include "common_fragment.h"
|
||||
#include "common_pbr_2.h"
|
||||
#include "common_fog.h"
|
||||
|
||||
uniform float g_Brightness; // {"material":"brightness","label":"ui_editor_properties_hdr_brightness","default":1,"range":[0,10]}
|
||||
|
||||
uniform vec3 g_TintColor; // {"material":"color","label":"ui_editor_properties_tint_color","type": "color", "default":"1 1 1"}
|
||||
uniform float g_TintAlpha; // {"material":"alpha","label":"ui_editor_properties_opacity","default":1,"range":[0,1]}
|
||||
|
||||
uniform sampler2D g_Texture0; // {"material":"albedo","label":"ui_editor_properties_albedo","default":"util/white"}
|
||||
uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal_map","format":"normalmap","formatcombo":true,"combo":"NORMALMAP"}
|
||||
uniform sampler2D g_Texture2; // {"combo":"PBRMASKS","components":[{"label":"ui_editor_properties_metallic_map","combo":"METALLIC_MAP"},{"label":"ui_editor_properties_roughness_map","combo":"ROUGHNESS_MAP"},{"label":"ui_editor_properties_reflection_map","combo":"REFLECTION_MAP"},{"label":"ui_editor_properties_emissive_map","combo":"EMISSIVE_MAP"}]}
|
||||
|
||||
uniform float g_Roughness; // {"material":"roughness","label":"ui_editor_properties_roughness","default":0.7,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Metallic; // {"material":"metallic","label":"ui_editor_properties_metallic","default":0,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#ifdef NORMALMAP
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
#else
|
||||
varying vec3 v_WorldNormal;
|
||||
#endif
|
||||
varying vec3 v_WorldPos;
|
||||
#endif
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec3 v_LightAmbientColor;
|
||||
//varying vec4 v_VertexColor;
|
||||
|
||||
#if REFLECTION
|
||||
uniform vec3 g_Screen;
|
||||
uniform sampler2D g_Texture3; // {"hidden":true,"default":"_rt_MipMappedFrameBuffer"}
|
||||
uniform float g_Reflectivity; // {"material":"reflectivity","label":"ui_editor_properties_reflectivity","default":1,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Texture3MipMapInfo;
|
||||
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
uniform vec3 g_EmissiveColor; // {"material":"emissivecolor", "label":"ui_editor_properties_emissive_color", "type": "color", "default":"1 1 1","group":"ui_editor_properties_material"}
|
||||
uniform float g_EmissiveBrightness; // {"material":"emissivebrightness", "label":"ui_editor_properties_emissive_brightness", "default":1.0,"range":[0,10],"group":"ui_editor_properties_material"}
|
||||
|
||||
#require LightingV1
|
||||
|
||||
void main() {
|
||||
vec4 albedo = texSample2D(g_Texture0, v_TexCoord.xy); // * v_VertexColor;
|
||||
|
||||
#if TINTMASKALPHA
|
||||
albedo.rgb = mix(albedo.rgb, CAST3(max(albedo.x, max(albedo.y, albedo.z))) * g_TintColor, albedo.a);
|
||||
albedo.a = 1.0;
|
||||
#else
|
||||
albedo.rgb *= g_TintColor;
|
||||
#endif
|
||||
albedo.a *= g_TintAlpha;
|
||||
|
||||
float metallic = g_Metallic;
|
||||
float roughness = g_Roughness;
|
||||
|
||||
#if PBRMASKS
|
||||
vec4 componentMaps = texSample2D(g_Texture2, v_TexCoord.xy);
|
||||
#endif
|
||||
|
||||
#if METALLIC_MAP
|
||||
metallic = componentMaps.x;
|
||||
#endif
|
||||
|
||||
#if ROUGHNESS_MAP
|
||||
roughness = componentMaps.y;
|
||||
#endif
|
||||
|
||||
vec3 f0 = CAST3(0.04);
|
||||
f0 = mix(f0, albedo.rgb, metallic);
|
||||
|
||||
float viewDist = length(v_ViewDir.xyz);
|
||||
vec3 normalizedViewVector = v_ViewDir.xyz / viewDist;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if NORMALMAP
|
||||
vec3 normal = DecompressNormal(texSample2D(g_Texture1, v_TexCoord.xy));
|
||||
mat3 tangentSpace = mat3(v_Tangent, v_Bitangent, v_Normal);
|
||||
normal = mul(normal, tangentSpace);
|
||||
#else
|
||||
vec3 normal = normalize(v_WorldNormal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec3 light = CAST3(0.0);
|
||||
|
||||
#if LIGHTING
|
||||
light = PerformLighting_V1(v_WorldPos, albedo.rgb, normal, normalizedViewVector, CAST3(1.0), f0, roughness, metallic);
|
||||
vec3 ambient = v_LightAmbientColor * albedo.rgb;
|
||||
#else
|
||||
vec3 ambient = albedo.rgb;
|
||||
#endif
|
||||
|
||||
#if EMISSIVE_MAP
|
||||
light = max(light, g_EmissiveColor * albedo.rgb * (componentMaps.a * g_EmissiveBrightness));
|
||||
#endif
|
||||
|
||||
albedo.rgb = CombineLighting(light, ambient);
|
||||
|
||||
#if REFLECTION
|
||||
float reflectivity = g_Reflectivity;
|
||||
|
||||
#if REFLECTION_MAP
|
||||
reflectivity *= componentMaps.z;
|
||||
#endif
|
||||
vec2 screenUV = (v_ScreenPos.xy / v_ScreenPos.z) * 0.5 + 0.5;
|
||||
|
||||
float fresnelTerm = abs(dot(normal, normalizedViewVector));
|
||||
normal = normalize(mul(normal, CAST3X3(g_ViewProjectionMatrix)));
|
||||
|
||||
#ifdef HLSL
|
||||
normal.y = -normal.y;
|
||||
#endif
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
normal.xy = normal.xy * vec2(0.20 / g_Screen.z, 0.20);
|
||||
#else
|
||||
// Make consistent on X since the width is usually more variable (multi monitors) - bad for phones tho
|
||||
normal.xy = normal.xy * vec2(0.15, 0.15 * g_Screen.z);
|
||||
#endif
|
||||
screenUV += normal.xy * pow(fresnelTerm, 4.0) * 10;
|
||||
float clipReflection = smoothstep(1.3, 1.0, screenUV.x) * smoothstep(-0.3, 0.0, screenUV.x) *
|
||||
smoothstep(1.3, 1.0, screenUV.y) * smoothstep(-0.3, 0.0, screenUV.y);
|
||||
|
||||
vec3 reflectionColor = texSample2DLod(g_Texture3, screenUV, roughness * g_Texture3MipMapInfo).rgb * clipReflection;
|
||||
reflectionColor = reflectionColor * (1.0 - fresnelTerm) * reflectivity;
|
||||
reflectionColor = pow(max(CAST3(0.001), reflectionColor), CAST3(2.0 - metallic));
|
||||
|
||||
albedo.rgb += saturate(reflectionColor);
|
||||
#endif
|
||||
|
||||
#if HDR
|
||||
albedo.rgb *= g_Brightness;
|
||||
|
||||
#if (LIGHTING || REFLECTION) && EMISSIVE_MAP
|
||||
float emissiveOverbright = max(0.0, componentMaps.a * (g_EmissiveBrightness - 1.0));
|
||||
albedo.rgb += g_EmissiveColor * albedo.rgb * emissiveOverbright;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if FOG_HEIGHT || FOG_DIST
|
||||
vec2 fogPixelState = CalculateFogPixelState(viewDist, v_ViewDir.w);
|
||||
albedo.rgb = ApplyFog(albedo.rgb, fogPixelState);
|
||||
#if ADDITIVE
|
||||
albedo.a = ApplyFogAlpha(albedo.a, fogPixelState);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gl_FragColor = albedo;
|
||||
|
||||
#if ALPHATOCOVERAGE
|
||||
gl_FragColor.a = (gl_FragColor.a - 0.5) / max(fwidth(gl_FragColor.a), 0.0001) + 0.5;
|
||||
#if GLSL
|
||||
if (gl_FragColor.a < 0.5) discard;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
175
modules/wallpaper-engine/shaders/generic4.vert
Normal file
175
modules/wallpaper-engine/shaders/generic4.vert
Normal file
@@ -0,0 +1,175 @@
|
||||
|
||||
#include "common_vertex.h"
|
||||
|
||||
uniform mat4 g_ModelMatrix;
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
uniform vec3 g_EyePosition;
|
||||
uniform vec3 g_LightAmbientColor;
|
||||
uniform vec3 g_LightSkylightColor;
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec3 a_Normal;
|
||||
attribute vec2 a_TexCoord;
|
||||
//attribute vec4 a_Color4u;
|
||||
//varying vec4 v_VertexColor;
|
||||
|
||||
#if SKINNING
|
||||
uniform mat4x3 g_Bones[BONECOUNT];
|
||||
|
||||
attribute uvec4 a_BlendIndices;
|
||||
attribute vec4 a_BlendWeights;
|
||||
#endif
|
||||
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec3 v_LightAmbientColor;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if NORMALMAP
|
||||
attribute vec4 a_Tangent4;
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
#else
|
||||
varying vec3 v_WorldNormal;
|
||||
#endif
|
||||
varying vec3 v_WorldPos;
|
||||
#endif
|
||||
|
||||
#if REFLECTION
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
#if MORPHING
|
||||
#if HLSL
|
||||
in uint gl_VertexID;
|
||||
#endif
|
||||
|
||||
uniform sampler2D g_Texture5; // {"material":"morph","hidden":true}
|
||||
uniform vec4 g_Texture5Resolution;
|
||||
|
||||
uniform uint g_MorphOffsets[12];
|
||||
uniform float g_MorphWeights[12];
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec3 localPos = a_Position;
|
||||
vec3 localNormal = a_Normal;
|
||||
|
||||
#if MORPHING
|
||||
vec2 texture5ResolutionInv = 1.0 / g_Texture5Resolution.xy;
|
||||
vec3 morphPos = CAST3(0.0);
|
||||
vec3 morphNormal = CAST3(0.0);
|
||||
for (uint morphTarget = 0u; morphTarget < g_MorphOffsets[0] % 12u; ++morphTarget)
|
||||
{
|
||||
uint morphMapOffset = CASTU(gl_VertexID) + g_MorphOffsets[1u + morphTarget];
|
||||
vec2 offset = 0.5 * texture5ResolutionInv;
|
||||
|
||||
#if MORPHING_NORMALS
|
||||
uint morphMapIndex = (morphMapOffset * 6u) / 4u;
|
||||
float morphMapFlip = CASTF((morphMapOffset * 6u) % 4u);
|
||||
|
||||
uint morphPixel1x = morphMapIndex % CASTU(g_Texture5Resolution.x);
|
||||
uint morphPixel1y = morphMapIndex / CASTU(g_Texture5Resolution.y);
|
||||
uint morphPixel2x = (morphMapIndex + 1u) % CASTU(g_Texture5Resolution.x);
|
||||
uint morphPixel2y = (morphMapIndex + 1u) / CASTU(g_Texture5Resolution.y);
|
||||
|
||||
vec4 morphCol1 = texSample2DLod(g_Texture5, vec2(morphPixel1x, morphPixel1y) * texture5ResolutionInv + offset, 0.0);
|
||||
vec4 morphCol2 = texSample2DLod(g_Texture5, vec2(morphPixel2x, morphPixel2y) * texture5ResolutionInv + offset, 0.0);
|
||||
|
||||
vec3 posDeltaV1 = morphCol1.xyz;
|
||||
vec3 posDeltaV2 = vec3(morphCol1.zw, morphCol2.x);
|
||||
|
||||
vec3 posDelta = mix(posDeltaV1, posDeltaV2, step(1.0, morphMapFlip));
|
||||
morphPos += posDelta.rgb * g_MorphWeights[1u + morphTarget];
|
||||
|
||||
vec3 normalDeltaV1 = vec3(morphCol1.w, morphCol2.xy);
|
||||
vec3 normalDeltaV2 = morphCol2.yzw;
|
||||
|
||||
vec3 normalDelta = mix(normalDeltaV1, normalDeltaV2, step(1.0, morphMapFlip));
|
||||
morphNormal += normalDelta * g_MorphWeights[1u + morphTarget];
|
||||
#else
|
||||
uint morphMapIndex = (morphMapOffset * 3u) / 4u;
|
||||
float morphMapFlip = CASTF((morphMapOffset * 3u) % 4u);
|
||||
|
||||
uint morphPixel1x = morphMapIndex % CASTU(g_Texture5Resolution.x);
|
||||
uint morphPixel1y = morphMapIndex / CASTU(g_Texture5Resolution.y);
|
||||
uint morphPixel2x = (morphMapIndex + 1u) % CASTU(g_Texture5Resolution.x);
|
||||
uint morphPixel2y = (morphMapIndex + 1u) / CASTU(g_Texture5Resolution.y);
|
||||
|
||||
vec4 morphCol1 = texSample2DLod(g_Texture5, vec2(morphPixel1x, morphPixel1y) * texture5ResolutionInv + offset, 0.0);
|
||||
vec4 morphCol2 = texSample2DLod(g_Texture5, vec2(morphPixel2x, morphPixel2y) * texture5ResolutionInv + offset, 0.0);
|
||||
|
||||
vec3 posDeltaV1 = morphCol1.xyz;
|
||||
vec3 posDeltaV2 = vec3(morphCol1.w, morphCol2.xy);
|
||||
vec3 posDeltaV3 = vec3(morphCol1.zw, morphCol2.x);
|
||||
vec3 posDeltaV4 = morphCol1.yzw;
|
||||
|
||||
vec3 posDelta = mix(posDeltaV1, mix(posDeltaV4, mix(posDeltaV3, posDeltaV2,
|
||||
step(2.5, morphMapFlip)), step(1.5, morphMapFlip)), step(0.5, morphMapFlip));
|
||||
morphPos += posDelta.rgb * g_MorphWeights[1u + morphTarget];
|
||||
#endif
|
||||
}
|
||||
|
||||
localPos += morphPos * g_MorphWeights[0];
|
||||
|
||||
#if MORPHING_NORMALS
|
||||
localNormal = normalize(localNormal + morphNormal * 3.465);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SKINNING
|
||||
localPos = mul(vec4(localPos, 1.0), g_Bones[a_BlendIndices.x] * a_BlendWeights.x +
|
||||
g_Bones[a_BlendIndices.y] * a_BlendWeights.y +
|
||||
g_Bones[a_BlendIndices.z] * a_BlendWeights.z +
|
||||
g_Bones[a_BlendIndices.w] * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
vec4 worldPos = mul(vec4(localPos, 1.0), g_ModelMatrix);
|
||||
gl_Position = mul(worldPos, g_ViewProjectionMatrix);
|
||||
|
||||
#if SKINNING
|
||||
localNormal = mul(localNormal, CAST3X3(g_Bones[a_BlendIndices.x]) * a_BlendWeights.x +
|
||||
CAST3X3(g_Bones[a_BlendIndices.y]) * a_BlendWeights.y +
|
||||
CAST3X3(g_Bones[a_BlendIndices.z]) * a_BlendWeights.z +
|
||||
CAST3X3(g_Bones[a_BlendIndices.w]) * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
vec3 normal = normalize(mul(localNormal, CAST3X3(g_ModelMatrix)));
|
||||
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
v_ViewDir.xyz = g_EyePosition - worldPos.xyz;
|
||||
v_ViewDir.w = worldPos.y;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
v_WorldPos = worldPos.xyz;
|
||||
#if NORMALMAP
|
||||
#if SKINNING
|
||||
vec3 tangent = mul(a_Tangent4.xyz, CAST3X3(g_Bones[a_BlendIndices.x]) * a_BlendWeights.x +
|
||||
CAST3X3(g_Bones[a_BlendIndices.y]) * a_BlendWeights.y +
|
||||
CAST3X3(g_Bones[a_BlendIndices.z]) * a_BlendWeights.z +
|
||||
CAST3X3(g_Bones[a_BlendIndices.w]) * a_BlendWeights.w);
|
||||
#else
|
||||
vec3 tangent = a_Tangent4.xyz;
|
||||
#endif
|
||||
|
||||
mat3 tangentSpace = BuildTangentSpace(CAST3X3(g_ModelMatrix), localNormal, vec4(tangent, a_Tangent4.w));
|
||||
|
||||
v_Tangent = normalize(tangentSpace[0]);
|
||||
v_Bitangent = normalize(tangentSpace[1]);
|
||||
v_Normal = normalize(tangentSpace[2]);
|
||||
#else
|
||||
v_WorldNormal = normal;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if REFLECTION
|
||||
v_ScreenPos = gl_Position.xyw;
|
||||
#ifdef HLSL
|
||||
v_ScreenPos.y = -v_ScreenPos.y;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//v_VertexColor = a_Color4u;
|
||||
v_LightAmbientColor = mix(g_LightSkylightColor, g_LightAmbientColor, dot(normal, vec3(0, 1, 0)) * 0.5 + 0.5);
|
||||
}
|
||||
30
modules/wallpaper-engine/shaders/genericimage.frag
Normal file
30
modules/wallpaper-engine/shaders/genericimage.frag
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
#include "common_fragment.h"
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
|
||||
uniform float g_Brightness; // {"material":"Bright","default":1,"range":[0,2]}
|
||||
uniform float g_UserAlpha; // {"material":"Alpha","default":1,"range":[0,1]}
|
||||
uniform float g_Power; // {"material":"Power","default":1,"range":[0,6]}
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
#if MULTI
|
||||
uniform sampler2D g_Texture1;
|
||||
|
||||
varying vec2 v_TexCoord2;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec4 albedo = texSample2D(g_Texture0, v_TexCoord.xy);
|
||||
|
||||
#if MULTI
|
||||
albedo *= texSample2D(g_Texture1, v_TexCoord2.xy);
|
||||
#endif
|
||||
|
||||
albedo.rgb *= g_Brightness;
|
||||
albedo.a *= g_UserAlpha;
|
||||
albedo.rgb = pow(albedo.rgb, CAST3(g_Power));
|
||||
|
||||
gl_FragColor = albedo;
|
||||
}
|
||||
41
modules/wallpaper-engine/shaders/genericimage.vert
Normal file
41
modules/wallpaper-engine/shaders/genericimage.vert
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
#include "common_vertex.h"
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
uniform float g_Time;
|
||||
uniform vec4 g_Texture0Rotation;
|
||||
uniform vec2 g_Texture0Translation;
|
||||
|
||||
uniform float g_ScrollX; // {"material":"Scroll 1 X","default":0,"range":[-2,2]}
|
||||
uniform float g_ScrollY; // {"material":"Scroll 1 Y","default":0,"range":[-2,2]}
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
#if MULTI
|
||||
uniform float g_Scroll2X; // {"material":"Scroll 2 X","default":0,"range":[-2,2]}
|
||||
uniform float g_Scroll2Y; // {"material":"Scroll 2 Y","default":0,"range":[-2,2]}
|
||||
|
||||
varying vec2 v_TexCoord2;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
vec2 scroll = vec2(g_ScrollX, g_ScrollY);
|
||||
scroll = sign(scroll) * pow(vec2(g_ScrollX, g_ScrollY), CAST2(2.0));
|
||||
|
||||
#if SPRITESHEET
|
||||
v_TexCoord = g_Texture0Translation + a_TexCoord.x * g_Texture0Rotation.xy + a_TexCoord.y * g_Texture0Rotation.zw;
|
||||
//v_TexCoord = a_TexCoord;
|
||||
#else
|
||||
v_TexCoord = a_TexCoord + g_Time * scroll;
|
||||
#endif
|
||||
|
||||
#if MULTI
|
||||
vec2 scroll2 = vec2(g_Scroll2X, g_Scroll2Y);
|
||||
scroll2 = sign(scroll2) * pow(vec2(g_Scroll2X, g_Scroll2Y), CAST2(2.0));
|
||||
v_TexCoord2 = a_TexCoord + g_Time * scroll2;
|
||||
#endif
|
||||
}
|
||||
169
modules/wallpaper-engine/shaders/genericimage2.frag
Normal file
169
modules/wallpaper-engine/shaders/genericimage2.frag
Normal file
@@ -0,0 +1,169 @@
|
||||
|
||||
#include "common_pbr.h"
|
||||
#include "common_blending.h"
|
||||
|
||||
uniform sampler2D g_Texture0; // {"label":"ui_editor_properties_albedo","nonremovable":true}
|
||||
|
||||
#ifndef VERSION
|
||||
uniform float g_Brightness; // {"material":"Brightness","label":"ui_editor_properties_brightness","default":1,"range":[0,2]}
|
||||
uniform float g_UserAlpha; // {"material":"Alpha","label":"ui_editor_properties_alpha","default":1,"range":[0,1]}
|
||||
#else
|
||||
uniform vec4 g_Color4;
|
||||
#endif
|
||||
|
||||
#if PBRMASKS
|
||||
varying vec4 v_TexCoord;
|
||||
#else
|
||||
varying vec2 v_TexCoord;
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal_map","combo":"NORMALMAP","format":"rg88","formatcombo":true,"mode":"normal","requireany":true,"require":{"LIGHTING":1,"REFLECTION":1}}
|
||||
uniform sampler2D g_Texture2; // {"combo":"PBRMASKS","mode":"opacitymask","paintdefaultcolor":"0 0 0 1","components":[{"label":"ui_editor_properties_metallic_map","combo":"METALLIC_MAP"},{"label":"ui_editor_properties_roughness_map","combo":"ROUGHNESS_MAP"},{"label":"ui_editor_properties_reflection_map","combo":"REFLECTION_MAP"},{"label":"ui_editor_properties_emissive_map","combo":"EMISSIVE_MAP"}],"requireany":true,"require":{"LIGHTING":1,"REFLECTION":1}}
|
||||
uniform float g_Roughness; // {"material":"roughness","label":"ui_editor_properties_roughness","default":0.5,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Metallic; // {"material":"metallic","label":"ui_editor_properties_metallic","default":0.5,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
|
||||
uniform vec3 g_EmissiveColor; // {"material":"emissivecolor", "label":"ui_editor_properties_emissive_color", "type": "color", "default":"1 1 1","group":"ui_editor_properties_material"}
|
||||
uniform float g_EmissiveBrightness; // {"material":"emissivebrightness", "label":"ui_editor_properties_emissive_brightness", "default":1.0,"range":[0,10],"group":"ui_editor_properties_material"}
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
uniform vec4 g_LightsColorPremultiplied[3];
|
||||
uniform vec3 g_LightAmbientColor;
|
||||
|
||||
varying vec4 v_Light0DirectionL3X;
|
||||
varying vec4 v_Light1DirectionL3Y;
|
||||
varying vec4 v_Light2DirectionL3Z;
|
||||
#endif
|
||||
|
||||
// Local space normal direction and precomputed tangent space in light vectors
|
||||
#if (LIGHTING || REFLECTION) && NORMALMAP == 0
|
||||
// World space normal direction without normal map
|
||||
varying vec3 v_Normal;
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP
|
||||
uniform vec3 g_Screen;
|
||||
uniform sampler2D g_Texture3; // {"hidden":true,"default":"_rt_MipMappedFrameBuffer"}
|
||||
uniform float g_Reflectivity; // {"material":"reflectivity","label":"ui_editor_properties_reflectivity","default":1,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Texture3MipMapInfo;
|
||||
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
#if BLENDMODE
|
||||
uniform sampler2D g_Texture4; // {"hidden":true,"default":"_rt_FullFrameBuffer"}
|
||||
varying vec3 v_ScreenCoord;
|
||||
#endif
|
||||
|
||||
#ifdef SKINNING_ALPHA
|
||||
varying float v_BoneAlpha;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec4 color = texSample2D(g_Texture0, v_TexCoord.xy);
|
||||
|
||||
#ifndef VERSION
|
||||
color.rgb *= g_Brightness;
|
||||
color.a *= g_UserAlpha;
|
||||
#else
|
||||
color *= g_Color4;
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
float metallic = g_Metallic;
|
||||
float roughness = g_Roughness;
|
||||
|
||||
#if PBRMASKS
|
||||
vec4 componentMaps = texSample2D(g_Texture2, v_TexCoord.zw);
|
||||
#endif
|
||||
|
||||
#if METALLIC_MAP
|
||||
metallic = componentMaps.x;
|
||||
#endif
|
||||
|
||||
#if ROUGHNESS_MAP
|
||||
roughness = componentMaps.y;
|
||||
#endif
|
||||
|
||||
#if NORMALMAP
|
||||
vec2 compressedNormal = texSample2D(g_Texture1, v_TexCoord.xy).xy * 2.0 - 1.0;
|
||||
vec3 normal = vec3(compressedNormal,
|
||||
sqrt(saturate(1.0 - compressedNormal.x * compressedNormal.x - compressedNormal.y * compressedNormal.y)));
|
||||
normal = normalize(normal);
|
||||
#else
|
||||
vec3 normal = normalize(v_Normal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
vec3 f0 = CAST3(0.04);
|
||||
f0 = mix(f0, color.rgb, metallic);
|
||||
|
||||
// Using the actual view vector is ugly for ortho rendering
|
||||
vec3 normalizedViewVector = vec3(0, 0, 1); //normalize(v_ViewDir);
|
||||
|
||||
vec3 light = ComputePBRLight(normal, v_Light0DirectionL3X.xyz, normalizedViewVector, color.rgb, g_LightsColorPremultiplied[0].rgb, f0, roughness, metallic);
|
||||
light += ComputePBRLight(normal, v_Light1DirectionL3Y.xyz, normalizedViewVector, color.rgb, g_LightsColorPremultiplied[1].rgb, f0, roughness, metallic);
|
||||
light += ComputePBRLight(normal, v_Light2DirectionL3Z.xyz, normalizedViewVector, color.rgb, g_LightsColorPremultiplied[2].rgb, f0, roughness, metallic);
|
||||
light += ComputePBRLight(normal, vec3(v_Light0DirectionL3X.w, v_Light1DirectionL3Y.w, v_Light2DirectionL3Z.w),
|
||||
normalizedViewVector, color.rgb,
|
||||
vec3(g_LightsColorPremultiplied[0].w, g_LightsColorPremultiplied[1].w, g_LightsColorPremultiplied[2].w),
|
||||
f0, roughness, metallic);
|
||||
vec3 ambient = max(CAST3(0.001), g_LightAmbientColor) * color.rgb;
|
||||
|
||||
#if EMISSIVE_MAP
|
||||
light = max(light, g_EmissiveColor * color.rgb * (componentMaps.a * g_EmissiveBrightness));
|
||||
#endif
|
||||
|
||||
color.rgb = CombineLighting(light, ambient);
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP
|
||||
float reflectivity = g_Reflectivity;
|
||||
|
||||
#if REFLECTION_MAP
|
||||
reflectivity *= componentMaps.z;
|
||||
#endif
|
||||
|
||||
vec2 tangent = normalize(v_Tangent.xy);
|
||||
vec2 bitangent = normalize(v_Bitangent.xy);
|
||||
vec2 screenUV = (v_ScreenPos.xy / v_ScreenPos.z) * 0.5 + 0.5;
|
||||
|
||||
float fresnelTerm = max(0.001, dot(normal, vec3(0, 0, 1)));
|
||||
#if PLATFORM_ANDROID
|
||||
normal.xy = normalize(normal.xy) * vec2(0.25 / g_Screen.z, 0.25);
|
||||
#else
|
||||
// Make consistent on X since the width is usually more variable (multi monitors) - bad for phones tho
|
||||
normal.xy = normalize(normal.xy) * vec2(0.15, 0.15 * g_Screen.z);
|
||||
#endif
|
||||
screenUV += (tangent * normal.x + bitangent * normal.y) * fresnelTerm;
|
||||
|
||||
vec3 reflectionColor = texSample2DLod(g_Texture3, screenUV, roughness * g_Texture3MipMapInfo).rgb;
|
||||
reflectionColor = reflectionColor * (1.0 - fresnelTerm) * reflectivity;
|
||||
reflectionColor = pow(max(CAST3(0.001), reflectionColor), CAST3(2.0 - metallic));
|
||||
|
||||
color.rgb += saturate(reflectionColor);
|
||||
#endif
|
||||
|
||||
#if HDR && EMISSIVE_MAP
|
||||
float emissiveOverbright = max(0.0, componentMaps.a * (g_EmissiveBrightness - 1.0));
|
||||
color.rgb += g_EmissiveColor * color.rgb * emissiveOverbright;
|
||||
#endif
|
||||
|
||||
#ifdef SKINNING_ALPHA
|
||||
color.a *= v_BoneAlpha;
|
||||
#endif
|
||||
|
||||
gl_FragColor = color;
|
||||
|
||||
#if BLENDMODE
|
||||
vec2 screenCoord = v_ScreenCoord.xy / v_ScreenCoord.z * vec2(0.5, 0.5) + 0.5;
|
||||
vec4 screen = texSample2D(g_Texture4, screenCoord);
|
||||
|
||||
gl_FragColor.rgb = ApplyBlending(BLENDMODE, screen.rgb, gl_FragColor.rgb, gl_FragColor.a);
|
||||
gl_FragColor.a = screen.a;
|
||||
#endif
|
||||
}
|
||||
186
modules/wallpaper-engine/shaders/genericimage2.vert
Normal file
186
modules/wallpaper-engine/shaders/genericimage2.vert
Normal file
@@ -0,0 +1,186 @@
|
||||
|
||||
// [COMBO] {"material":"ui_editor_properties_lighting","combo":"LIGHTING","default":0}
|
||||
// [COMBO] {"material":"ui_editor_properties_reflection","combo":"REFLECTION","default":0}
|
||||
|
||||
#include "common_vertex.h"
|
||||
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
uniform vec4 g_Texture0Rotation;
|
||||
uniform vec2 g_Texture0Translation;
|
||||
|
||||
#if SKINNING
|
||||
uniform mat4x3 g_Bones[BONECOUNT];
|
||||
#endif
|
||||
|
||||
attribute vec3 a_Position;
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
#if SKINNING
|
||||
attribute uvec4 a_BlendIndices;
|
||||
attribute vec4 a_BlendWeights;
|
||||
#endif
|
||||
|
||||
#if PBRMASKS
|
||||
uniform vec4 g_Texture2Resolution;
|
||||
varying vec4 v_TexCoord;
|
||||
#else
|
||||
varying vec2 v_TexCoord;
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
uniform vec3 g_EyePosition;
|
||||
|
||||
uniform mat4 g_ModelMatrix;
|
||||
uniform mat3 g_NormalModelMatrix;
|
||||
|
||||
uniform mat4 g_AltModelMatrix;
|
||||
uniform mat3 g_AltNormalModelMatrix;
|
||||
uniform mat4 g_AltViewProjectionMatrix;
|
||||
|
||||
#if PRELIGHTING
|
||||
#define M_MDL g_AltModelMatrix
|
||||
#define M_NML g_AltNormalModelMatrix
|
||||
#define M_VP g_AltViewProjectionMatrix
|
||||
#define M_MVP mul(g_AltModelMatrix, g_AltViewProjectionMatrix)
|
||||
#else
|
||||
#define M_MDL g_ModelMatrix
|
||||
#define M_NML g_NormalModelMatrix
|
||||
#define M_VP g_ViewProjectionMatrix
|
||||
#define M_MVP g_ModelViewProjectionMatrix
|
||||
#endif
|
||||
#else
|
||||
#define M_MVP g_ModelViewProjectionMatrix
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
uniform vec3 g_LightsPosition[4];
|
||||
|
||||
varying vec4 v_Light0DirectionL3X;
|
||||
varying vec4 v_Light1DirectionL3Y;
|
||||
varying vec4 v_Light2DirectionL3Z;
|
||||
#endif
|
||||
|
||||
#if (LIGHTING || REFLECTION) && NORMALMAP == 0
|
||||
varying vec3 v_Normal;
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
#if BLENDMODE
|
||||
varying vec3 v_ScreenCoord;
|
||||
#endif
|
||||
|
||||
#ifdef SKINNING_ALPHA
|
||||
uniform float g_BonesAlpha[BONECOUNT];
|
||||
varying float v_BoneAlpha;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
|
||||
#if SKINNING
|
||||
vec3 localPos = mul(vec4(a_Position, 1.0), g_Bones[a_BlendIndices.x] * a_BlendWeights.x +
|
||||
g_Bones[a_BlendIndices.y] * a_BlendWeights.y +
|
||||
g_Bones[a_BlendIndices.z] * a_BlendWeights.z +
|
||||
g_Bones[a_BlendIndices.w] * a_BlendWeights.w);
|
||||
#else
|
||||
vec3 localPos = a_Position;
|
||||
#endif
|
||||
|
||||
#if SKINNING_ALPHA
|
||||
v_BoneAlpha = saturate(g_BonesAlpha[a_BlendIndices.x] * a_BlendWeights.x +
|
||||
g_BonesAlpha[a_BlendIndices.y] * a_BlendWeights.y +
|
||||
g_BonesAlpha[a_BlendIndices.z] * a_BlendWeights.z +
|
||||
g_BonesAlpha[a_BlendIndices.w] * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
#if SPRITESHEET
|
||||
v_TexCoord.xy = g_Texture0Translation + a_TexCoord.x * g_Texture0Rotation.xy + a_TexCoord.y * g_Texture0Rotation.zw;
|
||||
#else
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
#endif
|
||||
|
||||
#if PBRMASKS
|
||||
v_TexCoord.zw = vec2(a_TexCoord.x * g_Texture2Resolution.z / g_Texture2Resolution.x,
|
||||
a_TexCoord.y * g_Texture2Resolution.w / g_Texture2Resolution.y);
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
// Compute normal and tangent space for lighting and/or reflection later
|
||||
vec3 normal = vec3(0, 0, 1.0);
|
||||
vec3 tangent = vec3(1.0, 0, 0);
|
||||
vec4 worldPos = mul(vec4(localPos, 1.0), M_MDL);
|
||||
|
||||
#if SKINNING
|
||||
normal = mul(normal, CAST3X3(g_Bones[a_BlendIndices.x]) * a_BlendWeights.x +
|
||||
CAST3X3(g_Bones[a_BlendIndices.y]) * a_BlendWeights.y +
|
||||
CAST3X3(g_Bones[a_BlendIndices.z]) * a_BlendWeights.z +
|
||||
CAST3X3(g_Bones[a_BlendIndices.w]) * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
#if NORMALMAP
|
||||
|
||||
#if SKINNING
|
||||
tangent = mul(tangent, CAST3X3(g_Bones[a_BlendIndices.x]) * a_BlendWeights.x +
|
||||
CAST3X3(g_Bones[a_BlendIndices.y]) * a_BlendWeights.y +
|
||||
CAST3X3(g_Bones[a_BlendIndices.z]) * a_BlendWeights.z +
|
||||
CAST3X3(g_Bones[a_BlendIndices.w]) * a_BlendWeights.w);
|
||||
#endif
|
||||
mat3 tangentSpace = BuildTangentSpace(M_NML, normal, vec4(tangent, 1.0));
|
||||
#if REFLECTION
|
||||
v_Tangent = tangentSpace[0];
|
||||
v_Bitangent = tangentSpace[1];
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Prepare lighting data
|
||||
#if LIGHTING
|
||||
v_Light0DirectionL3X.xyz = g_LightsPosition[0] - worldPos.xyz;
|
||||
v_Light1DirectionL3Y.xyz = g_LightsPosition[1] - worldPos.xyz;
|
||||
v_Light2DirectionL3Z.xyz = g_LightsPosition[2] - worldPos.xyz;
|
||||
vec3 l3 = g_LightsPosition[3] - worldPos.xyz;
|
||||
|
||||
gl_Position = mul(worldPos, M_VP);
|
||||
|
||||
#if NORMALMAP
|
||||
v_Light0DirectionL3X.xyz = mul(tangentSpace, v_Light0DirectionL3X.xyz);
|
||||
v_Light1DirectionL3Y.xyz = mul(tangentSpace, v_Light1DirectionL3Y.xyz);
|
||||
v_Light2DirectionL3Z.xyz = mul(tangentSpace, v_Light2DirectionL3Z.xyz);
|
||||
l3 = mul(tangentSpace, l3);
|
||||
#else
|
||||
v_Normal = normalize(mul(normal, M_NML));
|
||||
#endif
|
||||
|
||||
v_Light0DirectionL3X.w = l3.x;
|
||||
v_Light1DirectionL3Y.w = l3.y;
|
||||
v_Light2DirectionL3Z.w = l3.z;
|
||||
|
||||
#else
|
||||
gl_Position = mul(vec4(localPos, 1.0), M_MVP);
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP
|
||||
v_ScreenPos = gl_Position.xyw;
|
||||
#ifdef HLSL
|
||||
v_ScreenPos.y = -v_ScreenPos.y;
|
||||
v_Tangent.y = -v_Tangent.y;
|
||||
v_Bitangent.y = -v_Bitangent.y;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if PRELIGHTING
|
||||
gl_Position = mul(vec4(a_Position, 1.0), g_ModelViewProjectionMatrix);
|
||||
#endif
|
||||
|
||||
#if BLENDMODE
|
||||
v_ScreenCoord = gl_Position.xyw;
|
||||
#ifdef HLSL
|
||||
v_ScreenCoord.y = -v_ScreenCoord.y;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
297
modules/wallpaper-engine/shaders/genericimage3.frag
Normal file
297
modules/wallpaper-engine/shaders/genericimage3.frag
Normal file
@@ -0,0 +1,297 @@
|
||||
|
||||
// [COMBO] {"material":"ui_editor_properties_lighting","combo":"LIGHTING","default":0}
|
||||
// [COMBO] {"material":"ui_editor_properties_reflection","combo":"REFLECTION","default":0}
|
||||
|
||||
#include "common_pbr.h"
|
||||
#include "common_blending.h"
|
||||
|
||||
uniform sampler2D g_Texture0; // {"label":"ui_editor_properties_albedo","nonremovable":true}
|
||||
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
uniform vec4 g_Color4;
|
||||
|
||||
#if VERTEXCOLOR
|
||||
varying vec4 v_Color;
|
||||
#endif
|
||||
|
||||
#if PBRMASKS
|
||||
varying vec4 v_TexCoord;
|
||||
#else
|
||||
varying vec2 v_TexCoord;
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal_map","combo":"NORMALMAP","format":"rg88","formatcombo":true,"mode":"normal","requireany":true,"require":{"LIGHTING":1,"REFLECTION":1}}
|
||||
uniform sampler2D g_Texture2; // {"combo":"PBRMASKS","mode":"opacitymask","paintdefaultcolor":"0 0 0 1","components":[{"label":"ui_editor_properties_metallic_map","combo":"METALLIC_MAP"},{"label":"ui_editor_properties_roughness_map","combo":"ROUGHNESS_MAP"},{"label":"ui_editor_properties_reflection_map","combo":"REFLECTION_MAP"},{"label":"ui_editor_properties_emissive_map","combo":"EMISSIVE_MAP"}],"requireany":true,"require":{"LIGHTING":1,"REFLECTION":1}}
|
||||
uniform float g_Roughness; // {"material":"roughness","label":"ui_editor_properties_roughness","default":0.7,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Metallic; // {"material":"metallic","label":"ui_editor_properties_metallic","default":0,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform vec3 g_SpecularTint; // {"material":"speculartint","label":"ui_editor_properties_specular_tint","type":"color","default":"1 1 1","group":"ui_editor_properties_material"}
|
||||
|
||||
uniform vec3 g_EmissiveColor; // {"material":"emissivecolor", "label":"ui_editor_properties_emissive_color", "type": "color", "default":"1 1 1","group":"ui_editor_properties_material"}
|
||||
uniform float g_EmissiveBrightness; // {"material":"emissivebrightness", "label":"ui_editor_properties_emissive_brightness", "default":1.0,"range":[0,10],"group":"ui_editor_properties_material"}
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
uniform vec3 g_LightAmbientColor;
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
varying vec3 v_WorldPos;
|
||||
#if NORMALMAP == 0
|
||||
varying vec3 v_WorldNormal;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP
|
||||
uniform vec3 g_Screen;
|
||||
uniform sampler2D g_Texture3; // {"hidden":true,"default":"_rt_MipMappedFrameBuffer"}
|
||||
uniform float g_Reflectivity; // {"material":"reflectivity","label":"ui_editor_properties_reflectivity","default":1,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Texture3MipMapInfo;
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP || BLENDMODE
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
#if BLENDMODE
|
||||
uniform sampler2D g_Texture4; // {"hidden":true,"default":"_rt_FullFrameBuffer"}
|
||||
#endif
|
||||
|
||||
#if MORPHING || SKINNING_ALPHA
|
||||
varying float v_VertexAlpha;
|
||||
#endif
|
||||
|
||||
#if LIGHTS_POINT
|
||||
uniform vec4 g_LPoint_Color[LIGHTS_POINT];
|
||||
uniform vec4 g_LPoint_Origin[LIGHTS_POINT];
|
||||
#endif
|
||||
#if LIGHTS_SPOT
|
||||
uniform vec4 g_LSpot_Color[LIGHTS_SPOT];
|
||||
uniform vec4 g_LSpot_Origin[LIGHTS_SPOT];
|
||||
uniform vec4 g_LSpot_Direction[LIGHTS_SPOT];
|
||||
#endif
|
||||
#if LIGHTS_TUBE
|
||||
uniform vec4 g_LTube_Color[LIGHTS_TUBE];
|
||||
uniform vec4 g_LTube_OriginA[LIGHTS_TUBE];
|
||||
uniform vec4 g_LTube_OriginB[LIGHTS_TUBE];
|
||||
#endif
|
||||
#if LIGHTS_DIRECTIONAL
|
||||
uniform vec4 g_LDirectional_Color[LIGHTS_DIRECTIONAL];
|
||||
uniform vec4 g_LDirectional_Direction[LIGHTS_DIRECTIONAL];
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
#if SHADERVERSION < 62
|
||||
// DEPRECATION BSSSSS
|
||||
vec3 PerformLighting_Deprecated(vec3 worldPos, vec3 color, vec3 normal, vec3 viewVector, vec3 specularTint, vec3 ambient, float roughness, float metallic)
|
||||
{
|
||||
vec3 light = CAST3(0);
|
||||
|
||||
#if LIGHTS_POINT
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_POINT); ++l)
|
||||
{
|
||||
vec3 lightDelta = g_LPoint_Origin[l].xyz - worldPos;
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LPoint_Color[l].rgb, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_SPOT
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_SPOT); ++l)
|
||||
{
|
||||
vec3 lightDelta = g_LSpot_Origin[l].xyz - worldPos;
|
||||
float spotCookie = -dot(normalize(lightDelta), g_LSpot_Direction[l].xyz);
|
||||
spotCookie = smoothstep(g_LSpot_Direction[l].w, g_LSpot_Origin[l].w, spotCookie);
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LSpot_Color[l].rgb, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_TUBE
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_TUBE); ++l)
|
||||
{
|
||||
vec3 lightDelta = PointSegmentDelta(worldPos, g_LTube_OriginA[l].xyz, g_LTube_OriginB[l].xyz);
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LTube_Color[l].rgb, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_DIRECTIONAL
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_DIRECTIONAL); ++l)
|
||||
{
|
||||
light += ComputePBRLight(normal, g_LDirectional_Direction[l].xyz, viewVector, color, g_LDirectional_Color[l].rgb, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
vec3 PerformLighting_Deprecated(vec3 worldPos, vec3 color, vec3 normal, vec3 viewVector, vec3 specularTint, vec3 ambient, float roughness, float metallic)
|
||||
{
|
||||
vec3 light = CAST3(0);
|
||||
|
||||
#if LIGHTS_POINT
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_POINT); ++l)
|
||||
{
|
||||
vec3 lightDelta = g_LPoint_Origin[l].xyz - worldPos;
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LPoint_Color[l].rgb * g_LPoint_Color[l].w * g_LPoint_Color[l].w, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_SPOT
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_SPOT); ++l)
|
||||
{
|
||||
vec3 lightDelta = g_LSpot_Origin[l].xyz - worldPos;
|
||||
float spotCookie = -dot(normalize(lightDelta), g_LSpot_Direction[l].xyz);
|
||||
spotCookie = smoothstep(g_LSpot_Direction[l].w, g_LSpot_Origin[l].w, spotCookie);
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LSpot_Color[l].rgb * spotCookie * g_LSpot_Color[l].w * g_LSpot_Color[l].w, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_TUBE
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_TUBE); ++l)
|
||||
{
|
||||
vec3 lightDelta = PointSegmentDelta(worldPos, g_LTube_OriginA[l].xyz, g_LTube_OriginB[l].xyz);
|
||||
light += ComputePBRLight(normal, lightDelta, viewVector, color, g_LTube_Color[l].rgb * g_LTube_Color[l].w * g_LTube_Color[l].w, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIGHTS_DIRECTIONAL
|
||||
for (uint l = 0u; l < CASTU(LIGHTS_DIRECTIONAL); ++l)
|
||||
{
|
||||
light += ComputePBRLight(normal, g_LDirectional_Direction[l].xyz, viewVector, color, g_LDirectional_Color[l].rgb * g_LDirectional_Color[l].w * g_LDirectional_Color[l].w, ambient, roughness, metallic);
|
||||
}
|
||||
#endif
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec4 color = texSample2D(g_Texture0, v_TexCoord.xy) * g_Color4;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
float metallic = g_Metallic;
|
||||
float roughness = g_Roughness;
|
||||
|
||||
#if PBRMASKS
|
||||
vec4 componentMaps = texSample2D(g_Texture2, v_TexCoord.zw);
|
||||
#endif
|
||||
|
||||
#if METALLIC_MAP
|
||||
metallic = componentMaps.x;
|
||||
#endif
|
||||
|
||||
#if ROUGHNESS_MAP
|
||||
roughness = componentMaps.y;
|
||||
#endif
|
||||
|
||||
#if NORMALMAP
|
||||
vec2 compressedNormal = texSample2D(g_Texture1, v_TexCoord.xy).xy * 2.0 - 1.0;
|
||||
vec3 normal = vec3(compressedNormal,
|
||||
sqrt(saturate(1.0 - compressedNormal.x * compressedNormal.x - compressedNormal.y * compressedNormal.y)));
|
||||
normal = normalize(normal);
|
||||
#else
|
||||
vec3 normal = normalize(v_WorldNormal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if SCENE_ORTHO
|
||||
// View vector should be static on puppets on 2D wallpapers
|
||||
vec3 normalizedViewVector = vec3(0, 0, 1);
|
||||
#else
|
||||
vec3 normalizedViewVector = normalize(v_ViewDir.xyz);
|
||||
#endif
|
||||
|
||||
#if NORMALMAP
|
||||
mat3 tangentSpace = mat3(v_Tangent, v_Bitangent, v_Normal);
|
||||
normal = mul(normal, tangentSpace);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
vec3 f0 = CAST3(0.04);
|
||||
f0 = mix(f0, color.rgb, metallic);
|
||||
|
||||
vec3 light = PerformLighting_Deprecated(v_WorldPos, color.rgb, normal, normalizedViewVector, g_SpecularTint, f0, roughness, metallic);
|
||||
vec3 ambient = g_LightAmbientColor * color.rgb;
|
||||
|
||||
#if EMISSIVE_MAP
|
||||
light = max(light, g_EmissiveColor * color.rgb * (componentMaps.a * g_EmissiveBrightness));
|
||||
#endif
|
||||
|
||||
color.rgb = CombineLighting(light, ambient);
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP || BLENDMODE
|
||||
vec2 screenUV = (v_ScreenPos.xy / v_ScreenPos.z) * 0.5 + 0.5;
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP
|
||||
float reflectivity = g_Reflectivity;
|
||||
|
||||
#if REFLECTION_MAP
|
||||
reflectivity *= componentMaps.z;
|
||||
#endif
|
||||
|
||||
vec2 tangent = normalize(v_Tangent.xy);
|
||||
vec2 bitangent = normalize(v_Bitangent.xy);
|
||||
|
||||
float fresnelTerm = max(0.001, dot(normal, normalizedViewVector));
|
||||
normal = normalize(mul(normal, CAST3X3(g_ViewProjectionMatrix)));
|
||||
|
||||
#ifdef HLSL
|
||||
normal.y = -normal.y;
|
||||
#endif
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
normal.xy = normal.xy * vec2(0.25 / g_Screen.z, 0.25);
|
||||
#else
|
||||
// Make consistent on X since the width is usually more variable (multi monitors) - bad for phones tho
|
||||
normal.xy = normal.xy * vec2(0.15, 0.15 * g_Screen.z);
|
||||
#endif
|
||||
//screenUV += normal * fresnelTerm;
|
||||
screenUV += normal.xy * pow(fresnelTerm, 4.0) * 4;
|
||||
|
||||
vec3 reflectionColor = texSample2DLod(g_Texture3, screenUV, roughness * g_Texture3MipMapInfo).rgb;
|
||||
reflectionColor = reflectionColor * (1.0 - fresnelTerm) * reflectivity;
|
||||
reflectionColor = pow(max(CAST3(0.001), reflectionColor), CAST3(2.0 - metallic));
|
||||
|
||||
color.rgb += saturate(reflectionColor) * fresnelTerm;
|
||||
//color.rgb = mix(color.rgb, vec3(screenUV, 0), 0.99);
|
||||
#endif
|
||||
|
||||
#if HDR && (LIGHTING || REFLECTION) && EMISSIVE_MAP
|
||||
float emissiveOverbright = max(0.0, componentMaps.a * (g_EmissiveBrightness - 1.0));
|
||||
color.rgb += g_EmissiveColor * color.rgb * emissiveOverbright;
|
||||
#endif
|
||||
|
||||
#if MORPHING || SKINNING_ALPHA
|
||||
color.a *= v_VertexAlpha;
|
||||
#endif
|
||||
|
||||
#if VERTEXCOLOR
|
||||
color *= v_Color;
|
||||
#endif
|
||||
|
||||
gl_FragColor = color;
|
||||
|
||||
#if BLENDMODE
|
||||
vec4 screen = texSample2D(g_Texture4, screenUV);
|
||||
gl_FragColor.rgb = ApplyBlending(BLENDMODE, screen.rgb, gl_FragColor.rgb, gl_FragColor.a);
|
||||
gl_FragColor.a = screen.a;
|
||||
#endif
|
||||
|
||||
#if ALPHATOCOVERAGE
|
||||
gl_FragColor.a = (gl_FragColor.a - 0.5) / max(fwidth(gl_FragColor.a), 0.0001) + 0.5;
|
||||
#if GLSL
|
||||
if (gl_FragColor.a < 0.5) discard;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
230
modules/wallpaper-engine/shaders/genericimage3.vert
Normal file
230
modules/wallpaper-engine/shaders/genericimage3.vert
Normal file
@@ -0,0 +1,230 @@
|
||||
|
||||
#include "common_vertex.h"
|
||||
|
||||
uniform mat4 g_ModelMatrix;
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
uniform vec4 g_Texture0Rotation;
|
||||
uniform vec2 g_Texture0Translation;
|
||||
|
||||
#if SKINNING
|
||||
uniform mat4x3 g_Bones[BONECOUNT];
|
||||
#endif
|
||||
|
||||
#if MORPHING
|
||||
attribute vec4 a_PositionVec4;
|
||||
#else
|
||||
attribute vec3 a_Position;
|
||||
#endif
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
#if VERTEXCOLOR
|
||||
attribute vec4 a_Color;
|
||||
varying vec4 v_Color;
|
||||
#endif
|
||||
|
||||
#if SKINNING
|
||||
attribute vec3 a_Normal;
|
||||
#if NORMALMAP
|
||||
attribute vec4 a_Tangent4;
|
||||
#endif
|
||||
attribute uvec4 a_BlendIndices;
|
||||
attribute vec4 a_BlendWeights;
|
||||
#endif
|
||||
|
||||
#if PBRMASKS
|
||||
uniform vec4 g_Texture2Resolution;
|
||||
varying vec4 v_TexCoord;
|
||||
#else
|
||||
varying vec2 v_TexCoord;
|
||||
#endif
|
||||
|
||||
uniform vec3 g_EyePosition;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
uniform mat3 g_NormalModelMatrix;
|
||||
|
||||
uniform mat4 g_AltModelMatrix;
|
||||
uniform mat3 g_AltNormalModelMatrix;
|
||||
uniform mat4 g_AltViewProjectionMatrix;
|
||||
|
||||
#if PRELIGHTING
|
||||
#define M_MDL g_AltModelMatrix
|
||||
#define M_NML g_AltNormalModelMatrix
|
||||
#define M_VP g_AltViewProjectionMatrix
|
||||
#define M_MVP mul(g_AltModelMatrix, g_AltViewProjectionMatrix)
|
||||
#else
|
||||
#define M_MDL g_ModelMatrix
|
||||
#define M_NML g_NormalModelMatrix
|
||||
#define M_VP g_ViewProjectionMatrix
|
||||
#define M_MVP g_ModelViewProjectionMatrix
|
||||
#endif
|
||||
#else
|
||||
#define M_MVP g_ModelViewProjectionMatrix
|
||||
#define M_MDL g_ModelMatrix
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
varying vec3 v_WorldPos;
|
||||
#if NORMALMAP == 0
|
||||
varying vec3 v_WorldNormal;
|
||||
#endif
|
||||
#elif FOG_COMPUTED && (FOG_DIST || FOG_HEIGHT)
|
||||
varying vec4 v_ViewDir;
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP || BLENDMODE
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
#ifdef SKINNING_ALPHA
|
||||
uniform float g_BonesAlpha[BONECOUNT];
|
||||
#endif
|
||||
|
||||
#if MORPHING
|
||||
uniform sampler2D g_Texture5; // {"hidden":true}
|
||||
uniform vec4 g_Texture5Resolution;
|
||||
|
||||
uniform uint g_MorphOffsets[12];
|
||||
uniform float g_MorphWeights[12];
|
||||
#endif
|
||||
|
||||
#if MORPHING || SKINNING_ALPHA
|
||||
varying float v_VertexAlpha;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#if MORPHING
|
||||
vec3 position = a_PositionVec4.xyz;
|
||||
#else
|
||||
vec3 position = a_Position.xyz;
|
||||
#endif
|
||||
|
||||
#if MORPHING || SKINNING_ALPHA
|
||||
v_VertexAlpha = 1.0;
|
||||
#endif
|
||||
|
||||
vec3 localPos = position;
|
||||
|
||||
#if MORPHING
|
||||
vec2 texture5ResolutionInv = 1.0 / g_Texture5Resolution.xy;
|
||||
vec3 morphPos = CAST3(0.0);
|
||||
for (uint morphTarget = 0u; morphTarget < g_MorphOffsets[0] % 12u && a_PositionVec4.w > 0.0; ++morphTarget)
|
||||
{
|
||||
uint morphMapIndex = CASTU(a_PositionVec4.w) + g_MorphOffsets[1u + morphTarget];
|
||||
vec2 offset = 0.5 * texture5ResolutionInv;
|
||||
|
||||
uint morphPixelx = morphMapIndex % CASTU(g_Texture5Resolution.x);
|
||||
uint morphPixely = morphMapIndex / CASTU(g_Texture5Resolution.y);
|
||||
|
||||
vec4 morphCol = texSample2DLod(g_Texture5, vec2(morphPixelx, morphPixely) * texture5ResolutionInv + offset, 0.0);
|
||||
|
||||
morphPos += morphCol.xyz * g_MorphWeights[1u + morphTarget];
|
||||
#if PRELIGHTING == 0
|
||||
v_VertexAlpha *= morphCol.w * g_MorphWeights[1u + morphTarget] + 1.0 * (1.0 - g_MorphWeights[1u + morphTarget]);
|
||||
#endif
|
||||
}
|
||||
|
||||
localPos += morphPos * g_MorphWeights[0];
|
||||
#endif
|
||||
|
||||
#if SKINNING
|
||||
localPos = mul(vec4(localPos, 1.0), g_Bones[a_BlendIndices.x] * a_BlendWeights.x +
|
||||
g_Bones[a_BlendIndices.y] * a_BlendWeights.y +
|
||||
g_Bones[a_BlendIndices.z] * a_BlendWeights.z +
|
||||
g_Bones[a_BlendIndices.w] * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
#if SKINNING_ALPHA
|
||||
v_VertexAlpha *= saturate(g_BonesAlpha[a_BlendIndices.x] * a_BlendWeights.x +
|
||||
g_BonesAlpha[a_BlendIndices.y] * a_BlendWeights.y +
|
||||
g_BonesAlpha[a_BlendIndices.z] * a_BlendWeights.z +
|
||||
g_BonesAlpha[a_BlendIndices.w] * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
#if SPRITESHEET
|
||||
v_TexCoord.xy = g_Texture0Translation + a_TexCoord.x * g_Texture0Rotation.xy + a_TexCoord.y * g_Texture0Rotation.zw;
|
||||
#else
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
#endif
|
||||
|
||||
#if PBRMASKS
|
||||
v_TexCoord.zw = vec2(a_TexCoord.x * g_Texture2Resolution.z / g_Texture2Resolution.x,
|
||||
a_TexCoord.y * g_Texture2Resolution.w / g_Texture2Resolution.y);
|
||||
#endif
|
||||
|
||||
vec4 worldPos = mul(vec4(localPos, 1.0), M_MDL);
|
||||
vec3 viewDir = g_EyePosition - worldPos.xyz;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
vec3 normal = vec3(0, 0, 1.0);
|
||||
|
||||
#if SKINNING
|
||||
normal = mul(a_Normal, CAST3X3(g_Bones[a_BlendIndices.x]) * a_BlendWeights.x +
|
||||
CAST3X3(g_Bones[a_BlendIndices.y]) * a_BlendWeights.y +
|
||||
CAST3X3(g_Bones[a_BlendIndices.z]) * a_BlendWeights.z +
|
||||
CAST3X3(g_Bones[a_BlendIndices.w]) * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
#if NORMALMAP
|
||||
vec4 tangent = vec4(1, 0, 0, 1);
|
||||
|
||||
#if SKINNING
|
||||
tangent.w = a_Tangent4.w;
|
||||
tangent.xyz = mul(a_Tangent4.xyz, CAST3X3(g_Bones[a_BlendIndices.x]) * a_BlendWeights.x +
|
||||
CAST3X3(g_Bones[a_BlendIndices.y]) * a_BlendWeights.y +
|
||||
CAST3X3(g_Bones[a_BlendIndices.z]) * a_BlendWeights.z +
|
||||
CAST3X3(g_Bones[a_BlendIndices.w]) * a_BlendWeights.w);
|
||||
#endif
|
||||
mat3 tangentSpace = BuildTangentSpace(M_NML, normal, tangent);
|
||||
|
||||
v_Tangent = normalize(tangentSpace[0]);
|
||||
v_Bitangent = normalize(tangentSpace[1]);
|
||||
v_Normal = normalize(tangentSpace[2]);
|
||||
v_WorldPos = worldPos.xyz;
|
||||
#else
|
||||
|
||||
v_WorldPos = worldPos.xyz;
|
||||
#if SKINNING
|
||||
v_WorldNormal = mul(a_Normal, M_NML);
|
||||
#else
|
||||
v_WorldNormal = mul(vec3(0, 0, 1), M_NML);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
v_ViewDir.xyz = viewDir;
|
||||
v_ViewDir.w = 0.0;
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
gl_Position = mul(worldPos, M_VP);
|
||||
#else
|
||||
gl_Position = mul(vec4(localPos, 1.0), M_MVP);
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP || BLENDMODE
|
||||
v_ScreenPos = gl_Position.xyw;
|
||||
#ifdef HLSL
|
||||
v_ScreenPos.y = -v_ScreenPos.y;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if PRELIGHTING
|
||||
gl_Position = mul(vec4(position, 1.0), g_ModelViewProjectionMatrix);
|
||||
#endif
|
||||
|
||||
#if VERTEXCOLOR
|
||||
v_Color = a_Color;
|
||||
#endif
|
||||
|
||||
#if FOG_COMPUTED && (FOG_DIST || FOG_HEIGHT)
|
||||
v_ViewDir = vec4(viewDir, worldPos.y);
|
||||
#endif
|
||||
}
|
||||
215
modules/wallpaper-engine/shaders/genericimage4.frag
Normal file
215
modules/wallpaper-engine/shaders/genericimage4.frag
Normal file
@@ -0,0 +1,215 @@
|
||||
|
||||
// [COMBO] {"material":"ui_editor_properties_lighting","combo":"LIGHTING","default":0}
|
||||
// [COMBO] {"material":"ui_editor_properties_reflection","combo":"REFLECTION","default":0}
|
||||
// [COMBO] {"material":"ui_editor_properties_fog","combo":"FOG","default":1}
|
||||
|
||||
#if LIGHTS_SHADOW_MAPPING
|
||||
#define SHADOW_ATLAS_SAMPLER g_Texture6
|
||||
#define SHADOW_ATLAS_TEXEL g_Texture6Texel
|
||||
uniform sampler2DComparison g_Texture6; // {"hidden":true,"default":"_rt_shadowAtlas"}
|
||||
uniform vec4 g_Texture6Texel;
|
||||
#endif
|
||||
|
||||
#if LIGHTS_COOKIE
|
||||
#define COOKIE_SAMPLER g_Texture7
|
||||
uniform sampler2D g_Texture7; // {"hidden":true,"default":"_alias_lightCookie"}
|
||||
#endif
|
||||
|
||||
#include "common_pbr_2.h"
|
||||
#include "common_blending.h"
|
||||
#include "common_fog.h"
|
||||
|
||||
uniform sampler2D g_Texture0; // {"label":"ui_editor_properties_albedo","nonremovable":true}
|
||||
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
uniform vec4 g_Color4;
|
||||
|
||||
#if VERTEXCOLOR
|
||||
varying vec4 v_Color;
|
||||
#endif
|
||||
|
||||
#if PBRMASKS
|
||||
varying vec4 v_TexCoord;
|
||||
#else
|
||||
varying vec2 v_TexCoord;
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal_map","combo":"NORMALMAP","format":"rg88","formatcombo":true,"mode":"normal","requireany":true,"require":{"LIGHTING":1,"REFLECTION":1}}
|
||||
uniform sampler2D g_Texture2; // {"combo":"PBRMASKS","mode":"opacitymask","paintdefaultcolor":"0 0 0 1","components":[{"label":"ui_editor_properties_metallic_map","combo":"METALLIC_MAP"},{"label":"ui_editor_properties_roughness_map","combo":"ROUGHNESS_MAP"},{"label":"ui_editor_properties_reflection_map","combo":"REFLECTION_MAP"},{"label":"ui_editor_properties_emissive_map","combo":"EMISSIVE_MAP"}],"requireany":true,"require":{"LIGHTING":1,"REFLECTION":1}}
|
||||
uniform float g_Roughness; // {"material":"roughness","label":"ui_editor_properties_roughness","default":0.7,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Metallic; // {"material":"metallic","label":"ui_editor_properties_metallic","default":0,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform vec3 g_SpecularTint; // {"material":"speculartint","label":"ui_editor_properties_specular_tint","type":"color","default":"1 1 1","group":"ui_editor_properties_material"}
|
||||
|
||||
uniform vec3 g_EmissiveColor; // {"material":"emissivecolor", "label":"ui_editor_properties_emissive_color", "type": "color", "default":"1 1 1","group":"ui_editor_properties_material"}
|
||||
uniform float g_EmissiveBrightness; // {"material":"emissivebrightness", "label":"ui_editor_properties_emissive_brightness", "default":1.0,"range":[0,10],"group":"ui_editor_properties_material"}
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
uniform vec3 g_LightAmbientColor;
|
||||
//uniform vec3 g_AmbientLowPass; // {"material":"ambientlowpass", "label":"ui_editor_properties_ambient", "type": "color", "default":"0 0 0","group":"ui_editor_properties_material"}
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
varying vec3 v_WorldPos;
|
||||
#if NORMALMAP == 0
|
||||
varying vec3 v_WorldNormal;
|
||||
#endif
|
||||
#elif FOG_COMPUTED && (FOG_HEIGHT || FOG_DIST)
|
||||
varying vec4 v_ViewDir;
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP
|
||||
uniform vec3 g_Screen;
|
||||
uniform sampler2D g_Texture3; // {"hidden":true,"default":"_rt_MipMappedFrameBuffer"}
|
||||
uniform float g_Reflectivity; // {"material":"reflectivity","label":"ui_editor_properties_reflectivity","default":1,"range":[0,1],"group":"ui_editor_properties_material","nobindings":true}
|
||||
uniform float g_Texture3MipMapInfo;
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP || BLENDMODE
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
#if BLENDMODE
|
||||
uniform sampler2D g_Texture4; // {"hidden":true,"default":"_rt_FullFrameBuffer"}
|
||||
#endif
|
||||
|
||||
#if MORPHING || SKINNING_ALPHA
|
||||
varying float v_VertexAlpha;
|
||||
#endif
|
||||
|
||||
#require LightingV1
|
||||
|
||||
void main() {
|
||||
vec4 color = texSample2D(g_Texture0, v_TexCoord.xy) * g_Color4;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
float metallic = g_Metallic;
|
||||
float roughness = g_Roughness;
|
||||
|
||||
#if PBRMASKS
|
||||
vec4 componentMaps = texSample2D(g_Texture2, v_TexCoord.zw);
|
||||
#endif
|
||||
|
||||
#if METALLIC_MAP
|
||||
metallic = componentMaps.x;
|
||||
#endif
|
||||
|
||||
#if ROUGHNESS_MAP
|
||||
roughness = componentMaps.y;
|
||||
#endif
|
||||
|
||||
#if NORMALMAP
|
||||
vec2 compressedNormal = texSample2D(g_Texture1, v_TexCoord.xy).xy * 2.0 - 1.0;
|
||||
vec3 normal = vec3(compressedNormal,
|
||||
sqrt(saturate(1.0 - compressedNormal.x * compressedNormal.x - compressedNormal.y * compressedNormal.y)));
|
||||
normal = normalize(normal);
|
||||
#else
|
||||
vec3 normal = normalize(v_WorldNormal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
#if SCENE_ORTHO
|
||||
// View vector should be static on puppets on 2D wallpapers
|
||||
vec3 normalizedViewVector = vec3(0, 0, 1);
|
||||
#else
|
||||
vec3 normalizedViewVector = normalize(v_ViewDir.xyz);
|
||||
#endif
|
||||
|
||||
#if NORMALMAP
|
||||
mat3 tangentSpace = mat3(v_Tangent, v_Bitangent, v_Normal);
|
||||
normal = mul(normal, tangentSpace);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
vec3 f0 = CAST3(0.04);
|
||||
f0 = mix(f0, color.rgb, metallic);
|
||||
|
||||
vec3 light = PerformLighting_V1(v_WorldPos, color.rgb, normal, normalizedViewVector, g_SpecularTint, f0, roughness, metallic);
|
||||
vec3 ambient = g_LightAmbientColor * color.rgb;
|
||||
|
||||
#if EMISSIVE_MAP
|
||||
light = max(light, g_EmissiveColor * color.rgb * (componentMaps.a * g_EmissiveBrightness));
|
||||
#endif
|
||||
|
||||
//color.rgb = CombineLighting(light, color.rgb * g_AmbientLowPass, ambient);
|
||||
color.rgb = CombineLighting(light, ambient);
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP || BLENDMODE
|
||||
vec2 screenUV = (v_ScreenPos.xy / v_ScreenPos.z) * 0.5 + 0.5;
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP
|
||||
float reflectivity = g_Reflectivity;
|
||||
|
||||
#if REFLECTION_MAP
|
||||
reflectivity *= componentMaps.z;
|
||||
#endif
|
||||
|
||||
vec2 tangent = normalize(v_Tangent.xy);
|
||||
vec2 bitangent = normalize(v_Bitangent.xy);
|
||||
|
||||
float fresnelTerm = max(0.001, dot(normal, normalizedViewVector));
|
||||
normal = normalize(mul(normal, CAST3X3(g_ViewProjectionMatrix)));
|
||||
|
||||
#ifdef HLSL
|
||||
normal.y = -normal.y;
|
||||
#endif
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
normal.xy = normal.xy * vec2(0.25 / g_Screen.z, 0.25);
|
||||
#else
|
||||
// Make consistent on X since the width is usually more variable (multi monitors) - bad for phones tho
|
||||
normal.xy = normal.xy * vec2(0.15, 0.15 * g_Screen.z);
|
||||
#endif
|
||||
//screenUV += normal * fresnelTerm;
|
||||
screenUV += normal.xy * pow(fresnelTerm, 4.0) * 4;
|
||||
|
||||
vec3 reflectionColor = texSample2DLod(g_Texture3, screenUV, roughness * g_Texture3MipMapInfo).rgb;
|
||||
reflectionColor = reflectionColor * (1.0 - fresnelTerm) * reflectivity;
|
||||
reflectionColor = pow(max(CAST3(0.001), reflectionColor), CAST3(2.0 - metallic));
|
||||
|
||||
color.rgb += saturate(reflectionColor) * fresnelTerm;
|
||||
//color.rgb = mix(color.rgb, vec3(screenUV, 0), 0.99);
|
||||
#endif
|
||||
|
||||
#if HDR && (LIGHTING || REFLECTION) && EMISSIVE_MAP
|
||||
float emissiveOverbright = max(0.0, componentMaps.a * (g_EmissiveBrightness - 1.0));
|
||||
color.rgb += g_EmissiveColor * color.rgb * emissiveOverbright;
|
||||
#endif
|
||||
|
||||
#if MORPHING || SKINNING_ALPHA
|
||||
color.a *= v_VertexAlpha;
|
||||
#endif
|
||||
|
||||
#if VERTEXCOLOR
|
||||
color *= v_Color;
|
||||
#endif
|
||||
|
||||
gl_FragColor = color;
|
||||
|
||||
#if BLENDMODE
|
||||
vec4 screen = texSample2D(g_Texture4, screenUV);
|
||||
gl_FragColor.rgb = ApplyBlending(BLENDMODE, screen.rgb, gl_FragColor.rgb, gl_FragColor.a);
|
||||
gl_FragColor.a = screen.a;
|
||||
#endif
|
||||
|
||||
#if FOG_COMPUTED && (FOG_HEIGHT || FOG_DIST)
|
||||
vec2 fogPixelState = CalculateFogPixelState(length(v_ViewDir.xyz), v_ViewDir.w);
|
||||
gl_FragColor.rgb = ApplyFog(gl_FragColor.rgb, fogPixelState);
|
||||
#endif
|
||||
|
||||
#if ALPHATOCOVERAGE
|
||||
gl_FragColor.a = (gl_FragColor.a - 0.5) / max(fwidth(gl_FragColor.a), 0.0001) + 0.5;
|
||||
#if GLSL
|
||||
if (gl_FragColor.a < 0.5) discard;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
237
modules/wallpaper-engine/shaders/genericimage4.vert
Normal file
237
modules/wallpaper-engine/shaders/genericimage4.vert
Normal file
@@ -0,0 +1,237 @@
|
||||
|
||||
#include "common_vertex.h"
|
||||
|
||||
uniform mat4 g_ModelMatrix;
|
||||
uniform mat4 g_ModelViewProjectionMatrix;
|
||||
uniform vec4 g_Texture0Rotation;
|
||||
uniform vec2 g_Texture0Translation;
|
||||
|
||||
#if SKINNING
|
||||
uniform mat4x3 g_Bones[BONECOUNT];
|
||||
#endif
|
||||
|
||||
#if MORPHING
|
||||
attribute vec4 a_PositionVec4;
|
||||
#else
|
||||
attribute vec3 a_Position;
|
||||
#endif
|
||||
attribute vec2 a_TexCoord;
|
||||
|
||||
#if PRELIGHTINGDUALVERTEX
|
||||
attribute vec3 a_PositionC1;
|
||||
#endif
|
||||
|
||||
#if VERTEXCOLOR
|
||||
attribute vec4 a_Color;
|
||||
varying vec4 v_Color;
|
||||
#endif
|
||||
|
||||
#if SKINNING
|
||||
attribute vec3 a_Normal;
|
||||
#if NORMALMAP
|
||||
attribute vec4 a_Tangent4;
|
||||
#endif
|
||||
attribute uvec4 a_BlendIndices;
|
||||
attribute vec4 a_BlendWeights;
|
||||
#endif
|
||||
|
||||
#if PBRMASKS
|
||||
uniform vec4 g_Texture2Resolution;
|
||||
varying vec4 v_TexCoord;
|
||||
#else
|
||||
varying vec2 v_TexCoord;
|
||||
#endif
|
||||
|
||||
uniform vec3 g_EyePosition;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
uniform mat3 g_NormalModelMatrix;
|
||||
|
||||
uniform mat4 g_AltModelMatrix;
|
||||
uniform mat3 g_AltNormalModelMatrix;
|
||||
uniform mat4 g_AltViewProjectionMatrix;
|
||||
|
||||
#if PRELIGHTING
|
||||
#define M_MDL g_AltModelMatrix
|
||||
#define M_NML g_AltNormalModelMatrix
|
||||
#define M_VP g_AltViewProjectionMatrix
|
||||
#define M_MVP mul(g_AltModelMatrix, g_AltViewProjectionMatrix)
|
||||
#else
|
||||
#define M_MDL g_ModelMatrix
|
||||
#define M_NML g_NormalModelMatrix
|
||||
#define M_VP g_ViewProjectionMatrix
|
||||
#define M_MVP g_ModelViewProjectionMatrix
|
||||
#endif
|
||||
#else
|
||||
#define M_MVP g_ModelViewProjectionMatrix
|
||||
#define M_MDL g_ModelMatrix
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
#endif
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
varying vec4 v_ViewDir;
|
||||
varying vec3 v_Normal;
|
||||
varying vec3 v_Tangent;
|
||||
varying vec3 v_Bitangent;
|
||||
varying vec3 v_WorldPos;
|
||||
#if NORMALMAP == 0
|
||||
varying vec3 v_WorldNormal;
|
||||
#endif
|
||||
#elif FOG_COMPUTED && (FOG_DIST || FOG_HEIGHT)
|
||||
varying vec4 v_ViewDir;
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP || BLENDMODE
|
||||
varying vec3 v_ScreenPos;
|
||||
#endif
|
||||
|
||||
#ifdef SKINNING_ALPHA
|
||||
uniform float g_BonesAlpha[BONECOUNT];
|
||||
#endif
|
||||
|
||||
#if MORPHING
|
||||
uniform sampler2D g_Texture5; // {"hidden":true}
|
||||
uniform vec4 g_Texture5Resolution;
|
||||
|
||||
uniform uint g_MorphOffsets[12];
|
||||
uniform float g_MorphWeights[12];
|
||||
#endif
|
||||
|
||||
#if MORPHING || SKINNING_ALPHA
|
||||
varying float v_VertexAlpha;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#if MORPHING
|
||||
vec3 position = a_PositionVec4.xyz;
|
||||
#else
|
||||
vec3 position = a_Position.xyz;
|
||||
#endif
|
||||
|
||||
#if MORPHING || SKINNING_ALPHA
|
||||
v_VertexAlpha = 1.0;
|
||||
#endif
|
||||
|
||||
vec3 localPos = position;
|
||||
|
||||
#if MORPHING
|
||||
vec2 texture5ResolutionInv = 1.0 / g_Texture5Resolution.xy;
|
||||
vec3 morphPos = CAST3(0.0);
|
||||
for (uint morphTarget = 0u; morphTarget < g_MorphOffsets[0] % 12u && a_PositionVec4.w > 0.0; ++morphTarget)
|
||||
{
|
||||
uint morphMapIndex = CASTU(a_PositionVec4.w) + g_MorphOffsets[1u + morphTarget];
|
||||
vec2 offset = 0.5 * texture5ResolutionInv;
|
||||
|
||||
uint morphPixelx = morphMapIndex % CASTU(g_Texture5Resolution.x);
|
||||
uint morphPixely = morphMapIndex / CASTU(g_Texture5Resolution.y);
|
||||
|
||||
vec4 morphCol = texSample2DLod(g_Texture5, vec2(morphPixelx, morphPixely) * texture5ResolutionInv + offset, 0.0);
|
||||
|
||||
morphPos += morphCol.xyz * g_MorphWeights[1u + morphTarget];
|
||||
#if PRELIGHTING == 0
|
||||
v_VertexAlpha *= morphCol.w * g_MorphWeights[1u + morphTarget] + 1.0 * (1.0 - g_MorphWeights[1u + morphTarget]);
|
||||
#endif
|
||||
}
|
||||
|
||||
localPos += morphPos * g_MorphWeights[0];
|
||||
#endif
|
||||
|
||||
#if SKINNING
|
||||
localPos = mul(vec4(localPos, 1.0), g_Bones[a_BlendIndices.x] * a_BlendWeights.x +
|
||||
g_Bones[a_BlendIndices.y] * a_BlendWeights.y +
|
||||
g_Bones[a_BlendIndices.z] * a_BlendWeights.z +
|
||||
g_Bones[a_BlendIndices.w] * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
#if SKINNING_ALPHA
|
||||
v_VertexAlpha *= saturate(g_BonesAlpha[a_BlendIndices.x] * a_BlendWeights.x +
|
||||
g_BonesAlpha[a_BlendIndices.y] * a_BlendWeights.y +
|
||||
g_BonesAlpha[a_BlendIndices.z] * a_BlendWeights.z +
|
||||
g_BonesAlpha[a_BlendIndices.w] * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
#if SPRITESHEET
|
||||
v_TexCoord.xy = g_Texture0Translation + a_TexCoord.x * g_Texture0Rotation.xy + a_TexCoord.y * g_Texture0Rotation.zw;
|
||||
#else
|
||||
v_TexCoord.xy = a_TexCoord;
|
||||
#endif
|
||||
|
||||
#if PBRMASKS
|
||||
v_TexCoord.zw = vec2(a_TexCoord.x * g_Texture2Resolution.z / g_Texture2Resolution.x,
|
||||
a_TexCoord.y * g_Texture2Resolution.w / g_Texture2Resolution.y);
|
||||
#endif
|
||||
|
||||
vec4 worldPos = mul(vec4(localPos, 1.0), M_MDL);
|
||||
vec3 viewDir = g_EyePosition - worldPos.xyz;
|
||||
|
||||
#if LIGHTING || REFLECTION
|
||||
vec3 normal = vec3(0, 0, 1.0);
|
||||
|
||||
#if SKINNING
|
||||
normal = mul(a_Normal, CAST3X3(g_Bones[a_BlendIndices.x]) * a_BlendWeights.x +
|
||||
CAST3X3(g_Bones[a_BlendIndices.y]) * a_BlendWeights.y +
|
||||
CAST3X3(g_Bones[a_BlendIndices.z]) * a_BlendWeights.z +
|
||||
CAST3X3(g_Bones[a_BlendIndices.w]) * a_BlendWeights.w);
|
||||
#endif
|
||||
|
||||
#if NORMALMAP
|
||||
vec4 tangent = vec4(1, 0, 0, 1);
|
||||
|
||||
#if SKINNING
|
||||
tangent.w = a_Tangent4.w;
|
||||
tangent.xyz = mul(a_Tangent4.xyz, CAST3X3(g_Bones[a_BlendIndices.x]) * a_BlendWeights.x +
|
||||
CAST3X3(g_Bones[a_BlendIndices.y]) * a_BlendWeights.y +
|
||||
CAST3X3(g_Bones[a_BlendIndices.z]) * a_BlendWeights.z +
|
||||
CAST3X3(g_Bones[a_BlendIndices.w]) * a_BlendWeights.w);
|
||||
#endif
|
||||
mat3 tangentSpace = BuildTangentSpace(M_NML, normal, tangent);
|
||||
|
||||
v_Tangent = normalize(tangentSpace[0]);
|
||||
v_Bitangent = normalize(tangentSpace[1]);
|
||||
v_Normal = normalize(tangentSpace[2]);
|
||||
v_WorldPos = worldPos.xyz;
|
||||
#else
|
||||
|
||||
v_WorldPos = worldPos.xyz;
|
||||
#if SKINNING
|
||||
v_WorldNormal = mul(a_Normal, M_NML);
|
||||
#else
|
||||
v_WorldNormal = mul(vec3(0, 0, 1), M_NML);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
v_ViewDir.xyz = viewDir;
|
||||
v_ViewDir.w = 0.0;
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
gl_Position = mul(worldPos, M_VP);
|
||||
#else
|
||||
gl_Position = mul(vec4(localPos, 1.0), M_MVP);
|
||||
#endif
|
||||
|
||||
#if REFLECTION && NORMALMAP || BLENDMODE
|
||||
v_ScreenPos = gl_Position.xyw;
|
||||
#ifdef HLSL
|
||||
v_ScreenPos.y = -v_ScreenPos.y;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if PRELIGHTING
|
||||
#if PRELIGHTINGDUALVERTEX
|
||||
position = a_PositionC1;
|
||||
#endif
|
||||
gl_Position = mul(vec4(position, 1.0), g_ModelViewProjectionMatrix);
|
||||
#endif
|
||||
|
||||
#if VERTEXCOLOR
|
||||
v_Color = a_Color;
|
||||
#endif
|
||||
|
||||
#if FOG_COMPUTED && (FOG_DIST || FOG_HEIGHT)
|
||||
v_ViewDir = vec4(viewDir, worldPos.y);
|
||||
#endif
|
||||
}
|
||||
77
modules/wallpaper-engine/shaders/genericparticle.frag
Normal file
77
modules/wallpaper-engine/shaders/genericparticle.frag
Normal file
@@ -0,0 +1,77 @@
|
||||
|
||||
// [COMBO] {"material":"ui_editor_properties_fog","combo":"FOG","default":1}
|
||||
// [COMBO] {"material":"ui_editor_properties_refract","combo":"REFRACT","type":"options","default":0}
|
||||
|
||||
#include "common_fragment.h"
|
||||
#include "common_fog.h"
|
||||
|
||||
uniform sampler2D g_Texture0; // {"label":"ui_editor_properties_albedo","default":"util/white"}
|
||||
|
||||
uniform float g_Overbright; // {"material":"ui_editor_properties_overbright","default":1.0,"range":[0,5]}
|
||||
|
||||
#if REFRACT
|
||||
uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal","format":"normalmap","formatcombo":true,"default":"util/flatnormal"}
|
||||
uniform sampler2D g_Texture2; // {"default":"_rt_FullFrameBuffer","hidden":true}
|
||||
#endif
|
||||
|
||||
#if SPRITESHEET
|
||||
varying vec4 v_TexCoord;
|
||||
varying float v_TexCoordBlend;
|
||||
#else
|
||||
varying vec2 v_TexCoord;
|
||||
#endif
|
||||
|
||||
varying vec4 v_Color;
|
||||
|
||||
#if REFRACT
|
||||
varying vec3 v_ScreenCoord;
|
||||
varying vec4 v_ScreenTangents;
|
||||
#endif
|
||||
|
||||
#if FOG_DIST || FOG_HEIGHT
|
||||
varying vec4 v_ViewDir;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#if SPRITESHEET
|
||||
#if SPRITESHEETBLEND
|
||||
// This is wrong because it can sample colors that are invisible on one frame but changing this can negatively impact additive particles
|
||||
vec4 color = v_Color * mix(ConvertTexture0Format(texSample2D(g_Texture0, v_TexCoord.xy)),
|
||||
ConvertTexture0Format(texSample2D(g_Texture0, v_TexCoord.zw)),
|
||||
v_TexCoordBlend);
|
||||
#else
|
||||
vec4 color = v_Color * ConvertTexture0Format(texSample2D(g_Texture0, v_TexCoord.xy));
|
||||
#endif
|
||||
#else
|
||||
vec4 color = v_Color * ConvertTexture0Format(texSample2D(g_Texture0, v_TexCoord.xy));
|
||||
#endif
|
||||
|
||||
#if REFRACT
|
||||
vec4 normal = DecompressNormalWithMask(texSample2D(g_Texture1, v_TexCoord.xy));
|
||||
//normal = vec4((v_TexCoord.xy - 0.5) * 2, 0, 1);
|
||||
vec2 screenRefractionOffset = v_ScreenTangents.xy * normal.x + v_ScreenTangents.zw * normal.y;
|
||||
#ifndef HLSL
|
||||
screenRefractionOffset.y = -screenRefractionOffset.y;
|
||||
#endif
|
||||
vec2 refractTexCoord = v_ScreenCoord.xy / v_ScreenCoord.z * vec2(0.5, 0.5) + 0.5 + screenRefractionOffset * normal.a * v_Color.a;
|
||||
|
||||
color.rgb *= texSample2D(g_Texture2, refractTexCoord).rgb;
|
||||
#endif
|
||||
|
||||
color.rgb *= g_Overbright;
|
||||
|
||||
#if FOG_HEIGHT || FOG_DIST
|
||||
vec2 fogPixelState = CalculateFogPixelState(length(v_ViewDir.xyz), v_ViewDir.w);
|
||||
color.rgb = ApplyFog(color.rgb, fogPixelState);
|
||||
color.a = ApplyFogAlpha(color.a, fogPixelState);
|
||||
#endif
|
||||
|
||||
gl_FragColor = color;
|
||||
|
||||
#if ALPHATOCOVERAGE
|
||||
gl_FragColor.a = (gl_FragColor.a - 0.5) / max(fwidth(gl_FragColor.a), 0.0001) + 0.5;
|
||||
#if GLSL
|
||||
if (gl_FragColor.a < 0.5) discard;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
92
modules/wallpaper-engine/shaders/genericparticle.geom
Normal file
92
modules/wallpaper-engine/shaders/genericparticle.geom
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
#include "common_particles.h"
|
||||
|
||||
in vec3 v_Rotation;
|
||||
in vec4 v_Color;
|
||||
in vec4 gl_Position;
|
||||
|
||||
#if THICKFORMAT
|
||||
in vec4 v_VelocityLifetime;
|
||||
#endif
|
||||
|
||||
#if SPRITESHEET
|
||||
out vec4 v_TexCoord;
|
||||
out float v_TexCoordBlend;
|
||||
#else
|
||||
out vec2 v_TexCoord;
|
||||
#endif
|
||||
|
||||
#if REFRACT
|
||||
out vec3 v_ScreenCoord;
|
||||
out vec4 v_ScreenTangents;
|
||||
#endif
|
||||
|
||||
out vec4 v_Color;
|
||||
out vec4 gl_Position;
|
||||
|
||||
#if FOG_DIST || FOG_HEIGHT
|
||||
uniform mat4 g_ModelMatrix;
|
||||
out vec4 v_ViewDir;
|
||||
#endif
|
||||
|
||||
#if SPRITESHEET
|
||||
PS_INPUT CreateParticleVertex(vec2 sprite, float blend, mat3 mRotation, vec4 uvs, float textureRatio, in VS_OUTPUT IN, vec3 right, vec3 up)
|
||||
#else
|
||||
PS_INPUT CreateParticleVertex(vec2 sprite, float blend, mat3 mRotation, vec2 uvs, float textureRatio, in VS_OUTPUT IN, vec3 right, vec3 up)
|
||||
#endif
|
||||
{
|
||||
PS_INPUT v;
|
||||
|
||||
vec3 position = ComputeParticlePosition(sprite, textureRatio, IN.gl_Position, right, up);
|
||||
|
||||
v.gl_Position = mul(vec4(position, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord = uvs;
|
||||
v.v_Color = IN.v_Color;
|
||||
|
||||
#if SPRITESHEET
|
||||
v.v_TexCoordBlend = blend;
|
||||
#endif
|
||||
|
||||
#if REFRACT
|
||||
ComputeScreenRefractionTangents(v.gl_Position.xyw, mRotation, v.v_ScreenCoord, v.v_ScreenTangents);
|
||||
#endif
|
||||
|
||||
#if FOG_DIST || FOG_HEIGHT
|
||||
vec3 worldPos = mul(vec4(position, 1.0), g_ModelMatrix).xyz;
|
||||
v.v_ViewDir.xyz = g_EyePosition - worldPos.xyz;
|
||||
v.v_ViewDir.w = worldPos.y;
|
||||
#endif
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
[maxvertexcount(4)]
|
||||
void main() {
|
||||
|
||||
vec3 uvOffsets = vec3(1, 1, 0);
|
||||
float spriteBlend = 0.0;
|
||||
|
||||
#if SPRITESHEET
|
||||
float textureRatio = g_RenderVar1.w;
|
||||
vec4 uvs;
|
||||
ComputeSpriteFrame(IN[0].v_VelocityLifetime.w, uvs, uvOffsets.xy, spriteBlend);
|
||||
#else
|
||||
vec2 uvs = vec2(0, 0);
|
||||
float textureRatio = g_Texture0Resolution.y / g_Texture0Resolution.x;
|
||||
#endif
|
||||
|
||||
// Compute tangent vectors
|
||||
vec3 right, up;
|
||||
mat3 mRotation;
|
||||
#if TRAILRENDERER
|
||||
mRotation = CAST3X3(1.0);
|
||||
ComputeParticleTrailTangents(IN[0].gl_Position, IN[0].v_VelocityLifetime.xyz, right, up);
|
||||
#else
|
||||
ComputeParticleTangents(IN[0].v_Rotation, mRotation, right, up);
|
||||
#endif
|
||||
|
||||
OUT.Append(CreateParticleVertex(vec2(0, 0), spriteBlend, mRotation, uvs, textureRatio, IN[0], right, up));
|
||||
OUT.Append(CreateParticleVertex(vec2(0, 1), spriteBlend, mRotation, uvs + uvOffsets.zyzy, textureRatio, IN[0], right, up));
|
||||
OUT.Append(CreateParticleVertex(vec2(1, 0), spriteBlend, mRotation, uvs + uvOffsets.xzxz, textureRatio, IN[0], right, up));
|
||||
OUT.Append(CreateParticleVertex(vec2(1, 1), spriteBlend, mRotation, uvs + uvOffsets.xyxy, textureRatio, IN[0], right, up));
|
||||
}
|
||||
112
modules/wallpaper-engine/shaders/genericparticle.vert
Normal file
112
modules/wallpaper-engine/shaders/genericparticle.vert
Normal file
@@ -0,0 +1,112 @@
|
||||
|
||||
#include "common_particles.h"
|
||||
|
||||
// Declare dynamic attributes for all combinations
|
||||
attribute vec3 a_Position;
|
||||
attribute vec4 a_TexCoordVec4;
|
||||
attribute vec4 a_Color;
|
||||
varying vec4 v_Color;
|
||||
|
||||
#if THICKFORMAT
|
||||
attribute vec4 a_TexCoordVec4C1;
|
||||
#endif
|
||||
|
||||
#if GS_ENABLED || HLSL_GS40
|
||||
|
||||
varying vec3 v_Rotation;
|
||||
|
||||
#if THICKFORMAT
|
||||
varying vec4 v_VelocityLifetime;
|
||||
#endif // THICKFORMAT
|
||||
|
||||
#else // No geometry shaders
|
||||
|
||||
attribute vec2 a_TexCoordC2;
|
||||
|
||||
#if SPRITESHEET
|
||||
varying vec4 v_TexCoord;
|
||||
varying float v_TexCoordBlend;
|
||||
#else
|
||||
varying vec2 v_TexCoord;
|
||||
#endif // SPRITESHEET
|
||||
|
||||
#if REFRACT
|
||||
varying vec3 v_ScreenCoord;
|
||||
varying vec4 v_ScreenTangents;
|
||||
#endif // REFRACT
|
||||
|
||||
#if FOG_DIST || FOG_HEIGHT
|
||||
uniform mat4 g_ModelMatrix;
|
||||
varying vec4 v_ViewDir;
|
||||
#endif
|
||||
|
||||
#endif // GS_ENABLED
|
||||
|
||||
void main() {
|
||||
|
||||
// Prepare input layout
|
||||
#if GS_ENABLED || HLSL_GS40
|
||||
#define in_ParticleRotation (a_TexCoordVec4.xyz)
|
||||
#else
|
||||
#define in_ParticleRotation vec3(a_TexCoordC2.xy, a_TexCoordVec4.z)
|
||||
#endif
|
||||
|
||||
#define in_ParticleSize (a_TexCoordVec4.w)
|
||||
#define in_ParticleVelocity (a_TexCoordVec4C1.xyz)
|
||||
#define in_ParticleLifeTime (a_TexCoordVec4C1.w)
|
||||
|
||||
#if SPRITESHEET
|
||||
float textureRatio = g_RenderVar1.w;
|
||||
#else
|
||||
float textureRatio = g_Texture0Resolution.y / g_Texture0Resolution.x;
|
||||
#endif
|
||||
|
||||
// Prepare geometry shader input
|
||||
// or compute final vertex position
|
||||
#if GS_ENABLED || HLSL_GS40
|
||||
|
||||
#if THICKFORMAT
|
||||
v_VelocityLifetime = vec4(in_ParticleVelocity, frac(in_ParticleLifeTime));
|
||||
#endif
|
||||
v_Rotation = in_ParticleRotation;
|
||||
gl_Position = vec4(a_Position, in_ParticleSize);
|
||||
|
||||
#else // No geometry shaders
|
||||
|
||||
vec3 right, up;
|
||||
mat3 mRotation;
|
||||
#if TRAILRENDERER
|
||||
mRotation = CAST3X3(1.0);
|
||||
ComputeParticleTrailTangents(a_Position, in_ParticleVelocity, right, up);
|
||||
#else
|
||||
ComputeParticleTangents(in_ParticleRotation, mRotation, right, up);
|
||||
#endif
|
||||
|
||||
vec3 position = ComputeParticlePosition(a_TexCoordVec4.xy, textureRatio, vec4(a_Position.xyz, in_ParticleSize), right, up);
|
||||
gl_Position = mul(vec4(position, 1.0), g_ModelViewProjectionMatrix);
|
||||
|
||||
v_TexCoord.xy = a_TexCoordVec4.xy;
|
||||
#if SPRITESHEET
|
||||
vec2 uvOffsets;
|
||||
ComputeSpriteFrame(frac(in_ParticleLifeTime), v_TexCoord, uvOffsets, v_TexCoordBlend);
|
||||
uvOffsets *= step(0.001, a_TexCoordVec4.xy);
|
||||
v_TexCoord += uvOffsets.xyxy;
|
||||
#endif
|
||||
|
||||
#if FOG_DIST || FOG_HEIGHT
|
||||
vec3 worldPos = mul(vec4(position, 1.0), g_ModelMatrix).xyz;
|
||||
v_ViewDir.xyz = g_EyePosition - worldPos.xyz;
|
||||
v_ViewDir.w = worldPos.y;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
v_Color = a_Color;
|
||||
|
||||
#if GS_ENABLED || HLSL_GS40
|
||||
#else
|
||||
#if REFRACT
|
||||
ComputeScreenRefractionTangents(gl_Position.xyw, mRotation, v_ScreenCoord, v_ScreenTangents);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
36
modules/wallpaper-engine/shaders/genericropeparticle.frag
Normal file
36
modules/wallpaper-engine/shaders/genericropeparticle.frag
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
// [COMBO] {"material":"ui_editor_properties_fog","combo":"FOG","default":1}
|
||||
|
||||
#include "common_fragment.h"
|
||||
#include "common_fog.h"
|
||||
|
||||
uniform sampler2D g_Texture0; // {"material":"ui_editor_properties_albedo","default":"util/white"}
|
||||
uniform float g_Overbright; // {"material":"ui_editor_properties_overbright","default":1.0,"range":[0,5]}
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
varying vec4 v_Color;
|
||||
|
||||
#if FOG_DIST || FOG_HEIGHT
|
||||
varying vec4 v_ViewDir;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec4 color = v_Color * ConvertTexture0Format(texSample2D(g_Texture0, v_TexCoord.xy));
|
||||
|
||||
color.rgb *= g_Overbright;
|
||||
|
||||
#if FOG_HEIGHT || FOG_DIST
|
||||
vec2 fogPixelState = CalculateFogPixelState(length(v_ViewDir.xyz), v_ViewDir.w);
|
||||
color.rgb = ApplyFog(color.rgb, fogPixelState);
|
||||
color.a = ApplyFogAlpha(color.a, fogPixelState);
|
||||
#endif
|
||||
|
||||
gl_FragColor = color;
|
||||
|
||||
#if ALPHATOCOVERAGE
|
||||
gl_FragColor.a = (gl_FragColor.a - 0.5) / max(fwidth(gl_FragColor.a), 0.0001) + 0.5;
|
||||
#if GLSL
|
||||
if (gl_FragColor.a < 0.5) discard;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
162
modules/wallpaper-engine/shaders/genericropeparticle.geom
Normal file
162
modules/wallpaper-engine/shaders/genericropeparticle.geom
Normal file
@@ -0,0 +1,162 @@
|
||||
|
||||
#include "common_particles.h"
|
||||
|
||||
#if THICKFORMAT
|
||||
in vec4 v_EndPoint;
|
||||
in vec4 v_Color2;
|
||||
#else
|
||||
in vec3 v_EndPoint;
|
||||
#endif
|
||||
|
||||
in vec4 v_Color;
|
||||
in vec4 gl_Position;
|
||||
in vec2 v_UVMinMax;
|
||||
|
||||
in vec3 v_CPStart;
|
||||
in vec3 v_CPEnd;
|
||||
|
||||
#if FOG_DIST || FOG_HEIGHT
|
||||
uniform mat4 g_ModelMatrix;
|
||||
out vec4 v_ViewDir;
|
||||
#endif
|
||||
|
||||
out vec2 v_TexCoord;
|
||||
out vec4 v_Color;
|
||||
out vec4 gl_Position;
|
||||
|
||||
vec3 cubicBezier(vec3 A, vec3 B, vec3 C, vec3 D, float t)
|
||||
{
|
||||
vec3 p;
|
||||
float OneMinusT = 1.0 - t;
|
||||
float b0 = OneMinusT*OneMinusT*OneMinusT;
|
||||
float b1 = 3.0*t*OneMinusT*OneMinusT;
|
||||
float b2 = 3.0*t*t*OneMinusT;
|
||||
float b3 = t*t*t;
|
||||
return b0*A + b1*B + b2*C + b3*D;
|
||||
}
|
||||
|
||||
[maxvertexcount(4 + TRAILSUBDIVISION * 2)]
|
||||
void main() {
|
||||
|
||||
vec3 startPosition = IN[0].gl_Position.xyz;
|
||||
vec3 endPosition = IN[0].v_EndPoint.xyz;
|
||||
vec3 CPStart = IN[0].v_CPStart.xyz;
|
||||
vec3 CPEnd = IN[0].v_CPEnd.xyz;
|
||||
|
||||
#if THICKFORMAT
|
||||
float sizeStart = IN[0].gl_Position.w;
|
||||
float sizeEnd = IN[0].v_EndPoint.w;
|
||||
#else
|
||||
float sizeStart = IN[0].gl_Position.w;
|
||||
float sizeEnd = IN[0].gl_Position.w;
|
||||
#endif
|
||||
|
||||
vec3 eyeDirection = mul(g_OrientationForward, CAST3X3(g_ModelMatrixInverse));
|
||||
vec3 trailDelta = endPosition - startPosition;
|
||||
|
||||
vec3 trailRightStart = cross(CPStart, eyeDirection);
|
||||
trailRightStart = normalize(trailRightStart) * sizeStart;
|
||||
|
||||
vec3 trailRightEnd = cross(trailDelta - (CPEnd + trailDelta), eyeDirection);
|
||||
trailRightEnd = normalize(trailRightEnd) * sizeEnd;
|
||||
|
||||
float uvMinmimum = IN[0].v_UVMinMax.x;
|
||||
float uvMaximum = IN[0].v_UVMinMax.y;
|
||||
|
||||
CPStart = startPosition + CPStart * 0.15;
|
||||
CPEnd = endPosition + CPEnd * 0.15;
|
||||
|
||||
PS_INPUT v;
|
||||
|
||||
#if FOG_DIST || FOG_HEIGHT
|
||||
vec3 worldPos = mul(vec4(startPosition, 1.0), g_ModelMatrix).xyz;
|
||||
v.v_ViewDir.xyz = g_EyePosition - worldPos.xyz;
|
||||
v.v_ViewDir.w = worldPos.y;
|
||||
#endif
|
||||
|
||||
#if THICKFORMAT
|
||||
// Update color per set
|
||||
vec4 colorStart = IN[0].v_Color;
|
||||
vec4 colorEnd = IN[0].v_Color2;
|
||||
|
||||
v.v_Color = colorStart;
|
||||
v.gl_Position = mul(vec4(startPosition - trailRightStart, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(1, uvMinmimum);
|
||||
OUT.Append(v);
|
||||
v.gl_Position = mul(vec4(startPosition + trailRightStart, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(0, uvMinmimum);
|
||||
OUT.Append(v);
|
||||
|
||||
#if TRAILSUBDIVISION != 0
|
||||
float subDivStep = 1.0 / (TRAILSUBDIVISION + 1);
|
||||
float subDivCounter = subDivStep;
|
||||
for (int s = 0; s < TRAILSUBDIVISION; ++s)
|
||||
{
|
||||
float s = smoothstep(0, 1, subDivCounter);
|
||||
vec3 midPosition = cubicBezier(startPosition, CPStart, CPEnd, endPosition, s);
|
||||
float midUV = mix(uvMinmimum, uvMaximum, s);
|
||||
vec3 midRight = mix(trailRightStart, trailRightEnd, s);
|
||||
vec4 color = mix(colorStart, colorEnd, s);
|
||||
|
||||
v.v_Color = color;
|
||||
|
||||
v.gl_Position = mul(vec4(midPosition - midRight, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(1, midUV);
|
||||
OUT.Append(v);
|
||||
v.gl_Position = mul(vec4(midPosition + midRight, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(0, midUV);
|
||||
OUT.Append(v);
|
||||
|
||||
subDivCounter += subDivStep;
|
||||
}
|
||||
#endif
|
||||
v.v_Color = colorEnd;
|
||||
v.gl_Position = mul(vec4(endPosition - trailRightEnd, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(1, uvMaximum);
|
||||
OUT.Append(v);
|
||||
v.gl_Position = mul(vec4(endPosition + trailRightEnd, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(0, uvMaximum);
|
||||
OUT.Append(v);
|
||||
#else // NOT THICKFORMAT
|
||||
// Just set color once
|
||||
v.v_Color = IN[0].v_Color;
|
||||
v.gl_Position = mul(vec4(startPosition - trailRightStart, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(1, uvMinmimum);
|
||||
OUT.Append(v);
|
||||
v.gl_Position = mul(vec4(startPosition + trailRightStart, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(0, uvMinmimum);
|
||||
OUT.Append(v);
|
||||
|
||||
#if TRAILSUBDIVISION != 0
|
||||
float subDivStep = 1.0 / (TRAILSUBDIVISION + 1);
|
||||
float subDivCounter = subDivStep;
|
||||
for (int s = 0; s < TRAILSUBDIVISION; ++s)
|
||||
{
|
||||
float s = smoothstep(0, 1, subDivCounter);
|
||||
vec3 midPosition = cubicBezier(startPosition, CPStart, CPEnd, endPosition, s);
|
||||
float midUV = mix(uvMinmimum, uvMaximum, s);
|
||||
vec3 midRight = mix(trailRightStart, trailRightEnd, s);
|
||||
|
||||
v.gl_Position = mul(vec4(midPosition - midRight, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(1, midUV);
|
||||
OUT.Append(v);
|
||||
v.gl_Position = mul(vec4(midPosition + midRight, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(0, midUV);
|
||||
OUT.Append(v);
|
||||
subDivCounter += subDivStep;
|
||||
}
|
||||
#endif
|
||||
|
||||
v.gl_Position = mul(vec4(endPosition - trailRightEnd, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(1, uvMaximum);
|
||||
OUT.Append(v);
|
||||
v.gl_Position = mul(vec4(endPosition + trailRightEnd, 1.0), g_ModelViewProjectionMatrix);
|
||||
v.v_TexCoord.xy = vec2(0, uvMaximum);
|
||||
OUT.Append(v);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
198
modules/wallpaper-engine/shaders/genericropeparticle.vert
Normal file
198
modules/wallpaper-engine/shaders/genericropeparticle.vert
Normal file
@@ -0,0 +1,198 @@
|
||||
|
||||
#include "common_particles.h"
|
||||
|
||||
#if GS_ENABLED || HLSL_GS40
|
||||
/////////////////////////
|
||||
// Geometry shader
|
||||
/////////////////////////
|
||||
#if THICKFORMAT
|
||||
attribute vec4 a_PositionVec4;
|
||||
attribute vec4 a_TexCoordVec4;
|
||||
attribute vec4 a_TexCoordVec4C1;
|
||||
attribute vec4 a_TexCoordVec4C2;
|
||||
attribute vec4 a_TexCoordVec4C3;
|
||||
attribute vec4 a_Color;
|
||||
|
||||
varying vec4 v_EndPoint;
|
||||
varying vec4 v_Color2;
|
||||
#else
|
||||
attribute vec4 a_PositionVec4;
|
||||
attribute vec4 a_TexCoordVec4;
|
||||
attribute vec4 a_TexCoordVec4C1;
|
||||
attribute vec3 a_TexCoordVec3C2;
|
||||
attribute vec4 a_Color;
|
||||
|
||||
varying vec3 v_EndPoint;
|
||||
#endif
|
||||
|
||||
varying vec4 v_Color;
|
||||
|
||||
varying vec3 v_CPStart;
|
||||
varying vec3 v_CPEnd;
|
||||
varying vec2 v_UVMinMax;
|
||||
|
||||
void main() {
|
||||
|
||||
#define in_ParticleSize (a_PositionVec4.w)
|
||||
#define in_SegmentUVTimeOffset (g_RenderVar0.z)
|
||||
#define in_SegmentMaxCount (g_RenderVar0.w)
|
||||
#define in_ParticleTrailLength (a_TexCoordVec4.w)
|
||||
#define in_ParticleTrailPosition (a_TexCoordVec4C1.w)
|
||||
#define in_SplineCP0 (a_TexCoordVec4C1.xyz)
|
||||
|
||||
gl_Position = vec4(a_PositionVec4.xyz, in_ParticleSize);
|
||||
v_EndPoint.xyz = a_TexCoordVec4.xyz;
|
||||
|
||||
float usableLength = in_ParticleTrailLength - 1;
|
||||
|
||||
#if THICKFORMAT
|
||||
#define in_SplineCP1 (a_TexCoordVec4C2.xyz)
|
||||
|
||||
v_EndPoint.w = a_TexCoordVec4C2.w;
|
||||
|
||||
// New particles are at the end of the array
|
||||
float uvMinimum = 1.0 - (in_ParticleTrailPosition) / usableLength;
|
||||
float uvDelta = -1.0 / usableLength;
|
||||
//uvMinimum += uvDelta;
|
||||
v_Color2 = a_TexCoordVec4C3;
|
||||
#else
|
||||
#define in_SplineCP1 (a_TexCoordVec3C2.xyz)
|
||||
|
||||
// Still spawning new elements, extend to physical end of trail
|
||||
if (in_ParticleTrailLength < in_SegmentMaxCount)
|
||||
{
|
||||
usableLength += in_SegmentUVTimeOffset;
|
||||
}
|
||||
|
||||
float uvMinimum = (in_ParticleTrailPosition - (1.0 - in_SegmentUVTimeOffset)) / usableLength;
|
||||
float uvDelta = 1.0 / usableLength;
|
||||
|
||||
// The first element is shorter based on the history timer and always starts and UV 0
|
||||
if (in_ParticleTrailPosition < 0.5)
|
||||
{
|
||||
uvMinimum = 0.0;
|
||||
uvDelta = in_SegmentUVTimeOffset / usableLength;
|
||||
}
|
||||
#endif
|
||||
|
||||
v_UVMinMax.x = uvMinimum;
|
||||
v_UVMinMax.y = uvMinimum + uvDelta;
|
||||
|
||||
v_Color = a_Color;
|
||||
v_CPStart = a_PositionVec4.xyz - in_SplineCP0;
|
||||
v_CPEnd = v_EndPoint.xyz - in_SplineCP1;
|
||||
|
||||
vec3 dt = v_EndPoint.xyz - a_PositionVec4.xyz;
|
||||
v_CPStart = v_CPStart + dt;
|
||||
v_CPEnd = v_CPEnd - dt;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/////////////////////////
|
||||
// No geometry shader
|
||||
/////////////////////////
|
||||
|
||||
attribute vec4 a_PositionVec4;
|
||||
attribute vec4 a_TexCoordVec4;
|
||||
attribute vec4 a_TexCoordVec4C1;
|
||||
|
||||
#if THICKFORMAT
|
||||
attribute vec4 a_TexCoordVec4C2;
|
||||
attribute vec4 a_TexCoordVec4C3;
|
||||
attribute vec2 a_TexCoordC4;
|
||||
#else
|
||||
attribute vec3 a_TexCoordVec3C2;
|
||||
attribute vec2 a_TexCoordC3;
|
||||
#endif
|
||||
|
||||
attribute vec4 a_Color;
|
||||
|
||||
varying vec4 v_Color;
|
||||
|
||||
#if FOG_DIST || FOG_HEIGHT
|
||||
uniform mat4 g_ModelMatrix;
|
||||
varying vec4 v_ViewDir;
|
||||
#endif
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main() {
|
||||
|
||||
#define in_SegmentUVTimeOffset (g_RenderVar0.z)
|
||||
#define in_SegmentMaxCount (g_RenderVar0.w)
|
||||
#define in_ParticleTrailLength (a_TexCoordVec4.w)
|
||||
#define in_ParticleTrailPosition (a_TexCoordVec4C1.w)
|
||||
|
||||
// Prepare input layout
|
||||
vec3 startPosition = a_PositionVec4.xyz;
|
||||
vec3 endPosition = a_TexCoordVec4.xyz;
|
||||
vec3 CPStart = startPosition - a_TexCoordVec4C1.xyz;
|
||||
|
||||
float sizeStart = a_PositionVec4.w;
|
||||
vec4 colorStart = a_Color;
|
||||
|
||||
#if THICKFORMAT
|
||||
vec3 CPEnd = endPosition - a_TexCoordVec4C2.xyz;
|
||||
float sizeEnd = a_TexCoordVec4C2.w;
|
||||
vec4 colorEnd = a_TexCoordVec4C3;
|
||||
vec2 uvs = a_TexCoordC4.xy;
|
||||
#else
|
||||
vec3 CPEnd = endPosition - a_TexCoordVec3C2.xyz;
|
||||
float sizeEnd = sizeStart;
|
||||
vec4 colorEnd = a_Color;
|
||||
vec2 uvs = a_TexCoordC3.xy;
|
||||
#endif
|
||||
|
||||
vec3 eyeDirection = mul(g_OrientationForward, CAST3X3(g_ModelMatrixInverse));
|
||||
vec3 trailDelta = endPosition - startPosition;
|
||||
|
||||
vec3 trailRightStart = cross(eyeDirection, trailDelta + CPStart);
|
||||
trailRightStart = normalize(trailRightStart) * sizeStart;
|
||||
|
||||
vec3 trailRightEnd = cross(eyeDirection, trailDelta - CPEnd);
|
||||
trailRightEnd = normalize(trailRightEnd) * sizeEnd;
|
||||
|
||||
vec4 color = mix(colorStart, colorEnd, uvs.y);
|
||||
vec3 position = mix(startPosition, endPosition, uvs.y);
|
||||
vec3 right = mix(trailRightStart, trailRightEnd, uvs.y);
|
||||
right *= uvs.x * 2.0 - 1.0;
|
||||
|
||||
gl_Position = mul(vec4(position + right, 1.0), g_ModelViewProjectionMatrix);
|
||||
|
||||
float usableLength = in_ParticleTrailLength - 1;
|
||||
|
||||
#if THICKFORMAT
|
||||
float uvMinimum = 1.0 - (in_ParticleTrailPosition) / usableLength;
|
||||
float uvDelta = -1.0 / usableLength;
|
||||
#else
|
||||
// Still spawning new elements, extend to physical end of trail
|
||||
if (in_ParticleTrailLength < in_SegmentMaxCount)
|
||||
{
|
||||
usableLength += in_SegmentUVTimeOffset;
|
||||
}
|
||||
|
||||
float uvMinimum = (in_ParticleTrailPosition - (1.0 - in_SegmentUVTimeOffset)) / usableLength;
|
||||
float uvDelta = 1.0 / usableLength;
|
||||
|
||||
// The first element is shorter based on the history timer and always starts and UV 0
|
||||
if (in_ParticleTrailPosition < 0.5)
|
||||
{
|
||||
uvMinimum = 0.0;
|
||||
uvDelta = in_SegmentUVTimeOffset / usableLength;
|
||||
}
|
||||
#endif
|
||||
|
||||
v_TexCoord.xy = uvs.xy;
|
||||
v_TexCoord.y = mix(uvMinimum, uvMinimum + uvDelta, uvs.y);
|
||||
|
||||
#if FOG_DIST || FOG_HEIGHT
|
||||
vec3 worldPos = mul(vec4(startPosition, 1.0), g_ModelMatrix).xyz;
|
||||
v_ViewDir.xyz = g_EyePosition - worldPos.xyz;
|
||||
v_ViewDir.w = worldPos.y;
|
||||
#endif
|
||||
|
||||
v_Color = color;
|
||||
}
|
||||
|
||||
#endif
|
||||
95
modules/wallpaper-engine/shaders/hdr_downsample.frag
Normal file
95
modules/wallpaper-engine/shaders/hdr_downsample.frag
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
uniform sampler2D g_Texture0;
|
||||
uniform vec4 g_RenderVar0;
|
||||
|
||||
#if BICUBIC
|
||||
vec4 cubic(float v)
|
||||
{
|
||||
vec4 n = vec4(1.0, 2.0, 3.0, 4.0) - v;
|
||||
vec4 s = n * n * n;
|
||||
float x = s.x;
|
||||
float y = s.y - 4.0 * s.x;
|
||||
float z = s.z - 4.0 * s.y + 6.0 * s.x;
|
||||
float w = 6.0 - x - y - z;
|
||||
return vec4(x, y, z, w) * (1.0/6.0);
|
||||
}
|
||||
|
||||
vec4 textureBicubic(vec2 texCoords)
|
||||
{
|
||||
float sc = 0.5;
|
||||
vec2 texSize = sc / g_RenderVar0.xy;
|
||||
vec2 invTexSize = g_RenderVar0.xy / sc;
|
||||
|
||||
texCoords = texCoords * texSize - 0.5;
|
||||
|
||||
vec2 fxy = frac(texCoords);
|
||||
texCoords -= fxy;
|
||||
|
||||
vec4 xcubic = cubic(fxy.x);
|
||||
vec4 ycubic = cubic(fxy.y);
|
||||
|
||||
vec4 c = texCoords.xxyy + vec2 (-0.5, +1.5).xyxy;
|
||||
|
||||
vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw);
|
||||
vec4 offset = c + vec4 (xcubic.yw, ycubic.yw) / s;
|
||||
|
||||
offset *= invTexSize.xxyy;
|
||||
|
||||
vec4 sample0 = texSample2D(g_Texture0, offset.xz);
|
||||
vec4 sample1 = texSample2D(g_Texture0, offset.yz);
|
||||
vec4 sample2 = texSample2D(g_Texture0, offset.xw);
|
||||
vec4 sample3 = texSample2D(g_Texture0, offset.yw);
|
||||
|
||||
float sx = s.x / (s.x + s.y);
|
||||
float sy = s.z / (s.z + s.w);
|
||||
|
||||
return mix(
|
||||
mix(sample3, sample2, sx), mix(sample1, sample0, sx)
|
||||
, sy);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BLOOM
|
||||
uniform float g_BloomStrength; // {"material":"bloomstrength","default":2}
|
||||
uniform vec4 g_BloomBlendParams; // {"material":"blend","default":"1 1 0 1"}
|
||||
uniform vec3 g_BloomTint; // {"material":"bloomtint","default":"1 1 1"}
|
||||
#endif
|
||||
|
||||
#if UPSAMPLE
|
||||
uniform float g_BloomScatter; // {"material":"scatter","default":1}
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#if BICUBIC
|
||||
vec3 albedo = textureBicubic(v_TexCoord + g_RenderVar0.xy).rgb +
|
||||
textureBicubic(v_TexCoord + g_RenderVar0.zy).rgb +
|
||||
textureBicubic(v_TexCoord + g_RenderVar0.xw).rgb +
|
||||
textureBicubic(v_TexCoord + g_RenderVar0.zw).rgb;
|
||||
#else
|
||||
vec3 albedo = texSample2D(g_Texture0, v_TexCoord + g_RenderVar0.xy).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord + g_RenderVar0.zy).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord + g_RenderVar0.xw).rgb +
|
||||
texSample2D(g_Texture0, v_TexCoord + g_RenderVar0.zw).rgb;
|
||||
#endif
|
||||
|
||||
#if UPSAMPLE
|
||||
albedo *= 0.25 * g_BloomScatter;
|
||||
#else
|
||||
albedo *= 0.25;
|
||||
#endif
|
||||
|
||||
#if BLOOM
|
||||
albedo = max(CAST3(0), albedo);
|
||||
float brightness = max(albedo.r, max(albedo.g, albedo.b));
|
||||
float soft = brightness - g_BloomBlendParams.y;
|
||||
soft = clamp(soft, 0, g_BloomBlendParams.z);
|
||||
soft = soft * soft * g_BloomBlendParams.w;
|
||||
float contribution = max(soft, brightness - g_BloomBlendParams.x);
|
||||
contribution /= max(brightness, 0.00001);
|
||||
albedo *= contribution * g_BloomStrength * g_BloomTint;
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4(albedo, 1.0);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user