Unity Community |

Hi,
i've got a simple and quick question. As 3.5 comes with MRT support, how can one write to the other render targets in surface shaders? Is it possible at all?
Thanks,
Lennard
Chickens Shader Bundle on the Asset Store and on Unitymagic
Nice Transparency shaders on the Asset Store
Follow me on twitter
Looking for custom shaders? Send me a PM.
Chickens Shader Bundle on the Asset Store and on Unitymagic
Nice Transparency shaders on the Asset Store
Follow me on twitter
Looking for custom shaders? Send me a PM.
Theoretically, I think you cannot switch or pick render targets from shaders (I'm no expert on the subject at all so take that with a grain of salt).
Though you can do this from script with methods such as:
Code:
and
Calling these methods before rendering passes that require separate/additional render targets should do the trick (for cameras, I'd try calling this in OnPreRender and OnPostRender methods but that's just a shot in the dark, haven't tried at all).
By the way, they're both documented in the offline beta scripting reference (you can access it from Unity's Help menu).
Edit: Actually, the Graphics.SetRenderTarget allows settings multiple render targets in one pass and the docs mention that "The function call with colorBuffers array enables techniques that use Multiple Render Targets (MRT), where fragment shader can output more than one final color.". If you cannot get these multiple outputs from surface shader, a last resort method may be to use "open compiled shader" method from one of your surface shaders where you want to use MRT and start from there.
Edit2: Okay, after educating myself on the subject, it seems there are no documented feature for what you're looking for in surface shaders. Looks like you could file a feature request.
Last edited by jemast; 01-28-2012 at 03:34 PM.
jemast software — http://jemast.com
Asset Store: iCloud for Unity - Mac App Store Toolset (coming soon)
Games: Children's Playground
Having MRT output for surface shaders would be nice, coupled with the newly included GL MIN/MAX blend modes would allow for some really nice methods of building info about the scene for much more complex post effects.
Probably use Graphics.SetRenderTarget(RenderBuffer[] ...
Then in your shader besides outputting a single Color you would output a custom struct
struct COL_OUTPUT
{
float4 Col0 : COLOR0;
float4 Col1 : COLOR1;
float4 Cor2 : COLOR2;
};
and in your shader
COL_OUTPUT frag(v2f i)
{
COL_OUTPUT o;
... shader stuff
o.col1 = something;
o.col2 = something;
o.col3 = something;
return o;
}
If you like my demos a small donation would be appreciated.
Now on sale in the asset store
V-Lights Volumetric Light Package
V-Fog Volumetric Fog Shapes
Well, if i haven't missed anything this is not possible to achieve with surface shaders. Of course it's possible to return multiple results in standard cg vert/frag shaders, but i don't think anybody wants to convert all the surface shaders to standard ones using debug and in addition this would kill all the nice things surface shaders have to offer...
Chickens Shader Bundle on the Asset Store and on Unitymagic
Nice Transparency shaders on the Asset Store
Follow me on twitter
Looking for custom shaders? Send me a PM.
as far as i know there is no easy way to make it work with surface shaders atm. but there is a way: uncollapse them via #pragma debug and then write for the various passes to the different buffers, just as brianasu suggested.
EDIT: saw your post too late, but yes, for the time being MRT support mostly addresses possible post and custom FX speed-ups.
ole,
you plan to implement the builtin imagespace motion blur effect?