initial push

This commit is contained in:
itdominator 2024-04-28 16:51:22 -05:00
parent 11d7ae7b5b
commit 1087c53425
33 changed files with 944 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# state-machine
Note that most of these are stub scripts and have yet to be setup with logic.
The following (not complete list) are not stubs but do view/use with a grain of salt.
* dead.gd
* moving-to-target.gd
* persuing-fag.gd
* shooting.gd
* moving-to-cp.gd
* shooting.gd
* walking.gd

View File

@ -0,0 +1,14 @@
class_name CPState extends State
func enter():
pass
func exit():
pass
func update(_delta: float):
pass
func physics_update(_delta: float):
pass

View File

@ -0,0 +1,15 @@
class_name CPAttackers extends CPState
func process_idle():
pass
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,15 @@
class_name CPContested extends CPState
func process_idle():
pass
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,15 @@
class_name CPDefenders extends CPState
func process_idle():
pass
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,15 @@
class_name CPNeutral extends CPState
func process_idle():
pass
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,15 @@
class_name CPNonAligned extends CPState
func process_idle():
pass
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,14 @@
class_name EntityState extends State
func enter():
pass
func exit():
pass
func update(_delta: float):
pass
func physics_update(_delta: float):
pass

View File

@ -0,0 +1,15 @@
class_name Aiming extends EntityState
func process_idle():
anim_player.play(entity.IDLE_ANIM, 0.2)
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,15 @@
class_name BoidFlocking extends EntityState
func process_idle():
anim_player.play(entity.IDLE_ANIM, 0.2)
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,12 @@
class_name Dead extends EntityState
func process_dead():
entity.set_physics_process(false)
entity.set_process(false)
anim_player.stop()
entity.emit_has_died()
func enter():
process_dead()

View File

@ -0,0 +1,15 @@
class_name DefendingCP extends EntityState
func process_idle():
anim_player.play(entity.IDLE_ANIM, 0.2)
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,15 @@
class_name EscortingFlag extends EntityState
func process_idle():
anim_player.play(entity.IDLE_ANIM, 0.2)
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,15 @@
class_name Evading extends EntityState
func process_idle():
anim_player.play(entity.IDLE_ANIM, 0.2)
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,15 @@
class_name Idle extends EntityState
func process_idle():
anim_player.play(entity.IDLE_ANIM, 0.2)
func enter():
entity.emit_request_task()
func update(_delta: float):
pass
func physics_update(_delta: float):
process_idle()

View File

@ -0,0 +1,15 @@
class_name MovingFlag extends EntityState
func process_idle():
anim_player.play(entity.IDLE_ANIM, 0.2)
func enter():
pass
func update(delta: float):
pass
func physics_update(delta: float):
process_idle()

View File

@ -0,0 +1,32 @@
class_name Moving2CP extends EntityState
func process_idle(delta: float):
var target_pos = entity.target_cp.global_position
var distance_to = entity.global_position.distance_to(target_pos)
if distance_to > entity.MAX_DISTANCE_TO:
entity.look_at(target_pos, Vector3.UP)
apply_acceleration(delta, (target_pos - entity.global_position).normalized())
else:
transitioned.emit(self, "idle")
func apply_acceleration(delta: float, direction: Vector3 = Vector3.ZERO):
anim_player.play(entity.MOVEMENT_ANIM, 0.2)
entity.velocity.x = move_toward(entity.velocity.x, entity.SPEED * direction.x, entity.ACCELERATION * delta)
entity.velocity.z = move_toward(entity.velocity.z, entity.SPEED * direction.z, entity.ACCELERATION * delta)
func enter():
pass
func exit():
entity.target_cp = null
func update(_delta: float):
pass
func physics_update(delta: float):
process_idle(delta)

View File

