예제 #1
0
        public static void GenerateSpaceTranslationSurfaceInputs(
            NeededCoordinateSpace neededSpaces,
            InterpolatorType interpolatorType,
            ShaderGenerator surfaceInputs,
            string toReplace = "float3 {0};")
        {
            if ((neededSpaces & NeededCoordinateSpace.Object) > 0)
            {
                surfaceInputs.AddShaderChunk(string.Format(toReplace, CoordinateSpace.Object.ToVariableName(interpolatorType)), false);
            }

            if ((neededSpaces & NeededCoordinateSpace.World) > 0)
            {
                surfaceInputs.AddShaderChunk(string.Format(toReplace, CoordinateSpace.World.ToVariableName(interpolatorType)), false);
            }

            if ((neededSpaces & NeededCoordinateSpace.View) > 0)
            {
                surfaceInputs.AddShaderChunk(string.Format(toReplace, CoordinateSpace.View.ToVariableName(interpolatorType)), false);
            }

            if ((neededSpaces & NeededCoordinateSpace.Tangent) > 0)
            {
                surfaceInputs.AddShaderChunk(string.Format(toReplace, CoordinateSpace.Tangent.ToVariableName(interpolatorType)), false);
            }
        }
예제 #2
0
        public static void GenerateSpaceTranslationSurfaceInputs(
            NeededCoordinateSpace neededSpaces,
            InterpolatorType interpolatorType,
            ShaderStringBuilder builder,
            string format = "float3 {0};")
        {
            if ((neededSpaces & NeededCoordinateSpace.Object) > 0)
            {
                builder.AppendLine(format, CoordinateSpace.Object.ToVariableName(interpolatorType));
            }

            if ((neededSpaces & NeededCoordinateSpace.World) > 0)
            {
                builder.AppendLine(format, CoordinateSpace.World.ToVariableName(interpolatorType));
            }

            if ((neededSpaces & NeededCoordinateSpace.View) > 0)
            {
                builder.AppendLine(format, CoordinateSpace.View.ToVariableName(interpolatorType));
            }

            if ((neededSpaces & NeededCoordinateSpace.Tangent) > 0)
            {
                builder.AppendLine(format, CoordinateSpace.Tangent.ToVariableName(interpolatorType));
            }
        }
        public static void GenerateSpaceTranslations(
            NeededCoordinateSpace neededSpaces,
            InterpolatorType type,
            CoordinateSpace from,
            InputType inputType,
            ShaderStringBuilder pixelShader,
            Dimension dimension)
        {
            if ((neededSpaces & NeededCoordinateSpace.Object) > 0 && from != CoordinateSpace.Object)
            {
                pixelShader.AppendLine("float{0} {1} = {2};", DimensionToString(dimension),
                                       CoordinateSpace.Object.ToVariableName(type), ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.Object, inputType, from));
            }

            if ((neededSpaces & NeededCoordinateSpace.World) > 0 && from != CoordinateSpace.World)
            {
                pixelShader.AppendLine("float{0} {1} = {2};", DimensionToString(dimension),
                                       CoordinateSpace.World.ToVariableName(type), ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.World, inputType, from));
            }

            if ((neededSpaces & NeededCoordinateSpace.View) > 0 && from != CoordinateSpace.View)
            {
                pixelShader.AppendLine("float{0} {1} = {2};", DimensionToString(dimension),
                                       CoordinateSpace.View.ToVariableName(type),
                                       ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.View, inputType, from));
            }

            if ((neededSpaces & NeededCoordinateSpace.Tangent) > 0 && from != CoordinateSpace.Tangent)
            {
                pixelShader.AppendLine("float{0} {1} = {2};", DimensionToString(dimension),
                                       CoordinateSpace.Tangent.ToVariableName(type),
                                       ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.Tangent, inputType, from));
            }
        }
