Adding respective distance zabr and samayun for display priority in the sky

This commit is contained in:
yannk 2022-04-13 12:40:14 +02:00
parent e9aeddbf28
commit a845088619
2 changed files with 24 additions and 16 deletions

View file

@ -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/ground_color = Color(0.1, 0.07, 0.034, 1)
shader_param/exposure = 0.1 shader_param/exposure = 0.1
shader_param/dither_strength = 1.0 shader_param/dither_strength = 1.0
shader_param/samayun_arc = 25.0 shader_param/samayun_arc = 50.0
shader_param/samayun_position = Vector3(2.038, 0.584, -0.185) shader_param/samayun_position = Vector3(2.038, 0.584, -0.995)
shader_param/zabr_arc = null shader_param/zabr_arc = 15.0
shader_param/zabr_position = Vector3(0.812, 0.345, 0.263) shader_param/zabr_position = Vector3(0.6, 0.03, -0.342)
shader_param/samayun = ExtResource( "1_thm7k" ) shader_param/samayun = ExtResource( "1_thm7k" )
shader_param/zabr = ExtResource( "3_bgghj" ) shader_param/zabr = ExtResource( "3_bgghj" )

View file

@ -101,30 +101,38 @@ void sky() {
COLOR = texture(night_sky, SKY_COORDS).xyz * 0.04; COLOR = texture(night_sky, SKY_COORDS).xyz * 0.04;
COLOR *= exposure; COLOR *= exposure;
} }
// Adding Samayun // Calculate respective scales of celestial objects
float samayun_scale = radians(samayun_arc) ; 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 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 define a local plane tangent to the skydome at samayun_position
//We work with everything normalized //We work with everything normalized
vec3 n1 = normalize(cross(samayun_position,vec3(0.0,1.0,0.0))) ; vec3 n1 = normalize(cross(samayun_position,vec3(0.0,1.0,0.0))) ;
vec3 n2 = normalize(cross(samayun_position,n1)) ; vec3 n2 = normalize(cross(samayun_position,n1)) ;
//We project EYEDIR on this plane //We project EYEDIR on this plane with an approximate correction for projection
float x = dot(EYEDIR,n1) ; float x = dot(EYEDIR,n1) * 0.89 ;
float y = dot(EYEDIR,n2) ; float y = dot(EYEDIR,n2) * 0.89 ;
// We then add the final result to the sky // If zabr is nearer at this place, do nothing
COLOR += texture(samayun, vec2(x,y) / samayun_scale + vec2(0.5)).rgb * texture(samayun, vec2(x,y) / samayun_scale + vec2(0.5)).a; 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 // 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 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 define a local plane tangent to the skydome at zabr_position
//We work with everything normalized //We work with everything normalized
vec3 z_n1 = normalize(cross(zabr_position,vec3(0.0,1.0,0.0))) ; vec3 z_n1 = normalize(cross(zabr_position,vec3(0.0,1.0,0.0))) ;
vec3 z_n2 = normalize(cross(zabr_position,z_n1)) ; vec3 z_n2 = normalize(cross(zabr_position,z_n1)) ;
//We project EYEDIR on this plane //We project EYEDIR on this plane with an approximate correction for projection
float z_x = dot(EYEDIR,z_n1) ; float z_x = dot(EYEDIR,z_n1) * 0.89 ;
float z_y = dot(EYEDIR,z_n2) ; float z_y = dot(EYEDIR,z_n2) * 0.89 ;
// We then add the final result to the sky // If samayun is nearer at this place, do nothing
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; 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;
}
} }
} }