Compare commits
2 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
0db982723b | 3 years ago |
|
|
de366eb096 | 3 years ago |
Binary file not shown.
@ -0,0 +1,28 @@ |
|||||||
|
extends MultiMeshInstance |
||||||
|
|
||||||
|
var extents = Vector2(10, 10) |
||||||
|
|
||||||
|
func _ready(): |
||||||
|
var poisson_disc_sampling: PoissonDiscSampling = PoissonDiscSampling.new() |
||||||
|
var rng := RandomNumberGenerator.new() |
||||||
|
rng.randomize() |
||||||
|
var coords = [] |
||||||
|
for center in Global.terrain.get_centers(): |
||||||
|
if ( |
||||||
|
not center.get_data("mountain") |
||||||
|
and not center.get_data("water") |
||||||
|
and not center.get_data("coast") |
||||||
|
): |
||||||
|
var points = poisson_disc_sampling.generate_points(2, center.polygon(), 2) |
||||||
|
var points3d = [] |
||||||
|
for point in points: |
||||||
|
points3d.append(Vector3(point.x, center.get_elevation() * 120, point.y)) |
||||||
|
coords += points3d |
||||||
|
multimesh.instance_count = coords.size() |
||||||
|
for instance_index in multimesh.instance_count: |
||||||
|
|
||||||
|
var transform := Transform().rotated(Vector3.UP, rng.randf_range(-PI / 2, PI / 2)) |
||||||
|
transform.origin = Vector3(coords[instance_index].x, coords[instance_index].y, coords[instance_index].z) |
||||||
|
# transform.scaled(Vector3()) |
||||||
|
|
||||||
|
multimesh.set_instance_transform(instance_index, transform) |
||||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,12 @@ |
|||||||
|
# Blender MTL File: 'None' |
||||||
|
# Material Count: 1 |
||||||
|
|
||||||
|
newmtl Default_OBJ |
||||||
|
Ns 250.000000 |
||||||
|
Ka 1.000000 1.000000 1.000000 |
||||||
|
Kd 0.800000 0.800000 0.800000 |
||||||
|
Ks 0.500000 0.500000 0.500000 |
||||||
|
Ke 0.000000 0.000000 0.000000 |
||||||
|
Ni 1.450000 |
||||||
|
d 1.000000 |
||||||
|
illum 2 |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
# Blender v3.2.2 OBJ File: '' |
||||||
|
# www.blender.org |
||||||
|
mtllib grass.mtl |
||||||
|
o grass_triangle |
||||||
|
v 0.012754 0.302056 0.000000 |
||||||
|
v 0.000000 0.402742 0.000000 |
||||||
|
v -0.012754 0.302056 0.000000 |
||||||
|
v 0.025508 0.201371 0.000000 |
||||||
|
v -0.038262 0.100685 0.000000 |
||||||
|
v 0.038262 0.100685 0.000000 |
||||||
|
v -0.051016 0.000000 0.000000 |
||||||
|
v 0.051016 0.000000 0.000000 |
||||||
|
v -0.025508 0.201371 0.000000 |
||||||
|
vt 0.621057 0.520384 |
||||||
|
vt 0.497980 0.979655 |
||||||
|
vt 0.376628 0.520384 |
||||||
|
vt 0.744133 0.238847 |
||||||
|
vt 0.133923 0.098911 |
||||||
|
vt 0.867209 0.098911 |
||||||
|
vt 0.012570 0.013663 |
||||||
|
vt 0.990286 0.013663 |
||||||
|
vt 0.255275 0.238847 |
||||||
|
vn 0.0000 -0.0000 1.0000 |
||||||
|
usemtl Default_OBJ |
||||||
|
s 1 |
||||||
|
f 1/1/1 2/2/1 3/3/1 |
||||||
|
f 4/4/1 5/5/1 6/6/1 |
||||||
|
f 6/6/1 7/7/1 8/8/1 |
||||||
|
f 1/1/1 9/9/1 4/4/1 |
||||||
|
f 4/4/1 9/9/1 5/5/1 |
||||||
|
f 6/6/1 5/5/1 7/7/1 |
||||||
|
f 1/1/1 3/3/1 9/9/1 |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
[remap] |
||||||
|
|
||||||
|
importer="wavefront_obj" |
||||||
|
type="Mesh" |
||||||
|
path="res://.import/grass.obj-b367f86df935fca9f4b72c7070d3608f.mesh" |
||||||
|
|
||||||
|
[deps] |
||||||
|
|
||||||
|
files=[ "res://.import/grass.obj-b367f86df935fca9f4b72c7070d3608f.mesh" ] |
||||||
|
|
||||||
|
source_file="res://world/grass.obj" |
||||||
|
dest_files=[ "res://.import/grass.obj-b367f86df935fca9f4b72c7070d3608f.mesh", "res://.import/grass.obj-b367f86df935fca9f4b72c7070d3608f.mesh" ] |
||||||
|
|
||||||
|
[params] |
||||||
|
|
||||||
|
generate_tangents=true |
||||||
|
scale_mesh=Vector3( 1, 1, 1 ) |
||||||
|
offset_mesh=Vector3( 0, 0, 0 ) |
||||||
|
octahedral_compression=true |
||||||
|
optimize_mesh_flags=4286 |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
# Blender v2.83.0 OBJ File: '' |
||||||
|
# www.blender.org |
||||||
|
v -0.255078 0.000000 0.000000 |
||||||
|
v 0.255078 0.000000 0.000000 |
||||||
|
v 0.000000 2.013708 0.000000 |
||||||
|
v -0.127539 1.006854 0.000000 |
||||||
|
v 0.127539 1.006854 0.000000 |
||||||
|
v -0.191308 0.503427 0.000000 |
||||||
|
v 0.063769 1.510281 0.000000 |
||||||
|
v -0.063769 1.510281 0.000000 |
||||||
|
v 0.191308 0.503427 0.000000 |
||||||
|
vt 0.621057 0.520384 |
||||||
|
vt 0.497980 0.979655 |
||||||
|
vt 0.376628 0.520384 |
||||||
|
vt 0.744133 0.238847 |
||||||
|
vt 0.133923 0.098911 |
||||||
|
vt 0.867209 0.098911 |
||||||
|
vt 0.012570 0.013663 |
||||||
|
vt 0.990286 0.013663 |
||||||
|
vt 0.255275 0.238847 |
||||||
|
vn 0.0000 0.0000 1.0000 |
||||||
|
s 1 |
||||||
|
f 7/1/1 3/2/1 8/3/1 |
||||||
|
f 5/4/1 6/5/1 9/6/1 |
||||||
|
f 9/6/1 1/7/1 2/8/1 |
||||||
|
f 7/1/1 4/9/1 5/4/1 |
||||||
|
f 5/4/1 4/9/1 6/5/1 |
||||||
|
f 9/6/1 6/5/1 1/7/1 |
||||||
|
f 7/1/1 8/3/1 4/9/1 |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
[remap] |
||||||
|
|
||||||
|
importer="wavefront_obj" |
||||||
|
type="Mesh" |
||||||
|
path="res://.import/grass_triangle.obj-46b3ab3674e3d39ea8727b7c5a77c4a9.mesh" |
||||||
|
|
||||||
|
[deps] |
||||||
|
|
||||||
|
files=[ "res://.import/grass_triangle.obj-46b3ab3674e3d39ea8727b7c5a77c4a9.mesh" ] |
||||||
|
|
||||||
|
source_file="res://world/grass_triangle.obj" |
||||||
|
dest_files=[ "res://.import/grass_triangle.obj-46b3ab3674e3d39ea8727b7c5a77c4a9.mesh", "res://.import/grass_triangle.obj-46b3ab3674e3d39ea8727b7c5a77c4a9.mesh" ] |
||||||
|
|
||||||
|
[params] |
||||||
|
|
||||||
|
generate_tangents=true |
||||||
|
scale_mesh=Vector3( 1, 1, 1 ) |
||||||
|
offset_mesh=Vector3( 0, 0, 0 ) |
||||||
|
octahedral_compression=true |
||||||
|
optimize_mesh_flags=4286 |
||||||
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.9 KiB |
@ -0,0 +1,77 @@ |
|||||||
|
shader_type spatial; |
||||||
|
render_mode cull_disabled, unshaded; |
||||||
|
|
||||||
|
uniform float wind_speed = 0.2; |
||||||
|
uniform float wind_strength = 2.0; |
||||||
|
// How big, in world space, is the noise texture |
||||||
|
// wind will tile every wind_texture_tile_size |
||||||
|
uniform float wind_texture_tile_size = 20.0; |
||||||
|
uniform float wind_vertical_strength = 0.3; |
||||||
|
uniform vec2 wind_horizontal_direction = vec2(1.0, 0.5); |
||||||
|
|
||||||
|
uniform sampler2D color_ramp : hint_black_albedo; |
||||||
|
// we need a tiling noise here! |
||||||
|
uniform sampler2D wind_noise : hint_black; |
||||||
|
|
||||||
|
uniform vec3 character_position; |
||||||
|
uniform float character_radius = 3.0; |
||||||
|
uniform sampler2D character_distance_falloff_curve : hint_black_albedo; |
||||||
|
uniform float character_push_strength = 1.0; |
||||||
|
|
||||||
|
varying float debug_wind; |
||||||
|
|
||||||
|
void vertex() { |
||||||
|
vec3 world_vert = (WORLD_MATRIX * vec4(VERTEX, 1.0)).xyz; |
||||||
|
|
||||||
|
vec2 normalized_wind_direction = normalize(wind_horizontal_direction); |
||||||
|
vec2 world_uv = world_vert.xz / wind_texture_tile_size + normalized_wind_direction * TIME * wind_speed; |
||||||
|
// we displace only the top part of the mesh |
||||||
|
// note that this means that the mesh needs to have UV in a way that the bottom of UV space |
||||||
|
// is at the top of the mesh |
||||||
|
float displacement_affect = (1.0 - UV.y); |
||||||
|
float wind_noise_intensity = (textureLod(wind_noise, world_uv, 0.0).r - 0.5); |
||||||
|
|
||||||
|
// We convert the direction of the wind into vertex space from world space |
||||||
|
// if we used it directly in vertex space, rotated blades of grass wouldn't behave properly |
||||||
|
vec2 vert_space_horizontal_dir = |
||||||
|
(inverse(WORLD_MATRIX) * vec4(wind_horizontal_direction, 0.0, 0.0)).xy; |
||||||
|
|
||||||
|
vert_space_horizontal_dir = normalize(vert_space_horizontal_dir); |
||||||
|
|
||||||
|
vec3 bump_wind = vec3( |
||||||
|
wind_noise_intensity * vert_space_horizontal_dir.x, |
||||||
|
1.0 - wind_noise_intensity, |
||||||
|
wind_noise_intensity * vert_space_horizontal_dir.y); |
||||||
|
|
||||||
|
normalize(bump_wind); |
||||||
|
|
||||||
|
bump_wind *= vec3(wind_strength, wind_vertical_strength, wind_strength); |
||||||
|
|
||||||
|
VERTEX += bump_wind * displacement_affect; |
||||||
|
|
||||||
|
// At the moment the blades are pushed away in a perfectly circular manner. |
||||||
|
// We could distort the distance to the character based on a noise, to break a bit the |
||||||
|
// circular shape. We could distort the falloff by sampling in a noise based on the xz coordinates. |
||||||
|
// The task is left to the reader |
||||||
|
|
||||||
|
vec3 dir_to_character = character_position - WORLD_MATRIX[3].xyz; |
||||||
|
// uncomment the following line to have a horizontal only character push |
||||||
|
//dir_to_character.y = 0.0; |
||||||
|
float distance_to_character = length(dir_to_character); |
||||||
|
float falloff = 1.0 - smoothstep(0.0, 1.0, distance_to_character/character_radius); |
||||||
|
// Because we operate in vertex space, we need to convert the direction to the character |
||||||
|
// in vertex space. Otherwise, it wouldn't work for rotated blades of grass. |
||||||
|
// comment the next line to observe how the blades are not all facing away from the character. |
||||||
|
dir_to_character = (inverse(WORLD_MATRIX) * vec4(dir_to_character, 0.0)).xyz; |
||||||
|
dir_to_character = normalize(dir_to_character); |
||||||
|
|
||||||
|
// sample the curve based on how far we are from the character, in normalized coordinates |
||||||
|
float falloff_curve = texture(character_distance_falloff_curve, vec2(falloff)).x; |
||||||
|
// direction to character is inverted because we want to point away from it |
||||||
|
VERTEX += normalize(-dir_to_character) * falloff_curve * character_push_strength * displacement_affect; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void fragment() { |
||||||
|
ALBEDO = texture(color_ramp, vec2(1.0 - UV.y, 0)).rgb ; |
||||||
|
} |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
[gd_resource type="ShaderMaterial" load_steps=8 format=2] |
||||||
|
|
||||||
|
[ext_resource path="res://world/materials/wind_grass.shader" type="Shader" id=1] |
||||||
|
|
||||||
|
[sub_resource type="Curve" id=1] |
||||||
|
_data = [ Vector2( 0, 0 ), 0.0, 2.71765, 0, 0, Vector2( 1, 1 ), -0.129412, 0.0, 0, 0 ] |
||||||
|
|
||||||
|
[sub_resource type="CurveTexture" id=2] |
||||||
|
width = 128 |
||||||
|
curve = SubResource( 1 ) |
||||||
|
|
||||||
|
[sub_resource type="Gradient" id=3] |
||||||
|
offsets = PoolRealArray( 0, 0.486339, 0.966102 ) |
||||||
|
colors = PoolColorArray( 0.054902, 0.556863, 0.439216, 1, 0.321569, 0.886275, 0.341176, 1, 0.498039, 0.921569, 0.356863, 1 ) |
||||||
|
|
||||||
|
[sub_resource type="GradientTexture" id=4] |
||||||
|
gradient = SubResource( 3 ) |
||||||
|
|
||||||
|
[sub_resource type="OpenSimplexNoise" id=5] |
||||||
|
period = 109.1 |
||||||
|
persistence = 0.138 |
||||||
|
lacunarity = 0.44 |
||||||
|
|
||||||
|
[sub_resource type="NoiseTexture" id=6] |
||||||
|
seamless = true |
||||||
|
noise = SubResource( 5 ) |
||||||
|
|
||||||
|
[resource] |
||||||
|
shader = ExtResource( 1 ) |
||||||
|
shader_param/wind_speed = 0.2 |
||||||
|
shader_param/wind_strength = 2.0 |
||||||
|
shader_param/wind_texture_tile_size = 20.0 |
||||||
|
shader_param/wind_vertical_strength = 0.3 |
||||||
|
shader_param/wind_horizontal_direction = Vector2( 1, 0.5 ) |
||||||
|
shader_param/character_position = Vector3( 0, 1.22062, 0 ) |
||||||
|
shader_param/character_radius = 3.0 |
||||||
|
shader_param/character_push_strength = 1.0 |
||||||
|
shader_param/color_ramp = SubResource( 4 ) |
||||||
|
shader_param/wind_noise = SubResource( 6 ) |
||||||
|
shader_param/character_distance_falloff_curve = SubResource( 2 ) |
||||||
Loading…
Reference in new issue