Class MaterialInstance


  • public class MaterialInstance
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      MaterialInstance​(Engine engine, long nativeMaterialInstance)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static MaterialInstance duplicate​(MaterialInstance other, java.lang.String name)
      Creates a new MaterialInstance(long) using another MaterialInstance(long) as a template for initialization.
      Material getMaterial()  
      java.lang.String getName()  
      long getNativeObject()  
      void setColorWrite​(boolean enable)
      Overrides the default color-buffer write state that was set on the material.
      void setCullingMode​(Material.CullingMode mode)
      Overrides the default triangle culling state that was set on the material.
      void setDepthCulling​(boolean enable)
      Overrides the default depth testing state that was set on the material.
      void setDepthWrite​(boolean enable)
      Overrides the default depth-buffer write state that was set on the material.
      void setDoubleSided​(boolean doubleSided)
      Enables or disables double-sided lighting if the parent Material has double-sided capability, otherwise prints a warning.
      void setMaskThreshold​(float threshold)
      Overrides the minimum alpha value a fragment must have to not be discarded when the blend mode is MASKED.
      void setParameter​(java.lang.String name, boolean x)
      Sets the value of a bool parameter.
      void setParameter​(java.lang.String name, boolean x, boolean y)
      Sets the value of a bool2 parameter.
      void setParameter​(java.lang.String name, boolean x, boolean y, boolean z)
      Sets the value of a bool3 parameter.
      void setParameter​(java.lang.String name, boolean x, boolean y, boolean z, boolean w)
      Sets the value of a bool4 parameter.
      void setParameter​(java.lang.String name, float x)
      Sets the value of a float parameter.
      void setParameter​(java.lang.String name, float x, float y)
      Sets the value of a float2 parameter.
      void setParameter​(java.lang.String name, float x, float y, float z)
      Sets the value of a float3 parameter.
      void setParameter​(java.lang.String name, float x, float y, float z, float w)
      Sets the value of a float4 parameter.
      void setParameter​(java.lang.String name, int x)
      Sets the value of an int parameter.
      void setParameter​(java.lang.String name, int x, int y)
      Sets the value of an int2 parameter.
      void setParameter​(java.lang.String name, int x, int y, int z)
      Sets the value of a int3 parameter.
      void setParameter​(java.lang.String name, int x, int y, int z, int w)
      Sets the value of a int4 parameter.
      void setParameter​(java.lang.String name, Colors.RgbaType type, float r, float g, float b, float a)
      Sets the color of the given parameter on this material's default instance.
      void setParameter​(java.lang.String name, Colors.RgbType type, float r, float g, float b)
      Sets the color of the given parameter on this material's default instance.
      void setParameter​(java.lang.String name, MaterialInstance.BooleanElement type, boolean[] v, int offset, int count)
      Set a bool parameter array by name.
      void setParameter​(java.lang.String name, MaterialInstance.FloatElement type, float[] v, int offset, int count)
      Set a float parameter array by name.
      void setParameter​(java.lang.String name, MaterialInstance.IntElement type, int[] v, int offset, int count)
      Set an int parameter array by name.
      void setParameter​(java.lang.String name, Texture texture, TextureSampler sampler)
      Sets a texture and sampler parameter on this material's default instance.
      void setPolygonOffset​(float scale, float constant)
      Sets a polygon offset that will be applied to all renderables drawn with this material instance.
      void setScissor​(int left, int bottom, int width, int height)
      Set up a custom scissor rectangle; by default this encompasses the View.
      void setSpecularAntiAliasingThreshold​(float threshold)
      Sets the clamping threshold used to suppress estimation errors when applying specular anti-aliasing.
      void setSpecularAntiAliasingVariance​(float variance)
      Sets the screen space variance of the filter kernel used when applying specular anti-aliasing.
      void unsetScissor()
      Returns the scissor rectangle to its default setting, which encompasses the View.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MaterialInstance

        public MaterialInstance​(Engine engine,
                                long nativeMaterialInstance)
    • Method Detail

      • getMaterial

        @NonNull
        public Material getMaterial()
        Returns:
        the Material associated with this instance
      • getName

        @NonNull
        public java.lang.String getName()
        Returns:
        the name associated with this instance
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 boolean x)
        Sets the value of a bool parameter.
        Parameters:
        name - the name of the material parameter
        x - the value of the material parameter
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 float x)
        Sets the value of a float parameter.
        Parameters:
        name - the name of the material parameter
        x - the value of the material parameter
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 int x)
        Sets the value of an int parameter.
        Parameters:
        name - the name of the material parameter
        x - the value of the material parameter
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 boolean x,
                                 boolean y)
        Sets the value of a bool2 parameter.
        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 float x,
                                 float y)
        Sets the value of a float2 parameter.
        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 int x,
                                 int y)
        Sets the value of an int2 parameter.
        Parameters:
        name - the name of the material parameter
        x - the value of the first component
        y - the value of the second component
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 boolean x,
                                 boolean y,
                                 boolean z)
        Sets the value of a bool3 parameter.
        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
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 float x,
                                 float y,
                                 float z)
        Sets the value of a float3 parameter.
        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
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 int x,
                                 int y,
                                 int z)
        Sets the value of a int3 parameter.
        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
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 boolean x,
                                 boolean y,
                                 boolean z,
                                 boolean w)
        Sets the value of a bool4 parameter.
        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
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 float x,
                                 float y,
                                 float z,
                                 float w)
        Sets the value of a float4 parameter.
        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
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 int x,
                                 int y,
                                 int z,
                                 int w)
        Sets the value of a int4 parameter.
        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
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 @NonNull
                                 Texture texture,
                                 @NonNull
                                 TextureSampler sampler)
        Sets a texture and sampler parameter on this material's default instance.

        Note: Depth textures can't be sampled with a linear filter unless the comparison mode is set to COMPARE_TO_TEXTURE.

        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
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 @NonNull
                                 MaterialInstance.BooleanElement type,
                                 @NonNull
                                 boolean[] v,
                                 @IntRange(from=0L)
                                 int offset,
                                 @IntRange(from=1L)
                                 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 set

        For example, to set a parameter array of 4 bool4s:

        
             boolean[] a = new boolean[4 * 4];
             instance.setParameter("param", MaterialInstance.BooleanElement.BOOL4, a, 0, 4);
         

      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 @NonNull
                                 MaterialInstance.IntElement type,
                                 @NonNull
                                 int[] v,
                                 @IntRange(from=0L)
                                 int offset,
                                 @IntRange(from=1L)
                                 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 set

        For example, to set a parameter array of 4 int4s:

        
             int[] a = new int[4 * 4];
             instance.setParameter("param", MaterialInstance.IntElement.INT4, a, 0, 4);
         

      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.String name,
                                 @NonNull
                                 MaterialInstance.FloatElement type,
                                 @NonNull
                                 float[] v,
                                 @IntRange(from=0L)
                                 int offset,
                                 @IntRange(from=1L)
                                 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 set

        For example, to set a parameter array of 4 float4s:

        
             float[] a = new float[4 * 4];
             material.setDefaultParameter("param", MaterialInstance.FloatElement.FLOAT4, a, 0, 4);
         

      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.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
      • setParameter

        public void setParameter​(@NonNull
                                 java.lang.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
      • setScissor

        public void setScissor​(@IntRange(from=0L)
                               int left,
                               @IntRange(from=0L)
                               int bottom,
                               @IntRange(from=0L)
                               int width,
                               @IntRange(from=0L)
                               int height)
        Set up a custom scissor rectangle; by default this encompasses the View.
        Parameters:
        left - left coordinate of the scissor box
        bottom - bottom coordinate of the scissor box
        width - width of the scissor box
        height - height of the scissor box
      • unsetScissor

        public void unsetScissor()
        Returns the scissor rectangle to its default setting, which encompasses the View.
      • setPolygonOffset

        public void setPolygonOffset​(float scale,
                                     float constant)
        Sets a polygon offset that will be applied to all renderables drawn with this material instance. The value of the offset is scale * dz + r * constant, where dz is the change in depth relative to the screen area of the triangle, and r is the smallest value that is guaranteed to produce a resolvable offset for a given implementation. This offset is added before the depth test. Warning: using a polygon offset other than zero has a significant negative performance impact, as most implementations have to disable early depth culling. DO NOT USE unless absolutely necessary.
        Parameters:
        scale - scale factor used to create a variable depth offset for each triangle
        constant - scale factor used to create a constant depth offset for each triangle
      • setMaskThreshold

        public void setMaskThreshold​(float threshold)
        Overrides the minimum alpha value a fragment must have to not be discarded when the blend mode is MASKED. Defaults to 0.4 if it has not been set in the parent Material. The specified value should be between 0 and 1 and will be clamped if necessary.
        See Also:
        Blending and transparency: maskThreshold
      • setSpecularAntiAliasingVariance

        public void setSpecularAntiAliasingVariance​(float variance)
        Sets the screen space variance of the filter kernel used when applying specular anti-aliasing. The default value is set to 0.15. The specified value should be between 0 and 1 and will be clamped if necessary.
        See Also:
        Anti-aliasing: specularAntiAliasingVariance
      • setSpecularAntiAliasingThreshold

        public void setSpecularAntiAliasingThreshold​(float threshold)
        Sets the clamping threshold used to suppress estimation errors when applying specular anti-aliasing. The default value is set to 0.2. The specified value should be between 0 and 1 and will be clamped if necessary.
        See Also:
        Anti-aliasing: specularAntiAliasingThreshold
      • setDoubleSided

        public void setDoubleSided​(boolean doubleSided)
        Enables or disables double-sided lighting if the parent Material has double-sided capability, otherwise prints a warning. If double-sided lighting is enabled, backface culling is automatically disabled.
        See Also:
        Rasterization: doubleSided
      • setColorWrite

        public void setColorWrite​(boolean enable)
        Overrides the default color-buffer write state that was set on the material.
        See Also:
        Rasterization: colorWrite
      • setDepthWrite

        public void setDepthWrite​(boolean enable)
        Overrides the default depth-buffer write state that was set on the material.
        See Also:
        Rasterization: depthWrite
      • setDepthCulling

        public void setDepthCulling​(boolean enable)
        Overrides the default depth testing state that was set on the material.
        See Also:
        Rasterization: depthCulling
      • getNativeObject

        public long getNativeObject()