示例#1
0
        public virtual void DrawAsLight()
        {
            if (Mat != null && Mat.Shader != null)
            {
                IGLProgram shader = Mat.Shader;

                shader.Use();

                Matrix4 proj = Projection;
                Matrix4 view = View;
                Matrix4 m    = Model;
                Matrix4 norm = Matrix4.Invert(m);
                norm.Transpose();

                shader.SetUniformMatrix4("projectionMatrix", ref proj);
                shader.SetUniformMatrix4("viewMatrix", ref view);
                shader.SetUniformMatrix4("modelMatrix", ref m);
                shader.SetUniformMatrix4("normalMatrix", ref norm);

                Vector2 tiling = Tiling;

                Vector4 lightColor = new Vector4(LightColor * LightPower, 1);

                shader.SetUniform2("tiling", ref tiling);

                shader.SetUniform4F("color", ref lightColor);

                ///draw
                vao.Bind();
                IGL.Primary.DrawElements((int)BeginMode.Triangles, indicesCount, (int)DrawElementsType.UnsignedInt, 0);
                GLVertexArray.Unbind();
            }
        }
示例#2
0
        public static IGLProgram GetShader(string vertFile, string fragFile)
        {
            string path       = AppDomain.CurrentDomain.BaseDirectory;
            string vertexPath = Path.Combine(path, "Shaders", "Vertex", vertFile);
            string fragPath   = Path.Combine(path, "Shaders", "Frag", fragFile);

            IGLProgram shader = null;

            if (Shaders.TryGetValue(vertexPath + fragPath, out shader))
            {
                return(shader);
            }

            if (!File.Exists(vertexPath))
            {
                return(null);
            }
            if (!File.Exists(fragPath))
            {
                return(null);
            }

            string vertexData = File.ReadAllText(vertexPath);
            string fragdata   = File.ReadAllText(fragPath);

            GLFragmentShader frag = new GLFragmentShader(fragdata);
            string           log  = null;

            if (!frag.Compile(out log))
            {
                frag.Release();
                Log.Error(log);
                return(null);
            }

            GLVertexShader vert = new GLVertexShader(vertexData);

            if (!vert.Compile(out log))
            {
                vert.Release();
                Log.Error(log);
                return(null);
            }

            shader = new GLShaderProgram(true);
            shader.AttachShader(vert);
            shader.AttachShader(frag);

            if (!shader.Link(out log))
            {
                shader.Release();
                Log.Error(log);
                return(null);
            }

            Shaders[vertexPath + fragPath] = shader;

            return(shader);
        }
示例#3
0
 public BloomPass(int w, int h)
 {
     Intensity = 8;
     width     = w;
     height    = h;
     quad      = new FullScreenQuad();
     blur      = new BlurProcessor();
     shader    = Material.Material.GetShader("image.glsl", "bloom.glsl");
 }
示例#4
0
 public UVRenderer(MeshRenderer mesh)
 {
     if (mesh != null)
     {
         renderer     = mesh;
         indicesCount = mesh.IndicesCount;
         shader       = Material.Material.GetShader("uv.glsl", "uv.glsl");
     }
 }
示例#5
0
        public static IGLProgram CompileFragWithVert(string vertFile, string fragData)
        {
            string path       = AppDomain.CurrentDomain.BaseDirectory;
            string vertexPath = Path.Combine(path, "Shaders", "Vertex", vertFile);

            IGLProgram shader = null;

            if (!File.Exists(vertexPath))
            {
                return(null);
            }

            string vertexData = File.ReadAllText(vertexPath);

            GLFragmentShader frag = new GLFragmentShader(fragData);
            string           log  = null;

            if (!frag.Compile(out log))
            {
                frag.Release();
                Log.Error(log);
                Log.Debug(Environment.StackTrace);
                Log.Debug("Shader failure for: " + vertFile);
                return(null);
            }

            GLVertexShader vert = new GLVertexShader(vertexData);

            if (!vert.Compile(out log))
            {
                vert.Release();
                Log.Error(log);
                Log.Debug(Environment.StackTrace);
                Log.Debug("Shader failure for: " + vertFile);
                return(null);
            }

            shader = new GLShaderProgram(true);
            shader.AttachShader(vert);
            shader.AttachShader(frag);

            if (!shader.Link(out log))
            {
                shader.Release();
                Log.Error(log);
                Log.Debug(Environment.StackTrace);
                Log.Debug("Shader failure for: " + vertFile);
                return(null);
            }

            return(shader);
        }
