/// <summary> /// Create a Skybox material. /// </summary> /// <param name="i"></param> /// <param name="src"></param> /// <returns></returns> protected virtual Material CreateSkyboxMaterial(int i, glTFMaterial src) { var shader = m_shaderStore.GetShader(src); Material material = new Material(shader); material.name = CreateMaterialName(i, src); #if UNITY_EDITOR material.hideFlags = HideFlags.DontUnloadUnusedAsset; #endif VGO_materials_skybox vgoSkybox = src.extensions.VGO_materials_skybox; switch (shader.name) { case ShaderName.Skybox_6_Sided: UniSkybox.Utils.SetParametersToMaterial(material, new Skybox6SidedDefinition() { Tint = ArrayConverter.ToColor(vgoSkybox.tint, gamma: true), Exposure = vgoSkybox.exposure, Rotation = vgoSkybox.rotation, FrontTex = GetTexture(UniSkybox.Utils.PropFrontTex, vgoSkybox.frontTexIndex), BackTex = GetTexture(UniSkybox.Utils.PropBackTex, vgoSkybox.backTexIndex), LeftTex = GetTexture(UniSkybox.Utils.PropLeftTex, vgoSkybox.leftTexIndex), RightTex = GetTexture(UniSkybox.Utils.PropRightTex, vgoSkybox.rightTexIndex), UpTex = GetTexture(UniSkybox.Utils.PropUpTex, vgoSkybox.upTexIndex), DownTex = GetTexture(UniSkybox.Utils.PropDownTex, vgoSkybox.downTexIndex), }); break; case ShaderName.Skybox_Cubemap: // @todo Tex (Cubemap) UniSkybox.Utils.SetParametersToMaterial(material, new SkyboxCubemapDefinition() { Tint = ArrayConverter.ToColor(vgoSkybox.tint, gamma: true), Exposure = vgoSkybox.exposure, Rotation = vgoSkybox.rotation, Tex = GetCubemap(UniSkybox.Utils.PropTex, vgoSkybox.texIndex), }); break; case ShaderName.Skybox_Panoramic: UniSkybox.Utils.SetParametersToMaterial(material, new SkyboxPanoramicDefinition() { Tint = ArrayConverter.ToColor(vgoSkybox.tint, gamma: true), Exposure = vgoSkybox.exposure, Rotation = vgoSkybox.rotation, MainTex = GetTexture(UniSkybox.Utils.PropMainTex, vgoSkybox.mainTexIndex), Mapping = (Mapping)vgoSkybox.mapping, ImageType = (ImageType)vgoSkybox.imageType, MirrorOnBack = vgoSkybox.mirrorOnBack, Layout = (Layout)vgoSkybox.layout, }); break; case ShaderName.Skybox_Procedural: UniSkybox.Utils.SetParametersToMaterial(material, new SkyboxProceduralDefinition() { SunDisk = (SunDisk)vgoSkybox.sunDisk, SunSize = vgoSkybox.sunSize, SunSizeConvergence = vgoSkybox.sunSizeConvergence, AtmosphereThickness = vgoSkybox.atmosphereThickness, SkyTint = ArrayConverter.ToColor(vgoSkybox.skyTint, gamma: true), GroundColor = ArrayConverter.ToColor(vgoSkybox.groundColor, gamma: true), Exposure = vgoSkybox.exposure, }); break; default: break; } return(material); }
/// <summary> /// Create a Skybox material. /// </summary> /// <param name="m"></param> /// <param name="textureManager"></param> /// <returns></returns> protected virtual glTFMaterial CreateSkyboxMaterial(Material m, TextureExportManager textureManager) { VGO_materials_skybox vgoSkybox; switch (m.shader.name) { case ShaderName.Skybox_6_Sided: { Skybox6SidedDefinition skyboxDefinition = UniSkybox.Utils.GetParametersFromMaterial <Skybox6SidedDefinition>(m); vgoSkybox = new VGO_materials_skybox() { tint = skyboxDefinition.Tint.linear.ToArray(), exposure = skyboxDefinition.Exposure, rotation = skyboxDefinition.Rotation, frontTexIndex = textureManager.CopyAndGetIndex(skyboxDefinition.FrontTex, RenderTextureReadWrite.sRGB), backTexIndex = textureManager.CopyAndGetIndex(skyboxDefinition.BackTex, RenderTextureReadWrite.sRGB), leftTexIndex = textureManager.CopyAndGetIndex(skyboxDefinition.LeftTex, RenderTextureReadWrite.sRGB), rightTexIndex = textureManager.CopyAndGetIndex(skyboxDefinition.RightTex, RenderTextureReadWrite.sRGB), upTexIndex = textureManager.CopyAndGetIndex(skyboxDefinition.UpTex, RenderTextureReadWrite.sRGB), downTexIndex = textureManager.CopyAndGetIndex(skyboxDefinition.DownTex, RenderTextureReadWrite.sRGB), }; } break; case ShaderName.Skybox_Cubemap: // @todo Tex (Cubemap) { SkyboxCubemapDefinition skyboxDefinition = UniSkybox.Utils.GetParametersFromMaterial <SkyboxCubemapDefinition>(m); vgoSkybox = new VGO_materials_skybox() { tint = skyboxDefinition.Tint.linear.ToArray(), exposure = skyboxDefinition.Exposure, rotation = skyboxDefinition.Rotation, texIndex = textureManager.CopyAndGetIndex(skyboxDefinition.Tex, RenderTextureReadWrite.sRGB), }; } break; case ShaderName.Skybox_Panoramic: { SkyboxPanoramicDefinition skyboxDefinition = UniSkybox.Utils.GetParametersFromMaterial <SkyboxPanoramicDefinition>(m); vgoSkybox = new VGO_materials_skybox() { tint = skyboxDefinition.Tint.linear.ToArray(), exposure = skyboxDefinition.Exposure, rotation = skyboxDefinition.Rotation, mainTexIndex = textureManager.CopyAndGetIndex(skyboxDefinition.MainTex, RenderTextureReadWrite.sRGB), mapping = (SkyboxMapping)skyboxDefinition.Mapping, imageType = (SkyboxImageType)skyboxDefinition.ImageType, mirrorOnBack = skyboxDefinition.MirrorOnBack, layout = (SkyboxLayout)skyboxDefinition.Layout, }; } break; case ShaderName.Skybox_Procedural: { SkyboxProceduralDefinition skyboxDefinition = UniSkybox.Utils.GetParametersFromMaterial <SkyboxProceduralDefinition>(m); vgoSkybox = new VGO_materials_skybox() { sunDisk = (SkyboxSunDisk)skyboxDefinition.SunDisk, sunSize = skyboxDefinition.SunSize, sunSizeConvergence = skyboxDefinition.SunSizeConvergence, atmosphereThickness = skyboxDefinition.AtmosphereThickness, skyTint = skyboxDefinition.SkyTint.linear.ToArray(), groundColor = skyboxDefinition.GroundColor.linear.ToArray(), exposure = skyboxDefinition.Exposure, }; } break; default: throw new UniGLTFNotSupportedException(m.shader.name); } var material = new glTFMaterial(); material.name = m.name; // PBR Metallic Roughness if (material.pbrMetallicRoughness == null) { material.pbrMetallicRoughness = new glTFPbrMetallicRoughness(); } // extensions material.extensions = new glTFMaterial_extensions() { VGO_materials = new VGO_materials(m.shader.name), VGO_materials_skybox = vgoSkybox, }; return(material); }