示例#1
0
        public void Draw(Matrix4 view, float z, Matrix4 viewportTransform)
        {
            var program = ShaderLibrary.PlanetOrbit;

            GL.UseProgram(program.ProgramId);
            this.vao.Bind();             //TODO(v0.8) set program and bind VAO outside
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.Uniform1(program.TextureSamplerId, 0);
            GL.BindTexture(TextureTarget.Texture2D, this.objectData.TextureId);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Linear);

            var mvp = this.objectData.LocalTransform * view;
            var textureTransform = this.objectData.TextureTransform;

            GL.UniformMatrix4(program.LocalTransformId, false, ref mvp);
            GL.Uniform1(program.ZId, z);
            GL.Uniform4(program.ColorId, this.objectData.Color);
            GL.Uniform1(program.MinRId, this.objectData.MinRadius);
            GL.Uniform1(program.MaxRId, this.objectData.MaxRadius);
            GL.UniformMatrix3(program.TextureTransformId, false, ref textureTransform);

            GL.DrawArrays(PrimitiveType.Triangles, vao.ObjectStart(this.objectIndex), vao.ObjectSize(this.objectIndex));
            ShaderLibrary.PrintGlErrors("Draw orbits");
        }
 public ContainerManipulator(ShaderLibrary lab)
 {
     this.lab = lab;
     this.activators.Add(new ManipulatorActivationFilter {
         clickCount = 1, button = MouseButton.RightMouse
     });
     menu.AddItem(EditorGUIUtility.TrTextContent("Debug"), false, Debug, null);
 }
示例#3
0
        public ExampleLayer()
        {
            //Create camera
            cameraController = new OrthographicCameraController(1280.0f / 720.0f);

            //Shader library
            shaderLibrary = new ShaderLibrary();

            // ----------
            //Square
            // ----------
            squareVertexArray = IVertexArray.Create();

            float[] squareVertices =
            {
                -0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
                0.5f,  -0.5f, 0.0f, 1.0f, 0.0f,
                0.5f,   0.5f, 0.0f, 1.0f, 1.0f,
                -0.5f,  0.5f, 0.0f, 0.0f, 1.0f
            };

            IVertexBuffer squareVertexBuffer = IVertexBuffer.Create(squareVertices, squareVertices.GetBytes());

            BufferLayout squareBufferLayout = new BufferLayout(new[]
            {
                new BufferElement("a_Position", ShaderDataType.Float3),
                new BufferElement("a_TexCoord", ShaderDataType.Float2)
            });

            squareVertexBuffer.SetLayout(squareBufferLayout);
            squareVertexArray.AddVertexBuffer(squareVertexBuffer);

            uint[]       squareIndices     = { 0, 1, 2, 2, 3, 0 };
            IIndexBuffer squareIndexBuffer =
                IIndexBuffer.Create(squareIndices, squareIndices.GetBytes() / sizeof(uint));

            squareVertexArray.SetIndexBuffer(squareIndexBuffer);

            //Square shader
            shaderLibrary.LoadAndAddShader("Shaders/Square.glsl");

            //Texture shader
            IShader textureShader = IShader.Create("Shaders/Texture.glsl");

            shaderLibrary.AddShader(textureShader);

            birdiTexture = I2DTexture.Create("Textures/Birdi.png");
            faceTexture  = I2DTexture.Create("Textures/Face.png");

            textureShader.Bind();
            textureShader.SetInt("u_Texture", 0);
        }
        public Renderer(ShaderLibrary shaderLibrary, int width, int height)
        {
            State         = new State();
            Scheduler     = new Scheduler();
            ShaderLibrary = shaderLibrary;

            CameraUniformBuffer   = new UniformBuffer <CameraData>(State, 0);
            SceneUniformBuffer    = new UniformBuffer <SceneData>(State, 1);
            MaterialUniformBuffer = new UniformBuffer <MaterialData>(State, 2);
            ToneMapUniformBuffer  = new UniformBuffer <ToneMapData>(State, 3);

            Quad = new Quad(State);

            Initialize(width, height);
        }
