✨ Add water shader by Atlas and, flip some faces and experiment with animations
This commit is contained in:
parent
bf6da1e7c9
commit
c50e9258cf
1764 changed files with 303341 additions and 66722 deletions
79
Assets/Editor/x64/Bakery/shaderSrc/ftCullFarSphere.compute
Normal file
79
Assets/Editor/x64/Bakery/shaderSrc/ftCullFarSphere.compute
Normal file
|
@ -0,0 +1,79 @@
|
|||
#pragma kernel CSMain
|
||||
|
||||
StructuredBuffer<float3> verts;
|
||||
StructuredBuffer<uint3> indices;
|
||||
StructuredBuffer<float2> uvs;
|
||||
AppendStructuredBuffer<uint3> newIndices;
|
||||
Texture2D alphaTex;
|
||||
float cubeSize;
|
||||
uint triCount;
|
||||
//float3 localCamPos;
|
||||
|
||||
float3 trinormal(float3 v0, float3 v1, float3 v2)
|
||||
{
|
||||
float3 p = v0-v1;
|
||||
float3 q = v1-v2;
|
||||
float3 norm = cross(p,q);
|
||||
return normalize(norm);
|
||||
}
|
||||
|
||||
[numthreads(256,1,1)]
|
||||
void CSMain (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id.x >= triCount) return;
|
||||
|
||||
uint3 ind = indices[id.x];
|
||||
float3 a = verts[ind.x];
|
||||
float3 b = verts[ind.y];
|
||||
float3 c = verts[ind.z];
|
||||
|
||||
float ab = distance(a,b);
|
||||
float bc = distance(b,c);
|
||||
float ca = distance(c,a);
|
||||
|
||||
//if (max(max(ab, bc), ca) > 0.9) return;
|
||||
|
||||
float3 n = trinormal(a,b,c);
|
||||
|
||||
float3 dir = normalize(a);// - localCamPos);
|
||||
//if (dot(-dir, n) > 0.2f)
|
||||
float elimit = 10;
|
||||
float dlimit = 900;
|
||||
//if (distance(localCamPos, a) < dlimit && distance(localCamPos, b) < dlimit && distance(localCamPos, c) < dlimit)
|
||||
if (length(a) < dlimit && length(b) < dlimit && length(c) < dlimit)
|
||||
{
|
||||
if (dot(-dir, n) > 0.0f)
|
||||
{
|
||||
|
||||
float degenerateThreshold = 0.1f;
|
||||
bool deg = false;
|
||||
if (((bc + ca) - ab) / ab < degenerateThreshold)
|
||||
{
|
||||
deg = true;
|
||||
}
|
||||
else if (((ab + ca) - bc) / bc < degenerateThreshold)
|
||||
{
|
||||
deg = true;
|
||||
}
|
||||
else if (((ab + bc) - ca) / ca < degenerateThreshold)
|
||||
{
|
||||
deg = true;
|
||||
}
|
||||
if (!deg)
|
||||
{
|
||||
float2 uv0 = uvs[ind.x] * cubeSize;
|
||||
float2 uv1 = uvs[ind.y] * cubeSize;
|
||||
float2 uv2 = uvs[ind.z] * cubeSize;
|
||||
float a0 = alphaTex.Load(int3(uv0.x, uv0.y, 0)).a;
|
||||
float a1 = alphaTex.Load(int3(uv1.x, uv1.y, 0)).a;
|
||||
float a2 = alphaTex.Load(int3(uv2.x, uv2.y, 0)).a;
|
||||
//float a = a0 + a1 + a2;
|
||||
float a = a0 * a1 * a2;
|
||||
if (a > 1.0f / 255)
|
||||
{
|
||||
newIndices.Append(ind);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0a45c2cb58f63f2498cf418d09aaefd1
|
||||
timeCreated: 1617749862
|
||||
licenseType: Store
|
||||
ComputeShaderImporter:
|
||||
currentAPIMask: 4
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,64 @@
|
|||
#pragma kernel CSMain
|
||||
|
||||
RWStructuredBuffer<float3> verts;
|
||||
Texture2D<float> _DepthTex;
|
||||
SamplerState sampler_DepthTex;
|
||||
float3 objectCenter;
|
||||
float4 _InvProj0, _InvProj1, _InvProj2, _InvProj3;
|
||||
float3 wnormal;
|
||||
uint vertWidth;
|
||||
|
||||
float4 ComputeClipSpacePosition(float2 positionNDC, float deviceDepth)
|
||||
{
|
||||
float4 positionCS = float4(positionNDC * 2.0 - 1.0, deviceDepth, 1.0);
|
||||
positionCS.y = -positionCS.y;
|
||||
return positionCS;
|
||||
}
|
||||
|
||||
float3 ComputeViewSpacePosition(float2 positionNDC, float deviceDepth, float4x4 invProjMatrix)
|
||||
{
|
||||
float4 positionCS = ComputeClipSpacePosition(positionNDC, deviceDepth);
|
||||
float4 hpositionVS = mul(invProjMatrix, positionCS);
|
||||
return hpositionVS.xyz / hpositionVS.w;
|
||||
}
|
||||
|
||||
float planeIntersect(float3 ro, float3 rd, float4 p)
|
||||
{
|
||||
return -(dot(ro,p.xyz)+p.w)/dot(rd,p.xyz);
|
||||
}
|
||||
|
||||
[numthreads(16,16,1)]
|
||||
void CSMain (uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id.x >= vertWidth) return;
|
||||
if (id.y >= vertWidth) return;
|
||||
|
||||
int vertID = id.y * vertWidth + id.x;
|
||||
float3 lpos = verts[vertID];
|
||||
|
||||
float4x4 invProjMatrix = float4x4(_InvProj0, _InvProj1, _InvProj2, _InvProj3);
|
||||
|
||||
float2 uv = (id.xy) / (float)(vertWidth-1);
|
||||
uv.y = 1 - uv.y;
|
||||
|
||||
float texelSize = 1.0f / vertWidth;
|
||||
|
||||
uv = lerp(uv-texelSize*0.5, uv+texelSize*0.5, uv);
|
||||
|
||||
float2 centerUV = uv;//floor(uv * (vertWidth-1)) / (vertWidth-1);
|
||||
|
||||
float2 leftUV = centerUV - float2(texelSize, 0);
|
||||
float2 rightUV = centerUV + float2(texelSize, 0);
|
||||
float2 bottomUV = centerUV - float2(0, texelSize);
|
||||
float2 topUV = centerUV + float2(0, texelSize);
|
||||
|
||||
float depth = _DepthTex.SampleLevel(sampler_DepthTex, centerUV, 0).r;
|
||||
|
||||
//depth = -ComputeViewSpacePosition(uv * 2 - 1, depth, invProjMatrix).z;
|
||||
//float3 dir = normalize(lpos);
|
||||
//float3 worldPos = dir * planeIntersect(0, dir, float4(-wnormal.xyz, depth));
|
||||
|
||||
float3 worldPos = ComputeViewSpacePosition(uv, depth, invProjMatrix) - objectCenter;
|
||||
|
||||
verts[vertID] = worldPos;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 84e158810fe530a499c974bba77a220a
|
||||
timeCreated: 1617749862
|
||||
licenseType: Store
|
||||
ComputeShaderImporter:
|
||||
currentAPIMask: 4
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
171
Assets/Editor/x64/Bakery/shaderSrc/ftrace.cginc
Normal file
171
Assets/Editor/x64/Bakery/shaderSrc/ftrace.cginc
Normal file
|
@ -0,0 +1,171 @@
|
|||
#ifdef LIGHTMAP_RGBM_SCALE
|
||||
|
||||
#ifndef FTRACE_INCLUDED
|
||||
#define FTRACE_INCLUDED
|
||||
|
||||
// Bicubic interpolation
|
||||
|
||||
float ftBicubic_w0(float a)
|
||||
{
|
||||
return (1.0f/6.0f)*(a*(a*(-a + 3.0f) - 3.0f) + 1.0f);
|
||||
}
|
||||
|
||||
float ftBicubic_w1(float a)
|
||||
{
|
||||
return (1.0f/6.0f)*(a*a*(3.0f*a - 6.0f) + 4.0f);
|
||||
}
|
||||
|
||||
float ftBicubic_w2(float a)
|
||||
{
|
||||
return (1.0f/6.0f)*(a*(a*(-3.0f*a + 3.0f) + 3.0f) + 1.0f);
|
||||
}
|
||||
|
||||
float ftBicubic_w3(float a)
|
||||
{
|
||||
return (1.0f/6.0f)*(a*a*a);
|
||||
}
|
||||
|
||||
float ftBicubic_g0(float a)
|
||||
{
|
||||
return ftBicubic_w0(a) + ftBicubic_w1(a);
|
||||
}
|
||||
|
||||
float ftBicubic_g1(float a)
|
||||
{
|
||||
return ftBicubic_w2(a) + ftBicubic_w3(a);
|
||||
}
|
||||
|
||||
float ftBicubic_h0(float a)
|
||||
{
|
||||
return -1.0f + ftBicubic_w1(a) / (ftBicubic_w0(a) + ftBicubic_w1(a)) + 0.5f;
|
||||
}
|
||||
|
||||
float ftBicubic_h1(float a)
|
||||
{
|
||||
return 1.0f + ftBicubic_w3(a) / (ftBicubic_w2(a) + ftBicubic_w3(a)) + 0.5f;
|
||||
}
|
||||
|
||||
#ifdef SHADER_API_D3D11
|
||||
#if defined (SHADOWS_SHADOWMASK)
|
||||
|
||||
float4 ftBicubicSampleShadow3( Texture2D tex, SamplerState ftShadowSampler, float2 uv )
|
||||
{
|
||||
float width, height;
|
||||
tex.GetDimensions(width, height);
|
||||
|
||||
float x = uv.x * width;
|
||||
float y = uv.y * height;
|
||||
|
||||
x -= 0.5f;
|
||||
y -= 0.5f;
|
||||
|
||||
float px = floor(x);
|
||||
float py = floor(y);
|
||||
|
||||
float fx = x - px;
|
||||
float fy = y - py;
|
||||
|
||||
float g0x = ftBicubic_g0(fx);
|
||||
float g1x = ftBicubic_g1(fx);
|
||||
float h0x = ftBicubic_h0(fx);
|
||||
float h1x = ftBicubic_h1(fx);
|
||||
float h0y = ftBicubic_h0(fy);
|
||||
float h1y = ftBicubic_h1(fy);
|
||||
|
||||
float4 r = ftBicubic_g0(fy) * ( g0x * tex.Sample(ftShadowSampler, (float2(px + h0x, py + h0y) * 1.0f/width)) +
|
||||
g1x * tex.Sample(ftShadowSampler, (float2(px + h1x, py + h0y) * 1.0f/width))) +
|
||||
|
||||
ftBicubic_g1(fy) * ( g0x * tex.Sample(ftShadowSampler, (float2(px + h0x, py + h1y) * 1.0f/width)) +
|
||||
g1x * tex.Sample(ftShadowSampler, (float2(px + h1x, py + h1y) * 1.0f/width)));
|
||||
return r;
|
||||
}
|
||||
|
||||
#if UNITY_VERSION >= 201740
|
||||
SamplerState bakery_trilinear_clamp_sampler2;
|
||||
#endif
|
||||
|
||||
float4 ftBicubicSampleShadow( Texture2D tex, float2 uv )
|
||||
{
|
||||
#if UNITY_VERSION >= 201740
|
||||
SamplerState samplerMask = bakery_trilinear_clamp_sampler2;
|
||||
#else
|
||||
#if defined(LIGHTMAP_ON)
|
||||
SamplerState samplerMask = samplerunity_Lightmap;
|
||||
#else
|
||||
SamplerState samplerMask = samplerunity_ShadowMask;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return ftBicubicSampleShadow3(tex, samplerMask, uv);
|
||||
}
|
||||
|
||||
#define ftBicubicSampleShadow2(t,s,u) ftBicubicSampleShadow3(t, sampler##s, u)
|
||||
|
||||
#else
|
||||
#define ftBicubicSampleShadow UNITY_SAMPLE_TEX2D
|
||||
#define ftBicubicSampleShadow2 UNITY_SAMPLE_TEX2D_SAMPLER
|
||||
#endif
|
||||
#else
|
||||
#define ftBicubicSampleShadow UNITY_SAMPLE_TEX2D
|
||||
#define ftBicubicSampleShadow2 UNITY_SAMPLE_TEX2D_SAMPLER
|
||||
#endif
|
||||
|
||||
float3 ftLightmapBicubic( float2 uv )
|
||||
{
|
||||
#ifdef SHADER_API_D3D11
|
||||
float width, height;
|
||||
unity_Lightmap.GetDimensions(width, height);
|
||||
|
||||
float x = uv.x * width;
|
||||
float y = uv.y * height;
|
||||
|
||||
x -= 0.5f;
|
||||
y -= 0.5f;
|
||||
|
||||
float px = floor(x);
|
||||
float py = floor(y);
|
||||
|
||||
float fx = x - px;
|
||||
float fy = y - py;
|
||||
|
||||
// note: we could store these functions in a lookup table texture, but maths is cheap
|
||||
float g0x = ftBicubic_g0(fx);
|
||||
float g1x = ftBicubic_g1(fx);
|
||||
float h0x = ftBicubic_h0(fx);
|
||||
float h1x = ftBicubic_h1(fx);
|
||||
float h0y = ftBicubic_h0(fy);
|
||||
float h1y = ftBicubic_h1(fy);
|
||||
|
||||
float4 r = ftBicubic_g0(fy) * ( g0x * UNITY_SAMPLE_TEX2D(unity_Lightmap, (float2(px + h0x, py + h0y) * 1.0f/width)) +
|
||||
g1x * UNITY_SAMPLE_TEX2D(unity_Lightmap, (float2(px + h1x, py + h0y) * 1.0f/width))) +
|
||||
|
||||
ftBicubic_g1(fy) * ( g0x * UNITY_SAMPLE_TEX2D(unity_Lightmap, (float2(px + h0x, py + h1y) * 1.0f/width)) +
|
||||
g1x * UNITY_SAMPLE_TEX2D(unity_Lightmap, (float2(px + h1x, py + h1y) * 1.0f/width)));
|
||||
return DecodeLightmap(r);
|
||||
#else
|
||||
return DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, uv));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Light falloff
|
||||
|
||||
float ftLightFalloff(float4x4 ftUnityLightMatrix, float3 worldPos)
|
||||
{
|
||||
float3 lightCoord = mul(ftUnityLightMatrix, float4(worldPos, 1)).xyz / ftUnityLightMatrix._11;
|
||||
float distSq = dot(lightCoord, lightCoord);
|
||||
float falloff = saturate(1.0f - pow(sqrt(distSq) * ftUnityLightMatrix._11, 4.0f)) / (distSq + 1.0f);
|
||||
return falloff;
|
||||
}
|
||||
|
||||
float ftLightFalloff(float4 lightPosRadius, float3 worldPos)
|
||||
{
|
||||
float3 lightCoord = worldPos - lightPosRadius.xyz;
|
||||
float distSq = dot(lightCoord, lightCoord);
|
||||
float falloff = saturate(1.0f - pow(sqrt(distSq * lightPosRadius.w), 4.0f)) / (distSq + 1.0f);
|
||||
return falloff;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
9
Assets/Editor/x64/Bakery/shaderSrc/ftrace.cginc.meta
Normal file
9
Assets/Editor/x64/Bakery/shaderSrc/ftrace.cginc.meta
Normal file
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f1386c908e92ef64287e16194552143d
|
||||
timeCreated: 1527275740
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue