From a8450886191ae10830fec2eb7ef2678d7a8743b6 Mon Sep 17 00:00:00 2001 From: yannk Date: Wed, 13 Apr 2022 12:40:14 +0200 Subject: [PATCH] Adding respective distance zabr and samayun for display priority in the sky --- maps/basic_setup.tscn | 8 ++++---- maps/shaders/khanat_sky.gdshader | 32 ++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/maps/basic_setup.tscn b/maps/basic_setup.tscn index 40fd63a..1bdd5b8 100644 --- a/maps/basic_setup.tscn +++ b/maps/basic_setup.tscn @@ -30,10 +30,10 @@ shader_param/sun_disk_scale = 1.0 shader_param/ground_color = Color(0.1, 0.07, 0.034, 1) shader_param/exposure = 0.1 shader_param/dither_strength = 1.0 -shader_param/samayun_arc = 25.0 -shader_param/samayun_position = Vector3(2.038, 0.584, -0.185) -shader_param/zabr_arc = null -shader_param/zabr_position = Vector3(0.812, 0.345, 0.263) +shader_param/samayun_arc = 50.0 +shader_param/samayun_position = Vector3(2.038, 0.584, -0.995) +shader_param/zabr_arc = 15.0 +shader_param/zabr_position = Vector3(0.6, 0.03, -0.342) shader_param/samayun = ExtResource( "1_thm7k" ) shader_param/zabr = ExtResource( "3_bgghj" ) diff --git a/maps/shaders/khanat_sky.gdshader b/maps/shaders/khanat_sky.gdshader index b1335e4..1bb102b 100644 --- a/maps/shaders/khanat_sky.gdshader +++ b/maps/shaders/khanat_sky.gdshader @@ -101,30 +101,38 @@ void sky() { COLOR = texture(night_sky, SKY_COORDS).xyz * 0.04; COLOR *= exposure; } - // Adding Samayun + // Calculate respective scales of celestial objects float samayun_scale = radians(samayun_arc) ; + float zabr_scale = radians(zabr_arc) ; + + // Adding Samayun if (length(EYEDIR - normalize(samayun_position)) < samayun_scale / 2.0) { // we are in the area of the sky where samayun is placed //We define a local plane tangent to the skydome at samayun_position //We work with everything normalized vec3 n1 = normalize(cross(samayun_position,vec3(0.0,1.0,0.0))) ; vec3 n2 = normalize(cross(samayun_position,n1)) ; - //We project EYEDIR on this plane - float x = dot(EYEDIR,n1) ; - float y = dot(EYEDIR,n2) ; - // We then add the final result to the sky - COLOR += texture(samayun, vec2(x,y) / samayun_scale + vec2(0.5)).rgb * texture(samayun, vec2(x,y) / samayun_scale + vec2(0.5)).a; + //We project EYEDIR on this plane with an approximate correction for projection + float x = dot(EYEDIR,n1) * 0.89 ; + float y = dot(EYEDIR,n2) * 0.89 ; + // If zabr is nearer at this place, do nothing + if (length(EYEDIR - normalize(zabr_position)) < zabr_scale / 2.0 && length(zabr_position) < length(samayun_position)){ + } else { // // Add samayun to the sky + COLOR += texture(samayun, vec2(x,y) / samayun_scale + vec2(0.5)).rgb * texture(samayun, vec2(x,y) / samayun_scale + vec2(0.5)).a; + } } // Adding zabr - float zabr_scale = radians(zabr_arc) ; if (length(EYEDIR - normalize(zabr_position)) < zabr_scale / 2.0) { // we are in the area of the sky where zabr is placed //We define a local plane tangent to the skydome at zabr_position //We work with everything normalized vec3 z_n1 = normalize(cross(zabr_position,vec3(0.0,1.0,0.0))) ; vec3 z_n2 = normalize(cross(zabr_position,z_n1)) ; - //We project EYEDIR on this plane - float z_x = dot(EYEDIR,z_n1) ; - float z_y = dot(EYEDIR,z_n2) ; - // We then add the final result to the sky - COLOR += texture(zabr, vec2(z_x,z_y) / zabr_scale + vec2(0.5)).rgb * texture(zabr, vec2(z_x,z_y) / zabr_scale + vec2(0.5)).a; + //We project EYEDIR on this plane with an approximate correction for projection + float z_x = dot(EYEDIR,z_n1) * 0.89 ; + float z_y = dot(EYEDIR,z_n2) * 0.89 ; + // If samayun is nearer at this place, do nothing + if (length(EYEDIR - normalize(samayun_position)) < samayun_scale / 2.0 && length(samayun_position) < length(zabr_position)){ + } else { // Add zabr to the sky + COLOR += texture(zabr, vec2(z_x,z_y) / zabr_scale + vec2(0.5)).rgb * texture(zabr, vec2(z_x,z_y) / zabr_scale + vec2(0.5)).a; + } } }