Skip to content

Commit

Permalink
some shaders Test shader and ParallaxOclussion
Browse files Browse the repository at this point in the history
  • Loading branch information
Xlinka committed Jul 14, 2024
1 parent 5e16be2 commit 11213ad
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ProjectObsidian/Injection/ShaderInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uri> Shaders = new()
{

ObsidianTestShader,
ParallaxOcclusion
};
public static string ExtractSignature(Uri uri)
{
Expand Down
39 changes: 39 additions & 0 deletions ProjectObsidian/Materials/ObsidianTestShader.cs
Original file line number Diff line number Diff line change
@@ -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<int> 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);
}
}
90 changes: 90 additions & 0 deletions ProjectObsidian/Materials/ParallaxOcclusion.cs
Original file line number Diff line number Diff line change
@@ -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<colorX> Color;
public readonly AssetRef<ITexture2D> MainTex;
public readonly Sync<float> TextureScale;
public readonly AssetRef<ITexture2D> NormalMap;
[Range(0f, 1f, "0.00")]
public readonly Sync<float> NormalScale;
public readonly AssetRef<ITexture2D> ParallaxMap;
[Range(0f, 1f, "0.00")]
public readonly Sync<float> Parallax;
[Range(0f, 1f, "0.00")]
public readonly Sync<float> Glossiness;
[Range(0f, 1f, "0.00")]
public readonly Sync<float> Metallic;
[Range(2f, 100f, "0")]
public readonly Sync<float> ParallaxMinSamples;
[Range(2f, 100f, "0")]
public readonly Sync<float> ParallaxMaxSamples;
[Range(0f, 1f, "0.00")]
public readonly Sync<float> 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<int> 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;
}
}

0 comments on commit 11213ad

Please sign in to comment.