From d91b9ea1262f7459630c61db8d0c4bf508bd1c34 Mon Sep 17 00:00:00 2001 From: yannk Date: Thu, 14 Apr 2022 17:41:23 +0200 Subject: [PATCH] Managing superposition of celestial objects in passing over each other --- maps/basic_setup.tscn | 8 +++---- maps/shaders/khanat_sky.gdshader | 41 ++++++++++++++++---------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/maps/basic_setup.tscn b/maps/basic_setup.tscn index bbc1fd5..cb23d2e 100644 --- a/maps/basic_setup.tscn +++ b/maps/basic_setup.tscn @@ -32,11 +32,11 @@ 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 = 50.0 -shader_param/samayun_position = Vector3(2.038, 0.584, -0.995) +shader_param/samayun_position = Vector3(2.038, 0.695, -0.296) shader_param/zabr_arc = 15.0 -shader_param/zabr_position = Vector3(0.6, 0.03, -0.342) -shader_param/stigi_arc = null -shader_param/stigi_position = Vector3(0.688, 0.03, -0.342) +shader_param/zabr_position = Vector3(1.755, 0.627, 0.768) +shader_param/stigi_arc = 8.381 +shader_param/stigi_position = Vector3(0.925, 0.277, 0.17) shader_param/samayun = ExtResource( "1_thm7k" ) shader_param/zabr = ExtResource( "3_bgghj" ) shader_param/stigi = ExtResource( "3_jqgsm" ) diff --git a/maps/shaders/khanat_sky.gdshader b/maps/shaders/khanat_sky.gdshader index 9e88927..6f45e37 100644 --- a/maps/shaders/khanat_sky.gdshader +++ b/maps/shaders/khanat_sky.gdshader @@ -58,8 +58,8 @@ vec2 place_object(vec3 position, vec3 eyedir){ vec3 n1 = normalize(cross(position,vec3(0.0,1.0,0.0))) ; vec3 n2 = normalize(cross(position,n1)) ; //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 ; + float x = dot(eyedir,n1) * 0.9 ; + float y = dot(eyedir,n2) * 0.9 ; return vec2(x, y); } @@ -121,34 +121,35 @@ void sky() { float samayun_scale = radians(samayun_arc) ; float zabr_scale = radians(zabr_arc) ; float stigi_scale = radians(stigi_arc) ; - + // Calculate respective plane with UV to place celestial object textures vec2 samayun_uv = place_object(samayun_position, EYEDIR) ; vec2 zabr_uv = place_object(zabr_position, EYEDIR) ; vec2 stigi_uv = place_object(stigi_position, EYEDIR) ; - - // Adding Samayun + + // Adding the celestial objects from the nearest to the farest + // Adding stigi + if (length(EYEDIR - normalize(stigi_position)) < stigi_scale / 2.0){ // we are in the area of the sky where stigi is placed + COLOR += texture(stigi, stigi_uv / stigi_scale + vec2(0.5)).rgb * texture(stigi, stigi_uv / stigi_scale + vec2(0.5)).a; + } + // Adding samayun if (length(EYEDIR - normalize(samayun_position)) < samayun_scale / 2.0) { // we are in the area of the sky where samayun is placed - // 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 + if (length(EYEDIR - normalize(stigi_position)) < stigi_scale / 2.0){ // if stigi is in front of samayun, don’t draw where stigi alpha is > 0 + COLOR += texture(samayun, samayun_uv / samayun_scale + vec2(0.5)).rgb * max((texture(samayun, samayun_uv / samayun_scale + vec2(0.5)).a - texture(stigi, stigi_uv / stigi_scale + vec2(0.5)).a), 0.0) ; + } else { COLOR += texture(samayun, samayun_uv / samayun_scale + vec2(0.5)).rgb * texture(samayun, samayun_uv / samayun_scale + vec2(0.5)).a; } } // Adding zabr if (length(EYEDIR - normalize(zabr_position)) < zabr_scale / 2.0) { // we are in the area of the sky where zabr is placed - // 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 + if (length(EYEDIR - normalize(samayun_position)) < samayun_scale / 2.0){ // if samayun is in front of zabr, don’t draw where samayun alpha is > 0 + COLOR += texture(zabr, zabr_uv / zabr_scale + vec2(0.5)).rgb * max((texture(zabr, zabr_uv / zabr_scale + vec2(0.5)).a - texture(samayun, samayun_uv / samayun_scale + vec2(0.5)).a), 0.0); + } else { + if (length(EYEDIR - normalize(stigi_position)) < stigi_scale / 2.0){ // if stigi is in front of zabr, don’t draw where its alpha is > 0 + COLOR += texture(zabr, zabr_uv / zabr_scale + vec2(0.5)).rgb * (texture(zabr, zabr_uv / zabr_scale + vec2(0.5)).a - texture(stigi, stigi_uv / stigi_scale + vec2(0.5)).a); + } else { COLOR += texture(zabr, zabr_uv / zabr_scale + vec2(0.5)).rgb * texture(zabr, zabr_uv / zabr_scale + vec2(0.5)).a; - } - } - // Adding stigi - if (length(EYEDIR - normalize(stigi_position)) < stigi_scale / 2.0) { // we are in the area of the sky where stigi is placed - // If samayun is nearer at this place, do nothing - if (length(EYEDIR - normalize(samayun_position)) < samayun_scale / 2.0 && length(samayun_position) < length(stigi_position)){ - } else { // Add stigi to the sky - COLOR += texture(stigi, stigi_uv / stigi_scale + vec2(0.5)).rgb * texture(stigi, stigi_uv / stigi_scale + vec2(0.5)).a; - } + } } + } }