Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow usage of discard inside custom shader functions #93590

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

Chaosus
Copy link
Member

@Chaosus Chaosus commented Jun 25, 2024

Since #93358 got merged (which introduced call hierarchy checking), it's now easily possible to allow a user to use a discard keyword in custom user function in spatial/canvas_item shader types:

custom_func_discard

@Chaosus Chaosus requested a review from a team as a code owner June 25, 2024 12:45
@Chaosus Chaosus force-pushed the shader_custom_func_discard branch 3 times, most recently from 702020a to 3b168fb Compare June 25, 2024 13:29
@AThousandShips AThousandShips added this to the 4.x milestone Jun 25, 2024
@djrain
Copy link

djrain commented Jul 14, 2024

Is it possible to allow access to UV / SCREEN_UV and sdf functions as well? Just ran into this.

@Chaosus
Copy link
Member Author

Chaosus commented Jul 15, 2024

@djrain SDF functions (stage) are implemented in another PR : #93650, UV/SCREEN_UV still not.

@Chaosus Chaosus modified the milestones: 4.x, 4.4 Jul 17, 2024
@Chaosus Chaosus requested a review from Calinou July 18, 2024 20:33
@Chaosus Chaosus force-pushed the shader_custom_func_discard branch from 3b168fb to f81a720 Compare July 24, 2024 08:49
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally (rebased on top of master 44fa552), it works as expected.

shader_type spatial;

void checkerboard(vec2 frag_coord) {
	if (int(frag_coord.x + frag_coord.y) % 2 == 0) {
		discard;
	}
}

void fragment() {
	checkerboard(FRAGCOORD.xy);
}

image

If you try to call the function in vertex(), it fails as expected:

image

Or if you try to call discard directly in vertex():

image

@Chaosus Chaosus merged commit ff9fb0a into godotengine:master Oct 24, 2024
20 checks passed
@Chaosus Chaosus deleted the shader_custom_func_discard branch October 24, 2024 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants