This commit is contained in:
SoulliesOfficial
2025-07-21 05:42:20 -04:00
parent e483cfe502
commit bae0bfbc20
533 changed files with 172709 additions and 125965 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fa89a0fdb680e154f89c18f1a7fea2c6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,351 @@
#ifndef XUANXUAN_UTILITY
#define XUANXUAN_UTILITY
//引入自UnityCG.cginc
#define UNITY_PI 3.14159265359f
#define UNITY_TWO_PI 6.28318530718f
#define UNITY_FOUR_PI 12.56637061436f
#define UNITY_INV_PI 0.31830988618f
#define UNITY_INV_TWO_PI 0.15915494309f
#define UNITY_INV_FOUR_PI 0.07957747155f
#define UNITY_HALF_PI 1.57079632679f
#define UNITY_INV_HALF_PI 0.636619772367f
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
inline half NB_Remap(half x, half inMin, half inMax, half outMin, half outMax)
{
// x= clamp(x,inMin,inMax);
return saturate((x - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;
}
inline half NB_RemapNoClamp(half x, half inMin, half inMax, half outMin, half outMax)
{
// x= clamp(x,inMin,inMax);
return ((x - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;
}
//原生SmoothStep开销很大https://zhuanlan.zhihu.com/p/34629262
//在很多时候可以用简单线性映射代替。
half SimpleSmoothstep(half min,half max,half interp)
{
return saturate((interp - min)/(max-min));
}
half4 TryLinearize(half4 color)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return pow(color, 2.2f);
#else
return color;
#endif
}
half4 TryLinearizeWithoutAlpha(half4 color)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return half4(pow(color.rgb, 2.2f), color.a);
#else
return color;
#endif
}
half3 TryLinearize(half3 color)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return pow(color, 2.2f);
#else
return color;
#endif
}
half2 TryLinearize(half2 color)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return pow(color, 2.2f);
#else
return color;
#endif
}
half TryLinearize(half color)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return pow(color, 2.2f);
#else
return color;
#endif
}
half4 tex2D_TryLinearizeWithoutAlpha(sampler2D tex, float2 uv)
{
#if defined(UNITY_COLORSPACE_GAMMA)
return TryLinearizeWithoutAlpha(tex2D(tex, uv));
#else
return tex2D(tex, uv);
#endif
}
inline float LinearToGammaSpaceExact (float value)
{
if (value <= 0.0F)
return 0.0F;
else if (value <= 0.0031308F)
return 12.92F * value;
else if (value < 1.0F)
return 1.055F * pow(value, 0.4166667F) - 0.055F;
else
return pow(value, 0.45454545F);
}
// real FastSRGBToLinear(real c)
// {
// return c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878);
// }
float2 Rotate_Radians_float(float2 UV, float2 Center, float Rotation)
{
if(Rotation == 0)
{
return UV;
}
// Rotation = Rotation / 180 * 3.14; //从角度转为弧度。
Rotation *= 0.01745329222; //从角度转为弧度。
UV -= Center;
float s = sin(Rotation);
float c = cos(Rotation);
float2x2 rMatrix = float2x2(c, -s, s, c);
rMatrix *= 0.5;
rMatrix += 0.5;
rMatrix = rMatrix * 2 - 1;
UV.xy = mul(UV.xy, rMatrix);
UV += Center;
return UV;
}
inline half luminance(half3 color)
{
return dot(color, float3(0.2126f, 0.7152f, 0.0722f));
}
inline half DepthFactor(float Z, float near, float far)
{
Z = saturate((Z-near)/(far - near));
return Z;
}
//抽自Unity.cginc
inline half3 LinearToGammaSpace (half3 linRGB)
{
linRGB = max(linRGB, half3(0.h, 0.h, 0.h));
// An almost-perfect approximation from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
return max(1.055h * pow(linRGB, 0.416666667h) - 0.055h, 0.h);
// Exact version, useful for debugging.
//return half3(LinearToGammaSpaceExact(linRGB.r), LinearToGammaSpaceExact(linRGB.g), LinearToGammaSpaceExact(linRGB.b));
}
//ASE
float2 voronoihash1( float2 p )
{
p = float2( dot( p, float2( 127.1, 311.7 ) ), dot( p, float2( 269.5, 183.3 ) ) );
return frac( sin( p ) *43758.5453);
}
//ASE
float voronoi1( float2 v, float time, inout float2 id, inout float2 mr, float smoothness )
{
float2 n = floor( v );
float2 f = frac( v );
float F1 = 8.0;
float F2 = 8.0; float2 mg = 0;
for ( int j = -1; j <= 1; j++ )
{
for ( int i = -1; i <= 1; i++ )
{
float2 g = float2( i, j );
float2 o = voronoihash1( n + g );
o = ( sin( time + o * 6.2831 ) * 0.5 + 0.5 ); float2 r = f - g - o;
float d = 0.5 * dot( r, r );
if( d<F1 ) {
F2 = F1;
F1 = d; mg = g; mr = r; id = o;
} else if( d<F2 ) {
F2 = d;
}
}
}
return F2 - F1;
}
void voroniForgraphfunc_half(half2 uv,half angle,half scale,out float outVoroni1 )
{
uv = uv*scale;
float2 id1 = 0;
float2 uv1 = 0;
outVoroni1 = voronoi1( uv, angle, id1, uv1, 0 );
}
inline float2 unity_voronoi_noise_randomVector (float2 UV, float offset)
{
float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
UV = frac(sin(mul(UV, m)) * 46839.32);
return float2(sin(UV.y*+offset)*0.5+0.5, cos(UV.x*offset)*0.5+0.5);
}
void Unity_Voronoi_float(float2 UV, float AngleOffset, float CellDensity, out float Out, out float Cells)
{
float2 g = floor(UV * CellDensity);
float2 f = frac(UV * CellDensity);
float t = 8.0;
float3 res = float3(8.0, 0.0, 0.0);
for(int y=-1; y<=1; y++)
{
for(int x=-1; x<=1; x++)
{
float2 lattice = float2(x,y);
float2 offset = unity_voronoi_noise_randomVector(lattice + g, AngleOffset);
float d = distance(lattice + offset, f);
if(d < res.x)
{
res = float3(d, offset.x, offset.y);
Out = res.x;
Cells = res.y;
}
}
}
}
void Unity_Blend_Overlay_float4(float4 Base, float4 Blend, float Opacity, out float4 Out)
{
float4 result1 = 1.0 - 2.0 * (1.0 - Base) * (1.0 - Blend);
float4 result2 = 2.0 * Base * Blend;
float4 zeroOrOne = step(Base, 0.5);
Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
Out = lerp(Base, Out, Opacity);
}
void Unity_Blend_HardLight_half(half Base, half Blend, half Opacity, out half Out)
{
half result1 = 1.0 - 2.0 * (1.0 - Base) * (1.0 - Blend);
half result2 = 2.0 * Base * Blend;
half zeroOrOne = step(Blend, 0.5);
Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
Out = lerp(Base, Out, Opacity);
}
float2 randomGradient(float2 p) {
p = p + 0.02;
float x = dot(p, float2(123.4, 234.5));
float y = dot(p, float2(234.5, 345.6));
float2 gradient = float2(x, y);
gradient = sin(gradient);
gradient = gradient * 43758.5453;
// part 4.5 - update noise function with time
// gradient = sin(gradient + u_time);
return gradient;
// gradient = sin(gradient);
// return gradient;
}
#include "./jp.keijiro.noiseshader/Shader/SimplexNoise3D.hlsl"
half SimplexNoise(float2 uv,float time)
{
return SimplexNoise(float3(uv,time))*0.5+0.5;
}
#include "./jp.keijiro.noiseshader/Shader/ClassicNoise3D.hlsl"
half PerlinNoise(float2 uv,float time)
{
return ClassicNoise(float3(uv,time))*0.5+0.5;
}
float2 PolarCoordinates(float2 UV, float2 _PCCenter)
{
// float2 uvsource = float2(0, 0);
float2 delta = UV - _PCCenter.xy;//校准UV到中心
float radius = length(delta) * 2;
float angle = atan2(delta.x, delta.y) * UNITY_INV_TWO_PI ;
return float2(angle, radius);//翻转可以调整横向和纵向。
}
float2 PolarCoordinatesStrengthAndST(float2 UVBeforPollarCoord,float2 UVAfterPolarCoord,float polarStrenth ,float4 tex_ST)
{
UVAfterPolarCoord = UVAfterPolarCoord*tex_ST.xy + tex_ST.zw;//利用相应功能贴图的坐标对ST进行修改。
UVAfterPolarCoord = lerp(UVBeforPollarCoord, UVAfterPolarCoord, polarStrenth);
return UVAfterPolarCoord;
}
//极坐标//transformation为极坐标强度
float2 PolarCoordinates(float2 UV, float3 _PCCenter, float4 tex_ST)
{
// float2 uvsource = float2(0, 0);
//
// float2 delta = UV - _PCCenter.xy;//校准UV到中心
// float radius = length(delta) * 2;
// float angle = atan2(delta.x, delta.y) * UNITY_INV_TWO_PI ;
// uvsource = float2(angle, radius);//翻转可以调整横向和纵向。
// uvsource = uvsource*tex_ST.xy + tex_ST.zw;//利用相应功能贴图的坐标对ST进行修改。
// uvsource = lerp(UV, uvsource, _PCCenter.z);
// return uvsource;
//拆分成两步第一步求极坐标太耗atan一般源UV都是一样的只是ST不同。
float2 uvsource = PolarCoordinates(UV,_PCCenter.xy);
uvsource = PolarCoordinatesStrengthAndST(UV,uvsource,_PCCenter.z,tex_ST);
return uvsource;
}
float2 CylinderCoordinate(float3 positionOS)
{
float angle = atan2(positionOS.x,positionOS.z)* UNITY_INV_TWO_PI ;
return float2(angle,positionOS.y);
}
float2 UVOffsetAnimaiton(float2 UV,half2 OffsetSpeed,float time)
{
float2 newUV = float2(OffsetSpeed.x*time+UV.x,OffsetSpeed.y*time+UV.y);
return newUV;
}
half3 rgb2hsv(half3 c)
{
half4 K = half4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
half4 p = lerp(half4(c.bg, K.wz), half4(c.gb, K.xy), step(c.b, c.g));
half4 q = lerp(half4(p.xyw, c.r), half4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
half3 hsv2rgb(half3 c)
{
half4 K = half4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
half3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y);
}
half3 ColorSaturate(half3 color, half colorSaturation)
{
half3 lum = luminance(color);
return max(0, lerp(lum, color, colorSaturation));
}
half2 Rotate(half2 v, half cos0, half sin0)
{
return half2(v.x * cos0 - v.y * sin0,
v.x * sin0 + v.y * cos0);
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9f34986983f558c40a7e30a353dc3c34
timeCreated: 1684725413

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e95a8f1b5d23f4141b5121f98f90f10a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
Noise Shader Library for Unity
==============================
**NoiseShader** is a Unity package that provides 2D/3D gradient noise
functions written in the shader language. These functions are ported from the
[webgl-noise] library that is originally written by Stefan Gustavson and Ahima
Arts.
[webgl-noise]: https://github.com/ashima/webgl-noise
At the moment, it contains the following functions:
- Classic Perlin noise (2D/3D)
- Periodic Perlin noise (2D/3D)
- Simplex noise (2D/3D)
- Analytical derivatives of simplex noise (2D/3D)
How To Install
--------------
This package uses the [scoped registry] feature to resolve package dependencies.
Please add the following sections to the manifest file (Packages/manifest.json).
[scoped registry]: https://docs.unity3d.com/Manual/upm-scoped.html
To the `scopedRegistries` section:
```
{
"name": "Keijiro",
"url": "https://registry.npmjs.com",
"scopes": [ "jp.keijiro" ]
}
```
To the `dependencies` section:
```
"jp.keijiro.noiseshader": "2.0.0"
```
After changes, the manifest file should look like below:
```
{
"scopedRegistries": [
{
"name": "Keijiro",
"url": "https://registry.npmjs.com",
"scopes": [ "jp.keijiro" ]
}
],
"dependencies": {
"jp.keijiro.noiseshader": "2.0.0",
...
```

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b92baefe22663afa5ad0ab303b3dcc20
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 77b21af505211947eb730e678820eb8b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,66 @@
//
// GLSL textureless classic 2D noise "cnoise",
// with an RSL-style periodic variant "pnoise".
// Author: Stefan Gustavson (stefan.gustavson@liu.se)
// Version: 2011-08-22
//
// Many thanks to Ian McEwan of Ashima Arts for the
// ideas for permutation and gradient selection.
//
// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
// Distributed under the MIT license. See LICENSE file.
// https://github.com/ashima/webgl-noise
//
#ifndef _INCLUDE_JP_KEIJIRO_NOISESHADER_CLASSIC_NOISE_2D_HLSL_
#define _INCLUDE_JP_KEIJIRO_NOISESHADER_CLASSIC_NOISE_2D_HLSL_
#include "Common.hlsl"
float ClassicNoise_impl(float2 pi0, float2 pf0, float2 pi1, float2 pf1)
{
pi0 = wglnoise_mod289(pi0); // To avoid truncation effects in permutation
pi1 = wglnoise_mod289(pi1);
float4 ix = float2(pi0.x, pi1.x).xyxy;
float4 iy = float2(pi0.y, pi1.y).xxyy;
float4 fx = float2(pf0.x, pf1.x).xyxy;
float4 fy = float2(pf0.y, pf1.y).xxyy;
float4 i = wglnoise_permute(wglnoise_permute(ix) + iy);
float4 phi = i / 41 * 3.14159265359 * 2;
float2 g00 = float2(cos(phi.x), sin(phi.x));
float2 g10 = float2(cos(phi.y), sin(phi.y));
float2 g01 = float2(cos(phi.z), sin(phi.z));
float2 g11 = float2(cos(phi.w), sin(phi.w));
float n00 = dot(g00, float2(fx.x, fy.x));
float n10 = dot(g10, float2(fx.y, fy.y));
float n01 = dot(g01, float2(fx.z, fy.z));
float n11 = dot(g11, float2(fx.w, fy.w));
float2 fade_xy = wglnoise_fade(pf0);
float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x);
float n_xy = lerp(n_x.x, n_x.y, fade_xy.y);
return 1.44 * n_xy;
}
// Classic Perlin noise
float ClassicNoise(float2 p)
{
float2 i = floor(p);
float2 f = frac(p);
return ClassicNoise_impl(i, f, i + 1, f - 1);
}
// Classic Perlin noise, periodic variant
float PeriodicNoise(float2 p, float2 rep)
{
float2 i0 = wglnoise_mod(floor(p), rep);
float2 i1 = wglnoise_mod(i0 + 1, rep);
float2 f = frac(p);
return ClassicNoise_impl(i0, f, i1, f - 1);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8ec48974b9689234f9a4a7c1927e2a7b
timeCreated: 1498976326
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,93 @@
//
// GLSL textureless classic 3D noise "cnoise",
// with an RSL-style periodic variant "pnoise".
// Author: Stefan Gustavson (stefan.gustavson@liu.se)
// Version: 2011-10-11
//
// Many thanks to Ian McEwan of Ashima Arts for the
// ideas for permutation and gradient selection.
//
// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
// Distributed under the MIT license. See LICENSE file.
// https://github.com/ashima/webgl-noise
//
#ifndef _INCLUDE_JP_KEIJIRO_NOISESHADER_CLASSIC_NOISE_3D_HLSL_
#define _INCLUDE_JP_KEIJIRO_NOISESHADER_CLASSIC_NOISE_3D_HLSL_
#include "Common.hlsl"
float ClassicNoise_impl(float3 pi0, float3 pf0, float3 pi1, float3 pf1)
{
pi0 = wglnoise_mod289(pi0);
pi1 = wglnoise_mod289(pi1);
float4 ix = float4(pi0.x, pi1.x, pi0.x, pi1.x);
float4 iy = float4(pi0.y, pi0.y, pi1.y, pi1.y);
float4 iz0 = pi0.z;
float4 iz1 = pi1.z;
float4 ixy = wglnoise_permute(wglnoise_permute(ix) + iy);
float4 ixy0 = wglnoise_permute(ixy + iz0);
float4 ixy1 = wglnoise_permute(ixy + iz1);
float4 gx0 = lerp(-1, 1, frac(floor(ixy0 / 7) / 7));
float4 gy0 = lerp(-1, 1, frac(floor(ixy0 % 7) / 7));
float4 gz0 = 1 - abs(gx0) - abs(gy0);
bool4 zn0 = gz0 < -0.01;
gx0 += zn0 * (gx0 < -0.01 ? 1 : -1);
gy0 += zn0 * (gy0 < -0.01 ? 1 : -1);
float4 gx1 = lerp(-1, 1, frac(floor(ixy1 / 7) / 7));
float4 gy1 = lerp(-1, 1, frac(floor(ixy1 % 7) / 7));
float4 gz1 = 1 - abs(gx1) - abs(gy1);
bool4 zn1 = gz1 < -0.01;
gx1 += zn1 * (gx1 < -0.01 ? 1 : -1);
gy1 += zn1 * (gy1 < -0.01 ? 1 : -1);
float3 g000 = normalize(float3(gx0.x, gy0.x, gz0.x));
float3 g100 = normalize(float3(gx0.y, gy0.y, gz0.y));
float3 g010 = normalize(float3(gx0.z, gy0.z, gz0.z));
float3 g110 = normalize(float3(gx0.w, gy0.w, gz0.w));
float3 g001 = normalize(float3(gx1.x, gy1.x, gz1.x));
float3 g101 = normalize(float3(gx1.y, gy1.y, gz1.y));
float3 g011 = normalize(float3(gx1.z, gy1.z, gz1.z));
float3 g111 = normalize(float3(gx1.w, gy1.w, gz1.w));
float n000 = dot(g000, pf0);
float n100 = dot(g100, float3(pf1.x, pf0.y, pf0.z));
float n010 = dot(g010, float3(pf0.x, pf1.y, pf0.z));
float n110 = dot(g110, float3(pf1.x, pf1.y, pf0.z));
float n001 = dot(g001, float3(pf0.x, pf0.y, pf1.z));
float n101 = dot(g101, float3(pf1.x, pf0.y, pf1.z));
float n011 = dot(g011, float3(pf0.x, pf1.y, pf1.z));
float n111 = dot(g111, pf1);
float3 fade_xyz = wglnoise_fade(pf0);
float4 n_z = lerp(float4(n000, n100, n010, n110),
float4(n001, n101, n011, n111), fade_xyz.z);
float2 n_yz = lerp(n_z.xy, n_z.zw, fade_xyz.y);
float n_xyz = lerp(n_yz.x, n_yz.y, fade_xyz.x);
return 1.46 * n_xyz;
}
// Classic Perlin noise
float ClassicNoise(float3 p)
{
float3 i = floor(p);
float3 f = frac(p);
return ClassicNoise_impl(i, f, i + 1, f - 1);
}
// Classic Perlin noise, periodic variant
float PeriodicNoise(float3 p, float3 rep)
{
float3 i0 = wglnoise_mod(floor(p), rep);
float3 i1 = wglnoise_mod(i0 + 1, rep);
float3 f = frac(p);
return ClassicNoise_impl(i0, f, i1, f - 1);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2688615dc3cd4ed4cbca4cd0135d8e8a
timeCreated: 1498976326
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,64 @@
#ifndef _INCLUDE_JP_KEIJIRO_NOISESHADER_COMMON_HLSL_
#define _INCLUDE_JP_KEIJIRO_NOISESHADER_COMMON_HLSL_
float wglnoise_mod(float x, float y)
{
return x - y * floor(x / y);
}
float2 wglnoise_mod(float2 x, float2 y)
{
return x - y * floor(x / y);
}
float3 wglnoise_mod(float3 x, float3 y)
{
return x - y * floor(x / y);
}
float4 wglnoise_mod(float4 x, float4 y)
{
return x - y * floor(x / y);
}
float2 wglnoise_fade(float2 t)
{
return t * t * t * (t * (t * 6 - 15) + 10);
}
float3 wglnoise_fade(float3 t)
{
return t * t * t * (t * (t * 6 - 15) + 10);
}
float wglnoise_mod289(float x)
{
return x - floor(x / 289) * 289;
}
float2 wglnoise_mod289(float2 x)
{
return x - floor(x / 289) * 289;
}
float3 wglnoise_mod289(float3 x)
{
return x - floor(x / 289) * 289;
}
float4 wglnoise_mod289(float4 x)
{
return x - floor(x / 289) * 289;
}
float3 wglnoise_permute(float3 x)
{
return wglnoise_mod289((x * 34 + 1) * x);
}
float4 wglnoise_permute(float4 x)
{
return wglnoise_mod289((x * 34 + 1) * x);
}
#endif

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 443fb5ca2e0ec42bc8a96eb43c8470fe
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,63 @@
//
// Description : Array and textureless GLSL 2D simplex noise function.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : ijm
// Lastmod : 20110822 (ijm)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise
//
#ifndef _INCLUDE_JP_KEIJIRO_NOISESHADER_SIMPLEX_NOISE_2D_HLSL_
#define _INCLUDE_JP_KEIJIRO_NOISESHADER_SIMPLEX_NOISE_2D_HLSL_
#include "Common.hlsl"
float3 SimplexNoiseGrad(float2 v)
{
const float C1 = (3 - sqrt(3)) / 6;
const float C2 = (sqrt(3) - 1) / 2;
// First corner
float2 i = floor(v + dot(v, C2));
float2 x0 = v - i + dot(i, C1);
// Other corners
float2 i1 = x0.x > x0.y ? float2(1, 0) : float2(0, 1);
float2 x1 = x0 + C1 - i1;
float2 x2 = x0 + C1 * 2 - 1;
// Permutations
i = wglnoise_mod289(i); // Avoid truncation effects in permutation
float3 p = wglnoise_permute( i.y + float3(0, i1.y, 1));
p = wglnoise_permute(p + i.x + float3(0, i1.x, 1));
// Gradients: 41 points uniformly over a unit circle.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
float3 phi = p / 41 * 3.14159265359 * 2;
float2 g0 = float2(cos(phi.x), sin(phi.x));
float2 g1 = float2(cos(phi.y), sin(phi.y));
float2 g2 = float2(cos(phi.z), sin(phi.z));
// Compute noise and gradient at P
float3 m = float3(dot(x0, x0), dot(x1, x1), dot(x2, x2));
float3 px = float3(dot(g0, x0), dot(g1, x1), dot(g2, x2));
m = max(0.5 - m, 0);
float3 m3 = m * m * m;
float3 m4 = m * m3;
float3 temp = -8 * m3 * px;
float2 grad = m4.x * g0 + temp.x * x0 +
m4.y * g1 + temp.y * x1 +
m4.z * g2 + temp.z * x2;
return 99.2 * float3(grad, dot(m4, px));
}
float SimplexNoise(float2 v)
{
return SimplexNoiseGrad(v).z;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 66b8605d5d2f14d408b0f4aee5f9d25a
timeCreated: 1498976326
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,76 @@
//
// Description : Array and textureless GLSL 2D/3D/4D simplex
// noise functions.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : ijm
// Lastmod : 20110822 (ijm)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise
//
#ifndef _INCLUDE_JP_KEIJIRO_NOISESHADER_SIMPLEX_NOISE_3D_HLSL_
#define _INCLUDE_JP_KEIJIRO_NOISESHADER_SIMPLEX_NOISE_3D_HLSL_
#include "Common.hlsl"
float4 SimplexNoiseGrad(float3 v)
{
// First corner
float3 i = floor(v + dot(v, 1.0 / 3));
float3 x0 = v - i + dot(i, 1.0 / 6);
// Other corners
float3 g = x0.yzx <= x0.xyz;
float3 l = 1 - g;
float3 i1 = min(g.xyz, l.zxy);
float3 i2 = max(g.xyz, l.zxy);
float3 x1 = x0 - i1 + 1.0 / 6;
float3 x2 = x0 - i2 + 1.0 / 3;
float3 x3 = x0 - 0.5;
// Permutations
i = wglnoise_mod289(i); // Avoid truncation effects in permutation
float4 p = wglnoise_permute( i.z + float4(0, i1.z, i2.z, 1));
p = wglnoise_permute(p + i.y + float4(0, i1.y, i2.y, 1));
p = wglnoise_permute(p + i.x + float4(0, i1.x, i2.x, 1));
// 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)
float4 gx = lerp(-1, 1, frac(floor(p / 7) / 7));
float4 gy = lerp(-1, 1, frac(floor(p % 7) / 7));
float4 gz = 1 - abs(gx) - abs(gy);
bool4 zn = gz < -0.01;
gx += zn * (gx < -0.01 ? 1 : -1);
gy += zn * (gy < -0.01 ? 1 : -1);
float3 g0 = normalize(float3(gx.x, gy.x, gz.x));
float3 g1 = normalize(float3(gx.y, gy.y, gz.y));
float3 g2 = normalize(float3(gx.z, gy.z, gz.z));
float3 g3 = normalize(float3(gx.w, gy.w, gz.w));
// Compute noise and gradient at P
float4 m = float4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3));
float4 px = float4(dot(g0, x0), dot(g1, x1), dot(g2, x2), dot(g3, x3));
m = max(0.5 - m, 0);
float4 m3 = m * m * m;
float4 m4 = m * m3;
float4 temp = -8 * m3 * px;
float3 grad = m4.x * g0 + temp.x * x0 +
m4.y * g1 + temp.y * x1 +
m4.z * g2 + temp.z * x2 +
m4.w * g3 + temp.w * x3;
return 107 * float4(grad, dot(m4, px));
}
float SimplexNoise(float3 v)
{
return SimplexNoiseGrad(v).w;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2b1bb9b67aabb824998a7d2e026d2606
timeCreated: 1498976326
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
{
"author": "Keijiro Takahashi",
"description": "Noise Shader provides lightweight 2D/3D gradient noise functions for shader use.",
"displayName": "Noise Shader",
"keywords": [ "unity" ],
"license": "MIT",
"name": "jp.keijiro.noiseshader",
"repository": "github:keijiro/NoiseShader",
"unity": "2019.3",
"unityRelease": "0f1",
"version": "2.0.0"
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 39ccfaa9af9f4dc84a876b1b1c3ae8bb
PackageManifestImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: