japsuu / KorpiEngine

Simple, modern, code-only C# game engine!
https://japsuu.github.io/KorpiEngine/
MIT License
18 stars 1 forks source link

Shader property default values #48

Open japsuu opened 1 week ago

japsuu commented 1 week ago

Is your feature request related to a problem? Please describe. Not a problem per se, but you need to manually assign the default properties of a material after creating the material instance. This is clunky and unnecessary. For example, if the shader used by a material requires a texture, you might want to set it to a magenta texture by default.

Describe the solution you'd like I'd like to be able to define property defaults directly in the KSL (Korpi Shader Language) code:

Shader "..."

Properties
{
    _Texture0("main texture", TEXTURE_2D) = "white"
}

Pass 0
{
    ...
}

Describe alternatives you've considered None

Additional context This feature would work similar to Unity's ShaderLab defaults:

image

japsuu commented 1 week ago

This would also allow us to get rid of the setDefaultTextures parameter in the Material constructor:

    public Material(AssetRef<Shader> shader, string name, bool setDefaultTextures = true) : base(name)
    {
        ...
        if (setDefaultTextures)
            SetDefaultTextures();
    }

    public void SetDefaultTextures()
    {
        SetAlbedoDefault();
        SetNormalDefault();
        SetSurfaceDefault();
        SetEmissionDefault();
    }
    public void SetAlbedoDefault() => SetTexture(MAIN_TEX, DefaultAlbedoTex);
    public void SetNormalDefault() => SetTexture(NORMAL_TEX, DefaultNormalTex);
    public void SetSurfaceDefault() => SetTexture(SURFACE_TEX, DefaultSurfaceTex);
    public void SetEmissionDefault() => SetTexture(EMISSION_TEX, DefaultEmissionTex);