# Shader Effects on a Texture

**URL:** https://forum.castle-engine.io/t/shader-effects-on-a-texture/1259
**Category:** News
**Created:** [July 2, 2024, 5:09pm UTC](https://forum.castle-engine.io/t/shader-effects-on-a-texture/1259 "2024-07-02T17:09:36Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [July 2, 2024, 5:09pm UTC](https://forum.castle-engine.io/t/shader-effects-on-a-texture/1259/1 "2024-07-02T17:09:36Z")

</div>

| [![Shader Effects on Texture](https://forum.castle-engine.io/uploads/default/original/2X/e/e59eeb5935804cd271bcbda30ebd71908663cc83.png)](https://castle-engine.io/wp/wp-content/uploads/2024/07/screenshot.png "Shader Effects on Texture") |

First of all, sorry for a relatively silent last month when it comes to the _Castle Game Engine_ news. It was actually an incredibly busy June, and I’m going to prove it by posting lots of news in the upcoming days 🙂

Let’s start with a new example, [Shader Effects On Texture (examples/viewport\_and\_scenes/shader\_effects\_on\_texture)](https://github.com/castle-engine/castle-engine/tree/master/examples/viewport_and_scenes/shader_effects_on_texture). This example demonstrates how you can process colors (and alpha) coming from a texture using a shader, for basically any processing that is conceptually _“I wish this texture would look like this”_. For example you can tweak texture colors, you can perform any texture transformation, you can mix the texture with basically anything (like another texture or an animated effect), you can calculate some channel based on others (e.g. [calculate alpha based on intensity of RGB colors](https://forum.castle-engine.io/t/image-black-edge-blending/1245/10)). At the core, you just [write a shader using GLSL that defines a function with magic name `PLUG_texture_color`](https://github.com/castle-engine/castle-engine/blob/master/examples/viewport_and_scenes/shader_effects_on_texture/data/shaders/texture_effect_sepia.fs), so it’s really simple to start with some 1-line snippet, but you can explode it to do any crazy effect that GPU can handle 🙂

The interesting Pascal code of this example is rather simple and limited to the [GameViewMain unit](https://github.com/castle-engine/castle-engine/blob/master/examples/viewport_and_scenes/shader_effects_on_texture/code/gameviewmain.pas), it comes down to processing the scene, finding textures (`TAbstractSingleTextureNode` instances), and adding the effects. You can add any effect to any texture in any scene. The possibilities for tweaking this to your needs are vast:

- 

- You can apply the effect to any textures there (to detect which texture is which, use e.g. `TAbstractTexture2DNode.TextureUsedFullUrl` once the texture is loaded; set `TAbstractTexture2DNode.IsTextureLoaded` to `true` to force loading it now; use `TImageTextureNode.FdUrl` to look at specified possible URLs of the texture; as you can see there are a few useful texture classes involved, take a look at `TImageTextureNode` and all its ancestors for all the goodies),

- You can add multiple effects, no problem. The `PLUG_texture_color` function name is “magic”, as mentioned before — you absolutely can have multiple effects using it on one texture. The engine will internally transform it into a working shader code, integrated with full shape rendering code.

- If you would like to ignore the original color read from texture image, sure -\> you can. 

As always, follow the [README of the example](https://github.com/castle-engine/castle-engine/tree/master/examples/viewport_and_scenes/shader_effects_on_texture#readme) to know all the details.

See also the associated [Using Shader Effects to implement rendering effects that enhance the standard rendering (examples/viewport\_and\_scenes/shader\_effects)](https://github.com/castle-engine/castle-engine/tree/master/examples/viewport_and_scenes/shader_effects). It shows applying shader effects over shapes and scenes, independently of the textures. All the possibilities are in [Shader Effects (Compositing Shaders)](https://castle-engine.io/compositing_shaders.php) documentation, in particular see [Reference of available plugs](https://castle-engine.io/compositing_shaders_doc/html/appendix.plugs.html) to know all magic `PLUG_xxx` functions.

As always, have fun and we ask for [your support on Patreon](https://www.patreon.com/castleengine)! I hope we’ll all have a very fun, and _very_ productive vacation 🙂
