コード例 #1
0
    def __init__(self, ambient = [ 0.2, 0.2, 0.2, 1.0 ], *ls):
        self.shader = rl.LoadShader(b"resources/shaders/fogLight.vs",
                            b"resources/shaders/fogLight.fs");

        #// Get some shader loactions
        self.shader.locs[rl.LOC_MATRIX_MODEL] = rl.GetShaderLocation(self.shader, b"matModel");
        self.shader.locs[rl.LOC_VECTOR_VIEW] = rl.GetShaderLocation(self.shader, b"viewPos");

        #// ambient light level
        self.ambientLoc = rl.GetShaderLocation(self.shader, b"ambient");
        v = ffi.new("struct Vector4 *", ambient)
        rl.SetShaderValue(self.shader, self.ambientLoc, v, rl.UNIFORM_VEC4);

        for light in ls:
            self.add(light)
コード例 #2
0
from raylib.dynamic import raylib as rl, ffi
from raylib.colors import *

screenWidth = 1260
screenHeight = 768

rl.InitWindow(screenWidth, screenHeight, b'Skymap Demo')

camera = ffi.new('struct Camera3D *', [[1, 1, 1], [4, 1, 4], [0, 1, 0], 70, 0])

cube = rl.GenMeshCube(100, 100, 100)
skybox = rl.LoadModelFromMesh(cube)

skybox.materials[0].shader = rl.LoadShader(b'resources/shaders/skybox.vs',
                                           b'resources/shaders/skybox.fs')

rl.SetShaderValue(
    skybox.materials[0].shader,
    rl.GetShaderLocation(skybox.materials[0].shader, b"environmentMap"),
    ffi.new('int[]', [rl.MAP_CUBEMAP]), rl.UNIFORM_INT)

shdrCubemap = rl.LoadShader(b'resources/shaders/cubemap.vs',
                            b'resources/shaders/cubemap.fs')

rl.SetShaderValue(shdrCubemap,
                  rl.GetShaderLocation(shdrCubemap, b'equirectangularMap'),
                  ffi.new('int[]', [0]), rl.UNIFORM_INT)

texHDR = rl.LoadTexture(b'resources/dresden_square.hdr')

skybox.materials[0].maps[rl.MAP_CUBEMAP].texture = rl.GenTextureCubemap(
コード例 #3
0
rl.InitWindow(1280, 768, b'Fog Test')

camera = ffi.new('struct Camera3D *',
                 [[2, 2, 6], [0, 5, 0], [0, 1, 0], 45, rl.CAMERA_PERSPECTIVE])

model = rl.LoadModelFromMesh(rl.GenMeshTorus(0.4, 1, 16, 32))
model2 = rl.LoadModelFromMesh(rl.GenMeshCube(1, 1, 1))
model3 = rl.LoadModelFromMesh(rl.GenMeshSphere(0.5, 32, 32))

texture = rl.LoadTexture(b'resources/test.png')

model.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
model2.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
model3.materials[0].maps[rl.MAP_DIFFUSE].texture = texture

shader = rl.LoadShader(b'resources/shaders/fogLight.vs',
                       b'resources/shaders/fogLight.fs')
shader.locs[rl.LOC_MATRIX_MODEL] = rl.GetShaderLocation(shader, b'matModel')
shader.locs[rl.LOC_VECTOR_VIEW] = rl.GetShaderLocation(shader, b'viewPos')

amb = rl.GetShaderLocation(shader, b'ambient')
rl.SetShaderValue(shader, amb, ffi.new('float[]', [0.2, 0.2, 0.2, 1.0]),
                  rl.UNIFORM_VEC4)

fog_color = [0.2, 0.2, 1.0, 1.0]
fogC = rl.GetShaderLocation(shader, b'fogColor')
rl.SetShaderValue(shader, fogC, ffi.new('float[]', fog_color), rl.UNIFORM_VEC4)

fogD = rl.GetShaderLocation(shader, b'FogDensity')
fogDensity = 0.12
rl.SetShaderValue(shader, fogD, ffi.new('float[]', [fogDensity]),
                  rl.UNIFORM_FLOAT)
コード例 #4
0
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")

camera = ffi.new(
    'struct Camera3D *',
    [[2, 12, 6], [0, .5, 0], [0, 1, 0], 45, rl.CAMERA_PERSPECTIVE])

imBlank = rl.GenImageColor(1024, 1024, BLANK)
texture = rl.LoadTextureFromImage(
    imBlank)  #// Load blank texture to fill on shader
rl.UnloadImage(imBlank)

#// 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")

time = ffi.new("float *", 0.0)
timeLoc = rl.GetShaderLocation(shader, b"uTime")
rl.SetShaderValue(shader, timeLoc, time, rl.UNIFORM_FLOAT)

rl.SetTargetFPS(60)  # // Set our game to run at 60 frames-per-second
#//--------------------------------------------------------------------------------------

#// Main game loop
while not rl.WindowShouldClose():  #// Detect window close button or ESC key
    #// Update
    #//----------------------------------------------------------------------------------
    time[0] = rl.GetTime()
    rl.SetShaderValue(shader, timeLoc, time, rl.UNIFORM_FLOAT)
コード例 #5
0
# Enable Multi Sampling Anti Aliasing 4x (if available)
rl.InitWindow(screenWidth, screenHeight,
              b"raylib [shaders] example - basic lighting")

camera = ffi.new(
    'struct Camera3D *',
    [[2, 12, 6], [0, .5, 0], [0, 1, 0], 45, rl.CAMERA_PERSPECTIVE])

model = rl.LoadModel(b"resources/models/barracks.obj")  # // Load OBJ model
texture = rl.LoadTexture(b"resources/models/barracks_diffuse.png"
                         )  # // Load model texture (diffuse map)

#// Assign texture to default model material
model.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
#// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
shader = rl.LoadShader(b"", b"resources/shaders/glsl330/swirl.fs")
swirlCenterLoc = rl.GetShaderLocation(shader, b"center")
angle = 6.282

swirl = ffi.new("struct Vector2 *", [0, 0])

target = rl.LoadRenderTexture(screenWidth, screenHeight)

rl.SetTargetFPS(60)  # // Set our game to run at 60 frames-per-second
#//--------------------------------------------------------------------------------------

#// Main game loop
while not rl.WindowShouldClose():  #// Detect window close button or ESC key
    #// Update
    #//----------------------------------------------------------------------------------