diff options
| author | yum <yum.food.vr@gmail.com> | 2023-11-19 17:55:22 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2023-11-19 17:55:22 -0800 |
| commit | 8427cb479e6ea389e92bac7f9bc73294038059d4 (patch) | |
| tree | a371254dbd5600784e39264c16960ddcc6f13443 /Shaders | |
| parent | db026d39d481d22155afc1ac9eda0b4496c9f7c2 (diff) | |
Still a WIP, kinda looks like shit
Diffstat (limited to 'Shaders')
26 files changed, 1288 insertions, 1 deletions
diff --git a/Shaders/cloud.meta b/Shaders/cloud.meta new file mode 100644 index 0000000..86d6c79 --- /dev/null +++ b/Shaders/cloud.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1ab34b085dc2141438ab33ad59144ecb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/Cube.prefab b/Shaders/cloud/Cube.prefab new file mode 100644 index 0000000..2633cf7 --- /dev/null +++ b/Shaders/cloud/Cube.prefab @@ -0,0 +1,95 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &1404254295233746572 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1404254295233746576} + - component: {fileID: 1404254295233746575} + - component: {fileID: 1404254295233746574} + - component: {fileID: 1404254295233746573} + m_Layer: 0 + m_Name: Cube + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1404254295233746576 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1404254295233746572} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 100, y: 1, z: 100} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &1404254295233746575 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1404254295233746572} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &1404254295233746574 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1404254295233746572} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 9f3bfeca6fc628f45b8186d6f71100dc, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!65 &1404254295233746573 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1404254295233746572} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} diff --git a/Shaders/cloud/Cube.prefab.meta b/Shaders/cloud/Cube.prefab.meta new file mode 100644 index 0000000..5446ea5 --- /dev/null +++ b/Shaders/cloud/Cube.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8b77eb65653b3c94d9a6e841ceeb326c +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/Motion.cginc b/Shaders/cloud/Motion.cginc new file mode 100644 index 0000000..d6458e9 --- /dev/null +++ b/Shaders/cloud/Motion.cginc @@ -0,0 +1,90 @@ +#ifndef MOTION_ +#define MOTION_ + +// xyz represent quaternion vector, w represents theta. +typedef float4 Quaternion; + +// Math from here: +// https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation +float3 qrot(in float3 v, in Quaternion q) +{ + float a = q.w; + float b = q.x; + float c = q.y; + float d = q.z; + + float a2 = a*a; + float b2 = b*b; + float c2 = c*c; + float d2 = d*d; + + float3x3 rot = float3x3( + (a2 + b2 - c2) - d2, 2*b*c - 2*a*d, 2*b*d + 2*a*c, + 2*b*c + 2*a*d, (a2 - b2) + (c2 - d2), 2*c*d - 2*a*b, + 2*b*d - 2*a*c, 2*c*d + 2*a*b, ((a2 - b2) - c2) + d2 + ); + + return mul(rot, v); +} + +Quaternion qinv(in Quaternion q) +{ + return Quaternion(q.xyz, -q.w); +} + +// Multiply two quaternions. +// Math from here: https://www.haroldserrano.com/blog/quaternions-in-computer-graphics +Quaternion qmul(in Quaternion a, in Quaternion b) +{ + return Quaternion(a.w * b.xyz + b.w * a.xyz + cross(a.xyz, b.xyz), a.w * b.w - dot(a.xyz, b.xyz)); +} + +float4 affine3(in float3 m) +{ + return float4(m, 1.0); +} + +float4x4 affine3x3(in float3x3 m) +{ + return float4x4( + m[0][0], m[0][1], m[0][2], 0, + m[1][0], m[1][1], m[1][2], 0, + m[2][0], m[2][1], m[2][2], 0, + 0, 0, 0, 1 + ); +} + +float4x4 eye() +{ + return float4x4( + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + ); +} + +// Return affine translation matrix. +float4x4 translate(in float dx, in float dy, in float dz) +{ + return float4x4( + 1, 0, 0, dx, + 0, 1, 0, dy, + 0, 0, 1, dz, + 0, 0, 0, 1 + ); +} + +// Return affine scaling matrix. +float4x4 scale(in float sx, in float sy, in float sz) +{ + return float4x4( + sx, 0, 0, 0, + 0, sy, 0, 0, + 0, 0, sz, 0, + 0, 0, 0, 1 + ); +} + +#endif // MOTION_ + diff --git a/Shaders/cloud/Motion.cginc.meta b/Shaders/cloud/Motion.cginc.meta new file mode 100644 index 0000000..3df2f40 --- /dev/null +++ b/Shaders/cloud/Motion.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: e9821175c034d7947b7e8fde31852d20 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/cloud.mat b/Shaders/cloud/cloud.mat new file mode 100644 index 0000000..9308b8e --- /dev/null +++ b/Shaders/cloud/cloud.mat @@ -0,0 +1,49 @@ +%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: cloud + m_Shader: {fileID: 4800000, guid: a40068f12c2291f4ab8bf322d9b3d84c, type: 3} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _Custom_Cubemap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Matcap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _Ball_Height: 0 + - _Ball_Scale: 1 + - _Cloud_Opacity: 0.5 + - _Cloud_Scale: 20 + - _Cloud_W: 0.35 + - _Cloud_Y_Off: 0.5 + - _Enable_Custom_Cubemap: 0 + - _Enable_Matcap: 0 + - _Global_Scale: 1 + - _Matcap_Mode: 1 + - _Matcap_Str: 1 + - _Sphere_Scale: 1 + - _cloud_Opacity: 0.5 + - _cloud_Scale: 2 + - _cloud_W: 0.35 + - _cloud_Y_Off: 0 + m_Colors: + - _Offset: {r: 0, g: 0, b: 0, a: 0} + - _Orientation: {r: 1, g: 0, b: 0, a: 0} diff --git a/Shaders/cloud/cloud.mat.meta b/Shaders/cloud/cloud.mat.meta new file mode 100644 index 0000000..d2cb055 --- /dev/null +++ b/Shaders/cloud/cloud.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9f3bfeca6fc628f45b8186d6f71100dc +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/cloud.shader b/Shaders/cloud/cloud.shader new file mode 100644 index 0000000..95de6de --- /dev/null +++ b/Shaders/cloud/cloud.shader @@ -0,0 +1,72 @@ +Shader "yum_food/cloud" +{ + Properties + { + _Ball_Height("Ball height", float) = 0.15 + _Ball_Scale("Ball scale", float) = 1.0 + _Cloud_Y_Off("cloud Y offset", float) = -.3 + _Cloud_Opacity("cloud opacity", float) = 0.25 + _Cloud_W("cloud FBM W=", float) = 0.35 + _Cloud_Scale("cloud scale", float) = 2 + _Sphere_Scale("Sphere scale", float) = 1 + _Global_Scale("Global scale", float) = 1 + _Orientation("Orientation (axis and angle in radians)", Vector) = (1, 0, 0, 0) + _Offset("Offset (meters)", Vector) = (0, 0, 0, 0) + + [MaterialToggle] _Enable_Matcap("Enable matcap", float) = 1 + _Matcap("Matcap", 2D) = "black" {} + _Matcap_Str("Matcap strength", float) = 1.0 + _Matcap_Mode("Matcap mode: 1 add, 2 mul, 3 replace, 4 sub", Range(1,4)) = 1 + + [MaterialToggle] _Enable_Custom_Cubemap("Enable custom cubemap", float) = 0 + _Custom_Cubemap("Custom cubemap", Cube) = "" {} + } + SubShader + { + Pass { + Tags { + "RenderType"="Opaque" + "Queue"="AlphaTest+499" + "LightMode" = "ForwardBase" + } + Blend SrcAlpha OneMinusSrcAlpha + Cull Back + ZTest LEqual + + CGPROGRAM + #pragma target 5.0 + + #pragma multi_compile _ VERTEXLIGHT_ON + + #pragma vertex vert + #pragma fragment frag + + #define FORWARD_BASE_PASS + + #include "cloud_lighting.cginc" + ENDCG + } + Pass { + Tags { + "RenderType" = "Opaque" + "LightMode" = "ForwardAdd" + "Queue"="AlphaTest+499" + } + Blend One One + Cull Back + ZTest LEqual + + CGPROGRAM + #pragma target 5.0 + + #pragma multi_compile_fwdadd + + #pragma vertex vert + #pragma fragment frag + + #include "cloud_lighting.cginc" + ENDCG + } + } + //CustomEditor "TaSTTShaderGUI" +} diff --git a/Shaders/cloud/cloud.shader.meta b/Shaders/cloud/cloud.shader.meta new file mode 100644 index 0000000..0521d3b --- /dev/null +++ b/Shaders/cloud/cloud.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: a40068f12c2291f4ab8bf322d9b3d84c +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/cloud_lighting.cginc b/Shaders/cloud/cloud_lighting.cginc new file mode 100644 index 0000000..771d21d --- /dev/null +++ b/Shaders/cloud/cloud_lighting.cginc @@ -0,0 +1,195 @@ +#ifndef CLOUD_LIGHTING +#define CLOUD_LIGHTING + +#include "AutoLight.cginc" +#include "UnityPBSLighting.cginc" +#include "iq_sdf.cginc" +#include "math.cginc" +#include "Motion.cginc" +#include "pbr.cginc" +#include "pema99.cginc" + +#define MY_COORD_SCALE 100 +#define MY_COORD_SCALE_INV 1.0 / MY_COORD_SCALE +#define OBJ_SPACE_TO_MINE \ + float4x4( \ + MY_COORD_SCALE, 0, 0, 0, \ + 0, MY_COORD_SCALE, 0, 0, \ + 0, 0, MY_COORD_SCALE, 0, \ + 0, 0, 0, MY_COORD_SCALE \ + ) +#define WORLD_SPACE_TO_MINE \ + mul(unity_WorldToObject, OBJ_SPACE_TO_MINE) +#define MY_SPACE_TO_OBJ \ + float4x4( \ + MY_COORD_SCALE_INV, 0, 0, 0, \ + 0, MY_COORD_SCALE_INV, 0, 0, \ + 0, 0, MY_COORD_SCALE_INV, 0, \ + 0, 0, 0, MY_COORD_SCALE_INV \ + ) +#define MY_SPACE_TO_WORLD \ + mul(MY_SPACE_TO_OBJ, unity_ObjectToWorld) + +#define MINIMUM_HIT_DISTANCE .00002 * MY_COORD_SCALE +#define MAXIMUM_TRACE_DISTANCE 20 * MY_COORD_SCALE + +float _Ball_Height; +float _Ball_Scale; +float _Cloud_Y_Off; +float _Cloud_Opacity; +float _Cloud_W; +float _Cloud_Scale; +float _Sphere_Scale; +float _Global_Scale; +float4 _Orientation; +float3 _Offset; + +// Return the density of the mist at position `p`. +float mist_map(float3 p) +{ + float scale = MY_COORD_SCALE * _Global_Scale; + float dist_fade = max(length(p / scale) - .8, 0) * 12; + dist_fade = 1 / (1 + dist_fade); + + p.x += _Time[0] * scale * .1; + float noise = clamp(fbm(p * _Cloud_Scale / scale, /*n_octaves=*/5, _Cloud_W), 0, 1); + noise *= noise; + + // On [0,1] + float y_fade = p.y / scale + .5; + y_fade -= _Cloud_Y_Off; + y_fade = max(0, y_fade); + y_fade = 1 - y_fade; + noise *= y_fade; + + return clamp(noise * dist_fade, 0, 1); +} + +float3 mist_march(float3 ro, float3 rd, out float density) +{ + float3 current_position; +#define CLOUD_MARCH_ITER 7 + float scale = MY_COORD_SCALE * _Global_Scale; + float step_sz = (float(scale) / CLOUD_MARCH_ITER); + float total_distance = (CLOUD_MARCH_ITER - 1) * step_sz; + + // Dither starting point to avoid color banding + total_distance += step_sz * rand3(ro.xyz); + + float mist_v = 0; + for (int i = CLOUD_MARCH_ITER - 1; (i >= 0); --i) + { + current_position = ro + total_distance * rd; + + float4 cur_world_pos = mul(MY_SPACE_TO_WORLD, float4(current_position, MY_COORD_SCALE)); + float d0 = getWorldSpaceDepth(cur_world_pos); + float d1 = getDepthBufferAt(cur_world_pos); + //bool use_result = (d0 < d1); + bool use_result = true; + { + float3 axis = _Orientation.xyz; + float theta = _Orientation.w; + + Quaternion q = Quaternion(axis * cos(theta/2), sin(theta/2)); + current_position = qrot(current_position, q); + } + + float cur_v = mist_map(current_position) * _Cloud_Opacity; + float new_mist = cur_v + mist_v * (1 - cur_v); + mist_v = lerp(mist_v, new_mist, use_result); + + total_distance -= step_sz; + } + + density = mist_v; + + return current_position; +} + +float4 mist_ray_march(float3 ro, float3 rd, inout v2f v2f_i) +{ + float density; + float3 final_pos = mist_march(ro, rd, density); + + // Mist scatters light. The denser it is, the more it scatters it. + float r0 = rand3(v2f_i.worldPos + float3(_Time[0], 0, 0)); + float r1 = rand3(v2f_i.worldPos + float3(0, _Time[0], 0)); + float r2 = rand3(v2f_i.worldPos + float3(0, 0, _Time[0])); + v2f_i.normal = normalize(v2f_i.normal + density * normalize(float3(r0, r1, r2))); + + density = pow(density, 2) * 2; + density = smoothstep_quintic(density); + return float4(1, 1, 1, density); +} + +float4 ray_march(inout v2f v2f_i) +{ + float4 ray_march_color; + { + float3 camera_position = mul(WORLD_SPACE_TO_MINE, float4(_WorldSpaceCameraPos, 1.0)).xyz; + float3 ro = camera_position; + float3 mesh_position = mul(WORLD_SPACE_TO_MINE, v2f_i.worldPos).xyz; + float3 rd = normalize(mesh_position - ro); + ro = mesh_position; + + float4 mist_color = mist_ray_march(ro, rd, v2f_i); + ray_march_color = clamp(mist_color, 0, 1); + } + + return ray_march_color; +} + +void getVertexLightColor(inout v2f i) +{ + #if defined(VERTEXLIGHT_ON) + float3 light_pos = float3(unity_4LightPosX0.x, unity_4LightPosY0.x, + unity_4LightPosZ0.x); + float3 light_vec = light_pos - i.worldPos; + float3 light_dir = normalize(light_vec); + float ndotl = DotClamped(i.normal, light_dir); + // Light fills an expanding sphere with surface area 4 * pi * r^2. + // By conservation of energy, this means that at distance r, light intensity + // is proportional to 1/(r^2). + float attenuation = 1 / (1 + dot(light_vec, light_vec) * unity_4LightAtten0.x); + i.vertexLightColor = unity_LightColor[0].rgb * ndotl * attenuation; + + i.vertexLightColor = Shade4PointLights( + unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0, + unity_LightColor[0].rgb, + unity_LightColor[1].rgb, + unity_LightColor[2].rgb, + unity_LightColor[3].rgb, + unity_4LightAtten0, i.worldPos, i.normal + ); + #endif +} + +v2f vert(appdata v) +{ + v2f o; + o.position = UnityObjectToClipPos(v.position); + o.worldPos = mul(unity_ObjectToWorld, v.position); + o.normal = UnityObjectToWorldNormal(v.normal); + + o.uv = v.uv; + getVertexLightColor(o); + + return o; +} + +fixed4 frag(v2f i) : SV_Target +{ + float4 mist_unlit = ray_march(i); + + float4 mist_lit = light( + i, + mist_unlit, + /*metallic=*/0, + /*smoothness=*/0.7); + float emission_str = 1.0; + float4 mist_color = mist_lit + float4((mist_unlit * emission_str).xyz, 0); + + return mist_color; +} + +#endif // CLOUD_LIGHTING diff --git a/Shaders/cloud/cloud_lighting.cginc.meta b/Shaders/cloud/cloud_lighting.cginc.meta new file mode 100644 index 0000000..8c9f889 --- /dev/null +++ b/Shaders/cloud/cloud_lighting.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: eb2347c3eb0dcd6449d53650f0972536 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/eyes_data.cginc b/Shaders/cloud/eyes_data.cginc new file mode 100644 index 0000000..f08887b --- /dev/null +++ b/Shaders/cloud/eyes_data.cginc @@ -0,0 +1,24 @@ +#ifndef __EYES_DATA_INC__ +#define __EYES_DATA_INC__ + +struct appdata +{ + float4 position : POSITION; + float2 uv : TEXCOORD0; + float3 normal : NORMAL; +}; + +struct v2f +{ + float4 position : SV_POSITION; + float2 uv : TEXCOORD0; + float3 normal : TEXCOORD1; + float4 worldPos : TEXCOORD2; + + #if defined(VERTEXLIGHT_ON) + float3 vertexLightColor : TEXCOORD3; + #endif +}; + +#endif // __EYES_DATA_INC__ + diff --git a/Shaders/cloud/eyes_data.cginc.meta b/Shaders/cloud/eyes_data.cginc.meta new file mode 100644 index 0000000..fbecb22 --- /dev/null +++ b/Shaders/cloud/eyes_data.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: fb97965c37eb71b45a0d0fbf51aa24a0 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/hg_sdf.cginc b/Shaders/cloud/hg_sdf.cginc new file mode 100644 index 0000000..b1de0b0 --- /dev/null +++ b/Shaders/cloud/hg_sdf.cginc @@ -0,0 +1,187 @@ +#ifndef __HG_SDF__ +#define __HG_SDF__ + +#include "pema99.cginc" + +//////////////////////////////////////////////////////////////// +// +// HG_SDF +// +// GLSL LIBRARY FOR BUILDING SIGNED DISTANCE BOUNDS +// +// version 2021-07-28 +// +// Check https://mercury.sexy/hg_sdf for updates +// and usage examples. Send feedback to spheretracing@mercury.sexy. +// +// Brought to you by MERCURY https://mercury.sexy/ +// +// +// +// Released dual-licensed under +// Creative Commons Attribution-NonCommercial (CC BY-NC) +// or +// MIT License +// at your choice. +// +// SPDX-License-Identifier: MIT OR CC-BY-NC-4.0 +// +// ///// +// +// CC-BY-NC-4.0 +// https://creatifloatommons.org/licenses/by-nc/4.0/legalcode +// https://creatifloatommons.org/licenses/by-nc/4.0/ +// +// ///// +// +// MIT License +// +// Copyright (c) 2011-2021 Mercury Demogroup +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// ///// +// +//////////////////////////////////////////////////////////////// +// +// How to use this: +// +// 1. Build some system to #include glsl files in each other. +// Include this one at the very start. Or just paste everywhere. +// 2. Build a sphere tracer. See those papers: +// * "Sphere Tracing" https://link.springer.com/article/10.1007%2Fs003710050084 +// * "Enhanced Sphere Tracing" http://diglib.eg.org/handle/10.2312/stag.20141233.001-008 +// * "Improved Ray Casting of Procedural Distance Bounds" https://www.bibsonomy.org/bibtex/258e85442234c3ace18ba4d89de94e57d +// The Raymnarching Toolbox Thread on pouet can be helpful as well +// http://www.pouet.net/topic.php?which=7931&page=1 +// and contains links to many more resources. +// 3. Use the tools in this library to build your distance bound f(). +// 4. ??? +// 5. Win a compo. +// +// (6. Buy us a beer or a good vodka or something, if you like.) +// +//////////////////////////////////////////////////////////////// +// +// Table of Contents: +// +// * Helper functions and macros +// * Collection of some primitive objects +// * Domain Manipulation operators +// * Object combination operators +// +//////////////////////////////////////////////////////////////// +// +// Why use this? +// +// The point of this lib is that everything is structured according +// to patterns that we ended up using when building geometry. +// It makes it more easy to write code that is reusable and that somebody +// else can actually understand. Especially code on Shadertoy (which seems +// to be what everybody else is looking at for "inspiration") tends to be +// really ugly. So we were forced to do something about the situation and +// release this lib ;) +// +// Everything in here can probably be done in some better way. +// Please experiment. We'd love some feedback, especially if you +// use it in a scene production. +// +// The main patterns for building geometry this way are: +// * Stay Lipschitz continuous. That means: don't have any distance +// gradient larger than 1. Try to be as close to 1 as possible - +// Distances are euclidean distances, don't fudge around. +// Underestimating distances will happen. That's why calling +// it a "distance bound" is more correct. Don't ever multiply +// distances by some value to "fix" a Lipschitz continuity +// violation. The invariant is: each fSomething() function returns +// a correct distance bound. +// * Use very few primitives and combine them as building blocks +// using combine opertors that preserve the invariant. +// * Multiply objects by repeating the domain (space). +// If you are using a loop inside your distance function, you are +// probably doing it wrong (or you are building boring fractals). +// * At right-angle intersections between objects, build a new local +// coordinate system from the two distances to combine them in +// interesting ways. +// * As usual, there are always times when it is best to not follow +// specific patterns. +// +//////////////////////////////////////////////////////////////// +// +// FAQ +// +// Q: Why is there no sphere tracing code in this lib? +// A: Because our system is way too complex and always changing. +// This is the constant part. Also we'd like everyone to +// explore for themselves. +// +// Q: This does not work when I paste it into Shadertoy!!!! +// A: Yes. It is GLSL, not GLSL ES. We like real OpenGL +// because it has way more features and is more likely +// to work compared to browser-based WebGL. We recommend +// you consider using OpenGL for your productions. Most +// of this can be ported easily though. +// +// Q: How do I material? +// A: We recommend something like this: +// Write a material ID, the distance and the local coordinate +// p into some global variables whenever an object's distance is +// smaller than the stored distance. Then, at the end, evaluate +// the material to get color, roughness, etc., and do the shading. +// +// Q: I found an error. Or I made some function that would fit in +// in this lib. Or I have some suggestion. +// A: Awesome! Drop us a mail at spheretracing@mercury.sexy. +// +// Q: Why is this not on github? +// A: Because we were too lazy. If we get bugged about it enough, +// we'll do it. +// +// Q: Your license sucks for me. +// A: Oh. What should we change it to? +// +// Q: I have trouble understanding what is going on with my distances. +// A: Some visualization of the distance field helps. Try drawing a +// plane that you can sweep through your scene with some color +// representation of the distance field at each point and/or iso +// lines at regular intervals. Visualizing the length of the +// gradient (or better: how much it deviates from being equal to 1) +// is immensely helpful for understanding which parts of the +// distance field are broken. +// +//////////////////////////////////////////////////////////////// + +#define PI 3.14159265 + +// Repeat around the origin by a fixed angle. +// For easier use, num of repetitions is use to specify the angle. +float pModPolar(inout float2 p, float repetitions) { + float angle = 2*PI/repetitions; + float a = atan2(p.y, p.x) + angle/2.; + float r = length(p); + float c = floor(a/angle); + a = glsl_mod(a,angle) - angle/2.; + p = float2(cos(a), sin(a))*r; + // For an odd number of repetitions, fix cell index of the cell in -x direction + // (cell index would be e.g. -5 and 5 in the two halves of the cell): + if (abs(c) >= (repetitions/2)) c = abs(c); + return c; +} + +#endif // __HG_SDF__ diff --git a/Shaders/cloud/hg_sdf.cginc.meta b/Shaders/cloud/hg_sdf.cginc.meta new file mode 100644 index 0000000..7a38e94 --- /dev/null +++ b/Shaders/cloud/hg_sdf.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 9950132f78635324d8502352c56ffe04 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/iq_sdf.cginc b/Shaders/cloud/iq_sdf.cginc new file mode 100644 index 0000000..7951261 --- /dev/null +++ b/Shaders/cloud/iq_sdf.cginc @@ -0,0 +1,143 @@ +#ifndef __IQ_SDF_INC__ +#define __IQ_SDF_INC__ + +#include "pema99.cginc" + +// The MIT License +// Copyright © 2020 Inigo Quilez +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +float distance_from_octahedron(in float3 p) +{ + float s = 1.0; + float3 pp = abs(p); + float m = pp.x+pp.y+pp.z-s; + float3 q; + if( 3.0*pp.x < m ) q = pp.xyz; + else if( 3.0*pp.y < m ) q = pp.yzx; + else if( 3.0*pp.z < m ) q = pp.zxy; + else return m*0.57735027; + + float k = clamp(0.5*(q.z-q.y+s),0.0,s); + return length(float3(q.x,q.y-s+k,q.z-k)); +} + +float distance_from_sphere(float3 p) +{ + return length(p); +} + +float distance_from_sphere(float3 p, float3 c, float r) +{ + return length(p - c) - r; +} + +float distance_from_cut_sphere( in float3 p, in float r, in float h ) +{ + float w = sqrt(r*r-h*h); // constant for a given shape + + float2 q = float2( length(p.xz), p.y ); + + float s = max( (h-r)*q.x*q.x+w*w*(h+r-2.0*q.y), h*q.x-w*q.y ); + + return (s<0.0) ? length(q)-r : + (q.x<w) ? h - q.y : + length(q-float2(w,h)); +} + +float distance_from_cut_hollow_sphere( float3 p, float r, float h, float t ) +{ + float2 q = float2( length(p.xz), p.y ); + + float w = sqrt(r*r-h*h); + + return ((h*q.x<w*q.y) ? length(q-float2(w,h)) : + abs(length(q)-r) ) - t; +} + +float distance_from_box(float3 p, float3 b) +{ + float3 q = abs(p) - b; + return length(max(q,0.0)) + min(max(q.x,max(q.y,q.z)),0.0); +} + +float distance_from_box_frame(float3 p, float3 b, float e) +{ + p = abs(p)-b; + float3 q = abs(p+e)-e; + + return min(min( + length(max(float3(p.x,q.y,q.z),0.0))+min(max(p.x,max(q.y,q.z)),0.0), + length(max(float3(q.x,p.y,q.z),0.0))+min(max(q.x,max(p.y,q.z)),0.0)), + length(max(float3(q.x,q.y,p.z),0.0))+min(max(q.x,max(q.y,p.z)),0.0)); +} + +float distance_from_pyramid(float3 p, float h, bool invert) +{ + float m2 = h*h + 0.25; + + // symmetry + p.xz = abs(p.xz); // do p=abs(p) instead for double pyramid + p.xz = (p.z>p.x) ? p.zx : p.xz; + p.xz -= 0.5; + + // project into face plane (2D) + float3 q = float3( p.z, h*p.y-0.5*p.x, h*p.x+0.5*p.y); + + float s = max(-q.x,0.0); + float t = clamp( (q.y-0.5*q.x)/(m2+0.25), 0.0, 1.0 ); + + float a = m2*(q.x+s)*(q.x+s) + q.y*q.y; + float b = m2*(q.x+0.5*t)*(q.x+0.5*t) + (q.y-m2*t)*(q.y-m2*t); + + float d2 = max(-q.y,q.x*m2+q.y*0.5) < 0.0 ? 0.0 : min(a,b); + + // recover 3D and scale, and add sign + return sqrt( (d2+q.z*q.z)/m2 ) * sign(max(q.z,-p.y));; +} + +float distance_from_plane(float3 p, float3 n, float h) +{ + // n must be normalized + return dot(p,n) + h; +} + +float distance_from_torus( float3 p, float2 t ) +{ + float2 q = float2(length(p.xz)-t.x,p.y); + return length(q)-t.y; +} + +float distance_from_capped_torus( float3 p, float2 sc, float ra, float rb) +{ + p.x = abs(p.x); + float k = (sc.y*p.x>sc.x*p.y) ? dot(p.xy,sc) : length(p.xy); + return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb; +} + +float3 op_rep(in float3 p, in float3 c) +{ + return glsl_mod(p+0.5*c,c)-0.5*c; +} + +float smoothstep_cubic(float x) +{ + return x * x * (3.0 - 2.0 * x); +} + +float smoothstep_quintic(float x) +{ + return x*x*x*(x*(x*6.0-15.0)+10.0); +} + +float distance_from_line_segment( float3 p, float3 a, float3 b, float r ) +{ + float3 pa = p - a, ba = b - a; + float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); + return length( pa - ba*h ) - r; +} + +// End licensed section + +#endif // __IQ_SDF_INC__ + diff --git a/Shaders/cloud/iq_sdf.cginc.meta b/Shaders/cloud/iq_sdf.cginc.meta new file mode 100644 index 0000000..3ca2d2a --- /dev/null +++ b/Shaders/cloud/iq_sdf.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 3e8d81082e046b648bdfbf6352e41546 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/math.cginc b/Shaders/cloud/math.cginc new file mode 100644 index 0000000..2f2f902 --- /dev/null +++ b/Shaders/cloud/math.cginc @@ -0,0 +1,89 @@ +#ifndef __MATH_INC +#define __MATH_INC + +#include "pema99.cginc" + +#define PI 3.14159265 + +// Differentiable approximation of the standard `max` function. +float dmax(float a, float b, float k) +{ + return log2(exp2(k * a) + exp2(k * b)) / k; +} + +// Differentiable approximation of the standard `min` function. +float dmin(float a, float b, float k) +{ + return -1.0 * dmax(-1.0 * a, -1.0 * b, k); +} + +// Generate a random number on [0, 1]. +float rand2(float2 p) +{ + return glsl_mod(sin(dot(p, float2(561.0, 885.0))) * 776.2, 1.0); +} + +// Generate a random number on [0, 1]. +float rand3(float3 p) +{ + return glsl_mod(sin(dot(p, float3(897.0, 367.0, 197.0))) * 1073.6 + + sin(dot(p, float3(473.0, 599.0, 1093.0))) * 12.6, 1.0); +} + +// 3 dimensional value noise. `p` is assumed to be a point inside a unit cube. +// Theory: https://en.wikipedia.org/wiki/Value_noise +float vnoise3d(float3 p) +{ + float3 pu = floor(p); + float3 pv = glsl_mod(p, 1.0); + + // Assign random numbers to the corner of a cube. + float n000 = rand3(pu + float3(0,0,0)); + float n001 = rand3(pu + float3(0,0,1)); + float n010 = rand3(pu + float3(0,1,0)); + float n011 = rand3(pu + float3(0,1,1)); + float n100 = rand3(pu + float3(1,0,0)); + float n101 = rand3(pu + float3(1,0,1)); + float n110 = rand3(pu + float3(1,1,0)); + float n111 = rand3(pu + float3(1,1,1)); + + float n00 = lerp(n000, n001, pv.z); + float n01 = lerp(n010, n011, pv.z); + float n10 = lerp(n100, n101, pv.z); + float n11 = lerp(n110, n111, pv.z); + + float n0 = lerp(n00, n01, pv.y); + float n1 = lerp(n10, n11, pv.y); + + float n = lerp(n0, n1, pv.x); + + return n; +} + +float fbm(float3 p, const int n_octaves, float w) +{ + float g = exp2(-w); + float a = 1.0; + float p_scale = 1.0; + + float res = 0.0; + for (int i = 0; i < n_octaves; i++) { + res += a * vnoise3d(p * p_scale); + + p_scale /= w; + a *= g; + } + + // On average, vnoise3d returns 0.5. + // Sum of any geometric series is, for growth parameter r and constant a, + // a / (1 - r). + // We want to map onto [0, 1], so divide by this expected sum. + // Use a = 1, to account for the worst-case possibility that every call to + // vnoise3d() returns 1. + res /= (1 / (1 - g)); + + return res; +} + +#endif // __MATH_INC + diff --git a/Shaders/cloud/math.cginc.meta b/Shaders/cloud/math.cginc.meta new file mode 100644 index 0000000..7a61589 --- /dev/null +++ b/Shaders/cloud/math.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 9c48ff864b6b81847bcbcff58669e37d +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/pbr.cginc b/Shaders/cloud/pbr.cginc new file mode 100644 index 0000000..8b7405a --- /dev/null +++ b/Shaders/cloud/pbr.cginc @@ -0,0 +1,139 @@ +#ifndef __PBR_INC__ +#define __PBR_INC__ + +#include "AutoLight.cginc" +#include "eyes_data.cginc" +#include "UnityPBSLighting.cginc" + +float _Enable_Custom_Cubemap; +UNITY_DECLARE_TEXCUBE(_Custom_Cubemap); + +sampler2D _Matcap; +float _Matcap_Str; +float _Enable_Matcap; +float _Matcap_Mode; + +UnityIndirect GetIndirect(v2f i, float3 view_dir, float smoothness) { + UnityIndirect indirect; + indirect.diffuse = 0; + indirect.specular = 0; + + #if defined(VERTEXLIGHT_ON) + indirect.diffuse = i.vertexLightColor; + #endif + + #if defined(FORWARD_BASE_PASS) + indirect.diffuse += max(0, ShadeSH9(float4(i.normal, 1))); + float3 reflect_dir = reflect(-view_dir, i.normal); + // There's a nonlinear relationship between mipmap level and roughness. + float roughness = 1 - smoothness; + roughness *= 1.7 - .7 * roughness; + float3 env_sample; + if (_Enable_Custom_Cubemap) { + env_sample = UNITY_SAMPLE_TEXCUBE_LOD( + _Custom_Cubemap, + reflect_dir, + roughness * UNITY_SPECCUBE_LOD_STEPS); + } else { + env_sample = UNITY_SAMPLE_TEXCUBE_LOD( + unity_SpecCube0, + reflect_dir, + roughness * UNITY_SPECCUBE_LOD_STEPS); + } + if (_Enable_Matcap) { + // identity: (a, b, c) and (c, c, -(a +b)) are perpendicular to each other + float3 ortho_1 = normalize(float3(view_dir.z, view_dir.z, -(view_dir.y + view_dir.x))); + float3 ortho_2 = cross(view_dir, ortho_1); + float2 matcap_uv = (float2(dot(i.normal, ortho_1), dot(i.normal, ortho_2)) + 1) * .43; + float iddx = ddx(i.uv.x); + float iddy = ddy(i.uv.y); + float3 matcap = tex2Dgrad(_Matcap, matcap_uv, iddx, iddy) * _Matcap_Str; + + int mode = round(_Matcap_Mode); + switch (mode) { + case 1: + indirect.specular = clamp(env_sample + matcap, 0, 1); + break; + case 2: + indirect.specular = clamp(env_sample * matcap, 0, 1); + break; + case 3: + indirect.specular = clamp(matcap, 0, 1); + break; + case 4: + indirect.specular = clamp(env_sample - matcap, 0, 1); + break; + } + } else { + indirect.specular = env_sample; + } + #endif + + return indirect; +} + +UnityLight GetLight(v2f i) +{ + UNITY_LIGHT_ATTENUATION(attenuation, 0, i.worldPos.xyz); + float3 light_color = _LightColor0.rgb * attenuation; + + UnityLight light; + light.color = light_color; + #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) + light.dir = normalize(_WorldSpaceLightPos0.xyz - i.worldPos); + #else + light.dir = _WorldSpaceLightPos0.xyz; + #endif + light.ndotl = DotClamped(i.normal, light.dir); + + return light; +} + +void initNormal(inout v2f i) +{ + i.normal = normalize(i.normal); +} + +float4 light(inout v2f i, + float4 albedo, + float metallic, + float smoothness) +{ + initNormal(i); + + float3 specular_tint; + float one_minus_reflectivity; + albedo.rgb = DiffuseAndSpecularFromMetallic( + albedo, metallic, specular_tint, one_minus_reflectivity); + + float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos); + float3 pbr = UNITY_BRDF_PBS(albedo, + specular_tint, + one_minus_reflectivity, + smoothness, + i.normal, + view_dir, + GetLight(i), + GetIndirect(i, view_dir, smoothness)).rgb; + + return float4(saturate(pbr), albedo.a); +} + +float getWorldSpaceDepth(in float4 world_pos) +{ + float4 clip_pos = mul(UNITY_MATRIX_VP, world_pos); + return LinearEyeDepth(clip_pos.z / clip_pos.w); +} + +sampler2D _CameraDepthTexture; + +// Return depth buffer at coordinate, on [0, 1]. +float getDepthBufferAt(in float4 world_pos) +{ + float4 clip_pos = mul(UNITY_MATRIX_VP, world_pos); + float4 uv = ComputeGrabScreenPos(clip_pos); + return LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv.xy / uv.w)); +} + +#endif // __PBR_INC__ + diff --git a/Shaders/cloud/pbr.cginc.meta b/Shaders/cloud/pbr.cginc.meta new file mode 100644 index 0000000..7b1b9ce --- /dev/null +++ b/Shaders/cloud/pbr.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: e45b548d49f156b4098d423e71e74e83 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/pema99.cginc b/Shaders/cloud/pema99.cginc new file mode 100644 index 0000000..c895a48 --- /dev/null +++ b/Shaders/cloud/pema99.cginc @@ -0,0 +1,31 @@ +/* +MIT License + +Copyright (c) 2022 Pema Malling + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef __PEMA99_INC__ +#define __PEMA99_INC__ + +#define glsl_mod(x,y) (((x)-(y)*floor((x)/(y)))) + +#endif // __PEMA99_INC__ + diff --git a/Shaders/cloud/pema99.cginc.meta b/Shaders/cloud/pema99.cginc.meta new file mode 100644 index 0000000..9574d11 --- /dev/null +++ b/Shaders/cloud/pema99.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: b8e0d68eed5f6494b84171a10fb52de4 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/cloud/poi.cginc b/Shaders/cloud/poi.cginc new file mode 100644 index 0000000..87382bb --- /dev/null +++ b/Shaders/cloud/poi.cginc @@ -0,0 +1,60 @@ +#ifndef __POI_INC__ +#define __POI_INC__ + +/* +MIT License + +Copyright (c) 2018 King Arthur + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +static const float Epsilon = 1e-10; +float3 RGBtoHCV(in float3 RGB) +{ + // Based on work by Sam Hocevar and Emil Persson + float4 P = (RGB.g < RGB.b) ? float4(RGB.bg, -1.0, 2.0 / 3.0) : float4(RGB.gb, 0.0, -1.0 / 3.0); + float4 Q = (RGB.r < P.x) ? float4(P.xyw, RGB.r) : float4(RGB.r, P.yzx); + float C = Q.x - min(Q.w, Q.y); + float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z); + return float3(H, C, Q.x); +} + +float3 RGBtoHSV(in float3 RGB) +{ + float3 HCV = RGBtoHCV(RGB); + float S = HCV.y / (HCV.z + Epsilon); + return float3(HCV.x, S, HCV.z); +} + +float3 HUEtoRGB(in float H) +{ + float R = abs(H * 6 - 3) - 1; + float G = 2 - abs(H * 6 - 2); + float B = 2 - abs(H * 6 - 4); + return saturate(float3(R, G, B)); +} + +float3 HSVtoRGB(in float3 HSV) +{ + float3 RGB = HUEtoRGB(HSV.x); + return ((RGB - 1) * HSV.y + 1) * HSV.z; +} + +#endif // __POI_INC__ diff --git a/Shaders/cloud/poi.cginc.meta b/Shaders/cloud/poi.cginc.meta new file mode 100644 index 0000000..7acf360 --- /dev/null +++ b/Shaders/cloud/poi.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 852dd8abb4904f846a9c7e83f5a1a182 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shaders/grass/grass.mat b/Shaders/grass/grass.mat index eca7b7a..45c3c87 100644 --- a/Shaders/grass/grass.mat +++ b/Shaders/grass/grass.mat @@ -91,4 +91,4 @@ Material: m_Colors: - _Color: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - - _Offset: {r: -20, g: 0, b: 0, a: 0} + - _Offset: {r: 0, g: 0, b: 0, a: 0} |
