Interface ManagedShaderEffect
- All Superinterfaces:
UniformFinder
- All Known Implementing Classes:
ResettableManagedShaderEffect
Post shaders loaded through ShaderEffectManager.manage(ResourceLocation, Consumer) are self-managed and will be
reloaded when shader assets are reloaded (through F3-T or /ladylib_shader_reload) or the
screen resolution changes.
Examples of json-defined shader effects are available in assets/minecraft/shaders.
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionfindSampler(String samplerName) Finds a sampler declared in json@Nullable net.minecraft.client.renderer.PostChainReturns this object's managedPostChain, creating and initializing it if it doesn't exist.voidInitializes this shader, allocating required system resources such as render target objects, shaders objects and texture objects.booleanbooleanChecks whether this shader is initialized.voidrelease()Releases this shader's resources.voidrender(float tickDelta) Renders this shader.voidsetSamplerUniform(String samplerName, int textureName) Sets the value of a sampler uniform declared in jsonvoidsetSamplerUniform(String samplerName, com.mojang.blaze3d.pipeline.RenderTarget textureFbo) Sets the value of a sampler uniform declared in jsonvoidsetSamplerUniform(String samplerName, net.minecraft.client.renderer.texture.AbstractTexture texture) Sets the value of a sampler uniform declared in jsonvoidsetUniformValue(String uniformName, float value) Sets the value of a uniform declared in jsonvoidsetUniformValue(String uniformName, float value0, float value1) Sets the value of a uniform declared in jsonvoidsetUniformValue(String uniformName, float value0, float value1, float value2) Sets the value of a uniform declared in jsonvoidsetUniformValue(String uniformName, float value0, float value1, float value2, float value3) Sets the value of a uniform declared in jsonvoidsetUniformValue(String uniformName, int value) Sets the value of a uniform declared in jsonvoidsetUniformValue(String uniformName, int value0, int value1) Sets the value of a uniform declared in jsonvoidsetUniformValue(String uniformName, int value0, int value1, int value2) Sets the value of a uniform declared in jsonvoidsetUniformValue(String uniformName, int value0, int value1, int value2, int value3) Sets the value of a uniform declared in jsonvoidsetUniformValue(String uniformName, org.joml.Matrix4f value) Sets the value of a uniform declared in jsonvoidsetupDynamicUniforms(int index, Runnable dynamicSetBlock) Runs the given block while the shader at the given index is activevoidsetupDynamicUniforms(Runnable dynamicSetBlock) Forwards tosetupDynamicUniforms(int, Runnable)with an index of 0Methods inherited from interface dev.cammiescorner.velvet.api.managed.uniform.UniformFinder
findUniform1f, findUniform1i, findUniform2f, findUniform2i, findUniform3f, findUniform3i, findUniform4f, findUniform4i, findUniformMat4
-
Method Details
-
getShaderEffect
@Nullable @API(status=MAINTAINED, since="1.0.0") @Nullable net.minecraft.client.renderer.PostChain getShaderEffect()Returns this object's managedPostChain, creating and initializing it if it doesn't exist.This method will return
nullif an error occurs during initialization.Note: calling this before the graphic context is ready will cause issues.
- Returns:
- the
PostChainmanaged by this object - See Also:
-
initialize
Initializes this shader, allocating required system resources such as render target objects, shaders objects and texture objects. Any exception thrown during initialization is relayed to the caller.If the shader is already initialized, previously allocated resources will be disposed of before initializing new ones.
- Throws:
IOException- See Also:
- ApiNote:
- Calling this method directly is not required in most cases.
-
isInitialized
@API(status=MAINTAINED, since="1.0.0") boolean isInitialized()Checks whether this shader is initialized. If it is not, next call togetShaderEffect()will setup the shader group.- Returns:
- true if this does not require initialization
- See Also:
-
isErrored
@API(status=MAINTAINED, since="1.0.0") boolean isErrored()- Returns:
trueif this shader erred during initialization
-
release
@API(status=EXPERIMENTAL, since="1.0.0") void release()Releases this shader's resources.After this method is called, this shader will go back to its uninitialized state. Future calls to
isInitialized()will return false untilinitialize()is called again, recreating the shader group.If the caller does not intend to use this shader effect again, they should call
ShaderEffectManager.dispose(ManagedShaderEffect).- See Also:
-
render
@API(status=STABLE, since="1.0.0") void render(float tickDelta) Renders this shader.Calling this method first setups the graphic state for rendering, then uploads uniforms to the GPU if they have been changed since last draw, draws the
main render target's texture to intermediaterender targetsas defined by the JSON files and resets part of the graphic state. The shader will beinitializedif it has not been before.This method should be called every frame when the shader is active. Uniforms should be set before rendering.
-
getTarget
-
setupDynamicUniforms
Forwards tosetupDynamicUniforms(int, Runnable)with an index of 0- Parameters:
dynamicSetBlock- a block in which dynamic uniforms are set
-
setupDynamicUniforms
@API(status=EXPERIMENTAL, since="1.0.0") void setupDynamicUniforms(int index, Runnable dynamicSetBlock) Runs the given block while the shader at the given index is active- Parameters:
index- the shader index within the groupdynamicSetBlock- a block in which dynamic name uniforms are set
-
setUniformValue
Sets the value of a uniform declared in json- Parameters:
uniformName- the name of the uniform field in the shader source filevalue- int value- See Also:
-
setUniformValue
Sets the value of a uniform declared in json- Parameters:
uniformName- the name of the uniform field in the shader source filevalue0- int valuevalue1- int value- See Also:
-
setUniformValue
@API(status=STABLE, since="1.0.0") void setUniformValue(String uniformName, int value0, int value1, int value2) Sets the value of a uniform declared in json- Parameters:
uniformName- the name of the uniform field in the shader source filevalue0- int valuevalue1- int valuevalue2- int value- See Also:
-
setUniformValue
@API(status=STABLE, since="1.0.0") void setUniformValue(String uniformName, int value0, int value1, int value2, int value3) Sets the value of a uniform declared in json- Parameters:
uniformName- the name of the uniform field in the shader source filevalue0- int valuevalue1- int valuevalue2- int valuevalue3- int value- See Also:
-
setUniformValue
Sets the value of a uniform declared in json- Parameters:
uniformName- the name of the uniform field in the shader source filevalue- float value- See Also:
-
setUniformValue
@API(status=STABLE, since="1.0.0") void setUniformValue(String uniformName, float value0, float value1) Sets the value of a uniform declared in json- Parameters:
uniformName- the name of the uniform field in the shader source filevalue0- float valuevalue1- float value- See Also:
-
setUniformValue
@API(status=STABLE, since="1.0.0") void setUniformValue(String uniformName, float value0, float value1, float value2) Sets the value of a uniform declared in json- Parameters:
uniformName- the name of the uniform field in the shader source filevalue0- float valuevalue1- float valuevalue2- float value- See Also:
-
setUniformValue
@API(status=STABLE, since="1.0.0") void setUniformValue(String uniformName, float value0, float value1, float value2, float value3) Sets the value of a uniform declared in json- Parameters:
uniformName- the name of the uniform field in the shader source filevalue0- float valuevalue1- float valuevalue2- float valuevalue3- float value- See Also:
-
setUniformValue
@API(status=STABLE, since="1.0.0") void setUniformValue(String uniformName, org.joml.Matrix4f value) Sets the value of a uniform declared in json- Parameters:
uniformName- the name of the uniform field in the shader source filevalue- a matrix- See Also:
-
setSamplerUniform
@API(status=STABLE, since="1.0.0") void setSamplerUniform(String samplerName, net.minecraft.client.renderer.texture.AbstractTexture texture) Sets the value of a sampler uniform declared in json- Parameters:
samplerName- the name of the sampler uniform field in the shader source file and jsontexture- a texture object- See Also:
-
setSamplerUniform
@API(status=STABLE, since="1.0.0") void setSamplerUniform(String samplerName, com.mojang.blaze3d.pipeline.RenderTarget textureFbo) Sets the value of a sampler uniform declared in json- Parameters:
samplerName- the name of the sampler uniform field in the shader source file and jsontextureFbo- a render target which main texture will be used- See Also:
-
setSamplerUniform
Sets the value of a sampler uniform declared in json- Parameters:
samplerName- the name of the sampler uniform field in the shader source file and jsontextureName- an opengl texture name- See Also:
-
findSampler
Description copied from interface:UniformFinderFinds a sampler declared in json- Specified by:
findSamplerin interfaceUniformFinder- Parameters:
samplerName- the name of the sampler field in the shader source file
-