Fancy Background Shader

This commit is contained in:
hyperion51 2020-03-25 02:22:44 +00:00
commit 4221f304f1
18 changed files with 698 additions and 398 deletions

View file

@ -46,6 +46,7 @@
</e>
</e>
<e p="Scripts" t="Include">
<e p="BackgroundRenderer.cs" t="Include" />
<e p="CultClient.cs" t="Include" />
<e p="Editor" t="Include">
<e p="DatabaseInspector.cs" t="Include" />
@ -1089,21 +1090,22 @@
<e p="ZoneGenerator.cs" t="Include" />
</e>
<e p="Switch_state.cs" t="Include" />
<e p="TabActivator.cs" t="Include" />
<e p="TabButton.cs" t="Include" />
<e p="TabGroup.cs" t="Include" />
<e p="Targetable.cs" t="Include" />
<e p="UnityExtensions.cs" t="Include" />
<e p="UnityFormatters.cs" t="Include" />
<e p="ZoneRenderer.cs" t="Include" />
</e>
<e p="Shaders" t="Include">
<e p="Background.shader" t="Include" />
<e p="CubicPulseBrush.shader" t="Include" />
<e p="GalaxyMap.shader" t="Include" />
<e p="Isolines.shader" t="Include" />
<e p="PowerBrush.shader" t="Include" />
<e p="SimplexBrush.shader" t="Include" />
</e>
<e p="TabActivator.cs" t="Include" />
<e p="TabButton.cs" t="Include" />
<e p="TabGroup.cs" t="Include" />
<e p="TextMesh Pro" t="Include">
<e p="Fonts" t="Include">
<e p="LiberationSans - OFL.txt" t="Include" />

View file

@ -60,6 +60,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\Scripts\BackgroundRenderer.cs" />
<Compile Include="Assets\Scripts\CultClient.cs" />
<Compile Include="Assets\Scripts\Galaxy.cs" />
<Compile Include="Assets\Scripts\Icons.cs" />
@ -388,13 +389,14 @@
<Compile Include="Assets\Scripts\Prototype.cs" />
<Compile Include="Assets\Scripts\Scr_Log_In.cs" />
<Compile Include="Assets\Scripts\Switch_state.cs" />
<Compile Include="Assets\Scripts\TabActivator.cs" />
<Compile Include="Assets\Scripts\TabButton.cs" />
<Compile Include="Assets\Scripts\TabGroup.cs" />
<Compile Include="Assets\Scripts\Targetable.cs" />
<Compile Include="Assets\Scripts\UnityExtensions.cs" />
<Compile Include="Assets\Scripts\UnityFormatters.cs" />
<Compile Include="Assets\Scripts\ZoneRenderer.cs" />
<Compile Include="Assets\TabActivator.cs" />
<Compile Include="Assets\TabButton.cs" />
<Compile Include="Assets\TabGroup.cs" />
<None Include="Assets\Shaders\Background.shader" />
<None Include="Assets\TextMesh Pro\Resources\Shaders\TMP_SDF-Surface-Mobile.shader" />
<None Include="Assets\TextMesh Pro\Resources\LineBreaking Leading Characters.txt" />
<None Include="Assets\Scripts\NIH\GPU Noise\ClassicNoise3D.cginc" />

View file

