def on_start(self, ctx: gl.GL_ANY): self.ctx = ctx self.asset = px.AssetImporter(ctx, self.MODEL_PATH) self.mesh, = self.asset.meshes self.transform = px.transform.identity() self.albedo = px.vec3(1, 0.75, 0.5) self.specular = px.float32(0.5) self.shininess = px.float32(32) self._MOUSE_DRAG_SPEED = 4 self._FRICTION = 0.95 self._mouse_x, self._mouse_y = -1, -1 self._delta_x, self._delta_y = 0, 0 self._theta, self._phi = 0, 0 self._r = -200 self.fov = 60 self.camera = px.PerspectiveCamera(ctx, self.fov, 1, 0.1, 100, px.look_at(px.vec3(0, 0, -self._r / self.fov ), px.vec3(0, 0, 0), px.vec3(0, 1, 0))) self.ambient = px.vec3(0.1, 0.1, 0.1) self.key_light = px.DirectionalLight(ctx, px.vec3(-1, 0, 1), px.vec3(1, 1, 1), px.float32(1)) self.fill_light = px.DirectionalLight(ctx, px.vec3(1, 0, 0), px.vec3(0.5, 0.5, 1), px.float32(0.5)) self.rim_light = px.DirectionalLight(ctx, px.vec3(-1, 1, -2), px.vec3(1, 1, 1), px.float32(4)) self.point_light = px.PointLight(ctx, px.vec3(0, 0, 10), px.vec3(1, 0, 0), px.float32(1), px.float32(0.1)) # self.program = px.Program(ctx, # px.VertexShader(ctx, '../../pyplex/glsl/lambert/lambert.vs'), # px.FragmentShader(ctx, '../../pyplex/glsl/lambert/lambert.fs'), # vao=self.mesh.vao) self.program = px.Program(ctx, px.VertexShader(ctx, '../../pyplex/glsl/blinn_phong/blinn_phong.vs'), px.FragmentShader(ctx, '../../pyplex/glsl/blinn_phong/blinn_phong.fs'), vao=self.mesh.vao) self.program['albedo'] = self.albedo self.program['specular'] = self.specular self.program['shininess'] = self.shininess self.program['Camera'] = self.camera.buffer self.program['ambient'] = self.ambient self.program['DirectionalLightCount'] = px.int32(3) self.program['DirectionalLight[0]'] = self.key_light.buffer self.program['DirectionalLight[1]'] = self.fill_light.buffer self.program['DirectionalLight[2]'] = self.rim_light.buffer self.program['PointLightCount'] = px.int32(1) self.program['PointLight[0]'] = self.point_light.buffer self.ctx.clear_color(0.1, 0.2, 0.4, 1.0) self.ctx.enable(px.gl.Enableable.DEPTH_TEST)
def on_start(self, ctx: gl.GL_ANY): self.ctx = ctx self.program = px.Program(ctx, px.VertexShader(ctx, '../../pyplex/glsl/blinn_phong/blinn_phong.vs'), px.FragmentShader(ctx, '../../pyplex/glsl/blinn_phong/blinn_phong.fs')) self.asset = px.AssetImporter(ctx, Sponza.PATH) self.meshes = self.asset.meshes self.albedos = np.random.uniform(size=(len(self.meshes), 3)).astype(np.float32) self.transform = px.identity() self.camera = px.TrackBallCamera(self.ctx, 60, 1, 1, 5000, px.vec3(0, 100, 0), px.vec3(0, 1, 0), np.pi/2, 0, 500) self.point_lights = [ px.PointLight(self.ctx, px.vec3(np.random.uniform(-1000, 1000), np.random.uniform(100, 500), np.random.uniform(-500, 500)), px.normalize(np.random.uniform(0, 1, 3).astype(np.float32)), px.float32(20), px.float32(0.001)) for i in range(12)] self.program['Camera'] = self.camera.buffer self.program['ambient'] = px.vec3(0.1, 0.1, 0.1) self.program['Ns'] = px.float32(8) self.program['Ka'] = px.vec3(1, 1, 1) self.program['Kd'] = px.vec3(0.5, 0.5, 0.5) self.program['Ks'] = px.vec3(0.5, 0.5, 0.5) self.program['model'] = self.transform self.program['model_1T'] = np.ascontiguousarray(np.linalg.inv(self.transform).T[:3,:3]) self.program['PointLightCount'] = px.int32(len(self.point_lights)) for i, light in enumerate(self.point_lights): self.program['PointLight[{}]'.format(i)] = light.buffer self.ctx.clear_color(0.25, 0.5, 1.0, 1.0) self.ctx.enable(gl.DEPTH_TEST) self.ctx.enable(px.gl.Enableable.CULL_FACE) self.ctx.cull_face(px.gl.CullFace.BACK) # self.ctx.polygon_mode(px.gl.CullFace.FRONT_AND_BACK, px.gl.PolygonMode.LINE) self.theta = self.phi = 0.0 self.x_prev = self.y_prev = 0.0
def on_start(self, ctx: gl.GL_ANY): self.ctx = ctx plane = px.Plane() sphere = px.Sphere(64, 32) self.meshes = [ px.Mesh(self.ctx, plane.elements, plane.vertices, plane.uvs, plane.normals), px.Mesh(self.ctx, sphere.elements, sphere.vertices, normals=sphere.normals) ] self.transform = px.identity() self.program = px.Program(ctx, px.VertexShader(ctx, '../pyplex/glsl/blinn_phong/blinn_phong.vs'), px.FragmentShader(ctx, '../pyplex/glsl/blinn_phong/blinn_phong.fs')) self.camera = px.TrackBallCamera(self.ctx, 60, 1, 0.01, 10, px.vec3(0, 0, 0), px.vec3(0, 1, 0), np.pi/5, np.pi/4, 2) self.point_lights = [ px.PointLight(self.ctx, px.vec3(0, 2, 0), px.vec3(1, 1, 1), px.float32(1), px.float32(0.1)) ] self.program['Camera'] = self.camera.buffer self.program['ambient'] = px.vec3(0.025, 0.05, 0.1) self.program['Ns'] = px.float32(32) self.program['Ka'] = px.vec3(1, 1, 1) self.program['Kd'] = px.vec3(0.5, 0.5, 0.5) self.program['Ks'] = px.vec3(0.5, 0.5, 0.5) self.program['model'] = self.transform self.program['model_1T'] = np.ascontiguousarray(np.linalg.inv(self.transform).T[:3, :3]) self.program['PointLightCount'] = px.int32(len(self.point_lights)) for i, light in enumerate(self.point_lights): self.program['PointLight[{}]'.format(i)] = light.buffer self.ctx.clear_color(0.25, 0.5, 1.0, 1.0) self.ctx.enable(gl.DEPTH_TEST) self.ctx.enable(px.gl.Enableable.CULL_FACE) self.ctx.cull_face(px.gl.CullFace.BACK) self.theta = self.phi = 0.0 self.x_prev = self.y_prev = 0.0
def __init__(self, ctx: gl.GL31, direction: Vec3, color: Vec3, strength: Float32): self._direction = direction self._color = color self._strength = strength self._buffer = UniformBuffer( ctx, np.hstack( (normalize(direction), strength, color, float32(1))))
def _update_buffer(self): self._buffer.data = np.hstack( (normalize(self._direction), self._strength, self._color, float32(1)))