Ejemplo n.º 1
0
def shadowRenderPass(shadowShader, view, renderingSystem, shadowTex, terrain,
                     fbo):

    glViewport(0, 0, g_shadowWidth, g_shadowHeight)
    glEnable(GL_DEPTH_TEST)
    #glClearColor(0.1, 0.2, 0.1, 1.0)
    glBindFramebuffer(GL_FRAMEBUFFER, fbo)
    glClear(GL_DEPTH_BUFFER_BIT)
    #glClearDepth(1.0)

    glUseProgram(shadowShader)
    #renderingSystem.setCommonUniforms(shadowShader,view,lu.Mat4())
    #set common unforms?
    #bind terrain vertex array! -> we need terrain scene geometry...
    #bindTextures?

    #lu.bindTexture(TU_depthTexture, shadowTex)
    lu.setUniform(shadowShader, "lightPOVTransform", view.depthMVPTransform)
    glBindVertexArray(terrain.vertexArrayObject)
    glDrawElements(GL_TRIANGLES, len(terrain.terrainInds), GL_UNSIGNED_INT,
                   None)
    glBindFramebuffer(GL_FRAMEBUFFER, 0)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glBindVertexArray(0)
    glUseProgram(0)
Ejemplo n.º 2
0
    def render(self, view, renderingSystem):
        glUseProgram(self.shader)
        renderingSystem.setCommonUniforms(self.shader, view, lu.Mat4())

        lu.setUniform(self.shader, "terrainHeightScale", self.heightScale)
        lu.setUniform(self.shader, "terrainTextureXyScale",
                      self.textureXyScale)
        xyNormScale = 1.0 / (vec2(self.imageWidth, self.imageHeight) *
                             self.xyScale)
        lu.setUniform(self.shader, "xyNormScale", xyNormScale)
        xyOffset = -(vec2(self.imageWidth, self.imageHeight) +
                     vec2(1.0)) * self.xyScale / 2.0
        lu.setUniform(self.shader, "xyOffset", xyOffset)

        #TODO 1.4: Bind the grass texture to the right texture unit, hint: lu.bindTexture
        loc = glGetUniformLocation(self.shader, "someTexture")
        glUniform1i(loc, 0)
        lu.bindTexture(loc, glGenTextures(1))

        if self.renderWireFrame:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
            glLineWidth(1.0)
        glBindVertexArray(self.vertexArrayObject)
        glDrawElements(GL_TRIANGLES, len(self.terrainInds), GL_UNSIGNED_INT,
                       None)

        if self.renderWireFrame:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        glBindVertexArray(0)
        glUseProgram(0)
Ejemplo n.º 3
0
    def setCommonUniforms(self, shader, view, modelToWorldTransform):
        # Concatenate the transformations to take vertices directly from model space to clip space
        modelToClipTransform = view.viewToClipTransform * view.worldToViewTransform * modelToWorldTransform
        # Transform to view space from model space (used for the shading)
        modelToViewTransform = view.worldToViewTransform * modelToWorldTransform
        # Transform to view space for normals, need to use the inverse transpose unless only rigid body & uniform scale.
        modelToViewNormalTransform = lu.inverse(
            lu.transpose(lu.Mat3(modelToViewTransform)))

        # Set the standard transforms, these vary per object and must be set each time an object is drawn (since they have different modelToWorld transforms)
        lu.setUniform(shader, "modelToClipTransform", modelToClipTransform)
        lu.setUniform(shader, "modelToViewTransform", modelToViewTransform)
        lu.setUniform(shader, "modelToViewNormalTransform",
                      modelToViewNormalTransform)

        # These transforms are the same for the current view and could be set once for all the objects
        lu.setUniform(shader, "worldToViewTransform",
                      view.worldToViewTransform)
        lu.setUniform(shader, "viewToClipTransform", view.viewToClipTransform)
        # Lighting parameters as could these
        viewSpaceLightPosition = lu.transformPoint(view.worldToViewTransform,
                                                   g_sunPosition)
        lu.setUniform(shader, "viewSpaceLightPosition", viewSpaceLightPosition)
        lu.setUniform(shader, "globalAmbientLight", g_globalAmbientLight)
        lu.setUniform(shader, "sunLightColour", g_sunLightColour)
        lu.bindTexture(g_TU_shadow, g_shadowTexId)
        lu.setUniform(shader, "shadowMapTexture", g_shadowTexId)