@ -0,0 +1,67 @@
class_name Moving2Target extends EntityState
func process_moving_state(delta: float):
var target_pos = entity.target_enemy.global_position
var distance_to = entity.global_position.distance_to(target_pos)
var direction = (target_pos - entity.global_position).normalized()
if distance_to > entity.MAX_DISTANCE_TO:
entity.look_at(target_pos, Vector3.UP)
apply_acceleration(delta, direction)
else:
transitioned.emit(self, "shooting")
func apply_acceleration(delta: float, direction: Vector3 = Vector3.ZERO):
anim_player.play(entity.RUN_ANIM, 0.2)
entity.velocity.x = move_toward(entity.velocity.x, entity.SPEED * direction.x, entity.ACCELERATION * delta)
entity.velocity.z = move_toward(entity.velocity.z, entity.SPEED * direction.z, entity.ACCELERATION * delta)
func process_moving_state_nav_agent(delta):
entity.nav_agent.set_target_position(entity.target_enemy.global_position)
var target_pos = entity.nav_agent.get_next_path_position()
var target_enemy_pos = entity.target_enemy.global_position
var distance_to_target_enemy = entity.global_position.distance_to(target_enemy_pos)
var direction = (target_pos - entity.global_position).normalized() * entity.SPEED
if distance_to_target_enemy > entity.MAX_DISTANCE_TO:
entity.look_at(target_pos, Vector3.UP)
apply_acceleration_nav_agent(delta, direction)
else:
transitioned.emit(self, "shooting")
func apply_acceleration_nav_agent(_delta: float, direction: Vector3 = Vector3.ZERO):
anim_player.play(entity.RUN_ANIM, 0.2)
entity.nav_agent.set_velocity(direction)
func enter():
pass
func exit():
pass
func update(_delta: float):
pass
func physics_update(delta: float):
if not entity.target_enemy:
transitioned.emit(self, "idle")
return
if entity.target_enemy.state_machine.current_state is Dead:
transitioned.emit(self, "idle")
return
if not entity.USE_NAV_AGENT:
process_moving_state(delta)
else:
process_moving_state_nav_agent(delta)

View File

@ -0,0 +1,34 @@
class_name PersuingFlag extends EntityState
func process_idle(delta: float):
var target_pos = entity.target_ctf_flag.global_position
var distance_to = entity.global_position.distance_to(target_pos)
if distance_to > entity.MAX_DISTANCE_TO:
entity.look_at(target_pos, Vector3.UP)
apply_acceleration(delta, (target_pos - entity.global_position).normalized())
else:
# Note: Need to setup such that if flag free take it else if taken;
# target entity and shoot who has the flag
transitioned.emit(self, "idle")
func apply_acceleration(delta: float, direction: Vector3 = Vector3.ZERO):
anim_player.play(entity.MOVEMENT_ANIM, 0.2)
entity.velocity.x = move_toward(entity.velocity.x, entity.SPEED * direction.x, entity.ACCELERATION * delta)
entity.velocity.z = move_toward(entity.velocity.z, entity.SPEED * direction.z, entity.ACCELERATION * delta)
func enter():
pass
func exit():
entity.target_ctf_flag = null
func update(delta: float):
pass
func physics_update(delta: float):
process_idle(delta)

View File

@ -0,0 +1,2 @@
class_name Posing extends EntityState

View File

@ -0,0 +1,37 @@
class_name Shooting extends EntityState
func process_shooting():
var target_pos = entity.target_enemy.global_position
# Note: Need to rotate entity at pelvis when higher or lower than plane.
# As is it rotates the entire entity....
# entity.look_at(target_pos, Vector3.UP)
entity.equiped_item.get_children()[0].look_at(target_pos, Vector3.UP)
var item = entity.equiped_item.get_children()[0]
if item is Gun and item.can_shoot:
anim_player.play(entity.SHOOTING_ANIM, 0.2)
# Handled in animation
# item.shoot()
func enter():
pass
func exit():
entity.target_enemy = null
func update(_delta: float):
pass
func physics_update(_delta: float):
if not entity.target_enemy:
transitioned.emit(self, "idle")
return
if entity.target_enemy.state_machine.current_state is Dead:
transitioned.emit(self, "idle")
return
process_shooting()

View File

@ -0,0 +1,17 @@
class_name Walking extends EntityState
func process_moving_state(delta: float, direction: Vector3 = Vector3.FORWARD):
anim_player.play(entity.WALK_ANIM, 0.2)
entity.velocity.x = move_toward(entity.velocity.x, entity.SPEED * direction.x, entity.ACCELERATION * delta)
entity.velocity.z = move_toward(entity.velocity.z, entity.SPEED * direction.z, entity.ACCELERATION * delta)
func enter():
pass
func update(_delta: float):
pass
func physics_update(delta: float):
process_moving_state(delta)

