示例#1
0
 public static List<float> ToFloatList(VertexInfo[] vbo)
 {
     List<float> bytes = new List<float>(vbo.Length * 8);
     foreach(var v in vbo)
         bytes.AddRange(v.ToFloatList());
     return bytes;
 }
示例#2
0
        public static Object3dManager LoadFromRaw(string vboFile)
        {
            var vboBytes = File.ReadAllBytes(vboFile);

            var vboFloats = new float[vboBytes.Length / 4];

            Buffer.BlockCopy(vboBytes, 0, vboFloats, 0, vboBytes.Length);

            return(new Object3dManager(VertexInfo.FromFloatArray(vboFloats)));
        }
示例#3
0
 public Object3dInfo(List <VertexInfo> vbo)
 {
     VBO          = VertexInfo.ToFloatList(vbo).ToArray();
     IndicesCount = VBO.Length / 8;
     if (vbo.Count > 0)
     {
         var a = vbo[0].Position;
         var b = vbo[0].Position;
         foreach (var v in vbo)
         {
             a = Min(a, v.Position);
             b = Max(b, v.Position);
         }
         BoundingBoxMin = a;
         BoundingBoxMax = b;
     }
 }
示例#4
0
 public static List<VertexInfo> FromFloatArray(float[] vbo)
 {
     List<VertexInfo> vs = new List<VertexInfo>(vbo.Length / 8);
     var cnt = vbo.Length;
     for(int i = 0; i < cnt; i += 8)
     {
         var v = new VertexInfo();
         v.Position.X = vbo[i];
         v.Position.Y = vbo[i + 1];
         v.Position.Z = vbo[i + 2];
         v.UV.X = vbo[i + 3];
         v.UV.Y = vbo[i + 4];
         v.Normal.X = vbo[i + 5];
         v.Normal.Y = vbo[i + 6];
         v.Normal.Z = vbo[i + 7];
         vs.Add(v);
     }
     return vs;
 }
示例#5
0
        public static List <VertexInfo> FromFloatArray(float[] vbo)
        {
            List <VertexInfo> vs = new List <VertexInfo>(vbo.Length / 8);
            var cnt = vbo.Length;

            for (int i = 0; i < cnt; i += 8)
            {
                var v = new VertexInfo();
                v.Position.X = vbo[i];
                v.Position.Y = vbo[i + 1];
                v.Position.Z = vbo[i + 2];
                v.UV.X       = vbo[i + 3];
                v.UV.Y       = vbo[i + 4];
                v.Normal.X   = vbo[i + 5];
                v.Normal.Y   = vbo[i + 6];
                v.Normal.Z   = vbo[i + 7];
                vs.Add(v);
            }
            return(vs);
        }
示例#6
0
        public Renderer(int initialWidth, int initialHeight, int samples)
        {
            GlareTexture = new Texture(Media.Get("glaretex.png"));

            Voxelizer = new Voxel3dTextureWriter(256, 256, 256, new Vector3(22, 22, 22), new Vector3(0, 8, 0));

            CubeMapSphere = new Object3dInfo(Object3dManager.LoadFromObjSingle(Media.Get("cubemapsphere.obj")).Vertices);

            var cubeMapTexDefault = new CubeMapTexture(Media.Get("posx.jpg"), Media.Get("posy.jpg"), Media.Get("posz.jpg"),
                                                       Media.Get("negx.jpg"), Media.Get("negy.jpg"), Media.Get("negz.jpg"));

            CubeMaps.Add(new CubeMapInfo()
            {
                Texture      = cubeMapTexDefault,
                FalloffScale = 99999999.0f,
                Position     = Vector3.Zero
            });

            Width  = initialWidth;
            Height = initialHeight;


            Samples = samples;

            CreateBuffers();

            HDRShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "HDR.fragment.glsl");
            HDRShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                HDRShader.SetGlobal("USE_MSAA", "");
            }

            VXGIShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "VXGI.fragment.glsl");
            VXGIShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                VXGIShader.SetGlobal("USE_MSAA", "");
            }

            AmbientOcclusionShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "AmbientOcclusion.fragment.glsl");
            AmbientOcclusionShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                AmbientOcclusionShader.SetGlobal("USE_MSAA", "");
            }

            FogShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Fog.fragment.glsl");
            FogShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                FogShader.SetGlobal("USE_MSAA", "");
            }

            DeferredShader = ShaderProgram.Compile("PostProcessPerspective.vertex.glsl", "Deferred.fragment.glsl");
            DeferredShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                DeferredShader.SetGlobal("USE_MSAA", "");
            }

            EnvLightShader = ShaderProgram.Compile("PostProcessPerspective.vertex.glsl", "EnvironmentLight.fragment.glsl");
            EnvLightShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                EnvLightShader.SetGlobal("USE_MSAA", "");
            }

            CombinerShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Combiner.fragment.glsl");
            CombinerShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                CombinerShader.SetGlobal("USE_MSAA", "");
            }

            CombinerSecondShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "CombinerSecond.fragment.glsl");
            CombinerSecondShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                CombinerSecondShader.SetGlobal("USE_MSAA", "");
            }

            MotionBlurShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "MotionBlur.fragment.glsl");
            MotionBlurShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                MotionBlurShader.SetGlobal("USE_MSAA", "");
            }

            BloomShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Bloom.fragment.glsl");

            PostProcessingMesh          = new Object3dInfo(VertexInfo.FromFloatArray(postProcessingPlaneVertices));
            PostProcessingMesh.DrawMode = PrimitiveType.TriangleStrip;
        }
示例#7
0
 public Object3dManager(VertexInfo[] vertices)
 {
     Vertices = vertices.ToList();
 }
示例#8
0
 public Object3dInfo(VertexInfo[] vbo)
 {
     VBO = VertexInfo.ToFloatList(vbo).ToArray();
     IndicesCount = VBO.Length / 8;
 }