Skip to content

Commit

Permalink
fix: scatter
Browse files Browse the repository at this point in the history
  • Loading branch information
florianvazelle committed Jan 13, 2024
1 parent a5bada1 commit 6f16fab
Show file tree
Hide file tree
Showing 329 changed files with 19,478 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data_*/
.plugged/
addons/*
!addons/gd-plug/
!addons/proton_scatter/

# Python-specific ignores
venv/
Expand Down
12 changes: 10 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ repos:
rev: 4.2.2
hooks:
- id: gdformat
exclude: '^addons/gd-plug/'
exclude: |
(?x)^(
addons/gd-plug/|
addons/proton_scatter/
)
- id: gdlint
exclude: '^addons/gd-plug/'
exclude: |
(?x)^(
addons/gd-plug/|
addons/proton_scatter/
)
- repo: local
hooks:
- id: lower-case-only
Expand Down
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ godot_filename := "Godot_v" + godot_version + "_" + godot_platform
godot_template := "Godot_v" + godot_version + "_export_templates.tpz"
godot_bin := bin_dir / godot_filename
godot_editor_data_dir := "~/.local/share/godot"
godot_templates_dir := godot_editor_data_dir / "export_templates" / replace_regex(godot_version, "([^-]+)-([^-]+)", "$1.$2")
godot_templates_dir := godot_editor_data_dir / "export_templates" / replace_regex(godot_version, "([^-]+)-([^-]+)", "$1.$2")

# Game variables
game_name := env_var('GAME_NAME')
Expand Down
21 changes: 21 additions & 0 deletions addons/proton_scatter/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 HungryProton

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions addons/proton_scatter/demos/assets/brick.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[gd_scene load_steps=5 format=3 uid="uid://b4ted6l27vuyd"]

[ext_resource type="PackedScene" uid="uid://d1d1fag0m04yc" path="res://addons/proton_scatter/demos/assets/models/brick.glb" id="1_bkmk2"]
[ext_resource type="Texture2D" uid="uid://dqa2jfs1jy0hq" path="res://addons/proton_scatter/demos/assets/textures/t_rock.jpg" id="2_235bd"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_nwvh2"]
albedo_color = Color(0.678431, 0.596078, 0.466667, 1)
albedo_texture = ExtResource("2_235bd")
uv1_scale = Vector3(0.75, 0.75, 0.75)
uv1_triplanar = true

[sub_resource type="BoxShape3D" id="BoxShape3D_0rrnn"]
size = Vector3(0.4, 0.4, 0.4)

[node name="brick" instance=ExtResource("1_bkmk2")]

[node name="Cube" parent="." index="0"]
material_override = SubResource("StandardMaterial3D_nwvh2")

[node name="StaticBody3D" type="StaticBody3D" parent="." index="1"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="0"]
shape = SubResource("BoxShape3D_0rrnn")
10 changes: 10 additions & 0 deletions addons/proton_scatter/demos/assets/bush.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_scene load_steps=3 format=3 uid="uid://b8abs8me7ckgo"]

[ext_resource type="PackedScene" uid="uid://dbb4culid55v5" path="res://addons/proton_scatter/demos/assets/models/bush.glb" id="1_kv8tm"]
[ext_resource type="Material" uid="uid://bn3fr3m3glrnp" path="res://addons/proton_scatter/demos/assets/materials/m_bush.tres" id="2_bkwoq"]

[node name="bush" instance=ExtResource("1_kv8tm")]

[node name="Bush" parent="." index="0"]
material_override = ExtResource("2_bkwoq")
instance_shader_parameters/camera_bend_strength = 0.0
9 changes: 9 additions & 0 deletions addons/proton_scatter/demos/assets/dead_branch.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=3 uid="uid://ctkii8aivl17n"]

[ext_resource type="PackedScene" uid="uid://cmqlv88xp71tw" path="res://addons/proton_scatter/demos/assets/models/dead_branch.glb" id="1_5foyv"]
[ext_resource type="Material" uid="uid://d01d0h08lqqn6" path="res://addons/proton_scatter/demos/assets/materials/m_trunk.tres" id="2_tldro"]

[node name="dead_branch" instance=ExtResource("1_5foyv")]

[node name="DeadBranch" parent="." index="0"]
surface_material_override/0 = ExtResource("2_tldro")
18 changes: 18 additions & 0 deletions addons/proton_scatter/demos/assets/fence_planks.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[gd_scene load_steps=4 format=3 uid="uid://bfcjigq0vdl4d"]

[ext_resource type="PackedScene" uid="uid://6gxiul1pw13t" path="res://addons/proton_scatter/demos/assets/models/fence_planks.glb" id="1"]
[ext_resource type="Material" path="res://addons/proton_scatter/demos/assets/materials/m_fence.tres" id="2"]

[sub_resource type="BoxShape3D" id="BoxShape3D_fesk1"]
size = Vector3(1, 0.5, 0.1)

[node name="fence_planks" instance=ExtResource("1")]

[node name="fence_planks2" parent="." index="0"]
surface_material_override/0 = ExtResource("2")

[node name="StaticBody3D" type="StaticBody3D" parent="." index="1"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.197684, 0.0236663)
shape = SubResource("BoxShape3D_fesk1")
16 changes: 16 additions & 0 deletions addons/proton_scatter/demos/assets/gobot.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[gd_scene load_steps=3 format=3 uid="uid://bmglbfn5jaubp"]

[ext_resource type="PackedScene" uid="uid://d3f4d3m7n8tpr" path="res://addons/proton_scatter/demos/assets/models/gobot.glb" id="1_gfyx7"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_rhuea"]
albedo_color = Color(0.278431, 0.54902, 0.74902, 1)
metallic = 0.4
metallic_specular = 0.2
roughness = 0.15
rim_enabled = true
rim = 0.3

[node name="gobot" instance=ExtResource("1_gfyx7")]

[node name="Sphere001" parent="." index="0"]
surface_material_override/0 = SubResource("StandardMaterial3D_rhuea")
10 changes: 10 additions & 0 deletions addons/proton_scatter/demos/assets/grass.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_scene load_steps=3 format=3 uid="uid://c3c76je2y6vfj"]

[ext_resource type="PackedScene" uid="uid://018flajgtx7t" path="res://addons/proton_scatter/demos/assets/models/grass.glb" id="1_203fe"]
[ext_resource type="Material" uid="uid://c4mot1fo3siox" path="res://addons/proton_scatter/demos/assets/materials/m_grass.tres" id="2_sv1ar"]

[node name="grass" instance=ExtResource("1_203fe")]

[node name="Plane011" parent="." index="0"]
instance_shader_parameters/camera_bend_strength = 0.35
surface_material_override/0 = ExtResource("2_sv1ar")
9 changes: 9 additions & 0 deletions addons/proton_scatter/demos/assets/grass_2.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=3 uid="uid://cia3jakp3wj1d"]

[ext_resource type="PackedScene" uid="uid://dcnm2ijk7hj4j" path="res://addons/proton_scatter/demos/assets/models/grass_2.glb" id="1_xyqky"]
[ext_resource type="Material" uid="uid://c4mot1fo3siox" path="res://addons/proton_scatter/demos/assets/materials/m_grass.tres" id="2_63qe5"]

[node name="grass_2" instance=ExtResource("1_xyqky")]

[node name="Grass" parent="." index="0"]
surface_material_override/0 = ExtResource("2_63qe5")
17 changes: 17 additions & 0 deletions addons/proton_scatter/demos/assets/large_rock.tscn

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions addons/proton_scatter/demos/assets/materials/grass.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
shader_type spatial;

render_mode depth_draw_opaque, cull_disabled;

// Texture settings
uniform sampler2D texture_albedo : hint_default_white, repeat_disable;
uniform sampler2D texture_gradient : hint_default_white, repeat_disable;
uniform sampler2D texture_noise : hint_default_white;
uniform float alpha_scissor_threshold : hint_range(0.0, 1.0);
uniform vec4 transmission : source_color;
uniform vec4 secondary_color : source_color;
uniform float secondary_attenuation = 0.2;
uniform float grass_height = 1.0;

// Wind settings
uniform vec2 wind_direction = vec2(1, -0.5);
uniform float wind_speed = 1.0;
uniform float wind_strength = 2.0;
uniform float noise_scale = 20.0;

instance uniform float camera_bend_strength : hint_range(0.0, 3.0) = 0.2;

varying float color;
varying float height;

void vertex() {
height = VERTEX.y;
float influence = smoothstep(0, 1, height / 2.0);
vec4 world_pos = MODEL_MATRIX * vec4(VERTEX, 1.0);
vec2 uv = world_pos.xz / (noise_scale + 1e-2);
vec2 panning_uv = uv + fract(TIME * wind_direction * wind_speed);
float wind = texture(texture_noise, panning_uv).r * 2.0 - 0.4;
color = texture(texture_noise, uv).r;

vec2 wind_offset = -wind_direction * wind_strength * influence * wind;
world_pos.xz += wind_offset;
world_pos.y -= wind * influence * smoothstep(0.0, height, wind_strength);

//Push the top vertex away from the camera to bend the grass clump
float ndotv = 1.0 - dot(vec3(0.0, 1.0, 0.0), normalize(INV_VIEW_MATRIX[1].xyz));
world_pos.xz += INV_VIEW_MATRIX[1].xz * camera_bend_strength * height * ndotv;

vec4 local_pos = inverse(MODEL_MATRIX) * world_pos;
local_pos.x += wind_strength * influence * cos(TIME * 1.0) / 8.0;
local_pos.z += wind_strength * influence * sin(TIME * 1.5) / 8.0;

VERTEX = local_pos.xyz;
//NORMAL = vec3(0.0, 1.0, 0.0);
}

void fragment() {
vec4 tex = texture(texture_albedo, UV);
if (tex.a < alpha_scissor_threshold) {
discard;
}

BACKLIGHT = transmission.rgb;
vec4 gradient = texture(texture_gradient, vec2(height / grass_height, 0.0));
float secondary_weight = smoothstep(0.0, 1.0, color - secondary_attenuation);
ALBEDO = tex.rbg * gradient.rgb;
//ALBEDO = mix(ALBEDO, secondary_color.rgb, secondary_weight);
}
51 changes: 51 additions & 0 deletions addons/proton_scatter/demos/assets/materials/leaves.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
shader_type spatial;

render_mode depth_draw_opaque, cull_disabled;

// Texture settings
uniform sampler2D texture_albedo : hint_default_white, repeat_disable;
uniform sampler2D texture_gradient : hint_default_white;
uniform sampler2D texture_noise : hint_default_white;
uniform float alpha_scissor_threshold : hint_range(0.0, 1.0);
uniform vec4 transmission : source_color;
uniform float total_height = 1.0;

// Wind settings
uniform vec2 wind_direction = vec2(1, -0.5);
uniform float wind_speed = 1.0;
uniform float wind_strength = 2.0;
uniform float noise_scale = 20.0;

varying float color;
varying float height;

void vertex() {
height = VERTEX.y;

vec4 world_pos = MODEL_MATRIX * vec4(VERTEX, 1.0);
vec2 uv = (world_pos.xz + VERTEX.yy) / (noise_scale + 1e-2) ;
vec2 panning_uv = uv + fract(TIME * wind_direction * wind_speed);
float wind = texture(texture_noise, panning_uv).r * 2.0 - 0.4;
color = texture(texture_noise, uv).r;

float wind_influence = smoothstep(0, 1, 1.0 - UV.y);
vec2 wind_offset = -wind_direction * wind_strength * wind_influence * wind;
world_pos.xz += wind_offset;
world_pos.y -= wind * wind_influence * wind_strength * 0.45;

vec4 local_pos = inverse(MODEL_MATRIX) * world_pos;

VERTEX = local_pos.xyz;
//NORMAL = vec3(0.0, 1.0, 0.0);
}

void fragment() {
vec4 tex = texture(texture_albedo, UV);
if (tex.a < alpha_scissor_threshold) {
discard;
}

BACKLIGHT = transmission.rgb;
vec4 gradient = texture(texture_gradient, vec2(height / total_height, 0.0));
ALBEDO = tex.rbg * gradient.rgb;
}
37 changes: 37 additions & 0 deletions addons/proton_scatter/demos/assets/materials/m_bush.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[gd_resource type="ShaderMaterial" load_steps=7 format=3 uid="uid://bn3fr3m3glrnp"]

[ext_resource type="Shader" path="res://addons/proton_scatter/demos/assets/materials/grass.gdshader" id="1_peshr"]
[ext_resource type="Texture2D" uid="uid://b2a6ylo2enm4g" path="res://addons/proton_scatter/demos/assets/textures/t_bush.png" id="2_mbhvd"]

[sub_resource type="Gradient" id="Gradient_122hb"]
offsets = PackedFloat32Array(0, 0.5, 1)
colors = PackedColorArray(0.179688, 0.0759602, 0.0183228, 1, 0.386532, 0.390625, 0.0230687, 1, 1, 0.693237, 0.0687054, 1)

[sub_resource type="GradientTexture1D" id="GradientTexture1D_i0bw2"]
gradient = SubResource("Gradient_122hb")

[sub_resource type="FastNoiseLite" id="FastNoiseLite_eeqpx"]
seed = 1
frequency = 0.002

[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_7l0n1"]
in_3d_space = true
seamless = true
seamless_blend_skirt = 0.65
noise = SubResource("FastNoiseLite_eeqpx")

[resource]
render_priority = 0
shader = ExtResource("1_peshr")
shader_parameter/alpha_scissor_threshold = 0.25
shader_parameter/transmission = Color(0.619608, 0.541176, 0.101961, 1)
shader_parameter/secondary_color = Color(0, 0, 0, 1)
shader_parameter/secondary_attenuation = 0.2
shader_parameter/grass_height = 0.829
shader_parameter/wind_direction = Vector2(1, -0.5)
shader_parameter/wind_speed = 0.5
shader_parameter/wind_strength = 0.15
shader_parameter/noise_scale = 6.0
shader_parameter/texture_albedo = ExtResource("2_mbhvd")
shader_parameter/texture_gradient = SubResource("GradientTexture1D_i0bw2")
shader_parameter/texture_noise = SubResource("NoiseTexture2D_7l0n1")
6 changes: 6 additions & 0 deletions addons/proton_scatter/demos/assets/materials/m_fence.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_resource type="SpatialMaterial" format=2]

[resource]
resource_name = "wood"
vertex_color_use_as_albedo = true
albedo_color = Color( 0.568627, 0.466667, 0.372549, 1 )
37 changes: 37 additions & 0 deletions addons/proton_scatter/demos/assets/materials/m_grass.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[gd_resource type="ShaderMaterial" load_steps=7 format=3 uid="uid://c4mot1fo3siox"]

[ext_resource type="Shader" path="res://addons/proton_scatter/demos/assets/materials/grass.gdshader" id="1_fntgl"]
[ext_resource type="Texture2D" uid="uid://d23p13yi7asw0" path="res://addons/proton_scatter/demos/assets/textures/t_grass_2.png" id="2_1odx0"]

[sub_resource type="Gradient" id="Gradient_122hb"]
offsets = PackedFloat32Array(0, 0.473451, 1)
colors = PackedColorArray(0.179688, 0.0855483, 0.00322032, 1, 0.251693, 0.390625, 0.0117187, 1, 1, 0.964706, 0.129412, 1)

[sub_resource type="GradientTexture1D" id="GradientTexture1D_i0bw2"]
gradient = SubResource("Gradient_122hb")

[sub_resource type="FastNoiseLite" id="FastNoiseLite_eeqpx"]
seed = 1
frequency = 0.002

[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_7l0n1"]
in_3d_space = true
seamless = true
seamless_blend_skirt = 0.65
noise = SubResource("FastNoiseLite_eeqpx")

[resource]
render_priority = 0
shader = ExtResource("1_fntgl")
shader_parameter/alpha_scissor_threshold = 0.3
shader_parameter/transmission = Color(0.737255, 0.72549, 0, 1)
shader_parameter/secondary_color = Color(0, 0, 0, 1)
shader_parameter/secondary_attenuation = 0.2
shader_parameter/grass_height = 0.6
shader_parameter/wind_direction = Vector2(1, -0.5)
shader_parameter/wind_speed = 0.5
shader_parameter/wind_strength = 0.15
shader_parameter/noise_scale = 6.0
shader_parameter/texture_albedo = ExtResource("2_1odx0")
shader_parameter/texture_gradient = SubResource("GradientTexture1D_i0bw2")
shader_parameter/texture_noise = SubResource("NoiseTexture2D_7l0n1")
38 changes: 38 additions & 0 deletions addons/proton_scatter/demos/assets/materials/m_leaves.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[gd_resource type="ShaderMaterial" load_steps=7 format=3 uid="uid://djo80ucamk643"]

[ext_resource type="Shader" path="res://addons/proton_scatter/demos/assets/materials/grass.gdshader" id="1_8py1k"]
[ext_resource type="Texture2D" uid="uid://cgenco43aneod" path="res://addons/proton_scatter/demos/assets/textures/t_leaves_1.png" id="2_l2uea"]

[sub_resource type="Gradient" id="Gradient_yy7fg"]
offsets = PackedFloat32Array(0, 0.726872, 0.934272)
colors = PackedColorArray(0.333333, 0.486275, 0.556863, 1, 0.496467, 0.55, 0.1485, 1, 0.898039, 0.670588, 0.0196078, 1)

[sub_resource type="GradientTexture1D" id="GradientTexture1D_rwvaq"]
gradient = SubResource("Gradient_yy7fg")

[sub_resource type="FastNoiseLite" id="FastNoiseLite_wpihy"]
seed = 1
frequency = 0.002

[sub_resource type="NoiseTexture2D" id="NoiseTexture_tgrrr"]
in_3d_space = true
seamless = true
seamless_blend_skirt = 0.65
noise = SubResource("FastNoiseLite_wpihy")

[resource]
render_priority = 0
shader = ExtResource("1_8py1k")
shader_parameter/alpha_scissor_threshold = 0.5
shader_parameter/camera_bend_strength = 0.0
shader_parameter/grass_height = 1.0
shader_parameter/noise_scale = 12.0
shader_parameter/secondary_attenuation = 0.2
shader_parameter/secondary_color = Color(0, 0.305882, 0.211765, 1)
shader_parameter/texture_albedo = ExtResource("2_l2uea")
shader_parameter/texture_gradient = SubResource("GradientTexture1D_rwvaq")
shader_parameter/texture_noise = SubResource("NoiseTexture_tgrrr")
shader_parameter/transmission = Color(1, 0.975296, 0.943663, 1)
shader_parameter/wind_direction = Vector2(1, -0.5)
shader_parameter/wind_speed = 0.5
shader_parameter/wind_strength = 0.05
Loading

0 comments on commit 6f16fab

Please sign in to comment.