Package 

Class Material


  • 
    public class Material
    
                        

    A Filament Material defines the visual appearance of an object. Materials function as a templates from which MaterialInstances can be spawned. Use Builder to construct a Material object.

    • Constructor Detail

      • Material

        Material(long nativeMaterial)
    • Method Detail

      • compile

         void compile(@NonNull() Material.CompilerPriorityQueue priority, int variants, @Nullable() Object handler, @Nullable() Runnable callback)

        Asynchronously ensures that a subset of this Material's variants are compiled. After issuingseveral compile() calls in a row, it is recommended to call flush such that the backend can start the compilation work as soon as possible.The provided callback is guaranteed to be called on the main thread after all specifiedvariants of the material are compiled. This can take hundreds of milliseconds.

        If all the material's variants are already compiled, the callback will be scheduled assoon as possible, but this might take a few dozen millisecond, corresponding to howmany previous frames are enqueued in the backend. This also varies by backend. Therefore,it is recommended to only call this method once per material shortly after creation.

        If the same variant is scheduled for compilation multiple times, the first schedulingtakes precedence; later scheduling are ignored.

        caveat: A consequence is that if a variant is scheduled on the low priority queue and laterscheduled again on the high priority queue, the later scheduling is ignored.Therefore, the second callback could be called before the variant is compiled.However, the first callback, if specified, will trigger as expected.

        The callback is guaranteed to be called. If the engine is destroyed while some materialvariants are still compiling or in the queue, these will be discarded and the correspondingcallback will be called. In that case however the Material pointer passed to the callbackis guaranteed to be invalid (either because it's been destroyed by the user already, or,because it's been cleaned-up by the Engine).

        ALL should be used with caution. Only variants that an applicationneeds should be included in the variants argument. For example, the STE variant is only usedfor stereoscopic rendering. If an application is not planning to render in stereo, this bitshould be turned off to avoid unnecessary material compilations.

        Parameters:
        priority - Which priority queue to use, LOW or HIGH.
        variants - Variants to include to the compile command.
        handler - An Executor.
        callback - callback called on the main thread when the compilation is done onby backend.
      • getName

         String getName()

        Returns the name of this material. The material name is used for debugging purposes.

      • isColorWriteEnabled

         boolean isColorWriteEnabled()

        Indicates whether instances of this material will, by default, write to the color buffer.

      • isDepthWriteEnabled

         boolean isDepthWriteEnabled()

        Indicates whether instances of this material will, by default, write to the depth buffer.

      • isDepthCullingEnabled

         boolean isDepthCullingEnabled()

        Indicates whether instances of this material will, by default, use depth testing.

      • isDoubleSided

         boolean isDoubleSided()

        Indicates whether this material is double-sided.

      • isAlphaToCoverageEnabled

         boolean isAlphaToCoverageEnabled()

        Indicates whether instances of this material will use alpha to coverage.

      • getMaskThreshold

         float getMaskThreshold()

        Returns the alpha mask threshold used when the blending mode is set to masked.

      • getSpecularAntiAliasingVariance

         float getSpecularAntiAliasingVariance()

        Returns the screen-space variance for specular-antialiasing. This value is between 0 and 1.

      • getSpecularAntiAliasingThreshold

         float getSpecularAntiAliasingThreshold()

        Returns the clamping threshold for specular-antialiasing. This value is between 0 and 1.

      • getParameterCount

         int getParameterCount()

        Returns the number of parameters declared by this material.The returned value can be 0.

      • getParameters

         List<Material.Parameter> getParameters()

        Returns a list of Parameter objects representing this material's parameters.The list may be empty if the material has no declared parameters.

      • hasParameter

         boolean hasParameter(@NonNull() String name)

        Indicates whether a parameter of the given name exists on this material.

      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, boolean x)

        Sets the value of a bool parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the material parameter
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, float x)

        Sets the value of a float parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the material parameter
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, int x)

        Sets the value of an int parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the material parameter
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, boolean x, boolean y)

        Sets the value of a bool2 parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, float x, float y)

        Sets the value of a float2 parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, int x, int y)

        Sets the value of an int2 parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, boolean x, boolean y, boolean z)

        Sets the value of a bool3 parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
        z - the value of the third component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, float x, float y, float z)

        Sets the value of a float3 parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
        z - the value of the third component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, int x, int y, int z)

        Sets the value of a int3 parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
        z - the value of the third component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, boolean x, boolean y, boolean z, boolean w)

        Sets the value of a bool4 parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
        z - the value of the third component
        w - the value of the fourth component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, float x, float y, float z, float w)

        Sets the value of a float4 parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
        z - the value of the third component
        w - the value of the fourth component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, int x, int y, int z, int w)

        Sets the value of a int4 parameter on this material's default instance.

        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
        z - the value of the third component
        w - the value of the fourth component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, @NonNull() MaterialInstance.BooleanElement type, @NonNull() @Size(min = 1) Array<boolean> v, @IntRange(from = 0) int offset, @IntRange(from = 1) int count)

        Set a bool parameter array by name.

        Parameters:
        name - name of the parameter array as defined by this Material
        type - the number of components for each individual parameter
        v - array of values to set to the named parameter array
        offset - the number of elements in v to skip
        count - the number of elements in the parameter array to setFor example, to set a parameter array of 4 bool4s:
        {@code * boolean[] a = new boolean[4 * 4]; * material.setDefaultParameter("param", MaterialInstance.BooleanElement.BOOL4, a, 0, 4); * }
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, @NonNull() MaterialInstance.IntElement type, @NonNull() @Size(min = 1) Array<int> v, @IntRange(from = 0) int offset, @IntRange(from = 1) int count)

        Set an int parameter array by name.

        Parameters:
        name - name of the parameter array as defined by this Material
        type - the number of components for each individual parameter
        v - array of values to set to the named parameter array
        offset - the number of elements in v to skip
        count - the number of elements in the parameter array to setFor example, to set a parameter array of 4 int4s:
        {@code * int[] a = new int[4 * 4]; * material.setDefaultParameter("param", MaterialInstance.IntElement.INT4, a, 0, 4); * }
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, @NonNull() MaterialInstance.FloatElement type, @NonNull() @Size(min = 1) Array<float> v, @IntRange(from = 0) int offset, @IntRange(from = 1) int count)

        Set a float parameter array by name.

        Parameters:
        name - name of the parameter array as defined by this Material
        type - the number of components for each individual parameter
        v - array of values to set to the named parameter array
        offset - the number of elements in v to skip
        count - the number of elements in the parameter array to setFor example, to set a parameter array of 4 float4s:
        {@code * float[] a = new float[4 * 4]; * material.setDefaultParameter("param", MaterialInstance.FloatElement.FLOAT4, a, 0, 4); * }
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, @NonNull() Colors.RgbType type, float r, float g, float b)

        Sets the color of the given parameter on this material's default instance.

        Parameters:
        name - the name of the material color parameter
        type - whether the color is specified in the linear or sRGB space
        r - red component
        g - green component
        b - blue component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, @NonNull() Colors.RgbaType type, float r, float g, float b, float a)

        Sets the color of the given parameter on this material's default instance.

        Parameters:
        name - the name of the material color parameter
        type - whether the color is specified in the linear or sRGB space
        r - red component
        g - green component
        b - blue component
        a - alpha component
      • setDefaultParameter

         void setDefaultParameter(@NonNull() String name, @NonNull() Texture texture, @NonNull() TextureSampler sampler)

        Sets a texture and sampler parameter on this material's default instance.

        Parameters:
        name - The name of the material texture parameter
        texture - The texture to set as parameter
        sampler - The sampler to be used with this texture