View File

@ -0,0 +1,43 @@
class_name StateMachine extends Node
@export var initial_state: State
@export var anim_player: AnimationPlayer
var states: Dictionary = {}
var current_state: State
func init(entity):
for child in get_children():
if child is State:
states[child.name.to_lower()] = child
child.transitioned.connect(on_child_transition)
child.entity = entity
child.anim_player = anim_player
if initial_state:
initial_state.enter()
current_state = initial_state
func process(delta):
if current_state:
current_state.update(delta)
func physics_process(delta):
if current_state:
current_state.physics_update(delta)
func on_child_transition(state, new_state_name):
if state != current_state:
return
var new_state = states.get(new_state_name.to_lower())
if !new_state:
return
if current_state:
current_state.exit()
new_state.enter()
current_state = new_state

View File

@ -0,0 +1,19 @@
class_name State extends Node
var entity: Node = null
var anim_player: AnimationPlayer = null
signal transitioned
func enter():
pass
func exit():
pass
func update(_delta: float):
pass
func physics_update(_delta: float):
pass

8
src/shaders/README.md Normal file
View File

@ -0,0 +1,8 @@
# shaders
* Zelda like water
![1 Zelda like water. ](images/water.png)
* god-ray
![2 God ray. ](images/god-ray.png)

View File

