1 module play; 2 3 import re; 4 import re.gfx; 5 import re.gfx.shapes.cube; 6 import re.gfx.shapes.grid; 7 import re.ng.camera; 8 import re.math; 9 static import raylib; 10 11 class PlayScene : Scene3D { 12 private PostProcessor glitch_postproc; 13 private float[2] aberrationOffset = [0.01, 0]; 14 15 override void on_start() { 16 clear_color = Colors.LIGHTGRAY; 17 18 // load the effect and add it as a postprocessor 19 auto chrm_abr = Effect(Core.content.load_shader(null, 20 "chromatic_aberration.frag"), color_alpha_white(0.8)); 21 glitch_postproc = new PostProcessor(resolution, chrm_abr); 22 glitch_postproc.enabled = false; 23 postprocessors ~= glitch_postproc; 24 25 cam.entity.position = Vector3(0, 10, 10); 26 cam.look_at(Vector3(0, 0, 0)); 27 28 auto block = create_entity("block", Vector3(0, 0, 0)); 29 auto cube = block.add_component(new Cube(Vector3(2, 2, 2))); 30 31 cam.entity.add_component(new CameraOrbit(block, 0.5)); 32 33 // enable an example shader on cube 34 auto cross_stitch = Effect(Core.content.load_shader(null, 35 "cross_stitch.frag"), Colors.PURPLE); 36 auto mixAmt = 0.05f; 37 cross_stitch.set_shader_var("mixAmt", mixAmt); 38 cube.effect = cross_stitch; 39 40 auto grid = create_entity("grid"); 41 grid.add_component(new Grid3D(10, 1)); 42 } 43 44 override void update() { 45 super.update(); 46 47 if (Input.is_key_pressed(Keys.KEY_SPACE)) { 48 glitch_postproc.enabled = !glitch_postproc.enabled; 49 } 50 51 // make our postprocess effect fluctuate 52 import std.math : sin; 53 54 aberrationOffset[0] = 0.010 + 0.005 * sin(Time.total_time / 2); 55 glitch_postproc.effect.set_shader_var("aberrationOffset", aberrationOffset); 56 } 57 58 override void render() { 59 super.render(); 60 } 61 }