From 48eb111c45dabb2266059b52eee3b9448c48ef45 Mon Sep 17 00:00:00 2001 From: Josef Date: Wed, 17 Sep 2025 10:25:03 +0200 Subject: [PATCH] Shader Generator/Stencil/Upgrade 4.5 --- .../Inputs/Sensors/Move Back.tres | 22 -- .../Inputs/Sensors/Move Down.tres | 22 -- .../Inputs/Sensors/Move Forward.tres | 21 -- .../Inputs/Sensors/Move Left.tres | 22 -- .../Inputs/Sensors/Move Right.tres | 23 -- .../Inputs/Sensors/Move Upward.tres | 20 -- .../EditorCamera/Inputs/Sensors/Zoom In.tres | 7 - .../EditorCamera/Inputs/Sensors/Zoom Out.tres | 7 - Runtime/Graphs/Graph.cs | 77 +++++ Runtime/Graphs/Graph.cs.uid | 1 + Runtime/Graphs/GraphConnection.cs | 12 + Runtime/Graphs/GraphConnection.cs.uid | 1 + Runtime/Graphs/GraphWalker.cs | 51 +++ Runtime/Presets/App/MainModule.cs | 8 + Runtime/Procedural/Parametric/Plane/Plane.cs | 19 +- .../Rendering/Assets/Foliage/FoliageData.cs | 8 +- .../StandardMaterialOverride.cs | 15 + .../TextureOverride/FoliageTextureOverride.cs | 203 ++++++++++++ .../FoliageTextureOverride.cs.uid | 1 + .../Assets/Foliage/FoliageRenderLayer.cs | 10 + .../Assets/Foliage/FoliageRenderer.cs | 37 +++ .../Assets/Foliage/GPUFoliageShader.gdshader | 24 +- .../Foliage/GPUFoliageShaderMaterial.cs | 12 + .../TriplanerHeightMapTerrain.gdshader | 108 +++++++ .../TriplanerHeightMapTerrain.gdshader.uid | 1 + Runtime/Rendering/RenderingManager.cs | 19 ++ Runtime/Rendering/RenderingManagerData.cs | 4 + Runtime/Rendering/StencilLayer.cs | 18 ++ Runtime/Rendering/StencilLayer.cs.uid | 1 + .../Default-Input-Icons-Library.tres | 93 ------ .../Shading/Generators/Generic/ShaderCode.cs | 184 +++++++++++ .../{ => Generic}/ShaderCode.cs.uid | 0 .../Generators/Generic/ShaderCodeStage.cs | 20 ++ .../Generators/Generic/ShaderCodeStage.cs.uid | 1 + .../Generators/Generic/ShaderCodeVariable.cs | 67 ++++ .../Generic/ShaderCodeVariable.cs.uid | 1 + .../Generic/ShaderCodeVariableOccurance.cs | 47 +++ .../ShaderCodeVariableOccurance.cs.uid | 1 + .../{ => Generic}/ShaderGenerationContext.cs | 15 +- .../ShaderGenerationContext.cs.uid | 0 .../Generic/ShaderGenerationModule.cs | 297 ++++++++++++++++++ .../ShaderGenerationModule.cs.uid | 0 .../{ => Generic}/ShaderGenerator.cs | 42 ++- .../{ => Generic}/ShaderGenerator.cs.uid | 0 .../Generators/{ => Generic}/ShaderPhases.cs | 0 .../{ => Generic}/ShaderPhases.cs.uid | 0 .../{ => Generic}/ShaderRawModule.cs | 7 +- .../{ => Generic}/ShaderRawModule.cs.uid | 0 .../Generators/Generic/ShaderVariant.cs | 293 +++++++++++++++++ .../{ => Generic}/ShaderVariant.cs.uid | 0 Runtime/Shading/Generators/ShaderCode.cs | 51 --- .../Generators/ShaderGenerationModule.cs | 138 -------- Runtime/Shading/Generators/ShaderVariant.cs | 29 -- .../Generators/Spatial/Albedo/AlbedoModule.cs | 48 ++- .../Generators/Spatial/Alpha/AlphaFade.cs | 55 ++++ .../Generators/Spatial/Alpha/AlphaFade.cs.uid | 1 + .../Generators/Spatial/Alpha/AlphaModule.cs | 53 ++++ .../Spatial/Alpha/AlphaModule.cs.uid | 1 + .../Spatial/Backlight/BacklightModule.cs | 84 +++++ .../Spatial/Backlight/BacklightModule.cs.uid | 1 + .../Spatial/Emission/EmissionModule.cs | 68 ++++ .../Spatial/Emission/EmissionModule.cs.uid | 1 + .../CameraDistance/CameraDistanceFading.cs | 84 +++++ .../CameraDistanceFading.cs.uid | 1 + .../DepthProximity/DepthPromixityFading.cs | 55 ++++ .../DepthPromixityFading.cs.uid | 1 + .../Spatial/Fading/FadingModifier.cs | 50 +++ .../Spatial/Fading/FadingModifier.cs.uid | 1 + .../Generators/Spatial/Fading/FadingModule.cs | 81 +++++ .../Spatial/Fading/FadingModule.cs.uid | 1 + .../Spatial/Fading/Fresnel/FresnelFading.cs | 128 ++++++++ .../Fading/Fresnel/FresnelFading.cs.uid | 1 + .../Spatial/Fading/Line/LineFading.cs | 229 ++++++++++++++ .../Spatial/Fading/Line/LineFading.cs.uid | 1 + .../Spatial/Geometry/GeometryModifier.cs | 24 ++ .../GeometryModifier.cs.uid} | 0 .../Spatial/Geometry/GeometryModule.cs | 38 +++ .../GeometryModule.cs.uid} | 0 .../NormalOffset/GeometryNormalOffset.cs | 198 ++++++++++++ .../NormalOffset/GeometryNormalOffset.cs.uid | 1 + .../TerrainOffset/GeometryTerrainOffset.cs | 63 ++++ .../GeometryTerrainOffset.cs.uid | 1 + .../Wind/GeometryWind.cs} | 48 ++- .../Wind/GeometryWind.cs.uid} | 0 .../Spatial/Metallic/MetallicModule.cs | 53 ++++ .../Spatial/Metallic/MetallicModule.cs.uid | 1 + .../Spatial/NormalMap/NormalMapModule.cs | 58 ++++ .../Spatial/NormalMap/NormalMapModule.cs.uid | 1 + .../Spatial/Occlusion/OcclusionModule.cs | 53 ++++ .../Spatial/Occlusion/OcclusionModule.cs.uid | 1 + .../Spatial/Roughness/RoughnessModule.cs | 57 ++++ .../Spatial/Roughness/RoughnessModule.cs.uid | 1 + .../Spatial/{ => Shading}/ShadingModule.cs | 4 +- .../{ => Shading}/ShadingModule.cs.uid | 0 .../Generators/Spatial/SpatialShaderData.cs | 249 +++++++++++++++ .../Spatial/SpatialShaderData.cs.uid | 1 + .../Spatial/SpatialShaderGenerator.cs | 110 ++++--- .../Spatial/Specular/SpecularModule.cs | 53 ++++ .../Spatial/Specular/SpecularModule.cs.uid | 1 + .../Spatial/Stencil/StencilBaseReference.cs | 17 + .../Stencil/StencilBaseReference.cs.uid | 1 + .../Stencil/StencilCustomConfiguration.cs | 37 +++ .../Stencil/StencilCustomConfiguration.cs.uid | 1 + .../Spatial/Stencil/StencilIndexReference.cs | 20 ++ .../Stencil/StencilIndexReference.cs.uid | 1 + .../Spatial/Stencil/StencilLayerReference.cs | 20 ++ .../Stencil/StencilLayerReference.cs.uid | 1 + .../Generators/Spatial/Stencil/StencilMode.cs | 123 ++++++++ .../Spatial/Stencil/StencilMode.cs.uid | 1 + .../Spatial/Stencil/StencilModule.cs | 29 ++ .../Spatial/Stencil/StencilModule.cs.uid | 1 + .../Spatial/Stencil/StencilReadMask.cs | 34 ++ .../Spatial/Stencil/StencilReadMask.cs.uid | 1 + .../StencilReference.cs} | 5 +- .../Spatial/Stencil/StencilReference.cs.uid | 1 + .../Spatial/Stencil/StencilWriteMask.cs | 34 ++ .../Spatial/Stencil/StencilWriteMask.cs.uid | 1 + .../SubsurfaceScatteringModule.cs | 110 +++++++ .../SubsurfaceScatteringModule.cs.uid | 1 + .../Generators/Spatial/TextureModule.cs | 225 +++++++++++-- .../{ => Transparency}/TransparencyModule.cs | 8 +- .../TransparencyModule.cs.uid | 0 .../Shading/Generators/Spatial/UV/UVModule.cs | 10 +- .../Generators/Spatial/UV/UVScaleOffset.cs | 8 +- .../Vertex/VertexModifierModule.cs.uid | 1 - .../Generators/Spatial/Vertex/VertexModule.cs | 46 --- Runtime/Shading/Library/Cameras.gdshaderinc | 7 + Runtime/Shading/Library/Colors.gdshaderinc | 9 + Runtime/Shading/Library/Depth.gdshaderinc | 6 + Runtime/Shading/Library/Light.gdshaderinc | 18 +- Runtime/Shading/Library/Math.gdshaderinc | 22 +- Runtime/Shading/Library/Noise.gdshaderinc | 5 + Runtime/Shading/Library/Normals.gdshaderinc | 10 + Runtime/Shading/Library/SDF.gdshaderinc | 48 ++- Runtime/Shading/Library/Terrain.gdshaderinc | 42 +++ .../Shading/Library/Terrain.gdshaderinc.uid | 1 + Runtime/Shading/Library/Transform.gdshaderinc | 49 +++ Runtime/Shading/Library/Wind.gdshaderinc | 6 +- .../Properties/SetVector3PropertyFromNode.cs | 31 ++ .../SetVector3PropertyFromNode.cs.uid | 1 + .../Properties/Properties/Vector3Property.cs | 43 +++ .../Properties/Vector3Property.cs.uid | 1 + .../Text/JSON/Serializers/JSONSerializer.cs | 10 + Runtime/Text/Lexing/LexerEvent.cs | 8 +- Runtime/Text/Lexing/LexerMatcherLibrary.cs | 6 +- Runtime/Text/RegexUtility.cs | 10 + Runtime/Text/Text.cs | 30 ++ Runtime/Text/TextLinesMapper.cs | 17 +- Runtime/Tools/Lists.cs | 148 +++++++++ Runtime/Tools/ReflectionHelper.cs | 30 ++ Runtime/UI/UI-Settings-Default.tres | 3 - 151 files changed, 4691 insertions(+), 628 deletions(-) create mode 100644 Runtime/Graphs/Graph.cs create mode 100644 Runtime/Graphs/Graph.cs.uid create mode 100644 Runtime/Graphs/GraphConnection.cs create mode 100644 Runtime/Graphs/GraphConnection.cs.uid create mode 100644 Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/TextureOverride/FoliageTextureOverride.cs create mode 100644 Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/TextureOverride/FoliageTextureOverride.cs.uid create mode 100644 Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader create mode 100644 Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader.uid create mode 100644 Runtime/Rendering/StencilLayer.cs create mode 100644 Runtime/Rendering/StencilLayer.cs.uid create mode 100644 Runtime/Shading/Generators/Generic/ShaderCode.cs rename Runtime/Shading/Generators/{ => Generic}/ShaderCode.cs.uid (100%) create mode 100644 Runtime/Shading/Generators/Generic/ShaderCodeStage.cs create mode 100644 Runtime/Shading/Generators/Generic/ShaderCodeStage.cs.uid create mode 100644 Runtime/Shading/Generators/Generic/ShaderCodeVariable.cs create mode 100644 Runtime/Shading/Generators/Generic/ShaderCodeVariable.cs.uid create mode 100644 Runtime/Shading/Generators/Generic/ShaderCodeVariableOccurance.cs create mode 100644 Runtime/Shading/Generators/Generic/ShaderCodeVariableOccurance.cs.uid rename Runtime/Shading/Generators/{ => Generic}/ShaderGenerationContext.cs (63%) rename Runtime/Shading/Generators/{ => Generic}/ShaderGenerationContext.cs.uid (100%) create mode 100644 Runtime/Shading/Generators/Generic/ShaderGenerationModule.cs rename Runtime/Shading/Generators/{ => Generic}/ShaderGenerationModule.cs.uid (100%) rename Runtime/Shading/Generators/{ => Generic}/ShaderGenerator.cs (68%) rename Runtime/Shading/Generators/{ => Generic}/ShaderGenerator.cs.uid (100%) rename Runtime/Shading/Generators/{ => Generic}/ShaderPhases.cs (100%) rename Runtime/Shading/Generators/{ => Generic}/ShaderPhases.cs.uid (100%) rename Runtime/Shading/Generators/{ => Generic}/ShaderRawModule.cs (80%) rename Runtime/Shading/Generators/{ => Generic}/ShaderRawModule.cs.uid (100%) create mode 100644 Runtime/Shading/Generators/Generic/ShaderVariant.cs rename Runtime/Shading/Generators/{ => Generic}/ShaderVariant.cs.uid (100%) delete mode 100644 Runtime/Shading/Generators/ShaderCode.cs delete mode 100644 Runtime/Shading/Generators/ShaderGenerationModule.cs delete mode 100644 Runtime/Shading/Generators/ShaderVariant.cs create mode 100644 Runtime/Shading/Generators/Spatial/Alpha/AlphaFade.cs create mode 100644 Runtime/Shading/Generators/Spatial/Alpha/AlphaFade.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Alpha/AlphaModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/Alpha/AlphaModule.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Backlight/BacklightModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/Backlight/BacklightModule.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Emission/EmissionModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/Emission/EmissionModule.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Fading/CameraDistance/CameraDistanceFading.cs create mode 100644 Runtime/Shading/Generators/Spatial/Fading/CameraDistance/CameraDistanceFading.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Fading/DepthProximity/DepthPromixityFading.cs create mode 100644 Runtime/Shading/Generators/Spatial/Fading/DepthProximity/DepthPromixityFading.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Fading/FadingModifier.cs create mode 100644 Runtime/Shading/Generators/Spatial/Fading/FadingModifier.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Fading/FadingModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/Fading/FadingModule.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Fading/Fresnel/FresnelFading.cs create mode 100644 Runtime/Shading/Generators/Spatial/Fading/Fresnel/FresnelFading.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Fading/Line/LineFading.cs create mode 100644 Runtime/Shading/Generators/Spatial/Fading/Line/LineFading.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Geometry/GeometryModifier.cs rename Runtime/Shading/Generators/Spatial/{Vertex/VertexModifier.cs.uid => Geometry/GeometryModifier.cs.uid} (100%) create mode 100644 Runtime/Shading/Generators/Spatial/Geometry/GeometryModule.cs rename Runtime/Shading/Generators/Spatial/{Vertex/VertexModule.cs.uid => Geometry/GeometryModule.cs.uid} (100%) create mode 100644 Runtime/Shading/Generators/Spatial/Geometry/NormalOffset/GeometryNormalOffset.cs create mode 100644 Runtime/Shading/Generators/Spatial/Geometry/NormalOffset/GeometryNormalOffset.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Geometry/TerrainOffset/GeometryTerrainOffset.cs create mode 100644 Runtime/Shading/Generators/Spatial/Geometry/TerrainOffset/GeometryTerrainOffset.cs.uid rename Runtime/Shading/Generators/Spatial/{Vertex/VertexWind.cs => Geometry/Wind/GeometryWind.cs} (55%) rename Runtime/Shading/Generators/Spatial/{Vertex/VertexWind.cs.uid => Geometry/Wind/GeometryWind.cs.uid} (100%) create mode 100644 Runtime/Shading/Generators/Spatial/Metallic/MetallicModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/Metallic/MetallicModule.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/NormalMap/NormalMapModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/NormalMap/NormalMapModule.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Occlusion/OcclusionModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/Occlusion/OcclusionModule.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Roughness/RoughnessModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/Roughness/RoughnessModule.cs.uid rename Runtime/Shading/Generators/Spatial/{ => Shading}/ShadingModule.cs (94%) rename Runtime/Shading/Generators/Spatial/{ => Shading}/ShadingModule.cs.uid (100%) create mode 100644 Runtime/Shading/Generators/Spatial/SpatialShaderData.cs create mode 100644 Runtime/Shading/Generators/Spatial/SpatialShaderData.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Specular/SpecularModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/Specular/SpecularModule.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilBaseReference.cs create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilBaseReference.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilCustomConfiguration.cs create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilCustomConfiguration.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilIndexReference.cs create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilIndexReference.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilLayerReference.cs create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilLayerReference.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilMode.cs create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilMode.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilModule.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilReadMask.cs create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilReadMask.cs.uid rename Runtime/Shading/Generators/Spatial/{Vertex/VertexModifier.cs => Stencil/StencilReference.cs} (54%) create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilReference.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilWriteMask.cs create mode 100644 Runtime/Shading/Generators/Spatial/Stencil/StencilWriteMask.cs.uid create mode 100644 Runtime/Shading/Generators/Spatial/SubsurfaceScattering/SubsurfaceScatteringModule.cs create mode 100644 Runtime/Shading/Generators/Spatial/SubsurfaceScattering/SubsurfaceScatteringModule.cs.uid rename Runtime/Shading/Generators/Spatial/{ => Transparency}/TransparencyModule.cs (91%) rename Runtime/Shading/Generators/Spatial/{ => Transparency}/TransparencyModule.cs.uid (100%) delete mode 100644 Runtime/Shading/Generators/Spatial/Vertex/VertexModifierModule.cs.uid delete mode 100644 Runtime/Shading/Generators/Spatial/Vertex/VertexModule.cs create mode 100644 Runtime/Shading/Library/Terrain.gdshaderinc create mode 100644 Runtime/Shading/Library/Terrain.gdshaderinc.uid create mode 100644 Runtime/Shading/Properties/Properties/SetVector3PropertyFromNode.cs create mode 100644 Runtime/Shading/Properties/Properties/SetVector3PropertyFromNode.cs.uid create mode 100644 Runtime/Shading/Properties/Properties/Vector3Property.cs create mode 100644 Runtime/Shading/Properties/Properties/Vector3Property.cs.uid diff --git a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Back.tres b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Back.tres index 9fdc9c6..d133c55 100644 --- a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Back.tres +++ b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Back.tres @@ -8,47 +8,25 @@ [sub_resource type="Resource" id="Resource_jlvht"] script = ExtResource("2_dx1wq") key = 83 -keyLocation = 0 -ctrlHold = 2 -altHold = 2 -shiftHold = 2 -modifiersMode = 0 -continous = false [sub_resource type="Resource" id="Resource_75e6s"] script = ExtResource("1_ikub8") sensors = [SubResource("Resource_jlvht")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [sub_resource type="Resource" id="Resource_gmj7t"] script = ExtResource("3_1wc0w") axis = 1 -type = 0 -continous = false [sub_resource type="Resource" id="Resource_687xx"] script = ExtResource("4_wj7li") button = 12 -continous = false [sub_resource type="Resource" id="Resource_unhue"] script = ExtResource("1_ikub8") sensors = [SubResource("Resource_gmj7t"), SubResource("Resource_687xx")] showOnlyVisibleIcons = true numVisible = 1 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [resource] script = ExtResource("1_ikub8") sensors = [SubResource("Resource_75e6s"), SubResource("Resource_unhue")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false diff --git a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Down.tres b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Down.tres index bc17839..19d5435 100644 --- a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Down.tres +++ b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Down.tres @@ -7,41 +7,19 @@ [sub_resource type="Resource" id="Resource_1iwsh"] script = ExtResource("2_elgr4") key = 69 -keyLocation = 0 -ctrlHold = 2 -altHold = 2 -shiftHold = 2 -modifiersMode = 0 -continous = false [sub_resource type="Resource" id="Resource_jvxvp"] script = ExtResource("1_e8w3r") sensors = [SubResource("Resource_1iwsh")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [sub_resource type="Resource" id="Resource_3ovg5"] script = ExtResource("3_pyik4") button = 10 -continous = false [sub_resource type="Resource" id="Resource_yhdev"] script = ExtResource("1_e8w3r") sensors = [SubResource("Resource_3ovg5")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [resource] script = ExtResource("1_e8w3r") sensors = [SubResource("Resource_jvxvp"), SubResource("Resource_yhdev")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false diff --git a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Forward.tres b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Forward.tres index 1176f22..ea527b4 100644 --- a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Forward.tres +++ b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Forward.tres @@ -8,47 +8,26 @@ [sub_resource type="Resource" id="Resource_8h6fq"] script = ExtResource("2_rofew") key = 87 -keyLocation = 0 -ctrlHold = 2 -altHold = 2 -shiftHold = 2 -modifiersMode = 0 -continous = false [sub_resource type="Resource" id="Resource_nj1ud"] script = ExtResource("1_r4ul7") sensors = [SubResource("Resource_8h6fq")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [sub_resource type="Resource" id="Resource_mxixb"] script = ExtResource("3_nh2m3") axis = 1 type = 1 -continous = false [sub_resource type="Resource" id="Resource_c1vyq"] script = ExtResource("3_dyhbp") button = 11 -continous = false [sub_resource type="Resource" id="Resource_vhtjx"] script = ExtResource("1_r4ul7") sensors = [SubResource("Resource_mxixb"), SubResource("Resource_c1vyq")] showOnlyVisibleIcons = true numVisible = 1 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [resource] script = ExtResource("1_r4ul7") sensors = [SubResource("Resource_nj1ud"), SubResource("Resource_vhtjx")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false diff --git a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Left.tres b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Left.tres index 64e3c30..27c8c23 100644 --- a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Left.tres +++ b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Left.tres @@ -8,47 +8,25 @@ [sub_resource type="Resource" id="Resource_jlvht"] script = ExtResource("2_umtky") key = 65 -keyLocation = 0 -ctrlHold = 2 -altHold = 2 -shiftHold = 2 -modifiersMode = 0 -continous = false [sub_resource type="Resource" id="Resource_qts7v"] script = ExtResource("1_w0cyl") sensors = [SubResource("Resource_jlvht")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [sub_resource type="Resource" id="Resource_gmj7t"] script = ExtResource("3_ushvr") -axis = 0 type = 1 -continous = false [sub_resource type="Resource" id="Resource_687xx"] script = ExtResource("4_53tr6") button = 13 -continous = false [sub_resource type="Resource" id="Resource_0hx40"] script = ExtResource("1_w0cyl") sensors = [SubResource("Resource_gmj7t"), SubResource("Resource_687xx")] showOnlyVisibleIcons = true numVisible = 1 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [resource] script = ExtResource("1_w0cyl") sensors = [SubResource("Resource_qts7v"), SubResource("Resource_0hx40")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false diff --git a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Right.tres b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Right.tres index fa7bb58..086e7ad 100644 --- a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Right.tres +++ b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Right.tres @@ -8,47 +8,24 @@ [sub_resource type="Resource" id="Resource_jlvht"] script = ExtResource("2_prxyq") key = 68 -keyLocation = 0 -ctrlHold = 2 -altHold = 2 -shiftHold = 2 -modifiersMode = 0 -continous = false [sub_resource type="Resource" id="Resource_d1suo"] script = ExtResource("1_vdwin") sensors = [SubResource("Resource_jlvht")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [sub_resource type="Resource" id="Resource_c7ebh"] script = ExtResource("3_4antj") -axis = 0 -type = 0 -continous = false [sub_resource type="Resource" id="Resource_md70b"] script = ExtResource("4_ucs5r") button = 14 -continous = false [sub_resource type="Resource" id="Resource_fhaor"] script = ExtResource("1_vdwin") sensors = [SubResource("Resource_c7ebh"), SubResource("Resource_md70b")] showOnlyVisibleIcons = true numVisible = 1 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [resource] script = ExtResource("1_vdwin") sensors = [SubResource("Resource_d1suo"), SubResource("Resource_fhaor")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false diff --git a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Upward.tres b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Upward.tres index bb9eefb..3b723f4 100644 --- a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Upward.tres +++ b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Move Upward.tres @@ -7,41 +7,21 @@ [sub_resource type="Resource" id="Resource_jt01w"] script = ExtResource("2_g8pg7") key = 81 -keyLocation = 0 -ctrlHold = 2 -altHold = 2 -shiftHold = 2 -modifiersMode = 0 -continous = false [sub_resource type="Resource" id="Resource_pqldp"] script = ExtResource("1_5263n") sensors = [SubResource("Resource_jt01w")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [sub_resource type="Resource" id="Resource_ivi7v"] script = ExtResource("3_ejsq1") button = 9 -continous = false [sub_resource type="Resource" id="Resource_0uxqa"] script = ExtResource("1_5263n") sensors = [SubResource("Resource_ivi7v")] showOnlyVisibleIcons = true numVisible = 1 -inputIcons = [] -useInputIconsFromSensors = true -continous = false [resource] script = ExtResource("1_5263n") sensors = [SubResource("Resource_pqldp"), SubResource("Resource_0uxqa")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false diff --git a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Zoom In.tres b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Zoom In.tres index e337f8e..e00bcd6 100644 --- a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Zoom In.tres +++ b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Zoom In.tres @@ -7,14 +7,7 @@ [sub_resource type="Resource" id="Resource_rjqry"] script = ExtResource("3_5t03r") axis = 5 -type = 0 -continous = false [resource] script = ExtResource("1_lnrk8") sensors = [ExtResource("2_tuiuf"), SubResource("Resource_rjqry")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false diff --git a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Zoom Out.tres b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Zoom Out.tres index ffe8ecf..27edd64 100644 --- a/Runtime/Cameras/EditorCamera/Inputs/Sensors/Zoom Out.tres +++ b/Runtime/Cameras/EditorCamera/Inputs/Sensors/Zoom Out.tres @@ -7,14 +7,7 @@ [sub_resource type="Resource" id="Resource_aybyw"] script = ExtResource("3_pu70j") axis = 4 -type = 0 -continous = false [resource] script = ExtResource("1_w21si") sensors = [ExtResource("2_dk7mn"), SubResource("Resource_aybyw")] -showOnlyVisibleIcons = false -numVisible = 0 -inputIcons = [] -useInputIconsFromSensors = true -continous = false diff --git a/Runtime/Graphs/Graph.cs b/Runtime/Graphs/Graph.cs new file mode 100644 index 0000000..9e4cea0 --- /dev/null +++ b/Runtime/Graphs/Graph.cs @@ -0,0 +1,77 @@ +using System.Collections; +using System.Collections.Generic; +using System; + +namespace Rokojori +{ + public class Graph:GraphWalker where N:class + { + List _nodes = []; + + public Graph( List nodes ) + { + _nodes = nodes; + } + + List> _connections = []; + MapList _fromConnections = new MapList(); + MapList _toConnections = new MapList(); + + + public void Connect( N from, N to ) + { + var c = new GraphConnection(); + c.from = from; + c.to = to; + _connections.Add( c ); + + _toConnections.Add( from, to ); + _fromConnections.Add( to, from ); + } + + public override int NumConnectedTo( N n ) + { + if ( ! _toConnections.ContainsKey( n ) ) + { + return 0; + } + + return _toConnections[ n ].Count; + } + + public override N GetConnectedTo( N n, int index ) + { + if ( ! _toConnections.ContainsKey( n ) ) + { + return null; + } + + return _toConnections[ n ][ index ] ; + } + + public override int NumConnectedFrom( N n ) + { + if ( ! _fromConnections.ContainsKey( n ) ) + { + return 0; + } + + return _fromConnections[ n ].Count; + } + + public override N GetConnectedFrom( N n, int index ) + { + if ( ! _fromConnections.ContainsKey( n ) ) + { + return null; + } + + return _fromConnections[ n ][ index ] ; + } + + public List ComputeOrder() + { + return ComputeOrder( _nodes ); + } + } +} \ No newline at end of file diff --git a/Runtime/Graphs/Graph.cs.uid b/Runtime/Graphs/Graph.cs.uid new file mode 100644 index 0000000..3f1e015 --- /dev/null +++ b/Runtime/Graphs/Graph.cs.uid @@ -0,0 +1 @@ +uid://bqgpm4jivtvau diff --git a/Runtime/Graphs/GraphConnection.cs b/Runtime/Graphs/GraphConnection.cs new file mode 100644 index 0000000..1dad6d1 --- /dev/null +++ b/Runtime/Graphs/GraphConnection.cs @@ -0,0 +1,12 @@ +using System.Collections; +using System.Collections.Generic; +using System; + +namespace Rokojori +{ + public class GraphConnection where N:class + { + public N from; + public N to; + } +} \ No newline at end of file diff --git a/Runtime/Graphs/GraphConnection.cs.uid b/Runtime/Graphs/GraphConnection.cs.uid new file mode 100644 index 0000000..8ca9ec1 --- /dev/null +++ b/Runtime/Graphs/GraphConnection.cs.uid @@ -0,0 +1 @@ +uid://hloxykrb4wgx diff --git a/Runtime/Graphs/GraphWalker.cs b/Runtime/Graphs/GraphWalker.cs index cb4937e..8d04214 100644 --- a/Runtime/Graphs/GraphWalker.cs +++ b/Runtime/Graphs/GraphWalker.cs @@ -85,5 +85,56 @@ namespace Rokojori return false; } + + public List ComputeOrder( List nodes ) + { + var processed = new HashSet(); + var unprocessed = nodes.Clone(); + var order = new List(); + + while ( unprocessed.Count > 0 ) + { + var itemIndex = -1; + + for ( int i = 0; itemIndex == -1 && i < unprocessed.Count; i++ ) + { + if ( CanProcess( unprocessed[ i ], processed ) ) + { + itemIndex = i; + } + } + + if ( itemIndex == -1 ) + { + order.AddRange( unprocessed ); + return order; + } + + var item = unprocessed[ itemIndex ]; + unprocessed.RemoveAt( itemIndex ); + + processed.Add( item ); + order.Add( item ); + } + + return order; + } + + bool CanProcess( N n, HashSet processed ) + { + var dependencies = NumConnectedFrom( n ); + + for ( int i = 0 ; i < dependencies; i++ ) + { + var connected = GetConnectedFrom( n, i ); + + if ( ! processed.Contains( connected ) ) + { + return false; + } + } + + return true; + } } } \ No newline at end of file diff --git a/Runtime/Presets/App/MainModule.cs b/Runtime/Presets/App/MainModule.cs index 1b28c7d..ae162a8 100644 --- a/Runtime/Presets/App/MainModule.cs +++ b/Runtime/Presets/App/MainModule.cs @@ -22,6 +22,9 @@ namespace Rokojori [Export] public bool audioManager = true; + [Export] + public bool renderingManager = true; + [ExportGroup("Camera")] [Export] @@ -85,6 +88,11 @@ namespace Rokojori { root.CreateChild( "Audio Manager" ); } + + if ( renderingManager ) + { + root.CreateChild( "Rendering Manager" ); + } } void CreateCamera( PresetContext context ) diff --git a/Runtime/Procedural/Parametric/Plane/Plane.cs b/Runtime/Procedural/Parametric/Plane/Plane.cs index 111d673..89331e3 100644 --- a/Runtime/Procedural/Parametric/Plane/Plane.cs +++ b/Runtime/Procedural/Parametric/Plane/Plane.cs @@ -29,6 +29,9 @@ namespace Rokojori [Export] public float boundingBoxMaxY = 1; + + [Export] + public bool extendBoundingBoxToMax = true; public readonly EventProperty<__PlaneMeshType__> _type = new EventProperty<__PlaneMeshType__>(); [Export] @@ -92,9 +95,19 @@ namespace Rokojori if ( extendBoundingBox ) { - var extendedBounds = (Box3) outputMesh.Mesh.GetAabb(); - extendedBounds.EnsureYBounds( boundingBoxMinY, boundingBoxMaxY ); - outputMesh.CustomAabb = extendedBounds; + if ( extendBoundingBoxToMax ) + { + outputMesh.CustomAabb = Box3.Create( Vector3.One * -100000, Vector3.One * 100000 ); + } + else + { + var extendedBounds = (Box3) outputMesh.Mesh.GetAabb(); + extendedBounds.EnsureYBounds( boundingBoxMinY, boundingBoxMaxY ); + outputMesh.CustomAabb = extendedBounds; + + } + + } meshes[ i ] = outputMesh; diff --git a/Runtime/Rendering/Assets/Foliage/FoliageData.cs b/Runtime/Rendering/Assets/Foliage/FoliageData.cs index 033479b..a76edd5 100644 --- a/Runtime/Rendering/Assets/Foliage/FoliageData.cs +++ b/Runtime/Rendering/Assets/Foliage/FoliageData.cs @@ -269,10 +269,10 @@ namespace Rokojori particles.CastShadow = renderLayer.data.GetShadows( renderLayer.subLayerIndex ) ? GeometryInstance3D.ShadowCastingSetting.On : GeometryInstance3D.ShadowCastingSetting.Off; - processMaterial.positionVariance.Set( renderLayer.renderer.noise ); - processMaterial.rotationVariance.Set( renderLayer.renderer.noise ); - processMaterial.scaleVariance.Set( renderLayer.renderer.noise ); - processMaterial.occupancyVariance.Set( renderLayer.renderer.noise ); + // processMaterial.positionVariance.Set( renderLayer.renderer.noise ); + // processMaterial.rotationVariance.Set( renderLayer.renderer.noise ); + // processMaterial.scaleVariance.Set( renderLayer.renderer.noise ); + // processMaterial.occupancyVariance.Set( renderLayer.renderer.noise ); renderLayer.gpuFoliageShaderMaterial = processMaterial; diff --git a/Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/StandardMaterialOverride.cs b/Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/StandardMaterialOverride.cs index a845f9b..2c5fe2b 100644 --- a/Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/StandardMaterialOverride.cs +++ b/Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/StandardMaterialOverride.cs @@ -29,6 +29,9 @@ namespace Rokojori [Export] public FoliageTransparencyRenderMode transparencyRenderMode; + [Export] + public FoliageTextureOverride[] textureOverrides = []; + public override void CreateFoliageOverideMaterial( FoliageRenderLayer foliageRenderLayer ) { var gpuParticles3D = foliageRenderLayer.gpuParticles3D; @@ -63,6 +66,18 @@ namespace Rokojori var standardMaterial = (StandardMaterial3D) material; transparencyRenderMode?.ApplyTransparencyMode( standardMaterial, foliageRenderLayer ); + + textureOverrides.ForEach( + ( to )=> + { + if ( to == null ) + { + return; + } + + to.Apply( material ); + } + ); } public override Material GetOverrideMaterial(FoliageRenderLayer foliageRenderLayer) diff --git a/Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/TextureOverride/FoliageTextureOverride.cs b/Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/TextureOverride/FoliageTextureOverride.cs new file mode 100644 index 0000000..37dc8bd --- /dev/null +++ b/Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/TextureOverride/FoliageTextureOverride.cs @@ -0,0 +1,203 @@ +using System.Collections; +using System.Collections.Generic; +using Godot; +using System; +using System.Threading.Tasks; + + + +namespace Rokojori +{ + /** + + + Abstract archetype resource to create foliage texture overrides + + + + + + + + */ + + [Tool] + [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Scatterer.svg") ] + public partial class FoliageTextureOverride:Resource + { + public enum OverrideTarget + { + Albedo, + Normal, + Roughness, + Metallic, + Occlusion, + Specular, + Emission + } + + [Export] + public OverrideTarget target; + + [Export] + public Texture2D texture2D; + + [Export] + public bool assignValue = false; + + [Export] + public Color color; + + public void Apply( Material material ) + { + if ( OverrideTarget.Albedo == target ) + { + ApplyAlbedo( material ); + } + else if ( OverrideTarget.Normal == target ) + { + ApplyNormal( material ); + } + else if ( OverrideTarget.Roughness == target ) + { + ApplyRoughness( material ); + } + else if ( OverrideTarget.Metallic == target ) + { + ApplyMetallic( material ); + } + else if ( OverrideTarget.Occlusion == target ) + { + ApplyOcclusion( material ); + } + else if ( OverrideTarget.Specular == target ) + { + ApplySpecular( material ); + } + else if ( OverrideTarget.Emission == target ) + { + ApplyEmission( material ); + } + } + + + void ApplyAlbedo( Material material ) + { + if ( material is StandardMaterial3D sm ) + { + if ( assignValue ) + { + sm.AlbedoColor = color; + } + + if ( texture2D != null ) + { + sm.AlbedoTexture = texture2D; + } + } + } + + void ApplyNormal( Material material ) + { + + if ( material is StandardMaterial3D sm ) + { + sm.NormalEnabled = true; + + if ( assignValue ) + { + sm.NormalScale = color.R; + } + + if ( texture2D != null ) + { + sm.NormalTexture = texture2D; + } + } + } + + void ApplyRoughness( Material material ) + { + if ( material is StandardMaterial3D sm ) + { + if ( assignValue ) + { + sm.Roughness = color.R; + } + + if ( texture2D != null ) + { + sm.RoughnessTexture = texture2D; + } + } + } + + void ApplyMetallic( Material material ) + { + if ( material is StandardMaterial3D sm ) + { + if ( assignValue ) + { + sm.Metallic = color.R; + } + + if ( texture2D != null ) + { + sm.MetallicTexture = texture2D; + } + } + } + + + void ApplyOcclusion( Material material ) + { + if ( material is StandardMaterial3D sm ) + { + sm.AOEnabled = true; + + if ( assignValue ) + { + sm.AOLightAffect = color.R; + + } + + if ( texture2D != null ) + { + sm.AOTexture = texture2D; + } + } + } + + void ApplySpecular( Material material ) + { + if ( material is StandardMaterial3D sm ) + { + if ( assignValue ) + { + sm.MetallicSpecular = color.R; + + } + + } + } + + void ApplyEmission( Material material ) + { + if ( material is StandardMaterial3D sm ) + { + sm.EmissionEnabled = true; + if ( assignValue ) + { + sm.EmissionIntensity = color.R; + } + + if ( texture2D != null ) + { + sm.EmissionTexture = texture2D; + } + } + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/TextureOverride/FoliageTextureOverride.cs.uid b/Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/TextureOverride/FoliageTextureOverride.cs.uid new file mode 100644 index 0000000..56287e3 --- /dev/null +++ b/Runtime/Rendering/Assets/Foliage/FoliageMaterialOverrides/TextureOverride/FoliageTextureOverride.cs.uid @@ -0,0 +1 @@ +uid://u703jvqweclw diff --git a/Runtime/Rendering/Assets/Foliage/FoliageRenderLayer.cs b/Runtime/Rendering/Assets/Foliage/FoliageRenderLayer.cs index 9f91173..118ba37 100644 --- a/Runtime/Rendering/Assets/Foliage/FoliageRenderLayer.cs +++ b/Runtime/Rendering/Assets/Foliage/FoliageRenderLayer.cs @@ -137,6 +137,16 @@ namespace Rokojori gpuFoliageShaderMaterial.hideStart.Set( hideStart ); gpuFoliageShaderMaterial.hideOffset.Set( data.GetVisibilityFadeHidingOffset( subLayerIndex ) ); + gpuFoliageShaderMaterial.mapCenter.Set( renderer.globalMapSizeXZ ); + gpuFoliageShaderMaterial.mapSize.Set( renderer.globalMapSizeXZ ); + + gpuFoliageShaderMaterial.heightMap.Set( renderer.heightMap ); + gpuFoliageShaderMaterial.minHeight.Set( renderer.minHeight ); + gpuFoliageShaderMaterial.maxHeight.Set( renderer.maxHeight ); + + gpuFoliageShaderMaterial.coverageMap.Set( renderer.coverageMap ); + + gpuFoliageShaderMaterial.positionVariance.Set( renderer.noise ); gpuFoliageShaderMaterial.rotationVariance.Set( renderer.noise ); gpuFoliageShaderMaterial.scaleVariance.Set( renderer.noise ); diff --git a/Runtime/Rendering/Assets/Foliage/FoliageRenderer.cs b/Runtime/Rendering/Assets/Foliage/FoliageRenderer.cs index 3e0d47c..d6bb14d 100644 --- a/Runtime/Rendering/Assets/Foliage/FoliageRenderer.cs +++ b/Runtime/Rendering/Assets/Foliage/FoliageRenderer.cs @@ -49,6 +49,43 @@ namespace Rokojori [Export] public Camera3D camera; + + [Export] + public Vector2 globalMapSizeXZ; + + [Export] + public Vector2 globalMapCenterXZ; + + [ExportGroup("Shared/Region")] + [Export] + public bool trimToRegion = false; + + [Export] + public Vector2 regionSizeXZ; + + [Export] + public Vector2 regionCenterXZ; + + [ExportGroup("Shared")] + + [Export] + public Texture2D heightMap; + + [Export] + public float minHeight = 0; + + [Export] + public float maxHeight = 100; + + [Export] + public Texture2D normalMap; + + [Export] + public Texture2D coverageMap; + + [Export] + public Texture2D colorMap; + [Export] public Texture2D noise; diff --git a/Runtime/Rendering/Assets/Foliage/GPUFoliageShader.gdshader b/Runtime/Rendering/Assets/Foliage/GPUFoliageShader.gdshader index 73d183f..c784301 100644 --- a/Runtime/Rendering/Assets/Foliage/GPUFoliageShader.gdshader +++ b/Runtime/Rendering/Assets/Foliage/GPUFoliageShader.gdshader @@ -15,6 +15,10 @@ uniform vec3 positionOffset = vec3(0,0,0); uniform vec2 positionUVScale = vec2( 1.0, 1.0 ); uniform vec2 positionUVOffset = vec2( 1.0, 1.0 ); uniform float heightOffset = 0; +uniform sampler2D heightMap; +uniform float minHeight = 0; +uniform float maxHeight = 100; + uniform sampler2D rotationVariance; uniform vec3 minRotation = vec3( 0, 0, 0 ); @@ -37,11 +41,14 @@ uniform float occupancyHideScale = 0.1; uniform sampler2D occupancyVariance; uniform vec2 occupancyUVScale = vec2( 1.0, 1.0 ); uniform vec2 occupancyUVOffset = vec2( 1.0, 1.0 ); +uniform bool discardFullyHidden = true; uniform float hideStart = 40; uniform float hideMax = 60; uniform float hideOffset = -0.6; +uniform sampler2D coverageMap; +uniform sampler2D colorMap; uniform vec2 mapSize = vec2(1024,1024); uniform vec2 mapCenter = vec2(0,0); @@ -80,6 +87,8 @@ void process() vec2 mapOffset = mapCenter - mapSize/2.0; vec2 uv = ( vec2( position3D.x, position3D.z ) - mapOffset ) / mapSize; + + vec3 offset = (textureLod( positionVariance, tilingOffset( uv, positionUVScale, positionUVOffset ), 0 ).rgb - vec3(0.5,0.5,0.5) ) * maxPositionOffset; position3D += offset + positionOffset; vec3 rotSampled = textureLod( rotationVariance, tilingOffset( uv, rotationUVScale, rotationUVOffset ), 0 ).rgb; @@ -89,10 +98,19 @@ void process() sca = sca * ( maxScale - minScale ) + minScale; vec2 uv2 = ( vec2( position3D.x, position3D.z ) - mapOffset ) / mapSize; - + float sampledHeight = textureLod( heightMap, uv2, 0 ).r; float occ = textureLod( occupancyVariance, tilingOffset( uv2, occupancyUVScale, occupancyUVOffset ), 0 ).r; + float sampledCoverage = textureLod( coverageMap, uv2, 0 ).r; + occ = clamp( ( occ - occupancyTreshold ) * occupancyPower + occupancyTreshold, 0.0, 1.0 ); - sca *= mix( 1.0, occupancyHideScale , ( 1.0 - occ ) * occupancyAmount ); - position3D.y += ( 1.0 - occ ) * occupancyAmount * occupancyHideOffset; + occ = 1.0 - occ; + + occ = min( occ, 1.0 - sampledCoverage ); + + sca *= mix( 1.0, occupancyHideScale , occ * occupancyAmount ); + position3D.y += occ * occupancyAmount * occupancyHideOffset; + position3D.y += mix( minHeight, maxHeight, sampledHeight ); + + TRANSFORM = TRS( position3D, rot, vec3( sca.x , sca.y, sca.z ) ); } diff --git a/Runtime/Rendering/Assets/Foliage/GPUFoliageShaderMaterial.cs b/Runtime/Rendering/Assets/Foliage/GPUFoliageShaderMaterial.cs index 7296b6f..d129b13 100644 --- a/Runtime/Rendering/Assets/Foliage/GPUFoliageShaderMaterial.cs +++ b/Runtime/Rendering/Assets/Foliage/GPUFoliageShaderMaterial.cs @@ -21,6 +21,9 @@ namespace Rokojori public static readonly Vector2PropertyName positionUvScale = Vector2PropertyName.Create( "positionUVScale" ); public static readonly Vector2PropertyName positionUvOffset = Vector2PropertyName.Create( "positionUVOffset" ); public static readonly FloatPropertyName heightOffset = FloatPropertyName.Create( "heightOffset" ); + public static readonly Texture2DPropertyName heightMap = Texture2DPropertyName.Create( "heightMap" ); + public static readonly FloatPropertyName minHeight = FloatPropertyName.Create( "minHeight" ); + public static readonly FloatPropertyName maxHeight = FloatPropertyName.Create( "maxHeight" ); public static readonly Texture2DPropertyName rotationVariance = Texture2DPropertyName.Create( "rotationVariance" ); public static readonly Vector3PropertyName minRotation = Vector3PropertyName.Create( "minRotation" ); public static readonly Vector3PropertyName maxRotation = Vector3PropertyName.Create( "maxRotation" ); @@ -42,6 +45,7 @@ namespace Rokojori public static readonly FloatPropertyName hideStart = FloatPropertyName.Create( "hideStart" ); public static readonly FloatPropertyName hideMax = FloatPropertyName.Create( "hideMax" ); public static readonly FloatPropertyName hideOffset = FloatPropertyName.Create( "hideOffset" ); + public static readonly Texture2DPropertyName coverageMap = Texture2DPropertyName.Create( "coverageMap" ); public static readonly Vector2PropertyName mapSize = Vector2PropertyName.Create( "mapSize" ); public static readonly Vector2PropertyName mapCenter = Vector2PropertyName.Create( "mapCenter" ); @@ -63,6 +67,9 @@ namespace Rokojori public readonly CustomMaterialProperty positionUvScale; public readonly CustomMaterialProperty positionUvOffset; public readonly CustomMaterialProperty heightOffset; + public readonly CustomMaterialProperty heightMap; + public readonly CustomMaterialProperty minHeight; + public readonly CustomMaterialProperty maxHeight; public readonly CustomMaterialProperty rotationVariance; public readonly CustomMaterialProperty minRotation; public readonly CustomMaterialProperty maxRotation; @@ -84,6 +91,7 @@ namespace Rokojori public readonly CustomMaterialProperty hideStart; public readonly CustomMaterialProperty hideMax; public readonly CustomMaterialProperty hideOffset; + public readonly CustomMaterialProperty coverageMap; public readonly CustomMaterialProperty mapSize; public readonly CustomMaterialProperty mapCenter; @@ -102,6 +110,9 @@ namespace Rokojori positionUvScale = new CustomMaterialProperty( this, GPUFoliageShaderShader.positionUvScale ); positionUvOffset = new CustomMaterialProperty( this, GPUFoliageShaderShader.positionUvOffset ); heightOffset = new CustomMaterialProperty( this, GPUFoliageShaderShader.heightOffset ); + heightMap = new CustomMaterialProperty( this, GPUFoliageShaderShader.heightMap ); + minHeight = new CustomMaterialProperty( this, GPUFoliageShaderShader.minHeight ); + maxHeight = new CustomMaterialProperty( this, GPUFoliageShaderShader.maxHeight ); rotationVariance = new CustomMaterialProperty( this, GPUFoliageShaderShader.rotationVariance ); minRotation = new CustomMaterialProperty( this, GPUFoliageShaderShader.minRotation ); maxRotation = new CustomMaterialProperty( this, GPUFoliageShaderShader.maxRotation ); @@ -123,6 +134,7 @@ namespace Rokojori hideStart = new CustomMaterialProperty( this, GPUFoliageShaderShader.hideStart ); hideMax = new CustomMaterialProperty( this, GPUFoliageShaderShader.hideMax ); hideOffset = new CustomMaterialProperty( this, GPUFoliageShaderShader.hideOffset ); + coverageMap = new CustomMaterialProperty( this, GPUFoliageShaderShader.coverageMap ); mapSize = new CustomMaterialProperty( this, GPUFoliageShaderShader.mapSize ); mapCenter = new CustomMaterialProperty( this, GPUFoliageShaderShader.mapCenter ); } diff --git a/Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader b/Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader new file mode 100644 index 0000000..abe70d8 --- /dev/null +++ b/Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader @@ -0,0 +1,108 @@ + +shader_type spatial; +render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx; + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc" +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Normals.gdshaderinc" +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc" + + +uniform vec4 albedo : source_color; +uniform sampler2D texture_albedo : source_color, filter_linear_mipmap_anisotropic, repeat_enable; +uniform ivec2 albedo_texture_size; +uniform float point_size : hint_range(0.1, 128.0, 0.1); + +uniform float roughness : hint_range(0.0, 1.0); +uniform sampler2D texture_metallic : hint_default_white, filter_linear_mipmap_anisotropic, repeat_enable; +uniform vec4 metallic_texture_channel; +uniform sampler2D texture_roughness : hint_roughness_r, filter_linear_mipmap_anisotropic, repeat_enable; + +uniform float specular : hint_range(0.0, 1.0, 0.01); +uniform float metallic : hint_range(0.0, 1.0, 0.01); + +uniform sampler2D texture_normal : hint_roughness_normal, filter_linear_mipmap_anisotropic, repeat_enable; +uniform float normal_scale : hint_range(-16.0, 16.0); +varying vec3 uv1_triplanar_pos; + +uniform float uv1_blend_sharpness : hint_range(0.0, 150.0, 0.001); +varying vec3 uv1_power_normal; + +uniform vec3 uv1_scale; +uniform vec3 uv1_offset; +uniform vec3 uv2_scale; +uniform vec3 uv2_offset; + +uniform vec2 mapSize = vec2(1024,1024); +uniform vec2 mapCenter = vec2(0,0); +uniform sampler2D heightMap; +uniform float minHeight = 0; +uniform float maxHeight = 0; + +uniform float normalTexelSize = 0.1; +uniform float normalHeightSize = 1; +varying vec2 heightUV; + +uniform float snapDistance: hint_range(5.0, 100.0) = 25; + +void vertex() +{ + vec3 quantizedCam = snapRounded( CAMERA_POSITION_WORLD, snapDistance ); + quantizedCam.y = 0.0; + VERTEX += quantizedCam; + vec3 position3D = localToWorld( VERTEX, MODEL_MATRIX ); + + vec2 mapOffset = mapCenter - mapSize/2.0; + vec2 uv = ( vec2( position3D.x, position3D.z ) - mapOffset ) / mapSize; + heightUV = uv; + float sampledHeight = textureLod( heightMap, uv, 0 ).r; + position3D.y += mix( minHeight, maxHeight, sampledHeight ); + + VERTEX = worldToLocal( position3D, MODEL_MATRIX ); + + vec3 normal = MODEL_NORMAL_MATRIX * NORMAL; + + TANGENT = vec3(0.0, 0.0, -1.0) * abs(normal.x); + TANGENT += vec3(1.0, 0.0, 0.0) * abs(normal.y); + TANGENT += vec3(1.0, 0.0, 0.0) * abs(normal.z); + TANGENT = inverse(MODEL_NORMAL_MATRIX) * normalize(TANGENT); + + BINORMAL = vec3(0.0, 1.0, 0.0) * abs(normal.x); + BINORMAL += vec3(0.0, 0.0, -1.0) * abs(normal.y); + BINORMAL += vec3(0.0, 1.0, 0.0) * abs(normal.z); + BINORMAL = inverse(MODEL_NORMAL_MATRIX) * normalize(BINORMAL); + + // UV1 Triplanar: Enabled (with World Triplanar) + uv1_power_normal = pow(abs(normal), vec3(uv1_blend_sharpness)); + uv1_triplanar_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz * uv1_scale + uv1_offset; + uv1_power_normal /= dot(uv1_power_normal, vec3(1.0)); + uv1_triplanar_pos *= vec3(1.0, -1.0, 1.0); +} + +vec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) +{ + vec4 samp = vec4(0.0); + samp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z; + samp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y; + samp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x; + return samp; +} + +void fragment() +{ + vec4 albedo_tex = triplanar_texture(texture_albedo, uv1_power_normal, uv1_triplanar_pos); + ALBEDO = albedo.rgb * albedo_tex.rgb; + + float metallic_tex = dot(triplanar_texture(texture_metallic, uv1_power_normal, uv1_triplanar_pos), metallic_texture_channel); + METALLIC = metallic_tex * metallic; + SPECULAR = specular; + + vec4 roughness_texture_channel = vec4(1.0, 0.0, 0.0, 0.0); + float roughness_tex = dot(triplanar_texture(texture_roughness, uv1_power_normal, uv1_triplanar_pos), roughness_texture_channel); + ROUGHNESS = roughness_tex * roughness; + + vec3 worldNormal = computeNormalFromHeightMap( heightMap, heightUV, normalTexelSize, normalHeightSize ); + NORMAL = worldToViewDirection( worldNormal, VIEW_MATRIX ); + // Normal Map: Enabled + NORMAL_MAP = triplanar_texture(texture_normal, uv1_power_normal, uv1_triplanar_pos).rgb; + NORMAL_MAP_DEPTH = normal_scale; +} diff --git a/Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader.uid b/Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader.uid new file mode 100644 index 0000000..2e242b8 --- /dev/null +++ b/Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader.uid @@ -0,0 +1 @@ +uid://diw3ibat8rjxx diff --git a/Runtime/Rendering/RenderingManager.cs b/Runtime/Rendering/RenderingManager.cs index 6bb4e38..08a8db5 100644 --- a/Runtime/Rendering/RenderingManager.cs +++ b/Runtime/Rendering/RenderingManager.cs @@ -14,5 +14,24 @@ namespace Rokojori { [Export] public RenderingManagerData data; + + public static int GetStencilReferenceIndex( StencilLayer stencilLayer ) + { + if ( stencilLayer == null ) + { + return -1; + } + + var rm = Unique.Get(); + + if ( rm == null ) + { + return stencilLayer.fallBackIndex; + } + + var rmIndex = rm.data.stencilLayers.IndexOf( stencilLayer ); + + return rmIndex == -1 ? stencilLayer.fallBackIndex : ( rmIndex + 1 ); + } } } \ No newline at end of file diff --git a/Runtime/Rendering/RenderingManagerData.cs b/Runtime/Rendering/RenderingManagerData.cs index 42d42a0..fb3c2fb 100644 --- a/Runtime/Rendering/RenderingManagerData.cs +++ b/Runtime/Rendering/RenderingManagerData.cs @@ -14,5 +14,9 @@ namespace Rokojori { [Export] public RenderingPriority[] renderingPriorities; + + + [Export] + public StencilLayer[] stencilLayers; } } \ No newline at end of file diff --git a/Runtime/Rendering/StencilLayer.cs b/Runtime/Rendering/StencilLayer.cs new file mode 100644 index 0000000..c1744b1 --- /dev/null +++ b/Runtime/Rendering/StencilLayer.cs @@ -0,0 +1,18 @@ + +using System.Diagnostics; +using System.Collections; +using System.Collections.Generic; +using System; +using Godot; + + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class StencilLayer:Resource + { + [Export] + public int fallBackIndex = 0; + } +} \ No newline at end of file diff --git a/Runtime/Rendering/StencilLayer.cs.uid b/Runtime/Rendering/StencilLayer.cs.uid new file mode 100644 index 0000000..926c04b --- /dev/null +++ b/Runtime/Rendering/StencilLayer.cs.uid @@ -0,0 +1 @@ +uid://bsd5qj85xsio4 diff --git a/Runtime/Sensors/Default-Sensors/Default-Input-Icons-Library.tres b/Runtime/Sensors/Default-Sensors/Default-Input-Icons-Library.tres index 31888ea..3e63757 100644 --- a/Runtime/Sensors/Default-Sensors/Default-Input-Icons-Library.tres +++ b/Runtime/Sensors/Default-Sensors/Default-Input-Icons-Library.tres @@ -46,8 +46,6 @@ button = 5 script = ExtResource("2_g15ft") icons = [SubResource("Resource_m53ti"), SubResource("Resource_a3cu1")] texture = ExtResource("3_pm2rw") -widthScale = 1.0 -orderMode = 2 isUpperCase = false fontSizeScale = 0.0 @@ -63,8 +61,6 @@ button = 14 script = ExtResource("2_g15ft") icons = [SubResource("Resource_xbpgk"), SubResource("Resource_laa4d")] texture = ExtResource("5_ycc70") -widthScale = 1.0 -orderMode = 2 isUpperCase = false fontSizeScale = 0.0 @@ -80,33 +76,24 @@ button = 12 script = ExtResource("2_g15ft") icons = [SubResource("Resource_4mvgb"), SubResource("Resource_l8cwl")] texture = ExtResource("6_6nxcf") -widthScale = 1.0 -orderMode = 2 isUpperCase = false fontSizeScale = 0.0 [sub_resource type="Resource" id="Resource_8bcch"] script = ExtResource("7_y0txw") -axis = 0 -type = 0 [sub_resource type="Resource" id="Resource_rlnb1"] script = ExtResource("7_y0txw") -axis = 0 type = 1 [sub_resource type="Resource" id="Resource_fmatu"] script = ExtResource("20_55eoq") en = "L" -entries = [] -context = "" [sub_resource type="Resource" id="Resource_tqg5p"] script = ExtResource("2_g15ft") icons = [SubResource("Resource_8bcch"), SubResource("Resource_rlnb1")] texture = ExtResource("9_eeamd") -widthScale = 1.0 -orderMode = 2 label = SubResource("Resource_fmatu") isUpperCase = false fontSizeScale = 0.8 @@ -119,28 +106,21 @@ type = 1 [sub_resource type="Resource" id="Resource_vjbhe"] script = ExtResource("7_y0txw") axis = 1 -type = 0 [sub_resource type="Resource" id="Resource_q8dch"] script = ExtResource("20_55eoq") en = "L" -entries = [] -context = "" [sub_resource type="Resource" id="Resource_3oyc0"] script = ExtResource("2_g15ft") icons = [SubResource("Resource_vi3u1"), SubResource("Resource_vjbhe")] texture = ExtResource("10_3i85w") -widthScale = 1.0 -orderMode = 2 label = SubResource("Resource_q8dch") -isUpperCase = true fontSizeScale = 0.8 [sub_resource type="Resource" id="Resource_wd2xx"] script = ExtResource("7_y0txw") axis = 2 -type = 0 [sub_resource type="Resource" id="Resource_h3a17"] script = ExtResource("7_y0txw") @@ -150,15 +130,11 @@ type = 1 [sub_resource type="Resource" id="Resource_07ljj"] script = ExtResource("20_55eoq") en = "R" -entries = [] -context = "" [sub_resource type="Resource" id="Resource_c6gt5"] script = ExtResource("2_g15ft") icons = [SubResource("Resource_wd2xx"), SubResource("Resource_h3a17")] texture = ExtResource("9_eeamd") -widthScale = 1.0 -orderMode = 2 label = SubResource("Resource_07ljj") isUpperCase = false fontSizeScale = 0.8 @@ -171,17 +147,12 @@ type = 1 [sub_resource type="Resource" id="Resource_4ro5i"] script = ExtResource("20_55eoq") en = "R" -entries = [] -context = "" [sub_resource type="Resource" id="Resource_812y6"] script = ExtResource("2_g15ft") icons = [SubResource("Resource_qmgk3"), SubResource("Resource_vjbhe")] texture = ExtResource("10_3i85w") -widthScale = 1.0 -orderMode = 2 label = SubResource("Resource_4ro5i") -isUpperCase = true fontSizeScale = 0.8 [sub_resource type="Resource" id="Resource_udrbd"] @@ -192,39 +163,20 @@ combined = [SubResource("Resource_xpfqu"), SubResource("Resource_28c0y"), SubRes script = ExtResource("5_sn8hr") backgroundTexture = ExtResource("5_amgur") directionUpTexture = ExtResource("6_0hfff") -directionalOffset = 0.0 -fontSizeScale = 1.0 -isUpperCase = true [sub_resource type="Resource" id="Resource_40bf3"] script = ExtResource("2_4sutq") value = 0.7 unit = "em" -isAnimated = false -animationDuration = 0.0 -animationOffset = 0.0 [sub_resource type="Resource" id="Resource_xrtll"] script = ExtResource("1_64knt") backgroundTexture = ExtResource("10_q44jo") -widthScale = 1.0 -fontSizeScale = 1.0 -fontSizeCharacterMultiply = 0.9 -fontIsUpperCase = true hasLabel = false -borderLeft = 0.0 -borderRight = 0.0 -borderTop = 0.0 -borderBottom = 0.0 [sub_resource type="Resource" id="Resource_nkgsq"] script = ExtResource("1_64knt") backgroundTexture = ExtResource("12_mf3bj") -widthScale = 1.0 -fontSizeScale = 1.0 -fontSizeCharacterMultiply = 0.9 -fontIsUpperCase = true -hasLabel = true borderLeft = 40.0 borderRight = 40.0 borderTop = 40.0 @@ -236,8 +188,6 @@ backgroundTexture = ExtResource("12_mf3bj") widthScale = 2.0 fontSizeScale = 0.7 fontSizeCharacterMultiply = 1.0 -fontIsUpperCase = true -hasLabel = true borderLeft = 40.0 borderRight = 40.0 borderTop = 40.0 @@ -249,56 +199,27 @@ rightIndicatorTexture = ExtResource("13_ijjqw") script = ExtResource("1_64knt") backgroundTexture = ExtResource("14_6vom6") widthScale = 2.0 -fontSizeScale = 1.0 -fontSizeCharacterMultiply = 0.9 -fontIsUpperCase = true hasLabel = false -borderLeft = 0.0 -borderRight = 0.0 -borderTop = 0.0 -borderBottom = 0.0 [sub_resource type="Resource" id="Resource_qt31g"] script = ExtResource("20_55eoq") en = "L" -entries = [] -context = "" [sub_resource type="Resource" id="Resource_4s1kq"] script = ExtResource("5_sn8hr") backgroundTexture = ExtResource("18_amimm") directionUpTexture = ExtResource("20_r1y6a") -directionalOffset = 0.0 label = SubResource("Resource_qt31g") fontSizeScale = 0.8 -isUpperCase = true buttonPressTexture = ExtResource("19_7x4g0") [sub_resource type="Resource" id="Resource_dr7bt"] script = ExtResource("1_64knt") backgroundTexture = ExtResource("13_omll7") -widthScale = 1.0 -fontSizeScale = 1.0 -fontSizeCharacterMultiply = 0.9 -fontIsUpperCase = true -hasLabel = true -borderLeft = 0.0 -borderRight = 0.0 -borderTop = 0.0 -borderBottom = 0.0 [sub_resource type="Resource" id="Resource_2rh0g"] script = ExtResource("1_64knt") backgroundTexture = ExtResource("14_n68qo") -widthScale = 1.0 -fontSizeScale = 1.0 -fontSizeCharacterMultiply = 0.9 -fontIsUpperCase = true -hasLabel = true -borderLeft = 0.0 -borderRight = 0.0 -borderTop = 0.0 -borderBottom = 0.0 [sub_resource type="Resource" id="Resource_34cgw"] script = ExtResource("5_a3fep") @@ -311,31 +232,18 @@ wheelDownTexture = ExtResource("6_qyc6e") [sub_resource type="Resource" id="Resource_5ywoi"] script = ExtResource("20_55eoq") en = "R" -entries = [] -context = "" [sub_resource type="Resource" id="Resource_jl0ql"] script = ExtResource("5_sn8hr") backgroundTexture = ExtResource("18_amimm") directionUpTexture = ExtResource("20_r1y6a") -directionalOffset = 0.0 label = SubResource("Resource_5ywoi") fontSizeScale = 0.8 -isUpperCase = true buttonPressTexture = ExtResource("19_7x4g0") [sub_resource type="Resource" id="Resource_b5rf1"] script = ExtResource("1_64knt") backgroundTexture = ExtResource("21_hcyk3") -widthScale = 1.0 -fontSizeScale = 1.0 -fontSizeCharacterMultiply = 0.9 -fontIsUpperCase = true -hasLabel = true -borderLeft = 0.0 -borderRight = 0.0 -borderTop = 0.0 -borderBottom = 0.0 [resource] script = ExtResource("1_urlfx") @@ -353,4 +261,3 @@ digitalPad = SubResource("Resource_s3w6q") leftJoystick = SubResource("Resource_4s1kq") rightJoystick = SubResource("Resource_jl0ql") combinedInputs = SubResource("Resource_udrbd") -locales = [] diff --git a/Runtime/Shading/Generators/Generic/ShaderCode.cs b/Runtime/Shading/Generators/Generic/ShaderCode.cs new file mode 100644 index 0000000..d427ce7 --- /dev/null +++ b/Runtime/Shading/Generators/Generic/ShaderCode.cs @@ -0,0 +1,184 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + + public class ShaderCode + { + public string variantName = ""; + public ShaderPhase phase; + public bool sortableCode = false; + public List variableOccurances = new List(); + + + protected virtual string _GetCode( ShaderGenerationContext context ) + { + return ""; + } + + public string GetCode( ShaderGenerationContext context ) + { + return _GetCode( context ); + } + + public void ResolveVariableOccurances( ShaderGenerationContext context ) + { + var code = GetCode( context ); + var lexed = GDShaderLexer.Lex( code ); + var index = lexed.CreateIndex(); + + var relevantVariables = ShaderCodeVariable.DefaultVariables.Map( v => v.variableName ).CreateSet(); + var foundVariables = lexed.Filter( le => le.Is( LexerMatcherLibrary.CwordMatcher ) && relevantVariables.Contains( le.match ) ); + + var mapped = new Dictionary(); + + foundVariables.ForEach( + ( w )=> + { + var nextTokenResult = LexerEvent.Find( lexed, index[ w ], + ( le ) => + { + if ( le.Is( LexerMatcherLibrary.OperatorMatcher ) ) + { + return LexerEvent.FindResultType.Found; + } + + if ( le.IsAnyOf( LexerMatcherLibrary.Ignore ) ) + { + return LexerEvent.FindResultType.KeepSearching; + } + + return LexerEvent.FindResultType.NotFound; + + } + ); + + + if ( LexerEvent.FindResultType.NotFound == nextTokenResult.type ) + { + variableOccurances.Add( ShaderCodeVariableOccurance.Read( w.match ) ); + } + else + { + var token = lexed[ nextTokenResult.index ]; + + if ( token.match == "=" ) + { + variableOccurances.Add( ShaderCodeVariableOccurance.Assignment( w.match ) ); + } + else if ( token.MatchIsAny( "++", "--", "+=", "-=", "*=", "/=" ) ) + { + variableOccurances.Add( ShaderCodeVariableOccurance.Modification( w.match ) ); + } + else + { + variableOccurances.Add( ShaderCodeVariableOccurance.Read( w.match ) ); + } + } + + mapped[ variableOccurances.Last() ] = w; + } + ); + + variableOccurances.ForEach( + ( vo )=> + { + var lineInfo = mapped[ vo ].GetLineInfo( code ); + RJLog.Log( vo.type, ":", vo.variable.variableName, " >> ", lineInfo ); + } + ); + + } + + + } + + public class StringShaderCode:ShaderCode + { + public string code = ""; + + public StringShaderCode( string code ) + { + this.code = code; + } + + protected override string _GetCode( ShaderGenerationContext context ) + { + return code; + } + + public static StringShaderCode FromLines( List code, bool addBreaks = true ) + { + return new StringShaderCode( code.Join( addBreaks ? "\n" : "" ) ); + } + } + + public class BuiltInTextureShaderCode:ShaderCode + { + public enum TextureType + { + Screen, + Depth, + NormalRoughness + } + + public TextureType textureType => _textureType; + TextureType _textureType; + + public static BuiltInTextureShaderCode Screen + { + get + { + var sc = new BuiltInTextureShaderCode(); + sc._textureType = TextureType.Screen; + return sc; + } + } + + public static BuiltInTextureShaderCode Depth + { + get + { + var sc = new BuiltInTextureShaderCode(); + sc._textureType = TextureType.Depth; + return sc; + } + } + + public static BuiltInTextureShaderCode NormalRoughness + { + get + { + var sc = new BuiltInTextureShaderCode(); + sc._textureType = TextureType.NormalRoughness; + return sc; + } + } + + public ShaderCode GetBuiltInCode() + { + if ( _textureType == TextureType.Screen ) + { + return new StringShaderCode( ShaderGenerationModule.ScreenTextureUniform().LineBreak() ); + } + + if ( _textureType == TextureType.Depth ) + { + return new StringShaderCode( ShaderGenerationModule.DepthTextureUniform().LineBreak() ); + } + + if ( _textureType == TextureType.NormalRoughness ) + { + return new StringShaderCode( ShaderGenerationModule.NormalRoughnessTextureUniform().LineBreak() ); + } + + return null; + } + + + } + +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/ShaderCode.cs.uid b/Runtime/Shading/Generators/Generic/ShaderCode.cs.uid similarity index 100% rename from Runtime/Shading/Generators/ShaderCode.cs.uid rename to Runtime/Shading/Generators/Generic/ShaderCode.cs.uid diff --git a/Runtime/Shading/Generators/Generic/ShaderCodeStage.cs b/Runtime/Shading/Generators/Generic/ShaderCodeStage.cs new file mode 100644 index 0000000..663b95d --- /dev/null +++ b/Runtime/Shading/Generators/Generic/ShaderCodeStage.cs @@ -0,0 +1,20 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + public enum ShaderCodeStage + { + Vertex, + Fragment, + Light + } + + public static class ShaderCodeStages + { + public static readonly List Spatial = + [ ShaderCodeStage.Vertex, ShaderCodeStage.Fragment, ShaderCodeStage.Light ]; + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Generic/ShaderCodeStage.cs.uid b/Runtime/Shading/Generators/Generic/ShaderCodeStage.cs.uid new file mode 100644 index 0000000..490aa0e --- /dev/null +++ b/Runtime/Shading/Generators/Generic/ShaderCodeStage.cs.uid @@ -0,0 +1 @@ +uid://be11x132nwd1y diff --git a/Runtime/Shading/Generators/Generic/ShaderCodeVariable.cs b/Runtime/Shading/Generators/Generic/ShaderCodeVariable.cs new file mode 100644 index 0000000..571ea67 --- /dev/null +++ b/Runtime/Shading/Generators/Generic/ShaderCodeVariable.cs @@ -0,0 +1,67 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + + public class ShaderCodeVariable + { + public static readonly ShaderCodeVariable VERTEX = new ShaderCodeVariable( "VERTEX", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable NORMAL = new ShaderCodeVariable( "NORMAL", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable UV = new ShaderCodeVariable( "UV", ShaderCodeStages.Spatial, true ); + + public static readonly ShaderCodeVariable ALBEDO = new ShaderCodeVariable( "ALBEDO", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable ALPHA = new ShaderCodeVariable( "ALPHA", ShaderCodeStages.Spatial, true ); + + public static readonly ShaderCodeVariable NORMAL_MAP = new ShaderCodeVariable( "NORMAL_MAP", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable NORMAL_MAP_DEPTH = new ShaderCodeVariable( "NORMAL_MAP_DEPTH", ShaderCodeStages.Spatial, true ); + + public static readonly ShaderCodeVariable AO = new ShaderCodeVariable( "AO", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable ROUGHNESS = new ShaderCodeVariable( "ROUGHNESS", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable METALLIC = new ShaderCodeVariable( "METALLIC", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable SPECULAR = new ShaderCodeVariable( "SPECULAR", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable EMISSION = new ShaderCodeVariable( "EMISSION", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable BACKLIGHT = new ShaderCodeVariable( "BACKLIGHT", ShaderCodeStages.Spatial, true ); + + public static readonly ShaderCodeVariable SSS_STRENGTH = new ShaderCodeVariable( "SSS_STRENGTH", ShaderCodeStages.Spatial, true ); + + public static readonly ShaderCodeVariable SSS_TRANSMITTANCE_COLOR = new ShaderCodeVariable( "SSS_TRANSMITTANCE_COLOR", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable SSS_TRANSMITTANCE_DEPTH = new ShaderCodeVariable( "SSS_TRANSMITTANCE_DEPTH", ShaderCodeStages.Spatial, true ); + public static readonly ShaderCodeVariable SSS_TRANSMITTANCE_BOOST = new ShaderCodeVariable( "SSS_TRANSMITTANCE_BOOST", ShaderCodeStages.Spatial, true ); + + public static readonly ShaderCodeVariable MODEL_MATRIX = new ShaderCodeVariable( "MODEL_MATRIX", ShaderCodeStages.Spatial, true ); + + public static readonly List DefaultVariables = + [ + VERTEX, NORMAL, UV, + ALBEDO, ALPHA, + NORMAL_MAP, NORMAL_MAP_DEPTH, + AO, ROUGHNESS, METALLIC, SPECULAR, + EMISSION, BACKLIGHT, SSS_STRENGTH, + SSS_TRANSMITTANCE_COLOR, SSS_TRANSMITTANCE_DEPTH, SSS_TRANSMITTANCE_BOOST, + MODEL_MATRIX + ]; + + string _variableName; + public string variableName => _variableName; + + bool _builtIn = false; + public bool builtIn => _builtIn; + + List _stages = new List(); + public List stages => _stages; + + + public ShaderCodeVariable( string name, List stages, bool builtIn = false ) + { + _variableName = name; + _stages = stages; + _builtIn = builtIn; + + } + } + + +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Generic/ShaderCodeVariable.cs.uid b/Runtime/Shading/Generators/Generic/ShaderCodeVariable.cs.uid new file mode 100644 index 0000000..91262e2 --- /dev/null +++ b/Runtime/Shading/Generators/Generic/ShaderCodeVariable.cs.uid @@ -0,0 +1 @@ +uid://bb6q3uj0c5kj0 diff --git a/Runtime/Shading/Generators/Generic/ShaderCodeVariableOccurance.cs b/Runtime/Shading/Generators/Generic/ShaderCodeVariableOccurance.cs new file mode 100644 index 0000000..00ac752 --- /dev/null +++ b/Runtime/Shading/Generators/Generic/ShaderCodeVariableOccurance.cs @@ -0,0 +1,47 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + public enum ShaderCodeVariableOccuranceType + { + Read, + Assignment, // = + Modification // ++, --, +=, *= + } + + public class ShaderCodeVariableOccurance + { + public ShaderCodeVariableOccuranceType type; + public ShaderCodeVariable variable; + + + public static ShaderCodeVariableOccurance AsType( string name, ShaderCodeVariableOccuranceType type ) + { + var variable = new ShaderCodeVariable( name, ShaderCodeStages.Spatial ); + var occurance = new ShaderCodeVariableOccurance(); + occurance.variable = variable; + occurance.type = type; + return occurance; + } + + public static ShaderCodeVariableOccurance Read( string name ) + { + return AsType( name, ShaderCodeVariableOccuranceType.Read ); + } + + public static ShaderCodeVariableOccurance Assignment( string name ) + { + return AsType( name, ShaderCodeVariableOccuranceType.Assignment ); + } + + public static ShaderCodeVariableOccurance Modification( string name ) + { + return AsType( name, ShaderCodeVariableOccuranceType.Modification ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Generic/ShaderCodeVariableOccurance.cs.uid b/Runtime/Shading/Generators/Generic/ShaderCodeVariableOccurance.cs.uid new file mode 100644 index 0000000..16c665c --- /dev/null +++ b/Runtime/Shading/Generators/Generic/ShaderCodeVariableOccurance.cs.uid @@ -0,0 +1 @@ +uid://xnpahk8cgkye diff --git a/Runtime/Shading/Generators/ShaderGenerationContext.cs b/Runtime/Shading/Generators/Generic/ShaderGenerationContext.cs similarity index 63% rename from Runtime/Shading/Generators/ShaderGenerationContext.cs rename to Runtime/Shading/Generators/Generic/ShaderGenerationContext.cs index aef08ad..710034e 100644 --- a/Runtime/Shading/Generators/ShaderGenerationContext.cs +++ b/Runtime/Shading/Generators/Generic/ShaderGenerationContext.cs @@ -7,16 +7,25 @@ namespace Rokojori public class ShaderGenerationContext { public ShaderPhase phase; - - public List variants = new List(); + public List variants = new List(); + + public bool IsPhase( ShaderPhase phase ) + { + return phase == this.phase; + } + + public bool isIncludesPhase => IsPhase( ShaderPhase.Includes ); + public bool isVariablesPhase => IsPhase( ShaderPhase.Variables ); + public bool isVertexPhase => IsPhase( ShaderPhase.Vertex ); + public bool isFragmentPhase => IsPhase( ShaderPhase.Fragment ); public ShaderGenerationContext() { variants.Add( new ShaderVariant() ); } - public void Add( List code ) + public void AddVariants( List code ) { if ( code == null || code.Count == 0 ) { diff --git a/Runtime/Shading/Generators/ShaderGenerationContext.cs.uid b/Runtime/Shading/Generators/Generic/ShaderGenerationContext.cs.uid similarity index 100% rename from Runtime/Shading/Generators/ShaderGenerationContext.cs.uid rename to Runtime/Shading/Generators/Generic/ShaderGenerationContext.cs.uid diff --git a/Runtime/Shading/Generators/Generic/ShaderGenerationModule.cs b/Runtime/Shading/Generators/Generic/ShaderGenerationModule.cs new file mode 100644 index 0000000..c40c53f --- /dev/null +++ b/Runtime/Shading/Generators/Generic/ShaderGenerationModule.cs @@ -0,0 +1,297 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; +using Microsoft.VisualBasic; +using System.Linq; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public abstract partial class ShaderGenerationModule:Resource + { + public bool sortableCode = true; + + public virtual bool CodeIsSortable( ShaderPhase phase ) + { + return sortableCode; + } + + public virtual List GetVariantNames() + { + return new List(){ "" }; + } + + public virtual List GetVariants( ShaderGenerationContext context ) + { + return new List(){}; + } + + public static ShaderVariant ToVariant( params ShaderCode[] code ) + { + var variant = new ShaderVariant(); + variant.shaderCode = code.ToList(); + + return variant; + } + + public static List ToVariants( params ShaderCode[] code ) + { + return [ ToVariant( code ) ]; + } + + public string GetShaderCacheData() + { + var shaderHash = ""; + var name = "[ " + GetType().FullName + " ]"; + var exportedTuples = ReflectionHelper.GetExportedMembersAsJSON( this ); + exportedTuples.Sort(); + + shaderHash = name + " { " + ( exportedTuples.Map( t => $"\"{t.Item1}\":{t.Item2}" ).Join( ", " ) ) + " } "; + + + return shaderHash.Replace( "\n", "" ); + } + + public string GetShaderCacheHash() + { + var name = GetType().Name.Substring( 0, 3 ).ToLower(); + var exportedTuples = ReflectionHelper.GetExportedMembersAsJSON( this ); + exportedTuples.Sort(); + + var allAtts = " { " + ( exportedTuples.Map( t => $"\"{t.Item1}\":{t.Item2}" ).Join( ", " ) ) + " } "; + + + return name + "." + allAtts.Length; + } + + + public static List IncludeFromLibrary( string path ) + { + return ToCode( "#include \"res://addons/rokojori_action_library/Runtime/Shading/Library/" + path + ".gdshaderinc\"\n" ); + } + + public static List IncludeTransformLibrary(){ return IncludeFromLibrary( "Transform" ); } + + public static List IncludeDepthLibrary(){ return IncludeFromLibrary( "Depth" ); } + + public static List IncludeCamerasLibrary(){ return IncludeFromLibrary( "Cameras" ); } + + public static List IncludeNoiseLibrary(){ return IncludeFromLibrary( "Noise" ); } + + public static List IncludeDitheringLibrary(){ return IncludeFromLibrary( "Dithering" ); } + + public static List IncludeSDFLibrary(){ return IncludeFromLibrary( "SDF" ); } + + public static List IncludeMathLibrary(){ return IncludeFromLibrary( "Math" ); } + + public static List IncludeLightLibrary(){ return IncludeFromLibrary( "Light" ); } + + public static ShaderVariant ToVariant( List code ) + { + var variant = new ShaderVariant(); + variant.shaderCode = code; + + return variant; + } + + public static List ToVariants( List code ) + { + return [ ToVariant( code ) ]; + } + + public static List ToVariants( params string[] values ) + { + return ToVariants( ToCode( values ) ); + } + + public static List ToCode( params string[] values ) + { + return Lists.From( (ShaderCode)new StringShaderCode( Lists.From( values ).Join( "" ) ) ); + } + + public static List ToCode( string value ) + { + return Lists.From( (ShaderCode)new StringShaderCode( value ) ); + } + + public List AsUniformGroup( string name, string value ) + { + var wideName = RegexUtility.UpperCaseAndWide( name ); + var blockCode = value.Indent( " ", false ); + + var code = + @$" + // [ {wideName} ] + group_uniforms {name}; + + {blockCode} + + group_uniforms; + "; + + return ToCode( code.Indent( "" ) ); + + } + + + public List AsUniformGroup( string name, List code ) + { + var wideName = RegexUtility.UpperCaseAndWide( name ); + + var codeBefore = + @$" + // [ {wideName} ] + group_uniforms {name}; + + "; + + var codeAfter = + @$" + + + group_uniforms; + "; + + return Lists.From( ToCode( codeBefore.Indent("") ), code, ToCode( codeAfter.Indent("") ) ); + } + + public List StartUniformGroup( string name ) + { + var wideName = RegexUtility.UpperCaseAndWide( name ); + + var codeBefore = + @$" + // [ {wideName} ] + group_uniforms {name}; + + "; + + return ToCode( codeBefore.Indent("") ); + } + + public List EndUniformGroup() + { + var codeAfter = + @$" + group_uniforms; + "; + + return ToCode( codeAfter.Indent("") ); + } + + public static List ToInnerBlock( string name, string block ) + { + var wideName = RegexUtility.UpperCaseAndWide( name ); + var blockCode = block.Indent( " ", false ); + + var code = + + @$" + + // [ {wideName} ] + + {blockCode} + + "; + + return ToCode( code.Indent( " " ) ); + } + + public static List ToCode( List values ) + { + return Lists.From( (ShaderCode)new StringShaderCode( Lists.From( values ).Join( "" ) ) ); + } + + public static string Uniform( Vector2Property property ) + { + var name = property.propertyName.propertyName; + var x = property.value.X._G(); + var y = property.value.Y._G(); + + return @$"uniform vec2 {name} = vec2( {x}, {y});"; + } + + public static string Uniform( string name, float value ) + { + return @$"uniform float {name} = {value._G()};"; + } + + public static string Uniform01( string name, float value ) + { + return Uniform( name, value, 0, 1 ); + } + + public static string Uniform( string name, float value, float min, float max ) + { + var mi = min._G(); + var ma = max._G(); + var v = value._G(); + + return @$"uniform float {name}:hint_range( {mi}, {ma}) = {v};"; + } + + public static string UniformSampler( string name, string hints ) + { + return @$"uniform sampler2D {name}:{hints};"; + } + + public static string Uniform( string name, Color color ) + { + var r = color.R._G(); + var g = color.G._G(); + var b = color.B._G(); + var a = color.A._G(); + + return @$"uniform vec4 {name}:source_color = vec4( {r}, {g}, {b}, {a});"; + + } + + public static string Uniform( string name, Vector3 vec ) + { + var x = vec.X._G(); + var y = vec.Y._G(); + var z = vec.Z._G(); + + return @$"uniform vec3 {name} = vec3( {x}, {y}, {z});"; + } + + + public static string Varying( string type, string name ) + { + return @$"varying {type} {name};"; + } + + public static string VaryingFloat( string name ){ return Varying( "float", name ); } + public static string VaryingVec2( string name ){ return Varying( "vec2", name ); } + public static string VaryingVec3( string name ){ return Varying( "vec3", name ); } + public static string VaryingVec4( string name ){ return Varying( "vec4", name ); } + + public static string Uniform( string name, Vector4 vec ) + { + var x = vec.X._G(); + var y = vec.Y._G(); + var z = vec.Z._G(); + var w = vec.W._G(); + + return @$"uniform vec4 {name} = vec4( {x}, {y}, {z}, {w});"; + } + + public static string DepthTextureUniform() + { + return UniformSampler( "depthTexture", "hint_depth_texture, repeat_disable, filter_nearest" ); + } + + public static string ScreenTextureUniform() + { + return UniformSampler( "screenTexture", "hint_screen_texture, repeat_disable, filter_linear" ); + } + + public static string NormalRoughnessTextureUniform() + { + return UniformSampler( "normalRoughness", "hint_normal_roughness_texture, repeat_disable, filter_linear" ); + } + + } + +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/ShaderGenerationModule.cs.uid b/Runtime/Shading/Generators/Generic/ShaderGenerationModule.cs.uid similarity index 100% rename from Runtime/Shading/Generators/ShaderGenerationModule.cs.uid rename to Runtime/Shading/Generators/Generic/ShaderGenerationModule.cs.uid diff --git a/Runtime/Shading/Generators/ShaderGenerator.cs b/Runtime/Shading/Generators/Generic/ShaderGenerator.cs similarity index 68% rename from Runtime/Shading/Generators/ShaderGenerator.cs rename to Runtime/Shading/Generators/Generic/ShaderGenerator.cs index 5ed0d7f..accc178 100644 --- a/Runtime/Shading/Generators/ShaderGenerator.cs +++ b/Runtime/Shading/Generators/Generic/ShaderGenerator.cs @@ -29,6 +29,9 @@ namespace Rokojori [Export] public bool sendGodotUpdateMessage = false; + [Export] + public int numVariants = -1; + public virtual List GetPhases() { return new List(); @@ -41,11 +44,13 @@ namespace Rokojori public virtual ShaderGenerationContext GenerateShaderVariants() { + numVariants = 0; + var context = new ShaderGenerationContext(); var phases = GetPhases(); - this.LogInfo( context.variants ); + // this.LogInfo( context.variants ); phases.ForEach( ( phase )=> @@ -54,7 +59,7 @@ namespace Rokojori var modules = GetShaderGenerationModules( phase ); - this.LogInfo( "PHASE", phase, ">>", context.variants, "MODS:", modules == null ? "-" : ( modules.Map( m => m.GetType().Name ) )); + // this.LogInfo( "PHASE", phase, ">>", context.variants, "MODS:", modules == null ? "-" : ( modules.Map( m => m.GetType().Name ) )); if ( modules == null ) { @@ -64,16 +69,29 @@ namespace Rokojori modules.ForEach( ( m )=> { - var code = m.GetCode( context ); - - this.LogInfo( phase, m.GetType().Name, code ); - - if ( code == null ) + var variants = m.GetVariants( context ); + + if ( variants == null ) { return; } - context.Add( code ); + variants.ForEach( + c => + { + c.shaderCode.ForEach( + cs => + { + cs.phase = phase; + cs.sortableCode = m.CodeIsSortable( phase ); + } + ); + } + ); + + this.LogInfo( phase, m.GetType().Name, ">>", variants.Count ); + + context.AddVariants( variants ); } ); } @@ -87,8 +105,12 @@ namespace Rokojori public void UpdateShader() { + numVariants = 0; + var context = GenerateShaderVariants(); - this.LogInfo( "Created variants:", context.variants ); + + numVariants = context.variants.Count; + // this.LogInfo( "Created variants:", context.variants ); var first = true; @@ -102,7 +124,7 @@ namespace Rokojori absolutePath = ProjectSettings.GlobalizePath( path ); } - this.LogInfo( shaderCode ); + // this.LogInfo( shaderCode ); var filePath = FilePath.Join( absolutePath, shaderName + variant.variantName + ".gdshader" ); FilesSync.SaveUTF8( filePath, shaderCode ); diff --git a/Runtime/Shading/Generators/ShaderGenerator.cs.uid b/Runtime/Shading/Generators/Generic/ShaderGenerator.cs.uid similarity index 100% rename from Runtime/Shading/Generators/ShaderGenerator.cs.uid rename to Runtime/Shading/Generators/Generic/ShaderGenerator.cs.uid diff --git a/Runtime/Shading/Generators/ShaderPhases.cs b/Runtime/Shading/Generators/Generic/ShaderPhases.cs similarity index 100% rename from Runtime/Shading/Generators/ShaderPhases.cs rename to Runtime/Shading/Generators/Generic/ShaderPhases.cs diff --git a/Runtime/Shading/Generators/ShaderPhases.cs.uid b/Runtime/Shading/Generators/Generic/ShaderPhases.cs.uid similarity index 100% rename from Runtime/Shading/Generators/ShaderPhases.cs.uid rename to Runtime/Shading/Generators/Generic/ShaderPhases.cs.uid diff --git a/Runtime/Shading/Generators/ShaderRawModule.cs b/Runtime/Shading/Generators/Generic/ShaderRawModule.cs similarity index 80% rename from Runtime/Shading/Generators/ShaderRawModule.cs rename to Runtime/Shading/Generators/Generic/ShaderRawModule.cs index 01e66a7..b4faf3e 100644 --- a/Runtime/Shading/Generators/ShaderRawModule.cs +++ b/Runtime/Shading/Generators/Generic/ShaderRawModule.cs @@ -9,6 +9,7 @@ namespace Rokojori [GlobalClass] public partial class ShaderRawModule:ShaderGenerationModule { + [Export] public string value; @@ -20,6 +21,8 @@ namespace Rokojori public ShaderRawModule( string value, ShaderPhase? phase = null ) { + sortableCode = false; + if ( phase != null ) { phase = (ShaderPhase) phase; @@ -33,14 +36,14 @@ namespace Rokojori this.value = value; } - public override List GetCode( ShaderGenerationContext context ) + public override List GetVariants( ShaderGenerationContext context ) { if ( matchPhase && context.phase != phase ) { return null; } - return Lists.From( (ShaderCode) new StringShaderCode( value ) ); + return ToVariants( ToCode( value ) ); } } } \ No newline at end of file diff --git a/Runtime/Shading/Generators/ShaderRawModule.cs.uid b/Runtime/Shading/Generators/Generic/ShaderRawModule.cs.uid similarity index 100% rename from Runtime/Shading/Generators/ShaderRawModule.cs.uid rename to Runtime/Shading/Generators/Generic/ShaderRawModule.cs.uid diff --git a/Runtime/Shading/Generators/Generic/ShaderVariant.cs b/Runtime/Shading/Generators/Generic/ShaderVariant.cs new file mode 100644 index 0000000..ea4b8bd --- /dev/null +++ b/Runtime/Shading/Generators/Generic/ShaderVariant.cs @@ -0,0 +1,293 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + public class ShaderVariant + { + public string variantName = ""; + public List shaderCode = []; + + public string GetCode( ShaderGenerationContext context ) + { + + ResolveVariableOccurances( context ); + + var cleanedUpCode = RemoveDuplicateIncludes( shaderCode, context ); + + + var hasScreen = false; + var hasDepth = false; + var hasNormalRoughness = false; + + cleanedUpCode = cleanedUpCode.Filter( + ( c )=> + { + if ( c is BuiltInTextureShaderCode bsc ) + { + if ( BuiltInTextureShaderCode.TextureType.Screen == bsc.textureType ) + { + hasScreen = true; + } + + if ( BuiltInTextureShaderCode.TextureType.Depth == bsc.textureType ) + { + hasDepth = true; + } + + if ( BuiltInTextureShaderCode.TextureType.NormalRoughness == bsc.textureType ) + { + hasNormalRoughness = true; + } + + return false; + } + + return true; + } + ); + + var insertionIndex = cleanedUpCode.FindIndex( + ( c )=> + { + return c.GetCode( context ).Contains( "group_uniforms" ); + } + ); + + + + if ( hasNormalRoughness ) + { + cleanedUpCode.Insert( insertionIndex, ShaderGenerationModule.ToCode( "\n" )[ 0 ] ); + cleanedUpCode.Insert( insertionIndex, BuiltInTextureShaderCode.NormalRoughness.GetBuiltInCode() ); + cleanedUpCode.Insert( insertionIndex, ShaderGenerationModule.ToCode( "\n" )[ 0 ] ); + } + + if ( hasDepth ) + { + cleanedUpCode.Insert( insertionIndex, ShaderGenerationModule.ToCode( "\n" )[ 0 ] ); + cleanedUpCode.Insert( insertionIndex, BuiltInTextureShaderCode.Depth.GetBuiltInCode() ); + cleanedUpCode.Insert( insertionIndex, ShaderGenerationModule.ToCode( "\n" )[ 0 ] ); + } + + if ( hasScreen ) + { + cleanedUpCode.Insert( insertionIndex, ShaderGenerationModule.ToCode( "\n" )[ 0 ] ); + cleanedUpCode.Insert( insertionIndex, BuiltInTextureShaderCode.Screen.GetBuiltInCode() ); + cleanedUpCode.Insert( insertionIndex, ShaderGenerationModule.ToCode( "\n" )[ 0 ] ); + } + + + + var blocks = GetCodeBlocks( cleanedUpCode ); + + var sortedCode = new List(); + + blocks.ForEach( + ( b )=> + { + if ( ! b[ 0 ].sortableCode ) + { + sortedCode.AddRange( b ); + return; + } + + sortedCode.AddRange( SortBlock( b ) ); + } + ); + + return sortedCode.Map( s => s.GetCode( context ) ).Join( "" ); + } + + void ResolveVariableOccurances( ShaderGenerationContext context ) + { + shaderCode.ForEach( s => s.ResolveVariableOccurances( context ) ); + } + + + List> GetCodeBlocks( List shaderCode ) + { + var blocks = new List>(); + List currentBlock = null; + + for ( int i = 0; i < shaderCode.Count; i++ ) + { + if ( ! shaderCode[ i ].sortableCode || + currentBlock != null && currentBlock[ 0 ].phase != shaderCode[ i ].phase ) + { + if ( currentBlock != null && currentBlock.Count > 0 ) + { + blocks.Add( currentBlock ); + } + + currentBlock = null; + + if ( ! shaderCode[ i ].sortableCode ) + { + blocks.Add( [ shaderCode[ i ] ] ); + + continue; + } + + } + + if ( currentBlock == null ) + { + currentBlock = new List(); + } + + currentBlock.Add( shaderCode[ i ] ); + } + + if ( currentBlock != null ) + { + blocks.Add( currentBlock ); + } + + return blocks; + } + + List RemoveDuplicateIncludes( List shaderCode, ShaderGenerationContext context ) + { + var cleanedUp = new List(); + + var includes = new HashSet(); + + + var includeStart = "#include \"res://addons/rokojori_action_library/Runtime/Shading/Library/"; + + shaderCode.ForEach( + ( sc )=> + { + var code = sc.GetCode( context ); + + if ( ! code.Contains( includeStart ) ) + { + cleanedUp.Add( sc ); + return; + } + + + var include = code.GetInnerMatch( includeStart, ".gdshaderinc" ); + + if ( include != null && includes.Contains( include ) ) + { + return; + } + + cleanedUp.Add( sc ); + + if ( include != null ) + { + includes.Add( include ); + } + + + } + ); + + return cleanedUp; + } + + List SortBlock( List blockShaderCode ) + { + var g = new Graph( blockShaderCode ); + + var reads = new MapList(); + var assignments = new MapList(); + var modifications = new MapList(); + + blockShaderCode.ForEach( + ( sc )=> + { + sc.variableOccurances.ForEach( + ( occ )=> + { + if ( ShaderCodeVariableOccuranceType.Read == occ.type ) + { + reads.Add( occ.variable.variableName, sc ); + } + + if ( ShaderCodeVariableOccuranceType.Assignment == occ.type ) + { + assignments.Add( occ.variable.variableName, sc ); + } + + if ( ShaderCodeVariableOccuranceType.Modification == occ.type ) + { + modifications.Add( occ.variable.variableName, sc ); + } + } + ); + } + ); + + blockShaderCode.ForEach( + ( s ) => + { + s.variableOccurances.ForEach( + ( occ )=> + { + if ( ShaderCodeVariableOccuranceType.Assignment == occ.type ) + { + return; + } + + if ( ! assignments.ContainsKey( occ.variable.variableName ) ) + { + return; + } + + var assigningCodes = assignments[ occ.variable.variableName ]; + + assigningCodes.ForEach( sc => g.Connect( sc, s ) ); + + RJLog.Log( "Set dependency:", s, occ.variable.variableName ); + } + ); + } + ); + + return g.ComputeOrder(); + } + + public ShaderVariant Extend( ShaderCode shaderCode ) + { + var variant = new ShaderVariant(); + variant.variantName = variantName + shaderCode.variantName; + + variant.shaderCode = this.shaderCode.Clone(); + variant.shaderCode.Add( shaderCode ); + + return variant; + } + + public ShaderVariant Extend( ShaderVariant shaderVariant ) + { + var extendedVariant = new ShaderVariant(); + extendedVariant.variantName = variantName + shaderVariant.variantName; + + extendedVariant.shaderCode = shaderCode.Clone(); + extendedVariant.shaderCode.AddRange( shaderVariant.shaderCode ); + + return extendedVariant; + } + + public static List CombineVariants( List before, List addition ) + { + if ( before == null || before.Count == 0 ) + { + return addition; + } + + if ( addition == null || addition.Count == 0 ) + { + return before; + } + + return Lists.Combine( before, addition, ( a, b ) => a.Extend( b ) ); + } + } + +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/ShaderVariant.cs.uid b/Runtime/Shading/Generators/Generic/ShaderVariant.cs.uid similarity index 100% rename from Runtime/Shading/Generators/ShaderVariant.cs.uid rename to Runtime/Shading/Generators/Generic/ShaderVariant.cs.uid diff --git a/Runtime/Shading/Generators/ShaderCode.cs b/Runtime/Shading/Generators/ShaderCode.cs deleted file mode 100644 index 8fc2809..0000000 --- a/Runtime/Shading/Generators/ShaderCode.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Godot; -using System.Reflection; -using System.Collections.Generic; - -namespace Rokojori -{ - public class ShaderCodeImports - { - public string importPath; - } - - public class ShaderCodeVariable - { - public string variableName; - } - - public class ShaderCode - { - public string variantName = ""; - public List imports = []; - public List variables = []; - - protected virtual string _GetCode( ShaderGenerationContext context ) - { - return ""; - } - - public string GetCode( ShaderGenerationContext context ) - { - return _GetCode( context ); - } - - - } - - public class StringShaderCode:ShaderCode - { - public string code = ""; - - public StringShaderCode( string code ) - { - this.code = code; - } - - protected override string _GetCode( ShaderGenerationContext context ) - { - return code; - } - } - -} \ No newline at end of file diff --git a/Runtime/Shading/Generators/ShaderGenerationModule.cs b/Runtime/Shading/Generators/ShaderGenerationModule.cs deleted file mode 100644 index 722323e..0000000 --- a/Runtime/Shading/Generators/ShaderGenerationModule.cs +++ /dev/null @@ -1,138 +0,0 @@ -using Godot; -using System.Reflection; -using System.Collections.Generic; -using Microsoft.VisualBasic; - -namespace Rokojori -{ - [Tool] - [GlobalClass] - public partial class ShaderGenerationModule:Resource - { - public virtual List GetVariantNames() - { - return new List(){ "" }; - } - - public virtual List GetCode( ShaderGenerationContext context ) - { - return new List(){}; - } - - public List ToCode( params string[] values ) - { - return Lists.From( (ShaderCode)new StringShaderCode( Lists.From( values ).Join( "" ) ) ); - } - - public List ToCode( string value ) - { - return Lists.From( (ShaderCode)new StringShaderCode( value ) ); - } - - public List AsUniformGroup( string name, string value ) - { - var wideName = RegexUtility.UpperCaseAndWide( name ); - var blockCode = value.Indent( " ", false ); - - var code = - @$" - // [ {wideName} ] - group_uniforms {name}; - - {blockCode} - - group_uniforms; - "; - - return ToCode( code.Indent( "" ) ); - - } - - public List ToInnerBlock( string name, string block ) - { - var wideName = RegexUtility.UpperCaseAndWide( name ); - var blockCode = block.Indent( " ", false ); - - var code = - - @$" - - // [ {wideName} ] - - {blockCode} - - "; - - return ToCode( code.Indent( " " ) ); - } - - public List ToCode( List values ) - { - return Lists.From( (ShaderCode)new StringShaderCode( Lists.From( values ).Join( "" ) ) ); - } - - public string Uniform( Vector2Property property ) - { - var name = property.propertyName.propertyName; - var x = property.value.X._G(); - var y = property.value.Y._G(); - - return @$"uniform vec2 {name} = vec2( {x}, {y});"; - } - - public string Uniform( string name, float value ) - { - return @$"uniform float {name} = {value._G()};"; - } - - public string Uniform01( string name, float value ) - { - return Uniform( name, value, 0, 1 ); - } - - public string Uniform( string name, float value, float min, float max ) - { - var mi = min._G(); - var ma = max._G(); - var v = value._G(); - - return @$"uniform float {name}:hint_range( {mi}, {ma}) = {v};"; - } - - public string UniformSampler( string name, string hints ) - { - return @$"uniform sampler2D {name}:{hints};"; - } - - public string Uniform( string name, Color color ) - { - var r = color.R._G(); - var g = color.G._G(); - var b = color.B._G(); - var a = color.A._G(); - - return @$"uniform vec4 {name}:source_color = vec4( {r}, {g}, {b}, {a});"; - - } - - public string Uniform( string name, Vector3 vec ) - { - var x = vec.X._G(); - var y = vec.Y._G(); - var z = vec.Z._G(); - - return @$"uniform vec3 {name} = vec3( {x}, {y}, {z});"; - } - - public string Uniform( string name, Vector4 vec ) - { - var x = vec.X._G(); - var y = vec.Y._G(); - var z = vec.Z._G(); - var w = vec.W._G(); - - return @$"uniform vec4 {name} = vec4( {x}, {y}, {z}, {w});"; - } - } - -} \ No newline at end of file diff --git a/Runtime/Shading/Generators/ShaderVariant.cs b/Runtime/Shading/Generators/ShaderVariant.cs deleted file mode 100644 index faca9eb..0000000 --- a/Runtime/Shading/Generators/ShaderVariant.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Godot; -using System.Reflection; -using System.Collections.Generic; - -namespace Rokojori -{ - public class ShaderVariant - { - public string variantName = ""; - public List shaderCode = []; - - public string GetCode( ShaderGenerationContext context ) - { - return shaderCode.Map( s => s.GetCode( context ) ).Join( "" ); - } - - public ShaderVariant Extend( ShaderCode shaderCode ) - { - var variant = new ShaderVariant(); - variant.variantName = variantName + shaderCode.variantName; - - variant.shaderCode = this.shaderCode.Clone(); - variant.shaderCode.Add( shaderCode ); - - return variant; - } - } - -} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Albedo/AlbedoModule.cs b/Runtime/Shading/Generators/Spatial/Albedo/AlbedoModule.cs index a87ccdf..cbc67fb 100644 --- a/Runtime/Shading/Generators/Spatial/Albedo/AlbedoModule.cs +++ b/Runtime/Shading/Generators/Spatial/Albedo/AlbedoModule.cs @@ -10,12 +10,14 @@ namespace Rokojori { public AlbedoModule() { - _type = TextureChannelType.RGBA; - _domainName = "albedo"; _domainScaleName = "albedo"; + _domainValueName = "albedo"; + _target = "ALBEDO"; _srgb = true; + _type = TextureChannelType.RGB; + scaleType = TextureChannelType.RGB; } [Export] @@ -27,18 +29,58 @@ namespace Rokojori [Export] public bool srgb = true; + [Export] + public bool writeAlpha = true; + [Export] public bool repeat = true; + [Export] + public string uvChannel = "UV"; + [Export] public TextureDefault textureDefault = TextureDefault.White; + + + [Export] + public AssignmentType assignmentType = AssignmentType.Set; + + + public override void GrabValues() { - domainMode = useTint ? DomainMode.Texture_Scale : DomainMode.Texture; + _domainMode = useTint ? DomainMode.Texture_Scale : DomainMode.Texture; _textureFilter = filter; _srgb = srgb; _repeat = repeat; _textureDefault = textureDefault; + _uvChannel = uvChannel; + + _assignmentType = assignmentType; + } + + public override List GetVariants( ShaderGenerationContext context ) + { + var variants = base.GetVariants( context ); + + if ( ! writeAlpha || ShaderPhase.Fragment != context.phase ) + { + return variants; + } + + var value = GetSampledName() + ".a" ; + + if ( useTint ) + { + value += " * albedo.a"; + } + + var assignment = " ALPHA *= " + value + ";\n\n"; + return ShaderVariant.CombineVariants( variants, ToVariants( ToCode( assignment ) ) ); + + } + + } } \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Alpha/AlphaFade.cs b/Runtime/Shading/Generators/Spatial/Alpha/AlphaFade.cs new file mode 100644 index 0000000..511464e --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Alpha/AlphaFade.cs @@ -0,0 +1,55 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + public enum AlphaFadeMode + { + ___, + Alpha, + NoiseDitherDiscard + } + + + public static class AlphaFade + { + public static List Includes( string variableName, AlphaFadeMode mode ) + { + if ( AlphaFadeMode.NoiseDitherDiscard != mode ) + { + return null; + } + + return ShaderGenerationModule.IncludeNoiseLibrary(); + } + + + + public static string Fragment( string variableName, AlphaFadeMode mode ) + { + if ( AlphaFadeMode.Alpha == mode ) + { + return " ALPHA *= " + variableName + ";\n"; + } + + if ( AlphaFadeMode.NoiseDitherDiscard == mode ) + { + + var code = + $@" + if ( ditherDiscard( {variableName}, FRAGCOORD ) ) + {{ + discard; + }} + "; + + return code.Indent( " "); + } + + return null; + } + + } +} + diff --git a/Runtime/Shading/Generators/Spatial/Alpha/AlphaFade.cs.uid b/Runtime/Shading/Generators/Spatial/Alpha/AlphaFade.cs.uid new file mode 100644 index 0000000..6c9fba1 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Alpha/AlphaFade.cs.uid @@ -0,0 +1 @@ +uid://biah4fyd5aa4o diff --git a/Runtime/Shading/Generators/Spatial/Alpha/AlphaModule.cs b/Runtime/Shading/Generators/Spatial/Alpha/AlphaModule.cs new file mode 100644 index 0000000..d92e2f6 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Alpha/AlphaModule.cs @@ -0,0 +1,53 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class AlphaModule:TextureModule + { + public AlphaModule() + { + _domainName = "alpha"; + _domainScaleName = "alpha"; + _domainOffsetName = "alphaOffset"; + _domainValueName = "alpha"; + + _target = "ALPHA"; + _type = TextureChannelType.ONE; + _channelSource = TextureChannelSource.R; + domainScaleDefault = 1f; + } + + [Export] + public TextureFilter filter = TextureFilter.Linear_MipMap_Anisotropic; + + [Export] + public DomainMode domainMode = DomainMode.Texture_Scale; + + [Export] + public bool repeat = true; + + [Export] + public string uvChannel = "UV"; + + [Export] + public TextureDefault textureDefault = TextureDefault.White; + + [Export] + public AssignmentType assignmentType = AssignmentType.Set; + + public override void GrabValues() + { + _domainMode = domainMode; + _textureFilter = filter; + _repeat = repeat; + _textureDefault = textureDefault; + _uvChannel = uvChannel; + + _assignmentType = assignmentType; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Alpha/AlphaModule.cs.uid b/Runtime/Shading/Generators/Spatial/Alpha/AlphaModule.cs.uid new file mode 100644 index 0000000..cfb2486 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Alpha/AlphaModule.cs.uid @@ -0,0 +1 @@ +uid://8a10in76h56n diff --git a/Runtime/Shading/Generators/Spatial/Backlight/BacklightModule.cs b/Runtime/Shading/Generators/Spatial/Backlight/BacklightModule.cs new file mode 100644 index 0000000..a45d837 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Backlight/BacklightModule.cs @@ -0,0 +1,84 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class BacklightModule:TextureModule + { + public BacklightModule() + { + _domainName = "backlight"; + _domainScaleName = "backlight"; + _domainValueName = "backlight"; + + _target = "BACKLIGHT"; + _srgb = true; + _type = TextureChannelType.RGB; + scaleType = TextureChannelType.RGB; + scaleColor = Colors.Black; + } + + [Export] + public TextureFilter filter = TextureFilter.Linear_MipMap_Anisotropic; + + [Export] + public bool useTint = true; + + [Export] + public bool feedAlbedoIntoBacklight = true; + + [Export] + public bool srgb = true; + + [Export] + public bool repeat = true; + + [Export] + public string uvChannel = "UV"; + + [Export] + public TextureDefault textureDefault = TextureDefault.White; + + [Export] + public AssignmentType assignmentType = AssignmentType.Set; + + public override void GrabValues() + { + _domainMode = useTint ? DomainMode.Texture_Scale : DomainMode.Texture; + _textureFilter = filter; + _srgb = srgb; + _repeat = repeat; + _textureDefault = textureDefault; + _uvChannel = uvChannel; + + _assignmentType = assignmentType; + } + + public override string AddVariables() + { + if ( ! feedAlbedoIntoBacklight ) + { + return ""; + } + + return "\n" + Uniform01( "backlightFromAlbedo", 0.0f ); + } + + public override List GetVariants( ShaderGenerationContext context ) + { + var variants = base.GetVariants( context ); + + if ( ! feedAlbedoIntoBacklight || ShaderPhase.Fragment != context.phase ) + { + return variants; + } + + var backlightAssignment = " BACKLIGHT += backlightFromAlbedo * ALBEDO;\n\n"; + return ShaderVariant.CombineVariants( variants, ToVariants( ToCode( backlightAssignment ) ) ); + + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Backlight/BacklightModule.cs.uid b/Runtime/Shading/Generators/Spatial/Backlight/BacklightModule.cs.uid new file mode 100644 index 0000000..fa65526 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Backlight/BacklightModule.cs.uid @@ -0,0 +1 @@ +uid://bhqel20k1ky16 diff --git a/Runtime/Shading/Generators/Spatial/Emission/EmissionModule.cs b/Runtime/Shading/Generators/Spatial/Emission/EmissionModule.cs new file mode 100644 index 0000000..f10df76 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Emission/EmissionModule.cs @@ -0,0 +1,68 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class EmissionModule:TextureModule + { + + public EmissionModule() + { + _domainName = "emission"; + _domainScaleName = "emission"; + _domainIntensityName = "emissionIntensity"; + _domainValueName = "emission"; + + _target = "EMISSION"; + _srgb = true; + _type = TextureChannelType.RGB; + scaleType = TextureChannelType.RGB; + } + + [Export] + public TextureFilter filter = TextureFilter.Linear_MipMap_Anisotropic; + + public enum EmissionMode + { + Texture, + Texture_Tint, + Texture_Tint_Intensity + } + + [Export] + public EmissionMode mode = EmissionMode.Texture_Tint_Intensity; + + [Export] + public bool srgb = true; + + [Export] + public bool repeat = true; + + [Export] + public string uvChannel = "UV"; + + [Export] + public TextureDefault textureDefault = TextureDefault.Black; + + [Export] + public AssignmentType assignmentType = AssignmentType.Set; + + public override void GrabValues() + { + _domainMode = EmissionMode.Texture == mode ? DomainMode.Texture : + EmissionMode.Texture_Tint == mode ? DomainMode.Texture_Scale : + DomainMode.Texture_Scale_Intensity; + + _textureFilter = filter; + _srgb = srgb; + _repeat = repeat; + _textureDefault = textureDefault; + _uvChannel = uvChannel; + + _assignmentType = assignmentType; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Emission/EmissionModule.cs.uid b/Runtime/Shading/Generators/Spatial/Emission/EmissionModule.cs.uid new file mode 100644 index 0000000..f94c6bf --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Emission/EmissionModule.cs.uid @@ -0,0 +1 @@ +uid://dobmqsid1agkj diff --git a/Runtime/Shading/Generators/Spatial/Fading/CameraDistance/CameraDistanceFading.cs b/Runtime/Shading/Generators/Spatial/Fading/CameraDistance/CameraDistanceFading.cs new file mode 100644 index 0000000..ef1cf68 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/CameraDistance/CameraDistanceFading.cs @@ -0,0 +1,84 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CameraDistanceFading:FadingModifier + { + public enum Mode + { + Near_Camera, + Far_Camera + } + + [Export] + public Mode mode; + + + public override bool IsSameType( FadingModifier modifier ) + { + if ( modifier is CameraDistanceFading cdf ) + { + return cdf.mode == mode; + } + + return false; + } + + public override List GetFadingCode( ShaderGenerationContext context, int offsetIndex, AlphaFadeMode parentFadeMode ) + { + bool isNear = mode == Mode.Near_Camera; + + var alphaFadeMode = GetFadeMode( parentFadeMode ); + + var suffix = GetSuffix( offsetIndex ); + + if ( context.isIncludesPhase ) + { + return IncludeNoiseLibrary().Concat( IncludeCamerasLibrary() ); + } + + var fadeOutVariable = isNear ? "nearCameraFadeOutDistance" : "farCameraFadeOutDistance"; + var fadeInVariable = isNear ? "nearCameraFadeInDistance" : "farCameraFadeInDistance"; + + fadeOutVariable += suffix; + fadeInVariable += suffix; + + if ( context.isVariablesPhase ) + { + if ( isNear ) + { + var nearFadeOutDistance = Uniform( fadeOutVariable, 0.0f, 0.1f, 5000 ).LineBreak(); + var nearFadeInDistance = Uniform( fadeInVariable, 0.0f, 0.5f, 5000 ).LineBreak(); + + return ToCode( nearFadeOutDistance, nearFadeInDistance ); + } + else + { + var farFadeInDistance = Uniform( fadeInVariable, 0.0f, 0.1f, 5000 ).LineBreak(); + var farFadeOutDistance = Uniform( fadeOutVariable, 0.0f, 0.5f, 5000 ).LineBreak(); + + return ToCode( farFadeInDistance, farFadeOutDistance ); + } + } + + + if ( context.isFragmentPhase ) + { + var prefix = isNear ? "near" : "far"; + var variable = $"{prefix}CameraDistanceFadeAlpha{suffix}"; + var code = $"float {variable} = cameraDistanceFade( VERTEX, {fadeOutVariable}, {fadeInVariable});\n"; + + return ToCode( code.Indent( " ") ).Concat( ToCode( AlphaFade.Fragment( variable, alphaFadeMode ) ) ); + } + + return []; + } + + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Fading/CameraDistance/CameraDistanceFading.cs.uid b/Runtime/Shading/Generators/Spatial/Fading/CameraDistance/CameraDistanceFading.cs.uid new file mode 100644 index 0000000..cc4c314 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/CameraDistance/CameraDistanceFading.cs.uid @@ -0,0 +1 @@ +uid://cvcdfjgoog384 diff --git a/Runtime/Shading/Generators/Spatial/Fading/DepthProximity/DepthPromixityFading.cs b/Runtime/Shading/Generators/Spatial/Fading/DepthProximity/DepthPromixityFading.cs new file mode 100644 index 0000000..b5b5a9b --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/DepthProximity/DepthPromixityFading.cs @@ -0,0 +1,55 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class DepthPromixityFading:FadingModifier + { + public override List GetFadingCode( ShaderGenerationContext context, int offsetIndex, AlphaFadeMode parentFadeMode ) + { + var alphaFadeMode = GetFadeMode( parentFadeMode ); + var suffix = GetSuffix( offsetIndex ); + + if ( context.isIncludesPhase ) + { + return IncludeDepthLibrary(); + } + + if ( context.isVariablesPhase ) + { + var depthProximityFadeDistanceUniform = Uniform( "depthProximityFadeDistance" + suffix, 0.2f, 0, 1000 ).LineBreak(); + + var list = new List() + { + BuiltInTextureShaderCode.Depth, + ToCode( depthProximityFadeDistanceUniform ) + }; + + return list; + } + + + if ( context.isFragmentPhase ) + { + var code = + $@" + + float depthProximityAlpha{suffix} = getDepthProximityAlpha( depthTexture, + SCREEN_UV, INV_PROJECTION_MATRIX, + VERTEX.z, depthProximityFadeDistance{suffix} + ); + "; + + + return ToCode( code.Indent( " " ) ).Concat( ToCode( AlphaFade.Fragment( "depthProximityAlpha" + suffix, alphaFadeMode ) ) ); + } + + return []; + } + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Fading/DepthProximity/DepthPromixityFading.cs.uid b/Runtime/Shading/Generators/Spatial/Fading/DepthProximity/DepthPromixityFading.cs.uid new file mode 100644 index 0000000..7423126 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/DepthProximity/DepthPromixityFading.cs.uid @@ -0,0 +1 @@ +uid://ip3xwmcn077l diff --git a/Runtime/Shading/Generators/Spatial/Fading/FadingModifier.cs b/Runtime/Shading/Generators/Spatial/Fading/FadingModifier.cs new file mode 100644 index 0000000..8fdd1d0 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/FadingModifier.cs @@ -0,0 +1,50 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public abstract partial class FadingModifier:ShaderGenerationModule + { + [Export] + public AlphaFadeMode alphaFadeMode = AlphaFadeMode.___; + + [Export] + public bool createUniformGroup = false; + + + public abstract List GetFadingCode( ShaderGenerationContext context, int offsetIndex, AlphaFadeMode parentAlphaFadeMode ); + + public virtual bool IsSameType( FadingModifier modifier ) + { + return modifier.GetType() == GetType(); + } + + public override List GetVariants( ShaderGenerationContext context ) + { + return ToVariants( GetFadingCode( context, -1, alphaFadeMode ) ); + } + + public string GetSuffix( int offsetIndex ) + { + return offsetIndex <= 0 ? "" : ( "_" + ( offsetIndex + 1 ) ); + } + + public AlphaFadeMode GetFadeMode( AlphaFadeMode parent ) + { + if ( AlphaFadeMode.___ != alphaFadeMode ) + { + return alphaFadeMode; + } + + if ( AlphaFadeMode.___ != parent ) + { + return parent; + } + + return AlphaFadeMode.Alpha; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Fading/FadingModifier.cs.uid b/Runtime/Shading/Generators/Spatial/Fading/FadingModifier.cs.uid new file mode 100644 index 0000000..aa499ab --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/FadingModifier.cs.uid @@ -0,0 +1 @@ +uid://btwbxenq2cgyb diff --git a/Runtime/Shading/Generators/Spatial/Fading/FadingModule.cs b/Runtime/Shading/Generators/Spatial/Fading/FadingModule.cs new file mode 100644 index 0000000..2272a3d --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/FadingModule.cs @@ -0,0 +1,81 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class FadingModule:ShaderGenerationModule + { + [Export] + public AlphaFadeMode alphaFadeMode = AlphaFadeMode.NoiseDitherDiscard; + + [Export] + public FadingModifier[] fadingModifiers = []; + + + public override List GetVariants( ShaderGenerationContext context ) + { + + if ( fadingModifiers == null ) + { + return null ; + } + + var list = fadingModifiers.ToList().FilterNulls(); + + if ( list.Count == 0 ) + { + return null; + } + + + + var shaderCode = new List(); + + if ( ShaderPhase.Includes == context.phase ) + { + shaderCode.Add( IncludeNoiseLibrary() ); + } + + list.ForEach( + ( fm )=> + { + var fIndex = list.Filter( l => l.IsSameType( fm ) ).IndexOf( fm ); + var fCode = fm.GetFadingCode( context, fIndex, alphaFadeMode ); + + if ( fCode == null ) + { + return; + } + + if ( ShaderPhase.Variables == context.phase && fm.createUniformGroup ) + { + shaderCode.Add( EndUniformGroup() ); + fCode = AsUniformGroup( fm.GetType().Name + fm.GetSuffix( fIndex ), fCode ); + } + + shaderCode.Add( fCode ); + + if ( ShaderPhase.Variables == context.phase && fm.createUniformGroup ) + { + shaderCode.Add( StartUniformGroup( "Fading") ); + } + } + ); + + if ( ShaderPhase.Variables == context.phase ) + { + shaderCode = AsUniformGroup( "Fading", shaderCode ); + } + + + + return ToVariants( shaderCode ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Fading/FadingModule.cs.uid b/Runtime/Shading/Generators/Spatial/Fading/FadingModule.cs.uid new file mode 100644 index 0000000..308403d --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/FadingModule.cs.uid @@ -0,0 +1 @@ +uid://bqk5po80nylsk diff --git a/Runtime/Shading/Generators/Spatial/Fading/Fresnel/FresnelFading.cs b/Runtime/Shading/Generators/Spatial/Fading/Fresnel/FresnelFading.cs new file mode 100644 index 0000000..7c27163 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/Fresnel/FresnelFading.cs @@ -0,0 +1,128 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class FresnelFading:FadingModifier + { + [Export] + public bool advancedControls = true; + + public override bool IsSameType( FadingModifier modifier ) + { + if ( modifier is FresnelFading ff ) + { + return ff.advancedControls == advancedControls; + } + + return false; + } + + public override List GetFadingCode( ShaderGenerationContext context, int offsetIndex, AlphaFadeMode parentFadeMode ) + { + if ( advancedControls ) + { + return GetFadingCodeAdvanced( context, offsetIndex, parentFadeMode ); + } + else + { + return GetFadingCodeSimple( context, offsetIndex, parentFadeMode ); + } + + return null; + } + + public List GetFadingCodeSimple( ShaderGenerationContext context, int offsetIndex, AlphaFadeMode parentFadeMode ) + { + var alphaFadeMode = GetFadeMode( parentFadeMode ); + var suffix = GetSuffix( offsetIndex ); + + if ( context.isIncludesPhase ) + { + return IncludeLightLibrary().Concat( IncludeMathLibrary() ); + } + + if ( context.isVariablesPhase ) + { + var code = + $@" + uniform float fresnelFadingPower{suffix} = 1.0f; + uniform bool fresnelFadingInverse{suffix} = false; + "; + return ToCode( code.Indent( " " ) ); + } + + + if ( context.isFragmentPhase ) + { + var code = + $@" + float fresnelFadingAlpha{suffix} = clamp01( fresnelNormalizedFromView( NORMAL, fresnelFadingPower{suffix} ) ); + + if ( ! fresnelFadingInverse{suffix} ) + {{ fresnelFadingAlpha{suffix} = 1.0 - fresnelFadingAlpha{suffix}; }} + + "; + + + return ToCode( code.Indent( " " ) ).Concat( ToCode( AlphaFade.Fragment( "fresnelFadingAlpha" + suffix, alphaFadeMode ) ) ); + } + + return []; + } + + + public List GetFadingCodeAdvanced( ShaderGenerationContext context, int offsetIndex, AlphaFadeMode parentFadeMode ) + { + var alphaFadeMode = GetFadeMode( parentFadeMode ); + var suffix = GetSuffix( offsetIndex ); + + if ( context.isIncludesPhase ) + { + return IncludeLightLibrary(); + } + + if ( context.isVariablesPhase ) + { + var code = + $@" + uniform float advancedFresnelFadingZOffset{suffix} = 0.0f; + uniform float advancedFresnelFadingPower{suffix} = 1.0f; + uniform float advancedFresnelFadingPostScale{suffix} = 1.0f; + uniform float advancedFresnelFadingPostOffset{suffix} = 0.0f; + uniform bool advancedFresnelFadingInverse = false; + + "; + return ToCode( code.Indent( "" ) ); + } + + + if ( context.isFragmentPhase ) + { + var code = + $@" + float advancedFresnelFadingAlpha{suffix} = clamp01( fresnelNormalizedFromViewAdvanced( NORMAL, + advancedFresnelFadingZOffset{suffix}, + advancedFresnelFadingPower{suffix}, + advancedFresnelFadingPostScale{suffix}, + advancedFresnelFadingPostOffset{suffix} + ) ); + + if ( ! advancedFresnelFadingInverse{suffix} ) + {{ advancedFresnelFadingAlpha{suffix} = 1.0 - advancedFresnelFadingAlpha{suffix}; }} + + "; + + + return ToCode( code.Indent( " " ) ).Concat( ToCode( AlphaFade.Fragment( "advancedFresnelFadingAlpha" + suffix, alphaFadeMode ) ) ); + } + + return []; + } + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Fading/Fresnel/FresnelFading.cs.uid b/Runtime/Shading/Generators/Spatial/Fading/Fresnel/FresnelFading.cs.uid new file mode 100644 index 0000000..fda4491 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/Fresnel/FresnelFading.cs.uid @@ -0,0 +1 @@ +uid://dpkfvftsk23we diff --git a/Runtime/Shading/Generators/Spatial/Fading/Line/LineFading.cs b/Runtime/Shading/Generators/Spatial/Fading/Line/LineFading.cs new file mode 100644 index 0000000..1eacee7 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/Line/LineFading.cs @@ -0,0 +1,229 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class LineFading:FadingModifier + { + public enum Mode + { + World, + WorldPoint_To_Camera, + Screen + } + + [Export] + public Mode mode; + + public override bool IsSameType( FadingModifier modifier ) + { + if ( modifier is LineFading lf ) + { + return lf.mode == mode; + } + + return false; + } + + public override List GetFadingCode( ShaderGenerationContext context, int offsetIndex, AlphaFadeMode parentFadeMode ) + { + var alphaFadeMode = GetFadeMode( parentFadeMode ); + + var suffix = GetSuffix( offsetIndex ); + + if ( context.isIncludesPhase ) + { + return IncludeTransformLibrary().Concat( IncludeFromLibrary( "Line3" ) ).Concat( IncludeSDFLibrary() ); + } + + if ( context.isVariablesPhase ) + { + if ( Mode.Screen == mode ) + { + List variables = + [ + Uniform( "screenLineDistanceFadeWorldPositionA" + suffix, Vector3.Zero ), + Uniform( "screenLineDistanceFadeWorldPositionB" + suffix, Vector3.One ), + VaryingVec3( "screenLineDistanceFadeScreenPositionA" + suffix ), + VaryingVec3( "screenLineDistanceFadeScreenPositionB" + suffix ), + Uniform( "screenLineDistanceFadeInnerRadius" + suffix, 0.1f ), + Uniform( "screenLineDistanceFadeOuterRadius" + suffix, 0.15f ), + VaryingVec2( "screenLineDistanceViewportRatio" + suffix ) + ]; + + variables = variables.Map( v => v.LineBreak() ); + + return ToCode( variables ); + } + else if ( Mode.World == mode ) + { + List variables = + [ + Uniform( "worldLineDistanceFadeWorldPositionA" + suffix, Vector3.Zero ), + Uniform( "worldLineDistanceFadeWorldPositionB" + suffix, Vector3.One ), + VaryingVec3( "worldLineDistanceFadeViewPositionA" + suffix ), + VaryingVec3( "worldLineDistanceFadeViewPositionB" + suffix ), + Uniform( "worldLineDistanceFadeInnerRadius" + suffix, 0.1f ), + Uniform( "worldLineDistanceFadeOuterRadius" + suffix, 0.15f ) + ]; + + variables = variables.Map( v => v.LineBreak() ); + + return ToCode( variables ); + } + else if ( Mode.WorldPoint_To_Camera == mode ) + { + List variables = + [ + Uniform( "worldCameraLineDistanceFadeWorldPosition" + suffix, Vector3.Zero ), + VaryingVec3( "worldCameraLineDistanceFadeViewPosition" + suffix ), + Uniform( "worldCameraLineDistanceFadeInnerRadius" + suffix, 0.1f ), + Uniform( "worldCameraLineDistanceFadeOuterRadius" + suffix, 0.15f ) + ]; + + variables = variables.Map( v => v.LineBreak() ); + + return ToCode( variables ); + } + } + + if ( context.isVertexPhase ) + { + if ( Mode.Screen == mode ) + { + var code = + $@" + + screenLineDistanceFadeScreenPositionA{suffix} = vec3( worldToScreen( screenLineDistanceFadeWorldPositionA{suffix}, VIEW_MATRIX, PROJECTION_MATRIX ), 0.0 ); + screenLineDistanceFadeScreenPositionB{suffix} = vec3( worldToScreen( screenLineDistanceFadeWorldPositionB{suffix}, VIEW_MATRIX, PROJECTION_MATRIX ), 0.0 ); + + "; + + return ToCode( code.Indent( " ") ); + } + else if ( Mode.World == mode ) + { + var code = + $@" + + worldLineDistanceFadeViewPositionA{suffix} = worldToView( worldLineDistanceFadeWorldPositionA{suffix}, VIEW_MATRIX ); + worldLineDistanceFadeViewPositionB{suffix} = worldToView( worldLineDistanceFadeWorldPositionB{suffix}, VIEW_MATRIX ); + + "; + + return ToCode( code.Indent( " ") ); + + } + else if ( Mode.WorldPoint_To_Camera == mode ) + { + var code = + $@" + + worldCameraLineDistanceFadeViewPosition{suffix} = worldToView( worldCameraLineDistanceFadeWorldPosition{suffix}, VIEW_MATRIX ); + + "; + + return ToCode( code.Indent( " ") ); + + } + + + } + + if ( context.isFragmentPhase ) + { + if ( Mode.Screen == mode ) + { + var fadeVariable = "screenLineDistanceFadeAmount" + suffix; + var fade = AlphaFade.Fragment( fadeVariable, alphaFadeMode ); + var code = + $@" + + {{ + + vec2 screenRatioMultiply = VIEWPORT_SIZE; + + if ( screenRatioMultiply.x > screenRatioMultiply.y ) + {{ + screenRatioMultiply /= VIEWPORT_SIZE.x; + }} + else + {{ + screenRatioMultiply /= VIEWPORT_SIZE.y; + }} + + vec2 screenVertex = viewToScreen( VERTEX, PROJECTION_MATRIX ) * screenRatioMultiply; + + + + Line3 screenLineDistanceFadeLine3; + screenLineDistanceFadeLine3.start = screenLineDistanceFadeScreenPositionA{suffix} * vec3( screenRatioMultiply, 1.0 ); + screenLineDistanceFadeLine3.end = screenLineDistanceFadeScreenPositionB{suffix} * vec3( screenRatioMultiply, 1.0 ); + + float screenLineDistanceFadeDistance = Line3_getDistance( screenLineDistanceFadeLine3, vec3( screenVertex, 0.0 ) ); + + float {fadeVariable} = clamp( smoothstep( screenLineDistanceFadeInnerRadius{suffix}, screenLineDistanceFadeOuterRadius{suffix}, screenLineDistanceFadeDistance ), 0.0, 1.0 ); + + {fade} + + }} + "; + + return ToCode( code.Indent( " ") ); + } + else if ( Mode.World == mode ) + { + var fadeVariable = "worldLineDistanceFadeAmount" + suffix; + var fade = AlphaFade.Fragment( fadeVariable, alphaFadeMode ); + var code = + $@" + + {{ + + Line3 worldLineDistanceFadeLine3; + worldLineDistanceFadeLine3.start = worldLineDistanceFadeViewPositionA{suffix}; + worldLineDistanceFadeLine3.end = worldLineDistanceFadeViewPositionB{suffix}; + + float worldLineDistanceFadeDistance = Line3_getDistance( worldLineDistanceFadeLine3, VERTEX ); + + float {fadeVariable} = clamp( smoothstep( worldLineDistanceFadeInnerRadius{suffix}, worldLineDistanceFadeOuterRadius{suffix}, worldLineDistanceFadeDistance ), 0.0, 1.0 ); + + {fade} + + }} + "; + + return ToCode( code.Indent( " ") ); + } + else if ( Mode.WorldPoint_To_Camera == mode ) + { + var fadeVariable = "worldLineDistanceFadeAmount" + suffix; + var fade = AlphaFade.Fragment( fadeVariable, alphaFadeMode ); + var code = + $@" + + {{ + + float worldLineDistanceFadeDistance = sdRoundCone( VERTEX, vec3( 0.0, 0.0, 0.0), worldCameraLineDistanceFadeViewPosition{suffix}, 0, worldCameraLineDistanceFadeInnerRadius ); + + + float {fadeVariable} = clamp( smoothstep( 0, ( worldCameraLineDistanceFadeOuterRadius{suffix} - worldCameraLineDistanceFadeInnerRadius{suffix} ), worldLineDistanceFadeDistance ), 0.0, 1.0 ); + + {fade} + + }} + "; + + return ToCode( code.Indent( " ") ); + } + } + + return []; + } + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Fading/Line/LineFading.cs.uid b/Runtime/Shading/Generators/Spatial/Fading/Line/LineFading.cs.uid new file mode 100644 index 0000000..5141510 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Fading/Line/LineFading.cs.uid @@ -0,0 +1 @@ +uid://biqus8elamaeo diff --git a/Runtime/Shading/Generators/Spatial/Geometry/GeometryModifier.cs b/Runtime/Shading/Generators/Spatial/Geometry/GeometryModifier.cs new file mode 100644 index 0000000..27c41d5 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Geometry/GeometryModifier.cs @@ -0,0 +1,24 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public abstract partial class GeometryModifier:ShaderGenerationModule + { + public virtual bool IsSameType( GeometryModifier modifier ) + { + return modifier.GetType() == GetType(); + } + + public abstract List GetGeometryCode( ShaderGenerationContext context, int offsetIndex ); + + + public string GetSuffix( int offsetIndex ) + { + return offsetIndex <= 0 ? "" : ( "_" + ( offsetIndex + 1 ) ); + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Vertex/VertexModifier.cs.uid b/Runtime/Shading/Generators/Spatial/Geometry/GeometryModifier.cs.uid similarity index 100% rename from Runtime/Shading/Generators/Spatial/Vertex/VertexModifier.cs.uid rename to Runtime/Shading/Generators/Spatial/Geometry/GeometryModifier.cs.uid diff --git a/Runtime/Shading/Generators/Spatial/Geometry/GeometryModule.cs b/Runtime/Shading/Generators/Spatial/Geometry/GeometryModule.cs new file mode 100644 index 0000000..1c3af0e --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Geometry/GeometryModule.cs @@ -0,0 +1,38 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class GeometryModule:ShaderGenerationModule + { + [Export] + public GeometryModifier[] modifiers = []; + + public override List GetVariants( ShaderGenerationContext context ) + { + var list = new List(); + + var allModifiers = Lists.From( modifiers ).FilterNulls(); + + allModifiers.ForEach( + ( m )=> + { + var offsetIndex = allModifiers.Filter( l => l.IsSameType( m ) ).IndexOf( m ); + var geometryCode = m.GetGeometryCode( context, offsetIndex ); + + if ( geometryCode == null ) + { + return; + } + + list.AddRange( geometryCode ); + } + ); + + return ToVariants( list ); + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Vertex/VertexModule.cs.uid b/Runtime/Shading/Generators/Spatial/Geometry/GeometryModule.cs.uid similarity index 100% rename from Runtime/Shading/Generators/Spatial/Vertex/VertexModule.cs.uid rename to Runtime/Shading/Generators/Spatial/Geometry/GeometryModule.cs.uid diff --git a/Runtime/Shading/Generators/Spatial/Geometry/NormalOffset/GeometryNormalOffset.cs b/Runtime/Shading/Generators/Spatial/Geometry/NormalOffset/GeometryNormalOffset.cs new file mode 100644 index 0000000..284cc72 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Geometry/NormalOffset/GeometryNormalOffset.cs @@ -0,0 +1,198 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class GeometryNormalOffset:GeometryModifier + { + public enum Mode + { + Object, + World + } + + [Export] + public Mode mode; + + [ExportGroup("Texture")] + [Export] + public bool textureScaleEnabled = false; + + [Export] + public string textureUVChannel = "UV"; + + [Export] + public bool textureRepeat = true; + + [Export] + public TextureModule.TextureFilter textureFilter = TextureModule.TextureFilter.Linear_MipMap_Anisotropic; + + public override bool IsSameType( GeometryModifier modifier ) + { + if ( modifier is GeometryNormalOffset no ) + { + return no.mode == mode; + } + + return false; + } + + public override List GetGeometryCode( ShaderGenerationContext context, int offsetIndex ) + { + if ( Mode.Object == mode ) + { + return ObjectNormal( context, offsetIndex ); + } + else if ( Mode.World == mode ) + { + return WorldNormal( context, offsetIndex ); + } + + return null; + } + + List ObjectNormal( ShaderGenerationContext context, int offsetIndex ) + { + var suffix = GetSuffix( offsetIndex ); + + if ( ShaderPhase.Variables == context.phase ) + { + var hints = new List(); + + hints.Add( "hint_default_white" ); + hints.Add( textureRepeat ? "repeat_enable" : "repeat_disable" ); + hints.Add( "filter_" + ( textureFilter + "" ).ToLower() ); + + var sampler = UniformSampler( $"objectNormalOffsetTexture{suffix}", hints.Join( ", " ) ); + + if ( ! textureScaleEnabled ) + { + sampler = ""; + } + + return AsUniformGroup( $"ObjectNormalOffset{suffix}", + + $@" + uniform float objectNormalOffset{suffix} = 0.1; + {sampler} + + " + + ); + + } + + if ( ShaderPhase.Vertex == context.phase ) + { + var samplerMultply = + $@" + float sampledObjectNormalOffset{suffix} = texture( objectNormalOffsetTexture{suffix}, {textureUVChannel} ).r; + objectNormalOffsetAmount{suffix} *= sampledObjectNormalOffset{suffix}; + "; + + if ( ! textureScaleEnabled ) + { + samplerMultply = ""; + } + + return ToInnerBlock( $"ObjectNormalOffset{suffix}", + + $@" + + {{ + + float objectNormalOffsetAmount{suffix} = objectNormalOffset{suffix}; + {samplerMultply} + VERTEX += NORMAL * objectNormalOffsetAmount{suffix}; + + }} + " + + ); + } + + return null; + } + + + List WorldNormal( ShaderGenerationContext context, int offsetIndex ) + { + var suffix = GetSuffix( offsetIndex ); + + if ( ShaderPhase.Includes == context.phase ) + { + return IncludeTransformLibrary(); + } + else if ( ShaderPhase.Variables == context.phase ) + { + var hints = new List(); + + hints.Add( "hint_default_white" ); + hints.Add( textureRepeat ? "repeat_enable" : "repeat_disable" ); + hints.Add( "filter_" + ( textureFilter + "" ).ToLower() ); + + var sampler = UniformSampler( $"worldNormalOffsetTexture{suffix}", hints.Join( ", " ) ); + + if ( ! textureScaleEnabled ) + { + sampler = ""; + } + + return AsUniformGroup( $"WorldNormalOffset{suffix}", + + $@" + uniform float worldNormalOffsetScale{suffix} = 1.0; + uniform float worldNormalWorldOffset{suffix} = 0.1; + uniform float worldNormalViewOffset{suffix} = 0.1; + uniform float worldNormalScaleType{suffix}:hint_range( 0.0, 1.0 ) = 1.0; + {sampler} + + " + + ); + + } + + if ( ShaderPhase.Vertex == context.phase ) + { + var samplerMultply = + $@" + float sampledWorldNormalOffset{suffix} = texture( worldNormalOffsetTexture{suffix}, {textureUVChannel} ).r; + worldNormalOffsetAmount{suffix} *= sampledWorldNormalOffset{suffix}; + "; + + if ( ! textureScaleEnabled ) + { + samplerMultply = ""; + } + + return ToInnerBlock( $"WorldNormalOffset{suffix}", + + $@" + + {{ + + float vertexDistance = length( localToWorld( VERTEX, MODEL_MATRIX ) - CAMERA_POSITION_WORLD ); + float worldNormalOffsetAmount{suffix} = mix( worldNormalWorldOffset{suffix}, vertexDistance * worldNormalViewOffset{suffix}, worldNormalScaleType{suffix} ); + + {samplerMultply} + + + vec3 worldNormal = localToWorldDirection( NORMAL, MODEL_MATRIX ) * worldNormalOffsetAmount{suffix} * worldNormalOffsetScale{suffix}; + vec3 localNormal = worldToLocalDirection( worldNormal, MODEL_MATRIX ); + + VERTEX += localNormal; + + }} + " + + ); + } + + return null; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Geometry/NormalOffset/GeometryNormalOffset.cs.uid b/Runtime/Shading/Generators/Spatial/Geometry/NormalOffset/GeometryNormalOffset.cs.uid new file mode 100644 index 0000000..23eac71 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Geometry/NormalOffset/GeometryNormalOffset.cs.uid @@ -0,0 +1 @@ +uid://j4aagrd2fmce diff --git a/Runtime/Shading/Generators/Spatial/Geometry/TerrainOffset/GeometryTerrainOffset.cs b/Runtime/Shading/Generators/Spatial/Geometry/TerrainOffset/GeometryTerrainOffset.cs new file mode 100644 index 0000000..d48aa2b --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Geometry/TerrainOffset/GeometryTerrainOffset.cs @@ -0,0 +1,63 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class GeometryTerrainOffset:GeometryModifier + { + public override List GetGeometryCode( ShaderGenerationContext context, int offsetIndex ) + { + if ( offsetIndex != 0 ) + { + throw new System.Exception( "Unique component, can't be used multiple times"); + } + + if ( ShaderPhase.Includes == context.phase ) + { + return IncludeFromLibrary( "Terrain" ); + } + + if ( ShaderPhase.Variables == context.phase ) + { + return AsUniformGroup( "Terrain", + + @" + uniform sampler2D terrainHeightMap; + uniform vec2 terrainCenterXZ = vec2( 0.0, 0.0 ); + uniform vec2 terrainSizeXZ = vec2( 100.0, 100.0 ); + uniform float terrainMinHeight = 0.0; + uniform float terrainMaxHeight = 100.0; + " + + ); + + } + + if ( ShaderPhase.Vertex == context.phase ) + { + + return ToInnerBlock( "Terrain", + + @" + addTerrainOffset( + MODEL_MATRIX, + VERTEX, + terrainHeightMap, + terrainCenterXZ, + terrainSizeXZ, + terrainMinHeight, + terrainMaxHeight + ); + + " + + ); + } + + return null; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Geometry/TerrainOffset/GeometryTerrainOffset.cs.uid b/Runtime/Shading/Generators/Spatial/Geometry/TerrainOffset/GeometryTerrainOffset.cs.uid new file mode 100644 index 0000000..cb342b0 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Geometry/TerrainOffset/GeometryTerrainOffset.cs.uid @@ -0,0 +1 @@ +uid://cmby3d8ou6e30 diff --git a/Runtime/Shading/Generators/Spatial/Vertex/VertexWind.cs b/Runtime/Shading/Generators/Spatial/Geometry/Wind/GeometryWind.cs similarity index 55% rename from Runtime/Shading/Generators/Spatial/Vertex/VertexWind.cs rename to Runtime/Shading/Generators/Spatial/Geometry/Wind/GeometryWind.cs index 168242f..65c7cd4 100644 --- a/Runtime/Shading/Generators/Spatial/Vertex/VertexWind.cs +++ b/Runtime/Shading/Generators/Spatial/Geometry/Wind/GeometryWind.cs @@ -1,15 +1,14 @@ using Godot; using System.Reflection; using System.Collections.Generic; +using System; namespace Rokojori { [Tool] [GlobalClass] - public partial class VertexWind:VertexModifier + public partial class GeometryWind:GeometryModifier { - [Export] - public bool enabled = true; [Export] public bool sampleAngleFromNoise = true; @@ -18,11 +17,16 @@ namespace Rokojori public bool heightCompensation = true; - public override List GetCode( ShaderGenerationContext context ) + public override List GetGeometryCode( ShaderGenerationContext context, int offsetIndex ) { + if ( offsetIndex != 0 ) + { + throw new Exception( "Unique component, can't be used multiple times"); + } + if ( ShaderPhase.Includes == context.phase ) { - return ToCode( "#include \"res://addons/rokojori_action_library/Runtime/Shading/Library/Wind.gdshaderinc\"" ); + return IncludeFromLibrary( "Wind" ); } if ( ShaderPhase.Variables == context.phase ) @@ -30,16 +34,20 @@ namespace Rokojori return AsUniformGroup( "Wind", @" + uniform float windStrength = 0; uniform vec2 windSpeed = vec2(1,1); - uniform float windScale = 1; + uniform float windScale = 0.1; uniform sampler2D windNoise; uniform vec2 windNoiseAngleOffset; - uniform vec2 windNoiseStrengthOffset = vec2( 0.1234, 0.56789 ); + uniform vec2 windNoiseStrengthOffset; uniform float windStart = 0; uniform float windEnd = 1; uniform float windWeightCurve:hint_range(0,1) = 0.5f; uniform float windHeightCompensation :hint_range(0,1) = 0.5f; + uniform float windNormalBending :hint_range(0,1) = 0.1f; + uniform float windOcclusionAmount = 0; + varying float vertexWindAO; " ); @@ -51,10 +59,17 @@ namespace Rokojori return ToInnerBlock( "Wind", - @" - applyWind( - TIME, MODEL_MATRIX, VERTEX, + @" + float cachedVertexWindAO = 0.0; + + applyWind( + TIME, + MODEL_MATRIX, + VERTEX, + NORMAL, + cachedVertexWindAO, + windOcclusionAmount, windStrength, windSpeed, windScale, @@ -64,11 +79,20 @@ namespace Rokojori windStart, windEnd, windWeightCurve, - windHeightCompensation + windHeightCompensation, + windNormalBending ); + + vertexWindAO = cachedVertexWindAO; + " - ); + ) ; + } + + if ( ShaderPhase.Fragment == context.phase ) + { + return ToCode( "AO *= vertexWindAO;".Indent( " " ).LineBreaks() ); } return null; diff --git a/Runtime/Shading/Generators/Spatial/Vertex/VertexWind.cs.uid b/Runtime/Shading/Generators/Spatial/Geometry/Wind/GeometryWind.cs.uid similarity index 100% rename from Runtime/Shading/Generators/Spatial/Vertex/VertexWind.cs.uid rename to Runtime/Shading/Generators/Spatial/Geometry/Wind/GeometryWind.cs.uid diff --git a/Runtime/Shading/Generators/Spatial/Metallic/MetallicModule.cs b/Runtime/Shading/Generators/Spatial/Metallic/MetallicModule.cs new file mode 100644 index 0000000..36c0c1d --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Metallic/MetallicModule.cs @@ -0,0 +1,53 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class MetallicModule:TextureModule + { + public MetallicModule() + { + _domainName = "metallic"; + _domainScaleName = "metallic"; + _domainOffsetName = "metallicOffset"; + _domainValueName = "metallic"; + + _target = "METALLIC"; + _type = TextureChannelType.ONE; + _channelSource = TextureChannelSource.B; + domainScaleDefault = 0; + } + + [Export] + public TextureFilter filter = TextureFilter.Linear_MipMap_Anisotropic; + + [Export] + public DomainMode domainMode = DomainMode.Texture_Scale_Offset; + + [Export] + public bool repeat = true; + + [Export] + public string uvChannel = "UV"; + + [Export] + public TextureDefault textureDefault = TextureDefault.White; + + [Export] + public AssignmentType assignmentType = AssignmentType.Set; + + public override void GrabValues() + { + _domainMode = domainMode; + _textureFilter = filter; + _repeat = repeat; + _textureDefault = textureDefault; + _uvChannel = uvChannel; + + _assignmentType = assignmentType; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Metallic/MetallicModule.cs.uid b/Runtime/Shading/Generators/Spatial/Metallic/MetallicModule.cs.uid new file mode 100644 index 0000000..d626d95 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Metallic/MetallicModule.cs.uid @@ -0,0 +1 @@ +uid://n0gi67ntpq0y diff --git a/Runtime/Shading/Generators/Spatial/NormalMap/NormalMapModule.cs b/Runtime/Shading/Generators/Spatial/NormalMap/NormalMapModule.cs new file mode 100644 index 0000000..8b9a956 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/NormalMap/NormalMapModule.cs @@ -0,0 +1,58 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class NormalMapModule:TextureModule + { + public NormalMapModule() + { + _type = TextureChannelType.RGB; + + _domainName = "normal"; + _domainScaleName = "normalStrength"; + _domainValueName = "normal"; + _target = "NORMAL_MAP"; + _scaleTarget = "NORMAL_MAP_DEPTH"; + _normal = true; + _type = TextureChannelType.RGB; + scaleType = TextureChannelType.SCALAR; + } + + [Export] + public TextureFilter filter = TextureFilter.Linear_MipMap_Anisotropic; + + [Export] + public bool useStrength = true; + + [Export] + public float maximumStrength = 5; + + [Export] + public bool allowNegativeStrength = false; + + [Export] + public bool repeat = true; + + [Export] + public string uvChannel = "UV"; + + [Export] + public TextureDefault textureDefault = TextureDefault.White; + + public override void GrabValues() + { + _domainMode = useStrength ? DomainMode.Texture_Scale : DomainMode.Texture; + _textureFilter = filter; + _repeat = repeat; + _textureDefault = textureDefault; + _uvChannel = uvChannel; + + domainScaleMax = Mathf.Abs( maximumStrength ); + domainScaleMin = allowNegativeStrength ? -Mathf.Abs( maximumStrength ) : 0; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/NormalMap/NormalMapModule.cs.uid b/Runtime/Shading/Generators/Spatial/NormalMap/NormalMapModule.cs.uid new file mode 100644 index 0000000..9858c16 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/NormalMap/NormalMapModule.cs.uid @@ -0,0 +1 @@ +uid://tl4qfoxysj06 diff --git a/Runtime/Shading/Generators/Spatial/Occlusion/OcclusionModule.cs b/Runtime/Shading/Generators/Spatial/Occlusion/OcclusionModule.cs new file mode 100644 index 0000000..3a4b681 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Occlusion/OcclusionModule.cs @@ -0,0 +1,53 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class OcclusionModule:TextureModule + { + public OcclusionModule() + { + _domainName = "occlusion"; + _domainScaleName = "occlusion"; + _domainOffsetName = "occlusionOffset"; + _domainValueName = "occlusion"; + + _target = "AO"; + _type = TextureChannelType.ONE; + _channelSource = TextureChannelSource.R; + + } + + [Export] + public TextureFilter filter = TextureFilter.Linear_MipMap_Anisotropic; + + [Export] + public DomainMode domainMode = DomainMode.Texture_Scale_Offset; + + [Export] + public bool repeat = true; + + [Export] + public string uvChannel = "UV"; + + [Export] + public TextureDefault textureDefault = TextureDefault.White; + + [Export] + public AssignmentType assignmentType = AssignmentType.Set; + + public override void GrabValues() + { + _domainMode = domainMode; + _textureFilter = filter; + _repeat = repeat; + _textureDefault = textureDefault; + _uvChannel = uvChannel; + _assignmentType = assignmentType; + + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Occlusion/OcclusionModule.cs.uid b/Runtime/Shading/Generators/Spatial/Occlusion/OcclusionModule.cs.uid new file mode 100644 index 0000000..dd35e76 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Occlusion/OcclusionModule.cs.uid @@ -0,0 +1 @@ +uid://dnikyu81333q8 diff --git a/Runtime/Shading/Generators/Spatial/Roughness/RoughnessModule.cs b/Runtime/Shading/Generators/Spatial/Roughness/RoughnessModule.cs new file mode 100644 index 0000000..0df20ba --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Roughness/RoughnessModule.cs @@ -0,0 +1,57 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class RoughnessModule:TextureModule + { + public RoughnessModule() + { + _domainName = "roughness"; + _domainScaleName = "roughness"; + _domainOffsetName = "roughnessOffset"; + _domainValueName = "roughness"; + + _target = "ROUGHNESS"; + _type = TextureChannelType.ONE; + _channelSource = TextureChannelSource.G; + + } + + [Export] + public TextureFilter filter = TextureFilter.Linear_MipMap_Anisotropic; + + [Export] + public DomainMode domainMode = DomainMode.Texture_Scale_Offset; + + [Export] + public bool repeat = true; + + [Export] + public string uvChannel = "UV"; + + [Export] + public TextureDefault textureDefault = TextureDefault.White; + + [Export] + public AssignmentType assignmentType = AssignmentType.Set; + + [Export] + public bool clamp = true; + + public override void GrabValues() + { + _domainMode = domainMode; + _textureFilter = filter; + _repeat = repeat; + _textureDefault = textureDefault; + _uvChannel = uvChannel; + _assignmentType = assignmentType; + _clamp = clamp; + + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Roughness/RoughnessModule.cs.uid b/Runtime/Shading/Generators/Spatial/Roughness/RoughnessModule.cs.uid new file mode 100644 index 0000000..cd98902 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Roughness/RoughnessModule.cs.uid @@ -0,0 +1 @@ +uid://dew0uayffwxwk diff --git a/Runtime/Shading/Generators/Spatial/ShadingModule.cs b/Runtime/Shading/Generators/Spatial/Shading/ShadingModule.cs similarity index 94% rename from Runtime/Shading/Generators/Spatial/ShadingModule.cs rename to Runtime/Shading/Generators/Spatial/Shading/ShadingModule.cs index a4b08e5..16bd5e7 100644 --- a/Runtime/Shading/Generators/Spatial/ShadingModule.cs +++ b/Runtime/Shading/Generators/Spatial/Shading/ShadingModule.cs @@ -32,7 +32,7 @@ namespace Rokojori [Export] public bool wireFrameMode = false; - public override List GetCode( ShaderGenerationContext context ) + public override List GetVariants( ShaderGenerationContext context ) { if ( ShaderPhase.RenderMode != context.phase ) { @@ -91,7 +91,7 @@ namespace Rokojori value = RegexUtility.Replace( value, @"\,\s*$", "" ); - return Lists.From( (ShaderCode) new StringShaderCode( value ) ); + return ToVariants( ToCode( value ) ) ; } } diff --git a/Runtime/Shading/Generators/Spatial/ShadingModule.cs.uid b/Runtime/Shading/Generators/Spatial/Shading/ShadingModule.cs.uid similarity index 100% rename from Runtime/Shading/Generators/Spatial/ShadingModule.cs.uid rename to Runtime/Shading/Generators/Spatial/Shading/ShadingModule.cs.uid diff --git a/Runtime/Shading/Generators/Spatial/SpatialShaderData.cs b/Runtime/Shading/Generators/Spatial/SpatialShaderData.cs new file mode 100644 index 0000000..ebb3d10 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/SpatialShaderData.cs @@ -0,0 +1,249 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class SpatialShaderData:Resource + { + [ExportGroup("Presets/Starters")] + + [ExportToolButton("PBR Starter")] + public Callable pbrStarterButton => Callable.From( ()=>{ PBR_Starter(); } ); + + [ExportToolButton("PBR Alpha Starter")] + public Callable pbrAlphaStarterButton => Callable.From( ()=>{ PBR_Alpha_Starter(); } ); + + [ExportToolButton("PBR Emissive Starter")] + public Callable pbrEmissiveStarterButton => Callable.From( ()=>{ PBR_Emissive_Starter(); } ); + + [ExportToolButton("PBR Luminance Starter")] + public Callable pbrLuminanceStarterButton => Callable.From( ()=>{ PBR_Luminance_Starter(); } ); + + [ExportToolButton("PBR All Starter")] + public Callable pbrAllStarterButton => Callable.From( ()=>{ PBR_All_Starter(); } ); + + [ExportToolButton("Unshaded Starter")] + public Callable unshadedStarterButton => Callable.From( ()=>{ Unshaded_Starter(); } ); + + + + [ExportGroup("Modules")] + [Export] + public TransparencyModule transparency = new TransparencyModule(); + + [Export] + public ShadingModule shading = new ShadingModule(); + + [Export] + public StencilModule stencil = null; + + [Export] + public GeometryModule geometry = new GeometryModule(); + + [Export] + public UVModule uv = new UVModule(); + + + [Export] + public AlbedoModule albedo = new AlbedoModule(); + + [Export] + public AlphaModule alpha = null; + + [Export] + public FadingModule fading = null; + + + [Export] + public NormalMapModule normalMap = null; + + [Export] + public RoughnessModule roughness = null; + + [Export] + public MetallicModule metallic = null; + + [Export] + public SpecularModule specular = null; + + + [Export] + public OcclusionModule occlusion = null; + + [Export] + public EmissionModule emission = null; + + [Export] + public BacklightModule backlight = null; + + [Export] + public SubsurfaceScatteringModule subsurfaceScattering = null; + + public void PBR_All_Starter() + { + transparency = new TransparencyModule(); + shading = new ShadingModule(); + stencil = null; + + geometry = new GeometryModule(); + + uv = new UVModule(); + + albedo = new AlbedoModule(); + alpha = null; + fading = null; + + normalMap = new NormalMapModule(); + roughness = new RoughnessModule(); + metallic = new MetallicModule(); + specular = new SpecularModule(); + specular.domainMode = TextureModule.DomainMode.Value; + occlusion = new OcclusionModule(); + + emission = new EmissionModule(); + backlight = new BacklightModule(); + subsurfaceScattering = new SubsurfaceScatteringModule(); + } + + public void PBR_Luminance_Starter() + { + transparency = new TransparencyModule(); + shading = new ShadingModule(); + stencil = null; + + geometry = new GeometryModule(); + + uv = new UVModule(); + + albedo = new AlbedoModule(); + alpha = null; + fading = null; + + normalMap = new NormalMapModule(); + roughness = new RoughnessModule(); + metallic = new MetallicModule(); + specular = new SpecularModule(); + specular.domainMode = TextureModule.DomainMode.Value; + occlusion = new OcclusionModule(); + + emission = null; + backlight = new BacklightModule(); + subsurfaceScattering = new SubsurfaceScatteringModule(); + } + + + + public void PBR_Starter() + { + transparency = new TransparencyModule(); + shading = new ShadingModule(); + stencil = null; + + geometry = new GeometryModule(); + + uv = new UVModule(); + + albedo = new AlbedoModule(); + alpha = null; + fading = null; + + normalMap = new NormalMapModule(); + roughness = new RoughnessModule(); + metallic = new MetallicModule(); + specular = new SpecularModule(); + specular.domainMode = TextureModule.DomainMode.Value; + occlusion = new OcclusionModule(); + + emission = null; + backlight = null; + subsurfaceScattering = null; + } + + public void PBR_Emissive_Starter() + { + transparency = new TransparencyModule(); + shading = new ShadingModule(); + stencil = null; + + geometry = new GeometryModule(); + + uv = new UVModule(); + + albedo = new AlbedoModule(); + alpha = null; + fading = null; + + normalMap = new NormalMapModule(); + roughness = new RoughnessModule(); + metallic = new MetallicModule(); + specular = new SpecularModule(); + specular.domainMode = TextureModule.DomainMode.Value; + occlusion = new OcclusionModule(); + + emission = new EmissionModule(); + + backlight = null; + subsurfaceScattering = null; + } + + public void PBR_Alpha_Starter() + { + transparency = new TransparencyModule(); + transparency.transparency = BaseMaterial3D.TransparencyEnum.Alpha; + + shading = new ShadingModule(); + stencil = null; + + geometry = new GeometryModule(); + + uv = new UVModule(); + + albedo = new AlbedoModule(); + alpha = new AlphaModule(); + fading = null; + + normalMap = new NormalMapModule(); + roughness = new RoughnessModule(); + metallic = new MetallicModule(); + specular = new SpecularModule(); + specular.domainMode = TextureModule.DomainMode.Value; + occlusion = new OcclusionModule(); + + emission = null; + backlight = null; + subsurfaceScattering = null; + } + + public void Unshaded_Starter() + { + transparency = new TransparencyModule(); + transparency.transparency = BaseMaterial3D.TransparencyEnum.Alpha; + + shading = new ShadingModule(); + shading.shadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded; + stencil = null; + + geometry = new GeometryModule(); + + uv = new UVModule(); + + albedo = new AlbedoModule(); + alpha = new AlphaModule(); + fading = null; + + normalMap = null; + roughness = null; + metallic = null; + specular = null; + + occlusion = null; + emission = null; + backlight = null; + subsurfaceScattering = null; + } + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/SpatialShaderData.cs.uid b/Runtime/Shading/Generators/Spatial/SpatialShaderData.cs.uid new file mode 100644 index 0000000..ce037eb --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/SpatialShaderData.cs.uid @@ -0,0 +1 @@ +uid://bakspsqw7d0hn diff --git a/Runtime/Shading/Generators/Spatial/SpatialShaderGenerator.cs b/Runtime/Shading/Generators/Spatial/SpatialShaderGenerator.cs index 9b8556d..76868a9 100644 --- a/Runtime/Shading/Generators/Spatial/SpatialShaderGenerator.cs +++ b/Runtime/Shading/Generators/Spatial/SpatialShaderGenerator.cs @@ -9,20 +9,7 @@ namespace Rokojori public partial class SpatialShaderGenerator:ShaderGenerator { [Export] - public TransparencyModule transparency = new TransparencyModule(); - - [Export] - public ShadingModule shading = new ShadingModule(); - - [Export] - public VertexModule vertex = new VertexModule(); - - [Export] - public UVModule uv = new UVModule(); - - [Export] - public AlbedoModule albedo = new AlbedoModule(); - + public SpatialShaderData data = new SpatialShaderData(); public override List GetPhases() { @@ -39,38 +26,97 @@ namespace Rokojori }; } + public string RokojoriInfo() + { + var allModules = GetAllModules(); + var hashValues = allModules.Map( a => a.GetShaderCacheHash() ); + hashValues.Sort(); + var hash = hashValues.Join( "-" ); + var allInfos = allModules.Map( a => a.GetShaderCacheData() ); + + return $"// Rokojori Shader @{hash}: \n/*\n" + allInfos.Join( "\n" ) + "\n*/\n"; + } + + List GetAllModules() + { + return GetHeaderModules().Concat( GetMainModules() ); + } + + List GetHeaderModules() + { + List list = [ + data.transparency, + data.shading, + data.stencil + ]; + + return list.FilterNulls(); + } + + List GetMainModules() + { + List list = [ + data.geometry, + data.uv, + data.albedo, + data.alpha, + data.fading, + data.normalMap, + data.occlusion, + data.roughness, + data.metallic, + data.specular, + data.emission, + data.backlight, + data.subsurfaceScattering + ]; + + return list.FilterNulls(); + } + public override List GetShaderGenerationModules( ShaderPhase phase ) { if ( ShaderPhase.Header == phase ) { + var info = RokojoriInfo(); return [ - new ShaderRawModule( "\n\nshader_type spatial;\n" ) + new ShaderRawModule( "\n\nshader_type spatial;\n" ), + new ShaderRawModule( $"\n{info}\n") ]; } if ( ShaderPhase.RenderMode == phase ) { - return + List modules = [ new ShaderRawModule( "render_mode " ), - transparency, + data.transparency, new ShaderRawModule( ", " ), - shading, - new ShaderRawModule( ";\n\n" ), + data.shading, + new ShaderRawModule( ";\n" ), ]; + + if ( data.stencil != null ) + { + modules.Add( new ShaderRawModule( data.stencil.ToShaderCode() + "\n" ) ); + } + + modules.Add( new ShaderRawModule( "\n" ) ); + + return modules; } + var mainModules = GetMainModules(); + if ( ShaderPhase.Includes == phase || ShaderPhase.Variables == phase || ShaderPhase.Functions == phase ) { - return - [ - transparency, - shading, - vertex, - uv, - albedo - ]; + List preModules = [ + data.transparency, + data.shading ] + ; + + return preModules.Concat( mainModules ); } if ( ShaderPhase.Vertex == phase ) @@ -79,10 +125,7 @@ namespace Rokojori { new ShaderRawModule( "\nvoid vertex()\n{\n\n" ) } - .Concat - ( - uv, vertex, albedo - ) + .Concat( mainModules ) .Concat ( new ShaderRawModule( "\n}\n" ) @@ -95,10 +138,7 @@ namespace Rokojori { new ShaderRawModule( "\nvoid fragment()\n{\n\n" ) } - .Concat - ( - uv, vertex, albedo - ) + .Concat( mainModules ) .Concat ( new ShaderRawModule( "\n}\n" ) diff --git a/Runtime/Shading/Generators/Spatial/Specular/SpecularModule.cs b/Runtime/Shading/Generators/Spatial/Specular/SpecularModule.cs new file mode 100644 index 0000000..263cfe8 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Specular/SpecularModule.cs @@ -0,0 +1,53 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class SpecularModule:TextureModule + { + public SpecularModule() + { + _domainName = "specular"; + _domainScaleName = "specular"; + _domainOffsetName = "specularOffset"; + _domainValueName = "specular"; + + _target = "SPECULAR"; + _type = TextureChannelType.ONE; + _channelSource = TextureChannelSource.G; + + } + + [Export] + public TextureFilter filter = TextureFilter.Linear_MipMap_Anisotropic; + + [Export] + public DomainMode domainMode = DomainMode.Texture_Scale_Offset; + + [Export] + public bool repeat = true; + + [Export] + public string uvChannel = "UV"; + + [Export] + public TextureDefault textureDefault = TextureDefault.White; + + [Export] + public AssignmentType assignmentType = AssignmentType.Set; + + public override void GrabValues() + { + _domainMode = domainMode; + _textureFilter = filter; + _repeat = repeat; + _textureDefault = textureDefault; + _uvChannel = uvChannel; + _assignmentType = assignmentType; + + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Specular/SpecularModule.cs.uid b/Runtime/Shading/Generators/Spatial/Specular/SpecularModule.cs.uid new file mode 100644 index 0000000..e17062e --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Specular/SpecularModule.cs.uid @@ -0,0 +1 @@ +uid://c7bmbvoc57ebo diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilBaseReference.cs b/Runtime/Shading/Generators/Spatial/Stencil/StencilBaseReference.cs new file mode 100644 index 0000000..3e5a374 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilBaseReference.cs @@ -0,0 +1,17 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + + [Tool] + [GlobalClass] + public partial class StencilBaseReference:StencilReference + { + public override int GetReferenceIndex() + { + return 0; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilBaseReference.cs.uid b/Runtime/Shading/Generators/Spatial/Stencil/StencilBaseReference.cs.uid new file mode 100644 index 0000000..9a04411 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilBaseReference.cs.uid @@ -0,0 +1 @@ +uid://c63efp5rl2r2p diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilCustomConfiguration.cs b/Runtime/Shading/Generators/Spatial/Stencil/StencilCustomConfiguration.cs new file mode 100644 index 0000000..94e3579 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilCustomConfiguration.cs @@ -0,0 +1,37 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + + [Tool] + [GlobalClass] + public partial class StencilCustomConfiguration:StencilModule + { + [Export] + public StencilMode mode; + + [Export] + public BaseMaterial3D.StencilCompareEnum compare; + + [Export] + public int reference; + + public override StencilMode GetStencilMode() + { + return mode; + } + + public override BaseMaterial3D.StencilCompareEnum GetStencilCompare() + { + return compare; + } + + public override int GetStencilReference() + { + return reference; + } + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilCustomConfiguration.cs.uid b/Runtime/Shading/Generators/Spatial/Stencil/StencilCustomConfiguration.cs.uid new file mode 100644 index 0000000..2dee578 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilCustomConfiguration.cs.uid @@ -0,0 +1 @@ +uid://nhoibf6vabih diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilIndexReference.cs b/Runtime/Shading/Generators/Spatial/Stencil/StencilIndexReference.cs new file mode 100644 index 0000000..6e6bc3a --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilIndexReference.cs @@ -0,0 +1,20 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + + [Tool] + [GlobalClass] + public partial class StencilIndexReference:StencilReference + { + [Export] + public int index; + + public override int GetReferenceIndex() + { + return index; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilIndexReference.cs.uid b/Runtime/Shading/Generators/Spatial/Stencil/StencilIndexReference.cs.uid new file mode 100644 index 0000000..77684ec --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilIndexReference.cs.uid @@ -0,0 +1 @@ +uid://c7tu5fomgn8wd diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilLayerReference.cs b/Runtime/Shading/Generators/Spatial/Stencil/StencilLayerReference.cs new file mode 100644 index 0000000..609a38b --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilLayerReference.cs @@ -0,0 +1,20 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + + [Tool] + [GlobalClass] + public partial class StencilLayerReference:StencilReference + { + [Export] + public StencilLayer layer; + + public override int GetReferenceIndex() + { + return RenderingManager.GetStencilReferenceIndex( layer ); + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilLayerReference.cs.uid b/Runtime/Shading/Generators/Spatial/Stencil/StencilLayerReference.cs.uid new file mode 100644 index 0000000..f00e86a --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilLayerReference.cs.uid @@ -0,0 +1 @@ +uid://dbm74f662h3y6 diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilMode.cs b/Runtime/Shading/Generators/Spatial/Stencil/StencilMode.cs new file mode 100644 index 0000000..b3097b2 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilMode.cs @@ -0,0 +1,123 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + public enum StencilWriteMode + { + Write_Depth_Success, + Write_Depth_Fail, + Write_Always + } + + public enum StencilReadMode + { + Less, + Equal, + LessOrEqual, + Greater, + NotEqual, + GreaterOrEqual + } + + + public enum StencilMode + { + Read, + Write_Depth_Success, + Write_Depth_Fail, + Write_Always + } + + public static class StencilModeUtility + { + public static string ConvertToShaderCode( StencilMode mode ) + { + if ( StencilMode.Read == mode ) + { + return "read"; + } + + if ( StencilMode.Write_Depth_Success == mode ) + { + return "write"; + } + + if ( StencilMode.Write_Depth_Fail == mode ) + { + return "write_depth_fail"; + } + + return "write, write_depth_fail"; + } + + public static string ConvertToShaderCode( BaseMaterial3D.StencilCompareEnum compareMode ) + { + if ( BaseMaterial3D.StencilCompareEnum.Equal == compareMode ) + { + return "compare_equal"; + } + else if ( BaseMaterial3D.StencilCompareEnum.NotEqual == compareMode ) + { + return "compare_not_equal"; + } + + else if ( BaseMaterial3D.StencilCompareEnum.Greater == compareMode ) + { + return "compare_greater"; + } + else if ( BaseMaterial3D.StencilCompareEnum.GreaterOrEqual == compareMode ) + { + return "compare_greater_or_equal"; + } + + else if ( BaseMaterial3D.StencilCompareEnum.Less == compareMode ) + { + return "compare_less"; + } + else if ( BaseMaterial3D.StencilCompareEnum.LessOrEqual == compareMode ) + { + return "compare_less_or_equal"; + } + + return "compare_always"; + + } + + public static StencilMode ConvertWriteMode( StencilWriteMode writeMode ) + { + if ( writeMode == StencilWriteMode.Write_Depth_Success ) + { return StencilMode.Write_Depth_Success; } + + if ( writeMode == StencilWriteMode.Write_Depth_Fail ) + { return StencilMode.Write_Depth_Fail; } + + return StencilMode.Write_Always; + } + + public static BaseMaterial3D.StencilCompareEnum ConvertReadMode( StencilReadMode readMode ) + { + if ( readMode == StencilReadMode.NotEqual ) + { return BaseMaterial3D.StencilCompareEnum.NotEqual; } + + + if ( readMode == StencilReadMode.Less ) + { return BaseMaterial3D.StencilCompareEnum.Less; } + + if ( readMode == StencilReadMode.LessOrEqual ) + { return BaseMaterial3D.StencilCompareEnum.LessOrEqual; } + + + if ( readMode == StencilReadMode.Greater ) + { return BaseMaterial3D.StencilCompareEnum.Greater; } + + if ( readMode == StencilReadMode.GreaterOrEqual ) + { return BaseMaterial3D.StencilCompareEnum.GreaterOrEqual; } + + + return BaseMaterial3D.StencilCompareEnum.Equal; + } + } + +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilMode.cs.uid b/Runtime/Shading/Generators/Spatial/Stencil/StencilMode.cs.uid new file mode 100644 index 0000000..f4942be --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilMode.cs.uid @@ -0,0 +1 @@ +uid://pntpmqafirg1 diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilModule.cs b/Runtime/Shading/Generators/Spatial/Stencil/StencilModule.cs new file mode 100644 index 0000000..a50d4f3 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilModule.cs @@ -0,0 +1,29 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + + [Tool] + [GlobalClass] + public abstract partial class StencilModule:ShaderGenerationModule + { + public abstract StencilMode GetStencilMode(); + + public abstract BaseMaterial3D.StencilCompareEnum GetStencilCompare(); + + public abstract int GetStencilReference(); + + public string ToShaderCode() + { + var mode = StencilModeUtility.ConvertToShaderCode( GetStencilMode() ); + var compare = StencilModeUtility.ConvertToShaderCode( GetStencilCompare() ); + var reference = GetStencilReference(); + + return $"stencil_mode {mode}, {compare}, {reference};"; + } + + } + +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilModule.cs.uid b/Runtime/Shading/Generators/Spatial/Stencil/StencilModule.cs.uid new file mode 100644 index 0000000..9ca2e42 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilModule.cs.uid @@ -0,0 +1 @@ +uid://den5e7ft27385 diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilReadMask.cs b/Runtime/Shading/Generators/Spatial/Stencil/StencilReadMask.cs new file mode 100644 index 0000000..d3a7857 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilReadMask.cs @@ -0,0 +1,34 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + + [Tool] + [GlobalClass] + public partial class StencilReadMask:StencilModule + { + [Export] + public StencilReadMode readMode = StencilReadMode.NotEqual; + + [Export] + public StencilReference reference; + + public override StencilMode GetStencilMode() + { + return StencilMode.Read; + } + + public override BaseMaterial3D.StencilCompareEnum GetStencilCompare() + { + return StencilModeUtility.ConvertReadMode( readMode ); + } + + public override int GetStencilReference() + { + return reference == null ? -1 : reference.GetReferenceIndex(); + } + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilReadMask.cs.uid b/Runtime/Shading/Generators/Spatial/Stencil/StencilReadMask.cs.uid new file mode 100644 index 0000000..b69e41b --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilReadMask.cs.uid @@ -0,0 +1 @@ +uid://dajobmgr68xam diff --git a/Runtime/Shading/Generators/Spatial/Vertex/VertexModifier.cs b/Runtime/Shading/Generators/Spatial/Stencil/StencilReference.cs similarity index 54% rename from Runtime/Shading/Generators/Spatial/Vertex/VertexModifier.cs rename to Runtime/Shading/Generators/Spatial/Stencil/StencilReference.cs index 79c94f4..250064e 100644 --- a/Runtime/Shading/Generators/Spatial/Vertex/VertexModifier.cs +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilReference.cs @@ -4,10 +4,11 @@ using System.Collections.Generic; namespace Rokojori { + [Tool] [GlobalClass] - public partial class VertexModifier:ShaderGenerationModule + public abstract partial class StencilReference:Resource { - + public abstract int GetReferenceIndex(); } } \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilReference.cs.uid b/Runtime/Shading/Generators/Spatial/Stencil/StencilReference.cs.uid new file mode 100644 index 0000000..b593813 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilReference.cs.uid @@ -0,0 +1 @@ +uid://bsnoe0eyopto6 diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilWriteMask.cs b/Runtime/Shading/Generators/Spatial/Stencil/StencilWriteMask.cs new file mode 100644 index 0000000..efd8151 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilWriteMask.cs @@ -0,0 +1,34 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + + [Tool] + [GlobalClass] + public partial class StencilWriteMask:StencilModule + { + [Export] + public StencilWriteMode mode = StencilWriteMode.Write_Depth_Success; + + [Export] + public StencilReference reference; + + public override StencilMode GetStencilMode() + { + return StencilModeUtility.ConvertWriteMode( mode ); + } + + public override BaseMaterial3D.StencilCompareEnum GetStencilCompare() + { + return BaseMaterial3D.StencilCompareEnum.Always; + } + + public override int GetStencilReference() + { + return reference == null ? -1 : reference.GetReferenceIndex(); + } + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/Stencil/StencilWriteMask.cs.uid b/Runtime/Shading/Generators/Spatial/Stencil/StencilWriteMask.cs.uid new file mode 100644 index 0000000..f49cb33 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/Stencil/StencilWriteMask.cs.uid @@ -0,0 +1 @@ +uid://ddkem8ot7t13j diff --git a/Runtime/Shading/Generators/Spatial/SubsurfaceScattering/SubsurfaceScatteringModule.cs b/Runtime/Shading/Generators/Spatial/SubsurfaceScattering/SubsurfaceScatteringModule.cs new file mode 100644 index 0000000..8a2bb93 --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/SubsurfaceScattering/SubsurfaceScatteringModule.cs @@ -0,0 +1,110 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class SubsurfaceScatteringModule:TextureModule + { + public SubsurfaceScatteringModule() + { + _domainName = "subsurfaceScattering"; + _domainScaleName = "subsurfaceScattering"; + _domainValueName = "subsurfaceScattering"; + _target = "SSS_STRENGTH"; + _srgb = true; + _type = TextureChannelType.ONE; + _channelSource = TextureChannelSource.R; + } + + [Export] + public TextureFilter filter = TextureFilter.Linear_MipMap_Anisotropic; + + [Export] + public bool useScale = true; + + + + public enum TransmittanceMode + { + No_Transmittance, + Set_Transmittance, + Offset_Transmittance + } + + [Export] + public TransmittanceMode transmittanceMode = TransmittanceMode.Set_Transmittance; + + public bool useTransmittance => TransmittanceMode.No_Transmittance != transmittanceMode; + + [Export] + public bool skinMode = false; + + [Export] + public bool repeat = true; + + [Export] + public string uvChannel = "UV"; + + [Export] + public TextureDefault textureDefault = TextureDefault.White; + + + [Export] + public AssignmentType assignmentType = AssignmentType.Set; + + public override void GrabValues() + { + _domainMode = useScale ? DomainMode.Texture_Scale : DomainMode.Texture; + _textureFilter = filter; + _repeat = repeat; + _textureDefault = textureDefault; + _uvChannel = uvChannel; + _assignmentType = assignmentType; + + } + + static readonly string DepthUniform = "subsurfaceScatteringTransmittanceDepth"; + static readonly string BoostUniform = "subsurfaceScatteringTransmittanceBoost"; + + public override string AddVariables() + { + if ( ! useTransmittance ) + { + return ""; + } + + var depth = Uniform( DepthUniform, 0.1f, 0, 24 ); + var boost = Uniform( BoostUniform, 0, 0, 1 ); + + return "\n" + depth + "\n" + boost; + } + + public override List GetVariants( ShaderGenerationContext context ) + { + var variants = base.GetVariants( context ); + + if ( ! useTransmittance ) + { + return variants; + } + + if ( ShaderPhase.Fragment == context.phase ) + { + var op = TransmittanceMode.Set_Transmittance == transmittanceMode ? " = " : " += "; + + var color = ShaderCodeVariable.SSS_TRANSMITTANCE_COLOR.variableName + op + "vec4(1.0)" + ";"; + var depth = ShaderCodeVariable.SSS_TRANSMITTANCE_DEPTH.variableName + op + DepthUniform + ";"; + var boost = ShaderCodeVariable.SSS_TRANSMITTANCE_BOOST.variableName + op + BoostUniform + ";"; + + var code = "\n" + " " + color +"\n" + " " + depth + "\n" + " " + boost + "\n\n"; + return ShaderVariant.CombineVariants( variants, ToVariants( ToCode( code ) ) ); + + } + + return variants; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Generators/Spatial/SubsurfaceScattering/SubsurfaceScatteringModule.cs.uid b/Runtime/Shading/Generators/Spatial/SubsurfaceScattering/SubsurfaceScatteringModule.cs.uid new file mode 100644 index 0000000..805760a --- /dev/null +++ b/Runtime/Shading/Generators/Spatial/SubsurfaceScattering/SubsurfaceScatteringModule.cs.uid @@ -0,0 +1 @@ +uid://dfluv1ypy4ykh diff --git a/Runtime/Shading/Generators/Spatial/TextureModule.cs b/Runtime/Shading/Generators/Spatial/TextureModule.cs index 0cd3442..a87f8a8 100644 --- a/Runtime/Shading/Generators/Spatial/TextureModule.cs +++ b/Runtime/Shading/Generators/Spatial/TextureModule.cs @@ -6,13 +6,14 @@ namespace Rokojori { [Tool] [GlobalClass] - public partial class TextureModule:ShaderGenerationModule + public abstract partial class TextureModule:ShaderGenerationModule { public enum TextureChannelType { RGBA, RGB, - ONE + ONE, + SCALAR } public enum TextureChannelSource @@ -20,8 +21,7 @@ namespace Rokojori R, G, B, - A, - CUSTOMIZABLE + A } public TextureChannelType _type; @@ -33,8 +33,14 @@ namespace Rokojori public string _domainValueName; public string _domainScaleName; public string _domainOffsetName; + public string _domainIntensityName; + public string _target; + public string _scaleTarget; + + public string _uvChannel; public bool _srgb = false; + public bool _normal = false; public bool _repeat = true; public enum DomainMode @@ -42,18 +48,74 @@ namespace Rokojori Value, Texture, Texture_Scale, - Texture_Scale_Offset + Texture_Scale_Offset, + Texture_Scale_Intensity } - public DomainMode domainMode = DomainMode.Texture_Scale_Offset; + public DomainMode _domainMode = DomainMode.Texture_Scale_Offset; public float domainOffsetDefault = 0; public float domainOffsetMin = -1; public float domainOffsetMax = 1; + public float domainIntensityDefault = 1; + public float domainIntensityMin = 1; + public float domainIntensityMax = 20; + public float domainValueDefault = 0.5f; public float domainValueMin = 0; public float domainValueMax = 1; + public float domainScaleDefault = 1.0f; + public float domainScaleMin = 0; + public float domainScaleMax = 1; + + public bool _clamp = false; + + public enum AssignmentType + { + Set, + Add, + Subtract, + Multiply, + Divide + } + + public AssignmentType _assignmentType = AssignmentType.Set; + + public string assignmentOperator + { + get + { + + if ( AssignmentType.Add == _assignmentType ) + { + return " += "; + } + + if ( AssignmentType.Subtract == _assignmentType ) + { + return " -= "; + } + + if ( AssignmentType.Multiply == _assignmentType ) + { + return " *= "; + } + + if ( AssignmentType.Divide == _assignmentType ) + { + return " /= "; + } + + return " = "; + + } + } + + public TextureChannelType scaleType = TextureChannelType.SCALAR; + + public Color scaleColor = Colors.White; + public enum TextureDefault { White, @@ -79,10 +141,26 @@ namespace Rokojori } - public override List GetCode( ShaderGenerationContext context ) + public virtual string AddVariables() + { + return ""; + } + + public string GetSampledName() + { + return "sampled".ExtendVariableName( _domainName ); + + } + + public override List GetVariants( ShaderGenerationContext context ) { GrabValues(); + if ( _clamp && ShaderPhase.Includes == context.phase ) + { + return ToVariants( IncludeMathLibrary() ); + } + if ( ShaderPhase.Variables == context.phase ) { var textureName = _domainName; @@ -91,7 +169,7 @@ namespace Rokojori var samplerDefinition = ""; - if ( DomainMode.Value != domainMode ) + if ( DomainMode.Value != _domainMode ) { var hints = new List(); @@ -100,7 +178,16 @@ namespace Rokojori hints.Add( "source_color" ); } - hints.Add( TextureDefault.Black == _textureDefault ? "hint_default_black" : "hint_default_white" ); + if ( _normal ) + { + hints.Add( "hint_normal" ); + } + else + { + hints.Add( TextureDefault.Black == _textureDefault ? "hint_default_black" : "hint_default_white" ); + } + + hints.Add( _repeat ? "repeat_enable" : "repeat_disable" ); hints.Add( "filter_" + ( _textureFilter + "" ).ToLower() ); @@ -108,40 +195,140 @@ namespace Rokojori samplerDefinition = UniformSampler( textureSamplerName, hints.Join() ); - if ( domainMode != DomainMode.Texture ) + if ( _domainMode != DomainMode.Texture ) { if ( is1D ) { - valuesDefinition += Uniform01( _domainScaleName, 1.0f ); + valuesDefinition += Uniform( _domainScaleName, domainScaleDefault, domainScaleMin, domainScaleMax ); } else { - valuesDefinition += Uniform( _domainScaleName, Colors.White ); + if ( TextureChannelType.SCALAR == scaleType ) + { + valuesDefinition += Uniform( _domainScaleName, domainScaleDefault, domainScaleMin, domainScaleMax ); + } + else + { + valuesDefinition += Uniform( _domainScaleName, scaleColor ); + } + } valuesDefinition +="\n"; } } - if ( DomainMode.Value == domainMode ) + if ( DomainMode.Value == _domainMode ) { valuesDefinition += Uniform( _domainValueName, domainValueDefault, domainValueMin, domainValueMax ); } - else if ( DomainMode.Texture_Scale_Offset == domainMode ) + else if ( DomainMode.Texture_Scale_Offset == _domainMode ) { valuesDefinition += "\n"; valuesDefinition += Uniform( _domainOffsetName, domainOffsetDefault, domainOffsetMin, domainOffsetMax ); valuesDefinition += "\n"; } - - - - + else if ( DomainMode.Texture_Scale_Intensity == _domainMode ) + { + valuesDefinition += "\n"; + valuesDefinition += Uniform( _domainIntensityName, domainIntensityDefault, domainIntensityMin, domainIntensityMax ); + valuesDefinition += "\n"; + } var code = valuesDefinition + samplerDefinition; - return AsUniformGroup( textureName, code ); + code += AddVariables(); + return ToVariants( AsUniformGroup( textureName, code ) ); + + } + + if ( ShaderPhase.Fragment == context.phase ) + { + if ( DomainMode.Texture == _domainMode || + DomainMode.Texture_Scale == _domainMode || + DomainMode.Texture_Scale_Offset == _domainMode || + DomainMode.Texture_Scale_Intensity == _domainMode + ) + { + var textureSamplerName = _domainName + "Texture"; + var code = new List(); + var sampledName = GetSampledName(); + var sampled = "vec4 " + sampledName + " = texture( " + textureSamplerName + ", " + _uvChannel + " );"; + code.Add( sampled ); + + var member = ""; + + if ( TextureChannelType.RGB == _type ) + { + member = ".rgb"; + } + else if ( TextureChannelType.ONE== _type ) + { + member = TextureChannelSource.R == _channelSource ? ".r" : + TextureChannelSource.G == _channelSource ? ".g" : + TextureChannelSource.B == _channelSource ? ".b" : + ".a"; + } + + var scaleOffset = ""; + + var scaleMember = ""; + + if ( TextureChannelType.RGB == scaleType ) + { + scaleMember = ".rgb"; + } + else if ( TextureChannelType.ONE == scaleType ) + { + scaleMember = TextureChannelSource.R == _channelSource ? ".r" : + TextureChannelSource.G == _channelSource ? ".g" : + TextureChannelSource.B == _channelSource ? ".b" : + ".a"; + } + + // RJLog.Log( GetType().Name, "SCALE MEMBER", scaleMember, scaleType ); + + if ( DomainMode.Texture_Scale == _domainMode || + DomainMode.Texture_Scale_Offset == _domainMode || + DomainMode.Texture_Scale_Intensity == _domainMode + ) + { + scaleOffset += " * " + _domainScaleName + scaleMember; + + if ( DomainMode.Texture_Scale_Offset == _domainMode ) + { + scaleOffset += " + " + _domainOffsetName + scaleMember; + } + else if ( DomainMode.Texture_Scale_Intensity == _domainMode ) + { + scaleOffset += " * " + _domainIntensityName; + } + } + + + if ( DomainMode.Texture_Scale == _domainMode && _scaleTarget != "" && _scaleTarget != null ) + { + code.Add( _target + assignmentOperator + sampledName + member + ";" ); + code.Add( _scaleTarget + assignmentOperator + _domainScaleName + ";" ); + } + else + { + code.Add( _target + assignmentOperator + sampledName + member + scaleOffset + ";" ); + } + + if ( _clamp ) + { + code.Add( $"{_target} = clamp01( {_target} ); "); + } + + + return ToVariants( ToCode( code.Join( "\n" ).Indent( " " ).LineBreaks() ) ); + } + else + { + + } } return null; diff --git a/Runtime/Shading/Generators/Spatial/TransparencyModule.cs b/Runtime/Shading/Generators/Spatial/Transparency/TransparencyModule.cs similarity index 91% rename from Runtime/Shading/Generators/Spatial/TransparencyModule.cs rename to Runtime/Shading/Generators/Spatial/Transparency/TransparencyModule.cs index 4bdf012..fb2269a 100644 --- a/Runtime/Shading/Generators/Spatial/TransparencyModule.cs +++ b/Runtime/Shading/Generators/Spatial/Transparency/TransparencyModule.cs @@ -28,15 +28,15 @@ namespace Rokojori [Export] public bool noDepthTest = false; - public override List GetCode( ShaderGenerationContext context ) + public override List GetVariants( ShaderGenerationContext context ) { if ( ShaderPhase.Fragment == context.phase ) { if ( BaseMaterial3D.TransparencyEnum.AlphaScissor == transparency ) { - return Lists.From( (ShaderCode) new StringShaderCode( + return ToVariants( Lists.From( (ShaderCode) new StringShaderCode( "ALPHA_SCISSOR_THRESHOLD = " + RegexUtility.NumberToString( alphaScissorTreshold ) - ) ); + ) ) ); } return null; @@ -92,7 +92,7 @@ namespace Rokojori value = RegexUtility.Replace( value, @"\,\s*$", "" ); - return Lists.From( (ShaderCode) new StringShaderCode( value ) ); + return ToVariants( Lists.From( (ShaderCode) new StringShaderCode( value ) ) ); } diff --git a/Runtime/Shading/Generators/Spatial/TransparencyModule.cs.uid b/Runtime/Shading/Generators/Spatial/Transparency/TransparencyModule.cs.uid similarity index 100% rename from Runtime/Shading/Generators/Spatial/TransparencyModule.cs.uid rename to Runtime/Shading/Generators/Spatial/Transparency/TransparencyModule.cs.uid diff --git a/Runtime/Shading/Generators/Spatial/UV/UVModule.cs b/Runtime/Shading/Generators/Spatial/UV/UVModule.cs index a4e4bf7..cc71582 100644 --- a/Runtime/Shading/Generators/Spatial/UV/UVModule.cs +++ b/Runtime/Shading/Generators/Spatial/UV/UVModule.cs @@ -14,9 +14,9 @@ namespace Rokojori [Export] public UVModifier[] modifiers = []; - public override List GetCode( ShaderGenerationContext context ) + public override List GetVariants( ShaderGenerationContext context ) { - var list = new List(); + var list = new List(); var allModifiers = Lists.From( modifiers ).FilterNulls(); @@ -28,14 +28,14 @@ namespace Rokojori allModifiers.ForEach( ( m )=> { - var code = m.GetCode( context ); + var variants = m.GetVariants( context ); - if ( code == null ) + if ( variants == null ) { return; } - list.Add( code ); + list = ShaderVariant.CombineVariants( list, variants ); } ); diff --git a/Runtime/Shading/Generators/Spatial/UV/UVScaleOffset.cs b/Runtime/Shading/Generators/Spatial/UV/UVScaleOffset.cs index 0b84129..2d0868e 100644 --- a/Runtime/Shading/Generators/Spatial/UV/UVScaleOffset.cs +++ b/Runtime/Shading/Generators/Spatial/UV/UVScaleOffset.cs @@ -21,7 +21,7 @@ namespace Rokojori public string target = "UV"; - public override List GetCode( ShaderGenerationContext context ) + public override List GetVariants( ShaderGenerationContext context ) { if ( ShaderPhase.Variables == context.phase ) { @@ -36,13 +36,13 @@ namespace Rokojori ); - return AsUniformGroup( "UV", lines.Join( "" ) ); + return ToVariants( AsUniformGroup( "UV", lines.Join( "" ) ) ); } if ( ShaderPhase.Vertex == context.phase ) { - var expression = " " + target + " = " + target; + var expression = target + " = " + target; if ( uvScale != null ) { @@ -61,7 +61,7 @@ namespace Rokojori expression += ";"; - return ToCode( expression ); + return ToVariants( ToCode( expression ) ); } diff --git a/Runtime/Shading/Generators/Spatial/Vertex/VertexModifierModule.cs.uid b/Runtime/Shading/Generators/Spatial/Vertex/VertexModifierModule.cs.uid deleted file mode 100644 index f39ffeb..0000000 --- a/Runtime/Shading/Generators/Spatial/Vertex/VertexModifierModule.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://m63lib33qcs2 diff --git a/Runtime/Shading/Generators/Spatial/Vertex/VertexModule.cs b/Runtime/Shading/Generators/Spatial/Vertex/VertexModule.cs deleted file mode 100644 index 6800931..0000000 --- a/Runtime/Shading/Generators/Spatial/Vertex/VertexModule.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Godot; -using System.Reflection; -using System.Collections.Generic; - -namespace Rokojori -{ - [Tool] - [GlobalClass] - public partial class VertexModule:ShaderGenerationModule - { - [Export] - public VertexWind wind = new VertexWind(); - - - [Export] - public VertexModifier[] modifiers = []; - - public override List GetCode( ShaderGenerationContext context ) - { - var list = new List(); - - var allModifiers = Lists.From( modifiers ).FilterNulls(); - - if ( wind != null ) - { - allModifiers.Insert( 0, wind ); - } - - allModifiers.ForEach( - ( m )=> - { - var code = m.GetCode( context ); - - if ( code == null ) - { - return; - } - - list.Add( code ); - } - ); - - return list; - } - } -} \ No newline at end of file diff --git a/Runtime/Shading/Library/Cameras.gdshaderinc b/Runtime/Shading/Library/Cameras.gdshaderinc index ee34f5b..3dff451 100644 --- a/Runtime/Shading/Library/Cameras.gdshaderinc +++ b/Runtime/Shading/Library/Cameras.gdshaderinc @@ -27,3 +27,10 @@ float cameraDistanceAmount( vec3 localPosition, vec3 _CAMERA_POSITION_WORLD, mat float mapped = ( distance - close ) / ( far - close ); return clamp( mapped, 0, 1 ); } + + +float cameraDistanceFade( vec3 vertexViewPosition, float fadeOutDistance, float fadeInDistance ) +{ + float vertexDistance = length( vertexViewPosition ); + return clamp( smoothstep( fadeOutDistance, fadeInDistance, vertexDistance ), 0.0, 1.0 ); +} diff --git a/Runtime/Shading/Library/Colors.gdshaderinc b/Runtime/Shading/Library/Colors.gdshaderinc index 18c8932..f6f797c 100644 --- a/Runtime/Shading/Library/Colors.gdshaderinc +++ b/Runtime/Shading/Library/Colors.gdshaderinc @@ -113,6 +113,15 @@ float modPolarDegrees( float value ) return mod( value + 180.0, 360.0 ) - 180.0; } + +vec3 changeHueOfRGB( vec3 rgb, float hueChange ) +{ + vec3 hsl = RGBtoHSL( rgb ); + hsl.x = mod( hsl.x + hueChange, 1.0 ) ; + + return HSLtoRGB( hsl ); +} + float hue360ToYB( float hue ) { return modPolarDegrees( hue - 240.0 ); diff --git a/Runtime/Shading/Library/Depth.gdshaderinc b/Runtime/Shading/Library/Depth.gdshaderinc index ab7225f..8ec8afc 100644 --- a/Runtime/Shading/Library/Depth.gdshaderinc +++ b/Runtime/Shading/Library/Depth.gdshaderinc @@ -14,6 +14,12 @@ vec3 getDepthViewPositiontAtScreen( sampler2D _depthTexture, vec2 screenUV, mat4 return screenToView( screenUV, depthValue, _INV_PROJECTION_MATRIX ).xyz; } +float getDepthProximityAlpha( sampler2D _depthTexture, vec2 screenUV, mat4 _INV_PROJECTION_MATRIX, float vertexZ, float fadeDistance ) +{ + vec3 depthViewPosition = getDepthViewPositiontAtScreen( _depthTexture, screenUV, _INV_PROJECTION_MATRIX ); + return clamp( 1.0 - smoothstep( depthViewPosition.z + fadeDistance, depthViewPosition.z, vertexZ ), 0.0, 1.0); +} + vec3 getDepthViewPositionAtViewPosition( sampler2D _depthTexture, vec3 viewPosition, mat4 _PROJECTION_MATRIX, mat4 _INV_PROJECTION_MATRIX ) { vec2 screenPosition = viewToScreen( viewPosition, _PROJECTION_MATRIX ); diff --git a/Runtime/Shading/Library/Light.gdshaderinc b/Runtime/Shading/Library/Light.gdshaderinc index 98abcc9..6b98d4a 100644 --- a/Runtime/Shading/Library/Light.gdshaderinc +++ b/Runtime/Shading/Library/Light.gdshaderinc @@ -1,13 +1,23 @@ // #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Light.gdshaderinc" -float fresnel( vec3 normal, vec3 view, float amount ) +float fresnel( vec3 normal, vec3 view, float powerAmount ) { - return pow( ( 1.0 - clamp( dot( normalize( normal ), normalize( view ) ), 0.0, 1.0 ) ), amount ); + return pow( ( 1.0 - clamp( dot( normalize( normal ), normalize( view ) ), 0.0, 1.0 ) ), powerAmount ); } -float fresnelNormalized( vec3 normal, vec3 view, float amount ) +float fresnelNormalized( vec3 normal, vec3 view, float powerAmount ) { - return pow( ( 1.0 - clamp( dot( normal, view ), 0.0, 1.0 ) ), amount); + return pow( ( 1.0 - clamp( dot( normal, view ), 0.0, 1.0 ) ), powerAmount); +} + +float fresnelNormalizedFromView( vec3 viewNormal, float powerAmount ) +{ + return pow( 1.0 - max( viewNormal.z, 0.0 ), powerAmount ); +} + +float fresnelNormalizedFromViewAdvanced( vec3 viewNormal, float zOffset, float powerAmount, float postScale, float postOffset ) +{ + return pow( 1.0 - clamp( viewNormal.z + zOffset, 0.0, 1.0 ), powerAmount ) * postScale + postOffset; } diff --git a/Runtime/Shading/Library/Math.gdshaderinc b/Runtime/Shading/Library/Math.gdshaderinc index 48bba43..74c1f08 100644 --- a/Runtime/Shading/Library/Math.gdshaderinc +++ b/Runtime/Shading/Library/Math.gdshaderinc @@ -17,6 +17,21 @@ vec4 clamp01_v4( vec4 value ) return value; } +vec2 clamp01( vec2 value ) +{ + return clamp( value, 0.0, 1.0 ); +} + +vec3 clamp01( vec3 value ) +{ + return clamp( value, 0.0, 1.0 ); +} + +vec4 clamp01( vec4 value ) +{ + return clamp( value, 0.0, 1.0 ); +} + float normalizeToRange( float value, float min, float max ) { return ( value - min ) / ( max - min ); @@ -74,7 +89,12 @@ float angleDelta( float degreesA, float degreesB ) return angleDelta; } - float snapRounded( float value, float snappingDistance ) +float snapRounded( float value, float snappingDistance ) +{ + return round( value / snappingDistance ) * snappingDistance; +} + +vec3 snapRounded( vec3 value, float snappingDistance ) { return round( value / snappingDistance ) * snappingDistance; } diff --git a/Runtime/Shading/Library/Noise.gdshaderinc b/Runtime/Shading/Library/Noise.gdshaderinc index ed203b3..8e074ce 100644 --- a/Runtime/Shading/Library/Noise.gdshaderinc +++ b/Runtime/Shading/Library/Noise.gdshaderinc @@ -224,3 +224,8 @@ vec2 voronoi( vec2 uv, float columns, float rows ) return minimum_point; } +bool ditherDiscard( float ditherFadeValue, vec4 _FRAGCOORD ) +{ + vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 ); + return ditherFadeValue < 0.001 || ditherFadeValue < fract( magic.z * fract( dot( _FRAGCOORD.xy, magic.xy ) ) ); +} diff --git a/Runtime/Shading/Library/Normals.gdshaderinc b/Runtime/Shading/Library/Normals.gdshaderinc index 3f32ff0..4be9b86 100644 --- a/Runtime/Shading/Library/Normals.gdshaderinc +++ b/Runtime/Shading/Library/Normals.gdshaderinc @@ -1,5 +1,15 @@ // #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Normals.gdshaderinc" +vec3 computeNormalFromHeightMap( sampler2D _heightMap, vec2 _uv, float size, float strength ) +{ + float l = texture( _heightMap, _uv + vec2( -size, 0 ) ).r * strength; + float r = texture( _heightMap, _uv + vec2( size, 0 ) ).r * strength; + float d = texture( _heightMap, _uv + vec2( 0, -size ) ).r * strength; + float u = texture( _heightMap, _uv + vec2( 0, size ) ).r * strength; + + return normalize( vec3( l - r, 2.0 * size, d - u ) ); +} + vec3 scaleNormalMap( vec3 normal, float scale ) { normal -= vec3( 0.5 ); diff --git a/Runtime/Shading/Library/SDF.gdshaderinc b/Runtime/Shading/Library/SDF.gdshaderinc index 9246b57..02be197 100644 --- a/Runtime/Shading/Library/SDF.gdshaderinc +++ b/Runtime/Shading/Library/SDF.gdshaderinc @@ -68,7 +68,9 @@ https://iquilezles.org/articles/distfunctions2d/ */ - +float dot2( in vec2 v ) { return dot(v,v); } +float dot2( in vec3 v ) { return dot(v,v); } +float ndot( in vec2 a, in vec2 b ) { return a.x * b.x - a.y * b.y; } float sdCircle( vec2 p, float r ) @@ -106,4 +108,48 @@ float sdBox( in vec2 p, in vec2 b ) { vec2 d = abs(p)-b; return length(max(d,0.0)) + min(max(d.x,d.y),0.0); +} + + +/* + +TAKEN FROM +[ Inigo Quilez ] + +https://iquilezles.org/articles/distfunctions/ + +*/ + + + +float sdRoundCone( vec3 p, vec3 a, vec3 b, float r1, float r2 ) +{ + vec3 ba = b - a; + float l2 = dot( ba, ba ); + float rr = r1 - r2; + float a2 = l2 - rr * rr; + float il2 = 1.0 / l2; + + vec3 pa = p - a; + float y = dot( pa, ba ); + float z = y - l2; + float x2 = dot2( pa * l2 - ba * y ); + float y2 = y * y * l2; + float z2 = z * z * l2; + + // single square root! + float k = sign( rr ) * rr * rr * x2; + + if( sign( z ) * a2 * z2 > k ) + { + return sqrt( x2 + z2 ) * il2 - r2; + } + + + if( sign( y ) * a2 * y2 < k ) + { + return sqrt( x2 + y2 ) * il2 - r1; + } + + return ( sqrt( x2 * a2 * il2 ) + y * rr ) * il2 - r1; } \ No newline at end of file diff --git a/Runtime/Shading/Library/Terrain.gdshaderinc b/Runtime/Shading/Library/Terrain.gdshaderinc new file mode 100644 index 0000000..cf765c5 --- /dev/null +++ b/Runtime/Shading/Library/Terrain.gdshaderinc @@ -0,0 +1,42 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Wind.gdshaderinc" + + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc" +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc" + + +/* +uniform sampler2D terrainHeightMap; +uniform vec2 terrainCenterXZ = vec2( 0.0, 0.0 ); +uniform vec2 terrainSizeXZ = vec2( 100.0, 100.0 ); +uniform float terrainMinHeight = 0.0; +uniform float terrainMaxHeight = 100.0; + +uniform sampler2D terrainNormalMap; +*/ + +void addTerrainOffset( + mat4 _MODEL_MATRIX, + inout vec3 _VERTEX, + + sampler2D terrainHeightMap, + vec2 terrainCenterXZ, + vec2 terrainSizeXZ, + float terrainMinHeight, + float terrainMaxHeight + +) +{ + vec3 worldVertex = localToWorld( _VERTEX, _MODEL_MATRIX ); + + vec2 mapOffset = terrainCenterXZ - terrainSizeXZ/2.0; + + vec2 uv = ( worldVertex.xz - mapOffset ) / terrainSizeXZ; + + float height = mix( terrainMinHeight, terrainMaxHeight, texture( terrainHeightMap, uv ).r ); + + worldVertex.y += height; + + _VERTEX = worldToLocal( worldVertex, _MODEL_MATRIX ); + +} \ No newline at end of file diff --git a/Runtime/Shading/Library/Terrain.gdshaderinc.uid b/Runtime/Shading/Library/Terrain.gdshaderinc.uid new file mode 100644 index 0000000..6b74492 --- /dev/null +++ b/Runtime/Shading/Library/Terrain.gdshaderinc.uid @@ -0,0 +1 @@ +uid://ct3onbuwr7w3d diff --git a/Runtime/Shading/Library/Transform.gdshaderinc b/Runtime/Shading/Library/Transform.gdshaderinc index 95555fa..ffdfdae 100644 --- a/Runtime/Shading/Library/Transform.gdshaderinc +++ b/Runtime/Shading/Library/Transform.gdshaderinc @@ -595,4 +595,53 @@ vec2 worldUVfromLocalXZ( vec3 localVertex, vec2 centerXZ, vec2 sizeXZ, mat4 _MOD vec3 worldVertex = localToWorld( localVertex, _MODEL_MATRIX ); return worldUVfromWorldXZ( worldVertex, centerXZ, sizeXZ ); +} + +mat3 createFromToRotation( vec3 from, vec3 to ) +{ + + from = normalize( from ); + to = normalize( to ); + + float cosTheta = dot( from, to ); + +// if ( cosTheta < -0.9999 ) +// { +// // 180° rotation: pick arbitrary perpendicular axis +// vec3 axis = normalize( cross( vec3( 1.0, 0.0, 0.0 ), from ) ); + +// if ( length( axis ) < 0.01 ) +// { +// axis = normalize( cross( vec3(0.0, 1.0, 0.0), from ) ); +// } + +// return mat3( +// -1.0 + 2.0*axis.x*axis.x, 2.0*axis.x*axis.y, 2.0*axis.x*axis.z, +// 2.0*axis.x*axis.y, -1.0 + 2.0*axis.y*axis.y, 2.0*axis.y*axis.z, +// 2.0*axis.x*axis.z, 2.0*axis.y*axis.z, -1.0 + 2.0*axis.z*axis.z +// ); +// } + +// vec3 axis = normalize( cross(from, to) ); +// float s = sqrt( (1 .0 + cosTheta ) * 2.0 ); +// float invs = 1.0 / s; + +// mat3 rot = mat3( +// 1.0 + (axis.x * axis.x * (1.0 - s*invs)), +// axis.x * axis.y * (1.0 - s*invs) - axis.z * s*0.5*invs, +// axis.x * axis.z * (1.0 - s*invs) + axis.y * s*0.5*invs, + +// axis.y * axis.x * (1.0 - s*invs) + axis.z * s*0.5*invs, +// 1.0 + (axis.y * axis.y * (1.0 - s*invs)), +// axis.y * axis.z * (1.0 - s*invs) - axis.x * s*0.5*invs, + +// axis.z * axis.x * (1.0 - s*invs) - axis.y * s*0.5*invs, +// axis.z * axis.y * (1.0 - s*invs) + axis.x * s*0.5*invs, +// 1.0 + (axis.z * axis.z * (1.0 - s*invs)) +// ); + +// return rot; + + return mat3( 1.0 ); + } \ No newline at end of file diff --git a/Runtime/Shading/Library/Wind.gdshaderinc b/Runtime/Shading/Library/Wind.gdshaderinc index 3410302..7baacab 100644 --- a/Runtime/Shading/Library/Wind.gdshaderinc +++ b/Runtime/Shading/Library/Wind.gdshaderinc @@ -25,7 +25,7 @@ applyWind( MODEL_MATRIX, VERTEX, NORMAL, - windAO, + vertexWindAO, windOcclusionAmount, windStrength, windSpeed, @@ -46,7 +46,7 @@ void applyWind( mat4 _MODEL_MATRIX, inout vec3 _VERTEX, inout vec3 _NORMAL, - inout float _windAO, + inout float _vertexWindAO, float _windOcclusionAmount, float _windStrength, vec2 _windSpeed, @@ -75,5 +75,5 @@ void applyWind( float minY = min( _VERTEX.y, 0 ); _VERTEX.y = mix( _VERTEX.y, max( minY, _VERTEX.y - strength * _windAmount), _windHeightCompensation * 4.0f ); _NORMAL = normalize( mix( _NORMAL, vec3( circle.x, -1, circle.y ), generalStrength * _windNormalBending ) ); - _windAO = mix( 1, 0, generalStrength * _windOcclusionAmount); + _vertexWindAO = mix( 1, 0, generalStrength * _windOcclusionAmount); } \ No newline at end of file diff --git a/Runtime/Shading/Properties/Properties/SetVector3PropertyFromNode.cs b/Runtime/Shading/Properties/Properties/SetVector3PropertyFromNode.cs new file mode 100644 index 0000000..6707695 --- /dev/null +++ b/Runtime/Shading/Properties/Properties/SetVector3PropertyFromNode.cs @@ -0,0 +1,31 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class SetVector3PropertyFromNode:Action + { + [Export] + public Node3D node3D; + + [Export] + public bool global; + + [Export] + public Vector3PropertyName name; + + [Export] + public Material material; + + + protected override void _OnTrigger() + { + name.Set( material, node3D.GetPosition( global ) ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Shading/Properties/Properties/SetVector3PropertyFromNode.cs.uid b/Runtime/Shading/Properties/Properties/SetVector3PropertyFromNode.cs.uid new file mode 100644 index 0000000..59c1f73 --- /dev/null +++ b/Runtime/Shading/Properties/Properties/SetVector3PropertyFromNode.cs.uid @@ -0,0 +1 @@ +uid://xb4x2w5atnxp diff --git a/Runtime/Shading/Properties/Properties/Vector3Property.cs b/Runtime/Shading/Properties/Properties/Vector3Property.cs new file mode 100644 index 0000000..10b8a88 --- /dev/null +++ b/Runtime/Shading/Properties/Properties/Vector3Property.cs @@ -0,0 +1,43 @@ +using Godot; +using System.Reflection; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class Vector3Property : ShaderProperty + { + [Export] + public Vector3PropertyName propertyName; + + public string name => propertyName.propertyName; + + [Export] + public Vector3 value; + + public override void Apply( Material material ) + { + propertyName.Set( material, value ); + } + + public void ReadFrom( Material material ) + { + value = propertyName.Get( material ); + } + + public void ApplyLerped( Material material, Vector3 from, float lerpState ) + { + var lerpedValue = Math3D.Lerp( from, value, lerpState ); + propertyName.Set( material, lerpedValue ); + } + + public static Vector3Property Create( string name, Vector3 value ) + { + var fp = new Vector3Property(); + fp.propertyName = Vector3PropertyName.Create( name ); + fp.value = value; + return fp; + } + } +} \ No newline at end of file diff --git a/Runtime/Shading/Properties/Properties/Vector3Property.cs.uid b/Runtime/Shading/Properties/Properties/Vector3Property.cs.uid new file mode 100644 index 0000000..6ad66f7 --- /dev/null +++ b/Runtime/Shading/Properties/Properties/Vector3Property.cs.uid @@ -0,0 +1 @@ +uid://bhq3wuoierkuq diff --git a/Runtime/Text/JSON/Serializers/JSONSerializer.cs b/Runtime/Text/JSON/Serializers/JSONSerializer.cs index 664f064..4ea304b 100644 --- a/Runtime/Text/JSON/Serializers/JSONSerializer.cs +++ b/Runtime/Text/JSON/Serializers/JSONSerializer.cs @@ -64,6 +64,10 @@ namespace Rokojori else if ( ReflectionHelper.IsList( value ) ) { return JSON.Stringify( CreateArray( value as IList ) ); + } + else if ( value is Array ) + { + return JSON.Stringify( CreateArray( value as Array ) ); } else if ( IsSerializableDictionary( value ) ) { @@ -285,6 +289,8 @@ namespace Rokojori var fields = type.GetFields(); var jsonObject = new JSONObject(); + jsonObject.Set( "__class__", type.FullName ); + foreach ( var f in fields ) { if ( f.IsStatic ) @@ -337,6 +343,10 @@ namespace Rokojori } } + else if ( value is Array ) + { + jsonObject.Set( name, CreateArray( value as Array ) ); + } else if ( ReflectionHelper.IsList( value ) ) { jsonObject.Set( name, CreateArray( value as IList ) ); diff --git a/Runtime/Text/Lexing/LexerEvent.cs b/Runtime/Text/Lexing/LexerEvent.cs index ff9c773..252292b 100644 --- a/Runtime/Text/Lexing/LexerEvent.cs +++ b/Runtime/Text/Lexing/LexerEvent.cs @@ -119,6 +119,12 @@ namespace Rokojori return match == this.match; } + public string GetLineInfo( string source ) + { + return TextLinesMapper.GetLineInfo( source, this ); + } + + public bool MatchIsAny( params string[] matches ) { for ( int i = 0; i < matches.Length; i++ ) @@ -227,7 +233,7 @@ namespace Rokojori return match.ToString(); } - public static int Find( List tokens, int offset, params string[] types ) + public static int FindType( List tokens, int offset, params string[] types ) { for ( int i = offset; i < tokens.Count; i++ ) { diff --git a/Runtime/Text/Lexing/LexerMatcherLibrary.cs b/Runtime/Text/Lexing/LexerMatcherLibrary.cs index 67258e9..1a8686f 100644 --- a/Runtime/Text/Lexing/LexerMatcherLibrary.cs +++ b/Runtime/Text/Lexing/LexerMatcherLibrary.cs @@ -58,7 +58,7 @@ namespace Rokojori new LexerMatcher( "Logic", "if|else|switch|do|while|for|break|continue|return" ); public static readonly LexerMatcher OperatorMatcher = - new LexerMatcher( "Operator", "(?:\\=\\=)|(?:\\+\\+)|(?:\\-\\-)|\\+|\\-|\\*|\\/|\\^|\\||\\~|\\&|\\%|\\<|\\>|\\=|\\!|\\.|\\:|\\,|\\;" ); + new LexerMatcher( "Operator", "(?:\\=\\=)|(?:\\+\\+)|(?:\\-\\-)|(?:\\+\\=)|(?:\\*\\=)|(?:\\-\\=)|(?:\\/\\=)|\\+|\\-|\\*|\\/|\\^|\\||\\~|\\&|\\%|\\<|\\>|\\=|\\!|\\.|\\:|\\,|\\;" ); public static readonly LexerMatcher BracketMatcher = new LexerMatcher( "Bracket", @"\(|\)|\[|\]|\{|\}" ); @@ -106,6 +106,10 @@ namespace Rokojori new LexerMatcher( "URL", @"https?\:\/\/(\w|\.|\-|\?|\=|\+|\/)+" ); + public static readonly LexerMatcher[] Ignore = [ + WhiteSpaceMatcher, BreakMatcher, SingleLineCommentMatcher, MultiLineCommentMatcher + ]; + } diff --git a/Runtime/Text/RegexUtility.cs b/Runtime/Text/RegexUtility.cs index 2ff4b06..94fdeb2 100644 --- a/Runtime/Text/RegexUtility.cs +++ b/Runtime/Text/RegexUtility.cs @@ -110,6 +110,16 @@ namespace Rokojori return new Regex( source, regex.Options ); } + public static string LineBreak( this string value ) + { + return value + "\n"; + } + + public static string LineBreaks( this string value ) + { + return value + "\n\n"; + } + public static string Indent( this string value, string indentation = " ", bool indentFirstLine = true ) { var lines = SplitLines( value ); diff --git a/Runtime/Text/Text.cs b/Runtime/Text/Text.cs index ddfbf26..b5c071c 100644 --- a/Runtime/Text/Text.cs +++ b/Runtime/Text/Text.cs @@ -8,6 +8,36 @@ namespace Rokojori { public static class Text { + public static string GetInnerMatch( this string text, string start, string ending, int offset = 0) + { + var startIndex = text.IndexOf( start, offset ); + + if ( startIndex == -1 ) + { + return null; + } + + var startOffset = startIndex + start.Length; + + var endingIndex = text.IndexOf( ending, startOffset ); + + if ( endingIndex == -1 ) + { + return null; + } + + return text.Substring( startIndex, ( endingIndex ) - startIndex ); + } + + public static string CapitalizeVariable( this string name ) + { + return ( name[ 0 ] + "" ).ToUpper() + name.Substring( 1 ); + } + + public static string ExtendVariableName( this string before, string next ) + { + return before + next.CapitalizeVariable(); + } public static string MapCharacterToName( this char c ) { diff --git a/Runtime/Text/TextLinesMapper.cs b/Runtime/Text/TextLinesMapper.cs index 823972b..f9b0a43 100644 --- a/Runtime/Text/TextLinesMapper.cs +++ b/Runtime/Text/TextLinesMapper.cs @@ -106,6 +106,21 @@ namespace Rokojori return "@chars(" + startCharacterIndex + "," + endCharacterIndex + ")"; } + + public static string GetLineInfo( string source, int startCharacterIndex, int endCharacterIndex = -1 ) + { + endCharacterIndex = endCharacterIndex == -1 ? startCharacterIndex : endCharacterIndex; + + var linesMapper = new TextLinesMapper(); + linesMapper.Map( source ); + + return linesMapper.GetTextEditorSnippet( source, startCharacterIndex, endCharacterIndex ); + } + + public static string GetLineInfo( string source, LexerEvent le ) + { + return GetLineInfo( source, le.offset ); + } public string GetTextEditorSnippet( string source, int startCharacterIndex, int endCharacterIndex ) { @@ -120,7 +135,7 @@ namespace Rokojori var snippet = new StringBuilder(); var lengthMaxLineNumberIndex = ( _lines[ endLine ].textEditorLineIndex + "" ).Length; - for ( var i = startLine; i < endLine; i++ ) + for ( var i = startLine; i <= endLine; i++ ) { var line = _lines[ i ]; var lineNumber = _lines[ i ].textEditorLineIndex + ""; diff --git a/Runtime/Tools/Lists.cs b/Runtime/Tools/Lists.cs index 3bfadd9..990f7d9 100644 --- a/Runtime/Tools/Lists.cs +++ b/Runtime/Tools/Lists.cs @@ -4,6 +4,7 @@ using System.Text; using System; using Godot; using System.Threading.Tasks; +using System.Linq; namespace Rokojori { @@ -119,6 +120,68 @@ namespace Rokojori return cloned; } + public static List TopologicalSort( this List items, Func compare ) + { + var result = new List(); + var incomingEdges = new Dictionary(); + var edges = new Dictionary>(); + + foreach ( var item in items ) + { + incomingEdges[ item ] = 0; + edges[ item ] = new List(); + } + + var count = items.Count; + + for ( int i = 0; i < count; i++ ) + { + for ( int j = i + 1; j < count; j++ ) + { + var a = items[ i]; + var b = items[ j ]; + var cmp = compare( a, b ); + + if ( cmp < 0 ) + { + edges[ a ].Add( b ); + incomingEdges[ b ]++; + } + else if ( cmp > 0 ) + { + edges[b].Add( a ); + incomingEdges[ a ]++; + } + } + } + + var queue = new Queue( incomingEdges.Where( pair => pair.Value == 0 ).Select( pair => pair.Key ) ); + + while ( queue.Any() ) + { + var current = queue.Dequeue(); + result.Add( current ); + + foreach ( var next in edges[ current ] ) + { + incomingEdges[ next ]--; + + if ( incomingEdges[ next ] == 0 ) + { + queue.Enqueue( next ); + } + } + } + + if ( result.Count != items.Count ) + { + return null; + } + + return result; + } + + public static IndexLerpResult LerpIndex( List data, float value, Func getValue, bool sort = false ) { if ( sort ) @@ -351,6 +414,31 @@ namespace Rokojori return ToList( elements ); } + public static List From( params List[] elements ) + { + var list = new List(); + + elements.ForEach( e => list.AddRange( e ) ); + + return list; + } + + public static int MultiFindIndex( this List values, params Predicate[] finder ) + { + for ( int i = 0; i < finder.Length; i++ ) + { + var index = values.FindIndex( 0, finder[ i ] ); + + if ( index != -1 ) + { + return index; + } + } + + + return -1; + } + public static List SubList( T[] elements, int offset, int length ) { var list = new List(); @@ -619,6 +707,7 @@ namespace Rokojori }*/ + public static string Join( this List array, string seperator = ", " ) { var sb = new StringBuilder(); @@ -670,6 +759,21 @@ namespace Rokojori return copy; } + public static List Combine( List a, List b, Func combiner ) + { + var list = new List(); + + for ( int i = 0; i < a.Count; i++ ) + { + for ( int j = 0; j < b.Count; j++ ) + { + list.Add( combiner( a[ i ], b[ j ] ) ); + } + } + + return list; + } + public static bool Has( this List list, Func evaluater ) { foreach ( var t in list ) @@ -821,6 +925,26 @@ namespace Rokojori return list; } + public static List FilterType( this List inputList, Type type ) + { + var list = new List(); + + inputList.ForEach + ( + e => + { + if ( e == null || ! type.IsAssignableFrom( e.GetType() ) ) + { + return; + } + + list.Add( e ); + } + ); + + return list; + } + public static void Add( this List list, params T[] entries ) { list.AddRange( entries ); @@ -829,7 +953,12 @@ namespace Rokojori public static List Concat( this List list, params T[] entries ) { list.AddRange( entries ); + return list; + } + public static List Concat( this List list, List entries ) + { + list.AddRange( entries ); return list; } @@ -888,6 +1017,25 @@ namespace Rokojori return Map( list, mapper, new List() ); } + public static Dictionary CreateIndex( this List list ) + { + var m = new Dictionary(); + + for ( int i = 0; i < list.Count; i++ ) + { + m[ list[ i ] ] = i; + } + + return m; + } + + public static HashSet CreateSet( this List list ) + { + var set = new HashSet(); + list.ForEach( e => set.Add( e ) ); + return set; + } + public static List Map( List inputList, Func mapper, List list = null ) { if ( list == null ) diff --git a/Runtime/Tools/ReflectionHelper.cs b/Runtime/Tools/ReflectionHelper.cs index 4bfcb3e..4a77807 100644 --- a/Runtime/Tools/ReflectionHelper.cs +++ b/Runtime/Tools/ReflectionHelper.cs @@ -9,6 +9,36 @@ namespace Rokojori { public static class ReflectionHelper { + public static List> GetExportedMembersAsJSON( object obj ) + { + var type = obj.GetType(); + var results = new List>(); + + foreach ( var field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) ) + { + if ( Attribute.IsDefined( field, typeof(ExportAttribute) ) ) + { + var value = field.GetValue( obj ); + var json = JSON.StringifyObject( value ); + var tuple = new Tuple( field.Name, json ); + results.Add( tuple ); + } + } + + foreach ( var prop in type.GetProperties( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ) ) + { + if ( Attribute.IsDefined( prop, typeof(ExportAttribute) ) && prop.CanRead ) + { + var value = prop.GetValue( obj ); + var json = JSON.StringifyObject( value ); + var tuple = new Tuple( prop.Name, json ); + results.Add( tuple ); + } + } + + return results; + } + public static T Create( Type type, params object[] args ) { Type[] argTypes = Array.ConvertAll( args, arg => arg.GetType() ); diff --git a/Runtime/UI/UI-Settings-Default.tres b/Runtime/UI/UI-Settings-Default.tres index bf70d92..1052cbc 100644 --- a/Runtime/UI/UI-Settings-Default.tres +++ b/Runtime/UI/UI-Settings-Default.tres @@ -12,9 +12,6 @@ script = ExtResource("3_xon8j") value = 1.0 unit = "vw" -isAnimated = false -animationDuration = 0.0 -animationOffset = 0.0 metadata/_custom_type_script = "uid://cnkyynboxg1qg" [sub_resource type="Resource" id="Resource_6vky0"]