示例#6
0
        void BuildShader()
        {
            if (shader == null || preshader == null || rebuild)
            {
                if (shader != null)
                {
                    shader.Release();
                    shader = null;
                }

                if (preshader != null)
                {
                    preshader.Release();
                    preshader = null;
                }

                string rawFrag = Material.Material.GetRawFrag("distance.glsl");

                if (string.IsNullOrEmpty(rawFrag))
                {
                    return;
                }

                string outputType = "rgba32f";
                rawFrag = rawFrag.Replace("{0}", outputType);

                shader = Material.Material.CompileCompute(rawFrag);

                if (shader == null)
                {
                    return;
                }

                rawFrag = Material.Material.GetRawFrag("distanceprecalc.glsl");

                if (string.IsNullOrEmpty(rawFrag))
                {
                    return;
                }
                rawFrag   = rawFrag.Replace("{0}", outputType);
                preshader = Material.Material.CompileCompute(rawFrag);

                if (preshader == null)
                {
                    return;
                }

                rebuild = false;
            }
        }
示例#7
0
        public override void Dispose()
        {
            base.Dispose();

            if (processor != null)
            {
                processor.Release();
                processor = null;
            }

            if (shader != null)
            {
                shader.Release();
                shader = null;
            }

            if (preshader != null)
            {
                preshader.Release();
                preshader = null;
            }
        }
示例#8
0
 public NormalsProcessor() : base()
 {
     shader = GetShader("image.glsl", "normals.glsl");
 }
示例#9
0
 public GradientMapProcessor()
 {
     Horizontal = true;
     shader     = GetShader("image.glsl", "gradientmap.glsl");
     UseMask    = false;
 }
 public DirectionalWarpProcessor() : base()
 {
     shader    = GetShader("image.glsl", "warpdirectional.glsl");
     Intensity = 1;
 }
示例#11
0
        public static IGLProgram GetShader(string vertFile, string tcsFile, string tesFile, string fragFile)
        {
            string path       = AppDomain.CurrentDomain.BaseDirectory;
            string vertexPath = Path.Combine(path, "Shaders", "Vertex", vertFile);
            string fragPath   = Path.Combine(path, "Shaders", "Frag", fragFile);
            string tcsPath    = Path.Combine(path, "Shaders", "Tess", tcsFile);
            string tesPath    = Path.Combine(path, "Shaders", "Tess", tesFile);

            IGLProgram shader = null;

            if (Shaders.TryGetValue(vertexPath + tcsPath + tesPath + fragPath, out shader))
            {
                return(shader);
            }

            if (!File.Exists(vertexPath))
            {
                return(null);
            }
            if (!File.Exists(tcsPath))
            {
                return(null);
            }
            if (!File.Exists(tesPath))
            {
                return(null);
            }
            if (!File.Exists(fragPath))
            {
                return(null);
            }

            string vertexData = File.ReadAllText(vertexPath);
            string fragData   = File.ReadAllText(fragPath);
            string tcsData    = File.ReadAllText(tcsPath);
            string tesData    = File.ReadAllText(tesPath);

            GLFragmentShader frag = new GLFragmentShader(fragData);
            string           log  = null;

            if (!frag.Compile(out log))
            {
                frag.Release();
                Log.Error(log);
                Log.Debug(Environment.StackTrace);
                Log.Debug("Shader failure for: " + vertFile + " | " + tcsFile + " | " + tesFile + " | " + fragFile);
                return(null);
            }

            GLVertexShader vert = new GLVertexShader(vertexData);

            if (!vert.Compile(out log))
            {
                vert.Release();
                Log.Error(log);
                Log.Debug(Environment.StackTrace);
                Log.Debug("Shader failure for: " + vertFile + " | " + tcsFile + " | " + tesFile + " | " + fragFile);
                return(null);
            }

            GLTcsShader tcs = new GLTcsShader(tcsData);

            if (!tcs.Compile(out log))
            {
                tcs.Release();
                Log.Error(log);
                Log.Debug(Environment.StackTrace);
                Log.Debug("Shader failure for: " + vertFile + " | " + tcsFile + " | " + tesFile + " | " + fragFile);
                return(null);
            }

            GLTesShader tes = new GLTesShader(tesData);

            if (!tes.Compile(out log))
            {
                tes.Release();
                Log.Error(log);
                Log.Debug(Environment.StackTrace);
                Log.Debug("Shader failure for: " + vertFile + " | " + tcsFile + " | " + tesFile + " | " + fragFile);
                return(null);
            }

            shader = new GLShaderProgram(true);
            shader.AttachShader(vert);
            shader.AttachShader(tcs);
            shader.AttachShader(tes);
            shader.AttachShader(frag);

            if (!shader.Link(out log))
            {
                shader.Release();
                Log.Error(log);
            }

            Shaders[vertexPath + tcsPath + tesPath + fragPath] = shader;
            return(shader);
        }