@ -0,0 +1,152 @@
shader_type spatial;
uniform sampler2D noise;
uniform float height_scale = 1.5;
uniform vec4 WATER_COL : source_color = vec4(0.04, 0.38, 0.88, 1.0);
uniform vec4 WATER2_COL : source_color = vec4(0.04, 0.35, 0.78, 1.0);
uniform vec4 FOAM_COL : source_color = vec4(0.8125, 0.9609, 0.9648, 1.0);
uniform float distortion_speed = 2.0;
uniform vec2 tile = vec2(5.0, 5.0);
uniform float wave_speed = 1.5;
const float TWOPI = 6.283185307;
const float SIXPI = 18.84955592;
float circ(vec2 pos, vec2 c, float s) {
c = abs(pos - c);
c = min(c, 1.0 - c);
return smoothstep(0.0, 0.002, sqrt(s) - sqrt(dot(c, c))) * -1.0;
}
float waterlayer(vec2 uv) {
uv = mod(uv, 1.0); // Clamp to [0..1]
float ret = 1.0;
ret += circ(uv, vec2(0.37378, 0.277169), 0.0268181);
ret += circ(uv, vec2(0.0317477, 0.540372), 0.0193742);
ret += circ(uv, vec2(0.430044, 0.882218), 0.0232337);
ret += circ(uv, vec2(0.641033, 0.695106), 0.0117864);
ret += circ(uv, vec2(0.0146398, 0.0791346), 0.0299458);
ret += circ(uv, vec2(0.43871, 0.394445), 0.0289087);
ret += circ(uv, vec2(0.909446, 0.878141), 0.028466);
ret += circ(uv, vec2(0.310149, 0.686637), 0.0128496);
ret += circ(uv, vec2(0.928617, 0.195986), 0.0152041);
ret += circ(uv, vec2(0.0438506, 0.868153), 0.0268601);
ret += circ(uv, vec2(0.308619, 0.194937), 0.00806102);
ret += circ(uv, vec2(0.349922, 0.449714), 0.00928667);
ret += circ(uv, vec2(0.0449556, 0.953415), 0.023126);
ret += circ(uv, vec2(0.117761, 0.503309), 0.0151272);
ret += circ(uv, vec2(0.563517, 0.244991), 0.0292322);
ret += circ(uv, vec2(0.566936, 0.954457), 0.00981141);
ret += circ(uv, vec2(0.0489944, 0.200931), 0.0178746);
ret += circ(uv, vec2(0.569297, 0.624893), 0.0132408);
ret += circ(uv, vec2(0.298347, 0.710972), 0.0114426);
ret += circ(uv, vec2(0.878141, 0.771279), 0.00322719);
ret += circ(uv, vec2(0.150995, 0.376221), 0.00216157);
ret += circ(uv, vec2(0.119673, 0.541984), 0.0124621);
ret += circ(uv, vec2(0.629598, 0.295629), 0.0198736);
ret += circ(uv, vec2(0.334357, 0.266278), 0.0187145);
ret += circ(uv, vec2(0.918044, 0.968163), 0.0182928);
ret += circ(uv, vec2(0.965445, 0.505026), 0.006348);
ret += circ(uv, vec2(0.514847, 0.865444), 0.00623523);
ret += circ(uv, vec2(0.710575, 0.0415131), 0.00322689);
ret += circ(uv, vec2(0.71403, 0.576945), 0.0215641);
ret += circ(uv, vec2(0.748873, 0.413325), 0.0110795);
ret += circ(uv, vec2(0.0623365, 0.896713), 0.0236203);
ret += circ(uv, vec2(0.980482, 0.473849), 0.00573439);
ret += circ(uv, vec2(0.647463, 0.654349), 0.0188713);
ret += circ(uv, vec2(0.651406, 0.981297), 0.00710875);
ret += circ(uv, vec2(0.428928, 0.382426), 0.0298806);
ret += circ(uv, vec2(0.811545, 0.62568), 0.00265539);
ret += circ(uv, vec2(0.400787, 0.74162), 0.00486609);
ret += circ(uv, vec2(0.331283, 0.418536), 0.00598028);
ret += circ(uv, vec2(0.894762, 0.0657997), 0.00760375);
ret += circ(uv, vec2(0.525104, 0.572233), 0.0141796);
ret += circ(uv, vec2(0.431526, 0.911372), 0.0213234);
ret += circ(uv, vec2(0.658212, 0.910553), 0.000741023);
ret += circ(uv, vec2(0.514523, 0.243263), 0.0270685);
ret += circ(uv, vec2(0.0249494, 0.252872), 0.00876653);
ret += circ(uv, vec2(0.502214, 0.47269), 0.0234534);
ret += circ(uv, vec2(0.693271, 0.431469), 0.0246533);
ret += circ(uv, vec2(0.415, 0.884418), 0.0271696);
ret += circ(uv, vec2(0.149073, 0.41204), 0.00497198);
ret += circ(uv, vec2(0.533816, 0.897634), 0.00650833);
ret += circ(uv, vec2(0.0409132, 0.83406), 0.0191398);
ret += circ(uv, vec2(0.638585, 0.646019), 0.0206129);
ret += circ(uv, vec2(0.660342, 0.966541), 0.0053511);
ret += circ(uv, vec2(0.513783, 0.142233), 0.00471653);
ret += circ(uv, vec2(0.124305, 0.644263), 0.00116724);
ret += circ(uv, vec2(0.99871, 0.583864), 0.0107329);
ret += circ(uv, vec2(0.894879, 0.233289), 0.00667092);
ret += circ(uv, vec2(0.246286, 0.682766), 0.00411623);
ret += circ(uv, vec2(0.0761895, 0.16327), 0.0145935);
ret += circ(uv, vec2(0.949386, 0.802936), 0.0100873);
ret += circ(uv, vec2(0.480122, 0.196554), 0.0110185);
ret += circ(uv, vec2(0.896854, 0.803707), 0.013969);
ret += circ(uv, vec2(0.292865, 0.762973), 0.00566413);
ret += circ(uv, vec2(0.0995585, 0.117457), 0.00869407);
ret += circ(uv, vec2(0.377713, 0.00335442), 0.0063147);
ret += circ(uv, vec2(0.506365, 0.531118), 0.0144016);
ret += circ(uv, vec2(0.408806, 0.894771), 0.0243923);
ret += circ(uv, vec2(0.143579, 0.85138), 0.00418529);
ret += circ(uv, vec2(0.0902811, 0.181775), 0.0108896);
ret += circ(uv, vec2(0.780695, 0.394644), 0.00475475);
ret += circ(uv, vec2(0.298036, 0.625531), 0.00325285);
ret += circ(uv, vec2(0.218423, 0.714537), 0.00157212);
ret += circ(uv, vec2(0.658836, 0.159556), 0.00225897);
ret += circ(uv, vec2(0.987324, 0.146545), 0.0288391);
ret += circ(uv, vec2(0.222646, 0.251694), 0.00092276);
ret += circ(uv, vec2(0.159826, 0.528063), 0.00605293);
return max(ret, 0.0);
}
vec3 water(vec2 uv, vec3 cdir, float iTime) {
uv *= vec2(0.25);
// Parallax height distortion with two directional waves at
// slightly different angles.
vec2 a = 0.025 * cdir.xz / cdir.y; // Parallax offset
float h = sin(uv.x + iTime); // Height at UV
uv += a * h;
h = sin(0.841471 * uv.x - 0.540302 * uv.y + iTime);
uv += a * h;
// Texture distortion
float d1 = mod(uv.x + uv.y, TWOPI);
float d2 = mod((uv.x + uv.y + 0.25) * 1.3, SIXPI);
d1 = iTime * 0.07 + d1;
d2 = iTime * 0.5 + d2;
vec2 dist = vec2(
sin(d1) * 0.15 + sin(d2) * 0.05,
cos(d1) * 0.15 + cos(d2) * 0.05
);
vec3 ret = mix(WATER_COL.rgb, WATER2_COL.rgb, waterlayer(uv + dist.xy));
ret = mix(ret, FOAM_COL.rgb, waterlayer(vec2(1.0) - uv - dist.yx));
return ret;
}
void vertex() {
float height = texture(noise, VERTEX.xz / height_scale ).x; //divide by the size of the PlaneMesh
VERTEX.y += sin(height * height_scale * TIME) * cos(VERTEX.x * 4.0);
}
void fragment() {
vec2 uv = UV;
float fresnel = sqrt(1.0 - dot(NORMAL, VIEW));
RIM = 0.2;
METALLIC = 0.0;
ROUGHNESS = 0.2 * (1.0 - fresnel);
ALBEDO = vec3(water(uv * tile, vec3(0,1,0), TIME * distortion_speed));
}

