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

imports = {
	eye_vector = { 
		type = "float3"
		domain = "vertex"
		output_channel = "eye_vector"
	}

	fog_color = {
		type = "float3"
		domain = "global"
		source = "shading_environment"
	}

	sun_direction = {
		type = "float3"
		domain = "global"
		source = "shading_environment"
	}

	sun_color = {
		type = "float3"
		domain = "global"
		source = "engine"
	}

	fog_sun_blend = {
		type = "float3"
		domain = "global"
		source = "shading_environment"
	}

	/*
	// TODO
	custom_fog_blend_direction = {
		type = "float3"
		domain = "global"
		source = "shading_environment"
	}

	custom_fog_blend_color = {
		type = "float3"
		domain = "global"
		source = "shading_environment"
	}

	custom_fog_blend = {
		type = "float3"
		domain = "global"
		source = "shading_environment"
	}

	secondary_sun_direction = {
		type = "float3"
		domain = "global"
		source = "shading_environment"
	}

	secondary_sun_color = {
		type = "float3"
		domain = "global"
		source = "shading_environment"
	}

	secondary_sun_blend = {
		type = "float3"
		domain = "global"
		source = "shading_environment"
	}*/
}

defines = ["NEEDS_EYE_VECTOR", "HAS_SUN_COLOR"] 

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

options = {
	"44123bdc-7a38-4a69-b738-ad93e819f28c" = "SECONDARY_SUN_BLEND"
	"f169202d-4a88-4347-8f26-af46d249a5f6" = "CUSTOM_FOG_BLEND"
}

ui = [
	{ type = "checkbox" display_name = "Secondary sun blend" 	option = "44123bdc-7a38-4a69-b738-ad93e819f28c" }
	{ type = "checkbox" display_name = "Custom fog blend" 		option = "f169202d-4a88-4347-8f26-af46d249a5f6" }
]

language = "hlsl"
code = """
	float3 view_dir = normalize(eye_vector);
	
	half sa = 0.0;
	float3 c = fog_color;

	/*#if defined(SECONDARY_SUN_BLEND)
		sa = secondary_sun_blend.x * pow(saturate(dot(view_dir, secondary_sun_direction)), secondary_sun_blend.y);
		c = lerp(c, secondary_sun_blend.z * secondary_sun_color, sa);
	#endif	

	#if defined(CUSTOM_FOG_BLEND)
		sa = custom_fog_blend.x * pow(saturate(dot(view_dir, custom_fog_blend_direction)), custom_fog_blend.y);
		c = lerp(c, custom_fog_blend.z * custom_fog_blend_color, sa);
	#endif*/
				
	sa = fog_sun_blend.x * pow(saturate(dot(view_dir, sun_direction)), fog_sun_blend.y);
	c = lerp(c, fog_sun_blend.z * sun_color, sa);		

	RESULT(float4(c, sa));
"""