示例#12
0
 public InvertProcessor() : base()
 {
     shader = GetShader("image.glsl", "invert.glsl");
 }
示例#13
0
 public GammaProcessor()
 {
     Gamma  = 1;
     shader = GetShader("image.glsl", "gamma.glsl");
 }
示例#14
0
 public LevelsProcessor() : base()
 {
     shader = GetShader("image.glsl", "levels.glsl");
 }
示例#15
0
 public MeshDepthProcessor() : base()
 {
     shader = GetShader("image.glsl", "image-basic.glsl");
 }
示例#16
0
 public PreviewProcessor()
 {
     FlipY      = false;
     Luminosity = 1.0f;
     shader     = Material.Material.GetShader("preview.glsl", "preview.glsl");
 }
示例#17
0
 public SharpenProcessor()
 {
     shader = GetShader("image.glsl", "sharpen.glsl");
 }
示例#18
0
 public BlurProcessor() : base()
 {
     shader = GetShader("image.glsl", "blur.glsl");
 }
示例#19
0
 public GrayscaleConvProcessor() : base()
 {
     shader = GetShader("image.glsl", "grayscaleconv.glsl");
 }
示例#20
0
 public FXProcessor() : base()
 {
     Blending = FXBlend.Blend;
     shader   = GetShader("image.glsl", "fx.glsl");
 }
示例#21
0
 public MotionBlurProcessor() : base()
 {
     shader = GetShader("image.glsl", "motionblur.glsl");
 }
示例#22
0
 public BasicImageRenderer() : base()
 {
     shader = GetShader("image.glsl", "image-basic.glsl");
 }
示例#23
0
 public OcclusionProcessor() : base()
 {
     shader = GetShader("image.glsl", "occlusion.glsl");
 }
示例#24
0
 public ChannelSwitchProcessor() : base()
 {
     shader = GetShader("image.glsl", "channelswitch.glsl");
 }
示例#25
0
 public WarpProcessor() : base()
 {
     shader    = GetShader("image.glsl", "warp.glsl");
     Intensity = 1;
 }
