Esempio n. 1
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)

        # Head Light
        viewSpaceHeadLight = lu.transformPoint(view.worldToViewTransform,
                                               g_lightPos)
        lu.setUniform(shader, "viewSpaceHeadLight", viewSpaceHeadLight)
        lu.setUniform(shader, "headlightColour", g_lightColourAndIntensity)
Esempio n. 2
0
def renderFrame(xOffset, width, height, time, textures, vao):
    global g_camera
    global g_yFovDeg
    global g_model

    lightPosition = lu.vec3(0, 0, 0)

    sunPosition = lu.vec3(0, 0, 0)
    mercuryPosition = getPosition(80, 0.01, time)
    saturnPosition = getPosition(300, 0.05, time)
    experimentPosition = getPosition(150, 0.02, time)
    moonPosition = getPosition(25, 0.1, time)

    # This configures the fixed-function transformation from Normalized Device Coordinates (NDC)
    # to the screen (pixels - called 'window coordinates' in OpenGL documentation).
    #   See: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glViewport.xhtml
    glViewport(xOffset, 0, width, height)
    # Set the colour we want the frame buffer cleared to,
    glClearColor(0.0, 0.0, 0.0, 1.0)
    # Tell OpenGL to clear the render target to the clear values for both depth and colour buffers (depth uses the default)
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)

    worldToViewTransform = g_camera.getWorldToViewMatrix([0, 1, 0])
    viewToClipTransform = lu.make_perspective(g_yFovDeg, width / height, 0.1,
                                              1500.0)

    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    Sphere.drawSphereWithTexture(
        experimentPosition, 20.0, "planet1.png", viewToClipTransform,
        worldToViewTransform, textures, vao,
        lu.transformPoint(worldToViewTransform, lightPosition),
        "shaders/allVertexShader.glsl", "shaders/planetFragmentShader.glsl")
    Sphere.drawSphereWithTexture(
        mercuryPosition, 10.0, "planet2.png", viewToClipTransform,
        worldToViewTransform, textures, vao,
        lu.transformPoint(worldToViewTransform, lightPosition),
        "shaders/allVertexShader.glsl", "shaders/planetFragmentShader.glsl")
    Sphere.drawSphereWithTexture(
        saturnPosition, 10.0, "fire.png", viewToClipTransform,
        worldToViewTransform, textures, vao,
        lu.transformPoint(worldToViewTransform, lightPosition),
        "shaders/allVertexShader.glsl", "shaders/planetFragmentShader.glsl")

    randomNo = random.random()

    Sphere.drawSphereWithTexture(
        sunPosition, 15.0, "sun.png", viewToClipTransform,
        worldToViewTransform, textures, vao,
        lu.transformPoint(worldToViewTransform, lightPosition),
        "shaders/allVertexShader.glsl", "shaders/sunFragmentShader.glsl")
    Sphere.drawSphereWithTexture(
        sunPosition, 16.0 + 1 * randomNo, "sun.png", viewToClipTransform,
        worldToViewTransform, textures, vao,
        lu.transformPoint(worldToViewTransform, lightPosition),
        "shaders/allVertexShader.glsl", "shaders/cheekyShader.glsl")
    Sphere.drawSphereWithTexture(
        sunPosition, 17.0 + 2 * randomNo, "sun.png", viewToClipTransform,
        worldToViewTransform, textures, vao,
        lu.transformPoint(worldToViewTransform, lightPosition),
        "shaders/allVertexShader.glsl", "shaders/cheekyShader.glsl")
    Sphere.drawSphereWithTexture(
        sunPosition, 18.0 + 3 * randomNo, "sun.png", viewToClipTransform,
        worldToViewTransform, textures, vao,
        lu.transformPoint(worldToViewTransform, lightPosition),
        "shaders/allVertexShader.glsl", "shaders/cheekyShader.glsl")
    Sphere.drawSphereWithTexture(
        sunPosition, 20.0 + 5 * randomNo, "sun.png", viewToClipTransform,
        worldToViewTransform, textures, vao,
        lu.transformPoint(worldToViewTransform, lightPosition),
        "shaders/allVertexShader.glsl", "shaders/cheekyShader.1.glsl")
    Sphere.drawSphereWithTexture(
        sunPosition, 24.0 + 9 * randomNo, "sun.png", viewToClipTransform,
        worldToViewTransform, textures, vao,
        lu.transformPoint(worldToViewTransform, lightPosition),
        "shaders/allVertexShader.glsl", "shaders/cheekyShader.2.glsl")

    Sphere.drawSphereWithTexture(
        sunPosition, 700, "stars3.png", viewToClipTransform,
        worldToViewTransform, textures, vao,
        lu.transformPoint(worldToViewTransform, lightPosition),
        "shaders/allVertexShader.glsl", "shaders/sunFragmentShader.1.glsl")

    glDisable(GL_BLEND)
Esempio n. 3
0
def apply_rect_transform(rect, transform):
    """ Rotates rectangle vertices on given axes """
    return [lu.transformPoint(transform, vert) for vert in rect]