diff --git a/Assets/dbl-world/shaders/minecraft/standardAnimDisp.shader b/Assets/dbl-world/shaders/minecraft/standardAnimDisp.shader new file mode 100644 index 0000000..1fc569a --- /dev/null +++ b/Assets/dbl-world/shaders/minecraft/standardAnimDisp.shader @@ -0,0 +1,126 @@ +Shader "Custom/Minecraft/Standard Animated Displacement" +{ + Properties + { + [NoScaleOffset]_DiffuseArray("Transparent Albedo (RGBA)", 2DArray) = "" {} + _Color("Tint Color", Color) = (1, 1, 1, 1) + [NoScaleOffset]_MetallicArray("Metallic", 2DArray) = "" {} + _Glossiness("Smoothness", Range(0, 1)) = 0.5 + [NoScaleOffset]_NormalArray("Normal Map", 2DArray) = "" {} + _Bumpyness("Bumpyness", Float) = 1.0 + + _FlipbookFPS("Flipbook FPS", Integer) = 30 + _FlipbookFrames("Flipbook Frames", Integer) = 30 + + _WaveAmplitude("Wave Amplitude", Float) = 0.5 + _WaveFrequency("Wave Frequency", Float) = 1.0 + _WaveSpeed("Wave Speed", Float) = 1.0 + } + + SubShader + { + Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } + LOD 200 + + Blend SrcAlpha OneMinusSrcAlpha + ZWrite Off + Cull Back + + CGPROGRAM + // Physically based Standard lighting model, and enable shadows on all light types + #pragma surface surf Standard fullforwardshadows alpha:fade addshadow vertex:vert + #pragma target 3.5 + #pragma shader_feature_local _NORMALMAP + + UNITY_DECLARE_TEX2DARRAY(_DiffuseArray); + fixed4 _Color; + UNITY_DECLARE_TEX2DARRAY(_MetallicArray); + half _Glossiness; + UNITY_DECLARE_TEX2DARRAY(_NormalArray); + half _Bumpyness; + + int _FlipbookFPS; + int _FlipbookFrames; + + float _WaveAmplitude; + float _WaveFrequency; + float _WaveSpeed; + + struct Input + { + float2 uv_DiffuseArray; + INTERNAL_DATA // For proper normal handling + }; + + // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. + // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. + // #pragma instancing_options assumeuniformscaling + UNITY_INSTANCING_BUFFER_START(Props) + // put more per-instance properties here + UNITY_INSTANCING_BUFFER_END(Props) + + // Sine wave displacement function + float Wave(float3 pos) + { + return sin(pos.x * _WaveFrequency + _Time.y * _WaveSpeed) + + cos(pos.z * _WaveFrequency + _Time.y * _WaveSpeed); + } + + #define EPSILON 0.01 + + void vert(inout appdata_full v) + { + // Get world position + float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; + + // Displacement in world Y direction + float wave = Wave(worldPos); + float displacement = wave * _WaveAmplitude; + + worldPos.y += displacement; + + // Approximate normal in world space + float3 dx = float3(EPSILON, 0, 0); + float3 dz = float3(0, 0, EPSILON); + + float wave_dx = Wave(worldPos + dx) * _WaveAmplitude; + float wave_dz = Wave(worldPos + dz) * _WaveAmplitude; + + float3 tangentX = float3(1, (wave_dx - displacement) / EPSILON, 0); + float3 tangentZ = float3(0, (wave_dz - displacement) / EPSILON, 1); + + float3 normalWS = normalize(cross(tangentZ, tangentX)); + + // Transform back to object space + v.vertex = mul(unity_WorldToObject, float4(worldPos, 1.0)); + v.normal = mul((float3x3)unity_WorldToObject, normalWS); + } + + void surf(Input IN, inout SurfaceOutputStandard o) + { + // Common UV for all texture arrays + float frame = fmod(floor(_Time.y * _FlipbookFPS), _FlipbookFrames); // Cyclic frame value + float3 uvw = float3(IN.uv_DiffuseArray, frame); + + // Albedo with alpha + float4 diff = UNITY_SAMPLE_TEX2DARRAY(_DiffuseArray, uvw) * _Color; + o.Albedo = diff.rgb; + o.Alpha = diff.a; + + // Sample Metallic and smoothness (R = Metallic, A = Smoothness) plus slider variable + float4 metalGloss = UNITY_SAMPLE_TEX2DARRAY(_MetallicArray, uvw); + o.Metallic = metalGloss.r; + o.Smoothness = metalGloss.a * _Glossiness; + + // Normal map and it's scale + float4 normalTex = UNITY_SAMPLE_TEX2DARRAY(_NormalArray, uvw); + float3 normalMap = UnpackNormal(normalTex); + normalMap.xy *= _Bumpyness; + o.Normal = normalize(normalMap); + } + + ENDCG + } + + FallBack "Standard" +} diff --git a/Assets/dbl-world/shaders/minecraft/standardAnimDisp.shader.meta b/Assets/dbl-world/shaders/minecraft/standardAnimDisp.shader.meta new file mode 100644 index 0000000..af973a5 --- /dev/null +++ b/Assets/dbl-world/shaders/minecraft/standardAnimDisp.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 49d864ccc092ebb4bb1525a67cea143e +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: