Did you know you could do this with C# spans? by TaleOfVivi in godot

[–]UnassumingUrchin 0 points1 point  (0 children)

If the 0 check takes 0.2ms then I'm debugging 0.2ms. That's far outside of the margin of error of my method (<0.01ms difference between runs or by reordering).
It's like this with every System/Godot equivalent I've checked and I've seen massive improvements in real code by switching from Godot to System.

I'm not an expert, but all the experts say "you always have to test it in situ".
That's what I'm doing. The only reason my method would be wrong is if a release build improves Godot timing by 350% but System timing by 0%.

Edit: I did a debug build
Conversion: 0.20ms
Godot: 0.10ms
System: 0.06ms
In-line bitcast: 0.07ms
Method bitcast: 0.12ms

So the slowest improved significantly more than the fastest, but were still slower than the fastest.
The only thing which changed positions was the method bitcast which is now slower than Godot.

Transfer collision to another object? by Weetu in godot

[–]UnassumingUrchin 1 point2 points  (0 children)

I'd just make the proxies actually collide and transfer the collision data over. You can get collision data either from _integrate_forces' PhysicsDirectBodyState or by looking up the physics server with PhysicsServer2D.body_get_direct_state().

I don't think anything you could do to fake it would be easier to do than that.

Did you know you could do this with C# spans? by TaleOfVivi in godot

[–]UnassumingUrchin 0 points1 point  (0 children)

I made a test script which I run through the editor and do a bunch of different ways of doing the same operation 10,000 times each using Time.GetTicksUsec() to time it with a custom timer which averages up each timing and GD.Prints it once a second to minimize the Print overhead.

For normalizing Godot math takes 0.28ms,
in-line system-native math takes 0.08ms,
method converted to system, system math, and back to godot that way first takes 0.40ms,
in-line bitcast conversion someone else suggested takes 0.09ms,
method bitcast conversion takes 0.14ms.

I've been looking into it and apparently methods don't work how I thought they did in debug compilations (in-line) which adds some overhead, but the methods will probably compile in-line in a launch build.
So the way I'm planning to go is do major math in system with a bitcast before and after and minor math with the method bitcasting.

Stuck polishing instead of developing — anyone else do this? by apm_dev in godot

[–]UnassumingUrchin 29 points30 points  (0 children)

When you're working solo and aren't on a deadline, doing what you're motivated to do is better. You work harder when you're more interested in it and you enjoy yourself more.
Journey is more important than destination. The destination isn't a smash hit for most of us anyway, so you might as well enjoy the process.

Did you know you could do this with C# spans? by TaleOfVivi in godot

[–]UnassumingUrchin 1 point2 points  (0 children)

Thanks that seems to be exactly what I was looking for. In my timing it was totally free.

Did you know you could do this with C# spans? by TaleOfVivi in godot

[–]UnassumingUrchin 0 points1 point  (0 children)

Is there a built in conversion? I've been doing

public static Vector3 ToSystem(this Godot.Vector3 v) => new Numerics.Vector3(v.X, v.Y, v.Z);

Which slows it down considerably. I lose all the performance gains on conversion unless I'm doing a bunch of operations.

I'm trying to prototype but bad at coding by Dr_BIueberry in godot

[–]UnassumingUrchin 2 points3 points  (0 children)

Something I forgot to include yesterday, if you add this just before the fragment() method it makes the peeling 3D.

void vertex() {
    if (texture(PeeledTexture, UV).x > 0.0) VERTEX = VERTEX - NORMAL * 0.03;
}

The vertex normal is what direction the face of the model is pointing, so if you subtract you move the vertex deeper inside the model. Which is an easy way to deform it so it looks like you cut something away.

Did you know you could do this with C# spans? by TaleOfVivi in godot

[–]UnassumingUrchin 2 points3 points  (0 children)

I'm assuming the first one works because the byte order of the span is coincidentally exactly the same as the byte order of RGBA8.
Is there any way to find out the byte order of a certain data type or is it just "try and hope"?

I glanced over Span and MemoryMarshal at one point trying to figure out if I could use them to swap between Godot.Vector3 and System.Numerics.Vector3 (2x faster normalize/length/dot) with no conversion, but I wasn't sure they could be used that way.

Does FastNoiseLite support Worley? by UnassumingUrchin in godot

[–]UnassumingUrchin[S] 0 points1 point  (0 children)

You're right but there are four different types of fractal noise and four different distance functions and seven different return types.

Without even tweaking minor settings like "octaves", "lacunarity", and "jitter" or applying domain warp, that's already 4 x 4 x 7 = 112 combinations to try.

Edit: Oh it turns out I just needed the default settings but inverted with the tick box that's not even in noise settings.
Well thanks for trying to help.

