No announcement yet.

How can i render to texture?

  • Filter
  • Time
  • Show
Clear All
new posts

    How can i render to texture? trying to render a pass from my material to a texture..and use it in another material for blurring it? how it could be done?.thanks

    Material drawn to canvas into a scripted texture?


      Any other ways? I tried it but icant understand how it should work.


        it seems my hint of using a ScriptedTexture stuck on you... but the info thread wasn't clear enough. I usually don't share code because it usually leads people to copy and paste instead of learning, but here's a little something for you

        first you need a custom HUD class. I hope you're already using a custom game, in this case it's called MyGame

        I believe this is what will make your game use your custom HUD. the first function might not be needed but I remember having trouble getting my game to use my custom hud, so just leave all the code
        class myGameInfo extends UTGame;
        function GenericPlayerInitialization(Controller C)
        	if ( !bUseClassicHUD )
        		HUDType = class'MyGame.MyHUD';
        then you need your HUD class, where you'll create the scripted texture and render stuff to it
        my class has a lot more going on of course
        class myHUD extends UTHUD;
        var MaterialEffect MyPostFX;
        var Vector2D Resolution;
        var ScriptedTexture	MyScriptedTex;
        var MaterialInstanceConstant MySceneMat;
        var UTPlayerController UTPC;
        var() LinearColor ClearColor;
        //Called when this is destroyed
        singular event Destroyed() {
        	if (HudMovie != none) {
        		//Get rid of the memory usage of HudMovie
        		HudMovie = none;
        	MyScriptedTex = none;
        	MySceneMat = none;
        //Called after game loaded - initialise things
        simulated function PostBeginPlay()
        	UTPC = UTPlayerController(Owner);
        	MyPostFX = MaterialEffect(LocalPlayer(UTPC.Player).PlayerPostProcess.FindPostProcessEffect('MyPostEffectName'));
        //Called every tick the HUD should be updated
        event PostRender()
        	Resolution.X = (Canvas.ClipX);
        	Resolution.Y = (Canvas.ClipY);
        	// create the Scripted texture only once
        	if (!HUDLoaded)
        	// in some UDK builds the editor crashes when using a scripted texture
        	// if it does, comment the previous line and uncomment the following one:
        	//if (!HUDLoaded && !class'Engine'.static.IsEditor())
        		HUDLoaded = true;
        function CreateMyScriptedTex()
        	local MaterialInstanceConstant CanvasMaterial;
        	MyScriptedTex = ScriptedTexture(class'ScriptedTexture'.static.Create(Resolution.X, Resolution.Y,, ClearColor));
        	CanvasMaterial = new(self) class'MaterialInstanceConstant';
        	DynToneMap.Material = CanvasMaterial;
        	if (CanvasMaterial != None)
        		CanvasMaterial.SetTextureParameterValue('ScriptedTexture', MyScriptedTex);
        	MyScriptedTex.Render = MyScriptedRender;
        function MyScriptedRender(Canvas aCanvas)
        	MyScriptedTex = new(self) class'MaterialInstanceConstant';
        	aCanvas.DrawMaterialTile(MyScriptedTex , Resolution.X, Resolution.Y, 0, 0, 1, 1);
        	MyScriptedTex.bNeedsUpdate = true;
        	MyScriptedTex.bSkipNextClear = true;
        	HUDLoaded = false;
        this codes assumes you're using UTGame, and a UTPlayerController.
        for it to work you need a few things:
        - that your game uses a custom PostProcessChain
        - a material, where you'll be using your custom texture as if it's already rendered (ie. you apply your blur here!), which must be a TextureSampleParameter2D with a Parameter Name called 'ScriptedTexture'
        - a material instance of the previous material, called 'myEffects.PostEffectInstance' ("myEffects" is the package name)
        - a Material effect in your PostProcessChain called 'MyPostEffectName', that points to the material 'myEffects.PostEffectInstance' ("myEffects" is the package name)
        - a material that tell the custom texture what to render. for example if you want to have a copy of the scene, just put a Scene Texture Sample onto diffuse (ie. here is where you put your SSII nodes!)
        - a material instance of the previous material, called 'myEffects.MySceneIns' ("myEffects" is the package name)

        in case something doesn't work or just to clarify, and here's a little rundown of the process:
        1. you create a material of what you want to render to a texture, and then a material instance off it ('myEffects.MySceneIns')
        2. you tell the code to render your material into the canvas of a custom texture (function MyScriptedRender called every frame, the rest are just to initialize everything)
        3. before the render starts, the code makes sure to be using your CustomTexture as a TextureSample parameter (Param called 'ScriptedTexture') on whatever material you want it to appear (in this case a PostProcess effect called 'MyPostEffectName' which uses a material called 'myEffects.PostEffectInstance'), all because you want to use it as a postprocess
        4. enjoy and have fun

        hope that helps, looking forward to your IISS