View File

@ -0,0 +1,86 @@
shader_type spatial;
render_mode depth_draw_opaque;
uniform float height_scale = 0.5;
uniform float wave_speed = 0.1;
uniform float upper_transparency = 0.89;
uniform float global_transparency = 0.9;
uniform vec2 time_factor = vec2(2.0, 3.0);
uniform sampler2D texture_albedo : source_color;
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
uniform vec4 color1 : source_color = vec4(0.78, 0.91, 0.93, 1.0);
uniform vec4 color2 : source_color = vec4(0.71, 0.89, 0.95, 1.0);
varying flat vec3 out_color;
varying flat vec3 soft_color;
vec3 lerpColor(vec4 a, vec4 b, float t){
float rr = a.r + (b.r - a.r) * t;
float gg = a.g + (b.g - a.g) * t;
float bb = a.b + (b.b - a.b) * t;
return vec3(rr, gg, bb);
}
float hash(vec2 p) {
return fract(sin(dot(p * 17.17, vec2(14.91, 67.31))) * 4791.9511);
}
float noise(vec2 x) {
vec2 p = floor(x);
vec2 f = fract(x);
f = f * f * (3.0 - 2.0 * f);
vec2 a = vec2(1.0, 0.0);
return mix(mix(hash(p + a.yy), hash(p + a.xy), f.x),
mix(hash(p + a.yx), hash(p + a.xx), f.x), f.y);
}
float fbm(vec2 x, float time) {
float height = 0.0;
float amplitude = 0.5;
float frequency = 0.5;
for (int i = 0; i < 6; i++){
height += noise(x * frequency + time * time_factor * wave_speed) * amplitude;
amplitude *= 0.5;
frequency *= 2.0;
}
return height;
}
void vertex() {
UV=UV*uv1_scale.xy+uv1_offset.xy;
out_color = vec3(color1.r, color1.g, color1.b);
soft_color = vec3(color1.r, color1.g, color1.b);
float height = fbm(VERTEX.xz * 4.0, TIME);
VERTEX.y += height * height_scale;
COLOR.xyz = vec3(height);
if (VERTEX.y > 0.3){
out_color = lerpColor(color1, color2, clamp((VERTEX.y) / 3.0, 0.5, 1.0));
soft_color = vec3(color2.r, color2.g, color2.b);
}
}
void fragment(){
ALBEDO = COLOR.xyz;
vec2 base_uv = UV;
vec4 albedo_tex = texture(texture_albedo,base_uv);
ALPHA = global_transparency;
ALBEDO = out_color * albedo_tex.rgb * COLOR.xyz;
if (soft_color.r==color2.r && soft_color.g==color2.g && color2.b==color2.b) {
ALPHA = upper_transparency;
}
}

