From 645c0ab713a391f96bce344676582f99f72866a4 Mon Sep 17 00:00:00 2001 From: Milan Nikolic Date: Tue, 14 Nov 2017 13:24:06 +0100 Subject: [PATCH] Fix shaders --- .../shaders/postprocessing/glsl330/base.vs | 26 ------ .../shaders/postprocessing/glsl330/blur.fs | 35 ++++++++ .../postprocessing/glsl330/cross_hatching.fs | 48 ++++++++++ .../postprocessing/glsl330/cross_stitching.fs | 59 ++++++++++++ .../postprocessing/glsl330/dream_vision.fs | 34 +++++++ .../shaders/postprocessing/glsl330/fisheye.fs | 40 +++++++++ .../postprocessing/glsl330/grayscale.fs | 26 ++++++ .../postprocessing/glsl330/pixelizer.fs | 33 +++++++ .../postprocessing/glsl330/posterization.fs | 31 +++++++ .../postprocessing/glsl330/predator.fs | 32 +++++++ .../postprocessing/glsl330/scanlines.fs | 49 ++++++++++ .../shaders/postprocessing/glsl330/sobel.fs | 41 +++++++++ examples/shaders/postprocessing/main.go | 90 ++++++++++++++++--- raylib/shaders.go | 14 ++- 14 files changed, 518 insertions(+), 40 deletions(-) delete mode 100644 examples/shaders/postprocessing/glsl330/base.vs create mode 100644 examples/shaders/postprocessing/glsl330/blur.fs create mode 100644 examples/shaders/postprocessing/glsl330/cross_hatching.fs create mode 100644 examples/shaders/postprocessing/glsl330/cross_stitching.fs create mode 100644 examples/shaders/postprocessing/glsl330/dream_vision.fs create mode 100644 examples/shaders/postprocessing/glsl330/fisheye.fs create mode 100644 examples/shaders/postprocessing/glsl330/grayscale.fs create mode 100644 examples/shaders/postprocessing/glsl330/pixelizer.fs create mode 100644 examples/shaders/postprocessing/glsl330/posterization.fs create mode 100644 examples/shaders/postprocessing/glsl330/predator.fs create mode 100644 examples/shaders/postprocessing/glsl330/scanlines.fs create mode 100644 examples/shaders/postprocessing/glsl330/sobel.fs diff --git a/examples/shaders/postprocessing/glsl330/base.vs b/examples/shaders/postprocessing/glsl330/base.vs deleted file mode 100644 index 1cb3729..0000000 --- a/examples/shaders/postprocessing/glsl330/base.vs +++ /dev/null @@ -1,26 +0,0 @@ -#version 330 - -// Input vertex attributes -in vec3 vertexPosition; -in vec2 vertexTexCoord; -in vec3 vertexNormal; -in vec4 vertexColor; - -// Input uniform values -uniform mat4 mvp; - -// Output vertex attributes (to fragment shader) -out vec2 fragTexCoord; -out vec4 fragColor; - -// NOTE: Add here your custom variables - -void main() -{ - // Send vertex attributes to fragment shader - fragTexCoord = vertexTexCoord; - fragColor = vertexColor; - - // Calculate final vertex position - gl_Position = mvp*vec4(vertexPosition, 1.0); -} diff --git a/examples/shaders/postprocessing/glsl330/blur.fs b/examples/shaders/postprocessing/glsl330/blur.fs new file mode 100644 index 0000000..e4df406 --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/blur.fs @@ -0,0 +1,35 @@ +#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; + +// NOTE: Add here your custom variables + +// NOTE: Render size values must be passed from code +const float renderWidth = 800; +const float renderHeight = 450; + +float offset[3] = float[](0.0, 1.3846153846, 3.2307692308); +float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703); + +void main() +{ + // Texel color fetching from texture sampler + vec3 texelColor = texture(texture0, fragTexCoord).rgb*weight[0]; + + for (int i = 1; i < 3; i++) + { + texelColor += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; + texelColor += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; + } + + finalColor = vec4(texelColor, 1.0); +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/glsl330/cross_hatching.fs b/examples/shaders/postprocessing/glsl330/cross_hatching.fs new file mode 100644 index 0000000..f95ad07 --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/cross_hatching.fs @@ -0,0 +1,48 @@ +#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; + +// NOTE: Add here your custom variables + +float hatchOffsetY = 5.0; +float lumThreshold01 = 0.9; +float lumThreshold02 = 0.7; +float lumThreshold03 = 0.5; +float lumThreshold04 = 0.3; + +void main() +{ + vec3 tc = vec3(1.0, 1.0, 1.0); + float lum = length(texture(texture0, fragTexCoord).rgb); + + if (lum < lumThreshold01) + { + if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); + } + + if (lum < lumThreshold02) + { + if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); + } + + if (lum < lumThreshold03) + { + if (mod(gl_FragCoord.x + gl_FragCoord.y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); + } + + if (lum < lumThreshold04) + { + if (mod(gl_FragCoord.x - gl_FragCoord.y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); + } + + finalColor = vec4(tc, 1.0); +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/glsl330/cross_stitching.fs b/examples/shaders/postprocessing/glsl330/cross_stitching.fs new file mode 100644 index 0000000..9cdd36c --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/cross_stitching.fs @@ -0,0 +1,59 @@ +#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; + +// NOTE: Add here your custom variables + +// NOTE: Render size values must be passed from code +const float renderWidth = 800.0; +const float renderHeight = 450.0; + +float stitchingSize = 6.0; + +uniform int invert = 0; + +vec4 PostFX(sampler2D tex, vec2 uv) +{ + vec4 c = vec4(0.0); + float size = stitchingSize; + vec2 cPos = uv * vec2(renderWidth, renderHeight); + vec2 tlPos = floor(cPos / vec2(size, size)); + tlPos *= size; + + int remX = int(mod(cPos.x, size)); + int remY = int(mod(cPos.y, size)); + + if (remX == 0 && remY == 0) tlPos = cPos; + + vec2 blPos = tlPos; + blPos.y += (size - 1.0); + + if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))) + { + if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0); + else c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; + } + else + { + if (invert == 1) c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; + else c = vec4(0.0, 0.0, 0.0, 1.0); + } + + return c; +} + +void main() +{ + vec3 tc = PostFX(texture0, fragTexCoord).rgb; + + finalColor = vec4(tc, 1.0); +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/glsl330/dream_vision.fs b/examples/shaders/postprocessing/glsl330/dream_vision.fs new file mode 100644 index 0000000..0311586 --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/dream_vision.fs @@ -0,0 +1,34 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +void main() +{ + vec4 color = texture(texture0, fragTexCoord); + + color += texture(texture0, fragTexCoord + 0.001); + color += texture(texture0, fragTexCoord + 0.003); + color += texture(texture0, fragTexCoord + 0.005); + color += texture(texture0, fragTexCoord + 0.007); + color += texture(texture0, fragTexCoord + 0.009); + color += texture(texture0, fragTexCoord + 0.011); + + color += texture(texture0, fragTexCoord - 0.001); + color += texture(texture0, fragTexCoord - 0.003); + color += texture(texture0, fragTexCoord - 0.005); + color += texture(texture0, fragTexCoord - 0.007); + color += texture(texture0, fragTexCoord - 0.009); + color += texture(texture0, fragTexCoord - 0.011); + + color.rgb = vec3((color.r + color.g + color.b)/3.0); + color = color/9.5; + + fragColor = color; +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/glsl330/fisheye.fs b/examples/shaders/postprocessing/glsl330/fisheye.fs new file mode 100644 index 0000000..e85d7c9 --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/fisheye.fs @@ -0,0 +1,40 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +const float PI = 3.1415926535; + +void main() +{ + float aperture = 178.0; + float apertureHalf = 0.5 * aperture * (PI / 180.0); + float maxFactor = sin(apertureHalf); + + vec2 uv = vec2(0); + vec2 xy = 2.0 * fragTexCoord.xy - 1.0; + float d = length(xy); + + if (d < (2.0 - maxFactor)) + { + d = length(xy * maxFactor); + float z = sqrt(1.0 - d * d); + float r = atan(d, z) / PI; + float phi = atan(xy.y, xy.x); + + uv.x = r * cos(phi) + 0.5; + uv.y = r * sin(phi) + 0.5; + } + else + { + uv = fragTexCoord.xy; + } + + fragColor = texture(texture0, uv); +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/glsl330/grayscale.fs b/examples/shaders/postprocessing/glsl330/grayscale.fs new file mode 100644 index 0000000..5b3e11b --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/grayscale.fs @@ -0,0 +1,26 @@ +#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; + +// NOTE: Add here your custom variables + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord)*colDiffuse*fragColor; + + // Convert texel color to grayscale using NTSC conversion weights + float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); + + // Calculate final fragment color + finalColor = vec4(gray, gray, gray, texelColor.a); +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/glsl330/pixelizer.fs b/examples/shaders/postprocessing/glsl330/pixelizer.fs new file mode 100644 index 0000000..cf8aec4 --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/pixelizer.fs @@ -0,0 +1,33 @@ +#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; + +// NOTE: Add here your custom variables + +// NOTE: Render size values must be passed from code +const float renderWidth = 800; +const float renderHeight = 450; + +uniform float pixelWidth = 5.0; +uniform float pixelHeight = 5.0; + +void main() +{ + float dx = pixelWidth*(1.0/renderWidth); + float dy = pixelHeight*(1.0/renderHeight); + + vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy)); + + vec3 tc = texture(texture0, coord).rgb; + + finalColor = vec4(tc, 1.0); +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/glsl330/posterization.fs b/examples/shaders/postprocessing/glsl330/posterization.fs new file mode 100644 index 0000000..be2b5dd --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/posterization.fs @@ -0,0 +1,31 @@ +#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; + +// NOTE: Add here your custom variables + +float gamma = 0.6; +float numColors = 8.0; + +void main() +{ + // Texel color fetching from texture sampler + vec3 texelColor = texture(texture0, fragTexCoord.xy).rgb; + + texelColor = pow(texelColor, vec3(gamma, gamma, gamma)); + texelColor = texelColor*numColors; + texelColor = floor(texelColor); + texelColor = texelColor/numColors; + texelColor = pow(texelColor, vec3(1.0/gamma)); + + finalColor = vec4(texelColor, 1.0); +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/glsl330/predator.fs b/examples/shaders/postprocessing/glsl330/predator.fs new file mode 100644 index 0000000..6a55c76 --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/predator.fs @@ -0,0 +1,32 @@ +#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; + +// NOTE: Add here your custom variables + +void main() +{ + // Texel color fetching from texture sampler + vec3 texelColor = texture(texture0, fragTexCoord).rgb; + vec3 colors[3]; + colors[0] = vec3(0.0, 0.0, 1.0); + colors[1] = vec3(1.0, 1.0, 0.0); + colors[2] = vec3(1.0, 0.0, 0.0); + + float lum = (texelColor.r + texelColor.g + texelColor.b)/3.0; + + int ix = (lum < 0.5)? 0:1; + + vec3 tc = mix(colors[ix], colors[ix + 1], (lum - float(ix)*0.5)/0.5); + + finalColor = vec4(tc, 1.0); +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/glsl330/scanlines.fs b/examples/shaders/postprocessing/glsl330/scanlines.fs new file mode 100644 index 0000000..22dc9cd --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/scanlines.fs @@ -0,0 +1,49 @@ +#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; + +// NOTE: Add here your custom variables + +// NOTE: Render size values must be passed from code +const float renderWidth = 800; +const float renderHeight = 450; +float offset = 0.0; + +uniform float time; + +void main() +{ + float frequency = renderHeight/3.0; +/* + // Scanlines method 1 + float tval = 0; //time + vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval)); + + vec4 color = texture(texture0, fragTexCoord); + + color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0); + color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y); + color *= vec4(0.8, 1.0, 0.7, 1); + color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0); + color *= 0.97 + 0.03*sin(110.0*tval); + + fragColor = color; +*/ + // Scanlines method 2 + float globalPos = (fragTexCoord.y + offset) * frequency; + float wavePos = cos((fract(globalPos) - 0.5)*3.14); + + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord); + + finalColor = mix(vec4(0.0, 0.3, 0.0, 0.0), texelColor, wavePos); +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/glsl330/sobel.fs b/examples/shaders/postprocessing/glsl330/sobel.fs new file mode 100644 index 0000000..a1430cd --- /dev/null +++ b/examples/shaders/postprocessing/glsl330/sobel.fs @@ -0,0 +1,41 @@ +#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; + +// NOTE: Add here your custom variables +uniform vec2 resolution = vec2(800, 450); + +void main() +{ + float x = 1.0/resolution.x; + float y = 1.0/resolution.y; + + vec4 horizEdge = vec4(0.0); + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + + vec4 vertEdge = vec4(0.0); + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + + vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); + + finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a); +} \ No newline at end of file diff --git a/examples/shaders/postprocessing/main.go b/examples/shaders/postprocessing/main.go index 6b6d962..bec42f1 100644 --- a/examples/shaders/postprocessing/main.go +++ b/examples/shaders/postprocessing/main.go @@ -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 diff --git a/raylib/shaders.go b/raylib/shaders.go index 8688b88..e5482a4 100644 --- a/raylib/shaders.go +++ b/raylib/shaders.go @@ -97,12 +97,20 @@ func NewShaderFromPointer(ptr unsafe.Pointer) Shader { // LoadShader - Load a custom shader and bind default locations func LoadShader(vsFileName string, fsFileName string) Shader { cvsFileName := C.CString(vsFileName) - cfsFileName := C.CString(fsFileName) defer C.free(unsafe.Pointer(cvsFileName)) + + cfsFileName := C.CString(fsFileName) defer C.free(unsafe.Pointer(cfsFileName)) - ret := C.LoadShader(cvsFileName, cfsFileName) - v := NewShaderFromPointer(unsafe.Pointer(&ret)) + var v Shader + if vsFileName == "" { + ret := C.LoadShader(nil, cfsFileName) + v = NewShaderFromPointer(unsafe.Pointer(&ret)) + } else { + ret := C.LoadShader(cvsFileName, cfsFileName) + v = NewShaderFromPointer(unsafe.Pointer(&ret)) + } + return v }