Posts

Showing posts with the label custom render texture

scripting custom render texture creation, assignment, shaders

I got a little fed up of dragging the (wrong) custom render texture swatches onto materials in the inspector (slightly down to my crap naming conventions & Unity's project window only showing the first 8 letters of each name- can this be changed?!), so I decided to figure out a C# script that could make this easier. The entire script is way below - I'm just going to highlight a few important lines.   Shader shader = Shader.Find("custom/createdTextureShader"); This finds a shader that you've created externally. You could have a public shader variable at the top instead, so you could drop stuff into the Inspector.   _init_mat = new Material(init_shader);   Here we make a new material, using a specified shader type.  _init_mat.SetTexture("_initTex", init_texture); Then we give it a texture file. _initTex is a property I've specified for the init_shader. Typically there is a _MainTex by default. I just wanted to see if you could specify arbitrary p...

Custom Render Texture not updating when Double Buffered? WHY?

Image
There are two ways to fix this - one is in the update shader - make sure you have ZTest Always in your subshader block. OR (and I think this is something I was doing by accident, in order to make the custom render textures tile) you can disable depth on the custom render texture itself in the Inspector. This is probably a "well duh" to seasoned shader masters, but I must have spent 3 hours cursing Unity trying to figure out what was wrong. The other reason your CRT might not be updating is if you've set your initialisation to Realtime, which means it's always initialising!     SubShader     {                  Cull Off             ZWrite Off             ZTest Always         Pass         {    Name "update RD"    ...

Unity custom render textures

 It seems like Unity's Custom Render Textures provides much of the functionality that I'd want to create strange glitchy/feedback effects. The workflow is a little messy and nested, but we'll break it down here in text, cos I'm lazy to take screenshots. Firstly you have a material, which has a shader (could be anything), but importantly, it uses a texture - our custom render texture. The custom render texture itself takes a few different inputs - it needs a material to update it and "something" to initialise it with. The Initialisation could just be from a texture, but should you require something a bit more flexible, you can assign a material with a shader. Both the update material and intialisation material shaders are a little different to the ones I've been covering here, in terms of structure. This is because they're specifically operating within the custom render texture workflow. Firstly - the initialisation shader - Shader "customRT/init_s...