Initial commit
This commit is contained in:
commit
d7ff68b487
196 changed files with 286314 additions and 0 deletions
54966
examples/shaders/model_shader/dwarf.obj
Normal file
54966
examples/shaders/model_shader/dwarf.obj
Normal file
File diff suppressed because it is too large
Load diff
BIN
examples/shaders/model_shader/dwarf_diffuse.png
Normal file
BIN
examples/shaders/model_shader/dwarf_diffuse.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
26
examples/shaders/model_shader/glsl330/base.vs
Normal file
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
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
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()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue