/// <summary> /// Adds the properties. /// </summary> /// <param name="pbr">The PBR.</param> /// <param name="assimpMaterial">The assimp material.</param> protected virtual void AddProperties(PBRMaterialCore pbr, global::Assimp.Material assimpMaterial) { assimpMaterial.ShadingMode = ShadingMode.Fresnel; assimpMaterial.AddProperty(new MaterialProperty(AiMatKeys.COLOR_DIFFUSE_BASE, pbr.AlbedoColor.ToAssimpColor4D())); assimpMaterial.AddProperty(new MaterialProperty(GLTFMatKeys.AI_MATKEY_GLTF_BASECOLOR_FACTOR, pbr.AlbedoColor.ToAssimpColor4D())); assimpMaterial.AddProperty(new MaterialProperty(AiMatKeys.COLOR_EMISSIVE_BASE, pbr.EmissiveColor.ToAssimpColor4D())); assimpMaterial.AddProperty(new MaterialProperty(GLTFMatKeys.AI_MATKEY_GLTF_METALLIC_FACTOR, pbr.MetallicFactor)); assimpMaterial.AddProperty(new MaterialProperty(GLTFMatKeys.AI_MATKEY_GLTF_ROUGHNESS_FACTOR, pbr.RoughnessFactor)); if (pbr.AmbientOcclusionFactor != 1) { assimpMaterial.AddProperty(new MaterialProperty(AiMatKeys.COLOR_AMBIENT, new Color4D(pbr.AmbientOcclusionFactor))); } if (pbr.ReflectanceFactor != 0) { assimpMaterial.AddProperty(new MaterialProperty(GLTFMatKeys.AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS, true)); assimpMaterial.AddProperty(new MaterialProperty(GLTFMatKeys.AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_GLOSSINESS_FACTOR, pbr.ReflectanceFactor)); } if (pbr.AlbedoColor.Alpha < 1) { assimpMaterial.AddProperty(new MaterialProperty(AiMatKeys.OPACITY, pbr.AlbedoColor.Alpha)); } if (pbr.AlbedoMap != null && !string.IsNullOrEmpty(pbr.AlbedoMapFilePath)) { assimpMaterial.AddProperty(new MaterialProperty(AiMatKeys.TEXTURE_BASE, pbr.AlbedoMapFilePath, TextureType.Diffuse, 0)); assimpMaterial.AddProperty(new MaterialProperty( AiMatKeys.GetFullTextureName(AiMatKeys.MAPPINGMODE_U_BASE, TextureType.Diffuse, 0), (int)ToAssimpAddressMode(pbr.SurfaceMapSampler.AddressU))); assimpMaterial.AddProperty(new MaterialProperty( AiMatKeys.GetFullTextureName(AiMatKeys.MAPPINGMODE_V_BASE, TextureType.Diffuse, 0), (int)ToAssimpAddressMode(pbr.SurfaceMapSampler.AddressV))); } if (pbr.RoughnessMetallicMap != null && !string.IsNullOrEmpty(pbr.RoughnessMetallicMapFilePath)) { assimpMaterial.AddProperty(new MaterialProperty(GLTFMatKeys.AI_MATKEY_GLTF_METALLICROUGHNESSAO_TEXTURE, pbr.RoughnessMetallicMapFilePath, TextureType.Unknown, 0)); } if (pbr.EmissiveMap != null && !string.IsNullOrEmpty(pbr.EmissiveMapFilePath)) { assimpMaterial.AddProperty(new MaterialProperty(AiMatKeys.TEXTURE_BASE, pbr.EmissiveMapFilePath, TextureType.Emissive, 0)); } if (pbr.NormalMap != null && !string.IsNullOrEmpty(pbr.NormalMapFilePath)) { assimpMaterial.AddProperty(new MaterialProperty(AiMatKeys.TEXTURE_BASE, pbr.NormalMapFilePath, TextureType.Normals, 0)); } if (pbr.DisplacementMap != null && !string.IsNullOrEmpty(pbr.DisplacementMapFilePath)) { assimpMaterial.AddProperty(new MaterialProperty(AiMatKeys.TEXTURE_BASE, pbr.DisplacementMapFilePath, TextureType.Displacement, 0)); } if (pbr.IrradianceMap != null && !string.IsNullOrEmpty(pbr.IrradianceMapFilePath)) { assimpMaterial.AddProperty(new MaterialProperty(AiMatKeys.TEXTURE_BASE, pbr.IrradianceMapFilePath, TextureType.Lightmap, 0)); } if (pbr.UVTransform.HasUVTransform) { assimpMaterial.AddProperty(new MaterialProperty(AiMatKeys.UVTRANSFORM_BASE, pbr.UVTransform.ToArray())); } }
public PBRMaterialVariable(IEffectsManager manager, IRenderTechnique technique, PBRMaterialCore core) : base(manager, technique, DefaultMeshConstantBufferDesc, core) { textureManager = manager.MaterialTextureManager; statePoolManager = manager.StateManager; material = core; MaterialPass = technique[material.EnableTessellation ? DefaultPassNames.MeshPBRTriTessellation : DefaultPassNames.PBR]; MaterialOITPass = technique[material.EnableTessellation ? DefaultPassNames.MeshPBRTriTessellationOIT : DefaultPassNames.PBROITPass]; WireframePass = technique[DefaultPassNames.Wireframe]; WireframeOITPass = technique[DefaultPassNames.WireframeOITPass]; ShadowPass = technique[DefaultPassNames.ShadowPass]; UpdateMappings(MaterialPass); CreateTextureViews(); CreateSamplers(); //EnableTessellation = material.EnableTessellation; }
public static PBRMaterial ConvertToPBRMaterial(this PBRMaterialCore core) { return(core == null ? null : new PBRMaterial() { AlbedoColor = core.AlbedoColor, MetallicFactor = core.MetallicFactor, RoughnessFactor = core.RoughnessFactor, AlbedoMap = core.AlbedoMap, NormalMap = core.NormalMap, EmissiveMap = core.EmissiveMap, RoughnessMetallicMap = core.RoughnessMetallicMap, AmbientOcculsionMap = core.AmbientOcculsionMap, IrradianceMap = core.IrradianceMap, DisplacementMap = core.DisplacementMap, SurfaceMapSampler = core.SurfaceMapSampler, IBLSampler = core.IBLSampler, DisplacementMapSampler = core.DisplacementMapSampler, AmbientOcclusionFactor = core.AmbientOcclusionFactor, ClearCoatRoughness = core.ClearCoatRoughness, ClearCoatStrength = core.ClearCoatStrength, EmissiveColor = core.EmissiveColor, EnableAutoTangent = core.EnableAutoTangent, Name = core.Name, ReflectanceFactor = core.ReflectanceFactor, RenderAlbedoMap = core.RenderAlbedoMap, RenderDisplacementMap = core.RenderDisplacementMap, RenderEmissiveMap = core.RenderEmissiveMap, RenderEnvironmentMap = core.RenderEnvironmentMap, RenderIrradianceMap = core.RenderIrradianceMap, RenderNormalMap = core.RenderNormalMap, RenderRoughnessMetallicMap = core.RenderRoughnessMetallicMap, RenderAmbientOcclusionMap = core.RenderAmbientOcclusionMap, RenderShadowMap = core.RenderShadowMap, DisplacementMapScaleMask = core.DisplacementMapScaleMask, UVTransform = core.UVTransform, EnableTessellation = core.EnableTessellation, MaxDistanceTessellationFactor = core.MaxDistanceTessellationFactor, MinDistanceTessellationFactor = core.MinDistanceTessellationFactor, MaxTessellationDistance = core.MaxTessellationDistance, MinTessellationDistance = core.MinTessellationDistance, }); }
/// <summary> /// Initializes a new instance of the <see cref="PBRMaterial"/> class. /// </summary> /// <param name="core">The core.</param> public PBRMaterial(PBRMaterialCore core) : base(core) { AlbedoColor = core.AlbedoColor; MetallicFactor = core.MetallicFactor; RoughnessFactor = core.RoughnessFactor; AmbientOcclusionFactor = core.AmbientOcclusionFactor; ReflectanceFactor = core.ReflectanceFactor; ClearCoatStrength = core.ClearCoatStrength; ClearCoatRoughness = core.ClearCoatRoughness; AlbedoMap = core.AlbedoMap; NormalMap = core.NormalMap; EmissiveMap = core.EmissiveMap; RoughnessMetallicMap = core.RoughnessMetallicMap; AmbientOcculsionMap = core.AmbientOcculsionMap; IrradianceMap = core.IrradianceMap; DisplacementMap = core.DisplacementMap; SurfaceMapSampler = core.SurfaceMapSampler; IBLSampler = core.IBLSampler; DisplacementMapSampler = core.DisplacementMapSampler; RenderAlbedoMap = core.RenderAlbedoMap; RenderDisplacementMap = core.RenderDisplacementMap; RenderEmissiveMap = core.RenderEmissiveMap; RenderEnvironmentMap = core.RenderEnvironmentMap; RenderIrradianceMap = core.RenderIrradianceMap; RenderNormalMap = core.RenderNormalMap; RenderRoughnessMetallicMap = core.RenderRoughnessMetallicMap; RenderAmbientOcclusionMap = core.RenderAmbientOcclusionMap; RenderShadowMap = core.RenderShadowMap; EnableAutoTangent = core.EnableAutoTangent; DisplacementMapScaleMask = core.DisplacementMapScaleMask; UVTransform = core.UVTransform; EnableTessellation = core.EnableTessellation; MaxDistanceTessellationFactor = core.MaxDistanceTessellationFactor; MinDistanceTessellationFactor = core.MinDistanceTessellationFactor; MaxTessellationDistance = core.MaxTessellationDistance; MinTessellationDistance = core.MinTessellationDistance; EnableFlatShading = core.EnableFlatShading; VertexColorBlendingFactor = core.VertexColorBlendingFactor; }
public PBRMaterialVariable(IEffectsManager manager, IRenderTechnique technique, PBRMaterialCore core, string materialPassName = DefaultPassNames.PBR, string wireframePassName = DefaultPassNames.Wireframe, string materialOITPassName = DefaultPassNames.PBROITPass, string wireframeOITPassName = DefaultPassNames.WireframeOITPass, string shadowPassName = DefaultPassNames.ShadowPass, string tessellationPassName = DefaultPassNames.MeshPBRTriTessellation, string tessellationOITPassName = DefaultPassNames.MeshPBRTriTessellationOIT, string depthPassName = DefaultPassNames.DepthPrepass) : base(manager, technique, DefaultMeshConstantBufferDesc, core) { textureManager = manager.MaterialTextureManager; statePoolManager = manager.StateManager; material = core; MaterialPass = technique[material.EnableTessellation ? tessellationPassName : materialPassName]; MaterialOITPass = technique[material.EnableTessellation ? tessellationOITPassName : materialOITPassName]; WireframePass = technique[wireframePassName]; WireframeOITPass = technique[wireframeOITPassName]; ShadowPass = technique[shadowPassName]; DepthPass = technique[depthPassName]; UpdateMappings(MaterialPass); CreateTextureViews(); CreateSamplers(); }
public PBRMaterialVariable(IEffectsManager manager, IRenderTechnique technique, PBRMaterialCore core, string defaultPassName = DefaultPassNames.PBR) : base(manager, technique, DefaultMeshConstantBufferDesc, core) { textureManager = manager.MaterialTextureManager; statePoolManager = manager.StateManager; material = core; MaterialPass = technique[defaultPassName]; OITPass = technique[DefaultPassNames.PBROITPass]; OITDepthPeelingInit = technique[DefaultPassNames.OITDepthPeelingInit]; OITDepthPeeling = technique[DefaultPassNames.PBROITDPPass]; TessellationPass = technique[DefaultPassNames.MeshPBRTriTessellation]; TessellationOITPass = technique[DefaultPassNames.MeshPBRTriTessellationOIT]; TessellationOITDPPass = technique[DefaultPassNames.MeshPBRTriTessellationOITDP]; WireframePass = technique[DefaultPassNames.Wireframe]; WireframeOITPass = technique[DefaultPassNames.WireframeOITPass]; WireframeOITDPPass = technique[DefaultPassNames.WireframeOITDPPass]; ShadowPass = technique[DefaultPassNames.ShadowPass]; DepthPass = technique[DefaultPassNames.DepthPrepass]; UpdateMappings(MaterialPass); CreateTextureViews(); CreateSamplers(); }
/// <summary> /// To the PBR material. /// </summary> /// <param name="material">The material.</param> /// <returns></returns> protected virtual PBRMaterialCore OnCreatePBRMaterial(global::Assimp.Material material) { var pbr = new PBRMaterialCore { AlbedoColor = material.HasColorDiffuse ? material.ColorDiffuse.ToSharpDXColor4() : Color.Black, EmissiveColor = material.HasColorEmissive && !Configuration.IgnoreEmissiveColor ? material.ColorEmissive.ToSharpDXColor4() : Color.Black, }; if (material.HasNonTextureProperty(GLTFMatKeys.AI_MATKEY_GLTF_BASECOLOR_FACTOR)) { pbr.AlbedoColor = material.GetNonTextureProperty(GLTFMatKeys.AI_MATKEY_GLTF_BASECOLOR_FACTOR) .GetColor4DValue().ToSharpDXColor4(); } if (material.HasNonTextureProperty(GLTFMatKeys.AI_MATKEY_GLTF_METALLIC_FACTOR)) { pbr.MetallicFactor = material.GetNonTextureProperty(GLTFMatKeys.AI_MATKEY_GLTF_METALLIC_FACTOR) .GetFloatValue(); } if (material.HasColorAmbient) { pbr.AmbientOcclusionFactor = material.ColorAmbient.R; } if (material.HasNonTextureProperty(GLTFMatKeys.AI_MATKEY_GLTF_ROUGHNESS_FACTOR)) { pbr.RoughnessFactor = material.GetNonTextureProperty(GLTFMatKeys.AI_MATKEY_GLTF_METALLIC_FACTOR) .GetFloatValue(); } else if (material.HasColorSpecular && material.HasShininess) { //Ref https://github.com/assimp/assimp/blob/master/code/glTF2Exporter.cpp float specularIntensity = material.ColorSpecular.R * 0.2125f + material.ColorSpecular.G * 0.7154f + material.ColorSpecular.B * 0.0721f; float normalizedShininess = (float)Math.Sqrt(material.Shininess / 1000); normalizedShininess = Math.Min(Math.Max(normalizedShininess, 0), 1f); normalizedShininess *= specularIntensity; pbr.RoughnessFactor = 1 - normalizedShininess; } if (material.HasNonTextureProperty(GLTFMatKeys.AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS)) { var hasGlossiness = material.GetNonTextureProperty(GLTFMatKeys.AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS).GetBooleanValue(); if (hasGlossiness) { if (material.HasNonTextureProperty(GLTFMatKeys.AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_GLOSSINESS_FACTOR)) { pbr.ReflectanceFactor = material.GetNonTextureProperty(GLTFMatKeys.AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_GLOSSINESS_FACTOR).GetFloatValue(); } else if (material.HasShininess) { pbr.ReflectanceFactor = material.Shininess / 1000; } } } if (material.HasOpacity) { var c = pbr.AlbedoColor; c.Alpha = material.Opacity; pbr.AlbedoColor = c; } if (material.HasTextureDiffuse) { pbr.AlbedoMap = LoadTexture(material.TextureDiffuse.FilePath); pbr.AlbedoMapFilePath = material.TextureDiffuse.FilePath; var desc = Shaders.DefaultSamplers.LinearSamplerClampAni1; desc.AddressU = ToDXAddressMode(material.TextureDiffuse.WrapModeU); desc.AddressV = ToDXAddressMode(material.TextureDiffuse.WrapModeV); pbr.SurfaceMapSampler = desc; } if (material.HasTextureNormal) { pbr.NormalMap = LoadTexture(material.TextureNormal.FilePath); pbr.NormalMapFilePath = material.TextureNormal.FilePath; } else if (material.HasTextureHeight) { pbr.NormalMap = LoadTexture(material.TextureHeight.FilePath); pbr.NormalMapFilePath = material.TextureHeight.FilePath; } if (material.HasProperty(GLTFMatKeys.AI_MATKEY_GLTF_METALLICROUGHNESSAO_TEXTURE, TextureType.Unknown, 0)) { var t = material.GetProperty(GLTFMatKeys.AI_MATKEY_GLTF_METALLICROUGHNESSAO_TEXTURE, TextureType.Unknown, 0); pbr.RoughnessMetallicMap = LoadTexture(t.GetStringValue()); pbr.RoughnessMetallicMapFilePath = t.GetStringValue(); } else if (material.HasTextureSpecular) { pbr.RoughnessMetallicMap = LoadTexture(material.TextureSpecular.FilePath); pbr.RoughnessMetallicMapFilePath = material.TextureSpecular.FilePath; } if (material.HasTextureDisplacement) { pbr.DisplacementMap = LoadTexture(material.TextureDisplacement.FilePath); pbr.DisplacementMapFilePath = material.TextureDisplacement.FilePath; } if (material.HasTextureLightMap) { pbr.AmbientOcculsionMap = LoadTexture(material.TextureLightMap.FilePath); pbr.AmbientOcculsionMapFilePath = material.TextureLightMap.FilePath; } if (material.HasTextureEmissive) { pbr.EmissiveMap = LoadTexture(material.TextureEmissive.FilePath); pbr.EmissiveMapFilePath = material.TextureEmissive.FilePath; } if (material.HasNonTextureProperty(AiMatKeys.UVTRANSFORM_BASE)) { var values = material.GetNonTextureProperty(AiMatKeys.UVTRANSFORM_BASE).GetFloatArrayValue(); if (values != null && values.Length == 5) { pbr.UVTransform = new UVTransform(values[0], new Vector2(values[1], values[2]), new Vector2(values[3], values[4])); } } return(pbr); }