示例#26
0
        public virtual void DrawFull()
        {
            if (Mat != null && Mat.Shader != null)
            {
                IGLProgram shader = Mat.Shader;

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture0);
                if (Mat.Albedo != null)
                {
                    Mat.Albedo.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture1);
                if (Mat.Metallic != null)
                {
                    Mat.Metallic.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture2);
                if (Mat.Roughness != null)
                {
                    Mat.Roughness.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture3);
                if (Mat.Occlusion != null)
                {
                    Mat.Occlusion.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture4);
                if (Mat.Normal != null)
                {
                    Mat.Normal.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture5);
                if (Mat.Height != null)
                {
                    Mat.Height.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture6);
                PBRMaterial.BRDFLut.Bind();

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture7);
                if (IrradianceMap != null)
                {
                    IrradianceMap.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture8);
                if (PrefilterMap != null)
                {
                    PrefilterMap.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture9);
                if (Mat.Thickness != null)
                {
                    Mat.Thickness.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture10);
                if (Mat.Emission != null)
                {
                    Mat.Emission.Bind();
                }

                //use shader
                shader.Use();

                //set texture bind points
                shader.SetUniform("albedo", 0);
                shader.SetUniform("metallicMap", 1);
                shader.SetUniform("roughnessMap", 2);
                shader.SetUniform("occlusionMap", 3);
                shader.SetUniform("normalMap", 4);
                shader.SetUniform("heightMap", 5);
                shader.SetUniform("brdfLUT", 6);
                shader.SetUniform("irradianceMap", 7);
                shader.SetUniform("prefilterMap", 8);
                shader.SetUniform("thicknessMap", 9);
                shader.SetUniform("emissionMap", 10);

                Vector3 lpos = LightPosition;
                Vector3 lc   = LightColor;

                Vector3 cam = CameraPosition;

                //set camera and light stuff
                shader.SetUniform3("cameraPosition", ref cam);
                shader.SetUniform3("lightPosition", ref lpos);
                shader.SetUniform3("lightColor", ref lc);
                shader.SetUniform("lightPower", LightPower);

                //setup MVP and N matrices
                Matrix4 proj = Projection;
                Matrix4 view = View;
                Matrix4 m    = Model;
                Matrix4 norm = Matrix4.Invert(m);
                norm.Transpose();

                shader.SetUniformMatrix4("projectionMatrix", ref proj);
                shader.SetUniformMatrix4("viewMatrix", ref view);
                shader.SetUniformMatrix4("modelMatrix", ref m);
                shader.SetUniformMatrix4("normalMatrix", ref norm);

                shader.SetUniform("far", Far);
                shader.SetUniform("near", Near);

                shader.SetUniform("heightScale", Mat.HeightScale);
                shader.SetUniform("refraction", Mat.IOR);

                ///SSS Related
                shader.SetUniform("SSS_Distortion", Mat.SSSDistortion);
                shader.SetUniform("SSS_Ambient", Mat.SSSAmbient);
                shader.SetUniform("SSS_Power", Mat.SSSPower);

                if (Mat.ClipHeight)
                {
                    shader.SetUniform("occlusionClipBias", Mat.ClipHeightBias);
                }
                else
                {
                    shader.SetUniform("occlusionClipBias", -1.0f);
                }

                shader.SetUniform("displace", Mat.UseDisplacement);

                Vector2 tiling = Tiling;

                shader.SetUniform2("tiling", ref tiling);

                ///draw
                vao.Bind();

                if (Mat.UseDisplacement)
                {
                    IGL.Primary.DrawElements((int)BeginMode.Patches, indicesCount, (int)DrawElementsType.UnsignedInt, 0);
                }
                else
                {
                    IGL.Primary.DrawElements((int)BeginMode.Triangles, indicesCount, (int)DrawElementsType.UnsignedInt, 0);
                }

                GLVertexArray.Unbind();
                GLTextuer2D.Unbind();
            }
        }
示例#27
0
 public TransformProcessor() : base()
 {
     Stretch = false;
     shader  = GetShader("image.glsl", "transform.glsl");
 }
示例#28
0
 public EmbossProcessor() : base()
 {
     shader = GetShader("image.glsl", "emboss.glsl");
 }
示例#29
0
 public UniformColorProcessor() : base()
 {
     shader = GetShader("image.glsl", "uniformcolor.glsl");
 }
示例#30
0
 public DistanceProcessor() : base()
 {
     shader = GetShader("image.glsl", "distance.glsl");
 }