Initial commit
54966
examples/shaders/custom_uniform/dwarf.obj
Normal file
BIN
examples/shaders/custom_uniform/dwarf_diffuse.png
Normal file
After Width: | Height: | Size: 1.2 MiB |
26
examples/shaders/custom_uniform/glsl330/base.vs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvpMatrix;
|
||||
|
||||
// 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 = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||
}
|
46
examples/shaders/custom_uniform/glsl330/swirl.fs
Normal file
|
@ -0,0 +1,46 @@
|
|||
#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
|
||||
|
||||
const float renderWidth = 800.0; // HARDCODED for example!
|
||||
const float renderHeight = 480.0; // Use uniforms instead...
|
||||
|
||||
float radius = 250.0;
|
||||
float angle = 0.8;
|
||||
|
||||
uniform vec2 center = vec2(200.0, 200.0);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texSize = vec2(renderWidth, renderHeight);
|
||||
vec2 tc = fragTexCoord*texSize;
|
||||
tc -= center;
|
||||
|
||||
float dist = length(tc);
|
||||
|
||||
if (dist < radius)
|
||||
{
|
||||
float percent = (radius - dist)/radius;
|
||||
float theta = percent*percent*angle*8.0;
|
||||
float s = sin(theta);
|
||||
float c = cos(theta);
|
||||
|
||||
tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
|
||||
}
|
||||
|
||||
tc += center;
|
||||
vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
|
||||
|
||||
finalColor = vec4(color.rgb, 1.0);;
|
||||
}
|
97
examples/shaders/custom_uniform/main.go
Normal file
|
@ -0,0 +1,97 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
||||
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.Material.TexDiffuse = texture // Bind texture to model
|
||||
|
||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/swirl.fs") // Load postpro shader
|
||||
|
||||
// Get variable (uniform) location on the shader to connect with the program
|
||||
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
||||
swirlCenterLoc := raylib.GetShaderLocation(shader, "center")
|
||||
|
||||
swirlCenter := make([]float32, 2)
|
||||
swirlCenter[0] = float32(screenWidth) / 2
|
||||
swirlCenter[1] = float32(screenHeight) / 2
|
||||
|
||||
// Create a RenderTexture2D to be used for render to texture
|
||||
target := raylib.LoadRenderTexture(screenWidth, screenHeight)
|
||||
|
||||
// Setup orbital camera
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
mousePosition := raylib.GetMousePosition()
|
||||
|
||||
swirlCenter[0] = mousePosition.X
|
||||
swirlCenter[1] = float32(screenHeight) - mousePosition.Y
|
||||
|
||||
// Send new value to the shader to be used on drawing
|
||||
raylib.SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2)
|
||||
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.BeginTextureMode(target) // Enable drawing to texture
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, raylib.Red)
|
||||
|
||||
raylib.EndTextureMode() // End drawing to texture (now we have a texture available for next passes)
|
||||
|
||||
raylib.BeginShaderMode(shader)
|
||||
|
||||
// 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.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadShader(shader) // Unload shader
|
||||
raylib.UnloadTexture(texture) // Unload texture
|
||||
raylib.UnloadModel(dwarf) // Unload model
|
||||
raylib.UnloadRenderTexture(target) // Unload render texture
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
54966
examples/shaders/model_shader/dwarf.obj
Normal file
BIN
examples/shaders/model_shader/dwarf_diffuse.png
Normal file
After Width: | Height: | Size: 1.2 MiB |
26
examples/shaders/model_shader/glsl330/base.vs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvpMatrix;
|
||||
|
||||
// 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 = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||
}
|
26
examples/shaders/model_shader/glsl330/grayscale.fs
Normal file
|
@ -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);
|
||||
}
|
66
examples/shaders/model_shader/main.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
||||
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
|
||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs") // Load model shader
|
||||
|
||||
dwarf.Material.Shader = shader // Set shader effect to 3d model
|
||||
dwarf.Material.TexDiffuse = texture // Bind texture to model
|
||||
|
||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraFree) // Set free camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
|
||||
raylib.DrawText(fmt.Sprintf("Camera position: (%.2f, %.2f, %.2f)", camera.Position.X, camera.Position.Y, camera.Position.Z), 600, 20, 10, raylib.Black)
|
||||
raylib.DrawText(fmt.Sprintf("Camera target: (%.2f, %.2f, %.2f)", camera.Target.X, camera.Target.Y, camera.Target.Z), 600, 40, 10, raylib.Gray)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadShader(shader) // Unload shader
|
||||
raylib.UnloadTexture(texture) // Unload texture
|
||||
raylib.UnloadModel(dwarf) // Unload model
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
54966
examples/shaders/postprocessing/dwarf.obj
Normal file
BIN
examples/shaders/postprocessing/dwarf_diffuse.png
Normal file
After Width: | Height: | Size: 1.2 MiB |
26
examples/shaders/postprocessing/glsl330/base.vs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvpMatrix;
|
||||
|
||||
// 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 = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||
}
|
40
examples/shaders/postprocessing/glsl330/bloom.fs
Normal file
|
@ -0,0 +1,40 @@
|
|||
#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
|
||||
|
||||
const vec2 size = vec2(800, 450); // render size
|
||||
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 sum = vec4(0);
|
||||
vec2 sizeFactor = vec2(1)/size*quality;
|
||||
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 source = texture(texture0, fragTexCoord);
|
||||
|
||||
const int range = 2; // should be = (samples - 1)/2;
|
||||
|
||||
for (int x = -range; x <= range; x++)
|
||||
{
|
||||
for (int y = -range; y <= range; y++)
|
||||
{
|
||||
sum += texture(texture0, fragTexCoord + vec2(x, y)*sizeFactor);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate final fragment color
|
||||
finalColor = ((sum/(samples*samples)) + source)*colDiffuse;
|
||||
}
|
77
examples/shaders/postprocessing/main.go
Normal file
|
@ -0,0 +1,77 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint | raylib.FlagVsyncHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
||||
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.Material.TexDiffuse = 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
|
||||
|
||||
// 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)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.BeginTextureMode(target) // Enable drawing to texture
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
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)
|
||||
|
||||
// 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.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadShader(shader) // Unload shader
|
||||
raylib.UnloadTexture(texture) // Unload texture
|
||||
raylib.UnloadModel(dwarf) // Unload model
|
||||
raylib.UnloadRenderTexture(target) // Unload render texture
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
26
examples/shaders/shapes_textures/glsl330/base.vs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvpMatrix;
|
||||
|
||||
// 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 = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||
}
|
26
examples/shaders/shapes_textures/glsl330/grayscale.fs
Normal file
|
@ -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);
|
||||
}
|
72
examples/shaders/shapes_textures/main.go
Normal file
|
@ -0,0 +1,72 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders")
|
||||
|
||||
sonic := raylib.LoadTexture("sonic.png")
|
||||
|
||||
// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
// Start drawing with default shader
|
||||
|
||||
raylib.DrawText("USING DEFAULT SHADER", 20, 40, 10, raylib.Red)
|
||||
|
||||
raylib.DrawCircle(80, 120, 35, raylib.DarkBlue)
|
||||
raylib.DrawCircleGradient(80, 220, 60, raylib.Green, raylib.SkyBlue)
|
||||
raylib.DrawCircleLines(80, 340, 80, raylib.DarkBlue)
|
||||
|
||||
// Activate our custom shader to be applied on next shapes/textures drawings
|
||||
raylib.BeginShaderMode(shader)
|
||||
|
||||
raylib.DrawText("USING CUSTOM SHADER", 190, 40, 10, raylib.Red)
|
||||
|
||||
raylib.DrawRectangle(250-60, 90, 120, 60, raylib.Red)
|
||||
raylib.DrawRectangleGradient(250-90, 170, 180, 130, raylib.Maroon, raylib.Gold)
|
||||
raylib.DrawRectangleLines(250-40, 320, 80, 60, raylib.Orange)
|
||||
|
||||
// Activate our default shader for next drawings
|
||||
raylib.EndShaderMode()
|
||||
|
||||
raylib.DrawText("USING DEFAULT SHADER", 370, 40, 10, raylib.Red)
|
||||
|
||||
raylib.DrawTriangle(raylib.NewVector2(430, 80),
|
||||
raylib.NewVector2(430-60, 150),
|
||||
raylib.NewVector2(430+60, 150), raylib.Violet)
|
||||
|
||||
raylib.DrawTriangleLines(raylib.NewVector2(430, 160),
|
||||
raylib.NewVector2(430-20, 230),
|
||||
raylib.NewVector2(430+20, 230), raylib.DarkBlue)
|
||||
|
||||
raylib.DrawPoly(raylib.NewVector2(430, 320), 6, 80, 0, raylib.Brown)
|
||||
|
||||
// Activate our custom shader to be applied on next shapes/textures drawings
|
||||
raylib.BeginShaderMode(shader)
|
||||
|
||||
raylib.DrawTexture(sonic, 380, -10, raylib.White) // Using custom shader
|
||||
|
||||
// Activate our default shader for next drawings
|
||||
raylib.EndShaderMode()
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadShader(shader) // Unload shader
|
||||
raylib.UnloadTexture(sonic) // Unload texture
|
||||
|
||||
raylib.CloseWindow() // Close window and OpenGL context
|
||||
}
|
BIN
examples/shaders/shapes_textures/sonic.png
Normal file
After Width: | Height: | Size: 114 KiB |
54966
examples/shaders/standard_lighting/dwarf.obj
Normal file
BIN
examples/shaders/standard_lighting/dwarf_diffuse.png
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
examples/shaders/standard_lighting/dwarf_normal.png
Normal file
After Width: | Height: | Size: 3.9 MiB |
BIN
examples/shaders/standard_lighting/dwarf_specular.png
Normal file
After Width: | Height: | Size: 2.8 MiB |
93
examples/shaders/standard_lighting/main.go
Normal file
|
@ -0,0 +1,93 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint | raylib.FlagVsyncHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(4.0, 4.0, 4.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||
|
||||
material := raylib.LoadStandardMaterial()
|
||||
|
||||
material.TexDiffuse = raylib.LoadTexture("dwarf_diffuse.png") // Load model diffuse texture
|
||||
material.TexNormal = raylib.LoadTexture("dwarf_normal.png") // Load model normal texture
|
||||
material.TexSpecular = raylib.LoadTexture("dwarf_specular.png") // Load model specular texture
|
||||
material.ColDiffuse = raylib.White
|
||||
material.ColAmbient = raylib.NewColor(0, 0, 10, 255)
|
||||
material.ColSpecular = raylib.White
|
||||
material.Glossiness = 50.0
|
||||
|
||||
dwarf.Material = material // Apply material to model
|
||||
|
||||
spotLight := raylib.CreateLight(raylib.LightSpot, raylib.NewVector3(3.0, 5.0, 2.0), raylib.NewColor(255, 255, 255, 255))
|
||||
spotLight.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
spotLight.Intensity = 2.0
|
||||
spotLight.Diffuse = raylib.NewColor(255, 100, 100, 255)
|
||||
spotLight.ConeAngle = 60.0
|
||||
|
||||
dirLight := raylib.CreateLight(raylib.LightDirectional, raylib.NewVector3(0.0, -3.0, -3.0), raylib.NewColor(255, 255, 255, 255))
|
||||
dirLight.Target = raylib.NewVector3(1.0, -2.0, -2.0)
|
||||
dirLight.Intensity = 2.0
|
||||
dirLight.Diffuse = raylib.NewColor(100, 255, 100, 255)
|
||||
|
||||
pointLight := raylib.CreateLight(raylib.LightPoint, raylib.NewVector3(0.0, 4.0, 5.0), raylib.NewColor(255, 255, 255, 255))
|
||||
pointLight.Intensity = 2.0
|
||||
pointLight.Diffuse = raylib.NewColor(100, 100, 255, 255)
|
||||
pointLight.Radius = 3.0
|
||||
|
||||
// Setup orbital camera
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||
|
||||
//raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
||||
|
||||
raylib.DrawLight(spotLight) // Draw spot light
|
||||
raylib.DrawLight(dirLight) // Draw directional light
|
||||
raylib.DrawLight(pointLight) // Draw point light
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadMaterial(material) // Unload material and assigned textures
|
||||
raylib.UnloadModel(dwarf) // Unload model
|
||||
|
||||
// Destroy all created lights
|
||||
raylib.DestroyLight(pointLight)
|
||||
raylib.DestroyLight(dirLight)
|
||||
raylib.DestroyLight(spotLight)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|