diff --git a/Icons/RenderingManager.svg b/Icons/RenderingManager.svg
new file mode 100644
index 0000000..a264e18
--- /dev/null
+++ b/Icons/RenderingManager.svg
@@ -0,0 +1,197 @@
+
+
diff --git a/Icons/RenderingManager.svg.import b/Icons/RenderingManager.svg.import
new file mode 100644
index 0000000..e71df4f
--- /dev/null
+++ b/Icons/RenderingManager.svg.import
@@ -0,0 +1,43 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://yy73os4iqhw"
+path="res://.godot/imported/RenderingManager.svg-f5be4225af141f3c0e92c0529a74c481.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://addons/rokojori_action_library/Icons/RenderingManager.svg"
+dest_files=["res://.godot/imported/RenderingManager.svg-f5be4225af141f3c0e92c0529a74c481.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/uastc_level=0
+compress/rdo_quality_loss=0.0
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/channel_remap/red=0
+process/channel_remap/green=1
+process/channel_remap/blue=2
+process/channel_remap/alpha=3
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
+svg/scale=1.0
+editor/scale_with_editor_scale=false
+editor/convert_colors_with_editor_theme=false
diff --git a/Runtime/Math/Math3D.cs b/Runtime/Math/Math3D.cs
index a48d6bc..4d36cbe 100644
--- a/Runtime/Math/Math3D.cs
+++ b/Runtime/Math/Math3D.cs
@@ -570,6 +570,12 @@ namespace Rokojori
return a.Lerp( b, lerp );
}
+ // public static Vector4 Lerp( Vector4 a, Vector4 b, float lerp )
+ // {
+ // return a.Lerp( b, lerp );
+ // }
+
+
public static Vector3 LerpGlobalPosition( Node3D a, Node3D b, float lerp )
{
return a.GlobalPosition.Lerp( b.GlobalPosition, lerp );
diff --git a/Runtime/Rendering/Assets/Foliage/FoliageRenderer.cs b/Runtime/Rendering/Assets/Foliage/FoliageRenderer.cs
index d6bb14d..bf185c7 100644
--- a/Runtime/Rendering/Assets/Foliage/FoliageRenderer.cs
+++ b/Runtime/Rendering/Assets/Foliage/FoliageRenderer.cs
@@ -77,6 +77,9 @@ namespace Rokojori
[Export]
public float maxHeight = 100;
+ [Export]
+ public float snapDistance = 50;
+
[Export]
public Texture2D normalMap;
diff --git a/Runtime/Rendering/Assets/Foliage/GPUFoliageShader.gdshader b/Runtime/Rendering/Assets/Foliage/GPUFoliageShader.gdshader
index c784301..b20487f 100644
--- a/Runtime/Rendering/Assets/Foliage/GPUFoliageShader.gdshader
+++ b/Runtime/Rendering/Assets/Foliage/GPUFoliageShader.gdshader
@@ -41,12 +41,15 @@ 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 float discardTreshold = 0.01;
+uniform float discardOffset = 1000000;
+
uniform sampler2D coverageMap;
uniform sampler2D colorMap;
uniform vec2 mapSize = vec2(1024,1024);
@@ -108,9 +111,15 @@ void process()
occ = min( occ, 1.0 - sampledCoverage );
sca *= mix( 1.0, occupancyHideScale , occ * occupancyAmount );
- position3D.y += occ * occupancyAmount * occupancyHideOffset;
+
+ float combinedOcc = occ * occupancyAmount; ;
+ position3D.y += combinedOcc * occupancyHideOffset;
position3D.y += mix( minHeight, maxHeight, sampledHeight );
+ if ( combinedOcc >= ( 1.0 - clamp01( discardTreshold ) ) )
+ {
+ position3D.y += discardOffset;
+ }
TRANSFORM = TRS( position3D, rot, vec3( sca.x , sca.y, sca.z ) );
}
diff --git a/Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader b/Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader
index abe70d8..daa759f 100644
--- a/Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader
+++ b/Runtime/Rendering/Assets/Terrain/TriplanerHeightMapTerrain.gdshader
@@ -10,7 +10,6 @@ render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_sc
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;
@@ -29,8 +28,6 @@ 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);
@@ -98,7 +95,7 @@ void fragment()
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;
+ ROUGHNESS = clamp(roughness_tex * roughness,0,1);
vec3 worldNormal = computeNormalFromHeightMap( heightMap, heightUV, normalTexelSize, normalHeightSize );
NORMAL = worldToViewDirection( worldNormal, VIEW_MATRIX );
diff --git a/Runtime/Rendering/Compositor/SingleShaderCompositorEffect.cs b/Runtime/Rendering/Compositor/SingleShaderCompositorEffect.cs
index 29fe5da..67d728c 100644
--- a/Runtime/Rendering/Compositor/SingleShaderCompositorEffect.cs
+++ b/Runtime/Rendering/Compositor/SingleShaderCompositorEffect.cs
@@ -40,7 +40,7 @@ namespace Rokojori
return;
}
- _pipeline = RDPipeline.Create( context, _shader );
+ _pipeline = RDPipeline.CreateRender( context, _shader );
if ( _shader == null )
{
diff --git a/Runtime/Rendering/Context/RDContext.cs b/Runtime/Rendering/Context/RDContext.cs
index 49919bf..be9ad01 100644
--- a/Runtime/Rendering/Context/RDContext.cs
+++ b/Runtime/Rendering/Context/RDContext.cs
@@ -90,7 +90,7 @@ namespace Rokojori
public void SetProgramFromPath( string path )
{
Verbose( "Creating program:", path );
- var program = RDProgram.FromPath( this, path );
+ var program = RDProgram.ComputeFromPath( this, path );
SetProgram( program );
}
diff --git a/Runtime/Rendering/DefaultRenderAssets.cs b/Runtime/Rendering/DefaultRenderAssets.cs
new file mode 100644
index 0000000..b7d8123
--- /dev/null
+++ b/Runtime/Rendering/DefaultRenderAssets.cs
@@ -0,0 +1,31 @@
+
+using System.Diagnostics;
+using System.Collections;
+using System.Collections.Generic;
+using System;
+using Godot;
+
+
+namespace Rokojori
+{
+ [Tool]
+ [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/RenderingManager.svg") ]
+ public partial class DefaultRenderAssets:Resource
+ {
+ [Export]
+ public string prefix = "RJ_";
+
+ [ExportGroup("Noise")]
+ [Export]
+ public Sampler2DProperty noise;
+
+ [Export]
+ public Sampler2DProperty perlin;
+
+ [Export]
+ public Sampler2DProperty voronoi;
+
+
+
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Rendering/DefaultRenderAssets.cs.uid b/Runtime/Rendering/DefaultRenderAssets.cs.uid
new file mode 100644
index 0000000..d3cd17c
--- /dev/null
+++ b/Runtime/Rendering/DefaultRenderAssets.cs.uid
@@ -0,0 +1 @@
+uid://beebds1ml3ss6
diff --git a/Runtime/Rendering/Objects/RDFrameBuffer.cs b/Runtime/Rendering/Objects/RDFrameBuffer.cs
new file mode 100644
index 0000000..a37a51f
--- /dev/null
+++ b/Runtime/Rendering/Objects/RDFrameBuffer.cs
@@ -0,0 +1,20 @@
+
+using Godot;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ public class RDFrameBuffer: RDObject
+ {
+ public RDFrameBuffer( RDContext context, Rid rid ):base( context, rid )
+ {}
+
+ public static RDFrameBuffer Create( RDContext context, List textures, RDFrameBufferFormat format )
+ {
+ var RD = context.renderingDevice;
+ var rid = RD.FramebufferCreate( textures.Map( t => t.rid ).ToGodotArray(), format.id );
+
+ return new RDFrameBuffer( context, rid );
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Rendering/Objects/RDFrameBuffer.cs.uid b/Runtime/Rendering/Objects/RDFrameBuffer.cs.uid
new file mode 100644
index 0000000..eacec6f
--- /dev/null
+++ b/Runtime/Rendering/Objects/RDFrameBuffer.cs.uid
@@ -0,0 +1 @@
+uid://djw5ejaacwbop
diff --git a/Runtime/Rendering/Objects/RDFrameBufferFormat.cs b/Runtime/Rendering/Objects/RDFrameBufferFormat.cs
new file mode 100644
index 0000000..f66eea8
--- /dev/null
+++ b/Runtime/Rendering/Objects/RDFrameBufferFormat.cs
@@ -0,0 +1,28 @@
+
+using Godot;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ public class RDFrameBufferFormat
+ {
+ RDContext _context;
+ long _id;
+
+ public long id => _id;
+
+ public RDFrameBufferFormat( RDContext context, long id )
+ {
+ _context = context;
+ _id = id;
+ }
+
+ public static RDFrameBufferFormat Create( RDContext context, List formats, int viewCount = 1 )
+ {
+
+ var id = context.renderingDevice.FramebufferFormatCreate( formats.ToGodotArray(), (uint)viewCount );
+
+ return new RDFrameBufferFormat( context, id );
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Rendering/Objects/RDFrameBufferFormat.cs.uid b/Runtime/Rendering/Objects/RDFrameBufferFormat.cs.uid
new file mode 100644
index 0000000..733e501
--- /dev/null
+++ b/Runtime/Rendering/Objects/RDFrameBufferFormat.cs.uid
@@ -0,0 +1 @@
+uid://b8e6jnhrax1tx
diff --git a/Runtime/Rendering/Objects/RDPipeline.cs b/Runtime/Rendering/Objects/RDPipeline.cs
index 1f0565b..1ac9e8e 100644
--- a/Runtime/Rendering/Objects/RDPipeline.cs
+++ b/Runtime/Rendering/Objects/RDPipeline.cs
@@ -8,9 +8,21 @@ namespace Rokojori
public RDPipeline( RDContext context, Rid rid ):base( context, rid )
{}
- public static RDPipeline Create( RDContext context, RDShader shader )
+ public static RDPipeline CreateCompute( RDContext context, RDShader shader )
{
return new RDPipeline( context, context.renderingDevice.ComputePipelineCreate( shader.rid ) );
}
+
+ public static RDPipeline CreateRender( RDContext context, RDShader shader, RDRenderPipelineSetup setup )
+ {
+ var pipelineRid = context.renderingDevice.RenderPipelineCreate(
+ shader.rid, setup.frameBufferFormat.id, setup.vertexFormat.id,
+ setup.primitive, setup.rasterizationState,
+ setup.multisampleState,
+ setup.stencilState, setup.blendState
+ );
+
+ return new RDPipeline( context, pipelineRid );
+ }
}
}
\ No newline at end of file
diff --git a/Runtime/Rendering/Objects/RDProgram.cs b/Runtime/Rendering/Objects/RDProgram.cs
index 18230ed..d4199df 100644
--- a/Runtime/Rendering/Objects/RDProgram.cs
+++ b/Runtime/Rendering/Objects/RDProgram.cs
@@ -30,7 +30,7 @@ namespace Rokojori
protected RDPipeline _pipeline;
public RDPipeline pipeline => _pipeline;
- public static RDProgram FromPath( RDContext context, string path )
+ public static RDProgram ComputeFromPath( RDContext context, string path )
{
var p = new RDProgram( context );
@@ -42,7 +42,7 @@ namespace Rokojori
return null;
}
- p._pipeline = RDPipeline.Create( context, p._shader );
+ p._pipeline = RDPipeline.CreateCompute( context, p._shader );
if ( p._pipeline == null || ! p._pipeline.rid.IsValid )
{
@@ -53,4 +53,29 @@ namespace Rokojori
return p;
}
}
+
+ public static RDProgram RenderFromPath( RDContext context, string path, RDRenderPipelineSetup setup )
+ {
+ var p = new RDProgram( context );
+
+ p._shader = RDShader.FromPath( context, path );
+
+ if ( p._shader == null || ! p._shader.rid.IsValid )
+ {
+ context.Error( "Invalid shader", path );
+ return null;
+ }
+
+ p._pipeline = RDPipeline.CreateRender( context, p._shader, setup );
+
+ if ( p._pipeline == null || ! p._pipeline.rid.IsValid )
+ {
+ context.Error( "Invalid pipeline", path );
+ return null;
+ }
+
+ return p;
+ }
+ }
+}
}
\ No newline at end of file
diff --git a/Runtime/Rendering/Objects/RDRenderPipelineSetup.cs b/Runtime/Rendering/Objects/RDRenderPipelineSetup.cs
new file mode 100644
index 0000000..3de0344
--- /dev/null
+++ b/Runtime/Rendering/Objects/RDRenderPipelineSetup.cs
@@ -0,0 +1,57 @@
+
+using Godot;
+using System;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ public class RDRenderPipelineSetup
+ {
+ public RDFrameBufferFormat frameBufferFormat;
+ public RDVertexFormat vertexFormat;
+
+ public RDPipelineRasterizationState rasterizationState;
+ public RDPipelineMultisampleState multisampleState;
+
+ public RDPipelineDepthStencilState stencilState;
+ public RDPipelineColorBlendState blendState;
+ public RenderingDevice.RenderPrimitive primitive;
+
+
+ public static RDPipelineColorBlendState CreateBlendState()
+ {
+ var blend = new RDPipelineColorBlendState();
+ var blendAttachment = new RDPipelineColorBlendStateAttachment();
+
+ blend.Attachments.Add( blendAttachment );
+
+ return blend;
+ }
+
+ public static RDPipelineDepthStencilState CreateStencilState(
+ RenderingDevice.CompareOperator compareOperator, int mask, int reference,
+ RenderingDevice.StencilOperation failOperation, RenderingDevice.StencilOperation passOperation
+ )
+ {
+ var stencil_state = new RDPipelineDepthStencilState();
+ stencil_state.FrontOpCompare = compareOperator;
+ stencil_state.FrontOpCompareMask = (uint) mask;
+ stencil_state.FrontOpReference = (uint) reference;
+ stencil_state.FrontOpFail = failOperation;
+ stencil_state.FrontOpPass = passOperation;
+
+ return stencil_state;
+ }
+ public static RDRenderPipelineSetup Create( RDFrameBufferFormat fbFormat, RDVertexFormat vxFormat, RDPipelineDepthStencilState stencilState )
+ {
+ var setup = new RDRenderPipelineSetup();
+ setup.rasterizationState = new RDPipelineRasterizationState();
+ setup.multisampleState = new RDPipelineMultisampleState();
+ setup.primitive = RenderingDevice.RenderPrimitive.Triangles;
+ setup.blendState = CreateBlendState();
+ setup.stencilState = stencilState;
+ return setup;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Rendering/Objects/RDRenderPipelineSetup.cs.uid b/Runtime/Rendering/Objects/RDRenderPipelineSetup.cs.uid
new file mode 100644
index 0000000..e87efc6
--- /dev/null
+++ b/Runtime/Rendering/Objects/RDRenderPipelineSetup.cs.uid
@@ -0,0 +1 @@
+uid://l170iemiouuo
diff --git a/Runtime/Rendering/Objects/RDSampler.cs b/Runtime/Rendering/Objects/RDSampler.cs
index 58776a6..7c9bff1 100644
--- a/Runtime/Rendering/Objects/RDSampler.cs
+++ b/Runtime/Rendering/Objects/RDSampler.cs
@@ -5,7 +5,7 @@ namespace Rokojori
{
public class RDSampler: RDObject
{
- public RDSampler( RDContext effect, Rid rid ):base( effect, rid )
+ public RDSampler( RDContext context, Rid rid ):base( context, rid )
{}
public static RDSampler Create( RDContext context, RDSamplerState samplerState )
diff --git a/Runtime/Rendering/Objects/RDVertexFormat.cs b/Runtime/Rendering/Objects/RDVertexFormat.cs
new file mode 100644
index 0000000..e5f9882
--- /dev/null
+++ b/Runtime/Rendering/Objects/RDVertexFormat.cs
@@ -0,0 +1,26 @@
+
+using Godot;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ public class RDVertexFormat
+ {
+ RDContext _context;
+ long _id;
+
+ public long id => _id;
+
+ public RDVertexFormat( RDContext context, long id )
+ {
+ _context = context;
+ _id = id;
+ }
+
+ public static RDVertexFormat Create( RDContext context, List vertexAttributes )
+ {
+ var id = context.renderingDevice.VertexFormatCreate( vertexAttributes.ToGodotArray() );
+ return new RDVertexFormat( context, id );
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Rendering/Objects/RDVertexFormat.cs.uid b/Runtime/Rendering/Objects/RDVertexFormat.cs.uid
new file mode 100644
index 0000000..9262336
--- /dev/null
+++ b/Runtime/Rendering/Objects/RDVertexFormat.cs.uid
@@ -0,0 +1 @@
+uid://be6ubw4mbixmn
diff --git a/Runtime/Rendering/RenderGraph/RDShaderProcessor.cs b/Runtime/Rendering/RenderGraph/RDShaderProcessor.cs
index 6085d51..14eb72b 100644
--- a/Runtime/Rendering/RenderGraph/RDShaderProcessor.cs
+++ b/Runtime/Rendering/RenderGraph/RDShaderProcessor.cs
@@ -46,7 +46,7 @@ namespace Rokojori
return;
}
- _pipeline = RDPipeline.Create( graph.context, _shader );
+ _pipeline = RDPipeline.CreateRender( graph.context, _shader );
if ( _shader == null )
{
diff --git a/Runtime/Rendering/RenderingManager.cs b/Runtime/Rendering/RenderingManager.cs
index 08a8db5..3f99202 100644
--- a/Runtime/Rendering/RenderingManager.cs
+++ b/Runtime/Rendering/RenderingManager.cs
@@ -8,8 +8,8 @@ using Godot;
namespace Rokojori
{
- [Tool]
- [GlobalClass]
+ [Tool]
+ [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/RenderingManager.svg") ]
public partial class RenderingManager:Node
{
[Export]
diff --git a/Runtime/Rendering/RenderingManagerData.cs b/Runtime/Rendering/RenderingManagerData.cs
index fb3c2fb..08e03f4 100644
--- a/Runtime/Rendering/RenderingManagerData.cs
+++ b/Runtime/Rendering/RenderingManagerData.cs
@@ -18,5 +18,8 @@ namespace Rokojori
[Export]
public StencilLayer[] stencilLayers;
+
+ [Export]
+ public ShaderProperty[] globalShaderProperties;
}
}
\ No newline at end of file
diff --git a/Runtime/Shading/Generators/Generic/ShaderGenerationModule.cs b/Runtime/Shading/Generators/Generic/ShaderGenerationModule.cs
index c40c53f..655e0ef 100644
--- a/Runtime/Shading/Generators/Generic/ShaderGenerationModule.cs
+++ b/Runtime/Shading/Generators/Generic/ShaderGenerationModule.cs
@@ -87,6 +87,8 @@ namespace Rokojori
public static List IncludeLightLibrary(){ return IncludeFromLibrary( "Light" ); }
+ public static List IncludeUVLibrary(){ return IncludeFromLibrary( "UV" ); }
+
public static ShaderVariant ToVariant( List code )
{
var variant = new ShaderVariant();
diff --git a/Runtime/Shading/Generators/Spatial/Geometry/VertexSwizzleType.cs b/Runtime/Shading/Generators/Spatial/Geometry/VertexSwizzleType.cs
new file mode 100644
index 0000000..a3e1825
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/Geometry/VertexSwizzleType.cs
@@ -0,0 +1,22 @@
+using Godot;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ public enum VertexSwizzleType
+ {
+ XX,
+ YY,
+ ZZ,
+
+ XY,
+ YX,
+
+ XZ,
+ ZX,
+
+ YZ,
+ ZY
+ }
+}
diff --git a/Runtime/Shading/Generators/Spatial/Geometry/VertexSwizzleType.cs.uid b/Runtime/Shading/Generators/Spatial/Geometry/VertexSwizzleType.cs.uid
new file mode 100644
index 0000000..a1a5938
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/Geometry/VertexSwizzleType.cs.uid
@@ -0,0 +1 @@
+uid://cv7cy4kjy0rk0
diff --git a/Runtime/Shading/Generators/Spatial/Geometry/VertexTransformSpace.cs b/Runtime/Shading/Generators/Spatial/Geometry/VertexTransformSpace.cs
new file mode 100644
index 0000000..0c17f69
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/Geometry/VertexTransformSpace.cs
@@ -0,0 +1,13 @@
+using Godot;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ public enum VertexTransformSpace
+ {
+ Local,
+ World,
+ View
+ }
+}
diff --git a/Runtime/Shading/Generators/Spatial/Geometry/VertexTransformSpace.cs.uid b/Runtime/Shading/Generators/Spatial/Geometry/VertexTransformSpace.cs.uid
new file mode 100644
index 0000000..b9738c8
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/Geometry/VertexTransformSpace.cs.uid
@@ -0,0 +1 @@
+uid://c3omqjbtlbakj
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVChannel.cs b/Runtime/Shading/Generators/Spatial/UV/UVChannel.cs
new file mode 100644
index 0000000..a6921bf
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/UV/UVChannel.cs
@@ -0,0 +1,46 @@
+using Godot;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ [Tool]
+ [GlobalClass]
+ public partial class UVChannel:ShaderGenerationModule
+ {
+ [Export]
+ public string uvTarget = "UV";
+
+ [Export]
+ public UVSource uvSource = new MeshUVSource();
+
+ [Export]
+ public UVModifier modifier = new UVScaleOffset();
+
+
+ public List GetShaderCode( ShaderGenerationContext context )
+ {
+ var sourceCode = uvSource.GetUV( context, uvTarget, 0 );
+ var modifierCode = modifier.ModifyUV( context, uvTarget );
+
+ if ( sourceCode == null && modifierCode == null )
+ {
+ return null;
+ }
+
+ var list = new List();
+
+ if ( sourceCode != null )
+ {
+ list.AddRange( sourceCode );
+ }
+
+ if ( modifierCode != null )
+ {
+ list.AddRange( modifierCode );
+ }
+
+ return list;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVChannel.cs.uid b/Runtime/Shading/Generators/Spatial/UV/UVChannel.cs.uid
new file mode 100644
index 0000000..fdc2a12
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/UV/UVChannel.cs.uid
@@ -0,0 +1 @@
+uid://mcu62dbrsoeh
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVModifier.cs b/Runtime/Shading/Generators/Spatial/UV/UVModifier.cs
index 84a62df..5207242 100644
--- a/Runtime/Shading/Generators/Spatial/UV/UVModifier.cs
+++ b/Runtime/Shading/Generators/Spatial/UV/UVModifier.cs
@@ -6,8 +6,8 @@ namespace Rokojori
{
[Tool]
[GlobalClass]
- public partial class UVModifier:ShaderGenerationModule
+ public abstract partial class UVModifier:ShaderGenerationModule
{
-
+ public abstract List ModifyUV( ShaderGenerationContext context, string uvTarget );
}
}
\ No newline at end of file
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVModule.cs b/Runtime/Shading/Generators/Spatial/UV/UVModule.cs
index cc71582..02dab1b 100644
--- a/Runtime/Shading/Generators/Spatial/UV/UVModule.cs
+++ b/Runtime/Shading/Generators/Spatial/UV/UVModule.cs
@@ -8,38 +8,56 @@ namespace Rokojori
[GlobalClass]
public partial class UVModule:ShaderGenerationModule
{
- [Export]
- public UVScaleOffset uvScaleOffset = new UVScaleOffset();
+ // [Export]
+ // public UVScaleOffset uvScaleOffset = new UVScaleOffset();
+
+ // [Export]
+ // public UVModifier[] modifiers = [];
[Export]
- public UVModifier[] modifiers = [];
+ public UVChannel[] channels = [ ];
public override List GetVariants( ShaderGenerationContext context )
{
- var list = new List();
+ var list = new List();
- var allModifiers = Lists.From( modifiers ).FilterNulls();
-
- if ( uvScaleOffset != null )
- {
- allModifiers.Insert( 0, uvScaleOffset );
- }
-
- allModifiers.ForEach(
- ( m )=>
+ channels.ForEach(
+ ( c )=>
{
- var variants = m.GetVariants( context );
-
- if ( variants == null )
+ var code = c.GetShaderCode( context );
+
+ if ( code == null )
{
return;
}
- list = ShaderVariant.CombineVariants( list, variants );
+ list.AddRange( code );
}
);
+ // var list = new List();
- return list;
+ // var allModifiers = Lists.From( modifiers ).FilterNulls();
+
+ // if ( uvScaleOffset != null )
+ // {
+ // allModifiers.Insert( 0, uvScaleOffset );
+ // }
+
+ // allModifiers.ForEach(
+ // ( m )=>
+ // {
+ // var variants = m.GetVariants( context );
+
+ // if ( variants == null )
+ // {
+ // return;
+ // }
+
+ // list = ShaderVariant.CombineVariants( list, variants );
+ // }
+ // );
+
+ return ToVariants( list );
}
}
}
\ No newline at end of file
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVScaleOffset.cs b/Runtime/Shading/Generators/Spatial/UV/UVScaleOffset.cs
index 2d0868e..e5fa6d8 100644
--- a/Runtime/Shading/Generators/Spatial/UV/UVScaleOffset.cs
+++ b/Runtime/Shading/Generators/Spatial/UV/UVScaleOffset.cs
@@ -21,7 +21,8 @@ namespace Rokojori
public string target = "UV";
- public override List GetVariants( ShaderGenerationContext context )
+
+ public override List ModifyUV( ShaderGenerationContext context, string uvTarget )
{
if ( ShaderPhase.Variables == context.phase )
{
@@ -36,7 +37,7 @@ namespace Rokojori
);
- return ToVariants( AsUniformGroup( "UV", lines.Join( "" ) ) );
+ return AsUniformGroup( "UV", lines.Join( "" ) );
}
@@ -61,7 +62,7 @@ namespace Rokojori
expression += ";";
- return ToVariants( ToCode( expression ) );
+ return ToCode( expression );
}
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVSource/MeshUVSource.cs b/Runtime/Shading/Generators/Spatial/UV/UVSource/MeshUVSource.cs
new file mode 100644
index 0000000..bd34a97
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/UV/UVSource/MeshUVSource.cs
@@ -0,0 +1,48 @@
+using Godot;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ [Tool]
+ [GlobalClass]
+ public partial class MeshUVSource:UVSource
+ {
+ public enum MeshUV
+ {
+ UV,
+ UV2,
+ CUSTOM0_XY,
+ CUSTOM0_YW,
+ CUSTOM1_XY,
+ CUSTOM1_YW,
+ CUSTOM2_XY,
+ CUSTOM2_YW,
+ CUSTOM3_XY,
+ CUSTOM3_YW,
+ COLOR_XY,
+ COLOR_ZW
+ }
+
+ [Export]
+ public MeshUV meshUV;
+
+ public override List GetUV( ShaderGenerationContext context, string target, int offsetIndex )
+ {
+ if ( ShaderPhase.Vertex != context.phase )
+ {
+ return null;
+ }
+
+ var meshUVstring = meshUV + "";
+
+ if ( meshUVstring[ meshUVstring.Length - 3 ] == '_' )
+ {
+ var member = "." + meshUVstring.Substring( meshUVstring.Length - 2 );
+ meshUVstring = meshUVstring.Substring( 0, meshUVstring.Length - 3 ) + member;
+ }
+
+ return ShaderGenerationModule.ToCode( $"{target} = {meshUVstring};" );
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVSource/MeshUVSource.cs.uid b/Runtime/Shading/Generators/Spatial/UV/UVSource/MeshUVSource.cs.uid
new file mode 100644
index 0000000..831dd4d
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/UV/UVSource/MeshUVSource.cs.uid
@@ -0,0 +1 @@
+uid://ibhf7a1j2ivl
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVSource/UVSource.cs b/Runtime/Shading/Generators/Spatial/UV/UVSource/UVSource.cs
new file mode 100644
index 0000000..4dbaae3
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/UV/UVSource/UVSource.cs
@@ -0,0 +1,13 @@
+using Godot;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ [Tool]
+ [GlobalClass]
+ public abstract partial class UVSource:Resource
+ {
+ public abstract List GetUV( ShaderGenerationContext context, string target, int offsetIndex );
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVSource/UVSource.cs.uid b/Runtime/Shading/Generators/Spatial/UV/UVSource/UVSource.cs.uid
new file mode 100644
index 0000000..47b745a
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/UV/UVSource/UVSource.cs.uid
@@ -0,0 +1 @@
+uid://c20r5pq6wj703
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVSource/VertexUVSource.cs b/Runtime/Shading/Generators/Spatial/UV/UVSource/VertexUVSource.cs
new file mode 100644
index 0000000..b0f9610
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/UV/UVSource/VertexUVSource.cs
@@ -0,0 +1,83 @@
+using Godot;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ [Tool]
+ [GlobalClass]
+ public partial class VertexUVSource:UVSource
+ {
+ [Export]
+ public VertexTransformSpace space;
+
+ [Export]
+ public VertexSwizzleType dimensions;
+
+ [Export]
+ public string sizeCustomName;
+
+ [Export]
+ public string centerCustomName;
+
+ public override List GetUV( ShaderGenerationContext context, string target, int offsetIndex )
+ {
+ var size = sizeCustomName == null ? "vertexUVSourceSize" : sizeCustomName;
+ var center = centerCustomName == null ? "vertexUVSourceCenter" : centerCustomName;
+
+
+ var suffix = offsetIndex == 0 ? "" : ( "_" + ( offsetIndex + 1 ) );
+
+ size += suffix;
+ center += suffix;
+
+ if ( ShaderPhase.Includes == context.phase )
+ {
+ return ShaderGenerationModule.IncludeUVLibrary();
+ }
+ else if ( ShaderPhase.Variables == context.phase )
+ {
+ var uniforms =
+ @$"
+
+ uniform vec2 {size};
+ uniform vec2 {center};
+
+ ";
+
+ return ShaderGenerationModule.ToCode( uniforms.Indent( "" ) );
+ }
+
+ if ( ShaderPhase.Vertex != context.phase )
+ {
+ return null;
+ }
+
+ var member = ( dimensions + "" ).ToLower();
+ var vertex = "VERTEX";
+
+ if ( VertexTransformSpace.World == space )
+ {
+ vertex = "localToWorld( VERTEX, MODEL_MATRIX )";
+ }
+ else if ( VertexTransformSpace.View == space )
+ {
+ vertex = "localToView( VERTEX, MODELVIEW_MATRIX )";
+ }
+
+
+ var code =
+ @$"
+
+ {{
+ vec3 vertex = {vertex};
+ {target} = mapUV( vertex.{member}, {size}, {center} );
+
+ }}
+
+ ";
+
+ return ShaderGenerationModule.ToCode( code.Indent( " ") );
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Shading/Generators/Spatial/UV/UVSource/VertexUVSource.cs.uid b/Runtime/Shading/Generators/Spatial/UV/UVSource/VertexUVSource.cs.uid
new file mode 100644
index 0000000..f04c748
--- /dev/null
+++ b/Runtime/Shading/Generators/Spatial/UV/UVSource/VertexUVSource.cs.uid
@@ -0,0 +1 @@
+uid://q3pmo1xtm4qg
diff --git a/Runtime/Shading/Library/UV.gdshaderinc b/Runtime/Shading/Library/UV.gdshaderinc
new file mode 100644
index 0000000..68db790
--- /dev/null
+++ b/Runtime/Shading/Library/UV.gdshaderinc
@@ -0,0 +1,9 @@
+// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/UV.gdshaderinc"
+
+vec2 mapUV( vec2 position, vec2 size, vec2 center )
+{
+ vec2 offset = center - size/2.0;
+ vec2 uv = ( position - offset ) / mapSize;
+
+ return uv;
+}
\ No newline at end of file
diff --git a/Runtime/Shading/Library/UV.gdshaderinc.uid b/Runtime/Shading/Library/UV.gdshaderinc.uid
new file mode 100644
index 0000000..791f3f5
--- /dev/null
+++ b/Runtime/Shading/Library/UV.gdshaderinc.uid
@@ -0,0 +1 @@
+uid://7uu03yaikt2
diff --git a/Runtime/Shading/Properties/Properties/Sampler2DProperty.cs b/Runtime/Shading/Properties/Properties/Sampler2DProperty.cs
new file mode 100644
index 0000000..ee01ae3
--- /dev/null
+++ b/Runtime/Shading/Properties/Properties/Sampler2DProperty.cs
@@ -0,0 +1,35 @@
+using Godot;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ [Tool]
+ [GlobalClass]
+ public partial class Sampler2DProperty : ShaderProperty
+ {
+ [Export]
+ public Sampler2DPropertyName propertyName;
+
+ [Export]
+ public Texture2D value;
+
+ public override void Apply( Material material )
+ {
+ propertyName.Set( material, value );
+ }
+
+ public void ReadFrom( Material material )
+ {
+ value = propertyName.Get( material );
+ }
+
+ public static Sampler2DProperty Create( string name, Texture2D value )
+ {
+ var sp = new Sampler2DProperty();
+ sp.propertyName = Sampler2DPropertyName.Create( name );
+ sp.value = value;
+ return sp;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Shading/Properties/Properties/Sampler2DProperty.cs.uid b/Runtime/Shading/Properties/Properties/Sampler2DProperty.cs.uid
new file mode 100644
index 0000000..165ba2e
--- /dev/null
+++ b/Runtime/Shading/Properties/Properties/Sampler2DProperty.cs.uid
@@ -0,0 +1 @@
+uid://co43lpc6cforf
diff --git a/Runtime/Shading/Properties/Properties/ShaderProperty.cs b/Runtime/Shading/Properties/Properties/ShaderProperty.cs
index 64172b9..ac8efd5 100644
--- a/Runtime/Shading/Properties/Properties/ShaderProperty.cs
+++ b/Runtime/Shading/Properties/Properties/ShaderProperty.cs
@@ -6,7 +6,7 @@ namespace Rokojori
{
[Tool]
[GlobalClass]
- public partial class ShaderProperty : Resource
+ public abstract partial class ShaderProperty : Resource
{
public virtual void Apply( Material material )
{
diff --git a/Runtime/Shading/Properties/Properties/Vector3Property.cs b/Runtime/Shading/Properties/Properties/Vector3Property.cs
index 10b8a88..f600861 100644
--- a/Runtime/Shading/Properties/Properties/Vector3Property.cs
+++ b/Runtime/Shading/Properties/Properties/Vector3Property.cs
@@ -28,7 +28,7 @@ namespace Rokojori
public void ApplyLerped( Material material, Vector3 from, float lerpState )
{
- var lerpedValue = Math3D.Lerp( from, value, lerpState );
+ Vector3 lerpedValue = Math3D.Lerp( from, value, lerpState );
propertyName.Set( material, lerpedValue );
}
diff --git a/Runtime/Shading/Properties/Properties/Vector4Property.cs b/Runtime/Shading/Properties/Properties/Vector4Property.cs
new file mode 100644
index 0000000..6f6075d
--- /dev/null
+++ b/Runtime/Shading/Properties/Properties/Vector4Property.cs
@@ -0,0 +1,43 @@
+using Godot;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ [Tool]
+ [GlobalClass]
+ public partial class Vector4Property : ShaderProperty
+ {
+ [Export]
+ public Vector4PropertyName propertyName;
+
+ public string name => propertyName.propertyName;
+
+ [Export]
+ public Vector4 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, Vector4 from, float lerpState )
+ {
+ var lerpedValue = from.Lerp( value, lerpState );
+ propertyName.Set( material, lerpedValue );
+ }
+
+ public static Vector4Property Create( string name, Vector4 value )
+ {
+ var fp = new Vector4Property();
+ fp.propertyName = Vector4PropertyName.Create( name );
+ fp.value = value;
+ return fp;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Shading/Properties/Properties/Vector4Property.cs.uid b/Runtime/Shading/Properties/Properties/Vector4Property.cs.uid
new file mode 100644
index 0000000..ae601dd
--- /dev/null
+++ b/Runtime/Shading/Properties/Properties/Vector4Property.cs.uid
@@ -0,0 +1 @@
+uid://cyn0q8t6wqidh
diff --git a/Runtime/Shading/Properties/Sampler2DPropertyName.cs b/Runtime/Shading/Properties/Sampler2DPropertyName.cs
new file mode 100644
index 0000000..f7faea0
--- /dev/null
+++ b/Runtime/Shading/Properties/Sampler2DPropertyName.cs
@@ -0,0 +1,29 @@
+using Godot;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Rokojori
+{
+ [Tool]
+ [GlobalClass]
+ public partial class Sampler2DPropertyName : ShaderPropertyName
+ {
+
+ public void Set( Material material, Texture2D value )
+ {
+ _Set( material, value );
+ }
+
+ public Texture2D Get( Material material )
+ {
+ return _Get( material, null );
+ }
+
+ public static Sampler2DPropertyName Create( string name )
+ {
+ var p = new Sampler2DPropertyName();
+ p.propertyName = name;
+ return p;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Shading/Properties/Sampler2DPropertyName.cs.uid b/Runtime/Shading/Properties/Sampler2DPropertyName.cs.uid
new file mode 100644
index 0000000..20af034
--- /dev/null
+++ b/Runtime/Shading/Properties/Sampler2DPropertyName.cs.uid
@@ -0,0 +1 @@
+uid://dksspv30lkrq7
diff --git a/Runtime/Tools/Lists.cs b/Runtime/Tools/Lists.cs
index 990f7d9..b865b5e 100644
--- a/Runtime/Tools/Lists.cs
+++ b/Runtime/Tools/Lists.cs
@@ -1081,6 +1081,11 @@ namespace Rokojori
return list;
}
+ public static Godot.Collections.Array ToGodotArray<[MustBeVariant] T>( this List values )
+ {
+ return [.. values];
+ }
+
public static List Map<[Godot.MustBeVariant]T,U>( Godot.Collections.Array inputList, Func mapper, List list = null )
{
if ( list == null )