1 /** 2 * Copyright: Copyright (C) 2018 Gabriel Gheorghe, All Rights Reserved 3 * Authors: $(Gabriel Gheorghe) 4 * License: $(LINK2 https://www.gnu.org/licenses/gpl-3.0.txt, GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007) 5 * Source: $(LINK2 https://github.com/GabyForceQ/LibertyEngine/blob/master/source/liberty/framework/skybox/impl.d) 6 * Documentation: 7 * Coverage: 8 **/ 9 module liberty.framework.skybox.impl; 10 11 import liberty.framework.skybox.vertex; 12 import liberty.graphics.shader.impl; 13 import liberty.material.impl; 14 import liberty.math.matrix; 15 import liberty.math.vector; 16 import liberty.model.impl; 17 import liberty.model.io; 18 import liberty.scene.entity; 19 import liberty.scene.meta; 20 21 /** 22 * 23 **/ 24 final class SkyBox : Entity { 25 mixin NodeBody; 26 27 private { 28 Shader shader; 29 } 30 31 /** 32 * 33 **/ 34 this(string id) { 35 super(id); 36 register; 37 38 shader = Shader 39 .getOrCreate("SkyBox", (shader) { 40 shader 41 .setViewMatrixEnabled(false) 42 .addGlobalRenderMethod((program) { 43 // Make it unreachable 44 Matrix4F newViewMatrix = scene.camera.viewMatrix; 45 newViewMatrix.c[0][3] = 0; 46 newViewMatrix.c[1][3] = 0; 47 newViewMatrix.c[2][3] = 0; 48 49 program 50 .loadUniform("uFadeLowerLimit", 0.0f) 51 .loadUniform("uFadeUpperLimit", 30.0f) 52 .loadUniform("uFogColor", scene.world.getExpHeightFogColor) 53 .loadUniform("uViewMatrix", newViewMatrix); 54 }); 55 }); 56 57 shader.registerEntity(this); 58 scene.shaderMap[shader.id] = shader; 59 } 60 61 /** 62 * 63 * Returns reference to this so it can be used in a stream. 64 **/ 65 typeof(this) build(Material material) { 66 model = new Model(ModelIO.loadRawModel(skyBoxVertices), [material]); 67 return this; 68 } 69 } 70 71 private const float SIZE = 500.0f; 72 73 private SkyBoxVertex[36] skyBoxVertices = [ 74 SkyBoxVertex(Vector3F(-SIZE, SIZE, -SIZE)), 75 SkyBoxVertex(Vector3F(-SIZE, -SIZE, -SIZE)), 76 SkyBoxVertex(Vector3F( SIZE, -SIZE, -SIZE)), 77 SkyBoxVertex(Vector3F( SIZE, -SIZE, -SIZE)), 78 SkyBoxVertex(Vector3F( SIZE, SIZE, -SIZE)), 79 SkyBoxVertex(Vector3F(-SIZE, SIZE, -SIZE)), 80 81 SkyBoxVertex(Vector3F(-SIZE, -SIZE, SIZE)), 82 SkyBoxVertex(Vector3F(-SIZE, -SIZE, -SIZE)), 83 SkyBoxVertex(Vector3F(-SIZE, SIZE, -SIZE)), 84 SkyBoxVertex(Vector3F(-SIZE, SIZE, -SIZE)), 85 SkyBoxVertex(Vector3F(-SIZE, SIZE, SIZE)), 86 SkyBoxVertex(Vector3F(-SIZE, -SIZE, SIZE)), 87 88 SkyBoxVertex(Vector3F( SIZE, -SIZE, -SIZE)), 89 SkyBoxVertex(Vector3F( SIZE, -SIZE, SIZE)), 90 SkyBoxVertex(Vector3F( SIZE, SIZE, SIZE)), 91 SkyBoxVertex(Vector3F( SIZE, SIZE, SIZE)), 92 SkyBoxVertex(Vector3F( SIZE, SIZE, -SIZE)), 93 SkyBoxVertex(Vector3F( SIZE, -SIZE, -SIZE)), 94 95 SkyBoxVertex(Vector3F(-SIZE, -SIZE, SIZE)), 96 SkyBoxVertex(Vector3F(-SIZE, SIZE, SIZE)), 97 SkyBoxVertex(Vector3F( SIZE, SIZE, SIZE)), 98 SkyBoxVertex(Vector3F( SIZE, SIZE, SIZE)), 99 SkyBoxVertex(Vector3F( SIZE, -SIZE, SIZE)), 100 SkyBoxVertex(Vector3F(-SIZE, -SIZE, SIZE)), 101 102 SkyBoxVertex(Vector3F(-SIZE, SIZE, -SIZE)), 103 SkyBoxVertex(Vector3F( SIZE, SIZE, -SIZE)), 104 SkyBoxVertex(Vector3F( SIZE, SIZE, SIZE)), 105 SkyBoxVertex(Vector3F( SIZE, SIZE, SIZE)), 106 SkyBoxVertex(Vector3F(-SIZE, SIZE, SIZE)), 107 SkyBoxVertex(Vector3F(-SIZE, SIZE, -SIZE)), 108 109 SkyBoxVertex(Vector3F(-SIZE, -SIZE, -SIZE)), 110 SkyBoxVertex(Vector3F(-SIZE, -SIZE, SIZE)), 111 SkyBoxVertex(Vector3F( SIZE, -SIZE, -SIZE)), 112 SkyBoxVertex(Vector3F( SIZE, -SIZE, -SIZE)), 113 SkyBoxVertex(Vector3F(-SIZE, -SIZE, SIZE)), 114 SkyBoxVertex(Vector3F( SIZE, -SIZE, SIZE)) 115 ];