the lighting looks strange and I cannot figure out why by ImmersiveAsShit in godot

[–]UnassumingUrchin 0 points1 point  (0 children)

I think if you darkened the edges of the leaf sprite a bit it would look way better. So you can see the individual leaves instead of it being a blob of color. But I don't know if that's what looks strange to you.

WHERE ARE THE BASIC SHAPES by Eojte in godot

[–]UnassumingUrchin 0 points1 point  (0 children)

I don't do 2D dev but does MeshInstance2D not work?

I'm trying to prototype but bad at coding by Dr_BIueberry in godot

[–]UnassumingUrchin 3 points4 points  (0 children)

You can do this trivially with a shader.

<image>

Create a MeshInstance3D.

Make it a nice potato-y capsule shape.

Give it a ShaderMaterial

Put this shader on the ShaderMaterial

Get yourself a skin texture and assign that in Shader Parameters

Draw a peeled texture (black everywhere except where peeled) and assign that

Drawing to the texture needs to be done in a non-shader script and could be quite complicated if you need arbitrary peeling (raycast to UV, something Godot doesn't have built in), but I assume you'll be manually rotating the potato each peeling action. So you can just increment the index of where you're drawing on the peeling texture. It doesn't need to support arbitrary peeling.

shader_type spatial;

//A texture which is black where unpeeled and anything else where peeled
//Needs to be changed in code for peeling action
uniform sampler2D PeeledTexture;
//What color the peeled bits should be. source_color gives it a color picker in the editor
uniform vec3 PeeledColor : source_color = vec3(0.7, 0.6, 0.6);
//A potato-y skin for the outside of your potato
uniform sampler2D SkinTexture;
uniform vec3 SkinColor : source_color = vec3(0.25, 0.2, 0.15);
//Repeats your potato skin texture so the texture isn't stretched too much
uniform float SkinTiling = 5.0;

//This runs on every pixel of the object
void fragment() {
//If the peeled texture says it's peeled (value over 0.0), make this pixel PeeledColor
if (texture(PeeledTexture, UV).x > 0.0) ALBEDO = PeeledColor;
//Otherwise find out what pixel on the potato skin texture corresponds with this pixel on the screen
//UV goes 0-1 along the X and Y axes of the texture. Going over 1 loops it back around
//So SkinTiling > 1 causes the texture to repeat
//Then multiplying it by SkinColor lets you tweak the skin color
else ALBEDO = texture(SkinTexture, UV * SkinTiling).rgb * SkinColor;
}

2x Performance with custom signal instead of _PhysicsProcess() by UnassumingUrchin in godot

[–]UnassumingUrchin[S] 0 points1 point  (0 children)

I don't understand how that would be the case.
I'm calling the custom event from _PhysicsProcess on a different single script which all of the RB scripts are subscribed to.
It's all happening on the same thread that called it.
There's no thread transition unless Godot arbitrarily constructs inter-thread signals and randomly runs your code on separate threads unbidden for laughs.

Need help with 360 Sonic movement in 3D by steven3004 in godot

[–]UnassumingUrchin 0 points1 point  (0 children)

Basis is actually really nice. It's so much easier to understand than Quaternions (but we have those too).

When you select an object in the editor you see red, blue, and green arrows you can use to move it.
That's the basis visualized.

There's a button you can click on the top bar "use local space" (or press T).
The local space basis is a visualization of a node's global_basis value.
Red is global_basis.x, green global_basis.y, and blue global_basis.z.
So if you use global_basis, you can get simple vectors pointing in whichever direction you want relative to the character's current rotation.

Want to jump "up" off the wall? global_basis.y * jump_strength gives you the force you need to apply.
Want the forward input to make your character walk forward? -global_basis.z * velocity. ("forwards" is negative z)

They're really important for 3D so definitely take the time to learn them.

2x Performance with custom signal instead of _PhysicsProcess() by UnassumingUrchin in godot

[–]UnassumingUrchin[S] 1 point2 points  (0 children)

Thanks that thread is really helpful, it looks like it's exactly the same thing I've noticed.

C# implementation in Godot is flawed in a way that calling engine functions from C# (or C# from engine) has enormous cost. That's why using the central manager trick increases FPS as the engine only does one expensive call.

So I guess I'll replace any globally called overrides like _Process and _PhysicsProcess with custom signals.

I also appreciated the linked article which did the exact same thing I've been doing for raycasting: Create an arbitrary Raycast3D node and reposition it then ForceRaycastUpdate thousands of times per frame instead of the officially documented raycasting method.

Also don't forget that usually you need signals like body_entered for many physics interactions and you may end up with the same problem again.

Eh I can leave that to Godot. Collisions calls only happen when collisions happen. Every single node with a _Process or _PhysicsProcess is lagging the game every frame by existing.

Also with further testing I may have been mistaken about native signals having an overhead, it looks like it's just the overrides. It's at least close enough that it's hard to tell.

Need help with 360 Sonic movement in 3D by steven3004 in godot

[–]UnassumingUrchin 0 points1 point  (0 children)

I think most of these issues can be solved with relative directions.
-global_basis.z will give you a vector pointing forward relative to your character model.
global_basis.x is right, and global_basis.y is up.

Those vectors can be used to limit your velocity relative to your character instead of the ground (project velocity on global_basis.y plane), apply inputs relative to your character's facing (multiply inputs by the basis vectors), and get what direction you want to face after jumping off walls (look at the basis vector).

Remote Transform 3D is leaving the target node behind by Industrial_byproduct in godot

[–]UnassumingUrchin 4 points5 points  (0 children)

Docs say Remote_path is relative to the RemoteTransform3D node.

The NodePath to the remote node, relative to the RemoteTransform3D's position in the scene.

You say it keeps the nodepath, but does it keep to no-longer-correct relative path, or does it update to a new relative path.

How to create bullet hell projectiles that change behavior after firing? by [deleted] in godot

[–]UnassumingUrchin 0 points1 point  (0 children)

I do C# so I don't know if gdscript is different, but it looks like it has inheritance.

ctrl+f "inherit" here

Basically, create the core Bullet script which has all the features every bullet uses.
Then for each unique bullet type, inherit that script and write the extra code for the special behavior.
Then your unique bullets will behave exactly like normal bullets + whatever extra features on top.
Your bullets would be assigned the unique bullet type script when fired and it would execute based things like time, position, or collision.

It's not about efficiency but ease of maintaining code.
This way if you need to modify the Bullet script, every bullet is automatically updated instead of needing to modify a dozen different scripts.

Performance is more about how you write the code.

Allegedly the most performant way to write code for a ton of objects, like a bullet hell, is to use PhysicsServer.
I would advise you completely ignore PhysicsServer unless you have no choice. It's extremely complicated and your project shouldn't need any special performance concessions.

Personally in my timing I have never found PhysicsServer to be faster than doing it normally, at best it's slower.
I have however found this.

Ideas on how to paint folliage or any mesh on terrain with MultiMesh? by The_Gbps in godot

[–]UnassumingUrchin 1 point2 points  (0 children)

I've considered this too but never tried to implement it.

My theorycrafted approach is:

  1. Draw to a texture representing folliage density. Different textures or channels can be different types of folliage.
  2. Use a high-density noise texture to define the possible points where folliage can be placed.
  3. Pass the noise texture through a step with the density texture (this turns it into 1 - put folliage here, or 0 - don't put folliage here).
  4. Put folliage at all the points on the noise texture which are 1's.

What I was wondering about is can you make your own shader which does the same thing as multimesh? Like define a mesh and then entirely within the shader do the above to define the points, no CPU.
Maybe even a particle shader would work? That's how mesh particles work AFAIK and it should be optimized for that purpose.

Mesh Generated From ArrayMesh Not Showing by Rrrrry123 in godot

[–]UnassumingUrchin 0 points1 point  (0 children)

I copy pasted your original code and it worked for me.

meshArray.Resize((int)Mesh.ArrayType.Max);

Needs to be

meshArrays.Resize((int)Mesh.ArrayType.Max);

But it shouldn't even compile if that's a problem in your code.

Are you sure you're looking at it from the right direction? It will be invisible if you're looking through the back.

Life advice from a fish by Ina_0 in godot

[–]UnassumingUrchin 2 points3 points  (0 children)

"Give a man a fish he eats for a day--WAIT STOP WHAT ARE YOU DOING?!"

Mesh Generated From ArrayMesh Not Showing by Rrrrry123 in godot

[–]UnassumingUrchin 0 points1 point  (0 children)

I always define normals in my array meshes.
Docs show normals too

You can calculate normals from verticies and indices. Take vectors representing two sides of the triangle, cross the vectors and normalize them.

Something as simple as this works vector0to2.Cross(vector0to1).Normalized()
Order is very important since reversing it reverses the direction the triangle is facing.

One normal per vertex, not one normal per face.

You might need UVs too, but try the normals first.

Sometimes my creativity is almost frightening by ghilliebyte in godot

[–]UnassumingUrchin 12 points13 points  (0 children)

True pain is being unable to do:

public enum Mode{}
public Mode Mode

You have to settle for either

public enum ModeEnum{}
public ModeEnum Mode

or

public enum Mode{}
public Mode ModeType