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

HXSL return in entry-point methods breaks shaders #1213

Open
Yanrishatum opened this issue May 18, 2024 · 0 comments
Open

HXSL return in entry-point methods breaks shaders #1213

Yanrishatum opened this issue May 18, 2024 · 0 comments

Comments

@Yanrishatum
Copy link
Contributor

Honestly not sure if it's a bug or just wrong usage, but it definitely should be handled either at compile time or runtime in one way or another.
Having a return; inside fragment or vertex methods would cause shaders to break, as it would exit before outputs are properly assigned. I'd suggest making it a compile time error if return; statement is used inside entry-point methods.

Source: Haxe#Heaps Discord message by kevansevans

Shader code
class InfGridShader extends Shader
{
    
    static var SRC = {
        
        @:import h3d.shader.Texture;
        
        @param var size:Int = 1;
        @param var scale:Float = 1;
        
        @param var offset_x:Float = 0;
        @param var offset_y:Float = 0;
        
        @param var ratioX:Float = 1;
        @param var ratioY:Float = 1;
        
        function vertex()
        {
            calculatedUV = input.uv;
        }
        
        function fragment()
        {
            var uvOffset:Vec2 = calculatedUV;
            
            var copy:Vec4 = pixelColor; //commenting this out completely breaks it for some reason
            
            var alph:Float = min((size * (1 / scale)) / 3, 0.5);
                
            if (((uvOffset.x - 0.5) / ratioX) % (size * (1 / scale)) <= 0.01)
            {
                pixelColor = vec4(1, 1, 1, 1.0);
                return;
            }
            else if (((uvOffset.y - 0.5) / ratioY) % (size * (1 / scale)) <= 0.01) {
                pixelColor = vec4(1, 1, 1, 1);
                return;
            }
        }
    }
    
    public function new()
    {
        super();
    }
    
}

-D shader_debug_dump dump: 5_dump.txt

Produced fragment shader:

void main(void) {
	pixelColor = fragmentParams[0];
	uvOffset = calculatedUV_varying;
	if( mod(((uvOffset.x - 0.5) / fragmentParams[1].z), (float(int(fragmentParams[1].x)) * (1. / fragmentParams[1].y))) <= 0.01) {
		pixelColor = vec4(1., 1., 1., 1.);
		return;
	} else {
		if( mod(((uvOffset.y - 0.5) / fragmentParams[1].w), (float(int(fragmentParams[1].x)) * (1. / fragmentParams[1].y))) <= 0.01) {
			pixelColor = vec4(1., 1., 1., 1.);
			return;
		};
	};
	lightPixelColor = fragmentGlobals[0].xyz;
	pixelColor.xyz *= _val0();
	color2 = pixelColor;
	OUTPUT1 = color2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant