diff --git a/ProjectObsidian/Injection/ShaderInjection.cs b/ProjectObsidian/Injection/ShaderInjection.cs index e9e297a..1e61c57 100644 --- a/ProjectObsidian/Injection/ShaderInjection.cs +++ b/ProjectObsidian/Injection/ShaderInjection.cs @@ -10,11 +10,14 @@ namespace Obsidian.Shaders { internal class ShaderInjection { - + + public static readonly Uri ObsidianTestShader = new("resdb:///65178a8353f8c164cd2c6dc5d07ad3f978157b023f52331b4a0ca2e34781162e.unityshader"); + public static readonly Uri ParallaxOcclusion = new("resdb:///93ae78de262e31f8299661725899aac61d96071ac2ebea8b76a5c56febfc3feb.unityshader"); private static readonly List Shaders = new() { - + ObsidianTestShader, + ParallaxOcclusion }; public static string ExtractSignature(Uri uri) { diff --git a/ProjectObsidian/Materials/ObsidianTestShader.cs b/ProjectObsidian/Materials/ObsidianTestShader.cs new file mode 100644 index 0000000..0a159cc --- /dev/null +++ b/ProjectObsidian/Materials/ObsidianTestShader.cs @@ -0,0 +1,39 @@ +using System; +using Elements.Core; +using FrooxEngine; +using Obsidian.Shaders; + +[Category(new string[] { "Assets/Materials/Obsidian" })] +public class TestMaterial : SingleShaderMaterialProvider +{ + protected override Uri ShaderURL => ShaderInjection.ObsidianTestShader; + + [DefaultValue(-1)] + public readonly Sync RenderQueue; + + private static PropertyState _propertyInitializationState; + + public override PropertyState PropertyInitializationState + { + get => _propertyInitializationState; + protected set => _propertyInitializationState = value; + } + + protected override void UpdateKeywords(ShaderKeywords keywords) + { + // No keywords to update for this simple shader + } + + protected override void UpdateMaterial(Material material) + { + if (!RenderQueue.GetWasChangedAndClear()) return; + + var renderQueue = RenderQueue.Value; + if (renderQueue == -1) + { + renderQueue = 2600; + } + + material.SetRenderQueue(renderQueue); + } +} diff --git a/ProjectObsidian/Materials/ParallaxOcclusion.cs b/ProjectObsidian/Materials/ParallaxOcclusion.cs new file mode 100644 index 0000000..d3cb56d --- /dev/null +++ b/ProjectObsidian/Materials/ParallaxOcclusion.cs @@ -0,0 +1,90 @@ +using System; +using Elements.Core; +using FrooxEngine; +using Obsidian.Shaders; + +[Category(new string[] { "Assets/Materials/Obsidian/Effects" })] +public class ParallaxOcclusion : SingleShaderMaterialProvider +{ + protected override Uri ShaderURL => ShaderInjection.ParallaxOcclusion; + + public readonly Sync Color; + public readonly AssetRef MainTex; + public readonly Sync TextureScale; + public readonly AssetRef NormalMap; + [Range(0f, 1f, "0.00")] + public readonly Sync NormalScale; + public readonly AssetRef ParallaxMap; + [Range(0f, 1f, "0.00")] + public readonly Sync Parallax; + [Range(0f, 1f, "0.00")] + public readonly Sync Glossiness; + [Range(0f, 1f, "0.00")] + public readonly Sync Metallic; + [Range(2f, 100f, "0")] + public readonly Sync ParallaxMinSamples; + [Range(2f, 100f, "0")] + public readonly Sync ParallaxMaxSamples; + [Range(0f, 1f, "0.00")] + public readonly Sync AlphaCutoff; + + private static MaterialProperty _Color = new MaterialProperty("_Color"); + private static MaterialProperty _MainTex = new MaterialProperty("_MainTex"); + private static MaterialProperty _TextureScale = new MaterialProperty("_TextureScale"); + private static MaterialProperty _NormalMap = new MaterialProperty("_BumpMap"); + private static MaterialProperty _NormalScale = new MaterialProperty("_BumpScale"); + private static MaterialProperty _ParallaxMap = new MaterialProperty("_ParallaxMap"); + private static MaterialProperty _Parallax = new MaterialProperty("_Parallax"); + private static MaterialProperty _Glossiness = new MaterialProperty("_Glossiness"); + private static MaterialProperty _Metallic = new MaterialProperty("_Metallic"); + private static MaterialProperty _ParallaxMinSamples = new MaterialProperty("_ParallaxMinSamples"); + private static MaterialProperty _ParallaxMaxSamples = new MaterialProperty("_ParallaxMaxSamples"); + private static MaterialProperty _AlphaCutoff = new MaterialProperty("_AlphaCutoff"); + + [DefaultValue(-1)] + public readonly Sync RenderQueue; + private static PropertyState _propertyInitializationState; + + public override PropertyState PropertyInitializationState + { + get => _propertyInitializationState; + protected set => _propertyInitializationState = value; + } + + protected override void UpdateMaterial(Material material) + { + material.UpdateColor(_Color, Color); + material.UpdateTexture(_MainTex, MainTex); + material.UpdateFloat(_TextureScale, TextureScale); + material.UpdateTexture(_NormalMap, NormalMap); + material.UpdateFloat(_NormalScale, NormalScale); + material.UpdateTexture(_ParallaxMap, ParallaxMap); + material.UpdateFloat(_Parallax, Parallax); + material.UpdateFloat(_Glossiness, Glossiness); + material.UpdateFloat(_Metallic, Metallic); + material.UpdateFloat(_ParallaxMinSamples, ParallaxMinSamples); + material.UpdateFloat(_ParallaxMaxSamples, ParallaxMaxSamples); + material.UpdateFloat(_AlphaCutoff, AlphaCutoff); + + if (!RenderQueue.GetWasChangedAndClear()) return; + var renderQueue = RenderQueue.Value; + if ((int)RenderQueue == -1) renderQueue = 2000; + material.SetRenderQueue(renderQueue); + } + + protected override void UpdateKeywords(ShaderKeywords keywords) { } + + protected override void OnAttach() + { + base.OnAttach(); + Color.Value = colorX.White; + TextureScale.Value = 1f; + NormalScale.Value = 1f; + Parallax.Value = 0.05f; + Glossiness.Value = 0.5f; + Metallic.Value = 0f; + ParallaxMinSamples.Value = 4; + ParallaxMaxSamples.Value = 20; + AlphaCutoff.Value = 0.5f; + } +}