Esempio n. 1
0
        private void compileShader(GLSLShaderText vs, GLSLShaderText fs, GLSLShaderText gs, GLSLShaderText tes, GLSLShaderText tcs, SHADER_TYPE type, ref string log)
        {
            GLSLShaderConfig shader_conf = new GLSLShaderConfig(vs, fs, gs, tcs, tes, type);

            compileShader(shader_conf);
            MVCore.Common.RenderState.activeResMgr.GLShaders[shader_conf.shader_type] = shader_conf;
            log += shader_conf.log; //Append log
        }
Esempio n. 2
0
        public void compileShader(GLSLShaderConfig config)
        {
            if (config.program_id != -1)
            {
                GL.DeleteProgram(config.program_id);
            }

            GLShaderHelper.CreateShaders(config);
        }
Esempio n. 3
0
        private void renderBHull(GLSLShaderConfig shader)
        {
            if (bHullVao == null)
            {
                return;
            }
            //I ASSUME THAT EVERYTHING I NEED IS ALREADY UPLODED FROM A PREVIOUS PASS
            GL.PointSize(8.0f);
            GL.BindVertexArray(bHullVao.vao_id);

            GL.DrawElementsBaseVertex(PrimitiveType.Points, metaData.batchcount,
                                      metaData.indicesLength, IntPtr.Zero, -metaData.vertrstart_physics);
            GL.DrawElementsBaseVertex(PrimitiveType.Triangles, metaData.batchcount,
                                      metaData.indicesLength, IntPtr.Zero, -metaData.vertrstart_physics);
            GL.BindVertexArray(0);
        }
Esempio n. 4
0
        public void render()
        {
            GL.Enable(EnableCap.Blend);
            GL.Disable(EnableCap.DepthTest);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            //Render info right on the 0 buffer

            GLSLShaderConfig shader = resMgr.GLShaders[SHADER_TYPE.TEXT_SHADER];

            GL.UseProgram(shader.program_id);

#if (DEBUG)
            //Upload test options to the shader
            //GL.Uniform1(shader.uniformLocations["edge"], RenderState.renderSettings.testOpt1);
            //GL.Uniform1(shader.uniformLocations["width"], RenderState.renderSettings.testOpt2);
#endif

            GL.Disable(EnableCap.CullFace);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

            //Render texts included in Text manager
            foreach (Text t in resMgr.txtMgr.texts)
            {
                GLMeshVao m = t.meshVao;

                //Render Start
                //GL.Uniform1(shader.uniformLocations["size"], m.material.CustomPerMaterialUniforms["size"].Vec.X);
                GL.Uniform1(shader.uniformLocations["fontSize"], (float)t.font.Size);
                GL.Uniform1(shader.uniformLocations["textSize"], t.lineHeight);
                GL.Uniform2(shader.uniformLocations["offset"], t.pos);
                GL.Uniform3(shader.uniformLocations["color"], t.color);
                //GL.Uniform2(shader.uniformLocations["textDim"], t.size);
                m.render(shader, RENDERPASS.FORWARD);
            }
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Enable(EnableCap.CullFace);

            GL.PolygonMode(MaterialFace.FrontAndBack, RenderState.renderSettings.RENDERMODE);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Blend);
        }
Esempio n. 5
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f);
            GL.Enable(EnableCap.DepthTest);

            //Setup Texture
            string texturepath = "E:\\SteamLibrary1\\steamapps\\common\\No Man's Sky\\GAMEDATA\\TEXTURES\\PLANETS\\BIOMES\\WEIRD\\BEAMSTONE\\BEAMGRADIENT.DDS";
            //string texturepath = "E:\\SteamLibrary1\\steamapps\\common\\No Man's Sky\\GAMEDATA\\TEXTURES\\PLANETS\\BIOMES\\WEIRD\\BEAMSTONE\\SCROLLINGCLOUD.DDS";
            Texture tex = new Texture(texturepath);

            texture_id = tex.bufferID;


            string log = "";
            //Compile Necessary Shaders
            //Pass Shader
            GLSLShaderText gbuffer_shader_vs = new GLSLShaderText(ShaderType.VertexShader);

            gbuffer_shader_vs.addStringFromFile("Shaders/Gbuffer_VS.glsl");
            GLSLShaderText passthrough_shader_fs = new GLSLShaderText(ShaderType.FragmentShader);

            passthrough_shader_fs.addStringFromFile("Shaders/PassThrough_FS.glsl");


            shader_conf = new GLSLShaderConfig(gbuffer_shader_vs, passthrough_shader_fs,
                                               null, null, null, SHADER_TYPE.PASSTHROUGH_SHADER);
            compileShader(shader_conf);

            //Generate Geometry

            //Default render quad
            MVCore.Primitives.Quad q = new MVCore.Primitives.Quad();
            quad_vao_id = q.getVAO().vao_id;

            GL.Viewport(0, 0, 800, 600);
        }
Esempio n. 6
0
        //Default render method
        public bool render(GLSLShaderConfig shader, RENDERPASS pass)
        {
            //Render Object
            switch (pass)
            {
            //Render Main
            case RENDERPASS.DEFERRED:
            case RENDERPASS.FORWARD:
            case RENDERPASS.DECAL:
                renderMain(shader);
                break;

            case RENDERPASS.BBOX:
            case RENDERPASS.BHULL:
                //renderBbox(shader.program_id, 0);
                //renderBSphere(shader);
                renderBHull(shader);
                break;

            //Render Debug
            case RENDERPASS.DEBUG:
                //renderDebug(shader.program_id);
                break;

            //Render for Picking
            case RENDERPASS.PICK:
                //renderDebug(shader.program_id);
                break;

            default:
                //Do nothing in any other case
                break;
            }

            return(true);
        }