예제 #4
0
        public static ShaderGraphRequirements FromNodes <T>(List <T> nodes, ShaderStageCapability stageCapability = ShaderStageCapability.All, bool includeIntermediateSpaces = true)
            where T : AbstractMaterialNode
        {
            NeededCoordinateSpace requiresNormal    = nodes.OfType <IMayRequireNormal>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability));
            NeededCoordinateSpace requiresBitangent = nodes.OfType <IMayRequireBitangent>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresBitangent(stageCapability));
            NeededCoordinateSpace requiresTangent   = nodes.OfType <IMayRequireTangent>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability));
            NeededCoordinateSpace requiresViewDir   = nodes.OfType <IMayRequireViewDirection>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresViewDirection(stageCapability));
            NeededCoordinateSpace requiresPosition  = nodes.OfType <IMayRequirePosition>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability));
            bool requiresScreenPosition             = nodes.OfType <IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition());
            bool requiresVertexColor         = nodes.OfType <IMayRequireVertexColor>().Any(x => x.RequiresVertexColor());
            bool requiresFaceSign            = nodes.OfType <IMayRequireFaceSign>().Any(x => x.RequiresFaceSign());
            bool requiresDepthTexture        = nodes.OfType <IMayRequireDepthTexture>().Any(x => x.RequiresDepthTexture());
            bool requiresCameraOpaqueTexture = nodes.OfType <IMayRequireCameraOpaqueTexture>().Any(x => x.RequiresCameraOpaqueTexture());

            var meshUV = new List <UVChannel>();

            for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UVCount; ++uvIndex)
            {
                var channel = (UVChannel)uvIndex;
                if (nodes.OfType <IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(channel)))
                {
                    meshUV.Add(channel);
                }
            }

            // if anything needs tangentspace we have make
            // sure to have our othonormal basis!
            if (includeIntermediateSpaces)
            {
                var compoundSpaces = requiresBitangent | requiresNormal | requiresPosition
                                     | requiresTangent | requiresViewDir | requiresPosition
                                     | requiresNormal;

                var needsTangentSpace = (compoundSpaces & NeededCoordinateSpace.Tangent) > 0;
                if (needsTangentSpace)
                {
                    requiresBitangent |= NeededCoordinateSpace.World;
                    requiresNormal    |= NeededCoordinateSpace.World;
                    requiresTangent   |= NeededCoordinateSpace.World;
                }
            }

            var reqs = new ShaderGraphRequirements()
            {
                requiresNormal              = requiresNormal,
                requiresBitangent           = requiresBitangent,
                requiresTangent             = requiresTangent,
                requiresViewDir             = requiresViewDir,
                requiresPosition            = requiresPosition,
                requiresScreenPosition      = requiresScreenPosition,
                requiresVertexColor         = requiresVertexColor,
                requiresFaceSign            = requiresFaceSign,
                requiresMeshUVs             = meshUV,
                requiresDepthTexture        = requiresDepthTexture,
                requiresCameraOpaqueTexture = requiresCameraOpaqueTexture
            };

            return(reqs);
        }
예제 #5
0
        public NeededCoordinateSpace RequiresBitangent(ShaderStageCapability stageCapability)
        {
            NeededCoordinateSpace neededSpaces = NeededCoordinateSpace.None;

            if (m_TextureType == TextureType.Normal)
            {
                neededSpaces |= normalTransform.RequiresBitangent;
            }
            return(neededSpaces);
        }
예제 #6
0
        public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability)
        {
            NeededCoordinateSpace neededSpaces = normalSlot.RequiresNormal();

            if (m_TextureType == TextureType.Normal)
            {
                neededSpaces |= normalTransform.RequiresNormal;
            }
            return(neededSpaces);
        }
        public static ShaderGraphRequirements FromNodes(List <INode> nodes)
        {
            NeededCoordinateSpace requiresNormal    = nodes.OfType <IMayRequireNormal>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal());
            NeededCoordinateSpace requiresBitangent = nodes.OfType <IMayRequireBitangent>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresBitangent());
            NeededCoordinateSpace requiresTangent   = nodes.OfType <IMayRequireTangent>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent());
            NeededCoordinateSpace requiresViewDir   = nodes.OfType <IMayRequireViewDirection>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresViewDirection());
            NeededCoordinateSpace requiresPosition  = nodes.OfType <IMayRequirePosition>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition());
            bool requiresScreenPosition             = nodes.OfType <IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition());
            bool requiresVertexColor = nodes.OfType <IMayRequireVertexColor>().Any(x => x.RequiresVertexColor());

            var meshUV = new List <UVChannel>();

            for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UVCount; ++uvIndex)
            {
                var channel = (UVChannel)uvIndex;
                if (nodes.OfType <IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(channel)))
                {
                    meshUV.Add(channel);
                }
            }

            // if anything needs tangentspace we have make
            // sure to have our othonormal basis!
            var compoundSpaces = requiresBitangent | requiresNormal | requiresPosition
                                 | requiresTangent | requiresViewDir | requiresPosition
                                 | requiresNormal;

            var needsTangentSpace = (compoundSpaces & NeededCoordinateSpace.Tangent) > 0;

            if (needsTangentSpace)
            {
                requiresBitangent |= NeededCoordinateSpace.Object;
                requiresNormal    |= NeededCoordinateSpace.Object;
                requiresTangent   |= NeededCoordinateSpace.Object;
            }

            var reqs = new ShaderGraphRequirements()
            {
                requiresNormal         = requiresNormal,
                requiresBitangent      = requiresBitangent,
                requiresTangent        = requiresTangent,
                requiresViewDir        = requiresViewDir,
                requiresPosition       = requiresPosition,
                requiresScreenPosition = requiresScreenPosition,
                requiresVertexColor    = requiresVertexColor,
                requiresMeshUVs        = meshUV
            };

            return(reqs);
        }
예제 #8
0
        public static CoordinateSpace ToCoordinateSpace(this NeededCoordinateSpace space)
        {
            switch (space)
            {
            case NeededCoordinateSpace.Object:
                return(CoordinateSpace.Object);

            case NeededCoordinateSpace.View:
                return(CoordinateSpace.View);

            case NeededCoordinateSpace.World:
                return(CoordinateSpace.World);

            case NeededCoordinateSpace.Tangent:
                return(CoordinateSpace.Tangent);

            case NeededCoordinateSpace.AbsoluteWorld:
                return(CoordinateSpace.AbsoluteWorld);

            default:
                throw new ArgumentOutOfRangeException(nameof(space), space, null);
            }
        }
예제 #9
0
 public NeededTransform(NeededCoordinateSpace from, NeededCoordinateSpace to)
 {
     this.from = from;
     this.to   = to;
 }