Godot

7673 readers
46 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 3 years ago
MODERATORS
1
2
3
4
5
 
 

Build and manage your SETI infrastructure to complete the search for extraterrestrial intelligence.

Made with Godot of course. Playable in the browser. 100% free. No download required.

6
 
 

Hello, everyone! This is the second part of the tutorial in which we create a shader for simulating old film projection in Godot 4. You can find a link to the first part in the description of this video. This time, we will complete the entire effect by enhancing it with various scratches, stains, and other types of damage that can appear on film strips.

7
8
 
 

Preamble: I've been trying to write my first shader and have been stuck for several days now. I chose this shader because I thought it would be an easy first, but I've been down a few rabbit holes and I'm no longer sure what is the best approach.

I did my best to organize what I've tried and the problems/questions I have with each approach. Sorry if this is a long one...


I'm building a 2D platformer game and have made some really simple blank white tiles with black/gray borders to start off with and test my game. 32x32 px tiles, viewable [here](https://imgur.com/a/Y9pPH3c.

I wanted to build a shader on my TileMapLayer so that on the bottom and left sides they have a bit more grey. My thinking is for any white pixel, if there is a black pixel 1 or 2 pixels left or below the current one, make COLOR be grey.


Attempt 1: My first approach was following this post: https://forum.godotengine.org/t/how-to-check-color-of-adjacent-pixels-in-fragment-shader/27296/2 I got pretty close with this code:

shader_type canvas_item;

const vec4 BLACK = vec4(0, 0, 0, 1);
const vec4 WHITE = vec4(1, 1, 1, 1);

const vec2 LEFT_ONE = vec2(-1, 0);
const vec2 LEFT_TWO = vec2(-2, 0);
const vec2 DOWN_ONE = vec2(0, 1);
const vec2 DOWN_TWO = vec2(0, 2);

void fragment() {
    vec2 pixel_size = 1.0 / vec2(textureSize(TEXTURE, 0));
    if (texture(TEXTURE, UV).rgba == WHITE) {
        if (texture(TEXTURE, UV + LEFT_ONE * pixel_size).rgba == BLACK
            || texture(TEXTURE, UV + LEFT_TWO * pixel_size).rgba == BLACK
            || texture(TEXTURE, UV + DOWN_ONE * pixel_size).rgba == BLACK
            || texture(TEXTURE, UV + DOWN_TWO * pixel_size).rgba == BLACK) {
            COLOR = vec4(0.0, 1.0, 0.0, 1.0); // currently green for debugging
        }
    }
}

but the issue is that TEXTURE isn't my TileMapLayer, it's the tileset image itself (as in, the one linked above). This led to some weird issues, ex: https://imgur.com/a/WNlGpJe.

My first question: This approach could work, if only I could just have the texture of the TileMapLayer itself. Is there any way that's possible?


Attempt 2: It was suggested in the Godot Discord for me to try a Screen-Reading Shader. No matter what I try here, my screen_texture is always from before my TileMapLayer is drawn. This means I can't detect the colors of pixels on the TileMapLayer since screen_texture doesn't have it yet.

I can verify it with this code:

shader_type canvas_item;

const vec4 WHITE = vec4(1, 1, 1, 1);
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;

void fragment() {
	if (COLOR.rgba == WHITE) { // This is done to leave my borders alone and only draw on the white. This works.
		COLOR = texture(screen_texture, SCREEN_UV);
    }
}

This makes all the white pixels effectively transparent. If screen_texture had my TileMapLayer, I'd expect the pixels to remain white.

I've tried various attempts at converting my above code to use screen_texture and SCREEN_UV but I figure if I cannot get screen_texture to see the TileMapLayer, none of that code will work.

2a: I've read online about BackBorderCopy, but I've been unable to get any good results with one. I've tried it as a parent, child, and before/after sibling of my TileMapLayer, with Rect mode and Viewport mode, and while it does make some things happen, it never makes it so screen_texture gets my TileMapLayer's pixels.

Questions: Is BackBorderCopy what I need? Am I using it wrong? I think it needs to be a parent of my TileMapLayer, but I've had no luck no matter what. It seems to give the same results .

