补齐备份工程打开依赖
This commit is contained in:
@@ -0,0 +1,250 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#pragma kernel NoiseCS
|
||||
#pragma kernel RefractCS
|
||||
#pragma kernel RefractCS_CACalcSeparate
|
||||
#pragma kernel ColorCS
|
||||
#pragma kernel ColorCS_CACalcSeparate
|
||||
|
||||
#pragma warning(disable : 3571)
|
||||
|
||||
#define THREAD_SIZE 16
|
||||
#define WAVE_MAX_CNT 4
|
||||
|
||||
#pragma multi_compile_local __ EXTEND_RAY
|
||||
#pragma multi_compile_local STYLE_A STYLE_B STYLE_C
|
||||
|
||||
#include "snoise.cginc"
|
||||
|
||||
struct CausticsBufStruct {
|
||||
float2 offset;
|
||||
float3 color;
|
||||
};
|
||||
|
||||
RWStructuredBuffer<float> _BufNoiseRW;
|
||||
StructuredBuffer<float> _BufNoise;
|
||||
RWStructuredBuffer<CausticsBufStruct> _BufRefractRW;
|
||||
StructuredBuffer<CausticsBufStruct> _BufRefract;
|
||||
|
||||
cbuffer CB {
|
||||
uint _WaveCnt;
|
||||
float3 _WaveData[WAVE_MAX_CNT];
|
||||
float2 _WaveUVShift[WAVE_MAX_CNT];
|
||||
float2 _WaveNoiseDir[WAVE_MAX_CNT];
|
||||
uint _CalcResUI;
|
||||
float _CalcTexel;
|
||||
float _CalcTexelInv;
|
||||
float3 _LightDir;
|
||||
float3 _Eta;
|
||||
float _Brightness;
|
||||
float _Gamma;
|
||||
float _Clamp;
|
||||
uint _IdxStride;
|
||||
float2 _DrawOffset;
|
||||
}
|
||||
|
||||
uint idToIdx(uint2 id, uint width) {
|
||||
return id.x + id.y * width;
|
||||
}
|
||||
|
||||
uint idToIdxWrap(uint2 id, uint width) {
|
||||
uint2 tmp = id % width;
|
||||
return tmp.x + tmp.y * width;
|
||||
}
|
||||
|
||||
uint2 uvToID(float2 uv, float widthF) {
|
||||
return uint2(uv * widthF + widthF);
|
||||
}
|
||||
|
||||
uint uvToIdx(float2 uv, float widthF, uint width) {
|
||||
return idToIdxWrap(uint2(uv * widthF + widthF), width);
|
||||
}
|
||||
|
||||
uint3 idToIdxRGB(uint2 id, uint width) {
|
||||
uint3 idx;
|
||||
idx.r = idToIdx(id.xy, width);
|
||||
idx.g = idx.r + _IdxStride;
|
||||
idx.b = idx.g + _IdxStride;
|
||||
return idx;
|
||||
}
|
||||
|
||||
uint3 idToIdxWrapRGB(uint2 id, uint width) {
|
||||
uint3 idx;
|
||||
idx.r = idToIdxWrap(id.xy, width);
|
||||
idx.g = idx.r + _IdxStride;
|
||||
idx.b = idx.g + _IdxStride;
|
||||
return idx;
|
||||
}
|
||||
|
||||
static const float PI = 3.14159265359;
|
||||
|
||||
float2 easeInOutSine_f2(float2 t) {
|
||||
return 0.5 - cos(PI * t) * 0.5;
|
||||
}
|
||||
|
||||
static const float NOISE_RADIUS = 100;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
float genNoise(float2 uv, float4 lc, float density, float2 dir, float shift) {
|
||||
float2 s0 = uv * density + float2(NOISE_RADIUS, shift);
|
||||
float2 s1 = s0 + density;
|
||||
float3 p0 = float3(s0.x * dir.x, s0.y, s0.x * dir.y);
|
||||
float3 p1 = float3(s1.x * dir.x, s1.y, s1.x * dir.y);
|
||||
float4 n;
|
||||
n.x = snoise(p0);
|
||||
n.y = snoise(float3(p1.x, p0.y, p1.z));
|
||||
n.z = snoise(float3(p0.x, p1.y, p0.z));
|
||||
n.w = snoise(p1);
|
||||
return dot(n, lc);
|
||||
}
|
||||
|
||||
float4 lerpCoef(float2 uv) {
|
||||
float2 e = easeInOutSine_f2(uv);
|
||||
float2 adj = easeInOutSine_f2(uv * 2);
|
||||
adj = 1 - 0.4142 * 0.5 + 0.4142 * adj;
|
||||
float4 t = float4(e, 1 - e) * adj.xyxy;
|
||||
return t.xzxz * t.yyww;
|
||||
}
|
||||
|
||||
[numthreads(THREAD_SIZE, THREAD_SIZE, 1)]
|
||||
void NoiseCS(uint3 ID : SV_DispatchThreadID) {
|
||||
float2 uv = (float2)ID.xy * _CalcTexel;
|
||||
float noise = 0;
|
||||
[unroll(WAVE_MAX_CNT)]for (uint i = 0; i < _WaveCnt; i++) {
|
||||
float2 uvE = frac(uv + _WaveUVShift [i]);
|
||||
float4 lc = lerpCoef(uvE);
|
||||
uvE -= 0.5;
|
||||
float density = _WaveData[i].x;
|
||||
float height = _WaveData[i].y;
|
||||
float index = _WaveData[i].z;
|
||||
noise += genNoise(uvE, lc, density, _WaveNoiseDir[i], index * 20) * height;
|
||||
}
|
||||
_BufNoiseRW[idToIdx(ID.xy, _CalcResUI)] = noise;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
float3 calcNormal(uint2 ID) {
|
||||
uint idx0 = idToIdx(ID.xy, _CalcResUI);
|
||||
uint idx1 = idToIdxWrap(ID.xy + uint2(2, 0), _CalcResUI);
|
||||
uint idx2 = idToIdxWrap(ID.xy + uint2(0, 2), _CalcResUI);
|
||||
float h0 = _BufNoise [idx0];
|
||||
float h1 = _BufNoise [idx1];
|
||||
float h2 = _BufNoise [idx2];
|
||||
float span = _CalcTexel * 2;
|
||||
float3 v0 = float3(span, 0, h1 - h0);
|
||||
float3 v1 = float3(0, span, h2 - h0);
|
||||
return -normalize(cross(v0, v1));
|
||||
}
|
||||
|
||||
float2 calcOffset(float3 ray) {
|
||||
#if EXTEND_RAY
|
||||
return ray.xy / ray.z + _DrawOffset;
|
||||
#else
|
||||
return ray.xy + _DrawOffset;
|
||||
#endif
|
||||
}
|
||||
|
||||
[numthreads(THREAD_SIZE, THREAD_SIZE, 1)]
|
||||
void RefractCS(uint3 ID : SV_DispatchThreadID) {
|
||||
float3 norm = calcNormal(ID.xy);
|
||||
float3 ray = refract(_LightDir, norm, _Eta.g);
|
||||
uint idx = idToIdx(ID.xy, _CalcResUI);
|
||||
_BufRefractRW[idx].offset = calcOffset(ray);
|
||||
}
|
||||
|
||||
[numthreads(THREAD_SIZE, THREAD_SIZE, 1)]
|
||||
void RefractCS_CACalcSeparate(uint3 ID : SV_DispatchThreadID) {
|
||||
float3 norm = calcNormal(ID.xy);
|
||||
float3 rayR = refract(_LightDir, norm, _Eta.r);
|
||||
float3 rayG = refract(_LightDir, norm, _Eta.g);
|
||||
float3 rayB = refract(_LightDir, norm, _Eta.b);
|
||||
uint3 idx = idToIdxRGB(ID.xy, _CalcResUI);
|
||||
_BufRefractRW[idx.r].offset = calcOffset(rayR);
|
||||
_BufRefractRW[idx.g].offset = calcOffset(rayG);
|
||||
_BufRefractRW[idx.b].offset = calcOffset(rayB);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
float calcArea(float3x2 v) {
|
||||
#if STYLE_A
|
||||
float2 v01 = v[1] - v[0];
|
||||
float2 v02 = v[2] - v[0];
|
||||
return abs(v01.x * v02.y - v02.x * v01.y);
|
||||
#elif STYLE_B
|
||||
return distance(v[0], v[1]) * distance(v[0], v[2]);
|
||||
#else // STYLE_C
|
||||
return distance(v[0], v[1]) * distance(v[0], v[2]) * distance(v[1], v[2]);
|
||||
#endif
|
||||
}
|
||||
|
||||
float3x2 getPt3(uint3 idx) {
|
||||
float3x2 pt;
|
||||
pt[0] = _BufRefractRW[idx[0]].offset * _CalcTexelInv;
|
||||
pt[1] = _BufRefractRW[idx[1]].offset * _CalcTexelInv + float2(2, 0);
|
||||
pt[2] = _BufRefractRW[idx[2]].offset * _CalcTexelInv + float2(1, 2);
|
||||
return pt;
|
||||
}
|
||||
|
||||
float calcColor(uint3 idx) {
|
||||
#if STYLE_A
|
||||
float baseArea = 4.0;
|
||||
#elif STYLE_B
|
||||
float baseArea = 4.0 * 1.118034;
|
||||
#else // STYLE_C
|
||||
float baseArea = 8.0 * 1.118034 * 1.118034;
|
||||
#endif
|
||||
float area = calcArea(getPt3(idx));
|
||||
area = max(area, 0.000001);
|
||||
float c = pow(baseArea / area, _Gamma) * _Brightness;
|
||||
return min(c, _Clamp);
|
||||
}
|
||||
|
||||
[numthreads(THREAD_SIZE, THREAD_SIZE, 1)]
|
||||
void ColorCS(uint3 ID : SV_DispatchThreadID) {
|
||||
uint m = _CalcResUI - 1;
|
||||
uint3 idxs;
|
||||
idxs[0] = idToIdxWrap(ID.xy + uint2(m, m), _CalcResUI);
|
||||
idxs[1] = idToIdxWrap(ID.xy + uint2(1, m), _CalcResUI);
|
||||
idxs[2] = idToIdxWrap(ID.xy + uint2(0, 1), _CalcResUI);
|
||||
|
||||
float col = calcColor(idxs);
|
||||
|
||||
uint idx = idToIdx(ID.xy, _CalcResUI);
|
||||
_BufRefractRW[idx].color = col.rrr;
|
||||
}
|
||||
|
||||
[numthreads(THREAD_SIZE, THREAD_SIZE, 1)]
|
||||
void ColorCS_CACalcSeparate(uint3 ID : SV_DispatchThreadID) {
|
||||
uint m = _CalcResUI - 1;
|
||||
uint3x3 idxs;
|
||||
idxs[0] = idToIdxWrapRGB(ID.xy + uint2(m, m), _CalcResUI);
|
||||
idxs[1] = idToIdxWrapRGB(ID.xy + uint2(1, m), _CalcResUI);
|
||||
idxs[2] = idToIdxWrapRGB(ID.xy + uint2(0, 1), _CalcResUI);
|
||||
idxs = transpose(idxs);
|
||||
|
||||
float3 col;
|
||||
col.r = calcColor(idxs[0]);
|
||||
col.g = calcColor(idxs[1]);
|
||||
col.b = calcColor(idxs[2]);
|
||||
|
||||
uint3 idx = idToIdxRGB(ID.xy, _CalcResUI);
|
||||
_BufRefractRW[idx.r].color = float3(col.r, 0, 0);
|
||||
_BufRefractRW[idx.g].color = float3(0, col.g, 0);
|
||||
_BufRefractRW[idx.b].color = float3(0, 0, col.b);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------- for Debug
|
||||
#pragma kernel DebugNoiseCS
|
||||
[numthreads(THREAD_SIZE, THREAD_SIZE, 1)]
|
||||
void DebugNoiseCS(uint3 ID : SV_DispatchThreadID) {
|
||||
uint idx = idToIdx(ID.xy, _CalcResUI);
|
||||
_BufRefractRW[idx].color = pow(_BufNoise [idx] * _Brightness * 1000 + 0.5, _Gamma * 5);
|
||||
_BufRefractRW[idx].offset = 0;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf24bd9d2b71b65458b930c520b46e99
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 2097156
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,178 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
Shader "Hidden/WaterCausticsModules/TexGenShader" {
|
||||
Properties {
|
||||
_MainTex ("Texture", 2D) = "black" { }
|
||||
}
|
||||
|
||||
SubShader {
|
||||
Tags { "RenderType" = "Opaque" }
|
||||
LOD 100
|
||||
|
||||
// -------------------------------------------- Pass0 DrawCaustics
|
||||
Pass {
|
||||
AlphaToMask Off Cull Off ZWrite Off ZTest Always
|
||||
Blend One One
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
#pragma multi_compile_local_fragment _ _USE_RGB
|
||||
|
||||
struct appdata {
|
||||
float4 vertex : POSITION;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 pos : SV_POSITION;
|
||||
float3 color : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct CausticsBufStruct {
|
||||
float2 offset;
|
||||
float3 color;
|
||||
};
|
||||
|
||||
StructuredBuffer<CausticsBufStruct> _BufRefract;
|
||||
|
||||
v2f vert(appdata v) {
|
||||
CausticsBufStruct buf = _BufRefract[(uint)v.vertex.z];
|
||||
v2f o;
|
||||
float2 pos = v.vertex.xy + buf.offset * 2;
|
||||
o.pos = float4(pos.xy, 0, 1);
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
o.pos.y *= -1;
|
||||
#endif
|
||||
o.color = buf.color;
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag(v2f i) : SV_Target {
|
||||
#if defined(_USE_RGB)
|
||||
return max(0, i.color.rgb).rgbg;
|
||||
#else
|
||||
return max(0, i.color.r).rrrr;
|
||||
#endif
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// -------------------------------------------- Pass1 Post Process Effect
|
||||
Pass {
|
||||
Cull Off ZTest Always ZWrite Off Blend Off
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
#pragma multi_compile_local _ _USE_RGB
|
||||
#pragma multi_compile_local _ _SAMPLE4
|
||||
#pragma multi_compile_local_fragment _ _BRIGHTNESS_ADJ
|
||||
|
||||
struct vIn {
|
||||
float4 vertex : POSITION;
|
||||
half2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 pos : SV_POSITION;
|
||||
#if defined(_SAMPLE4)
|
||||
half2 uvG[4] : TEXCOORD0;
|
||||
#if defined(_USE_RGB)
|
||||
half2 uvR[4] : TEXCOORD4;
|
||||
half2 uvB[4] : TEXCOORD8;
|
||||
#endif
|
||||
#else // _SAMPLE1
|
||||
half2 uvG[1] : TEXCOORD0;
|
||||
#if defined(_USE_RGB)
|
||||
half2 uvR[1] : TEXCOORD1;
|
||||
half2 uvB[1] : TEXCOORD2;
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
half4 _MainTex_TexelSize;
|
||||
half4 _Offset;
|
||||
half2 _OffsetColor;
|
||||
|
||||
v2f vert(vIn v) {
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
#if defined(_SAMPLE4)
|
||||
half4 ofs = _MainTex_TexelSize.xyxy * _Offset.xyzw;
|
||||
half4 uv0 = v.uv.xyxy + ofs.xyzw;
|
||||
half4 uv1 = v.uv.xyxy - ofs.xyzw;
|
||||
o.uvG[0] = uv0.xy;
|
||||
o.uvG[1] = uv0.zw;
|
||||
o.uvG[2] = uv1.xy;
|
||||
o.uvG[3] = uv1.zw;
|
||||
#if defined(_USE_RGB)
|
||||
half2 ofc = _OffsetColor.xy;
|
||||
o.uvR[0] = uv0.xy - ofc;
|
||||
o.uvR[1] = uv0.zw - ofc;
|
||||
o.uvR[2] = uv1.xy - ofc;
|
||||
o.uvR[3] = uv1.zw - ofc;
|
||||
o.uvB[0] = uv0.xy + ofc;
|
||||
o.uvB[1] = uv0.zw + ofc;
|
||||
o.uvB[2] = uv1.xy + ofc;
|
||||
o.uvB[3] = uv1.zw + ofc;
|
||||
#endif
|
||||
#else // _SAMPLE1
|
||||
o.uvG[0] = v.uv.xy;
|
||||
#if defined(_USE_RGB)
|
||||
half2 ofc = _OffsetColor.xy;
|
||||
o.uvR[0] = o.uvG[0] - ofc;
|
||||
o.uvB[0] = o.uvG[0] + ofc;
|
||||
#endif
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
Texture2D_half _MainTex;
|
||||
SamplerState sampler_MainTex;
|
||||
half _Gamma;
|
||||
half _Brightness;
|
||||
|
||||
#if defined(_SAMPLE4)
|
||||
half sample(const half2 uv[4], const int channel) {
|
||||
half c0 = _MainTex.Sample(sampler_MainTex, uv[0])[channel];
|
||||
half c1 = _MainTex.Sample(sampler_MainTex, uv[1])[channel];
|
||||
half c2 = _MainTex.Sample(sampler_MainTex, uv[2])[channel];
|
||||
half c3 = _MainTex.Sample(sampler_MainTex, uv[3])[channel];
|
||||
return (c0 + c1 + c2 + c3) * 0.25;
|
||||
}
|
||||
#else // _SAMPLE1
|
||||
half sample(const half2 uv[1], const int channel) {
|
||||
return _MainTex.Sample(sampler_MainTex, uv[0])[channel];
|
||||
}
|
||||
#endif
|
||||
|
||||
half4 frag(v2f i) : COLOR {
|
||||
half4 c;
|
||||
#if defined(_USE_RGB)
|
||||
c.r = sample(i.uvR, 0);
|
||||
c.g = sample(i.uvG, 1);
|
||||
c.b = sample(i.uvB, 2);
|
||||
#if defined(_BRIGHTNESS_ADJ)
|
||||
c.rgb = pow(c.rgb, _Gamma) * _Brightness;
|
||||
#endif
|
||||
c.a = c.g;
|
||||
#else
|
||||
half s = sample(i.uvG, 0);
|
||||
#if defined(_BRIGHTNESS_ADJ)
|
||||
s = pow(s, _Gamma) * _Brightness;
|
||||
#endif
|
||||
c.rgba = s.rrrr;
|
||||
#endif
|
||||
return c;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e031a2e28107901449265842632577a4
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: UIRawImagePreview
|
||||
m_Shader: {fileID: 4800000, guid: 574921246e55ae74b832fa9b7204d519, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats: []
|
||||
m_Colors: []
|
||||
m_BuildTextureStacks: []
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1628abb22c4c2e441a7eeffe50894237
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
Shader "Hidden/WaterCausticsModules/UIRawImagePreview" {
|
||||
Properties {
|
||||
_MainTex ("Texture", 2D) = "Black" { }
|
||||
}
|
||||
SubShader {
|
||||
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" "CanUseSpriteAtlas" = "True" }
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest Always
|
||||
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata {
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert(appdata v) {
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag(v2f i) : SV_Target {
|
||||
float4 col;
|
||||
col.rgb = tex2D(_MainTex, i.uv).rgb;
|
||||
col.a = 1;
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 574921246e55ae74b832fa9b7204d519
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
//
|
||||
// Description : Array and textureless GLSL 2D/3D/4D simplex
|
||||
// noise functions.
|
||||
// Author : Ian McEwan, Ashima Arts.
|
||||
// Maintainer : stegu
|
||||
// Lastmod : 20201014 (stegu)
|
||||
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
|
||||
// Distributed under the MIT License. See LICENSE file.
|
||||
// https://github.com/ashima/webgl-noise
|
||||
// https://github.com/stegu/webgl-noise
|
||||
//
|
||||
|
||||
float3 mod289(float3 x) {
|
||||
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
||||
}
|
||||
|
||||
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) {
|
||||
v.z += 0.111111;
|
||||
const float2 C = float2(1.0 / 6.0, 1.0 / 3.0) ;
|
||||
const float4 D = float4(0.0, 0.5, 1.0, 2.0);
|
||||
|
||||
// First corner
|
||||
float3 i = floor(v + dot(v, C.yyy));
|
||||
float3 x0 = v - i + dot(i, C.xxx) ;
|
||||
|
||||
// Other corners
|
||||
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);
|
||||
|
||||
// x0 = x0 - 0.0 + 0.0 * C.xxx;
|
||||
// x1 = x0 - i1 + 1.0 * C.xxx;
|
||||
// x2 = x0 - i2 + 2.0 * C.xxx;
|
||||
// x3 = x0 - 1.0 + 3.0 * C.xxx;
|
||||
float3 x1 = x0 - i1 + C.xxx;
|
||||
float3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
|
||||
float3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
|
||||
|
||||
// Permutations
|
||||
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));
|
||||
|
||||
// Gradients: 7x7 points over a square, mapped onto an octahedron.
|
||||
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
|
||||
float n_ = 0.142857142857; // 1.0/7.0
|
||||
float3 ns = n_ * D.wyz - D.xzx;
|
||||
|
||||
float4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
|
||||
|
||||
float4 x_ = floor(j * ns.z);
|
||||
float4 y_ = floor(j - 7.0 * x_); // mod(j,N)
|
||||
|
||||
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 = float4(lessThan(b0,0.0))*2.0 - 1.0;
|
||||
//float4 s1 = float4(lessThan(b1,0.0))*2.0 - 1.0;
|
||||
float4 s0 = floor(b0) * 2.0 + 1.0;
|
||||
float4 s1 = floor(b1) * 2.0 + 1.0;
|
||||
float4 sh = -step(h, float4(0, 0, 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);
|
||||
|
||||
// Normalize gradients
|
||||
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;
|
||||
|
||||
// Mix final noise value
|
||||
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)));
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93c00ef01897fb84598c650ffc36d562
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user