Fix examples
This commit is contained in:
parent
c42d027833
commit
ad07f2586d
14 changed files with 5164 additions and 55024 deletions
Binary file not shown.
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
@ -1,8 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
|
@ -17,20 +15,16 @@ func main() {
|
|||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
camera.Type = rl.CameraPerspective
|
||||
|
||||
image := rl.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
||||
cubicmap := rl.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
|
||||
|
||||
mesh := rl.GenMeshCubicmap(*image, rl.NewVector3(1.0, 1.0, 1.0))
|
||||
fmt.Printf("%+v\n", mesh)
|
||||
|
||||
model := rl.LoadModelFromMesh(mesh)
|
||||
|
||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||
texture := rl.LoadTexture("cubicmap_atlas.png") // Load map texture
|
||||
model.Materials = make([]rl.Material, 1)
|
||||
model.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||
texture := rl.LoadTexture("cubicmap_atlas.png") // Load map texture
|
||||
rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
|
||||
|
||||
mapPosition := rl.NewVector3(-16.0, 0.0, -8.0) // Set model position
|
||||
|
||||
|
|
|
@ -22,12 +22,11 @@ func main() {
|
|||
texture := rl.LoadTextureFromImage(image) // Convert image to texture (VRAM)
|
||||
|
||||
mesh := rl.GenMeshHeightmap(*image, rl.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and VRAM)
|
||||
//fmt.Printf("%+v\n", mesh)
|
||||
model := rl.LoadModelFromMesh(mesh) // Load model from generated mesh
|
||||
//fmt.Printf("%+v\n", model)
|
||||
model.Materials = make([]rl.Material, 1)
|
||||
model.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||
mapPosition := rl.NewVector3(-8.0, 0.0, -8.0) // Set model position
|
||||
model := rl.LoadModelFromMesh(mesh) // Load model from generated mesh
|
||||
|
||||
rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
|
||||
|
||||
mapPosition := rl.NewVector3(-8.0, 0.0, -8.0) // Set model position
|
||||
|
||||
rl.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM
|
||||
|
||||
|
|
|
@ -11,16 +11,16 @@ func main() {
|
|||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading")
|
||||
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Position = rl.NewVector3(50.0, 50.0, 50.0)
|
||||
camera.Target = rl.NewVector3(0.0, 10.0, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
camera.Type = rl.CameraPerspective
|
||||
|
||||
obj := rl.LoadModel("castle.obj") // Load OBJ model
|
||||
texture := rl.LoadTexture("castle_diffuse.png") // Load model texture
|
||||
|
||||
obj.Materials = make([]rl.Material, 1)
|
||||
obj.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set castle model diffuse texture
|
||||
rl.SetMaterialTexture(obj.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
|
||||
|
||||
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
|
@ -33,9 +33,9 @@ func main() {
|
|||
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
rl.DrawModel(obj, position, 2.0, rl.White) // Draw 3d model with texture
|
||||
rl.DrawModel(obj, position, 1.0, rl.White) // Draw 3d model with texture
|
||||
|
||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||
rl.DrawGrid(20, 10.0) // Draw a grid
|
||||
|
||||
rl.EndMode3D()
|
||||
|
||||
|
|
|
@ -21,12 +21,11 @@ func main() {
|
|||
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
|
||||
dwarf.Materials = make([]rl.Material, 1)
|
||||
dwarf.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
rl.SetMaterialTexture(dwarf.Materials, rl.MapDiffuse, texture) // Set dwarf model diffuse texture
|
||||
|
||||
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
shader := rl.LoadShader("glsl330/base.vs", "glsl330/swirl.fs") // Load postpro shader
|
||||
shader := rl.LoadShader("", "glsl330/swirl.fs")
|
||||
|
||||
// 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
|
||||
|
@ -53,7 +52,7 @@ func main() {
|
|||
swirlCenter[1] = float32(screenHeight) - mousePosition.Y
|
||||
|
||||
// Send new value to the shader to be used on drawing
|
||||
rl.SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2)
|
||||
rl.SetShaderValue(shader, swirlCenterLoc, swirlCenter, 1)
|
||||
|
||||
rl.UpdateCamera(&camera) // Update camera
|
||||
|
||||
|
|
|
@ -24,9 +24,8 @@ func main() {
|
|||
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
shader := rl.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs") // Load model shader
|
||||
|
||||
dwarf.Materials = make([]rl.Material, 1)
|
||||
dwarf.Materials[0].Shader = shader // Set shader effect to 3d model
|
||||
dwarf.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
rl.SetMaterialTexture(dwarf.Materials, rl.MapDiffuse, texture)
|
||||
dwarf.Materials.Shader = shader // Set shader effect to 3d model
|
||||
|
||||
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
|
|
5116
examples/shaders/postprocessing/church.obj
Normal file
5116
examples/shaders/postprocessing/church.obj
Normal file
File diff suppressed because it is too large
Load diff
BIN
examples/shaders/postprocessing/church_diffuse.png
Normal file
BIN
examples/shaders/postprocessing/church_diffuse.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 350 KiB |
File diff suppressed because it is too large
Load diff
Binary file not shown.
Before Width: | Height: | Size: 1.2 MiB |
|
@ -15,7 +15,7 @@ out vec4 finalColor;
|
|||
|
||||
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
|
||||
const float quality = 2.5; // lower = smaller glow, better quality
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
@ -31,4 +31,4 @@ void main()
|
|||
color = color/9.5;
|
||||
|
||||
fragColor = color;
|
||||
}
|
||||
}
|
|
@ -16,26 +16,26 @@ uniform vec2 resolution = vec2(800, 450);
|
|||
|
||||
void main()
|
||||
{
|
||||
float x = 1.0/resolution.x;
|
||||
float y = 1.0/resolution.y;
|
||||
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 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;
|
||||
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);
|
||||
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
|
||||
|
||||
finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
|
||||
}
|
|
@ -40,20 +40,19 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint | rl.FlagVsyncHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader")
|
||||
|
||||
camera := rl.Camera{}
|
||||
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Position = rl.NewVector3(2.0, 3.0, 2.0)
|
||||
camera.Target = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
dwarf.Materials = make([]rl.Material, 1)
|
||||
dwarf.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||
obj := rl.LoadModel("church.obj") // Load OBJ model
|
||||
texture := rl.LoadTexture("church_diffuse.png") // Load model texture
|
||||
rl.SetMaterialTexture(obj.Materials, rl.MapDiffuse, texture) // Set obj model diffuse texture
|
||||
|
||||
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
|
@ -105,7 +104,7 @@ func main() {
|
|||
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
rl.DrawModel(dwarf, position, 2.0, rl.White) // Draw 3d model with texture
|
||||
rl.DrawModel(obj, position, 0.1, rl.White) // Draw 3d model with texture
|
||||
|
||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
|
@ -123,7 +122,7 @@ func main() {
|
|||
|
||||
rl.DrawRectangle(0, 9, 580, 30, rl.Fade(rl.LightGray, 0.7))
|
||||
|
||||
rl.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, rl.DarkGray)
|
||||
rl.DrawText("(c) Church 3D model by Alberto Cano", screenWidth-200, screenHeight-20, 10, rl.DarkGray)
|
||||
|
||||
rl.DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, rl.Black)
|
||||
rl.DrawText(postproShaderText[currentShader], 330, 15, 20, rl.Red)
|
||||
|
@ -140,7 +139,7 @@ func main() {
|
|||
}
|
||||
|
||||
rl.UnloadTexture(texture) // Unload texture
|
||||
rl.UnloadModel(dwarf) // Unload model
|
||||
rl.UnloadModel(obj) // Unload model
|
||||
rl.UnloadRenderTexture(target) // Unload render texture
|
||||
|
||||
rl.CloseWindow()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue