Example #1
0
        private static common_newparam_type MakeNewParamForEffect(ulong id_num, bool isSampler2D)
        {
            common_newparam_type newparam = new common_newparam_type();

            if (isSampler2D)
            {
                fx_sampler2D_common sampler2D = new fx_sampler2D_common();
                sampler2D.source         = "surface_" + id_num;
                newparam.Item            = sampler2D;
                newparam.ItemElementName = ItemChoiceType.sampler2D;
                newparam.sid             = "sampler2D_" + id_num;
            }
            else
            {
                fx_surface_init_from_common initFrom = new fx_surface_init_from_common();
                fx_surface_common           surface  = new fx_surface_common();
                initFrom.Value    = "image_" + id_num;
                surface.type      = fx_surface_type_enum.Item2D;
                surface.init_from = new fx_surface_init_from_common[] {
                    initFrom
                };
                newparam.Item            = surface;
                newparam.ItemElementName = ItemChoiceType.surface;
                newparam.sid             = "surface_" + id_num;
            }
            return(newparam);
        }
Example #2
0
        internal DAEEffect(effect efx)
        {
            foreach (effectFx_profile_abstractProfile_COMMON profile in efx.Items)
            {
                if (profile.Items != null)
                {
                    foreach (var item in profile.Items)
                    {
                        if (item is common_newparam_type)
                        {
                            common_newparam_type newparam = item as common_newparam_type;
                            if (newparam.Item is fx_surface_common)
                            {
                                foreach (fx_surface_init_from_common initFrom in (newparam.Item as fx_surface_common).init_from)
                                {
                                    _imageId = initFrom.Value;
                                    break;
                                }
                            }
                        }
                    }
                }

                effectFx_profile_abstractProfile_COMMONTechnique technique = profile.technique;

                DAEVector4     transpColor  = new DAEVector4(1, 1, 1, 1);
                double         transparency = 1;
                fx_opaque_enum opaqueMode   = fx_opaque_enum.RGB_ZERO;

                if (technique.Item is effectFx_profile_abstractProfile_COMMONTechniquePhong) // phong
                {
                    effectFx_profile_abstractProfile_COMMONTechniquePhong p = technique.Item as effectFx_profile_abstractProfile_COMMONTechniquePhong;
                    if (p.transparent != null)
                    {
                        if (p.transparency != null)
                        {
                            if (p.transparency.Item is common_float_or_param_typeFloat)
                            {
                                opaqueMode   = p.transparent.opaque;
                                transpColor  = GetRgbaColor(p.transparent.Item);
                                transparency = (p.transparency.Item as common_float_or_param_typeFloat).Value;
                            }
                        }
                    }

                    if (p.ambient != null)
                    {
                        _ambient = GetColor(opaqueMode, GetRgbaColor(p.ambient.Item), transpColor, transparency);
                    }

                    if (p.diffuse != null)
                    {
                        _diffuse = GetColor(opaqueMode, GetRgbaColor(p.diffuse.Item), transpColor, transparency);
                    }

                    if (p.specular != null)
                    {
                        _specular = GetColor(opaqueMode, GetRgbaColor(p.specular.Item), transpColor, transparency);
                    }

                    if (p.shininess != null && p.shininess.Item is common_float_or_param_typeFloat)
                    {
                        _shininess = (float)(p.shininess.Item as common_float_or_param_typeFloat).Value;
                    }
                }
                else if (technique.Item is effectFx_profile_abstractProfile_COMMONTechniqueBlinn) // blinn
                {
                    effectFx_profile_abstractProfile_COMMONTechniqueBlinn p = technique.Item as effectFx_profile_abstractProfile_COMMONTechniqueBlinn;
                    if (p.transparent != null)
                    {
                        if (p.transparency != null)
                        {
                            if (p.transparency.Item is common_float_or_param_typeFloat)
                            {
                                opaqueMode   = p.transparent.opaque;
                                transpColor  = GetRgbaColor(p.transparent.Item);
                                transparency = (p.transparency.Item as common_float_or_param_typeFloat).Value;
                            }
                        }
                    }

                    if (p.ambient != null)
                    {
                        _ambient = GetColor(opaqueMode, GetRgbaColor(p.ambient.Item), transpColor, transparency);
                    }

                    if (p.diffuse != null)
                    {
                        _diffuse = GetColor(opaqueMode, GetRgbaColor(p.diffuse.Item), transpColor, transparency);
                    }

                    if (p.specular != null)
                    {
                        _specular = GetColor(opaqueMode, GetRgbaColor(p.specular.Item), transpColor, transparency);
                    }

                    if (p.shininess != null && p.shininess.Item is common_float_or_param_typeFloat)
                    {
                        _shininess = (float)(p.shininess.Item as common_float_or_param_typeFloat).Value;
                    }
                }
                else if (technique.Item is effectFx_profile_abstractProfile_COMMONTechniqueLambert) // lambert
                {
                    effectFx_profile_abstractProfile_COMMONTechniqueLambert p = technique.Item as effectFx_profile_abstractProfile_COMMONTechniqueLambert;
                    if (p.transparent != null)
                    {
                        if (p.transparency != null)
                        {
                            if (p.transparency.Item is common_float_or_param_typeFloat)
                            {
                                opaqueMode   = p.transparent.opaque;
                                transpColor  = GetRgbaColor(p.transparent.Item);
                                transparency = (p.transparency.Item as common_float_or_param_typeFloat).Value;
                            }
                        }
                    }

                    if (p.ambient != null)
                    {
                        _ambient = GetColor(opaqueMode, GetRgbaColor(p.ambient.Item), transpColor, transparency);
                    }

                    if (p.diffuse != null)
                    {
                        _diffuse = GetColor(opaqueMode, GetRgbaColor(p.diffuse.Item), transpColor, transparency);
                    }

                    _specular = new DAEVector4(0.0f, 0.0f, 0.0f, 0.0f);
                }
                else if (technique.Item is effectFx_profile_abstractProfile_COMMONTechniqueConstant) // constant
                {
                    effectFx_profile_abstractProfile_COMMONTechniqueConstant p = technique.Item as effectFx_profile_abstractProfile_COMMONTechniqueConstant;
                    if (p.transparent != null)
                    {
                        if (p.transparency != null)
                        {
                            if (p.transparency.Item is common_float_or_param_typeFloat)
                            {
                                opaqueMode   = p.transparent.opaque;
                                transpColor  = GetRgbaColor(p.transparent.Item);
                                transparency = (p.transparency.Item as common_float_or_param_typeFloat).Value;
                            }
                        }
                    }

                    if (p.emission != null)
                    {
                        _ambient   = GetColor(opaqueMode, GetRgbaColor(p.emission.Item), transpColor, transparency);
                        _diffuse   = GetColor(opaqueMode, GetRgbaColor(p.emission.Item), transpColor, transparency);
                        _specular  = GetColor(opaqueMode, GetRgbaColor(p.emission.Item), transpColor, transparency);
                        _shininess = 0;
                    }
                }

                _isTransparent = _diffuse.W < 1.0;
            }
        }