Esempio n. 1
0
 def __init__(self,
             camera,
             surface,
             depth,
             causticTexture,
             photonScale=4.0,
             photonIntensity=2.0):
               
     self.surface = surface
     self.depth = depth
     self.camera = camera
     self.lightPosition = Vector3(0.0,5000.0,0.0)
     
     # The dimension of the photon map should match the tile size
     self.tileSize = self.surface.tileSize
     
     # Compile the shader
     self.shader = shader.openfiles( 'shaders/photonmap.vertex',
                                     'shaders/photonmap.fragment')
     
     self.causticTexture = causticTexture     
     
     self.photonIntensity = photonIntensity
     self.photonScale = photonScale
     
     # Photon Texture Shader Handles
     self.positionHandle = glGetAttribLocation(
                                 self.shader.id,
                                 "vPosition"
                             )
     self.normalHandle = glGetAttribLocation(
                                 self.shader.id,
                                 "vNormal"
                             )                                        
     self.lightPositionHandle = glGetUniformLocation(
                                 self.shader.id,
                                 "vLightPosition"
                             )
     self.depthHandle = glGetUniformLocation(
                                 self.shader.id,
                                 "depth"
                             ) 
     self.sizeHandle = glGetUniformLocation(
                                 self.shader.id,
                                 "tileSize"
                             )
     self.photonIntensityHandle = glGetUniformLocation(
                                 self.shader.id,
                                 "photonIntensity"
                             )
     self.photonScaleHandle = glGetUniformLocation(
                                 self.shader.id,
                                 "photonScale"
                             )
                             
     # Get a framebuffer object
     self.pointMapFBO = frameBuffer(self.causticTexture)
             
     self.setupVAO()
Esempio n. 2
0
    def __init__(self,
                 camera,
                 cubemap=None,
                 scale=20.0,
                 tileSize=128,
                 tilesX=1,
                 tilesZ=1,
                 depth=30.0,
                 waveHeight=3.125e-5,
                 wind=Vector2(64.0, 128.0),
                 period=10.0):
        self.cubemapTexture = cubemap.texture if cubemap else None

        self.wind = wind  # Ocean wind in X,Z axis
        self.waveHeight = waveHeight  # The phillips spectrum parameter
        self.oceanDepth = depth
        self.period = period  # Period of ocean surface anim

        self.tileSize = tileSize
        self.tilesX = tilesX
        self.tilesZ = tilesZ
        self.length = tileSize  # Ocean length parameter
        self.camera = camera
        self.scale = scale

        self.surfaceShader = shader.openfiles('shaders/ocean.vertex',
                                              'shaders/ocean.fragment')

        # Use Tessendorf FFT synthesis to create a convincing ocean surface.
        self.heightfield = Tessendorf(self.tileSize, self.waveHeight,
                                      self.wind, self.length, self.period)

        # The water surface
        self.surface = Surface(self.surfaceShader,
                               self.camera,
                               cubemapTexture=self.cubemapTexture,
                               heightfield=self.heightfield,
                               tileSize=self.tileSize,
                               tilesX=self.tilesX,
                               tilesZ=self.tilesZ,
                               scale=self.scale,
                               offset=Vector3(0.0, self.oceanDepth, 0.0))
Esempio n. 3
0
import shader

from pyglet import clock
from pyglet import font

from external import Camera, World, Player

from PIL import Image

from ctypes import c_byte

import console
import controller

program = shader.openfiles(  
    'shaders/main.vertex',
    'shaders/main.fragment'
)

# Set up the Window (pyglet)
config = Config(buffers=2, samples=4)
window = pyglet.window.Window(caption='GlBlox', width=1152, height=864, config=config, vsync=False, fullscreen=False)
window.set_exclusive_mouse(True)

console_font = font.load('Consolas', 14, bold=False, italic=False)

status = console.StatusConsole(x=window.width * 0.005, 
                          y=window.height * 0.98,
                          width=window.width)
                             
