How to make shaders pickup custom enums?

I want to use custom enums inside a shader. How can I achieve this?

In the chat @tonfilm said:

I’ve tried this now and it doesn’t seem to work.

Folder structure looks like this:

📂ShaderEnums
 ┣ 📂lib
 ┃ ┗ 📂net6.0
 ┃   ┗ 📜EffectEnums.dll
 ┣ 📂src
 ┃ ┣ 📂EffectEnums
 ┃ ┃ ┣ 📜EffectEnums.cs
 ┃ ┃ ┗ 📜EffectEnums.csproj
 ┃ ┗ 📜EffectEnums.sln
 ┗ 📂vl
   ┣ 📂shaders
   ┃ ┗📜EnumTest_TextureFX.sdsl
   ┗ 📜EnumTrial.vl

The enum is defined like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace VL.Stride.Effects.TextureFX 
{
    public enum SomeColor
    {
        Black,
        White,
        Red,
        Green,
        Blue
    };
 }

And forwarded by EnumTrial.vl.

The shader looks like this:

[TextureSource]
[Category("Source")]
[Summary("For testing custom enum")]
shader EnumTest_TextureFX : TextureFX
{
    [EnumType("VL.Stride.Effects.TextureFX.SomeColor")]
    int Color;

    stage override float4 Shading()
    {
        float4 col = 0;

        switch((uint)Color%3)
        {
            case 0 : col = 0; break;
            case 1 : col = 1; break;
            case 2 : col = float4(1.0, 0.0, 0.0, 0.0); break;
        }
        return col;
    }
};

Still the input is of type Int32 in the patch:


ShaderEnums.7z (28.4 KB)

4 Likes

Hey, this is currently a bit of a show stopper. Any feedback would help – even if it is just “sorry doesn’t / won’t work” – so we can decide on an other approach (wrapping shaders in process nodes).

2 Likes

Sorry to say, this apparently never worked for external shaders. The internal type lookup only finds enums defined in VL.Stride. We would need to add an option to guide the system to the dll where the enum is defined.

I’ve opened an issue for it.

2 Likes

Turns out this was working all along by using assembly qualified names. For example

Say our library has an enum MyLib.MyEnum located in lib\net6.0\MyLib.dll, we can use it by appending the assembly name:
EnumType("MyLib.MyEnum, MyLib")]

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.