GODOT Shaders for NOOBS - 012 The grid

  Рет қаралды 1,595

Pixezy

Pixezy

Күн бұрын

Пікірлер: 5
@animedreamz2009
@animedreamz2009 11 ай бұрын
What about making a pixel gradient
@BeyondPC
@BeyondPC Жыл бұрын
This was a very useful tutorial; however there are issues with the audio. On my cell phone it sounds 'ok' but on my computer it is very muffled and bassy - to the point where I cannot understand what you are saying. That said the tutorial was perfect for what I needed to do! Thanks :)
@jeremiahmcelroy2726
@jeremiahmcelroy2726 11 ай бұрын
How would I detect if the mouse is hovering over a given cell? I created this code to load from a dataTexture generated by a compute shader that generates the game of life, but I can't for the life of me figure out how to use GlobalMousePosition I'm passing to the shader to determine if the mouse is within a given cell shader_type canvas_item; uniform sampler2D unlitTexture; uniform sampler2D litTexture; uniform sampler2D binaryDataTexture; uniform int gridWidth; uniform int gridHeight; uniform vec2 globalMousePos; varying flat vec2 vertexPos[2]; varying vec2 screenUV; const int cellSize = 8; void vertex() { vertexPos[0] = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy; } void fragment() { //total size of the grid in pixels vec2 totalGridSize = vec2(float(gridWidth) * float(cellSize), float(gridHeight) * float(cellSize)); //scale UV to grid dimensions vec2 scaledUV = UV * vec2(float(gridWidth), float(gridHeight)); vec2 cellUV = fract(scaledUV); bool isInsideCell = all(greaterThanEqual(cellUV, vec2(0.0))) && all(lessThan(cellUV, vec2(1.0))); ivec2 cellIndex = ivec2(floor(scaledUV)); vec2 binaryDataUV = vec2( float(cellIndex.x) / float(gridWidth - 1), float(cellIndex.y) / float(gridHeight - 1) ); float binaryValue = texture(binaryDataTexture, binaryDataUV).r; bool isWhite = binaryValue > 0.5; vec4 color = texture(unlitTexture, cellUV); if(isWhite && isInsideCell) { color = texture(litTexture, cellUV); } COLOR = color; }
@pixezy8962
@pixezy8962 11 ай бұрын
I've never tried it before, it looks like a coordinate problem, it's something that's going on my list of tutorials to do.
@jeremiahmcelroy2726
@jeremiahmcelroy2726 11 ай бұрын
@@pixezy8962 I ended up getting it actually. Here's the working code. Only issue is my compute shader isn't exactly updating now, I need to write it back to the data texture. I might take a pause on this project and read through the big book of shaders. Here's my code properly highlighting cells at least shader_type canvas_item; uniform sampler2D unlitTexture; uniform sampler2D litTexture; uniform sampler2D binaryDataTexture; uniform int gridWidth; uniform int gridHeight; uniform float brushSize; uniform vec2 globalMousePos; varying vec2 vertexPos; // Declare vertexPos varying variable const int cellSize = 8; void vertex() { // Automatically provided VERTEX is used, no manual assignment needed vertexPos = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy; } void fragment() { //total size of the grid in pixels vec2 totalGridSize = vec2(float(gridWidth) * float(cellSize), float(gridHeight) * float(cellSize)); //scale UV to grid dimensions vec2 scaledUV = UV * vec2(float(gridWidth), float(gridHeight)); vec2 cellUV = fract(scaledUV); bool isInsideCell = all(greaterThanEqual(cellUV, vec2(0.0))) && all(lessThan(cellUV, vec2(1.0))); ivec2 cellIndex = ivec2(floor(scaledUV)); vec2 binaryDataUV = vec2( float(cellIndex.x) / float(gridWidth - 1), float(cellIndex.y) / float(gridHeight - 1) ); float binaryValue = texture(binaryDataTexture, binaryDataUV).r; bool isWhite = binaryValue > 0.5; vec4 color = texture(unlitTexture, cellUV); // Use vertex positions to determine if the mouse is within the vertices of a cell vec2 vertex1 = floor(vertexPos / vec2(brushSize)) * vec2(brushSize); vec2 vertex2 = vertex1 + vec2(brushSize); bool isMouseInsideVertices = all(greaterThanEqual(globalMousePos, vertex1)) && all(lessThan(globalMousePos, vertex2)); // && isMouseInsideVertices if(isWhite && isInsideCell) { color = texture(litTexture, cellUV); } if(isMouseInsideVertices) { if(color == texture(litTexture, cellUV)) { color = texture(unlitTexture, cellUV); } else if(color == texture(unlitTexture, cellUV)){ color = texture(litTexture, cellUV); } } COLOR = color; } //void light() { // Called for every pixel for every light affecting the CanvasItem. // Uncomment to replace the default light processing function with this one. //}
GODOT Shaders for NOOBS - 013 Deformations
12:12
Pixezy
Рет қаралды 1,1 М.
GODOT TUTORIAL: Shockwave shader for noobs
15:48
Nolkaloid
Рет қаралды 56 М.
#behindthescenes @CrissaJackson
0:11
Happy Kelli
Рет қаралды 27 МЛН
Draw fewer tiles - by using a Dual-Grid system!
6:22
jess::codes
Рет қаралды 696 М.
MORE VFX Shader Techniques ft. Godot
8:43
onetupthree
Рет қаралды 29 М.
Godot: Baked Pivots
11:41
Pixezy
Рет қаралды 1,9 М.
How To Write Fast Shaders
10:33
Jump Trajectory
Рет қаралды 21 М.
Hex Grid Basics in Godot 4.2 - Clicking in Grid, Tilemap, Tileset
8:37
Introduction to shaders: Learn the basics!
34:50
Barney Codes
Рет қаралды 372 М.
An introduction to Shader Art Coding
22:40
kishimisu
Рет қаралды 1 МЛН
The Key to Realistic Renders in Blender
14:31
Kaizen
Рет қаралды 147 М.
I Made My First Game in Godot in 3 Weeks...
26:21
Jack Sather
Рет қаралды 462 М.
Welcome to Shaderland - An introduction to shaders in Godot
1:12:51