Dit artikel is een technische handleiding voor het creëren van een geanimeerd portaal-effect in de game engine Godot 4, waarbij de focus ligt op de combinatie van GDShader en GDScript.
De belangrijkste technische concepten die aan bod komen zijn:
Texture Sampling & UV's: Hoe UV-coördinaten werken, het verschil tussen Nearest en Linear filtering, en het gebruik van repeat-modi voor texturen.
Deformatie-logica: Het gebruik van een Distance Field aanpak om de vorm van het portaal te bepalen, inclusief het toevoegen van oscillatie (sin(TIME)) en noise voor een organisch effect.
Animatietechnieken: Het toepassen van texture panning en het gebruik van Tweens in GDScript voor vloeiende overgangen van shader-parameters.
GDScript & Shader Interactie: Het onderscheid tussen standaard uniforms en instance uniforms, waarbij die laatste essentieel zijn voor prestaties wanneer meerdere unieke objecten dezelfde shader gebruiken.
Geavanceerde Kleuring: Het creëren van radiale gradiënten door smoothstep() te combineren met de mix() functie.
Below is a structured summary and a "cheat sheet" of the key concepts taught in the tutorial, organized by technical category.
---
1. Texture Sampling & UVs
UV Coordinates: Represented as percentages (0.0 to 1.0). (0,0) is top-left, (1,1) is bottom-right.
Filtering:
Nearest: Picks the closest texel (pixelated/retro look).
Linear: Blends surrounding texels (smooth look).
Repeat Modes: Controls what happens when UVs go outside the 0-1 range.
Disabled: Clamps to the edge (creates streaks).
Enabled: Tiles the texture infinitely.
Mirror: Tiles the texture but flips every other tile.
Sampling Code:texture(TEXTURE, UV).r (samples the red channel of the texture at the current UV position).
2. Deforming Shapes (The Portal Logic)
The portal is created using a Distance Field approach:
Distance Calculation: Calculate how far a pixel is from the center: distance(UV, vec2(0.5, 0.5)).
Deformation: Add values to this distance to "push" or "pull" the edge:
Oscillation:sin(TIME) * strength (creates a breathing effect).
Masking: Use smoothstep() to create hard or soft edges based on a radius threshold.
Layering: Creating a "rim" by subtracting a smaller inner mask from a larger outer mask (maskrim = maskouter - mask_inner).
3. Animation Techniques
Panning: Moving a texture over time by adding TIME to the UV coordinates:
vec2 sample_uv = UV + TIME direction speed;
Seamlessness: Enabling TextureSeamless in the NoiseTexture2D properties removes the visible seam where the texture wraps.
4. GDScript & Shader Interaction
Standard Uniforms: Use material.setshaderparameter("name", value). These affect all objects sharing that material.
Instance Uniforms: Declared as instance uniform float name. These allow each individual object to have unique values without duplicating the material resource.
Masking: Use smoothstep() to create hard or soft edges based on a radius threshold.
Layering: Creating a "rim" by subtracting a smaller inner mask from a larger outer mask (maskrim = maskouter - mask_inner).
3. Animation Techniques
Panning: Moving a texture over time by adding TIME to the UV coordinates:
vec2 sample_uv = UV + TIME direction speed;
Seamlessness: Enabling TextureSeamless in the NoiseTexture2D properties removes the visible seam where the texture wraps.
4. GDScript & Shader Interaction
Standard Uniforms: Use material.setshaderparameter("name", value). These affect all objects sharing that material.
Instance Uniforms: Declared as instance uniform float name. These allow each individual object to have unique values without duplicating the material resource.
Tweens: For smooth transitions (e.g., opening the portal).
Path: To animate a shader parameter via a Tween, use the property path: "shader_parameter/radius".
Parallelism: Use .set_parallel() to animate multiple parameters (radius, color, strength) simultaneously.
5. Advanced Coloring (Gradients)
The mix() Function: Blends two values based on a weight (0.0 to 1.0).
vec3 color = mix(colora, colorb, weight);
Creating Radial Gradients:
Use smoothstep() to map the distance from the center to a 0-1 range.
Use that result as the weight for mix().
Apply this to the masks to ensure the gradient only appears inside the portal.
---
Final "Pro-Tip" Summary
Goal
Tool/Function
Key Detail
Smooth Edges
smoothstep()
Better than step() as it prevents aliasing.
Randomness
NoiseTexture2D
Use the .r channel for grayscale displacement.
Performance
instance uniform
Prevents creating hundreds of unique material resources.
Natural Motion
sin(TIME) + Noise
Combines predictable math with chaotic textures.
Smooth Transition
Tween + TRANS_CUBIC
Makes the portal "feel" organic rather than robotic.
Zichtbare categorieën
Kies welke categorieën je wilt zien.
Over deze site
Waarom Tech-update?
Tech-update is ontstaan omdat ik merkte dat ik dagelijks veel verschillende websites moest bezoeken om interessant technieuws te vinden. Dat kon efficiënter.
Hoe werkt het?
Meerdere keren per etmaal gaat mijn zelfgebouwde AI-agent op zoek naar interessante artikelen op blogs en nieuwssites.
Vindt hij iets relevants, dan wordt het artikel naar het Nederlands vertaald en op Tech-Update geplaatst.
Van ieder artikel maakt de AI ook een korte samenvatting. Zo kun je snel bepalen of het de moeite waard is om het volledige artikel te lezen.
Bij ieder artikel staat altijd een link naar de oorspronkelijke bron (vaak een Engelstalige website).
Artikelen kun je bewaren als favoriet, vastzetten in de zijbalk of terugvinden via de zoekfunctie.
In de instellingen (tandwielikoon rechtsboven) geef je aan in welk soort nieuws je geïnteresseert bent.