コード例 #1
0
 private ILightAsset TransformLight(PunctualLight o, string id, ReaderContext context)
 {
     return(new LightAsset(id));
 }
コード例 #2
0
        private SamplerParameters?TransfromSamplerParameters(MaterialChannel materialChannel, ReaderContext context)
        {
            var materialChannelTexture = materialChannel.Texture;

            if (materialChannelTexture == null)
            {
                return(null);
            }
            var primaryImage = materialChannelTexture.PrimaryImage;

            if (primaryImage == null)
            {
                return(null);
            }
            return(new SamplerParameters
            {
                Image = context.Images[primaryImage.LogicalIndex],
                TextureCoordinate = materialChannel.TextureCoordinate,
                TextureTransform = TransformTextureTransform(materialChannel.TextureTransform)
            });
        }
コード例 #3
0
 private ICameraAsset TransformCamera(Camera o, string id, ReaderContext context)
 {
     return(new CameraAsset(id));
 }
コード例 #4
0
        private IEnumerable <IShaderParameter> TransformShaderParameter(MaterialChannel materialChannel, ReaderContext context)
        {
            var parameter = materialChannel.Parameter;

            switch (materialChannel.Key)
            {
            case "BaseColor":
            {
                var samplerParameters = TransfromSamplerParameters(materialChannel, context);
                if (samplerParameters.HasValue)
                {
                    yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.BaseColorTexture, samplerParameters.Value));
                }
            }
                yield return(new ShaderParameter <Vector4>(ShaderParameterKey.BaseColorFactor, parameter));

                yield break;

            case "Diffuse":
            {
                var samplerParameters = TransfromSamplerParameters(materialChannel, context);
                if (samplerParameters.HasValue)
                {
                    yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.DiffuseTexture, samplerParameters.Value));
                }
            }
                yield return(new ShaderParameter <Vector4>(ShaderParameterKey.DiffuseFactor, parameter));

                yield break;

            case "MetallicRoughness":
            {
                var samplerParameters = TransfromSamplerParameters(materialChannel, context);
                if (samplerParameters.HasValue)
                {
                    yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.MetallicRoughnessTexture, samplerParameters.Value));
                }
            }
                yield return(new ShaderParameter <float>(ShaderParameterKey.MetallicFactor, parameter.X));

                yield return(new ShaderParameter <float>(ShaderParameterKey.RoughnessFactor, parameter.Y));

                yield break;

            case "SpecularGlossiness":
            {
                var samplerParameters = TransfromSamplerParameters(materialChannel, context);
                if (samplerParameters.HasValue)
                {
                    yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.SpecularGlossinessTexture, samplerParameters.Value));
                }
            }
                yield return(new ShaderParameter <Vector3>(ShaderParameterKey.SpecularFactor, new Vector3(parameter.X, parameter.Y, parameter.Z)));

                yield return(new ShaderParameter <float>(ShaderParameterKey.GlossinessFactor, parameter.W));

                yield break;

            case "Normal":
            {
                var samplerParameters = TransfromSamplerParameters(materialChannel, context);
                if (samplerParameters.HasValue)
                {
                    yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.NormalTexture, samplerParameters.Value));
                }
            }
                yield return(new ShaderParameter <float>(ShaderParameterKey.NormalTextureScale, parameter.X));

                yield break;

            case "Occlusion":
            {
                var samplerParameters = TransfromSamplerParameters(materialChannel, context);
                if (samplerParameters.HasValue)
                {
                    yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.OcclusionTexture, samplerParameters.Value));
                }
            }
                yield return(new ShaderParameter <float>(ShaderParameterKey.OcclusionTextureStrength, parameter.X));

                yield break;

            case "Emissive":
            {
                var samplerParameters = TransfromSamplerParameters(materialChannel, context);
                if (samplerParameters.HasValue)
                {
                    yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.EmissiveTexture,
                                                                         samplerParameters.Value));
                }
            }
                {
                    yield return(new ShaderParameter <Vector3>(ShaderParameterKey.EmissiveFactor, new Vector3(parameter.X, parameter.Y, parameter.Z)));
                }
                yield break;

            default:
                throw new NotImplementedException($"Material channel {materialChannel.Key} is not supported yet");
            }
        }