#Drawing a material to a texture in an importer using URP
1 messages · Page 1 of 1 (latest)
I wonder if for my case I could skip the blit family of functions and use CoreUtils.DrawFullScreen... (brb trying that)
Hmm, same results, sparkly BS with CopyTexture and plain black without
CopyTexture's output reminds me of unallocated memory, perhaps just garbage data floating around on the gpu
yep definitely looks like such
Maybe try a sanity check: have your blit shader output just the color red or something
See if it's just _BlitTexture not being assigned for whatever reason
my blit shader is just that, I don't even declare the _BlitTexture
Huh
Shader "Hidden/Keen Vectors/Blit Bezier"
{
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"}
ZWrite Off
Cull Off
Pass
{
Name "ColorBlitPass"
HLSLPROGRAM
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#pragma vertex Vert
#pragma fragment frag
float4 frag (Varyings input) : SV_Target
{
return float4(0, 1000, 0, 1);
}
ENDHLSL
}
}
}```
(i mean it will not be that in the end, but i haven't even began writing the shader part of this thing)
Yeah, makes sense..
Try to debug.Log() in the importer. Maybe print the front.rt variable, see if it's null, and if it isn't see what it's dimensions are
Maybe the RTHandle isn't being created correctly?
the render texture looks alright, but now looking at the handle its weird that the referenceSize is 0
even though the system's reference size is non 0
(i changed the naming around since with DrawFullPass i dont need to double buffer)
That sounds like it would do it, might be setting the texture's viewport to be 0x0 pixels
Explaining why outputting a solid color in the fragment shader doesn't even work
at that same point the system has a non 0 reference size though
Is it possible to set a handle's reference size directly? Just to check?
maybe, it has a SetCustomHandleProperties method
Another idea depending on how that goes, looking at the static Blitter class, it seems that the bitter as well needs an Initialize method. (Since it's a static class presumably it's called by the render pipeline automatically by the time you're in a monobehaviour)
hmm, nope
Try calling Blitter.Initialize()
It could be that the importer is so seperate from everything that there isn't even an initialized static class of blitter yet
true, but i'm not even using Blitter anymore, just CoreUtils 
xD
it looks a bit magical, CoreUtils.DrawFullScreen calls CommandBuffer.DrawProcedural with a vertex count but i have no idea where those vertices come from
Okay.. Best lead so far is that the textures themselves are the problem, since Blitter isn't involved, and copying them leads to garbage data.
yep
RTHandle shouldn't even be the problem, since we are bypassing most things with CoreUtils()
what is a very common texture format for vulkan? as a test I just tried RenderTextureFormat.R8, which despite the fact i would not be able to use for my actual application, also yields a pure black texture. so i don't think the exotic 128bit per pixel format is to blame
well DefaultFormat.LDR is also black so i don't think its the formats fault anyways, i play video games in this GPU so i'm quite certain it supports at least one LDR rgb format lol
Shouldn't be the format, hopefully.
Uhh. Maybe try using plain Rendertextures in the built in RP, to see if it works at all?
ah
that's probably a good idea lol
i can just unassign the RP asset in the project settings right?
Yeah I think so
hmm, the plot thickens
var renderTexture = new RenderTexture(128, 128, GraphicsFormat.R32G32B32A32_SFloat, GraphicsFormat.None);
var brush = new Material(Shader.Find("Hidden/Keen Vectors/Blit Bezier"));
RenderTexture.active = renderTexture;
Graphics.Blit(Texture2D.whiteTexture, renderTexture, brush);
ctx.AddObjectToAsset(nameof(renderTexture), renderTexture);```
that should be about it, no?
Something along those lines yeah
i now get the warning "Releasing render texture that is set to be RenderTexture.active!"
and i'm definitely not destroying the RT at all, this is all the code of my OnImportAsset currently
Probably happens when the importer ends, and tries to cleanup anything left over
Like when the scope changes
yeah maybe it just doesn't like render textures in it
Still all black?
aye
also tried sticking a Graphics.CopyTexture(renderTexture, output); to a texture2d of same dimensions and format and export that, the warning is gone but the output is still black
Grasping at straws now.. Maybe the shader doesn't work anymore since you swapped to built in?
Like perhaps the vertex function provided by blit.hlsl only works on URP
thought so too, it is now even simpler: ```Shader "Hidden/Keen Vectors/Blit Bezier"
{
SubShader
{
Tags { "RenderType"="Opaque"}
ZWrite Off
Cull Off
Pass
{
Name "ColorBlitPass"
HLSLPROGRAM
#pragma fragment frag
float4 frag (Varyings input) : SV_Target
{
return float4(100, 100, 100, 1);
}
ENDHLSL
}
}
}
still black
i'm gonna make a new empty project lol, maybe unity is cursed
That shader actually shouldn't work
Nowhere is Varyings defined, neither is a vertex function
That's kind of weird too
lovely isn't it
and by lovely i mean i want to scream at a wall
Isn't graphics programming just wonderful
ok there were secret warnings on the shader asset itself
Ahhh
can i just return void from the vertex function?
I see
unity doesnt complain
but then again
it doesnt have a good track record at this point in time
you could probably just throw on the default image effect shader from the asset create menu
It just inverts colors
nope, all black
(i edited the default image effect to always output white)
"you might not like it but this is what peak graphics programming is like"
alright so on a clean, built in (not even Core RP package is installed) renderer, its also black 🤓
"We love graphics programming"
That's both reassuring and demoralizing.
It's not URP's fault
But now it could be anything
at this point im almost writing this 💩 on the CPU
How fast does this asset importer even need to be? They can't stop you from writing it on the CPU...
well i plan on selling this so i would hope to not completely obliterate editor performance
if only the frame debugger / RenderDoc could work on asset importers
indeed
or at all, i'm on linux and even though we have renderdoc, unitys integration specifically has an "if not linux" setting
Damn.
This is starting to seem like a question for the forums / unity developers. (Assuming they respond)
I'm pretty sure my knowledge doesn't extend far enough to help much more here, aside from being a second set of eyes
:0
never have i been so happy to see a white square
Oh my god
That must feel good
var buffer = new RenderTexture(128, 128, GraphicsFormat.R32G32B32A32_SFloat, GraphicsFormat.None);
var source = new Texture2D(...);
var output = Instantiate(source);
var brush = new Material(Shader.Find("Hidden/CLOWN"));
Graphics.Blit(source, buffer, brush);
RenderTexture.active = buffer;
output.ReadPixels(new Rect(Vector2.zero, new(buffer.width, buffer.height)), 0, 0);
output.Apply();
RenderTexture.active = null;
this works, on built in empty project (shader = image effect set to return 1,1,1,1)
now i'll try backtracking
and to be sure, its not a white default color either, it is the shader. this is fixed4(sin(i.uv.x),0,0,1)
Nice
The cat wishes you luck integrating with URP
backtrack step 1. same code works on the actual project in builtin, so it's not some satanic haunted setting
with the blessing of their supreme power, i shall persevere. i am filled with DETERMINATION
backtrack step 2. added the URP back onto the project settings, still imports fine with clown shader
backtrack step 3. straight up Graphics.Blit works with the clown shader
i wonder if unity is doing some shenanigans, gotta restart it to ensure its not using builtin or something behind the scenes
Understandable
yep, restarted and it still works
backtrack step 4. _commands.Blit(_canvas, _canvas, material, pass) works (?! it doesnt even complain of reading and writing to the same thing anymore)
i am glad to declare
Backtrack Complete 
thank you so much again Kabinet for your technical and emotional support, as well as your cat
also thanks Joachim Ante for founding the abomination that dominates my professional life otherwise known as Unity
what was I doing wrong? i have absolutely no clue