Skip to content

Commit

Permalink
LightView render of depth buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
feyil committed Jun 9, 2019
1 parent f6b4517 commit dfd388f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions assignment6.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
"exponent": 0
}

shadow.createLightView(Light.LIGHT_NUM[0], [0,48,0], [0,-1,0], [0,0,1])

spotLight2 = {
"lightName": "OUTSIDE_SPOT",
"lightNum": 1,
Expand Down
Binary file modified jpap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lights/SpotLight.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def updatePosition(self, x, y, z):
def transformShape(self, aMath3d):
# Tricky implementation for now
# It places light shape to where the light is located in that moment
self.placeRepresentativeShape(aMath3d)
#self.placeRepresentativeShape(aMath3d)

self.__position = aMath3d.multiplyByVec3d(self.__position)
self.__direction = aMath3d.multiplyByVec3d(self.__direction)
Expand Down
22 changes: 17 additions & 5 deletions shadows/Shadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self):

# reference to Camera object, we can obtain lookAt
self.__lightView = None
self.__lightNum = None

# to remember
self.__activeCamName = None
Expand Down Expand Up @@ -61,7 +62,9 @@ def attachFrameBufferDepthBuffer(self):
glReadBuffer(GL_NONE)
glBindFramebuffer(GL_FRAMEBUFFER, 0)

def createLightView(self, lightPos, directionFront, upVector):
def createLightView(self, lightNum, lightPos, directionFront, upVector):
self.__lightNum = lightNum

cam = Camera()
cam.setCameraFront(*directionFront)
cam.setCameraPosition(*lightPos)
Expand All @@ -74,14 +77,24 @@ def createLightView(self, lightPos, directionFront, upVector):

def updateSceneWithLightView(self, scene):
if(self.__lightView != None):
# scene.lightsON(False)
# scene.lightON(self.__lightNum, False)

self.__activeCamName = scene.getActiveCameraName()

scene.addCamera(self, "lightView", self.__lightView)
scene.addCamera("lightView", self.__lightView)
scene.selectCamera("lightView")
else:
# print("Light View None")
pass

def recoverSceneView(self, scene):
if(self.__activeCamName != None):
scene.selectCamera(self.__activeCamName)
# scene.lightON(self.__lightNum, True)
# scene.lightsON(True)


def renderDepthMap(self, scene):
#glViewport(0, 0, width, height)
glBindFramebuffer(GL_FRAMEBUFFER, self.__depthMapFBO)
Expand All @@ -91,11 +104,10 @@ def renderDepthMap(self, scene):
self.updateSceneWithLightView(scene)
scene.draw()

#self.recoverSceneView(scene)
glBindFramebuffer(GL_FRAMEBUFFER, 0)

# Recover scene view
if(self.__activeCamName != None):
scene.selectCamera(self.__activeCamName)


return self.__depthMapTexture

Expand Down
12 changes: 6 additions & 6 deletions windows/Window.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from OpenGL.GLU import *
import sys
from PIL import Image
# from PIL import Image

import numpy as np

Expand Down Expand Up @@ -145,12 +145,12 @@ def __drawGLScene(self):

shadow.bindFBO(False)

# Use PIL to convert raw RGB buffer and flip the right way up
image = Image.frombytes(mode="L", size=(800, 600), data=depth_data)
image = image.transpose(Image.FLIP_TOP_BOTTOM)
# # Use PIL to convert raw RGB buffer and flip the right way up
# image = Image.frombytes(mode="L", size=(800, 600), data=depth_data)
# image = image.transpose(Image.FLIP_TOP_BOTTOM)

# Save image to disk
image.save('jpap.png')
# # Save image to disk
# image.save('jpap.png')

# Clear the screen and the depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
Expand Down

0 comments on commit dfd388f

Please sign in to comment.