group = "Skydome"
display_name = "Skydome Color"
depends_on = ["core/stingray_renderer/output_nodes/skydome_base"]

inputs = {
	"33d9da7d-4833-40a3-84d9-c88daa3b2c1e" = { name = "texcoord" display_name = "UV" type = "vector2" domain = "pixel" }
}

imports = {
	skydome_u_offset = {
		type = "float"
		domain = "global"
		source = "shading_environment"
	}

	skydome_intensity = {
		type = "float"
		domain = "global"
		source = "shading_environment"
	}
}


domain = "pixel"
output = {
	type = "float4"
}

options = {
	"e333e9d1-0cb9-4caa-a40e-d212b375c777" = "ADDRESS_CLAMP"
	"6599f9bf-2828-4b29-a20f-2f78e991862b" = "ADDRESS_WRAP"
	"b5ec6d15-ed64-4c8a-b850-5c269a296f4a" = "FILTER_LINEAR"
	"4f6b3270-b92a-433a-88e4-b2a3d015bd8a" = "FILTER_POINT"
	"f7162c47-1353-4a4c-adfc-5b52dedc6053" = "FILTER_ANISOTROPIC"
	"2392b33c-e963-4553-bebd-066f2a27bc30" = "SRGB"
    "cf74777c-db6d-4ccc-b20a-801302770d6d" = "LINEAR"
    "1f9c9f28-91ea-4bc9-ad22-f099146fead1" = "RGBM_DECODE"
}

ui = [
	{
		type = "drop_down"
		display_name = "Encoding"
		options = {
			"Linear Color" 	= "cf74777c-db6d-4ccc-b20a-801302770d6d"
			"sRGB Color" 	= "2392b33c-e963-4553-bebd-066f2a27bc30"
			"RGBM Color" 	= "1f9c9f28-91ea-4bc9-ad22-f099146fead1"
		}
		default = "cf74777c-db6d-4ccc-b20a-801302770d6d"
	}
	{
		type = "drop_down"
		display_name = "Address mode"
		options = {
			"Clamp" = "e333e9d1-0cb9-4caa-a40e-d212b375c777"
			"Wrap" 	= "6599f9bf-2828-4b29-a20f-2f78e991862b"
		}
		default = "6599f9bf-2828-4b29-a20f-2f78e991862b"
	}
	{
		type = "drop_down"
		display_name = "Filter mode"
		options = {
			"Anisotropic" 	= "f7162c47-1353-4a4c-adfc-5b52dedc6053"
			"Linear" 		= "b5ec6d15-ed64-4c8a-b850-5c269a296f4a"
			"Point" 		= "4f6b3270-b92a-433a-88e4-b2a3d015bd8a"
		}
		default = "b5ec6d15-ed64-4c8a-b850-5c269a296f4a"
	}
]

code_blocks = {
	default = {
		language = "hlsl"
		samplers = {
			skydome_map = {
				sampler_state = "core/shader_nodes/graph_common#default_node_sampler"
				source = "resource_set"
				slot_name = "skydome_map"
				type = "2d"
			}
		}

		code = """
			float4 skydome_color = TEX2D(skydome_map, texcoord + float2(skydome_u_offset, 0));

			#if defined(RENDERER_GL) && defined(SRGB)
				skydome_color = fast_gamma_to_linear_rgba(skydome_color);
			#elif defined(RGBM_DECODE)
				skydome_color = float4(rgbm_decode(skydome_color), 0);
			#endif

			skydome_color.rgb *= skydome_intensity;

			RESULT(skydome_color);
		"""
	}
}
