Harbor

branch main
showing the latest snapshot on main
spec_constant.luma 835 B · Plain text
gpu/shader/tests/shaders/spec_constant.luma 0644 Raw
-- Test: Specialization constants across all backends

@spec(0) const NUM_LIGHTS: int = 4
@spec(1) const BRIGHTNESS: float = 1.0
@spec(2) const USE_GAMMA: bool = true

struct Uniforms
	base_color: vec3
	ambient: float
end

@varying
struct VertexOutput
	@builtin(position) position: vec4
end

@group(0) @binding(0) uniform uniforms: Uniforms

@entry(vertex)
function vs_main(@location(0) position: vec3) -> VertexOutput
	return VertexOutput {
		position = vec4(position, 1.0),
	}
end

@entry(fragment)
function fs_main(@location(0) frag_coord: vec4) -> (color: vec4)
	let color = uniforms.base_color * uniforms.ambient

	-- Use spec constants in computation
	let i = 0
	while i < NUM_LIGHTS do
		color = color + vec3(0.1, 0.1, 0.1)
		i = i + 1
	end

	color = color * BRIGHTNESS

	return _fs_main_Output { color = vec4(color, 1.0) }
end