示例#1
0
def renderFrame(width, height):
    aspectRatio = float(width) / float(height)
    #shadow pass?
    view = ViewParams()
    # Projection (view to clip space transform)
    view.viewToClipTransform = lu.make_perspective(g_fov, aspectRatio,
                                                   g_nearDistance,
                                                   g_farDistance)
    # Transform from world space to view space.
    view.worldToViewTransform = lu.make_lookAt(g_viewPosition, g_viewTarget,
                                               g_viewUp)
    #debug
    #view.worldToViewTransform = lu.make_lookAt(g_sunPosition,[0.0,0.0,0.0],g_viewUp)
    view.width = width
    view.height = height
    # the values are taken from Tutorial 16
    lightPOV = lu.make_lookAt(g_sunPosition, g_viewTarget, g_viewUp)
    view.depthMVPTransform = lu.orthographic_projection_matrix(
        0, 1024, 0, 1024, g_nearDistance, g_farDistance) * lightPOV
    shadow.shadowRenderPass(g_shadowShader, view, g_renderingSystem,
                            g_shadowTexId, g_terrain, g_fbo)

    glViewport(0, 0, width, height)
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)

    # ViewParams is used to contain the needed data to represent a 'view' mostly we want to get at the
    # projection and world-to-view transform, as these are used in all shaders. Keeping them in one
    # object makes it easier to pass around. It is also convenient future-proofing if we want to add more
    # views (e.g., for a shadow map).

    # Call each part of the scene to render itself
    g_terrain.render(view, g_renderingSystem, g_shadowTexId)
    g_racer.render(view, g_renderingSystem)
    for p in g_props:
        p.render(view, g_renderingSystem)
示例#2
0
def renderFrame(width, height):
    glViewport(0, 0, width, height)
    glClearColor(g_backGroundColour[0], g_backGroundColour[1],
                 g_backGroundColour[2], 1.0)
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)

    aspectRatio = float(width) / float(height)

    # ViewParams is used to contain the needed data to represent a 'view' mostly we want to get at the
    # projection and world-to-view transform, as these are used in all shaders. Keeping them in one
    # object makes it easier to pass around. It is also convenient future-proofing if we want to add more
    # views (e.g., for a shadow map).
    view = ViewParams()
    # Projection (view to clip space transform)
    view.viewToClipTransform = lu.make_perspective(g_fov, aspectRatio,
                                                   g_nearDistance,
                                                   g_farDistance)
    # Transform from world space to view space.
    view.worldToViewTransform = lu.make_lookAt(g_viewPosition, g_viewTarget,
                                               g_viewUp)
    view.width = width
    view.height = height

    # Call each part of the scene to render itself
    g_terrain.render(view, g_renderingSystem)
    g_racer.render(view, g_renderingSystem)
    #g_props.render(view, g_renderingSystem)
    for prop in g_props:
        prop.render(view, g_renderingSystem)
示例#3
0
def render_frame(width, height):
    """ Renders the frame """
    global g_shader
    global g_squares
    global g_square_colors
    global g_square_normals
    global g_cam
    global g_light_1
    global g_light_color_1
    global g_ambi_color
    global g_spec_color
    # Make the camera position
    eye_pos = g_cam
    look_at = [1.5, 1.5, -1.5]
    up_dir = [0, 1, 0]
    y_fov = 45

    # Light constants
    ambient_light = g_ambi_color
    specular_light = g_spec_color

    world_to_view = lu.make_lookAt(eye_pos, look_at, up_dir)
    view_to_clip = lu.make_perspective(y_fov, width / height, 0.1, 260)
    world_to_clip = view_to_clip * world_to_view
    model_to_view_normal = lu.inverse(lu.transpose(lu.Mat3(world_to_view)))

    # Make openGL use transform from screen space to NDC
    glViewport(0, 0, width, height)
    # Set the clear colour (i.e. background colour)
    glClearColor(0.7, 0.8, 1.0, 1.0)

    make_squares()
    make_texture_coords()

    # Unbind the buffers
    glBindBuffer(GL_ARRAY_BUFFER, 0)
    glBindVertexArray(0)

    # Clear the colour and depth buffers
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)

    # Buffer the world to clip transform matrix
    tfm_uniform_index = glGetUniformLocation(g_shader, "worldToClipTfm")
    glUseProgram(g_shader)
    glUniformMatrix4fv(tfm_uniform_index, 1, GL_TRUE, world_to_clip.getData())
    glBindVertexArray(g_vertex_array)

    model_uniform_index = glGetUniformLocation(g_shader, "modelToView")
    glUseProgram(g_shader)
    glUniformMatrix4fv(model_uniform_index, 1, GL_TRUE, world_to_view.getData())

    norm_uniform_index = glGetUniformLocation(g_shader, "modelToViewNormal")
    glUseProgram(g_shader)
    glUniformMatrix3fv(norm_uniform_index, 1, GL_TRUE,
                       model_to_view_normal.getData())

    lu.setUniform(g_shader, "camPos", eye_pos)

    # Add light 1 uniforms
    lu.setUniform(g_shader, "lightColourAndIntensity1", g_light_color_1)
    lu.setUniform(g_shader, "viewSpaceLightPosition1", g_light_1)
    # Add light 2 uniforms
    lu.setUniform(g_shader, "lightColourAndIntensity2", g_light_color_2)
    lu.setUniform(g_shader, "viewSpaceLightPosition2", g_light_2)
    # Add light 3 uniforms
    lu.setUniform(g_shader, "lightColourAndIntensity3", g_light_color_3)
    lu.setUniform(g_shader, "viewSpaceLightPosition3", g_light_3)
    # Add light 4 uniforms
    lu.setUniform(g_shader, "lightColourAndIntensity4", g_light_color_4)
    lu.setUniform(g_shader, "viewSpaceLightPosition4", g_light_4)

    lu.setUniform(g_shader, "ambientLightColourAndIntensity", ambient_light)
    lu.setUniform(g_shader, "materialSpecular", specular_light)

    # Fog settings
    lu.setUniform(g_shader, "fogColor", g_fog_color)
    lu.setUniform(g_shader, "fogDensityConst", g_fog_density)
    lu.setUniform(g_shader, "fogHeightConst", g_fog_height)
    lu.setUniform(g_shader, "fogMax", g_fog_max)

    glActiveTexture(GL_TEXTURE0)
    glBindTexture(GL_TEXTURE_2D, g_texture_id)
    loc = glGetUniformLocation(g_shader, "plasticTexture")
    glUniform1i(loc, 0)

    for i in range(int(len(g_squares) / 4)):
        lu.setUniform(g_shader, "squareColorIndex", g_square_colors[i])
        lu.setUniform(g_shader, "squareNormal", g_square_normals[i])
        glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4)