first examples
This commit is contained in:
parent
a01a7a7acc
commit
2219e943da
33 changed files with 785 additions and 6 deletions
16
shaders/000_playground/playground.gd
Normal file
16
shaders/000_playground/playground.gd
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
@tool
|
||||
extends Node3D
|
||||
|
||||
@export var my_variable: float = 1.0:
|
||||
set(value):
|
||||
my_variable = value
|
||||
shader_material.set_shader_parameter("my_variable", value)
|
||||
|
||||
@onready var shader_material = $MeshInstance3D.mesh.material
|
||||
|
||||
func _ready() -> void:
|
||||
print(shader_material)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
13
shaders/000_playground/playground.gdshader
Normal file
13
shaders/000_playground/playground.gdshader
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
shader_type spatial;
|
||||
|
||||
uniform float my_variable = 0.0;
|
||||
|
||||
void vertex() {
|
||||
VERTEX.y += my_variable;
|
||||
// Called for every vertex the material is visible on.
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
ALBEDO = NORMAL;
|
||||
// Called for every pixel the material is visible on.
|
||||
}
|
||||
18
shaders/000_playground/playground.tscn
Normal file
18
shaders/000_playground/playground.tscn
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://c0c1k04qmog56"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/000_playground/playground.gdshader" id="1_0fhw0"]
|
||||
[ext_resource type="Script" path="res://shaders/000_playground/playground.gd" id="1_08keh"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_h8cto"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_0fhw0")
|
||||
shader_parameter/my_variable = 1.0
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_6preo"]
|
||||
material = SubResource("ShaderMaterial_h8cto")
|
||||
|
||||
[node name="Playground" type="Node3D"]
|
||||
script = ExtResource("1_08keh")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_6preo")
|
||||
5
shaders/001_change_color/change_color.gdshader
Normal file
5
shaders/001_change_color/change_color.gdshader
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
shader_type spatial;
|
||||
|
||||
void fragment() {
|
||||
ALBEDO = vec3(0.1, 0.2, 0.6);
|
||||
}
|
||||
15
shaders/001_change_color/change_color.tscn
Normal file
15
shaders/001_change_color/change_color.tscn
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://o76dbkg8478j"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/001_change_color/change_color.gdshader" id="1_d0kbx"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_yrrhw"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_d0kbx")
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_16ni7"]
|
||||
material = SubResource("ShaderMaterial_yrrhw")
|
||||
|
||||
[node name="ChangeColor" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_16ni7")
|
||||
5
shaders/002_change_position/change_position.gdshader
Normal file
5
shaders/002_change_position/change_position.gdshader
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
shader_type spatial;
|
||||
|
||||
void vertex() {
|
||||
VERTEX.y += 0.5;
|
||||
}
|
||||
15
shaders/002_change_position/change_position.tscn
Normal file
15
shaders/002_change_position/change_position.tscn
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bm381ddsm6nv3"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/002_change_position/change_position.gdshader" id="1_milct"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_q2e1w"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_milct")
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_f3uhw"]
|
||||
material = SubResource("ShaderMaterial_q2e1w")
|
||||
|
||||
[node name="ChangePosition" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_f3uhw")
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
shader_type spatial;
|
||||
|
||||
void vertex() {
|
||||
VERTEX.y += 0.5;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
ALBEDO = vec3(0.1, 0.2, 0.6);
|
||||
}
|
||||
15
shaders/003_color_and_position/color_and_position.tscn
Normal file
15
shaders/003_color_and_position/color_and_position.tscn
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://b2nxlaom04udy"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/003_color_and_position/color_and_position.gdshader" id="1_igsbe"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_r8oyo"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_igsbe")
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_5deb6"]
|
||||
material = SubResource("ShaderMaterial_r8oyo")
|
||||
|
||||
[node name="ColorAndPosition" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_5deb6")
|
||||
9
shaders/004_adding_time/adding_time.gdshader
Normal file
9
shaders/004_adding_time/adding_time.gdshader
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
shader_type spatial;
|
||||
|
||||
void vertex() {
|
||||
VERTEX.y += 0.5 + sin(TIME * 3.0) * 0.35;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
ALBEDO = vec3(0.1, 0.2, 0.6);
|
||||
}
|
||||
15
shaders/004_adding_time/adding_time.tscn
Normal file
15
shaders/004_adding_time/adding_time.tscn
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://dcrg7uyqekgl7"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/004_adding_time/adding_time.gdshader" id="1_ejoc4"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5gyar"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_ejoc4")
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_xljse"]
|
||||
material = SubResource("ShaderMaterial_5gyar")
|
||||
|
||||
[node name="AddingTime" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_xljse")
|
||||
12
shaders/005_displacing_vertices/displacing_vertices.gdshader
Normal file
12
shaders/005_displacing_vertices/displacing_vertices.gdshader
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
shader_type spatial;
|
||||
|
||||
uniform float waves = 3.0;
|
||||
|
||||
void vertex() {
|
||||
// Changing the waves parameter changes how warped the sphere is
|
||||
VERTEX.y += 0.5 + sin(VERTEX.x * waves + TIME * 4.0) * 0.35;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
ALBEDO = vec3(0.1, 0.2, 0.6);
|
||||
}
|
||||
16
shaders/005_displacing_vertices/displacing_vertices.tscn
Normal file
16
shaders/005_displacing_vertices/displacing_vertices.tscn
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://du06a3dwu2yy6"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/005_displacing_vertices/displacing_vertices.gdshader" id="1_7mier"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_c46ul"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_7mier")
|
||||
shader_parameter/waves = 3.0
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_l7vfg"]
|
||||
material = SubResource("ShaderMaterial_c46ul")
|
||||
|
||||
[node name="DisplacingVertices" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_l7vfg")
|
||||
25
shaders/006_variables/variables.gdshader
Normal file
25
shaders/006_variables/variables.gdshader
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
shader_type spatial;
|
||||
|
||||
/**
|
||||
* This is a documentation comment.
|
||||
* These lines will appear in the inspector when hovering over the shader parameters
|
||||
* You can use [b]BBCode[/b] [i]formatting[/i] in the comment.
|
||||
* The Offset From Ground shifts the model up and down.
|
||||
*/
|
||||
uniform float offset_from_ground = 0.5;
|
||||
|
||||
/**
|
||||
* This parameter influcenes the amount of waves
|
||||
*/
|
||||
uniform float waves = 8.0;
|
||||
uniform float speed = 2.0;
|
||||
uniform float wave_height = 0.5;
|
||||
|
||||
void vertex() {
|
||||
// Changing the waves parameter changes how warped the sphere is
|
||||
VERTEX.y += offset_from_ground + sin(VERTEX.x * waves + TIME * speed) * wave_height;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
ALBEDO = vec3(0.1, 0.2, 0.6);
|
||||
}
|
||||
19
shaders/006_variables/variables.tscn
Normal file
19
shaders/006_variables/variables.tscn
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://5clduk3kph4t"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/006_variables/variables.gdshader" id="1_gh1k7"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_u3tcf"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_gh1k7")
|
||||
shader_parameter/offset_from_ground = 0.5
|
||||
shader_parameter/waves = 8.0
|
||||
shader_parameter/speed = 2.0
|
||||
shader_parameter/wave_height = 0.5
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_sctja"]
|
||||
material = SubResource("ShaderMaterial_u3tcf")
|
||||
|
||||
[node name="Variables" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_sctja")
|
||||
17
shaders/007_reflections/reflections.gdshader
Normal file
17
shaders/007_reflections/reflections.gdshader
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
shader_type spatial;
|
||||
|
||||
uniform float offset_from_ground = 0.5;
|
||||
uniform float waves = 8.0;
|
||||
uniform float speed = 2.0;
|
||||
uniform float wave_height = 0.5;
|
||||
|
||||
void vertex() {
|
||||
// Changing the waves parameter changes how warped the sphere is
|
||||
VERTEX.y += offset_from_ground + sin(VERTEX.x * waves + TIME * speed) * wave_height;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
ALBEDO = vec3(0.8, 0.5, 0.0);
|
||||
METALLIC = 1.0;
|
||||
ROUGHNESS = 0.1;
|
||||
}
|
||||
19
shaders/007_reflections/reflections.tscn
Normal file
19
shaders/007_reflections/reflections.tscn
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://csh1kbx37l5el"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/007_reflections/reflections.gdshader" id="1_jqhug"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_vldik"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_jqhug")
|
||||
shader_parameter/offset_from_ground = 0.5
|
||||
shader_parameter/waves = 8.0
|
||||
shader_parameter/speed = 2.0
|
||||
shader_parameter/wave_height = 0.5
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_ww17y"]
|
||||
material = SubResource("ShaderMaterial_vldik")
|
||||
|
||||
[node name="Reflections" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_ww17y")
|
||||
14
shaders/008_normals/normals.gdshader
Normal file
14
shaders/008_normals/normals.gdshader
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
shader_type spatial;
|
||||
|
||||
// To send data from the vertex to the fragment (or light) processor function,
|
||||
// varyings are used. They are set for every primitive vertex in the vertex processor,
|
||||
// and the value is interpolated for every pixel in the fragment processor.
|
||||
varying vec3 color;
|
||||
|
||||
void vertex() {
|
||||
color = NORMAL;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
ALBEDO = color;
|
||||
}
|
||||
15
shaders/008_normals/normals.tscn
Normal file
15
shaders/008_normals/normals.tscn
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bjoxcmy6sy8lb"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/008_normals/normals.gdshader" id="1_bpfbn"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ktxik"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_bpfbn")
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_288vy"]
|
||||
material = SubResource("ShaderMaterial_ktxik")
|
||||
|
||||
[node name="Normals" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_288vy")
|
||||
Loading…
Add table
Add a link
Reference in a new issue