Esempio n. 7
0
        public virtual void renderMain(GLSLShaderConfig shader)
        {
            //Upload Material Information

            //Upload Custom Per Material Uniforms
            foreach (Uniform un in material.CustomPerMaterialUniforms.Values)
            {
                if (shader.uniformLocations.Keys.Contains(un.Name))
                {
                    GL.Uniform4(shader.uniformLocations[un.Name], un.vec.vec4);
                }
            }

            //BIND TEXTURES
            //Diffuse Texture
            foreach (Sampler s in material.PSamplers.Values)
            {
                if (shader.uniformLocations.ContainsKey(s.Name) && s.Map != "")
                {
                    GL.Uniform1(shader.uniformLocations[s.Name], MyTextureUnit.MapTexUnitToSampler[s.Name]);
                    GL.ActiveTexture(s.texUnit.texUnit);
                    GL.BindTexture(s.tex.target, s.tex.texID);
                }
            }

            //BIND TEXTURE Buffer
            if (skinned)
            {
                GL.Uniform1(shader.uniformLocations["mpCustomPerMaterial.skinMatsTex"], 6);
                GL.ActiveTexture(TextureUnit.Texture6);
                GL.BindTexture(TextureTarget.TextureBuffer, instanceBoneMatricesTex);
                GL.TexBuffer(TextureBufferTarget.TextureBuffer,
                             SizedInternalFormat.Rgba32f, instanceBoneMatricesTexTBO);
            }

            //if (instance_count > 100)
            //    Console.WriteLine("Increase the buffers");

            switch (type)
            {
            case TYPES.GIZMO:
            case TYPES.GIZMOPART:
            case TYPES.MESH:
            case TYPES.TEXT:
                renderMesh();
                break;

            case TYPES.LOCATOR:
            case TYPES.MODEL:
                renderLocator();
                break;

            case TYPES.JOINT:
                renderJoint();
                break;

            case TYPES.COLLISION:
                renderCollision();
                break;

            case TYPES.LIGHT:
                renderLight();
                break;
            }
        }
Esempio n. 8
0
        private void compileMaterialShader()
        {
            Dictionary <int, GLSLShaderConfig>  shaderDict;
            Dictionary <int, List <GLMeshVao> > meshList;

            List <string> includes = new List <string>();
            List <string> defines  = new List <string>();

            //Save shader to resource Manager
            //Check for explicit materials
            if (Name == "collisionMat" || Name == "jointMat" || Name == "crossMat")
            {
                shaderDict = Common.RenderState.activeResMgr.GLDefaultShaderMap;
                meshList   = Common.RenderState.activeResMgr.defaultMeshShaderMap;
                defines.Add("_D_DEFERRED_RENDERING");
            }
            else if (MaterialFlags.Contains("_F51_DECAL_DIFFUSE") ||
                     MaterialFlags.Contains("_F52_DECAL_NORMAL"))
            {
                shaderDict = Common.RenderState.activeResMgr.GLDeferredShaderMapDecal;
                meshList   = Common.RenderState.activeResMgr.decalMeshShaderMap;
                defines.Add("_D_DEFERRED_RENDERING");
            }
            else if (MaterialFlags.Contains("_F09_TRANSPARENT") ||
                     MaterialFlags.Contains("_F22_TRANSPARENT_SCALAR") ||
                     MaterialFlags.Contains("_F11_ALPHACUTOUT"))
            {
                shaderDict = Common.RenderState.activeResMgr.GLForwardShaderMapTransparent;
                meshList   = Common.RenderState.activeResMgr.transparentMeshShaderMap;
            }

            else if (MaterialFlags.Contains("_F07_UNLIT"))
            {
                shaderDict = Common.RenderState.activeResMgr.GLDeferredUNLITShaderMap;
                meshList   = Common.RenderState.activeResMgr.opaqueMeshShaderMap;
                defines.Add("_D_DEFERRED_RENDERING");
            }
            else
            {
                shaderDict = Common.RenderState.activeResMgr.GLDeferredLITShaderMap;
                meshList   = Common.RenderState.activeResMgr.opaqueMeshShaderMap;
                defines.Add("_D_DEFERRED_RENDERING");
            }

            for (int i = 0; i < MaterialFlags.Count; i++)
            {
                if (supported_flags.Contains(MaterialFlags[i]))
                {
                    includes.Add(MaterialFlags[i]);
                }
            }

            GLSLShaderConfig shader = GLShaderHelper.compileShader("Shaders/Simple_VS.glsl", "Shaders/Simple_FS.glsl", null, null, null,
                                                                   defines, includes, SHADER_TYPE.MATERIAL_SHADER, ref Common.RenderState.shaderCompilationLog);


            //Attach UBO binding Points
            GLShaderHelper.attachUBOToShaderBindingPoint(shader, "_COMMON_PER_FRAME", 0);
            GLShaderHelper.attachSSBOToShaderBindingPoint(shader, "_COMMON_PER_MESH", 1);


            //Save shader to the resource Manager
            shaderDict[shader.shaderHash] = shader;
            meshList[shader.shaderHash]   = new List <GLMeshVao>(); //Init list
        }