add more texture & shader examples
This commit is contained in:
parent
0dda56d08d
commit
f121c0e386
7 changed files with 415 additions and 0 deletions
67
examples/shaders/texture_waves/main.go
Normal file
67
examples/shaders/texture_waves/main.go
Normal file
|
@ -0,0 +1,67 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture waves")
|
||||
|
||||
texture := rl.LoadTexture("space.png")
|
||||
|
||||
shader := rl.LoadShader("", "wave.fs")
|
||||
|
||||
secondsLoc := rl.GetShaderLocation(shader, "seconds")
|
||||
freqXLoc := rl.GetShaderLocation(shader, "freqX")
|
||||
freqYLoc := rl.GetShaderLocation(shader, "freqY")
|
||||
ampXLoc := rl.GetShaderLocation(shader, "ampX")
|
||||
ampYLoc := rl.GetShaderLocation(shader, "ampY")
|
||||
speedXLoc := rl.GetShaderLocation(shader, "speedX")
|
||||
speedYLoc := rl.GetShaderLocation(shader, "speedY")
|
||||
|
||||
freqX := []float32{25}
|
||||
freqY := []float32{25}
|
||||
ampX := []float32{5}
|
||||
ampY := []float32{5}
|
||||
speedX := []float32{8}
|
||||
speedY := []float32{8}
|
||||
|
||||
screensize := []float32{float32(rl.GetScreenWidth()), float32(rl.GetScreenHeight())}
|
||||
|
||||
rl.SetShaderValue(shader, rl.GetShaderLocation(shader, "size"), screensize, rl.ShaderUniformVec2)
|
||||
rl.SetShaderValue(shader, freqXLoc, freqX, rl.ShaderUniformFloat)
|
||||
rl.SetShaderValue(shader, freqYLoc, freqY, rl.ShaderUniformFloat)
|
||||
rl.SetShaderValue(shader, ampXLoc, ampX, rl.ShaderUniformFloat)
|
||||
rl.SetShaderValue(shader, ampYLoc, ampY, rl.ShaderUniformFloat)
|
||||
rl.SetShaderValue(shader, speedXLoc, speedX, rl.ShaderUniformFloat)
|
||||
rl.SetShaderValue(shader, speedYLoc, speedY, rl.ShaderUniformFloat)
|
||||
|
||||
seconds := []float32{0}
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
seconds[0] += rl.GetFrameTime()
|
||||
rl.SetShaderValue(shader, secondsLoc, seconds, rl.ShaderUniformFloat)
|
||||
|
||||
rl.BeginDrawing()
|
||||
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
rl.BeginShaderMode(shader)
|
||||
rl.DrawTexture(texture, 0, 0, rl.White)
|
||||
rl.DrawTexture(texture, texture.Width, 0, rl.White)
|
||||
rl.EndShaderMode()
|
||||
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
rl.UnloadShader(shader)
|
||||
rl.UnloadTexture(texture)
|
||||
|
||||
rl.CloseWindow()
|
||||
}
|
BIN
examples/shaders/texture_waves/space.png
Normal file
BIN
examples/shaders/texture_waves/space.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
37
examples/shaders/texture_waves/wave.fs
Normal file
37
examples/shaders/texture_waves/wave.fs
Normal file
|
@ -0,0 +1,37 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
uniform float seconds;
|
||||
|
||||
uniform vec2 size;
|
||||
|
||||
uniform float freqX;
|
||||
uniform float freqY;
|
||||
uniform float ampX;
|
||||
uniform float ampY;
|
||||
uniform float speedX;
|
||||
uniform float speedY;
|
||||
|
||||
void main() {
|
||||
float pixelWidth = 1.0 / size.x;
|
||||
float pixelHeight = 1.0 / size.y;
|
||||
float aspect = pixelHeight / pixelWidth;
|
||||
float boxLeft = 0.0;
|
||||
float boxTop = 0.0;
|
||||
|
||||
vec2 p = fragTexCoord;
|
||||
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (seconds * speedX)) * ampX * pixelWidth;
|
||||
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (seconds * speedY)) * ampY * pixelHeight;
|
||||
|
||||
finalColor = texture(texture0, p)*colDiffuse*fragColor;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue