コード例 #1
0
ファイル: Material.cs プロジェクト: polytronicgr/onyx3dsharp
        public void ApplyProperties()
        {
            foreach (KeyValuePair <string, MaterialProperty> mp in Properties)
            {
                switch (mp.Value.Type)
                {
                case MaterialPropertyType.SamplerCube:
                    CubemapMaterialProperty cmp = (CubemapMaterialProperty)mp.Value;
                    GL.ActiveTexture(TextureUnit.Texture0 + cmp.DataIndex);
                    GL.BindTexture(TextureTarget.TextureCubeMap, cmp.CubemapId);
                    GL.Uniform1(GL.GetUniformLocation(Shader.Program, mp.Key), cmp.DataIndex);
                    break;

                case MaterialPropertyType.Sampler2D:
                    TextureMaterialProperty tmp = (TextureMaterialProperty)mp.Value;
                    GL.ActiveTexture(TextureUnit.Texture0 + tmp.DataIndex);
                    Texture t = Onyx3DEngine.Instance.Resources.GetTexture(tmp.TextureGuid);
                    GL.BindTexture(TextureTarget.Texture2D, t.Id);
                    GL.Uniform1(GL.GetUniformLocation(Shader.Program, mp.Key), tmp.DataIndex);
                    break;

                case MaterialPropertyType.Float:
                    int loc = GL.GetUniformLocation(Shader.Program, mp.Key);
                    GL.Uniform1(loc, (float)mp.Value.Data);
                    break;

                case MaterialPropertyType.Vector2:
                    Vector2 v2 = (Vector2)mp.Value.Data;
                    GL.Uniform2(GL.GetUniformLocation(Shader.Program, mp.Key), v2);
                    break;

                case MaterialPropertyType.Vector3:
                    Vector3 v3 = (Vector3)mp.Value.Data;
                    GL.Uniform3(GL.GetUniformLocation(Shader.Program, mp.Key), v3);
                    break;

                case MaterialPropertyType.Vector4:
                case MaterialPropertyType.Color:
                    Vector4 v4 = (Vector4)mp.Value.Data;
                    GL.Uniform4(GL.GetUniformLocation(Shader.Program, mp.Key), v4);
                    break;
                }
            }
        }
コード例 #2
0
        public void ApplyProperties()
        {
            foreach (KeyValuePair <string, MaterialProperty> mp in Properties)
            {
                switch (mp.Value.Type)
                {
                case MaterialPropertyType.Sampler2D:
                    TextureMaterialProperty tmp = (TextureMaterialProperty)mp.Value;
                    GL.ActiveTexture(TextureUnit.Texture0 + tmp.DataIndex);
                    GL.BindTexture(TextureTarget.Texture2D, (int)mp.Value.Data);
                    GL.Uniform1(GL.GetUniformLocation(Shader.Program, mp.Key), tmp.DataIndex);
                    break;

                case MaterialPropertyType.Float:
                    int loc = GL.GetUniformLocation(Shader.Program, mp.Key);
                    GL.Uniform1(loc, (float)mp.Value.Data);
                    break;

                case MaterialPropertyType.Vector2:
                    Vector2 v2 = (Vector2)mp.Value.Data;
                    GL.Uniform2(GL.GetUniformLocation(Shader.Program, mp.Key), v2);
                    break;

                case MaterialPropertyType.Vector3:
                    Vector3 v3 = (Vector3)mp.Value.Data;
                    GL.Uniform3(GL.GetUniformLocation(Shader.Program, mp.Key), v3);
                    break;

                case MaterialPropertyType.Vector4:
                case MaterialPropertyType.Color:
                    Vector4 v4 = (Vector4)mp.Value.Data;
                    GL.Uniform4(GL.GetUniformLocation(Shader.Program, mp.Key), v4);
                    break;
                }
            }
        }
コード例 #3
0
ファイル: Material.cs プロジェクト: polytronicgr/onyx3dsharp
        public void WriteXml(XmlWriter writer)
        {
            writer.WriteStartElement("Material");


            writer.WriteElementString("Shader", Shader.LinkedProjectAsset.Guid.ToString());

            foreach (KeyValuePair <string, MaterialProperty> prop in Properties)
            {
                writer.WriteStartElement("Property");
                writer.WriteAttributeString("id", prop.Key);
                switch (prop.Value.Type)
                {
                case MaterialPropertyType.Color:
                    writer.WriteAttributeString("type", "color");
                    writer.WriteAttributeString("value", XmlUtils.Vector4ToString((Vector4)prop.Value.Data));
                    break;

                case MaterialPropertyType.Vector4:
                    writer.WriteAttributeString("type", "float4");
                    writer.WriteAttributeString("value", XmlUtils.Vector4ToString((Vector4)prop.Value.Data));
                    break;

                case MaterialPropertyType.Vector3:
                    writer.WriteAttributeString("type", "float3");
                    writer.WriteAttributeString("value", XmlUtils.Vector3ToString((Vector3)prop.Value.Data));
                    break;

                case MaterialPropertyType.Vector2:
                    writer.WriteAttributeString("type", "float2");
                    writer.WriteAttributeString("value", XmlUtils.Vector2ToString((Vector2)prop.Value.Data));
                    break;

                case MaterialPropertyType.Float:
                    writer.WriteAttributeString("type", "float");
                    writer.WriteAttributeString("value", ((float)prop.Value.Data).ToString());
                    break;

                case MaterialPropertyType.Sampler2D:
                    writer.WriteAttributeString("type", "sampler2d");
                    TextureMaterialProperty textureProp = (TextureMaterialProperty)prop.Value;
                    writer.WriteAttributeString("value", textureProp.TextureGuid.ToString());
                    writer.WriteAttributeString("index", textureProp.DataIndex.ToString());
                    break;

                case MaterialPropertyType.SamplerCube:
                    writer.WriteAttributeString("type", "samplerCube");
                    CubemapMaterialProperty cubemapProp = (CubemapMaterialProperty)prop.Value;
                    writer.WriteAttributeString("value", cubemapProp.TextureGuid.ToString());
                    writer.WriteAttributeString("index", cubemapProp.DataIndex.ToString());
                    break;
                }


                writer.WriteEndElement();
            }



            writer.WriteEndElement();
        }