@ -0,0 +1,90 @@
%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: Background
m_Shader: {fileID: 4800000, guid: 7a1e6fc0f6159b44eacd456c2a308968, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- Distortion: 0.5
- NoiseAmplitude: 0.5
- NoiseFrequency: 0.3
- NoiseGain: 0.6
- NoiseLacunarity: 2.5
- NoiseOffset: 0.35
- NoisePosition: 0
- ScrollSpeed: 2
- Speed: 5
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _Frequency: 1
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Color1: {r: 0, g: 0.12804878, b: 0.25, a: 1}
- _Color2: {r: 0.15, g: 0, b: 0.0077922107, a: 1}
- _Color3: {r: 0, g: 0.05, b: 0.028846158, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c5172385780bc994f9dbac669e78b48b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/Resources/Ubuntu/Ubuntu-L SDF.asset (Stored with Git LFS)

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,31 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BackgroundRenderer : MonoBehaviour
{
public Transform Background;
// public float RotationSpeed1 = 1;
// public float RotationSpeed2 = 1;
private Camera _camera;
private float _ratio;
//private Material _material;
private float _depth;
private void Start()
{
_camera = GetComponent<Camera>();
_depth = Background.position.z;
//_material = Background.GetComponent<MeshRenderer>().material;
}
private void OnPreRender()
{
//_material.SetVector("Rot1", );
_ratio = (float) Screen.height / Screen.width;
Background.position = new Vector3(transform.position.x, transform.position.y, _depth);
var size = _camera.orthographicSize;
Background.localScale = new Vector3(size * 4, size * 4 * _ratio, 1);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 60335bb143d92fd4eac7a5ed8b12494c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -19,25 +19,7 @@
// https://github.com/ashima/webgl-noise
//
float3 mod289(float3 x)
{
return x - floor(x / 289.0) * 289.0;
}
float2 mod289(float2 x)
{
return x - floor(x / 289.0) * 289.0;
}
float3 permute(float3 x)
{
return mod289((x * 34.0 + 1.0) * x);
}
float3 taylorInvSqrt(float3 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
#include "SimplexNoise2D.cginc"
float2 snoise_grad(float2 v)
{

View file

@ -0,0 +1,118 @@
Shader "Unlit/Background"
{
Properties
{
_Color1 ("Color 1", Color) = (1,1,1,1)
_Color2 ("Color 2", Color) = (1,1,1,1)
_Color3 ("Color 2", Color) = (1,1,1,1)
NoisePosition("NoisePosition", Float) = 0.5
NoiseAmplitude("NoiseAmplitude", Float) = 0.5
NoiseOffset("NoiseOffset", Float) = 0.5
NoiseGain("NoiseGain", Float) = 1
NoiseLacunarity("NoiseLacunarity", Float) = 2
NoiseFrequency("NoiseFrequency", Float) = 1
Speed("Speed", Float) = 1
ScrollSpeed("ScrollSpeed", Float) = 1
Distortion("Distortion", Float) = 1
}
SubShader
{
Tags { "RenderType"="Transparent" }
Cull Off Lighting Off ZWrite Off
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "Assets/Scripts/NIH/GPU Noise/SimplexNoiseGrad2D.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
half4 _Color1;
half4 _Color2;
half4 _Color3;
float NoisePosition;
float NoiseAmplitude;
float NoiseOffset;
float NoiseGain;
float NoiseLacunarity;
float NoiseFrequency;
float Speed;
float ScrollSpeed;
float Distortion;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = mul (unity_ObjectToWorld, v.vertex).xy;
return o;
}
// fractal sum, range -1.0 - 1.0
float fbm(float2 p)
{
float freq = NoiseFrequency, amp = .5;
float sum = 0;
for(int i = 0; i < 4; i++)
{
sum += snoise(p * freq) * amp;
freq *= NoiseLacunarity;
amp *= NoiseGain;
}
return (sum + NoiseOffset)*NoiseAmplitude;
}
// fractal sum, range -1.0 - 1.0
float2 fbmgrad(float2 p)
{
float freq = NoiseFrequency, amp = .5;
float2 sum = 0;
for(int i = 0; i < 4; i++)
{
sum += snoise_grad(p * freq) * amp;
freq *= NoiseLacunarity;
amp *= NoiseGain;
}
return (sum + NoiseOffset)*NoiseAmplitude;
}
fixed4 frag (v2f i) : SV_Target
{
float3x3 rot = float3x3(cos(_Time.x*Speed), sin(_Time.x*Speed), 0,
-sin(_Time.x*Speed), cos(_Time.x*Speed), 0,
0,0,1);
float3x3 rot2 = float3x3(cos(_Time.x*Speed*2), sin(_Time.x*Speed*2), 0,
-sin(_Time.x*Speed*2), cos(_Time.x*Speed*2), 0,
0,0,1);
float2 offset0 = i.uv - float2(0,_Time.x*ScrollSpeed*.5);
float noise0 = fbm(offset0);
float2 offset1 = mul(float3(fbmgrad(offset0),1), rot).xy;
float2 offsetuv1 = i.uv + offset1 * Distortion + float2(_Time.x*ScrollSpeed,0);
float noise1 = fbm(offsetuv1);
float2 offset2 = mul(float3(fbmgrad(offsetuv1),1), rot2).xy;
float2 offsetuv2 = i.uv + offset2 * Distortion * .5 + float2(0,_Time.x*ScrollSpeed*.5);
float noise2 = abs(fbm(offsetuv1));
return float4(noise1*_Color1.rgb+abs(noise0-noise1)*_Color2.rgb + abs(noise0-noise2) * _Color3.rgb, 1);
}
ENDCG
}
}
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7a1e6fc0f6159b44eacd456c2a308968
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -14,9 +14,10 @@
}
SubShader
{
Tags { "RenderType"="Opaque" }
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
LOD 100
Blend SrcAlpha OneMinusSrcAlpha
Blend One One
Cull Off Lighting Off ZWrite Off
Pass
{