View File

@ -0,0 +1,106 @@
/*
Shader from Godot Shaders - the free shader library.
godotshaders.com/shader/god-rays
Feel free to use, improve and change this shader according to your needs
and consider sharing the modified result on godotshaders.com.
*/
shader_type spatial;
render_mode unshaded, blend_add;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
uniform float angle = -0.3;
uniform float position = -0.2;
uniform float spread : hint_range(0.0, 1.0) = 0.5;
uniform float cutoff : hint_range(-1.0, 1.0) = 0.1;
uniform float falloff : hint_range(0.0, 1.0) = 0.2;
uniform float edge_fade : hint_range(0.0, 1.0) = 0.15;
uniform float speed = 1.0;
uniform float ray1_density = 8.0;
uniform float ray2_density = 30.0;
uniform float ray2_intensity : hint_range(0.0, 1.0) = 0.3;
uniform vec4 color : source_color = vec4(1.0, 0.9, 0.65, 0.8);
uniform bool hdr = false;
uniform float seed = 5.0;
// Random and noise functions from Book of Shader's chapter on Noise.
float random(vec2 _uv) {
return fract( sin( dot(_uv.xy, vec2(12.9898, 78.233))) * 43758.5453123);
}
float noise (in vec2 uv) {
vec2 i = floor(uv);
vec2 f = fract(uv);
// Four corners in 2D of a tile
float a = random(i);
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
// Smooth Interpolation
// Cubic Hermine Curve. Same as SmoothStep()
vec2 u = f * f * (3.0-2.0 * f);
// Mix 4 coorners percentages
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
mat2 rotate(float _angle) {
return mat2(vec2(cos(_angle), -sin(_angle)),
vec2(sin(_angle), cos(_angle)));
}
vec4 screen(vec4 base, vec4 blend) {
return 1.0 - (1.0 - base) * (1.0 - blend);
}
void fragment() {
// Rotate, skew and move the UVs
vec2 transformed_uv = ( rotate(angle) * (UV - position) ) / ( (UV.y + spread) - (UV.y * spread) );
// Animate the ray according the the new transformed UVs
vec2 ray1 = vec2(transformed_uv.x * ray1_density + sin(TIME * 0.1 * speed) * (ray1_density * 0.2) + seed, 1.0);
vec2 ray2 = vec2(transformed_uv.x * ray2_density + sin(TIME * 0.2 * speed) * (ray1_density * 0.2) + seed, 1.0);
// Cut off the ray's edges
float cut = step(cutoff, transformed_uv.x) * step(cutoff, 1.0 - transformed_uv.x);
ray1 *= cut;
ray2 *= cut;
// Apply the noise pattern (i.e. create the rays)
float rays;
if (hdr){
// This is not really HDR, but check this to not clamp the two merged rays making
// their values go over 1.0. Can make for some nice effect
rays = noise(ray1) + (noise(ray2) * ray2_intensity);
}
else{
rays = clamp(noise(ray1) + (noise(ray2) * ray2_intensity), 0., 1.);
}
// Fade out edges
rays *= smoothstep(0.0, falloff, (1.0 - UV.y)); // Bottom
rays *= smoothstep(0.0 + cutoff, edge_fade + cutoff, transformed_uv.x); // Left
rays *= smoothstep(0.0 + cutoff, edge_fade + cutoff, 1.0 - transformed_uv.x); // Right
// Color to the rays
vec3 shine = vec3(rays) * color.rgb;
// Try different blending modes for a nicer effect. "Screen" is included in the code,
// but take a look at https://godotshaders.com/snippet/blending-modes/ for more.
// With "Screen" blend mode:
shine = screen(texture(SCREEN_TEXTURE, SCREEN_UV), vec4(color)).rgb;
// COLOR = vec4(shine, rays * color.a);
ALPHA = 1.0;
ALBEDO = vec3(shine * rays * color.a);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

3
src/tscns/README.md Normal file
View File

@ -0,0 +1,3 @@
# tscns
For the world.tscn make sure to copy the shader folder with the respective water and godray shaders to the project folder.

9
src/tscns/world.tres Normal file
View File

@ -0,0 +1,9 @@
[gd_resource type="VisualShader" format=3 uid="uid://jvscynpfi2um"]
[resource]
code = "shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;
"

96
src/tscns/world.tscn Normal file
View File

@ -0,0 +1,96 @@
[gd_scene load_steps=12 format=3 uid="uid://c326ujkp5ldur"]
[ext_resource type="Shader" path="res://shaders/arctic-water.gdshader" id="1_kiv5b"]
[ext_resource type="Shader" path="res://shaders/god-ray.gdshader" id="2_oa8hx"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_u4s8b"]
sky_top_color = Color(0.415686, 0.694118, 0.843137, 1)
sky_horizon_color = Color(0.211765, 0.470588, 0.67451, 1)
sky_curve = 0.0609
ground_bottom_color = Color(0.121569, 0.309804, 0.458824, 1)
ground_horizon_color = Color(0.211765, 0.470588, 0.67451, 1)
sun_angle_max = 18.35
sun_curve = 0.0477
[sub_resource type="Sky" id="Sky_0i4i8"]
sky_material = SubResource("ProceduralSkyMaterial_u4s8b")
[sub_resource type="Environment" id="Environment_6pt2h"]
background_mode = 2
sky = SubResource("Sky_0i4i8")
[sub_resource type="FastNoiseLite" id="FastNoiseLite_6s8sc"]
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_wq5fs"]
noise = SubResource("FastNoiseLite_6s8sc")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ubxpm"]
render_priority = 0
shader = ExtResource("1_kiv5b")
shader_parameter/height_scale = 1.5
shader_parameter/WATER_COL = Color(0.121569, 0.309804, 0.458824, 1)
shader_parameter/WATER2_COL = Color(0.121569, 0.309804, 0.458824, 1)
shader_parameter/FOAM_COL = Color(0.811765, 0.960784, 0.964706, 1)
shader_parameter/distortion_speed = 0.8
shader_parameter/tile = Vector2(54, 54)
shader_parameter/wave_speed = 1.5
shader_parameter/noise = SubResource("NoiseTexture2D_wq5fs")
[sub_resource type="QuadMesh" id="QuadMesh_puhpp"]
material = SubResource("ShaderMaterial_ubxpm")
size = Vector2(200, 200)
subdivide_width = 54
subdivide_depth = 54
orientation = 1
[sub_resource type="QuadMesh" id="QuadMesh_tr2ws"]
size = Vector2(200, 200)
subdivide_width = 12
subdivide_depth = 12
[sub_resource type="ShaderMaterial" id="ShaderMaterial_rn40m"]
render_priority = 0
shader = ExtResource("2_oa8hx")
shader_parameter/angle = -0.3
shader_parameter/position = -0.2
shader_parameter/spread = 0.5
shader_parameter/cutoff = 0.1
shader_parameter/falloff = 0.2
shader_parameter/edge_fade = 0.15
shader_parameter/speed = 1.0
shader_parameter/ray1_density = 8.0
shader_parameter/ray2_density = 30.0
shader_parameter/ray2_intensity = 0.3
shader_parameter/color = Color(1, 0.9, 0.65, 0.8)
shader_parameter/hdr = false
shader_parameter/seed = 5.0
[node name="world" type="Node3D"]
[node name="sky" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_6pt2h")
[node name="sun" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.942641, 0.333807, 0, -0.333807, 0.942641, 0, 8, 0)
shadow_enabled = true
[node name="ocean" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -126.494, 0, -43)
mesh = SubResource("QuadMesh_puhpp")
[node name="ocean2" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 72.7354, 0, -43)
mesh = SubResource("QuadMesh_puhpp")
[node name="ocean3" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -126.494, 0, -221.948)
mesh = SubResource("QuadMesh_puhpp")
[node name="ocean4" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 72.7354, 0, -221.948)
mesh = SubResource("QuadMesh_puhpp")
[node name="god_ray" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -77.5202, 83.1627, -70)
mesh = SubResource("QuadMesh_tr2ws")
surface_material_override/0 = SubResource("ShaderMaterial_rn40m")