Adding stigi - no superposition in shader

This commit is contained in:
yannk 2022-04-13 13:08:40 +02:00
parent a845088619
commit 3dd5d7edd8
4 changed files with 62 additions and 3 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=23 format=3 uid="uid://b8p2h0rmwy7qn"] [gd_scene load_steps=24 format=3 uid="uid://b8p2h0rmwy7qn"]
[ext_resource type="Material" uid="uid://dpegsmygxcfmv" path="res://maps/materials/basic_ground.material" id="1_lodye"] [ext_resource type="Material" uid="uid://dpegsmygxcfmv" path="res://maps/materials/basic_ground.material" id="1_lodye"]
[ext_resource type="Shader" path="res://maps/shaders/khanat_sky.gdshader" id="1_mheqi"] [ext_resource type="Shader" path="res://maps/shaders/khanat_sky.gdshader" id="1_mheqi"]
@ -6,6 +6,7 @@
[ext_resource type="PackedScene" uid="uid://cveshwnu272vf" path="res://maps/objects/ramp-complex.tscn" id="2_4eueh"] [ext_resource type="PackedScene" uid="uid://cveshwnu272vf" path="res://maps/objects/ramp-complex.tscn" id="2_4eueh"]
[ext_resource type="Texture2D" uid="uid://y0ka7tysfp6b" path="res://maps/textures/zabr_tex_001.png" id="3_bgghj"] [ext_resource type="Texture2D" uid="uid://y0ka7tysfp6b" path="res://maps/textures/zabr_tex_001.png" id="3_bgghj"]
[ext_resource type="PackedScene" uid="uid://omess6wwwwcq" path="res://maps/objects/ramp-moving.tscn" id="3_bvbgo"] [ext_resource type="PackedScene" uid="uid://omess6wwwwcq" path="res://maps/objects/ramp-moving.tscn" id="3_bvbgo"]
[ext_resource type="Texture2D" uid="uid://dlxp52r0wnwlq" path="res://maps/textures/stigi_tex_001.png" id="3_jqgsm"]
[ext_resource type="PackedScene" uid="uid://dvsl8x3lb1h4e" path="res://maps/objects/moutain.tscn" id="3_rbp35"] [ext_resource type="PackedScene" uid="uid://dvsl8x3lb1h4e" path="res://maps/objects/moutain.tscn" id="3_rbp35"]
[ext_resource type="PackedScene" path="res://maps/objects/cave.tscn" id="4_pc85h"] [ext_resource type="PackedScene" path="res://maps/objects/cave.tscn" id="4_pc85h"]
[ext_resource type="PackedScene" uid="uid://b61edh0bre65c" path="res://maps/objects/ramp.tscn" id="5_dfm8h"] [ext_resource type="PackedScene" uid="uid://b61edh0bre65c" path="res://maps/objects/ramp.tscn" id="5_dfm8h"]
@ -34,8 +35,11 @@ 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.584, -0.995)
shader_param/zabr_arc = 15.0 shader_param/zabr_arc = 15.0
shader_param/zabr_position = Vector3(0.6, 0.03, -0.342) 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/samayun = ExtResource( "1_thm7k" ) shader_param/samayun = ExtResource( "1_thm7k" )
shader_param/zabr = ExtResource( "3_bgghj" ) shader_param/zabr = ExtResource( "3_bgghj" )
shader_param/stigi = ExtResource( "3_jqgsm" )
[sub_resource type="Sky" id="Sky_fa16p"] [sub_resource type="Sky" id="Sky_fa16p"]
sky_material = SubResource( "ShaderMaterial_s2q0l" ) sky_material = SubResource( "ShaderMaterial_s2q0l" )

View file

@ -19,13 +19,17 @@ uniform float dither_strength : hint_range(0, 10) = 1.0;
uniform sampler2D night_sky : hint_black_albedo; uniform sampler2D night_sky : hint_black_albedo;
uniform sampler2D samayun : hint_albedo; uniform sampler2D samayun : hint_albedo;
uniform float samayun_arc = 25 ; uniform float samayun_arc = 45 ;
uniform vec3 samayun_position = vec3( 0.0, 0.5, 0.0 ); uniform vec3 samayun_position = vec3( 0.0, 0.5, 0.0 );
uniform sampler2D zabr : hint_albedo; uniform sampler2D zabr : hint_albedo;
uniform float zabr_arc = 12 ; uniform float zabr_arc = 15 ;
uniform vec3 zabr_position = vec3( 0.0, 0.7, 0.0 ); uniform vec3 zabr_position = vec3( 0.0, 0.7, 0.0 );
uniform sampler2D stigi : hint_albedo;
uniform float stigi_arc = 8 ;
uniform vec3 stigi_position = vec3( 0.0, 0.8, 0.0 );
const vec3 UP = vec3( 0.0, 1.0, 0.0 ); const vec3 UP = vec3( 0.0, 1.0, 0.0 );
// Sun constants // Sun constants
@ -104,6 +108,7 @@ void sky() {
// Calculate respective scales of celestial objects // Calculate respective scales of celestial objects
float samayun_scale = radians(samayun_arc) ; float samayun_scale = radians(samayun_arc) ;
float zabr_scale = radians(zabr_arc) ; float zabr_scale = radians(zabr_arc) ;
float stigi_scale = radians(stigi_arc) ;
// Adding Samayun // 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
@ -135,4 +140,19 @@ void 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; 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;
} }
} }
// Adding stigi
if (length(EYEDIR - normalize(stigi_position)) < stigi_scale / 2.0) { // we are in the area of the sky where stigi is placed
//We define a local plane tangent to the skydome at stigi_position
//We work with everything normalized
vec3 s_n1 = normalize(cross(stigi_position,vec3(0.0,1.0,0.0))) ;
vec3 s_n2 = normalize(cross(stigi_position,s_n1)) ;
//We project EYEDIR on this plane with an approximate correction for projection
float s_x = dot(EYEDIR,s_n1) * 0.89 ;
float s_y = dot(EYEDIR,s_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(stigi_position)){
} else { // Add stigi to the sky
COLOR += texture(stigi, vec2(s_x,s_y) / stigi_scale + vec2(0.5)).rgb * texture(stigi, vec2(s_x,s_y) / stigi_scale + vec2(0.5)).a;
}
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 913 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dlxp52r0wnwlq"
path.s3tc="res://.godot/imported/stigi_tex_001.png-422a9b36925acddfd148694fe140318a.s3tc.ctex"
path.etc2="res://.godot/imported/stigi_tex_001.png-422a9b36925acddfd148694fe140318a.etc2.ctex"
metadata={
"imported_formats": ["s3tc", "etc2"],
"vram_texture": true
}
[deps]
source_file="res://maps/textures/stigi_tex_001.png"
dest_files=["res://.godot/imported/stigi_tex_001.png-422a9b36925acddfd148694fe140318a.s3tc.ctex", "res://.godot/imported/stigi_tex_001.png-422a9b36925acddfd148694fe140318a.etc2.ctex"]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/size_limit=0
detect_3d/compress_to=0