def setup_grey3x_rendering(update_projector=False): """ Return (Shader, FBO, QuadMesh) for rendering in Propixx's 'GREY3X' mode. If desired, can also apply the settings to the beamer to set it to this mode (caution: won't change back afterward). """ if update_projector: beamer = propixx.PROPixx() beamer.setDlpSequencerProgram('GREY3X') vert_shader = open(rc.resources.deferredShader.vert).read() frag_shader = """ #version 400 #extension GL_ARB_texture_rectangle : enable uniform sampler2D TextureMap; in vec2 texCoord; out vec3 color; void main( void ) { if (gl_FragCoord.x * 3 + 1 < 1920){ color = vec3(texture2D(TextureMap, vec2(floor(gl_FragCoord.x * 3. + 0.0) / 1920.0, gl_FragCoord.y / 1080.0)).r, texture2D(TextureMap, vec2(floor(gl_FragCoord.x * 3. + 1.0) / 1920.0, gl_FragCoord.y / 1080.0)).r, texture2D(TextureMap, vec2(floor(gl_FragCoord.x * 3. + 2.0) / 1920.0, gl_FragCoord.y / 1080.0)).r ); } else { color = vec3(.2, 0., 0.); } return; } """ shader = rc.Shader(vert=vert_shader, frag=frag_shader) quad = rc.gen_fullscreen_quad('Grey3xQuad') return RenderCollection(shader=shader, fbo=None, quad=quad)
void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); } """ FRAG_SHADER2 = """ #version 120 #extension GL_NV_shadow_samplers_cube : enable void main() { gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); } """ shader = rc.Shader(vert=VERT_SHADER, frag=FRAG_SHADER) # Make Stimuli (Spheres) reader = rc.WavefrontReader(rc.resources.obj_primitives) circles = [ reader.get_mesh("Circle", scale=0.07) for _ in range(1, nCircles + 1) ] targets = [reader.get_mesh("Plane", scale=0.4)] # Writing text during experiment(instructions...bla bla bla) text = psychopy.visual.TextStim(win=win) # ----------------------------------- Define Spheres Coordinates ---------------------------------------- # Define initial coordinates
float pi = 3.14159; float mean = 0.5; float std = .1; uniform float theta; void main() { brightness = sin(texCoord.x / width + theta) / 2.; // Sine wave brightness *= exp(-.5 * pow(texCoord.x - mean, 2) / pow(std, 2)); // x-gaussian brightness *= exp(-.5 * pow(texCoord.y - mean, 2) / pow(std, 2)); // y-gaussian brightness += .5; // Add grey value final_color = vec4(vec3(brightness), 1.) ; } """ shader = rc.Shader(vert=vert_shader, frag=frag_shader) plane = rc.WavefrontReader(rc.resources.obj_primitives).get_mesh( 'Plane') #gen_fullscreen_quad() plane.scale.xyz = .2 plane.position.xyz = 0, 0, -1 plane.uniforms['theta'] = 0. plane.uniforms['width'] = .01 window = pyglet.window.Window(fullscreen=True) scene = rc.Scene(meshes=[plane], bgColor=(.5, .5, .5), camera=rc.Camera(projection=rc.OrthoProjection())) # Draw Function
def debug_view(vertices, texcoord, image=None, window_size=(800, 600)): # creates the window and sets its properties width, height = window_size window = pyglet.window.Window(width=width, height=height, caption='Debug Viewer', resizable=False) num_verts = 3 * vertices.shape[0] model = ratcave.Mesh(arrays=(vertices.reshape(num_verts, 3), texcoord.reshape(num_verts, 2))) model.position.xyz = 0, 0, -10 if image is not None: image = image.transpose(PIL.Image.FLIP_TOP_BOTTOM) imgdata = pyglet.image.ImageData(image.width, image.height, 'RGBA', image.tobytes()) mipmap = False tex = imgdata.get_mipmapped_texture( ) if mipmap else imgdata.get_texture() pyglet.gl.glBindTexture(pyglet.gl.GL_TEXTURE_2D, 0) model.textures.append( ratcave.Texture(id=tex.id, data=tex, mipmap=mipmap)) scene = ratcave.Scene(meshes=[model]) scene.camera.projection = ratcave.PerspectiveProjection(60.0, width / float(height), z_far=100.0) def update(dt): pass pyglet.clock.schedule(update) shader = ratcave.Shader(vert=vert_shader, frag=frag_shader) @window.event def on_resize(width, height): # TODO update scene.camera.projection.viewport scene.camera.projection.aspect = width / float(height) return pyglet.event.EVENT_HANDLED @window.event def on_draw(): with shader: scene.draw() @window.event def on_mouse_scroll(x, y, scroll_x, scroll_y): # scroll the MOUSE WHEEL to zoom scene.camera.position.z -= scroll_y / 10.0 @window.event def on_mouse_drag(x, y, dx, dy, button, modifiers): # press the LEFT MOUSE BUTTON to rotate if button == pyglet.window.mouse.LEFT: model.rotation.y += dx / 5.0 model.rotation.x -= dy / 5.0 # press the LEFT and RIGHT MOUSE BUTTONS simultaneously to pan if button == pyglet.window.mouse.LEFT | pyglet.window.mouse.RIGHT: scene.camera.position.x -= dx / 100.0 scene.camera.position.y -= dy / 100.0 # starts the application pyglet.app.run()