console = console.Console(x=window.width * 0.005,
                          y=window.height * 0.70,
Esempio n. 4
0
    def __init__(self, window, camera, options):
        ''' Constructor '''
        # Options
        self.options = options
        # Register the renderer for control input
        self.keys = key.KeyStateHandler()
        self.pressedKeys = {}
        self.window = window
        self.window.push_handlers(self.on_key_press)
        self.window.push_handlers(self.on_key_release)
        self.window.push_handlers(self.on_mouse_motion)
        self.window.push_handlers(self.keys)
        # Window size
        (szx, szy) = self.window.get_size()
        self.windowWidth = szx
        self.windowHeight = szy
        self.camera = camera

        self.time = 0.0

        # Ocean Render Parameters
        self.wireframe = False
        self.oceanDepth = self.options.getfloat('Scene', 'oceandepth')
        self.enableUpdates = True
        self.oceanWind = Vector2(self.options.getfloat('Scene', 'oceanwindx'),
                                 self.options.getfloat('Scene', 'oceanwindy'))
        self.oceanWaveHeight = self.options.getfloat('Scene',
                                                     'oceanwaveheight')
        self.oceanTileSize = self.options.getint('Scene', 'oceantilesize')
        self.oceanTiles = Vector2(self.options.getint('Scene', 'oceantilesx'),
                                  self.options.getint('Scene', 'oceantilesy'))
        self.period = self.options.getfloat('Scene', 'period')
        self.env_path = self.options.get('Scene', 'env_path')
        self.frame = 0
        self.skyboxScale = 640.0
        self.skyboxOffset = Vector3(0.0, 0.0, 0.0)

        # Compile the shader
        self.skyboxShader = shader.openfiles('shaders/skybox.vertex',
                                             'shaders/skybox.fragment')

        # Renderables
        self.scene = []

        self.skybox = Skybox(
            self.skyboxShader,
            self.camera,
            self.skyboxScale,
            self.skyboxOffset,
            xpos_path=self.env_path + '/xpos.tga',
            ypos_path=self.env_path + '/ypos.tga',
            zpos_path=self.env_path + '/zpos.tga',
            xneg_path=self.env_path + '/xneg.tga',
            yneg_path=self.env_path + '/yneg.tga',
            zneg_path=self.env_path + '/zneg.tga',
        )
        self.scene.append(self.skybox)

        self.ocean = Ocean(self.camera,
                           cubemap=self.skybox,
                           depth=self.oceanDepth,
                           waveHeight=self.oceanWaveHeight,
                           wind=self.oceanWind,
                           tileSize=self.oceanTileSize,
                           tilesX=self.oceanTiles.x,
                           tilesZ=self.oceanTiles.y,
                           period=self.period)
        self.scene.append(self.ocean)
Esempio n. 5
0
from pyglet.gl import *
import shader

from pyglet import clock
from pyglet import font

from external import Camera, World, Player

from PIL import Image

from ctypes import c_byte

import console
import controller

program = shader.openfiles('shaders/main.vertex', 'shaders/main.fragment')

# Set up the Window (pyglet)
config = Config(buffers=2, samples=4)
window = pyglet.window.Window(caption='GlBlox',
                              width=1152,
                              height=864,
                              config=config,
                              vsync=False,
                              fullscreen=False)
window.set_exclusive_mouse(True)

console_font = font.load('Consolas', 14, bold=False, italic=False)

status = console.StatusConsole(x=window.width * 0.005,
                               y=window.height * 0.98,
Esempio n. 6
0
    def __init__(   self,
                    camera,
                    cubemap=None,
                    scale=1.0,
                    tileSize=128,
                    tilesX=1,
                    tilesZ=1,
                    depth=30.0,
                    waveHeight=3.125e-5,
                    wind=Vector2(64.0,128.0),
                    period=10.0,
                    photonScale=4.0,
                    photonIntensity=2.0):
                    
                    
        if cubemap:
            self.cubemapTexture = cubemap.texture
        else:
            self.cubemapTexture = None
            
        self.wind = wind                    # Ocean wind in X,Z axis
        self.waveHeight = waveHeight        # The phillips spectrum parameter
        self.oceanDepth = depth
        self.period = period                # Period of ocean surface anim
        self.drawSeaSurface = True
        self.drawSeaFloor = True
        self.enableCaustics = True
        self.photonIntensity = photonIntensity
        self.photonScale = photonScale
        
        self.tileSize = tileSize
        self.tilesX = tilesX
        self.tilesZ = tilesZ
        self.length = tileSize              # Ocean length parameter
        self.camera = camera
        self.scale = scale

        self.surfaceShader = shader.openfiles(  'shaders/ocean.vertex',
                                                'shaders/ocean.fragment')
        self.groundShader = shader.openfiles(   'shaders/oceanfloor.vertex',
                                                'shaders/oceanfloor.fragment')

        self.oceanFloorTexture = image.load('images/tiles.png').get_texture() 
        
        
        # Caustic texture
        self.causticTexture = image.DepthTexture.create_for_size(GL_TEXTURE_2D, 
                                                            self.tileSize, 
                                                            self.tileSize,
                                                            GL_RGBA)
        
        # Use Tessendorf FFT synthesis to create a convincing ocean surface.
        self.heightfield = Tessendorf(  self.tileSize,
                                        self.waveHeight, 
                                        self.wind,
                                        self.length,
                                        self.period)
                                           
        # The water surface
        self.surface = Surface( self.surfaceShader,
                                self.camera,
                                texture=self.oceanFloorTexture,
                                causticTexture=self.causticTexture,
                                cubemapTexture=self.cubemapTexture,
                                heightfield=self.heightfield,
                                tileSize=self.tileSize, 
                                tilesX=self.tilesX,
                                tilesZ=self.tilesZ,
                                scale=self.scale, 
                                offset=Vector3(0.0,self.oceanDepth,0.0))
                                
        # The caustics engine, uses the water surface to generate a caustic tex                      
        self.caustics = Caustics (  self.camera,
                                    self.surface,
                                    self.oceanDepth,
                                    self.causticTexture,
                                    self.photonScale,
                                    self.photonIntensity,
                                 )
        
        # The sea bed, an undisturbed mesh
        self.ground = Surface( self.groundShader,
                                self.camera,
                                texture=self.oceanFloorTexture,
                                causticTexture=self.causticTexture,
                                heightfield=None,
                                tileSize=1, 
                                tilesX=self.tilesX,
                                tilesZ=self.tilesZ,
                                scale=self.scale * self.tileSize, 
                                offset=Vector3(0.0,0.0,0.0))
Esempio n. 7
0
    def __init__(self, window, camera, statusConsole, options):
        ''' Constructor '''
        # Options
        self.options = options
        # Register the renderer for control input
        self.keys = key.KeyStateHandler()
        self.pressedKeys = {}
        self.window = window
        self.window.push_handlers(self.on_key_press)
        self.window.push_handlers(self.on_key_release)
        self.window.push_handlers(self.on_mouse_motion)
        self.window.push_handlers(self.keys)   
        # Window size
        (szx, szy) = self.window.get_size()
        self.windowWidth = szx
        self.windowHeight = szy
        self.camera = camera
        # Console
        self.status = statusConsole
        self.status.addParameter('Wind')      
        self.status.addParameter('Wave height')
        self.status.addParameter('Ocean depth')
        self.status.addParameter('Time')
        self.status.addParameter('Caustics intensity')
        self.status.addParameter('Caustics scale')
        
        self.time = 0.0
        
        # Ocean Render Parameters
        self.wireframe = False
        self.oceanDepth = self.options.getfloat('Scene', 'oceandepth')
        self.enableUpdates = True
        self.oceanWind = Vector2(
                            self.options.getfloat('Scene', 'oceanwindx'),
                            self.options.getfloat('Scene', 'oceanwindy'))
        self.oceanWaveHeight = self.options.getfloat('Scene', 'oceanwaveheight')
        self.oceanTileSize = self.options.getint('Scene', 'oceantilesize')
        self.oceanTiles = Vector2(
                            self.options.getint('Scene', 'oceantilesx'),
                            self.options.getint('Scene', 'oceantilesy'))
        self.drawSurface = True
        self.drawFloor = True
        self.enableCaustics = True
        self.causticIntensity= self.options.getfloat('Scene','causticintensity')
        self.causticPhotonScale = self.options.getfloat('Scene', 'causticscale')
        self.period = self.options.getfloat('Scene', 'period')
        self.env_path = self.options.get('Scene', 'env_path')
        self.frame = 0
        self.skyboxScale = 640.0
        self.skyboxOffset = Vector3(0.0,0.0,0.0)

        # Compile the shader
        self.skyboxShader = shader.openfiles( 'shaders/skybox.vertex',
                                        'shaders/skybox.fragment')
        
        
        # Renderables
        self.scene = []
        
        self.skybox = Skybox(
                        self.skyboxShader,
                        self.camera,
                        self.skyboxScale,
                        self.skyboxOffset,
                        xpos_path=self.env_path + '/xpos.tga',
                        ypos_path=self.env_path + '/ypos.tga',
                        zpos_path=self.env_path + '/zpos.tga',
                        xneg_path=self.env_path + '/xneg.tga',
                        yneg_path=self.env_path + '/yneg.tga',
                        zneg_path=self.env_path + '/zneg.tga',
                    )
        self.scene.append(self.skybox)
                                
        self.ocean = Ocean( self.camera,
                            cubemap=self.skybox,
                            depth=self.oceanDepth,
                            waveHeight=self.oceanWaveHeight,
                            wind=self.oceanWind,
                            tileSize=self.oceanTileSize,
                            tilesX=self.oceanTiles.x,
                            tilesZ=self.oceanTiles.y,
                            photonScale=self.causticPhotonScale,
                            photonIntensity=self.causticIntensity,
                            period=self.period)
                                     
        self.scene.append(self.ocean)