Ejemplo n.º 4
0
    def render(self, view, renderingSystem):
        glUseProgram(self.shader)
        renderingSystem.setCommonUniforms(self.shader, view, lu.Mat4())

        lu.setUniform(self.shader, "terrainHeightScale", self.heightScale)
        lu.setUniform(self.shader, "terrainTextureXyScale",
                      self.textureXyScale)
        xyNormScale = 1.0 / (vec2(self.imageWidth, self.imageHeight) *
                             self.xyScale)
        lu.setUniform(self.shader, "xyNormScale", xyNormScale)
        xyOffset = -(vec2(self.imageWidth, self.imageHeight) +
                     vec2(1.0)) * self.xyScale / 2.0
        lu.setUniform(self.shader, "xyOffset", xyOffset)

        #TODO 1.4: Bind the grass texture to the right texture unit, hint: lu.bindTexture
        lu.bindTexture(self.TU_Grass, self.grassTexture)
        lu.setUniform(self.shader, "grassTexture", self.TU_Grass)

        # 2.1
        # High
        lu.bindTexture(self.TU_Wall, self.wallTexture)
        lu.setUniform(self.shader, "wallTexture", self.TU_Wall)
        # Steep
        lu.bindTexture(self.TU_Seats, self.seatsTexture)
        lu.setUniform(self.shader, "seatsTexture", self.TU_Seats)
        # Road
        lu.bindTexture(self.TU_Track, self.trackTexture)
        lu.bindTexture(self.TU_Map, self.mapTexture)
        lu.setUniform(self.shader, "trackTexture", self.TU_Track)
        lu.setUniform(self.shader, "mapTexture", self.TU_Map)

        # Olympics
        lu.bindTexture(self.TU_Concrete, self.concreteTexture)
        lu.setUniform(self.shader, "concreteTexture", self.TU_Concrete)

        if self.renderWireFrame:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
            glLineWidth(1.0)
        glBindVertexArray(self.vertexArrayObject)
        glDrawElements(GL_TRIANGLES, len(self.terrainInds), GL_UNSIGNED_INT,
                       None)

        if self.renderWireFrame:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        glBindVertexArray(0)
        glUseProgram(0)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    def render(self, view, renderingSystem, depthMap):
        glUseProgram(self.shader)
        renderingSystem.setCommonUniforms(self.shader, view, lu.Mat4())

        lu.setUniform(self.shader, "terrainHeightScale", self.heightScale)
        lu.setUniform(self.shader, "terrainTextureXyScale",
                      self.textureXyScale)
        xyNormScale = 1.0 / (vec2(self.imageWidth, self.imageHeight) *
                             self.xyScale)
        lu.setUniform(self.shader, "xyNormScale", xyNormScale)
        xyOffset = -(vec2(self.imageWidth, self.imageHeight) + vec2(1.0)) / 2.0
        lu.setUniform(self.shader, "xyOffset", xyOffset)
        lu.setUniform(self.shader, "lightPOVTransform", view.depthMVPTransform)
        #depthTexture binding for use in terrain frag shader
        #lu.bindTexture(shadow.TU_depthTexture, depthMap)
        #lu.setUniform(self.shader, "shadowMapTexture", shadow.TU_depthTexture)
        #FINISH HERE
        #TODO 1.4: Bind the grass texture to the right texture unit, hint: lu.bindTexture
        lu.bindTexture(self.TU_Grass, self.terrainTexId)
        lu.bindTexture(self.TU_high, self.highTexId)
        lu.bindTexture(self.TU_road, self.roadTexId)
        lu.bindTexture(self.TU_steep, self.steepTexId)
        lu.bindTexture(self.TU_map, self.terrainDataSampleTexId)
        #bind specs
        lu.bindTexture(self.TU_spec_grass, self.specGrassTexId)
        lu.bindTexture(self.TU_spec_high, self.specHighTexId)
        lu.bindTexture(self.TU_spec_road, self.specRoadTexId)
        lu.bindTexture(self.TU_spec_steep, self.specSteepTexId)
        #set uniform specs
        lu.setUniform(self.shader, "specularGrassTexture", self.TU_spec_grass)
        lu.setUniform(self.shader, "specularHighTexture", self.TU_spec_high)
        lu.setUniform(self.shader, "specularRoadTexture", self.TU_spec_road)
        lu.setUniform(self.shader, "specularSteepTexture", self.TU_spec_steep)
        #
        lu.setUniform(self.shader, "terrainTexture", self.TU_Grass)
        lu.setUniform(self.shader, "highTexture", self.TU_high)
        lu.setUniform(self.shader, "roadTexture", self.TU_road)
        lu.setUniform(self.shader, "steepTexture", self.TU_steep)
        lu.setUniform(self.shader, "terrainDataSample", self.TU_map)

        if self.renderWireFrame:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
            glLineWidth(1.0)
        glBindVertexArray(self.vertexArrayObject)
        glDrawElements(GL_TRIANGLES, len(self.terrainInds), GL_UNSIGNED_INT,
                       None)

        if self.renderWireFrame:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        glBindVertexArray(0)
        glUseProgram(0)
Ejemplo n.º 7
0
    def render(self, view, renderingSystem):
        glUseProgram(self.shader)
        renderingSystem.setCommonUniforms(self.shader, view, lu.Mat4())

        lu.setUniform(self.shader, "terrainHeightScale", self.heightScale)
        lu.setUniform(self.shader, "terrainTextureXyScale",
                      self.textureXyScale)
        xyNormScale = 1.0 / (vec2(self.imageWidth, self.imageHeight) *
                             self.xyScale)
        lu.setUniform(self.shader, "xyNormScale", xyNormScale)
        xyOffset = -(vec2(self.imageWidth, self.imageHeight) +
                     vec2(1.0)) * self.xyScale / 2.0
        lu.setUniform(self.shader, "xyOffset", xyOffset)

        #TODO 1.4: Bind the grass texture to the right texture unit, hint: lu.bindTexture
        lu.setUniform(self.shader, "grassTexture", self.TU_Grass)
        lu.bindTexture(self.TU_Grass, self.grass, None)

        lu.setUniform(self.shader, "highRockTexture", self.TU_highRock)
        lu.bindTexture(self.TU_highRock, self.highRock, None)

        lu.setUniform(self.shader, "lowRockTexture", self.TU_lowRock)
        lu.bindTexture(self.TU_lowRock, self.lowRock, None)

        lu.setUniform(self.shader, "pavemenTexture", self.TU_pavement)
        lu.bindTexture(self.TU_pavement, self.pavement, None)

        lu.setUniform(self.shader, "terrainMapTexture", self.TU_terrainMap)
        lu.bindTexture(self.TU_terrainMap, self.terrainMap, None)

        if self.renderWireFrame:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
            glLineWidth(1.0)
        glBindVertexArray(self.vertexArrayObject)
        glDrawElements(GL_TRIANGLES, len(self.terrainInds), GL_UNSIGNED_INT,
                       None)

        if self.renderWireFrame:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        glBindVertexArray(0)
        glUseProgram(0)