2b: I've tried adding my TileMapLayer as a child of a CanvasGroup, and putting the shader on the CanvasGroup. Somehow this has the same issue where it doesn't have the pixels from the TileMapLayer, but with an added bonus of making everything a big white square. Is there any validity in this approach?

2c: I've tried putting my TileMapLayer in a SubViewport and adding a Sprite2D with a ViewportTexture and putting the shader on the Sprite2D. Maybe this will work, I don't know, but I have way too many issues trying to line things up so that my tiles all show on screen and also are in the same place that they are supposed to be that I gave up.] This approach seems too heavy-handed. If anyone thinks it will work I'd be happy to elaborate on how I had problems making things fit.

9
10
 
 

Hello, everyone! We already had a shader that transformed an image into an old photograph, and this time we’ll take that effect to the next level. I’ll show how a similar approach can be used to simulate old film played through a low-quality projector, meaning that various visual imperfections will also change over time.

11
 
 

Newbie, want to make a point system in my dress up game in godot for endings

Hello, just so you know, I'm a newbie in programming in general, so I ask you to be easy on me even if the question is resolved just by going through the docs (already did that, still have hard time understanding it).

I'm working on a dress-up game that has a character that won't want to wear certain clothes and if there are clothes on him that he doesn't like, the game will lead to a bad-ending scene and vice-versa.

I can search how to make events lead to changing a scene by myself. The actual questions are:

  1. How do I group the clothes properly (I think I should look up global groups on docs here)?

  2. How do I make points reset when clothes are dragged away from their perfect position (i.e. on character sprite)?

  3. How do I make clothes correspond with eachother for the point system (explained further)?

Current issues

I'm away from my laptop, so can't provide exact code for now, so I'll do my best to explain

The code I'm using is from this tutorial

Pastebin with the drag and drop function itself as well

What I tried to do is a boolean @export for bad and good clothes, then go through if-elif statements for them in a drag and drop code, which sorta works, but:

  1. Points get attributed only to one clothing (for example: I drag a yellow shirt as a good clothing type and get +1 to the point variable (therefore it is =1), but when I drag pants from the same type, it doesn't consider previous +1 and stays =1)

  2. Points don't reset after clothes being reattached (if I drag away said yellow shirt and drag it back to the perfect position, it still will add a +1 and the point variable will equal 2 and so on)

@godot

#godot #duckduckfedi #askfedi

12
13
14
 
 

UPDATE: The consensus seems to be overwhelmingly in favour of the match variant. And not to worry, I have replaced the magic numbers with an enum. Will try to remember to merge the branch tomorrow

Does an if-statement block or a switch statement fit better here? For context (and advertisement), this is part of my all-purpose utility plugin ( Codeberg link)

The code:

		# Method 1 (Yandere Dev Technique)  
		if self.throw_errors and status==MpupTest.TESTSTATUS.ERROR:  
			push_error(result)  
		if self.throw_warnings and status==MpupTest.TESTSTATUS.WARNING:  
			push_warning(result)  
		
		# Method 2 (Pirate Software Technique)  
		match status:  
			MpupTest.TESTSTATUS.ERROR:  
				if self.throw_errors:  
					push_error(result)  
			MpupTest.TESTSTATUS.WARNING:  
				if self.throw_warnings:  
					push_warning(result)  
15
16
17
18
19
 
 

Hello, everyone! This time let’s make something a bit simpler, so we can take a break from overly long videos. I will create an infinite tunnel using a so-called Menger sponge, which is a three-dimensional fractal that we'll project onto a two-dimensional plane.

20
21
 
 

This may be interesting for people to read. Just a warning, all AGPL, so using this code snippets will make your source open. Hope you like the reading.

22
23
24
 
 

Hello, everyone! On this channel, I’ve been creating Godot shaders of all kinds, but there’s one type I’ve ignored until now - so it’s time to fix that. It’s the shader_type particles, and as the name suggests, we’ll apply it to a GPUParticles3D node. So let’s take a look at how we can create a simulation of insects flying around a light in the fog.

25
view more: next ›