Before MultiBaker Update

This commit is contained in:
Josef 2025-04-06 18:39:24 +02:00
parent 24e6ca84c3
commit e103f0ab56
9 changed files with 160 additions and 132 deletions

View File

@ -11,20 +11,11 @@ namespace Rokojori
[GlobalClass] [GlobalClass]
public partial class MultiBaker:Node public partial class MultiBaker:Node
{ {
[Export] [ExportToolButton( "Initialize")]
public bool initialize; public Callable InitializeButton => Callable.From( () => Initialize() );
public bool bake; [ExportToolButton( "Bake")]
public Callable BakeButton => Callable.From( () => Bake() );
public bool saveTexture;
[ExportGroup("Preview")]
[Export]
public bool preview_UpdateAlways = true;
[Export]
public bool preview_DilateTextures = true;
public enum MaterialMode public enum MaterialMode
{ {
@ -179,9 +170,6 @@ namespace Rokojori
[Export] [Export]
public WorldEnvironment X_worldEnvironment; public WorldEnvironment X_worldEnvironment;
// [Export]
// public DilateTexture X_dilateTexture;
[Export] [Export]
public MeshInstance3D X_outputMesh; public MeshInstance3D X_outputMesh;
@ -213,46 +201,14 @@ namespace Rokojori
bool _initialized = false; bool _initialized = false;
bool _baking = false; bool _baking = false;
public override void _Ready() public async Task Bake()
{ {
}
public bool preventProcessing = true;
public override void _Process( double delta )
{
if ( preventProcessing )
{
return;
}
X_texturePreview.Visible = showOutputTexture;
if ( _baking ) if ( _baking )
{ {
return; return;
} }
if ( initialize )
{
initialize = false;
Initialize();
}
if ( bake || preview_UpdateAlways )
{
bake = false;
Bake();
}
}
public async Task Bake()
{
_baking = true; _baking = true;
try try
@ -333,20 +289,9 @@ namespace Rokojori
this.LogInfo( "Texture created:", bakingMaterialModes[ i ] ); this.LogInfo( "Texture created:", bakingMaterialModes[ i ] );
// if ( preview_DilateTextures ) texture = Textures.Copy( texture );
// { await this.RequestNextFrame();
// this.LogInfo( "Dilating:", bakingMaterialModes[ i ] ); await this.RequestNextFrame();
// texture = await CreateDilatedTexture();
// this.LogInfo( "Dilating done:", bakingMaterialModes[ i ] );
// }
// else
// {
texture = Textures.Copy( texture );
await this.RequestNextFrame();
await this.RequestNextFrame();
// }
this.LogInfo( "Assigning Texture", bakingMaterialModes[ i ] ); this.LogInfo( "Assigning Texture", bakingMaterialModes[ i ] );
GetBakeModeImplementation().AssignMaterial( bakingMaterialModes[ i ], texture ); GetBakeModeImplementation().AssignMaterial( bakingMaterialModes[ i ], texture );
@ -373,38 +318,6 @@ namespace Rokojori
} }
// public async Task<Texture2D> CreateDilatedTexture()
// {
// var viewports = GetAllViewports();
// var textures = Lists.Map( viewports, v => v.GetTexture() as Texture2D );
// var dilatedTextures = new List<Texture2D>();
// var index = 0;
// foreach ( var t in textures )
// {
// index ++;
// var dilatedTexture = await X_dilateTexture.Create( t );
// dilatedTextures.Add( dilatedTexture );
// }
// X_textureMerger.sourceTextures = dilatedTextures.ToArray();
// X_textureMerger.sourceMode = TextureMerger.SourceMode.Textures;
// X_textureMerger.Initialize();
// await this.RequestNextFrame();
// X_textureMerger.CreateLayout();
// await this.RequestNextFrame();
// var finalTexture = await X_dilateTexture.Create( X_textureMerger.X_textureMergerViewport.GetTexture() );
// return finalTexture;
// }
public List<SubViewport> GetAllViewports() public List<SubViewport> GetAllViewports()
{ {

View File

@ -391,6 +391,8 @@ namespace Rokojori
public List<int> Selection( int possibleValues, int selection ) public List<int> Selection( int possibleValues, int selection )
{ {
selection = Mathf.Min( selection, possibleValues );
var list = new List<int>(); var list = new List<int>();
for ( int i = 0; i < possibleValues; i++ ) for ( int i = 0; i < possibleValues; i++ )

View File

@ -1,35 +0,0 @@
shader_type canvas_item;
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
uniform float kernelOffset = 1;
void fragment()
{
vec2 pixelSize = SCREEN_PIXEL_SIZE * kernelOffset;
vec4 blurred = vec4( 0, 0, 0, 0 );
int kernel = 2;
for ( int x = -kernel; x<= kernel; ++x )
{
for ( int y = -kernel; y<= kernel; ++y )
{
vec2 sampledUV = SCREEN_UV + pixelSize * vec2( float(x), float( y ) );
vec4 value = textureLod( screen_texture, sampledUV, 0 );
if ( ( value.r + value.g + value.b ) * 255.0 < 10.0 )
{
value.a = 0.0;
}
blurred += value;
}
}
blurred /= float( kernel * kernel );
COLOR = blurred;
;
}

View File

@ -1 +0,0 @@
uid://djf46k1sq5eks

View File

@ -0,0 +1,93 @@
// NOTE: Shader automatically converted from Godot Engine 4.4.stable.mono's StandardMaterial3D.
shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_disabled, unshaded;
uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;
uniform vec2 resolution;
uniform int maxRadius = 32;
uniform int alphaTreshold:hint_range(1,255) = 1;
uniform int genericAlphaOffset:hint_range(0,255) = 9;
uniform int assignedColorAlphaMinimum:hint_range(0,255) = 0;
uniform float amount:hint_range(0,1)=1;
vec4 getPaddingColor( vec2 uv, vec2 pixelSize, int closestDistance, float t )
{
vec4 closestPixel = texture( texture_albedo, uv );
if ( closestPixel.a >= t )
{
return closestPixel / closestPixel.a;;
}
for ( int x = -maxRadius; x <= maxRadius; ++x )
{
for ( int y = -maxRadius; y <= maxRadius; ++y )
{
int d = x * x + y * y;
if ( d >= closestDistance )
{
continue;
}
vec2 pUV = uv + pixelSize * vec2( float( x ), float( y ) );
vec4 pixel = texture( texture_albedo, pUV );
if ( pixel.a >= t )
{
closestPixel = pixel / pixel.a;
closestPixel.a = pixel.a;
closestDistance = d;
}
}
}
return closestPixel;
}
varying vec2 pixelSize;
varying float closestDistance;
const float halfSquare = pow( 2.0, 0.5 ) * 0.5;
varying float tresholdFloat;
varying float assignedColorAlphaMinimumFloat;
varying float genericAlphaOffsetFloat;
void vertex()
{
pixelSize = vec2( 1.0 / resolution.x, 1.0 / resolution.y );
float range = float( maxRadius ) * halfSquare;
closestDistance = ( range * range + range * range );
tresholdFloat = float( alphaTreshold ) / 255.0;
assignedColorAlphaMinimumFloat = float( assignedColorAlphaMinimum ) / 255.0;
genericAlphaOffsetFloat = float( genericAlphaOffset ) / 255.0;
}
void fragment()
{
vec2 pixelPerfectUV = round( UV * resolution ) / resolution;
vec4 original = texture( texture_albedo, pixelPerfectUV );
if ( original.a == 1.0 )
{
ALBEDO = original.rgb;
ALPHA = original.a;
}
else
{
int closestDistanceInteger = int( closestDistance );
vec4 outputColor = getPaddingColor( pixelPerfectUV, pixelSize, closestDistanceInteger, tresholdFloat );
outputColor.a = max( original.a, outputColor.a > 0.0 ? assignedColorAlphaMinimumFloat : 0.0 );
ALBEDO = mix( original.rgb, outputColor.rgb, amount );
ALPHA = mix( original.a, min( 1, outputColor.a + genericAlphaOffsetFloat ), amount );
}
}

View File

@ -0,0 +1 @@
uid://cpe2qaooyu4rx

View File

@ -0,0 +1,53 @@
using Godot;
namespace Rokojori
{
// Generated by ShaderClassGenerator
public class DilationDrawerShader
{
public static readonly CachedResource<Shader> shader = new CachedResource<Shader>(
"res://addons/rokojori_action_library/Runtime/Shading/Shaders/Baking/DilationDrawer.gdshader"
);
public static readonly Texture2DPropertyName textureAlbedo = Texture2DPropertyName.Create( "texture_albedo" );
public static readonly Vector2PropertyName resolution = Vector2PropertyName.Create( "resolution" );
public static readonly IntPropertyName maxRadius = IntPropertyName.Create( "maxRadius" );
public static readonly IntPropertyName alphaTreshold = IntPropertyName.Create( "alphaTreshold" );
public static readonly IntPropertyName genericAlphaOffset = IntPropertyName.Create( "genericAlphaOffset" );
public static readonly IntPropertyName assignedColorAlphaMinimum = IntPropertyName.Create( "assignedColorAlphaMinimum" );
public static readonly FloatPropertyName amount = FloatPropertyName.Create( "amount" );
}
[Tool]
public partial class DilationDrawerMaterial:CustomMaterial
{
public static readonly CachedResource<DilationDrawerMaterial> DepthMap = CustomMaterial.Cached<DilationDrawerMaterial>(
"res://addons/rokojori_action_library/Runtime/Shading/Shaders/Baking/DepthMap.material"
);
public readonly CustomMaterialProperty<Texture2D> textureAlbedo;
public readonly CustomMaterialProperty<Vector2> resolution;
public readonly CustomMaterialProperty<int> maxRadius;
public readonly CustomMaterialProperty<int> alphaTreshold;
public readonly CustomMaterialProperty<int> genericAlphaOffset;
public readonly CustomMaterialProperty<int> assignedColorAlphaMinimum;
public readonly CustomMaterialProperty<float> amount;
public DilationDrawerMaterial()
{
Shader = DilationDrawerShader.shader.Get();
textureAlbedo = new CustomMaterialProperty<Texture2D>( this, DilationDrawerShader.textureAlbedo );
resolution = new CustomMaterialProperty<Vector2>( this, DilationDrawerShader.resolution );
maxRadius = new CustomMaterialProperty<int>( this, DilationDrawerShader.maxRadius );
alphaTreshold = new CustomMaterialProperty<int>( this, DilationDrawerShader.alphaTreshold );
genericAlphaOffset = new CustomMaterialProperty<int>( this, DilationDrawerShader.genericAlphaOffset );
assignedColorAlphaMinimum = new CustomMaterialProperty<int>( this, DilationDrawerShader.assignedColorAlphaMinimum );
amount = new CustomMaterialProperty<float>( this, DilationDrawerShader.amount );
}
}
}

View File

@ -0,0 +1 @@
uid://dq3gkhoapw0ad

View File

@ -0,0 +1 @@
uid://cbec0e07mfxps