예제 #1
0
        private ShaderEffect MakeMaterial(MaterialComponent mc)
        {
            WeightComponent   wc  = CurrentNode.GetWeights();
            ShaderCodeBuilder scb = new ShaderCodeBuilder(mc, null, wc); // TODO, CurrentNode.GetWeights() != null);
            var effectParameters  = AssembleEffectParamers(mc, scb);

            ShaderEffect ret = new ShaderEffect(new []
            {
                new EffectPassDeclaration()
                {
                    VS = scb.VS,
                    //VS = VsBones,
                    PS       = scb.PS,
                    StateSet = new RenderStateSet()
                    {
                        ZEnable          = true,
                        AlphaBlendEnable = false
                    }
                }
            },
                                                effectParameters
                                                );

            return(ret);
        }
예제 #2
0
        private ShaderEffectProtoPixel LookupMaterial(FusMaterial m)
        {
            if (_matMap.TryGetValue(m, out var sfx))
            {
                return(sfx);
            }

            var vals = new MaterialValues();

            if (m.HasNormalMap)
            {
                vals.NormalMap          = m.NormalMap.Texture ?? null;
                vals.NormalMapIntensity = m.HasNormalMap ? m.NormalMap.Intensity : 0;
            }
            if (m.HasAlbedo)
            {
                vals.AlbedoColor   = m.Albedo.Color;
                vals.AlbedoMix     = m.Albedo.Mix;
                vals.AlbedoTexture = m.Albedo.Texture ?? null;
            }
            if (m.HasEmissive)
            {
                vals.EmissiveColor   = m.Emissive.Color;
                vals.EmissiveMix     = m.Emissive.Mix;
                vals.EmissiveTexture = m.Emissive.Texture ?? null;
            }

            if (m.HasSpecular)
            {
                vals.SpecularColor     = m.Specular.Color;
                vals.SpecularMix       = m.Specular.Mix;
                vals.SpecularTexture   = m.Specular.Texture ?? null;
                vals.SpecularIntensity = m.Specular.Intensity;
                vals.SpecularShininess = m.Specular.Shininess;
            }

            sfx = ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(
                new ShaderEffectProps
            {
                MatProbs =
                {
                    HasAlbedo          = m.HasAlbedo,
                    HasAlbedoTexture   = m.HasAlbedo && m.Albedo.Texture != null,
                    HasSpecular        = m.HasSpecular,
                    HasSpecularTexture = m.HasSpecular && m.Specular.Texture != null,
                    HasEmissive        = m.HasEmissive,
                    HasEmissiveTexture = m.HasEmissive && m.Emissive.Texture != null,
                    HasNormalMap       = m.HasNormalMap
                },
                MatType   = MaterialType.Standard,
                MatValues = vals
            });

            sfx.Name = m.Name ?? "";

            _matMap.Add(m, sfx);
            return(sfx);
        }
예제 #3
0
        private ShaderEffect LookupMaterial(MaterialPBRComponent mc)
        {
            if (_pbrComponent.TryGetValue(mc, out var mat))
            {
                return(mat);
            }

            mat = ShaderCodeBuilder.MakeShaderEffectFromMatComp(mc, _currentNode.GetWeights());
            _pbrComponent.Add(mc, mat);
            return(mat);
        }
예제 #4
0
        private List <EffectParameterDeclaration> AssembleEffectParamers(MaterialComponent mc, ShaderCodeBuilder scb)
        {
            List <EffectParameterDeclaration> effectParameters = new List <EffectParameterDeclaration>();

            if (mc.HasDiffuse)
            {
                effectParameters.Add(new EffectParameterDeclaration
                {
                    Name  = scb.DiffuseColorName,
                    Value = (object)mc.Diffuse.Color
                });
                if (mc.Diffuse.Texture != null)
                {
                    effectParameters.Add(new EffectParameterDeclaration
                    {
                        Name  = scb.DiffuseMixName,
                        Value = mc.Diffuse.Mix
                    });
                    effectParameters.Add(new EffectParameterDeclaration
                    {
                        Name  = scb.DiffuseTextureName,
                        Value = LoadTexture(mc.Diffuse.Texture)
                    });
                }
            }

            if (mc.HasSpecular)
            {
                effectParameters.Add(new EffectParameterDeclaration
                {
                    Name  = scb.SpecularColorName,
                    Value = (object)mc.Specular.Color
                });
                effectParameters.Add(new EffectParameterDeclaration
                {
                    Name  = scb.SpecularShininessName,
                    Value = (object)mc.Specular.Shininess
                });
                effectParameters.Add(new EffectParameterDeclaration
                {
                    Name  = scb.SpecularIntensityName,
                    Value = (object)mc.Specular.Intensity
                });
                if (mc.Specular.Texture != null)
                {
                    effectParameters.Add(new EffectParameterDeclaration
                    {
                        Name  = scb.SpecularMixName,
                        Value = mc.Specular.Mix
                    });
                    effectParameters.Add(new EffectParameterDeclaration
                    {
                        Name  = scb.SpecularTextureName,
                        Value = LoadTexture(mc.Specular.Texture)
                    });
                }
            }

            if (mc.HasEmissive)
            {
                effectParameters.Add(new EffectParameterDeclaration
                {
                    Name  = scb.EmissiveColorName,
                    Value = (object)mc.Emissive.Color
                });
                if (mc.Emissive.Texture != null)
                {
                    effectParameters.Add(new EffectParameterDeclaration
                    {
                        Name  = scb.EmissiveMixName,
                        Value = mc.Emissive.Mix
                    });
                    effectParameters.Add(new EffectParameterDeclaration
                    {
                        Name  = scb.EmissiveTextureName,
                        Value = LoadTexture(mc.Emissive.Texture)
                    });
                }
            }

            if (mc.HasBump)
            {
                effectParameters.Add(new EffectParameterDeclaration
                {
                    Name  = scb.BumpIntensityName,
                    Value = mc.Bump.Intensity
                });
                effectParameters.Add(new EffectParameterDeclaration
                {
                    Name  = scb.BumpTextureName,
                    Value = LoadTexture(mc.Bump.Texture)
                });
            }

            // Any light calculation needed at all?
            if (mc.HasDiffuse || mc.HasSpecular)
            {
                // Light calculation parameters
                effectParameters.Add(new EffectParameterDeclaration
                {
                    Name  = ShaderCodeBuilder.LightColorName,
                    Value = new float3(1, 1, 1)
                });
                effectParameters.Add(new EffectParameterDeclaration
                {
                    Name  = ShaderCodeBuilder.LightIntensityName,
                    Value = (float)1
                });
                effectParameters.Add(new EffectParameterDeclaration
                {
                    Name  = ShaderCodeBuilder.LightDirectionName,
                    Value = new float3(0, 0, 1)
                });
            }

            return(effectParameters);
        }