test, review and fix the shader examples. https://github.com/electronstudio/raylib-python-cffi/issues/47
This commit is contained in:
parent
ff84bdf2dd
commit
218d9a18f7
7 changed files with 84 additions and 145 deletions
|
@ -1,4 +1,4 @@
|
||||||
from raylib.dynamic import raylib as rl, ffi
|
import raylib as rl
|
||||||
|
|
||||||
|
|
||||||
class LightSystem:
|
class LightSystem:
|
||||||
|
@ -11,13 +11,13 @@ class LightSystem:
|
||||||
b"resources/shaders/fogLight.fs");
|
b"resources/shaders/fogLight.fs");
|
||||||
|
|
||||||
#// Get some shader loactions
|
#// Get some shader loactions
|
||||||
self.shader.locs[rl.LOC_MATRIX_MODEL] = rl.GetShaderLocation(self.shader, b"matModel");
|
self.shader.locs[rl.SHADER_LOC_MATRIX_MODEL] = rl.GetShaderLocation(self.shader, b"matModel");
|
||||||
self.shader.locs[rl.LOC_VECTOR_VIEW] = rl.GetShaderLocation(self.shader, b"viewPos");
|
self.shader.locs[rl.SHADER_LOC_VECTOR_VIEW] = rl.GetShaderLocation(self.shader, b"viewPos");
|
||||||
|
|
||||||
#// ambient light level
|
#// ambient light level
|
||||||
self.ambientLoc = rl.GetShaderLocation(self.shader, b"ambient");
|
self.ambientLoc = rl.GetShaderLocation(self.shader, b"ambient");
|
||||||
v = ffi.new("struct Vector4 *", ambient)
|
v = rl.ffi.new("struct Vector4 *", ambient)
|
||||||
rl.SetShaderValue(self.shader, self.ambientLoc, v, rl.UNIFORM_VEC4);
|
rl.SetShaderValue(self.shader, self.ambientLoc, v, rl.SHADER_UNIFORM_VEC4);
|
||||||
|
|
||||||
for light in ls:
|
for light in ls:
|
||||||
self.add(light)
|
self.add(light)
|
||||||
|
@ -29,7 +29,7 @@ class LightSystem:
|
||||||
raise Exception("Too many lights")
|
raise Exception("Too many lights")
|
||||||
|
|
||||||
def update(self, cameraPos):
|
def update(self, cameraPos):
|
||||||
rl.SetShaderValue(self.shader, self.shader.locs[rl.LOC_VECTOR_VIEW], ffi.new("struct Vector3 *",cameraPos), rl.UNIFORM_VEC3)
|
rl.SetShaderValue(self.shader, self.shader.locs[rl.SHADER_LOC_VECTOR_VIEW], rl.ffi.new("struct Vector3 *",cameraPos), rl.SHADER_UNIFORM_VEC3)
|
||||||
for light in self.lights:
|
for light in self.lights:
|
||||||
light.UpdateLightValues()
|
light.UpdateLightValues()
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class Light:
|
||||||
def __init__(self, type, position, target, color):
|
def __init__(self, type, position, target, color):
|
||||||
self.enabled = True
|
self.enabled = True
|
||||||
self.type = type
|
self.type = type
|
||||||
self.position = ffi.new("struct Vector3 *",position)
|
self.position = rl.ffi.new("struct Vector3 *",position)
|
||||||
self.target = target
|
self.target = target
|
||||||
self.color = color
|
self.color = color
|
||||||
|
|
||||||
|
@ -80,20 +80,20 @@ class Light:
|
||||||
#// NOTE: Light shader locations should be available
|
#// NOTE: Light shader locations should be available
|
||||||
def UpdateLightValues(self):
|
def UpdateLightValues(self):
|
||||||
#// Send to shader light enabled state and type
|
#// Send to shader light enabled state and type
|
||||||
rl.SetShaderValue(self.shader, self.enabledLoc, ffi.new("int *",self.enabled), rl.UNIFORM_INT)
|
rl.SetShaderValue(self.shader, self.enabledLoc, rl.ffi.new("int *",self.enabled), rl.SHADER_UNIFORM_INT)
|
||||||
rl.SetShaderValue(self.shader, self.typeLoc, ffi.new("int *",self.type), rl.UNIFORM_INT)
|
rl.SetShaderValue(self.shader, self.typeLoc, rl.ffi.new("int *",self.type), rl.SHADER_UNIFORM_INT)
|
||||||
|
|
||||||
#// Send to shader light position values
|
#// Send to shader light position values
|
||||||
position = [ self.position.x, self.position.y, self.position.z]
|
position = [ self.position.x, self.position.y, self.position.z]
|
||||||
rl.SetShaderValue(self.shader, self.posLoc, ffi.new("struct Vector3 *",position), rl.UNIFORM_VEC3)
|
rl.SetShaderValue(self.shader, self.posLoc, rl.ffi.new("struct Vector3 *",position), rl.SHADER_UNIFORM_VEC3)
|
||||||
|
|
||||||
#// Send to shader light target position values
|
#// Send to shader light target position values
|
||||||
target =[ self.target.x, self.target.y, self.target.z ]
|
target =[ self.target.x, self.target.y, self.target.z ]
|
||||||
rl.SetShaderValue(self.shader, self.targetLoc, ffi.new("struct Vector3 *",target), rl.UNIFORM_VEC3)
|
rl.SetShaderValue(self.shader, self.targetLoc, rl.ffi.new("struct Vector3 *",target), rl.SHADER_UNIFORM_VEC3)
|
||||||
|
|
||||||
#// Send to shader light color values
|
#// Send to shader light color values
|
||||||
color = [self.color[0]/255.0, self.color[1]/255.0, self.color[2]/255.0, self.color[3]/255.0]
|
color = [self.color[0]/255.0, self.color[1]/255.0, self.color[2]/255.0, self.color[3]/255.0]
|
||||||
rl.SetShaderValue(self.shader, self.colorLoc, ffi.new("struct Vector4 *",color), rl.UNIFORM_VEC4)
|
rl.SetShaderValue(self.shader, self.colorLoc, rl.ffi.new("struct Vector4 *",color), rl.SHADER_UNIFORM_VEC4)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,9 @@
|
||||||
# just a few functions from raymath
|
# just a few functions from raymath
|
||||||
#from raylib.dynamic import raylib as rl, ffi
|
|
||||||
from raylib import rl, ffi
|
import raylib as rl
|
||||||
import math
|
import math
|
||||||
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
#=======
|
|
||||||
#>>>>>>> 2e2e575 (added shaders custom uniform)
|
|
||||||
#=======
|
|
||||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
|
||||||
PI = 3.14159265358979323846
|
PI = 3.14159265358979323846
|
||||||
DEG2RAD = (PI/180.0)
|
DEG2RAD = (PI/180.0)
|
||||||
RAD2DEG = (180.0/PI)
|
RAD2DEG = (180.0/PI)
|
||||||
|
@ -27,16 +21,9 @@ def Lerp(start: float, end: float, amount: float):
|
||||||
def Vector2Zero():
|
def Vector2Zero():
|
||||||
return ffi.new("struct Vector2 *",[ 0, 0])
|
return ffi.new("struct Vector2 *",[ 0, 0])
|
||||||
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
#=======
|
|
||||||
#>>>>>>> ffe4403 (complete fog example)
|
|
||||||
#=======
|
|
||||||
#>>>>>>> 2e2e575 (added shaders custom uniform)
|
|
||||||
#=======
|
|
||||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
|
||||||
def Vector3Zero():
|
def Vector3Zero():
|
||||||
return ffi.new("struct Vector3 *",[ 0, 0, 0])
|
return rl.ffi.new("struct Vector3 *",[ 0, 0, 0])
|
||||||
|
|
||||||
def MatrixRotateX(angle):
|
def MatrixRotateX(angle):
|
||||||
result = MatrixIdentity();
|
result = MatrixIdentity();
|
||||||
|
@ -68,7 +55,7 @@ def MatrixRotateY(angle):
|
||||||
|
|
||||||
|
|
||||||
def MatrixIdentity():
|
def MatrixIdentity():
|
||||||
result = ffi.new("struct Matrix *",[ 1.0, 0.0, 0.0, 0.0,0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ])
|
result = rl.ffi.new("struct Matrix *",[ 1.0, 0.0, 0.0, 0.0,0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +75,7 @@ def MatrixRotateZ(angle):
|
||||||
|
|
||||||
|
|
||||||
def MatrixMultiply(left, right):
|
def MatrixMultiply(left, right):
|
||||||
result = ffi.new("struct Matrix *")
|
result = rl.ffi.new("struct Matrix *")
|
||||||
result.m0 = left.m0*right.m0 + left.m1*right.m4 + left.m2*right.m8 + left.m3*right.m12;
|
result.m0 = left.m0*right.m0 + left.m1*right.m4 + left.m2*right.m8 + left.m3*right.m12;
|
||||||
result.m1 = left.m0*right.m1 + left.m1*right.m5 + left.m2*right.m9 + left.m3*right.m13;
|
result.m1 = left.m0*right.m1 + left.m1*right.m5 + left.m2*right.m9 + left.m3*right.m13;
|
||||||
result.m2 = left.m0*right.m2 + left.m1*right.m6 + left.m2*right.m10 + left.m3*right.m14;
|
result.m2 = left.m0*right.m2 + left.m1*right.m6 + left.m2*right.m10 + left.m3*right.m14;
|
||||||
|
|
|
@ -27,19 +27,10 @@
|
||||||
# *
|
# *
|
||||||
# ********************************************************************************************/
|
# ********************************************************************************************/
|
||||||
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
#<<<<<<< HEAD
|
import raylib as rl
|
||||||
#<<<<<<< HEAD
|
|
||||||
from raylib import rl, ffi
|
|
||||||
#=======
|
|
||||||
#from raylib.dynamic import raylib as rl, ffi
|
|
||||||
#>>>>>>> ffe4403 (complete fog example)
|
|
||||||
#=======
|
|
||||||
#from raylib.static import rl, ffi
|
|
||||||
#>>>>>>> 10b63b9 (added shaders_texture_waves.py)
|
|
||||||
#=======
|
|
||||||
#from raylib.static import rl, ffi
|
|
||||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
|
||||||
from raylib.colors import *
|
from raylib.colors import *
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
@ -60,7 +51,7 @@ screenHeight = 720;
|
||||||
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - basic lighting")
|
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - basic lighting")
|
||||||
|
|
||||||
camera = ffi.new('struct Camera3D *', [
|
camera = rl.ffi.new('struct Camera3D *', [
|
||||||
[2, 2, 6],
|
[2, 2, 6],
|
||||||
[0, .5, 0],
|
[0, .5, 0],
|
||||||
[0, 1, 0],
|
[0, 1, 0],
|
||||||
|
@ -77,9 +68,9 @@ modelC = rl.LoadModelFromMesh(rl.GenMeshSphere(0.5, 32, 32))
|
||||||
texture = rl.LoadTexture(b"resources/texel_checker.png")
|
texture = rl.LoadTexture(b"resources/texel_checker.png")
|
||||||
|
|
||||||
#// Assign texture to default model material
|
#// Assign texture to default model material
|
||||||
modelA.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
|
modelA.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||||
modelB.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
|
modelB.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||||
modelC.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
|
modelC.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||||
|
|
||||||
angle = 6.282;
|
angle = 6.282;
|
||||||
|
|
||||||
|
@ -137,8 +128,8 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
||||||
#// Rotate the torus
|
#// Rotate the torus
|
||||||
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)[0])[0]
|
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)[0])[0]
|
||||||
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)[0])[0]
|
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)[0])[0]
|
||||||
modelA.transform = ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)))[0]
|
modelA.transform = rl.ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)))[0]
|
||||||
modelA.transform = ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)))[0]
|
modelA.transform = rl.ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)))[0]
|
||||||
|
|
||||||
if (rl.IsKeyPressed(rl.KEY_F)):
|
if (rl.IsKeyPressed(rl.KEY_F)):
|
||||||
rl.ToggleFullscreen()
|
rl.ToggleFullscreen()
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
|
|
||||||
#=======
|
|
||||||
# /*******************************************************************************************
|
# /*******************************************************************************************
|
||||||
# *
|
# *
|
||||||
# * raylib [shaders] example - basic lighting
|
# * raylib [shaders] example - custom uniform
|
||||||
# *
|
# *
|
||||||
# * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
# * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
# * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
# * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
||||||
|
@ -30,12 +25,9 @@
|
||||||
# *
|
# *
|
||||||
# *
|
# *
|
||||||
# ********************************************************************************************/
|
# ********************************************************************************************/
|
||||||
#>>>>>>> 2e2e575 (added shaders custom uniform)
|
|
||||||
#=======#
|
|
||||||
#
|
|
||||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
|
||||||
|
|
||||||
from raylib.dynamic import raylib as rl, ffi
|
|
||||||
|
import raylib as rl
|
||||||
from raylib.colors import *
|
from raylib.colors import *
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
@ -49,9 +41,9 @@ screenWidth = 800;
|
||||||
screenHeight = 450;
|
screenHeight = 450;
|
||||||
|
|
||||||
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - basic lighting")
|
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - custom uniform")
|
||||||
|
|
||||||
camera = ffi.new('struct Camera3D *', [
|
camera = rl.ffi.new('struct Camera3D *', [
|
||||||
[2, 12, 6],
|
[2, 12, 6],
|
||||||
[0, .5, 0],
|
[0, .5, 0],
|
||||||
[0, 1, 0],
|
[0, 1, 0],
|
||||||
|
@ -63,7 +55,7 @@ model = rl.LoadModel(b"resources/models/barracks.obj") # // Loa
|
||||||
texture = rl.LoadTexture(b"resources/models/barracks_diffuse.png") # // Load model texture (diffuse map)
|
texture = rl.LoadTexture(b"resources/models/barracks_diffuse.png") # // Load model texture (diffuse map)
|
||||||
|
|
||||||
#// Assign texture to default model material
|
#// Assign texture to default model material
|
||||||
model.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
|
model.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||||
#// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
|
#// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
|
||||||
shader = rl.LoadShader(b"", b"resources/shaders/glsl330/swirl.fs")
|
shader = rl.LoadShader(b"", b"resources/shaders/glsl330/swirl.fs")
|
||||||
swirlCenterLoc = rl.GetShaderLocation(shader, b"center")
|
swirlCenterLoc = rl.GetShaderLocation(shader, b"center")
|
||||||
|
@ -71,7 +63,7 @@ angle = 6.282;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
swirl = ffi.new("struct Vector2 *", [0,0])
|
swirl = rl.ffi.new("struct Vector2 *", [0,0])
|
||||||
|
|
||||||
target = rl.LoadRenderTexture(screenWidth, screenHeight)
|
target = rl.LoadRenderTexture(screenWidth, screenHeight)
|
||||||
|
|
||||||
|
@ -90,7 +82,7 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
||||||
|
|
||||||
swirl.x = rl.GetMouseX()
|
swirl.x = rl.GetMouseX()
|
||||||
swirl.y = screenHeight - rl.GetMouseY()
|
swirl.y = screenHeight - rl.GetMouseY()
|
||||||
rl.SetShaderValue(shader, swirlCenterLoc, swirl, rl.UNIFORM_VEC2);
|
rl.SetShaderValue(shader, swirlCenterLoc, swirl, rl.SHADER_UNIFORM_VEC2);
|
||||||
#//----------------------------------------------------------------------------------
|
#//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
#// Draw
|
#// Draw
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Example converted to Python from:
|
Example converted to Python from:
|
||||||
|
@ -8,20 +7,9 @@ http://bedroomcoders.co.uk/raylib-fog/
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
#
|
|
||||||
#<<<<<<< HEAD
|
import raylib as rl
|
||||||
#<<<<<<< HEAD
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
from raylib import rl, ffi
|
|
||||||
#=======
|
|
||||||
#from raylib.dynamic import raylib as rl, ffi
|
|
||||||
#>>>>>>> ffe4403 (complete fog example)
|
|
||||||
#=======
|
|
||||||
#from raylib.static import rl, ffi
|
|
||||||
#>>>>>>> 10b63b9 (added shaders_texture_waves.py)
|
|
||||||
#=======
|
|
||||||
#from raylib.static import rl, ffi
|
|
||||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
|
||||||
from raylib.colors import *
|
from raylib.colors import *
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
@ -31,7 +19,7 @@ from light_system import *
|
||||||
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT | rl.FLAG_WINDOW_RESIZABLE)
|
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT | rl.FLAG_WINDOW_RESIZABLE)
|
||||||
rl.InitWindow(1280, 768, b'Fog Test')
|
rl.InitWindow(1280, 768, b'Fog Test')
|
||||||
|
|
||||||
camera = ffi.new('struct Camera3D *', [
|
camera = rl.ffi.new('struct Camera3D *', [
|
||||||
[6, 2, 6],
|
[6, 2, 6],
|
||||||
[0, .5, 0],
|
[0, .5, 0],
|
||||||
[0, 1, 0],
|
[0, 1, 0],
|
||||||
|
@ -45,26 +33,20 @@ model3 = rl.LoadModelFromMesh(rl.GenMeshSphere(0.5, 32, 32))
|
||||||
|
|
||||||
texture = rl.LoadTexture(b'resources/test.png')
|
texture = rl.LoadTexture(b'resources/test.png')
|
||||||
|
|
||||||
model.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
|
model.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||||
model2.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
|
model2.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||||
model3.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
|
model3.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||||
|
|
||||||
light = Light(LIGHT_POINT, [ 0, 4, 0 ], Vector3Zero(), WHITE)
|
light = Light(LIGHT_POINT, [ 0, 4, 0 ], Vector3Zero(), WHITE)
|
||||||
lightSystem = LightSystem([ 0.2, 0.2, 0.2, 1.0 ], light)
|
lightSystem = LightSystem([ 0.2, 0.2, 0.2, 1.0 ], light)
|
||||||
#
|
|
||||||
#<<<<<<< HEAD
|
fog_color = rl.ffi.new('float[]', [0.2,0.2,1.0,1.0])
|
||||||
#<<<<<<< HEAD
|
|
||||||
fog_color = ffi.new('float[]', [0.2,0.2,1.0,1.0])
|
|
||||||
fogC = rl.GetShaderLocation(lightSystem.shader, b'fogColor')
|
fogC = rl.GetShaderLocation(lightSystem.shader, b'fogColor')
|
||||||
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.UNIFORM_VEC4);
|
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.SHADER_UNIFORM_VEC4);
|
||||||
#=======
|
|
||||||
#fog_color = [0.2, 0.2, 1.0, 1.0]
|
|
||||||
#>>>>>>> ffe4403 (complete fog example)
|
|
||||||
#=======
|
|
||||||
#fog_color = ffi.new('float[]', [0.2,0.2,1.0,1.0])
|
|
||||||
fogC = rl.GetShaderLocation(lightSystem.shader, b'fogColor')
|
fogC = rl.GetShaderLocation(lightSystem.shader, b'fogColor')
|
||||||
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.UNIFORM_VEC4);
|
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.SHADER_UNIFORM_VEC4);
|
||||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
|
||||||
fogD = rl.GetShaderLocation(lightSystem.shader, b'FogDensity')
|
fogD = rl.GetShaderLocation(lightSystem.shader, b'FogDensity')
|
||||||
fogDensity = 0.12
|
fogDensity = 0.12
|
||||||
|
|
||||||
|
@ -84,8 +66,8 @@ while not rl.WindowShouldClose():
|
||||||
lightSystem.update(camera.position)
|
lightSystem.update(camera.position)
|
||||||
|
|
||||||
|
|
||||||
model.transform = ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateX(-0.025)))[0]
|
model.transform = rl.ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateX(-0.025)))[0]
|
||||||
model.transform = ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateZ(0.012)))[0]
|
model.transform = rl.ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateZ(0.012)))[0]
|
||||||
|
|
||||||
if rl.IsKeyDown(rl.KEY_UP):
|
if rl.IsKeyDown(rl.KEY_UP):
|
||||||
fogDensity = min(fogDensity + 0.001, 1)
|
fogDensity = min(fogDensity + 0.001, 1)
|
||||||
|
@ -93,21 +75,15 @@ while not rl.WindowShouldClose():
|
||||||
if rl.IsKeyDown(rl.KEY_DOWN):
|
if rl.IsKeyDown(rl.KEY_DOWN):
|
||||||
fogDensity = max(fogDensity - 0.001, 0)
|
fogDensity = max(fogDensity - 0.001, 0)
|
||||||
|
|
||||||
rl.SetShaderValue(lightSystem.shader, fogD, ffi.new('float[]', [fogDensity]), rl.UNIFORM_FLOAT)
|
rl.SetShaderValue(lightSystem.shader, fogD, rl.ffi.new('float[]', [fogDensity]), rl.SHADER_UNIFORM_FLOAT)
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
rl.ClearBackground([int(255 * i) for i in fog_color])
|
rl.ClearBackground([int(255 * i) for i in fog_color])
|
||||||
#<<<<<<< HEAD
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
# if rl.IsKeyDown(rl.KEY_SPACE):
|
|
||||||
# rl.ClearBackground(BLACK)
|
|
||||||
#=======
|
|
||||||
#>>>>>>> ffe4403 (complete fog example)
|
|
||||||
#=======
|
|
||||||
if rl.IsKeyDown(rl.KEY_SPACE):
|
if rl.IsKeyDown(rl.KEY_SPACE):
|
||||||
rl.ClearBackground(BLACK)
|
rl.ClearBackground(BLACK)
|
||||||
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
|
|
||||||
|
|
||||||
rl.BeginMode3D(camera[0])
|
rl.BeginMode3D(camera[0])
|
||||||
rl.DrawModel(model, [0] * 3, 1, WHITE)
|
rl.DrawModel(model, [0] * 3, 1, WHITE)
|
||||||
|
@ -118,7 +94,8 @@ while not rl.WindowShouldClose():
|
||||||
rl.DrawModel(model, [i, 0, 2], 1, WHITE)
|
rl.DrawModel(model, [i, 0, 2], 1, WHITE)
|
||||||
|
|
||||||
|
|
||||||
rl.DrawGizmo([1000, 1000, 1000])
|
#Raylib removed this function
|
||||||
|
#rl.DrawGizmo([1000, 1000, 1000])
|
||||||
|
|
||||||
rl.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
import raylib as rl
|
||||||
|
|
||||||
|
|
||||||
from raylib.dynamic import raylib as rl, ffi
|
|
||||||
from raylib.colors import *
|
|
||||||
|
|
||||||
|
|
||||||
# a few functions ported from raymath
|
|
||||||
from rlmath import *
|
|
||||||
|
|
||||||
|
|
||||||
#// Initialization
|
#// Initialization
|
||||||
|
@ -17,7 +11,7 @@ screenHeight = 450;
|
||||||
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - basic lighting")
|
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - basic lighting")
|
||||||
|
|
||||||
camera = ffi.new('struct Camera3D *', [
|
camera = rl.ffi.new('struct Camera3D *', [
|
||||||
[2, 12, 6],
|
[2, 12, 6],
|
||||||
[0, .5, 0],
|
[0, .5, 0],
|
||||||
[0, 1, 0],
|
[0, 1, 0],
|
||||||
|
@ -25,16 +19,16 @@ camera = ffi.new('struct Camera3D *', [
|
||||||
rl.CAMERA_PERSPECTIVE
|
rl.CAMERA_PERSPECTIVE
|
||||||
])
|
])
|
||||||
|
|
||||||
imBlank = rl.GenImageColor(1024, 1024, BLANK)
|
imBlank = rl.GenImageColor(1024, 1024, rl.BLANK)
|
||||||
texture = rl.LoadTextureFromImage(imBlank) #// Load blank texture to fill on shader
|
texture = rl.LoadTextureFromImage(imBlank) #// Load blank texture to fill on shader
|
||||||
rl.UnloadImage(imBlank);
|
rl.UnloadImage(imBlank);
|
||||||
|
|
||||||
#// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
#// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
||||||
shader = rl.LoadShader(b"", b"resources/shaders/glsl330/cubes_panning.fs");
|
shader = rl.LoadShader(b"", b"resources/shaders/glsl330/cubes_panning.fs");
|
||||||
|
|
||||||
time = ffi.new("float *", 0.0)
|
time = rl.ffi.new("float *", 0.0)
|
||||||
timeLoc = rl.GetShaderLocation(shader, b"uTime");
|
timeLoc = rl.GetShaderLocation(shader, b"uTime");
|
||||||
rl.SetShaderValue(shader, timeLoc, time, rl.UNIFORM_FLOAT);
|
rl.SetShaderValue(shader, timeLoc, time, rl.SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
|
rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
|
||||||
|
@ -45,7 +39,7 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
||||||
#// Update
|
#// Update
|
||||||
#//----------------------------------------------------------------------------------
|
#//----------------------------------------------------------------------------------
|
||||||
time[0] = rl.GetTime();
|
time[0] = rl.GetTime();
|
||||||
rl.SetShaderValue(shader, timeLoc, time, rl.UNIFORM_FLOAT);
|
rl.SetShaderValue(shader, timeLoc, time, rl.SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
#//----------------------------------------------------------------------------------
|
#//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -53,13 +47,13 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
||||||
#//----------------------------------------------------------------------------------
|
#//----------------------------------------------------------------------------------
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
rl.ClearBackground(RAYWHITE)
|
rl.ClearBackground(rl.RAYWHITE)
|
||||||
|
|
||||||
rl.BeginShaderMode(shader) #// Enable our custom shader for next shapes/textures drawings
|
rl.BeginShaderMode(shader) #// Enable our custom shader for next shapes/textures drawings
|
||||||
rl.DrawTexture(texture, 0, 0, WHITE) #// Drawing BLANK texture, all magic happens on shader
|
rl.DrawTexture(texture, 0, 0, rl.WHITE) #// Drawing BLANK texture, all magic happens on shader
|
||||||
rl.EndShaderMode() #// Disable our custom shader, return to default shader
|
rl.EndShaderMode() #// Disable our custom shader, return to default shader
|
||||||
|
|
||||||
rl.DrawText(b"BACKGROUND is PAINTED and ANIMATED on SHADER!", 10, 10, 20, MAROON);
|
rl.DrawText(b"BACKGROUND is PAINTED and ANIMATED on SHADER!", 10, 10, 20, rl.MAROON);
|
||||||
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
#!/usr/bin/env python3
|
import raylib as rl
|
||||||
|
|
||||||
from raylib import rl, ffi
|
|
||||||
from raylib.colors import *
|
from raylib.colors import *
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
@ -17,7 +15,7 @@ screenHeight = 450;
|
||||||
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders]")
|
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders]")
|
||||||
|
|
||||||
camera = ffi.new('struct Camera3D *', [
|
camera = rl.ffi.new('struct Camera3D *', [
|
||||||
[2, 12, 6],
|
[2, 12, 6],
|
||||||
[0, .5, 0],
|
[0, .5, 0],
|
||||||
[0, 1, 0],
|
[0, 1, 0],
|
||||||
|
@ -36,24 +34,24 @@ ampYLoc = rl.GetShaderLocation(shader, b"ampY")
|
||||||
speedXLoc = rl.GetShaderLocation(shader, b"speedX")
|
speedXLoc = rl.GetShaderLocation(shader, b"speedX")
|
||||||
speedYLoc = rl.GetShaderLocation(shader, b"speedY")
|
speedYLoc = rl.GetShaderLocation(shader, b"speedY")
|
||||||
|
|
||||||
freqX = ffi.new("float *", 25.0)
|
freqX = rl.ffi.new("float *", 25.0)
|
||||||
freqY = ffi.new("float *", 25.0)
|
freqY = rl.ffi.new("float *", 25.0)
|
||||||
ampX = ffi.new("float *", 5.0)
|
ampX = rl.ffi.new("float *", 5.0)
|
||||||
ampY = ffi.new("float *", 5.0)
|
ampY = rl.ffi.new("float *", 5.0)
|
||||||
speedX = ffi.new("float *", 8.0)
|
speedX = rl.ffi.new("float *", 8.0)
|
||||||
speedY = ffi.new("float *", 8.0)
|
speedY = rl.ffi.new("float *", 8.0)
|
||||||
|
|
||||||
screenSize = ffi.new("struct Vector2 *",[ rl.GetScreenWidth(), rl.GetScreenHeight() ])
|
screenSize = rl.ffi.new("struct Vector2 *",[ rl.GetScreenWidth(), rl.GetScreenHeight() ])
|
||||||
rl.SetShaderValue(shader, rl.GetShaderLocation(shader, b"size"), screenSize, rl.UNIFORM_VEC2)
|
rl.SetShaderValue(shader, rl.GetShaderLocation(shader, b"size"), screenSize, rl.SHADER_UNIFORM_VEC2)
|
||||||
|
|
||||||
rl.SetShaderValue(shader, freqXLoc, freqX, rl.UNIFORM_FLOAT)
|
rl.SetShaderValue(shader, freqXLoc, freqX, rl.SHADER_UNIFORM_FLOAT)
|
||||||
rl.SetShaderValue(shader, freqYLoc, freqY, rl.UNIFORM_FLOAT)
|
rl.SetShaderValue(shader, freqYLoc, freqY, rl.SHADER_UNIFORM_FLOAT)
|
||||||
rl.SetShaderValue(shader, ampXLoc, ampX, rl.UNIFORM_FLOAT)
|
rl.SetShaderValue(shader, ampXLoc, ampX, rl.SHADER_UNIFORM_FLOAT)
|
||||||
rl.SetShaderValue(shader, ampYLoc, ampY, rl.UNIFORM_FLOAT)
|
rl.SetShaderValue(shader, ampYLoc, ampY, rl.SHADER_UNIFORM_FLOAT)
|
||||||
rl.SetShaderValue(shader, speedXLoc, speedX, rl.UNIFORM_FLOAT)
|
rl.SetShaderValue(shader, speedXLoc, speedX, rl.SHADER_UNIFORM_FLOAT)
|
||||||
rl.SetShaderValue(shader, speedYLoc, speedY, rl.UNIFORM_FLOAT)
|
rl.SetShaderValue(shader, speedYLoc, speedY, rl.SHADER_UNIFORM_FLOAT)
|
||||||
|
|
||||||
seconds = ffi.new("float *", 0.0)
|
seconds = rl.ffi.new("float *", 0.0)
|
||||||
|
|
||||||
rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
|
rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
|
||||||
#//--------------------------------------------------------------------------------------
|
#//--------------------------------------------------------------------------------------
|
||||||
|
@ -63,7 +61,7 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
||||||
#// Update
|
#// Update
|
||||||
#//----------------------------------------------------------------------------------
|
#//----------------------------------------------------------------------------------
|
||||||
seconds[0] += rl.GetFrameTime()
|
seconds[0] += rl.GetFrameTime()
|
||||||
rl.SetShaderValue(shader, secondsLoc, seconds, rl.UNIFORM_FLOAT)
|
rl.SetShaderValue(shader, secondsLoc, seconds, rl.SHADER_UNIFORM_FLOAT)
|
||||||
#//----------------------------------------------------------------------------------
|
#//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
#// Draw
|
#// Draw
|
||||||
|
|
Reference in a new issue