Exemplo n.º 1
0
 public void FrontXmlShader(string name, ICyclesMaterial crm)
 {
     _front = new ShaderBody(Id)
     {
         Name = name,
         Crm  = crm,
         CyclesMaterialType = ShaderBody.CyclesMaterial.Xml
     };
 }
Exemplo n.º 2
0
        internal CclShader CreateCyclesShaderFromXml(ShaderBody shader)
        {
            var sh = new CclShader(Client, CclShader.ShaderType.Material)
            {
                UseMis = true,
                UseTransparentShadow = true,
                HeterogeneousVolume  = false,
                Name = shader.Name ?? $"V6 Basic Material {shader.Id}"
            };

            CclShader.ShaderFromXml(ref sh, shader.Crm.MaterialXml);

            return(sh);
        }
Exemplo n.º 3
0
 internal CclShader RecreateCyclesShaderFromXml(ShaderBody shader, CclShader existing)
 {
     existing.Recreate();
     CclShader.ShaderFromXml(ref existing, shader.Crm.MaterialXml);
     return(existing);
 }
Exemplo n.º 4
0
 public bool CreateBackShader(RenderMaterial rm, float gamma)
 {
     _back = new ShaderBody(Id);
     return(CreateShaderPart(_back, rm, gamma));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Sets up a shader with Front set to a default ShaderBody. Used for CodeShader
 /// </summary>
 public void SetupShaderShim()
 {
     _front = new ShaderBody(Id);
 }
Exemplo n.º 6
0
 public bool CreateFrontShader(RenderMaterial rm, float gamma)
 {
     _front = new ShaderBody(Id);
     return(CreateShaderPart(_front, rm, gamma));
 }
Exemplo n.º 7
0
 public CyclesShader(uint id)
 {
     Id     = id;
     _front = null;
     _back  = null;
 }
Exemplo n.º 8
0
        private bool CreateShaderPart(ShaderBody shb, RenderMaterial rm, float gamma)
        {
            var crm = rm as ICyclesMaterial;

            ShaderBody.CyclesMaterial mattype = ShaderBody.CyclesMaterial.No;
            if (crm == null)
            {
                // always simulate material, need to know now myself
                // what to read out from the simulated material to
                // populate my own material descriptions.
                var m = rm.SimulateMaterial(true);
                // figure out what type of material we are.
                //var probemat = GuessMaterialFromSmell(rm);
                var probemat = WhatMaterial(rm, m);

                rm.BeginChange(RenderContent.ChangeContexts.Ignore);
                var dcl          = m.DiffuseColor;
                var scl          = m.SpecularColor;
                var rcl          = m.ReflectionColor;
                var rfcl         = m.TransparentColor;
                var emcl         = m.EmissionColor;
                var polish       = (float)m.ReflectionGlossiness;
                var reflectivity = (float)m.Reflectivity;
                var metalic      = 0f;
                var shine        = (float)(m.Shine / Material.MaxShine);

                switch (probemat)
                {
                case ProbableMaterial.Plaster:
                    mattype = ShaderBody.CyclesMaterial.Diffuse;
                    break;

                case ProbableMaterial.Glass:
                case ProbableMaterial.Gem:
                    metalic = 0f;
                    mattype = ShaderBody.CyclesMaterial.Glass;
                    break;

                case ProbableMaterial.Metal:
                    metalic = 1.0f;
                    mattype = ShaderBody.CyclesMaterial.SimpleMetal;
                    break;

                case ProbableMaterial.Plastic:
                    //polish = reflectivity;
                    //shine = polish;
                    //reflectivity = 0f;
                    metalic = 0f;
                    mattype = ShaderBody.CyclesMaterial.SimplePlastic;
                    break;

                case ProbableMaterial.Paint:
                    mattype = ShaderBody.CyclesMaterial.Paint;
                    break;

                case ProbableMaterial.Custom:
                    mattype = ShaderBody.CyclesMaterial.No;
                    break;
                }

                var difftexAlpha = m.AlphaTransparency;

                var col    = RenderEngine.CreateFloat4(dcl.R, dcl.G, dcl.B, 255);
                var spec   = RenderEngine.CreateFloat4(scl.R, scl.G, scl.B, 255);
                var refl   = RenderEngine.CreateFloat4(rcl.R, rcl.G, rcl.B, 255);
                var transp = RenderEngine.CreateFloat4(rfcl.R, rfcl.G, rfcl.B, 255);
                var refr   = RenderEngine.CreateFloat4(rfcl.R, rfcl.G, rfcl.B, 255);
                var emis   = RenderEngine.CreateFloat4(emcl.R, emcl.G, emcl.B, 255);

                //shb.Type = CyclesShader.Shader.Diffuse,
                shb.CyclesMaterialType = mattype;

                shb.Shadeless = m.DisableLighting;

                shb.DiffuseColor        = col;
                shb.SpecularColor       = spec;
                shb.ReflectionColor     = refl;
                shb.ReflectionRoughness = (float)m.ReflectionGlossiness;                 // polish;
                shb.RefractionColor     = refr;
                shb.RefractionRoughness = (float)m.RefractionGlossiness;
                shb.TransparencyColor   = transp;
                shb.EmissionColor       = emis;


                shb.FresnelIOR   = (float)m.FresnelIndexOfRefraction;
                shb.IOR          = (float)m.IndexOfRefraction;
                shb.Roughness    = (float)m.ReflectionGlossiness;
                shb.Reflectivity = reflectivity;
                shb.Metalic      = metalic;
                shb.Transparency = (float)m.Transparency;
                shb.Shine        = shine;
                shb.Gloss        = (float)m.ReflectionGlossiness;

                shb.FresnelReflections = m.FresnelReflections;

                shb.Gamma = gamma;

                shb.Name = m.Name ?? "";

                shb.DiffuseTexture.Amount      = 0.0f;
                shb.BumpTexture.Amount         = 0.0f;
                shb.TransparencyTexture.Amount = 0.0f;
                shb.EnvironmentTexture.Amount  = 0.0f;

                if (rm.GetTextureOnFromUsage(RenderMaterial.StandardChildSlots.Diffuse))
                {
                    var difftex = rm.GetTextureFromUsage(RenderMaterial.StandardChildSlots.Diffuse);

                    BitmapConverter.MaterialBitmapFromEvaluator(ref shb, rm, difftex, RenderMaterial.StandardChildSlots.Diffuse);
                    if (shb.HasDiffuseTexture)
                    {
                        shb.DiffuseTexture.UseAlpha = difftexAlpha;
                        shb.DiffuseTexture.Amount   = (float)Math.Min(rm.GetTextureAmountFromUsage(RenderMaterial.StandardChildSlots.Diffuse) / 100.0f, 1.0f);
                    }
                }

                if (rm.GetTextureOnFromUsage(RenderMaterial.StandardChildSlots.Bump))
                {
                    var bumptex = rm.GetTextureFromUsage(RenderMaterial.StandardChildSlots.Bump);
                    BitmapConverter.MaterialBitmapFromEvaluator(ref shb, rm, bumptex, RenderMaterial.StandardChildSlots.Bump);
                    if (shb.HasBumpTexture)
                    {
                        shb.BumpTexture.Amount = (float)Math.Min(rm.GetTextureAmountFromUsage(RenderMaterial.StandardChildSlots.Bump) / 100.0f, 1.0f);
                    }
                }

                if (rm.GetTextureOnFromUsage(RenderMaterial.StandardChildSlots.Transparency))
                {
                    var transtex = rm.GetTextureFromUsage(RenderMaterial.StandardChildSlots.Transparency);
                    BitmapConverter.MaterialBitmapFromEvaluator(ref shb, rm, transtex,
                                                                RenderMaterial.StandardChildSlots.Transparency);
                    if (shb.HasTransparencyTexture)
                    {
                        shb.TransparencyTexture.Amount = (float)Math.Min(rm.GetTextureAmountFromUsage(RenderMaterial.StandardChildSlots.Transparency) / 100.0f, 1.0f);
                    }
                }

                if (rm.GetTextureOnFromUsage(RenderMaterial.StandardChildSlots.Environment))
                {
                    var envtex = rm.GetTextureFromUsage(RenderMaterial.StandardChildSlots.Environment);
                    BitmapConverter.MaterialBitmapFromEvaluator(ref shb, rm, envtex,
                                                                RenderMaterial.StandardChildSlots.Environment);
                    if (shb.HasEnvironmentTexture)
                    {
                        shb.EnvironmentTexture.Amount = (float)Math.Min(rm.GetTextureAmountFromUsage(RenderMaterial.StandardChildSlots.Environment) / 100.0f, 1.0f);
                    }
                }

                rm.EndChange();
            }
            else
            {
                crm.BakeParameters();
                shb.Crm = crm;
                shb.CyclesMaterialType = ShaderBody.CyclesMaterial.Xml;
                shb.Gamma = gamma;
                shb.Name  = rm.Name ?? "some cycles material";
            }
            return(true);
        }