chore: Project Restructuring & Theatre
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
#ifndef ENKI_BILLAL_INCLUDED
|
||||
#define ENKI_BILLAL_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
//#include "Assets/_Content/Shaders/EnkiBillal/Stripes.hlsl"
|
||||
#include "Assets/_Content/Shaders/Include/Noises.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/AmbientOcclusion.hlsl"
|
||||
|
||||
float MainLightShadowAtten(float3 PositionWS, float3 NormalWS, float CastAtten)
|
||||
{
|
||||
float4 shadowCoord = TransformWorldToShadowCoord(PositionWS);
|
||||
Light mainLight = GetMainLight(shadowCoord);
|
||||
|
||||
float lightGradient = dot(normalize(NormalWS), normalize(mainLight.direction));
|
||||
lightGradient = smoothstep(-.5, 1, lightGradient);
|
||||
|
||||
float shadow = 1 - mainLight.shadowAttenuation;
|
||||
shadow = lerp(0, shadow, lightGradient) * CastAtten;
|
||||
shadow = lerp(1, shadow, lightGradient);
|
||||
shadow = 1 - shadow;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
float3 TriplanarMask(float3 NormalWS, float Sharpness)
|
||||
{
|
||||
float sharpness = Remap(0, 1, 1, 16, smoothstep(0, .9, Sharpness));
|
||||
float3 hard = abs(NormalWS) == max(abs(NormalWS.x), max(abs(NormalWS.y), abs(NormalWS.z)));
|
||||
float3 blend = pow(abs(NormalWS), sharpness);
|
||||
blend /= max(dot(blend, float3(1, 1, 1)), 0.0001);
|
||||
blend = lerp(blend, hard, smoothstep(.9, 1, Sharpness));
|
||||
return blend;
|
||||
}
|
||||
|
||||
float2 RotateUV(float2 UV, float2 Pivot, float Angle)
|
||||
{
|
||||
float s = sin(Angle);
|
||||
float c = cos(Angle);
|
||||
|
||||
UV -= Pivot;
|
||||
|
||||
float2 rotated = float2(
|
||||
UV.x * c - UV.y * s,
|
||||
UV.x * s + UV.y * c
|
||||
);
|
||||
|
||||
return rotated + Pivot;
|
||||
}
|
||||
|
||||
float StableStripes(float x, float depth, float width, float smooth)
|
||||
{
|
||||
float phase = frac(depth);
|
||||
float index = floor(depth);
|
||||
float scale = exp2(-index);
|
||||
|
||||
float rawX = x * scale - 0.5;
|
||||
|
||||
float cellIndex = floor(rawX);
|
||||
|
||||
float2 uv = float2(frac(rawX), phase);
|
||||
|
||||
float isContinuing = abs(fmod(cellIndex, 2));
|
||||
|
||||
float w = lerp(width, lerp(-smooth, width * 2, isContinuing), uv.y);
|
||||
float s = smooth;
|
||||
|
||||
return smoothstep(w + s, w - s, abs(uv.x - .5) * 2);
|
||||
}
|
||||
|
||||
void EnkiBillal_float
|
||||
(
|
||||
float4 Color,
|
||||
float2 ScreenUV,
|
||||
float3 PositionWS,
|
||||
float3 PositionOS,
|
||||
float3 NormalWS,
|
||||
float3 NormalOS,
|
||||
float3 ObjectScale,
|
||||
float TriplanarBlend,
|
||||
float StripesDensity,
|
||||
float StripesWidth,
|
||||
float StripesSmooth,
|
||||
int Step,
|
||||
out float3 Output
|
||||
)
|
||||
{
|
||||
float3 scaledPositionOS = PositionOS * ObjectScale;
|
||||
float depth = length(PositionWS - _WorldSpaceCameraPos.xyz);
|
||||
//Light mainLight = GetMainLight(0);
|
||||
float3 mainLightDir = normalize(float3(1, -1, 1)); //normalize(float3(0, 13, 8) - PositionWS); //float3(0, -1, 0);//normalize(mainLight.direction);
|
||||
float lightGradient = dot(normalize(NormalWS), normalize(mainLightDir));
|
||||
lightGradient = smoothstep(-.5, 1, lightGradient);
|
||||
float ao = GetScreenSpaceAmbientOcclusion(ScreenUV).directAmbientOcclusion;
|
||||
|
||||
|
||||
// Triplanar
|
||||
|
||||
//float3 triplanarMask = TriplanarMask(NormalWS, TriplanarBlend);
|
||||
|
||||
// Shadow
|
||||
|
||||
float shadowMask = lightGradient;//MainLightShadowAtten(PositionWS, NormalWS, .8);
|
||||
float shadowAtten = Remap(0, 1, .6, 1, shadowMask);
|
||||
|
||||
// Grain
|
||||
|
||||
float grain = ValueNoise3DLOD(PositionWS, scaledPositionOS, 600, 3.5);
|
||||
float grainMin = lerp(.4, .8, shadowMask);
|
||||
float grainAtten = Remap(0, 1, grainMin, 1, grain);
|
||||
|
||||
// Dirt
|
||||
|
||||
float dirt = FBMNoise3D(scaledPositionOS, 1, 3, 2, .5);
|
||||
float dirtMin = lerp(.2, .7, shadowMask);
|
||||
float dirtAtten = Remap(0, 1, dirtMin, 1, dirt);
|
||||
|
||||
/*// Stripes
|
||||
|
||||
float StripesScale = StripesDensity;
|
||||
//float StripesWidth = .5;
|
||||
//float StripesSmooth = .05;
|
||||
|
||||
// Octahedral face normals (4 faces + 3 world axes)
|
||||
float3 octaFaceNormals[7] = {
|
||||
normalize(float3(1, 1, 1)),
|
||||
normalize(float3(-1, 1, 1)),
|
||||
normalize(float3(1, -1, 1)),
|
||||
normalize(float3(-1, -1, 1)),
|
||||
float3(1, 0, 0),
|
||||
float3(0, 1, 0),
|
||||
float3(0, 0, 1)
|
||||
};
|
||||
|
||||
// Octahedral blending mask
|
||||
float sharpness = Remap(0, 1, 1, 16, smoothstep(0, .9, TriplanarBlend));
|
||||
float octaMask[7];
|
||||
float hardMax = -1;
|
||||
int hardIdx = 0;
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
float d = abs(dot(NormalWS, octaFaceNormals[i]));
|
||||
octaMask[i] = pow(saturate(d), sharpness);
|
||||
if (d > hardMax) { hardMax = d; hardIdx = i; }
|
||||
}
|
||||
float maskSum = 0;
|
||||
for (int i = 0; i < 7; i++) maskSum += octaMask[i];
|
||||
for (int i = 0; i < 7; i++) octaMask[i] /= max(maskSum, 0.0001);
|
||||
float hardFactor = smoothstep(.9, 1, TriplanarBlend);
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
float hard = (i == hardIdx) ? 1.0 : 0.0;
|
||||
octaMask[i] = lerp(octaMask[i], hard, hardFactor);
|
||||
}
|
||||
|
||||
// Patern
|
||||
float3 stripesPos = PositionWS;
|
||||
float3 stripesPos0 = stripesPos;// + PerlinColor3D(PositionWS, .63) * .10;
|
||||
float3 stripesPos1 = stripesPos;// + PerlinColor3D(PositionWS, 5.7) * .02;
|
||||
|
||||
float width = StripesWidth; // * .5;
|
||||
float smooth = max(StripesSmooth, 1e-5);
|
||||
|
||||
float stripes0 = 0;
|
||||
float stripes1 = 0;
|
||||
|
||||
[unroll]
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
float3 n = octaFaceNormals[i];
|
||||
|
||||
float3 up = abs(n.y) < 0.999 ? float3(0, 1, 0) : float3(1, 0, 0);
|
||||
float3 tangent = normalize(cross(up, n));
|
||||
float3 bitangent = normalize(cross(n, tangent));
|
||||
|
||||
float3 ref = normalize(mainLightDir - dot(mainLightDir, n) * n);
|
||||
float3 axis = normalize(up - dot(up, n) * n);
|
||||
float angle = -atan2(dot(cross(axis, ref), n), dot(axis, ref));
|
||||
|
||||
float2 p0 = RotateUV(float2(dot(stripesPos0, tangent), dot(stripesPos0, bitangent)), 0, angle) * StripesScale;
|
||||
float2 p1 = (RotateUV(float2(dot(stripesPos1, tangent), dot(stripesPos1, bitangent)), 0, angle) + .5) * StripesScale;
|
||||
|
||||
float stripe0 = StableStripes(p0.x, log2(depth), width, smooth);
|
||||
float stripe1 = StableStripes(p1.x + p1.y, log2(depth), width, smooth);
|
||||
|
||||
stripes0 += stripe0 * octaMask[i];
|
||||
stripes1 += stripe1 * octaMask[i];
|
||||
}
|
||||
|
||||
//float stripes = stripes0 * smoothstep(.5, 0, lightGradient);
|
||||
float stripes = max(stripes0, stripes1 * .5);
|
||||
stripes *= smoothstep(.5, 0, lightGradient) * smoothstep(.97, .93, ao);*/
|
||||
|
||||
|
||||
// Test
|
||||
|
||||
//float test = ValueNoise3D(PositionWS, 40);
|
||||
//float test = PerlinNoise3D(PositionWS, 40);
|
||||
//float test = PerlinNoise3DLOD(PositionWS, 100, 3.5);
|
||||
//float test = SimplexNoise3D(PositionWS, 40);
|
||||
//float test = WorleyNoise3D(PositionWS, 40, 1);
|
||||
//float id;
|
||||
//float test = VoronoiNoise3D(PositionWS, 10, 1, .05, id);
|
||||
//float test = FBMNoise3D(PositionWS, 10, 2, 2, .5);
|
||||
//float test = RidgedNoise3D(PositionWS, 10, 2, 2, .5);
|
||||
|
||||
// Output
|
||||
|
||||
Output = 1;
|
||||
if (Step > 0 ) Output *= Color;
|
||||
if (Step > 1 ) Output *= grainAtten;
|
||||
if (Step > 2 ) Output *= dirtAtten;
|
||||
if (Step > 3 ) Output *= shadowAtten;
|
||||
//if (Step > 4 ) Output = lerp(Output, Output * .1, stripes * .8);
|
||||
|
||||
//Output = PerlinColor3D(PositionWS, 5);
|
||||
//Output = smoothstep(.97, .93, ao);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 411dec433a23f2c4da8f56e83e7230da
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef STRIPES_INCLUDED
|
||||
#define STRIPES_INCLUDED
|
||||
|
||||
// Returns a value in [0, 1)
|
||||
float VanDerCorput(uint index)
|
||||
{
|
||||
// Reverse bits of the integer and scale to [0,1]
|
||||
return (float) reversebits(index) * 2.3283064365386963e-10;
|
||||
}
|
||||
|
||||
void Stripes_float(
|
||||
float2 UV,
|
||||
float Density,
|
||||
float Count,
|
||||
float Thickness,
|
||||
float Offset,
|
||||
float DistortionAmplitude,
|
||||
float DistortionFrequency,
|
||||
out float Stripes
|
||||
)
|
||||
{
|
||||
float density = saturate(Density);
|
||||
float offset = frac(Offset);
|
||||
float distortionAmplitude = DistortionAmplitude * .1;
|
||||
uint stripeCount = max((uint) round(Count), 1u);
|
||||
|
||||
float2 uv = UV;
|
||||
uv.x += offset;
|
||||
|
||||
float2 uvA = uv;
|
||||
float2 uvB = uv;
|
||||
uvA.x = frac(uvA.x + cos((uv.y + offset) * sin(uv.x) * DistortionFrequency + offset * 7.8) * distortionAmplitude);
|
||||
uvB.x = frac(uvB.x + sin((uv.y + offset) * cos(uv.x) * DistortionFrequency + offset * 5.3) * distortionAmplitude);
|
||||
|
||||
float stripDistanceY = abs(saturate(uv.y) - .5);
|
||||
|
||||
float stripeMax = 0;
|
||||
|
||||
for (uint i = 0u; i < stripeCount; i++)
|
||||
{
|
||||
float vdc = VanDerCorput(i);
|
||||
bool usesSecondDistortion = vdc >= .5;
|
||||
|
||||
float thickness = vdc < .3 ? 1 : (vdc < .6 ? 1.8 : 2.6);
|
||||
thickness *= saturate(Thickness);
|
||||
|
||||
float wrappedX = usesSecondDistortion ? uvB.x : uvA.x;
|
||||
|
||||
float localProgress = saturate(density * stripeCount - vdc * stripeCount);
|
||||
|
||||
float stripeCenterX = frac((i + .5) / stripeCount);
|
||||
float stripDistanceX = abs(wrappedX - stripeCenterX);
|
||||
stripDistanceX = min(stripDistanceX, 1.0 - stripDistanceX);
|
||||
|
||||
float stepX = (1. / stripeCount) * localProgress * thickness * .5;
|
||||
float stepY = localProgress * .5 - .01;
|
||||
|
||||
float softEdgeX = .01;
|
||||
float softEdgeY = .05;
|
||||
|
||||
float widthMask = 1 - smoothstep(stepX - softEdgeX, stepX, stripDistanceX);
|
||||
float heightMask = 1 - smoothstep(stepY - softEdgeY, stepY, stripDistanceY);
|
||||
|
||||
float stripeMask = widthMask * heightMask;
|
||||
stripeMax = max(stripeMax, stripeMask);
|
||||
}
|
||||
|
||||
Stripes = stripeMax;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e32323363e459a4fa93de6067070a10
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user