private ShaderFunc BuildMathVectorOperation(ShaderFunc a, ShaderFunc b, MathOperation operation)
        {
            switch (operation)
            {
            case MathOperation.Add:
                return(new ShaderFunc(() => $"({a.Compile()}) + ({b.Compile()})"));

            case MathOperation.Subtract:
                return(new ShaderFunc(() => $"({a.Compile()}) - ({b.Compile()})"));

            case MathOperation.Multiply:
                return(new ShaderFunc(() => $"({a.Compile()}) * ({b.Compile()})"));

            case MathOperation.Divide:
                return(new ShaderFunc(() => $"({a.Compile()}) / ({b.Compile()})"));

            case MathOperation.CrossProduct:
                return(new ShaderFunc(() => $"cross(({a.Compile()}), ({b.Compile()}))"));

            case MathOperation.Reflect:
                return(new ShaderFunc(() => $"reflect(({a.Compile()}), ({b.Compile()}))"));

            case MathOperation.Min:
                return(new ShaderFunc(() => $"min(({a.Compile()}), ({b.Compile()}))"));

            case MathOperation.Max:
                return(new ShaderFunc(() => $"max(({a.Compile()}), ({b.Compile()}))"));

            default: return(null);
            }
        }
        private ShaderFunc BuildMathFloatOperation(ShaderFunc a, ShaderFunc b, MathOperation operation)
        {
            switch (operation)
            {
            case MathOperation.DotProduct:
                return(new ShaderFunc(() => $"dot(({a.Compile()}), ({b.Compile()}))"));

            case MathOperation.Distance:
                return(new ShaderFunc(() => $"distance(({a.Compile()}), ({b.Compile()}))"));

            default: return(null);
            }
        }
Ejemplo n.º 3
0
        private ShaderFunc BuildMathOperation(ShaderFunc a, MathOperation operation)
        {
            switch (operation)
            {
            case MathOperation.Sine:
                return(new ShaderFunc(() => $"sin({a.Compile()})"));

            case MathOperation.Cosine:
                return(new ShaderFunc(() => $"cos({a.Compile()})"));

            case MathOperation.Tangent:
                return(new ShaderFunc(() => $"tan({a.Compile()})"));

            case MathOperation.Arcsine:
                return(new ShaderFunc(() => $"asin({a.Compile()})"));

            case MathOperation.Arccosine:
                return(new ShaderFunc(() => $"acos({a.Compile()})"));

            case MathOperation.Arctangent:
                return(new ShaderFunc(() => $"atan({a.Compile()})"));

            case MathOperation.Logarithm:
                return(new ShaderFunc(() => $"log({a.Compile()})"));

            case MathOperation.Round:
                return(new ShaderFunc(() => $"round({a.Compile()})"));

            case MathOperation.Floor:
                return(new ShaderFunc(() => $"floor({a.Compile()})"));

            case MathOperation.Ceil:
                return(new ShaderFunc(() => $"ceil({a.Compile()})"));

            case MathOperation.Absolute:
                return(new ShaderFunc(() => $"abs({a.Compile()})"));

            case MathOperation.Sign:
                return(new ShaderFunc(() => $"sign({a.Compile()})"));

            case MathOperation.Sqrt:
                return(new ShaderFunc(() => $"sqrt({a.Compile()})"));

            default:
                throw new Exception("Unsupported math operation");
            }
        }
        private ShaderFunc BuildMathOperation(ShaderFunc a, ShaderFunc b, MathOperation operation)
        {
            switch (operation)
            {
            case MathOperation.Add:
                return(new ShaderFunc(() => $"({a.Compile()}) + ({b.Compile()})"));

            case MathOperation.Subtract:
                return(new ShaderFunc(() => $"({a.Compile()}) - ({b.Compile()})"));

            case MathOperation.Multiply:
                return(new ShaderFunc(() => $"({a.Compile()}) * ({b.Compile()})"));

            case MathOperation.Divide:
                return(new ShaderFunc(() => $"({a.Compile()}) / ({b.Compile()})"));

            case MathOperation.Power:
                return(new ShaderFunc(() => $"pow(({a.Compile()}), ({b.Compile()}))"));

            case MathOperation.Minimum:
                return(new ShaderFunc(() => $"min(({a.Compile()}), ({b.Compile()}))"));

            case MathOperation.Maximum:
                return(new ShaderFunc(() => $"max(({a.Compile()}), ({b.Compile()}))"));

            case MathOperation.LessThan:
                return(new ShaderFunc(() => $"({a.Compile()}) < ({b.Compile()}) ? 1 : 0"));

            case MathOperation.GreaterThan:
                return(new ShaderFunc(() => $"({a.Compile()}) > ({b.Compile()}) ? 1 : 0"));

            case MathOperation.Modulo:
                return(new ShaderFunc(() => $"mod(({a.Compile()}), ({b.Compile()}))"));

            default:
                throw new Exception("Unsupported math operation");
            }
        }
Ejemplo n.º 5
0
 public Shader(ShaderFunc calculate) => Calculate = calculate;