Hi everyone !
I need to render the world normal (unperturbed / without normal map) of a landscape to a render texture in Editor for a tool i’m working on.
To do that, I thought I could spawn an orthographic scenecapture2D above it and aiming at it with correct dimensions and make it render to a render target with a Unlit material assigned returning only WS normals in color.
Coming from unity, I used to set replacement shaders for this kind of thing, but they seems to be missing in UE so I came with this function in a Editor utility BP :
Get Landscape => Swap its material with the WS normals one => Spawn SceneCapture2D actor with correct parameters => Make it render => Reassign back the base material.
My problem is that the result render target is inapropriate because it actually captures with the wrong material.
My guess is that rendering occurs on a different thread or at a different time of the frame so material swap hasn’t occured yet or already occured (Material is already swapped back)
Any idea on how to register in a Post Render event of this camera to workaround this ? Is there any Unity’s “replacement shader” feature equivalent that I could use ?
I also tried reconstructing normal from heightmap but I’d rather not be dependent of landscape resolution (+ it’s quite complex)
Thank you !
1 Like
How are you calling this function? Using Editor Utility? This seems to work for me:
Don’t forget to turn off the capture every frame option.
Are you sure you don’t want to use the heightmap to generate a normal map? There are fully functioning algorithms for this out there. Since you’re already dependant on the render target resolution, you could use a high-res landscape to paint on, then use a second lower-res landscape to apply everything to, for later use.
Thanks for answering!
This works if you do not try to reassign back old material after capture is done in the same loop…
My guess is that capture is performed after everything (rendering must occur in a separate tick or something). So reassigning material back fails the capture since it would be the one actually used then.
I need to generate ws normals and not tangent though (which heightmap to normal node make). I tried to dig on the web for algorithms that does this but I didn’t find anything that give result as smooth as capture method unfortunately…
I just wish I could register a callback after capture is done in ASceneCapture2D but i’m to novice with unreal and c++ to do so
Thanks for your answer !
This only works until you try to reassign old material back after capture. My guess is that the capture occurs at the end of the editor tick or in a separate thread (as most rendering do). So when you reassign material back, capture will be wrong because it would be shot after reassignment.
I need to generate World Space normals and not tangent as the UE material node do. I tried to dig some algorithms that do this reconstructing it using heightmap but I haven’t found any that gives results as smooth as the capture…
I just wish I could register a callback at capture end or even just be able to wait one tick before reassigning materials and follow up with the method but i’m to novice in Unreal and c++ to do so.
updated graph:
resulting 4k render target:
works for me…
Not sure if you’re aware of this, so I’ll just mention it; Landscape height maps have the same resolution as the landscape. I presume this is what leads to reduced smoothness on the normal map generation for you.
I think you just have to transform the resulting normal map in the material where you generate it.
The Unreal node is not accurate, I would not recommend using it. [Sobel Algorithm][3]
posting again because the pictures are missing… i think… answer hub is going crazy.
1 Like
Thanks, and sorry for double post, those two post were days appart tho…