示例#5
0
 public void SetMaterial()
 {
     mGraphic = this.GetComponent <MaskableGraphic>();
     if (mGraphic != null)
     {
         if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
         {
             //Applying default material with UI Image Crop shader
             mGraphic.material = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/UIScreen"));
         }
     }
     else
     {
         Debug.LogError("Please attach component to a Graphical UI component");
     }
 }
示例#6
0
        protected override int Execute(string[] args)
        {
            ShaderLibrary sl = new ShaderLibrary();

            sl.Init();
            ShaderDbXml xmlob = new ShaderDbXml();

            foreach (ShaderSet shaderSet in sl.ShaderSets)
            {
                ShaderXml shaderXml = new ShaderXml(shaderSet.Name, shaderSet.UIName);
                foreach (ShaderSetParameter shaderSetParameter in shaderSet.Parameters)
                {
                    ShaderParamXml shaderParamXml = new ShaderParamXml();
                    shaderParamXml.DefaultValue = shaderSetParameter.DefaultValue != null?
                                                  shaderSetParameter.DefaultValue.ToString() : null;

                    shaderParamXml.Category    = shaderSetParameter.Category;
                    shaderParamXml.Description = shaderSetParameter.Description;
                    shaderParamXml.EditorHash  = shaderSetParameter.EditorHash;
                    shaderParamXml.MaxValue    = shaderSetParameter.MaxValue;
                    shaderParamXml.MinValue    = shaderSetParameter.MinValue;
                    shaderParamXml.StepValue   = shaderSetParameter.StepValue;
                    shaderParamXml.Name        = shaderSetParameter.Name;
                    shaderParamXml.Type        = shaderSetParameter.Type;
                    shaderXml.Params.Add(shaderParamXml);
                }
                xmlob.Shaders.Add(shaderXml);
            }
            XmlSerializer xs         = new XmlSerializer(typeof(ShaderDbXml));
            string        outputPath = Path.Combine(this.OverrideUserDataPath, "Shaders.xml");

            using (FileStream stream = File.Create(outputPath))
            {
                try
                {
                    xs.Serialize(stream, xmlob);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(0);
        }
        public Shader CreateShader(string name)
        {
            var shader = ShaderLibrary.Create(name);

            shader.Use(State);
            shader.BindUniformBuffer("CameraData", CameraUniformBuffer);
            shader.BindUniformBuffer("SceneData", SceneUniformBuffer);
            shader.BindUniformBuffer("MaterialData", MaterialUniformBuffer);
            shader.BindUniformBuffer("ToneMapData", ToneMapUniformBuffer);

            shader.SetUniform("uUseIBL", true);

            foreach (var samplerInfo in Sampler.All)
            {
                samplerInfo.Bind(shader);
            }

            return(shader);
        }
示例#8
0
        public void Draw(Matrix4 view, float z)
        {
            var program = ShaderLibrary.Sprite;

            GL.UseProgram(program.ProgramId);
            this.vao.Bind();             //TODO(v0.6) set program and bind VAO outside
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.Uniform1(program.TextureSamplerId, 0);

            var mvp = this.objectData.LocalTransform * view;

            GL.UniformMatrix4(program.LocalTransformId, false, ref mvp);
            GL.BindTexture(TextureTarget.Texture2D, this.objectData.TextureId);
            GL.Uniform1(program.ZId, z);
            GL.Uniform4(program.ColorId, this.objectData.Color);

            GL.DrawArrays(PrimitiveType.Triangles, vao.ObjectStart(this.objectIndex), vao.ObjectSize(this.objectIndex));
            ShaderLibrary.PrintGlErrors("Draw sprites");
        }
        public void Dispose()
        {
            ShaderLibrary.Dispose();

            foreach (var pass in Passes)
            {
                pass.Dispose();
            }

            Quad.Dispose();

            CameraUniformBuffer.Dispose();
            SceneUniformBuffer.Dispose();
            MaterialUniformBuffer.Dispose();
            ToneMapUniformBuffer.Dispose();

            ShadowMapFramebuffer.Dispose();
            ShadowMapTexture.Dispose();

            ShadowMapFilteredFramebuffer.Dispose();
            ShadowMapFilteredTexture.Dispose();

            SSSDepthTexture.Dispose();
            SSSHighFramebuffer.Dispose();
            SSSHighTexture.Dispose();
            SSSMiddleFramebuffer.Dispose();
            SSSMiddleTexture.Dispose();
            SSSLowFramebuffer.Dispose();
            SSSLowTexture.Dispose();
            SSSLowFilteredFramebuffer.Dispose();
            SSSLowFilteredTexture.Dispose();

            SceneFramebuffer.Dispose();
            SceneColorTexture.Dispose();
            SceneDepthTexture.Dispose();

            ToneMapFramebuffer.Dispose();
            ToneMapColorTexture.Dispose();
        }
示例#10
0
        // Use this for initialization
        void Start()
        {
            if (MaskArea == null)
            {
                MaskArea = GetComponent <RectTransform>();
            }

            var text = GetComponent <Text>();

            if (text != null)
            {
                mat                   = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/SoftMaskShader"));
                text.material         = mat;
                cachedCanvas          = text.canvas;
                cachedCanvasTransform = cachedCanvas.transform;
                // For some reason, having the mask control on the parent and disabled stops the mouse interacting
                // with the texture layer that is not visible.. Not needed for the Image.
                if (transform.parent.GetComponent <Mask>() == null)
                {
                    transform.parent.gameObject.AddComponent <Mask>();
                }

                transform.parent.GetComponent <Mask>().enabled = false;
                return;
            }

            var graphic = GetComponent <Graphic>();

            if (graphic != null)
            {
                mat = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/SoftMaskShader"));
                graphic.material      = mat;
                cachedCanvas          = graphic.canvas;
                cachedCanvasTransform = cachedCanvas.transform;
            }
        }
示例#11
0
 public Shader(ShaderLibrary shaderLibrary, string shaderName)
     : base(shaderLibrary.GraphicsDevice)
 {
     PlatformConstruct(shaderLibrary, shaderName);
 }
示例#12
0
        protected bool Initialize()
        {
            // initialize members
            if (_transform == null)
            {
                _transform = transform;
            }
            if (pSystem == null)
            {
                pSystem = GetComponent <ParticleSystem>();

                if (pSystem == null)
                {
                    return(false);
                }

#if UNITY_5_5_OR_NEWER
                mainModule = pSystem.main;
                if (pSystem.main.maxParticles > 14000)
                {
                    mainModule.maxParticles = 14000;
                }
#else
                if (pSystem.maxParticles > 14000)
                {
                    pSystem.maxParticles = 14000;
                }
#endif

                pRenderer = pSystem.GetComponent <ParticleSystemRenderer>();
                if (pRenderer != null)
                {
                    pRenderer.enabled = false;
                }

                if (material == null)
                {
                    var foundShader = ShaderLibrary.GetShaderInstance("UI Extensions/Particles/Additive");
                    if (foundShader)
                    {
                        material = new Material(foundShader);
                    }
                }

                currentMaterial = material;
                if (currentMaterial && currentMaterial.HasProperty("_MainTex"))
                {
                    currentTexture = currentMaterial.mainTexture;
                    if (currentTexture == null)
                    {
                        currentTexture = Texture2D.whiteTexture;
                    }
                }
                material = currentMaterial;
                // automatically set scaling
#if UNITY_5_5_OR_NEWER
                mainModule.scalingMode = ParticleSystemScalingMode.Hierarchy;
#else
                pSystem.scalingMode = ParticleSystemScalingMode.Hierarchy;
#endif

                particles = null;
            }
#if UNITY_5_5_OR_NEWER
            if (particles == null)
            {
                particles = new ParticleSystem.Particle[pSystem.main.maxParticles];
            }
#else
            if (particles == null)
            {
                particles = new ParticleSystem.Particle[pSystem.maxParticles];
            }
#endif

            imageUV = new Vector4(0, 0, 1, 1);

            // prepare texture sheet animation
            textureSheetAnimation          = pSystem.textureSheetAnimation;
            textureSheetAnimationFrames    = 0;
            textureSheetAnimationFrameSize = Vector2.zero;
            if (textureSheetAnimation.enabled)
            {
                textureSheetAnimationFrames    = textureSheetAnimation.numTilesX * textureSheetAnimation.numTilesY;
                textureSheetAnimationFrameSize = new Vector2(1f / textureSheetAnimation.numTilesX, 1f / textureSheetAnimation.numTilesY);
            }

            return(true);
        }