Fix shaders
This commit is contained in:
parent
4ecc34b892
commit
645c0ab713
14 changed files with 518 additions and 40 deletions
|
@ -4,6 +4,38 @@ import (
|
|||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const MaxPostproShaders = 12
|
||||
|
||||
const (
|
||||
FxGrayscale = iota
|
||||
FxPosterization
|
||||
FxDreamVision
|
||||
FxPixelizer
|
||||
FxCrossHatching
|
||||
FxCrossStitching
|
||||
FxPredatorView
|
||||
FxScanlines
|
||||
FxFisheye
|
||||
FxSobel
|
||||
FxBloom
|
||||
FxBlur
|
||||
)
|
||||
|
||||
var postproShaderText = []string{
|
||||
"GRAYSCALE",
|
||||
"POSTERIZATION",
|
||||
"DREAM_VISION",
|
||||
"PIXELIZER",
|
||||
"CROSS_HATCHING",
|
||||
"CROSS_STITCHING",
|
||||
"PREDATOR_VIEW",
|
||||
"SCANLINES",
|
||||
"FISHEYE",
|
||||
"SOBEL",
|
||||
"BLOOM",
|
||||
"BLUR",
|
||||
}
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
@ -18,25 +50,52 @@ func main() {
|
|||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
|
||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
|
||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/bloom.fs") // Load postpro shader
|
||||
// Load all postpro shaders
|
||||
// NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER)
|
||||
shaders := make([]raylib.Shader, MaxPostproShaders)
|
||||
shaders[FxGrayscale] = raylib.LoadShader("", "glsl330/grayscale.fs")
|
||||
shaders[FxPosterization] = raylib.LoadShader("", "glsl330/posterization.fs")
|
||||
shaders[FxDreamVision] = raylib.LoadShader("", "glsl330/dream_vision.fs")
|
||||
shaders[FxPixelizer] = raylib.LoadShader("", "glsl330/pixelizer.fs")
|
||||
shaders[FxCrossHatching] = raylib.LoadShader("", "glsl330/cross_hatching.fs")
|
||||
shaders[FxCrossStitching] = raylib.LoadShader("", "glsl330/cross_stitching.fs")
|
||||
shaders[FxPredatorView] = raylib.LoadShader("", "glsl330/predator.fs")
|
||||
shaders[FxScanlines] = raylib.LoadShader("", "glsl330/scanlines.fs")
|
||||
shaders[FxFisheye] = raylib.LoadShader("", "glsl330/fisheye.fs")
|
||||
shaders[FxSobel] = raylib.LoadShader("", "glsl330/sobel.fs")
|
||||
shaders[FxBlur] = raylib.LoadShader("", "glsl330/blur.fs")
|
||||
shaders[FxBloom] = raylib.LoadShader("", "glsl330/bloom.fs")
|
||||
|
||||
currentShader := FxGrayscale
|
||||
|
||||
// Create a RenderTexture2D to be used for render to texture
|
||||
target := raylib.LoadRenderTexture(screenWidth, screenHeight)
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set free camera mode
|
||||
|
||||
//raylib.SetTargetFPS(60)
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyRight) {
|
||||
currentShader++
|
||||
} else if raylib.IsKeyPressed(raylib.KeyLeft) {
|
||||
currentShader--
|
||||
}
|
||||
|
||||
if currentShader >= MaxPostproShaders {
|
||||
currentShader = 0
|
||||
} else if currentShader < 0 {
|
||||
currentShader = MaxPostproShaders - 1
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
@ -51,25 +110,34 @@ func main() {
|
|||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.DrawText("HELLO POSTPROCESSING!", 70, 190, 50, raylib.Red)
|
||||
|
||||
raylib.EndTextureMode() // End drawing to texture (now we have a texture available for next passes)
|
||||
|
||||
raylib.BeginShaderMode(shader)
|
||||
// Render previously generated texture using selected postpro shader
|
||||
raylib.BeginShaderMode(shaders[currentShader])
|
||||
|
||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||
raylib.DrawTextureRec(target.Texture, raylib.NewRectangle(0, 0, target.Texture.Width, -target.Texture.Height), raylib.NewVector2(0, 0), raylib.White)
|
||||
|
||||
raylib.EndShaderMode()
|
||||
|
||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
raylib.DrawRectangle(0, 9, 580, 30, raylib.Fade(raylib.LightGray, 0.7))
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.DarkGray)
|
||||
|
||||
raylib.DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, raylib.Black)
|
||||
raylib.DrawText(postproShaderText[currentShader], 330, 15, 20, raylib.Red)
|
||||
raylib.DrawText("< >", 540, 10, 30, raylib.DarkBlue)
|
||||
|
||||
raylib.DrawFPS(700, 15)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadShader(shader) // Unload shader
|
||||
// Unload all postpro shaders
|
||||
for i := 0; i < MaxPostproShaders; i++ {
|
||||
raylib.UnloadShader(shaders[i])
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture) // Unload texture
|
||||
raylib.UnloadModel(dwarf) // Unload model
|
||||
raylib.UnloadRenderTexture(target) // Unload render texture
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue