#archived-shaders

1 messages ยท Page 10 of 1

kind juniper
#

Does the GPU generate the lod levels automatically?๐Ÿค”

regal stag
#

It samples each mipmap level of the texture (lower resolution versions). I don't know how the gpu stores/connects them exactly but it's different from an array which requires each slice to be the same dimensions.
To sample an array you'd use
SAMPLE_TEXTURE2D_ARRAY(texture, sampler, uv2, slice) or
SAMPLE_TEXTURE2D_ARRAY_LOD(texture, sampler, uv2, slice, lod)

meager pelican
#

You're using time and a sine function, so that will return negatives. Try adding a saturate node before plugging it into the color. Just a thought.

kind juniper
meager pelican
#

Like Uri said. lol ๐Ÿ˜‰

regal stag
mental bone
kind juniper
#

Since the two legends have gathered here, do you mind having a look at the thread that I created yesterday?@regal stag @meager pelican

meager pelican
#

Good. But what I still don't understand is why it is so different between scene view and game view and the game view is the one that worked.

mental bone
#

oh guys btw if you remember my elipsoid vertex clip problem. Turns out position node returns post skinned positions that are in who knows what space so I had to bake the pre-skinned ones into a extra uv channel to get it to work

regal stag
kind juniper
meager pelican
regal stag
kind juniper
#

Using a texture array would've been more convenient from several points though.๐Ÿ˜ฎโ€๐Ÿ’จ

regal stag
kind juniper
#

Because I need it sampled in the vertex stage and it doesn't seem to work.

#

I want to interpolate the sampled data

#

Using custom interpolators.

regal stag
#

It should work if you use SAMPLE_TEXTURE2D_ARRAY_LOD(texture, sampler, uv2, slice, lod)

kind juniper
regal stag
#

Of course ๐Ÿ™‚

kind juniper
#

I'll give it a try.

mental bone
#

yeah thats for sampling in the vert stage

#

but you have to provide mip level yourself

meager pelican
#

Wow. A bit out of my league too, but I'll give you some paths to track.

The graphics system includes a FENCE for deciding on when execution of a given routine has been completed for all processors. It's kind of a "Lets all wait here until EVERYONE is done". That exists on the individual core level, but there's also a level in the graphics pipeline itself.
https://docs.unity3d.com/ScriptReference/Rendering.GraphicsFence.html
(more in next post)

kind juniper
#

I knew about the Texture2D one, but didn't think there's one for an array.

mental bone
#

as far as I understand texture arrays they are nothing more that a old school texture atlas laid out sequentially in memory so in a way they are a Texture2D

kind juniper
meager pelican
#

IDK of any "common workflow" to keep the data serialized from a render texture. I mean, other than read-back and storing in a serialized object.

There's not even any guarantee that the GPU won't discard the whole thing during some massive OS operation and demand the texture gets reloaded again by the engine!

kind juniper
#

At any point.

meager pelican
meager pelican
kind juniper
regal stag
kind juniper
kind juniper
meager pelican
meager pelican
native otter
#

I'm mistaken to use the word 'texture', I think it's more clear if I use 'image'.
My goal is to change the image tint a little bit. For example I have an image of some green branches, I want to slightly change to another green tint by the objects position.

#

Maybe I'm doing it correctly already with the hue node, but I wanted to pick different tint colors with the gradient myself, if that is common to do.

meager pelican
#

So "just" pick your tint color out of the gradient, and multiply your leaf pixels by that tint color. But if the leaf starts out as only green, the result will only have a green channel in it. Whereas if it is grey-scale leaf, it can have nice fall colors with reds and even blues if you want them.

#

You can do masks and stuff too if you're working with an actual image and not a model.

native otter
#

I understand. Thank you. I will try something. In this case it's a pine tree texture, so I want to make it very slightly ๐Ÿ˜‰

meager pelican
#

You could just vary the green channel by a random amount....

native otter
#

I will try..

meager pelican
# native otter I will try..

I should mention too that you can do a luminescence calc and then multiply, or just use the green channel value as the luminescence. There's a node for luminescence/grey-scale in SG. So you don't have to really have an original image that is B&W because you can calc the B&W value from it.

native otter
native otter
meager pelican
#

You'd have to scale the random result range to match the expected sample gradient input

kind juniper
#

Hey, so maybe a stupid question, but can I use a RenderTexture as a Texture2DArray?

#

If I have an RWTexture2DArray<float4> on hlsl side, will a RenderTexture bind to it properly?

meager pelican
kind juniper
#

I'm getting this error if I try to bind a Texture2DArray. I guess it does not allow writing to it in compute shader?๐Ÿค”

#
Compute shader (TerrainBaseGenerator): Property (Splatmaps) at kernel index (0): Attempting to bind texture as UAV but the texture wasn't created with the UAV usage flag set!
meager pelican
kind juniper
#

Yeah, but Texture2DArray does not have that property

#

Render textures have enableRandomWrite which I've been using successfully, but it seems like regular textures are not meant to be written to in compute shaders.

meager pelican
#

Right, use a render texture.

#

I missed that you weren't using an RT

kind juniper
#

I guess the issue was that I though of an RT as a special version of Texture2D

#

But it seems like it can be any kind of texture: 2d, 3d, array

meager pelican
#

It is special, it's writable. lol ๐Ÿ˜‰

kind juniper
#

Yeah, but the point that I was missing is that it can take many forms.

meager pelican
#

Yeah. I haven't used that much, but from what I read...yeah. So each element is an RT, of the same size and I think same format.

kind juniper
#

ugh... But the regular shader still considers it as a Texture2D it seems.๐Ÿค”

#
Error assigning 2D texture to 2DArray texture property '_Splatmaps': Dimensions must match
#

nvm. I had to explicitly set the dimension property. Thought that it was inferred from the constructor.

meager pelican
#

And then there's full blown 3D textures, although IDK if you can write them in a shader. EDIT there's an isreadable flag on them.

kind juniper
#

Yeah, that part I've figured out some time ago ๐Ÿ˜„

native otter
ocean bough
#

was busy for a few days, but I tried doing this in an empty scene now, and it doesn't seem like it works.

It renders the fore and background in a camera, it uses a volume with DoF
I add an overlay camera on this other camera, to only render the middleground without DoF.
The overlay camera gets rendered, but it doesn't place itself between the other layers. just goes on top. I'm not sure if I missed some setting or anything, but I can't seem to get it work no matter what i play with in priority/depth/culling

#

keep in mind i cant select dont clear on the overlay camera, only on the normal camera(that renders the fore and back) - where its called clear depth

#

ill show you some pics of the settings if you'd like.

#

it is possible to enable/disable these things btw in the render file. I can play with this in a shader using _CameraDepthTexture (and CameraOpaqueTexture)

meager pelican
ocean bough
#

an update: i just realized background color places a full color on a stack of cameras, covering stuff in the "back". ALSO- the lights in 2D clears the color to black

meager pelican
#

IDK if that makes sense.

meager pelican
ocean bough
#

Yep understood, I think you're on a good path to it though, so I'll keep trying

#

will keep posted

meager pelican
violet bough
#

Is there a way to make the _Time variable in shaders not stutter in the editor while play mode is turned off?
Are there some settings for maybe either pausing it or making it update properly?

native otter
regal stag
regal stag
quick cape
#

How do I get random numbers in my ComputeShader?

#

I tried Everything

#
float random = scaleToRange01(hash((uint)23523*time*id.x));

uint hash(uint state)
{
    state ^= 2747636419u;
    state *= 2654435769u;
    state ^= state >> 16;
    state *= 2654435769u;
    state ^= state >> 16;
    state *= 2654435769u;
    return state;
}

Debug.Log confirms that the time value on the Shader side is definitely the FixedTime value

#

So even though my hash() function gets different inputs everytime

#

I still get the same freakin number out....

#

Omg I think I figured it out

#

I am multiplying it by 0 since my first id.x is 0

#

Yeaaaaahhhhh

#

Not my brightest debug moment >w<

long moat
#

Hello! can someone help me with original code based shaders? i understand nothing about them and all i wish is to add glossiness to a distortion shader

#

This is the distortion shader:

#

the goal is to basically reflect light based on the normal map, the shader only distorts whatever is below it

#

I would really appreciate if someone could help me out

meager pelican
# long moat Hello! can someone help me with original code based shaders? i understand nothin...

Maybe start with some default environment reflections.
From here:https://docs.unity3d.com/2017.4/Documentation/Manual/SL-VertexFragmentShaderExamples.html

// refection vector calculated in vert() and passed in
// v2f's i.worldRefl member via 
// o.worldRefl = reflect(-worldViewDir, worldNormal);

// sample the default reflection cubemap, using the reflection vector
half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
// decode cubemap data into actual color
half3 skyColor = DecodeHDR (skyData, unity_SpecCube0_HDR);
// output it!
fixed4 c = 0;
c.rgb = skyColor;
return c;```
You can't just "paste that in" but it's an example of environment reflections in a vert/frag shader. 
You have a world-space normal vector already, and can use that calc in the comment above to pass along a world-reflection vector in the v2f struct.  Sample it per pixel in the frag(), decode it, and decide what you want to do with it when applying it to your result.
long moat
#

i mainly need only this shader with light reflection/gloss, everything else uses regular standard material

#

everywhere i search it seems it is impossible to make a transparent shader to be glossy

long moat
#

along with that, why is that in game the distortion looks timid

#

while in editor it looks much better?

meager pelican
#

Hmm...IDK, play with the power and refraction settings maybe.

As for your shader, I literally copy/pasted it into notepad and edited in the changes for you. This is a rare thing, as I don't usually code stuff for others in discord questions, that's something you need to learn to do, so I want to be clear...no warranties. I haven't even loaded this into Unity so there could be syntax errors. But here it is, attached as a file.

#

And that line near the end with the 0.5 hard coded in it should have said:
vDistortColor.rgb = saturate(vDistortColor.rgb + skyColor * _ReflectionPower);

long moat
#

omg thank you so much, ill try it now ๐Ÿ˜

#

btw changing power does not help..

#

for some reason ingame camera gives different visual effect

#

hmm yes its not working as you warned ๐Ÿ˜…, ill try to go over and search for syntax errors

meager pelican
#

Did you get a error-pink result?

#

Make sure to fix that one line...

long moat
#

pink shader yes

meager pelican
#

let me know the error in the console

long moat
meager pelican
#

Oh, that's not too bad for notepad. lol

#

Let's see.

long moat
#

ok i did not noticed you also added .rgb, so i added it now, no errors but still pink shader

#

This error did remain, reapplied the shader:

meager pelican
#

Yeah, I just tracked that down. I missed a semicolon.
o.vReflectionWS = reflect(-worldViewDir, o.vNormalWs); Needs a semicolon on the end.

#

It's line 88 in the file.

#

That's what I get for using notepad. lol

native otter
#

I saved my .fbx object with multiple uv maps. I was wondering if I could change those to my liking in shadergraph?
(blender example)

#

I must be googling the wrong keyword, because I cannot find anything about switching uv maps.

meager pelican
mental bone
#

Uv node has a little dropdown that lets you sellect a uv set

meager pelican
#

I think they want to do it programmatically/dynamically.

long moat
meager pelican
long moat
native otter
meager pelican
#

lol

#

I'm sure there's a reason.........

#

somewhere

#

๐Ÿ˜‰

#

It's a common...observation...

long moat
meager pelican
#

Let's start from the top.
What shape is that mesh that you're applying this shader to?

long moat
#

simple quad

meager pelican
#

OK, put it on a sphere instead

#

Just as an experiment

#

Turn off the quad

long moat
#

i mean, i do have that preview window for shader that is a sphere

meager pelican
#

Nah, in scene.

long moat
meager pelican
#

OK, that's exactly what I think you asked for, but sounds like it's not what you wanted. ๐Ÿ˜‰

#

Now it has environmental reflections based on the OBJECTS normals (which is what that shader does).

long moat
meager pelican
#

They're not great reflections, but they're reflections. And it is distorting the background.

#

OK, we can mess with our calcs. Sec, afk.

long moat
#

i tried raising refraction and power and it never reaches the same effect

meager pelican
#

But there's another problem...

long moat
#

it doesnt have to reflect the enviroment, only light sources, i already have underneath a shader that does planar reflection

#

mm ill try to show you what i mean, one sec

#

in another game, I have these cobblestone that reflect the orange light above them, it gives off this highlight effect

#

you can see it also here with the blue light on the wet ground

meager pelican
#

OK, let's talk about "The other problem".

#

The shader you started the question with is a shader that takes an object, like that sphere, and distorts the background behind it.

#

It does that with a grabpass.

long moat
#

ill be back in a moment ๐Ÿ˜…

meager pelican
#

OK.

#

So what it does is take a screen shot and then distorts it. It doesn't know anything about the normal vectors (although there is such a thing as screen-space normals) of what was drawn behind it.

#

So I assumed you wanted lighting on, say, a sphere or whatever. At first. And that's what stuck in my head. And then you posted screen shots, but I didn't realize that what you actually wanted was a post processing effect or something to distort the WHOLE SCREEN.

#

So let me get this figured out. You are putting this on a quad the covers the screen? Yes?

visual gull
#

Hey guys, I hope you're doing well. Does anyone knows why my preview is pink ? I followed a youtube tutorial but it doesn't seem to be working for me

meager pelican
visual gull
#

I don't know where the problem could be coming from (i absolutely suck at shaders ^^'), maybe a missing package ?...

visual gull
meager pelican
#

Graphics settings.

long moat
meager pelican
#

So this is 2D?

#

Or no?

long moat
#

yup 2D

meager pelican
#

Crap on a cracker.

long moat
#

i mean, the tile is

meager pelican
#

I don't do much 2D

#

lol

long moat
#

the world is 3D in my game

meager pelican
#

OK

long moat
#

its a mix of both

#

some call it 2.5D

visual gull
#

Graphics settings

long moat
#

so its impossible to give the same bumped normal tile effect on a transparent shader?

meager pelican
#

well....we're talking about..."Who's normals?"

#

The normals on a quad...are all the same flat normals. You seem to be saying you want the normals of the object drawn BEHIND the quad.

long moat
#

i guess to sum it up, im trying to achieve the pool water shader, its transparent with distortion and it does reflect light

long moat
meager pelican
#

OK, that's better. We're actually still on the right track, and I'm going to buy a lottery ticket because I'm getting convinced I'm psychic or something. lol ๐Ÿ˜‰

#

So we DO want normals on your quad

#

But you want to use a normal map passed in.

long moat
#

glad to hear you are interested on it as much as i do ๐Ÿ˜

meager pelican
#

And you don't care about the normals on the background, but you're distorting based on water surface normals.

long moat
#

the only texture/map the shader will have is the normal map

long moat
#

what do you mean by "And you don't care about the normals on the background"?

meager pelican
#

You don't care about the normal direction of that block under the water.

#

It doesn't matter anymore

#

You care about the water surface normal and how it distorts the background

long moat
#

mm i dont think so.. for the most part, everything below the shader will be flat textures with single normal upwards

meager pelican
#

And when you put the new shader on it, with environment reflections, all you got was a lighter version.

long moat
#

yes overall slightly brighter

#

basically i decide the brightness with the reflection power slider

meager pelican
#

Right on all counts. And that slider is the same for all pixels, which isn't what we want.

#

But we'll keep it, because it scales the whole effect.

#

So with your normal map, we have to calc how relfective the angle is...that brings us back to blinn-phong or some such calc

long moat
#

how does it work on regular shader with high metallic, low smoothness and with a normal map?

meager pelican
#

OK, that's PBR lighing. And it's a bit more complicated.

#

You probably don't need that for mostly-transparent water, FYI.

long moat
#

so its not something that will work on a transparent shader

#

so how does anyone make a transparent shader with light reflection by normal map? even without distortion

#

or does distortion also play huge role on it?

meager pelican
#

It will work but it's more complex and slower.
Hell, you can probably do it in a surface shader.

#

I seem to remember someone having a transparent wall of some sort that distorted stuff behind it.

long moat
meager pelican
#

Probably. But PBR is overkill for water, IMO.

long moat
#

if its slower then i better avoid it

meager pelican
#

AFK for a bit

long moat
#

so what is the other option?

#

ok

meager pelican
#

Well, we have environment reflection information now (just the color of the walls/sky/whatever from the reflection probe).
We don't have the main light direction, nor its intensity/color. Yet.
And we have most of the info we need to calculate specular reflections.

#

And we already have some type of distorted background, even if it isn't scaled like you want it yet.

#

Do you want actual waves? Or just the color distortion. In other words...at the edges of the pool...right now they will be flat due to using a flat quad.

long moat
#

well the normal map animation already has this sort of pixelated wave

#

what do you mean by color distortion?

meager pelican
#

By that I mean that you don't pick the pixel directly behind, you pick a different one, causing distortion effect based on mormal mapping.

long moat
#

edges of the pool? if by that you mean the edges of each quad then no, itll look blocky... if its somehow when the shader touches a surface, I guess itll look nice

meager pelican
#

There's multiple quads?

long moat
#

tiles of water

meager pelican
#

OK, but...I guess what I'm asking is...
Are those different pools, or do you have, say, a 10 x 10 grid of tiles in that one pool pic you showed me?

long moat
#

umm, its both, its basically and island and there are water tiles both in and outside the island

#

this is basically the standard shader with blue color and the normal map that i use on water

#

so i mainly need it to reflect the pink pixels and everything else remains transparent

meager pelican
#

We should have started a thread.

long moat
#

i agree ๐Ÿ˜…

meager pelican
#

I'm going to recommend that we do one of two things now.

  1. Start a thread so we don't keep flooding this main thread. But I won't be able to continue following it up alone, others will have to jump in, as I'll be at work.
  2. check out various tuts for water shaders for BiRP. They have some methods for dealing with all this stuff so we don't have to reinvent the wheel. For example, they make waves by vertex displacement of a plane that has a lot of triangles, they do the waves in the shader, add caustics if you want them, etc.
    Unity even ships with some standard water shaders you can try.
long moat
latent inlet
#

hi, using TextMesh Pro, whenever I switch the shader of a text, it also changes the shader of all texts elements to that new shader, any help? I want all texts use one TMP shader, but one text to use another.

timber isle
#

What would you suggest for writing a shader if your looking for low level access?

olive aspen
#

Guys why is the structuredbuffer here not blue:

#

It also gives me this error:

timber isle
olive aspen
#

no, what is that

#

?

timber isle
#

An assembly reference tells unity that you want to use an assembly outside of your project assembly

#

I'll find an example

violet bough
#

anybody any idea why this could be happening? I had a bug and tracked it down to sampling a render texture that i render my scene to

#
base.rgb = _PixelTex.Sample(point_clamp_sampler, i.screenUV).rgb;
return base;
olive aspen
timber isle
timber isle
olive aspen
#

I uh need to look those up because I do not know what an assembly is

#

Kind of overwhelming at this point, I do not know where to start learning this advanced stuff

timber isle
#

Just learn what you need as you need it...

olive aspen
#

Yep, that is what I'm doing now thank you

timber isle
#

How much difference is there between CG and HLSL?

pale python
#

Does anyone knows how to stop this from happening ?? .. I dont want the texture to get stretched like that, I rather want it to get repeated/tiling across the surface area available.

My current material is made of just 1 texture and it it's connected to the base.
the material is made by Unity shader graph and its ulit type
( the scene is using urp ).

ocean bough
# meager pelican could be a 2D thing, I don't do much of that. Like I said it was a guess as to ...

ive sat all day with this now and i never actually came to a solution with your workaround, mainly the problem being that i could never get rid off the automatic clearing of the scene color in rendering. i just think unity 2d simply cannot do this with semi transparent assets. it would've worked if i had more control with opaque techniques

I kept searching around for ways to do it in a shader instead but i just simply couldnt find any way of making a really nice gaussian blur, the problem being sampling it correctly.

Stumbled upon this article, which is an actual goldmine. He explains how they tried several methods of doing EXACTLY what I've been trying to do, and in the end deciding to roll with the method of using separate files with baked blur directly in photoshop, in the end showing up to be a way more performant and actually not at all memory issue. So I'll be rolling with this. Makes it a lot simple to handle everything too shrug
https://80.lv/articles/depth-of-field-in-unity-for-2d-games-with-semi-transparent-sprites/

The Co-Founder of The Sixth Hammer Dimitar Popov has shared the company's findings on setting up DoF Blur in 2D games, discussed the problems they faced, and how they overcame the challenges of this task.

#

I think the biggest issue out of all here is the way to do this with specifically semi transparent sprites, just like these guys, because Unity can't really handle it in a nice way

#

probably explains why i could search for this forever and never find an answer. simply because i dont think there is one simple answer

#

makes me wonder though how other games have done it, like ori

meager pelican
#

See, and I don't do 2D much, so I took a shot.
Glad you found a performant solution ๐Ÿ™‚

ocean bough
#

yeah :) still worth to try what you suggested. made me learn a little bit more about how the rendering works.
and yeah, as for this solution, its something that fits with my level of expertise at least so thats good.

#

mucho gracias!

atomic bloom
#

Hello I'm new here and I've been trying to use the unity shadergraph but it stays the same default pink texture. I've changed my project to URP I'm not sure what the problem is

wintry valley
#

Is there a way to force writing to the depth buffer on a 2nd pass of a transparent material?

The first pass should be transparent and use the depth buffer, and the 2nd pass should ONLY write to the depth buffer for a later stage with decals.

karmic hatch
#

(Open the graph, open the graph inspector (button in top right), then select URP)

atomic bloom
#

Universal is URP correct ?

regal cargo
#

universal render pipeline yea

karmic hatch
#

Ok so what is your shadergraph then

#

Is it just the fragment and vertex nodes?

atomic bloom
#

yes

dawn ginkgo
#

hey, I want to copy paste the nodes but that doesn't work. Im trying to export my shader graph to another project and it doesn't really work. what can i do?

meager pelican
wintry valley
lavish plaza
#

Hey I'm working on a stylized shadow shader that I place on a plane beneath each actor. Then It uses a "shadow caster" camera's depth texture to draw dithered shadows beneath characters. The problem is that when two or more actors get close, you can see their shadow planes overlapping and their shadow dither patterns not lining up. Is it possible for me to somehow check what was blocking the light on a fragment and only draw the owner's shadow on the plane? I can't think of how I would get that information to the fragment shader.

Shader is written in shaderlab/hlsl and running in unity 2021.3.9f1 with urp.

#

This may be a tough question to try and solve over discord.

gritty steeple
#

Hey guys, What's the best way to show fingerprints under a UV light?

#

I figured a shader but my experience with shaders is minimal to none.

cosmic prairie
lavish plaza
open jackal
#

Hey there, I just imported my texture in a shader graph and it has this weird diamond shape around it

#

this is the actual texture

#

i import the same thing into a shader graph and it gives me the light blue diamond around it

tacit parcel
meager pelican
# lavish plaza One of my goals was to make the pattern move with the character, which I think r...

I think @cosmic prairie is correct. It was my first thought as well.
The point being that you align the dithering pattern on the grid formed in either screen space or world space, so the squares line up when two character shadows overlap. Black is black, and squares are squares.

The problem, though, is if it dithers based on any intensity. If you're at a hard-binary shadow or no-shadow, not a problem. But if you have any degree of fade off...where the dither patterns differ, the overlaps won't match up...if that makes sense. Right now your shadows don't look like a traditional dither so much as they look like a checker pattern...always the same pattern. And if so you're in luck...just do what Peter said and use world-space dithering to align the grids.

Shadow existence is still calculated relative to the character positions, so they move with the character. The pattern is relative to world/screen space.

meager pelican
wintry valley
# meager pelican In theory. Did it work? If not, why not...what's not working?

I have water that has a different color depending on the scene depth, and a decal that needs to render on top of the water. The decal is rendering on render queue 5000

The water is rendering on render queue 3000.

However, the depth buffer is not being wrote to so the decals still use the depth from before the water and draws below the water.

cosmic prairie
meager pelican
#

If you're drawing the water last except for the decal, you should just be able to draw it while updating the depth buffer. You can draw transparents and update depth. At least I think you can in URP, should be able to. One pass.

wintry valley
#

The decal is the build in solution, are you still able to draw the depth before drawing it without modifying engine source code?

meager pelican
#

Are you hand-writing URP shaders?

#

Or using SG?

#

At any rate, "just" turn depth-writing on when you draw the water. What happened when you tried that?

wintry valley
#

And the water is in shader graph, the decals are the build in shader graph solution

meager pelican
#

Huh. I don't understand that (why). I mean, the depth write happens AFTER the pixel is "sent", not before. Is it a multi-pass shader, excluding your decal-update pass, is there still more than one pass? E.G. with your decal update transparent pass is there three or more passes?

#

Oh, SG.

wintry valley
#

I believe it is all as one pass. When I force write depth on, it looks the same as if I render is as a geometry render pass rather than a transparent render pass.

#

But when it does that, the depth buffer is correct and the decals display on top of the water

#

Another thing I tried was a hand written URP shader that is on render queue 3001 to render right after the water that has those lines of code in the shader to try to force the depth buffer to the water level

meager pelican
#

Yeah, might be an SG thing. Not sure what's going on. Maybe post your shader so people can help debug this issue.

In theory, you should be able to have a trasparent shader, and still output depth, it's just not commonly done with transparent things.

wintry valley
#

The shader itself is quite large, because it does color calculations, and modifies the vertices to create waves. Do you want to see just the depth buffer / color part?

meager pelican
#

I'd start with showing settings.

#

I don't care how it looks as long as the depth value is right and it looks OK.

#

But from the sound of it, it's not right

#

IDK what SG does differently with transparent things that would impact this. If it writes depth, it writes depth. To me.

wintry valley
#

This is on URP 10, I have tried on URP 15 as well with Force Depth to on. I am using URP 10 because that is what the other developers were using when I joined the project

meager pelican
#

So 15 has an option for "force depth = true" or something?

#

But 10 doesn't? Because if you need to use 10, then, you're screwed.

wintry valley
#

I found this online from a different person, and this is URP 15. This did write to the depth buffer, but it had the same issue with the depth buffer affecting the water color

#

The other people aren't opposed to upgrading, just need probable reason to.

#

The two outcomes so far is either:
No depth write, water looks fine but decal underwater
Yes depth write, but water has wrong depth texture and thus wrong color / texture

meager pelican
#

That last point, I don't understand why it would have the wrong depth texture. Confused here.

#

I get why they changed the decal to be a later event in that article. Because skybox is drawn before transparents are drawn.

#

I suppose you could try to see if you can shoe-horn the water into the opaque queue, but do alpha blending or whatever.

wintry valley
#

No writing to zbuffer gives the first image.

Writing to the zbuffer (forcing, or rendering as opaque, geometry, or alphatest) gives the second result

#

That shader does calculations based on the depth to determine whether or not to add white spots for foam for coastal water, or with little to no room between the water and the terrain under it, which is why it has that color.

meager pelican
#

Yeah, but the depth should be the bottom-depth.

#

That's what I'm not understanding.

#

Why is it getting it's own depth?

#

Wait.

#

I think I know.

#

Did you put it in the regular opaque queue? Or opaque + something.

#

You have to draw the bottom first.

wintry valley
#

The image I had there was as AlphaTest

#

2450 I believe

meager pelican
#

Opaques are drawn front to back...closest to farthest.

#

So you have to draw the bottom (farthest) before you draw the water. So the water has to be in a higher queue number.

#

The water is essentially over-draw

wintry valley
#

The terrain under it is render queue 2000
That 2nd image I provided was render queue 2450 (for the water)

meager pelican
#

That's still an opaque range, yes?

wintry valley
#

Opaque is in the 1000s, Geometry starts at 2000, and AlphaTest starts at 2450

#

Transparent starts at 3000

#

Without +- render queue like you can do (eg 2999 is Transparent-1)

meager pelican
#

IDK why you want to alpha test, is there a reason?

wintry valley
#

Draw after terrain (2000) but before transparent (3000)

#

I want it to be transparent ideally, just writing to zBuffer

#

If it would help I can send the generated .shader file that the shader graph creates

meager pelican
#

Yeah, it gets confusing. IDK if URP forces settings on things based on queue number, but "transparent" is just a matter of shader settings, not really queue numbers. Per se. It about sort order though.

#

I'd try queue 2010 or something, and no alpha clipping unless you need it. You do need depth buffer clipping.

wintry valley
#

That effect happens with anything except transparent render queues

meager pelican
#

Damn.

#

Maybe others, smarter than me, will figure it out. I'm at a loss as to what the hell it is doing. It should render the <=2000's before your water, and your water should get the depth buffer value which should be the "ocean bottom". Then you should be able to blend on top of that. In theory. IDK what is happening in practice. Frame debugger might help you.

wintry valley
#

I also just tried copying the generated shadergraph code into a test hlsl shader and modifying the ZWrite property and didn't change anything either.

#

How do I access the frame debugger?

meager pelican
wintry valley
#

Aha, I have this pulled up. Is there any way to view depth buffer with it?

#

I can see that the water is indeed drawing after the rest of the geometry but before the decals as expected. This is similar to RenderDoc

meager pelican
#

Yeah, and yes.
There's a depth buffer view, right where you select the render target (keep reading down the page).

#

You can also check shader properties to see if depth write is enabled, blending, etc.

wintry valley
#

What a handy depth texture -.-

#

Appreciate the link for the tool though

meager pelican
#

lol

amber saffron
wintry valley
wintry valley
amber saffron
#

Top of the window

meager pelican
#

That article talked about a depth buffer transfer pass. Which concerns me, as to when it happens.
That's why I suggested queue 2010

tacit parcel
wintry valley
#

Before and after the water draw call

#

It might just be something with the decal shader, not necessarily the water depth buffer

meager pelican
#

Yeah.
Why are there still two draw calls for the water shader?

wintry valley
#

That is a good question lol. The generated .shader only has a single pass, so I am not sure. It is using gpu instancing too

meager pelican
#

So you're no longer doing a 2nd pass manually or whatever, that's good.

#

Just checking

#

Not two materials on the thing.

#

OK, so it is updating the depth buffer.

#

I cannot tell when/if the decal shader uses that same depth buffer or if there's a copy pass somewhere BEFORE the water is drawn.

#

But if the decal is using that depth buffer, it looks updated AF so why wouldn't the decal use it?

tacit parcel
#

Isnt decal use it's own buffer? dbuffer?

meager pelican
#

That's what I'm wondering, and where it comes from and WHEN

wintry valley
meager pelican
#

Hang on, Cyan is here. (insert Superman swoosh sound)

wintry valley
#

The 3 SRP batches that includes the decals I have included here, including their details

regal stag
#

I think decals would also use the Depth Texture, so there indeed may be a CopyPass to copy the depth buffer, or a DepthPrepass, if it can't copy.

meager pelican
#

Yeah but that's why we're trying a queue like 2010 or something in opaque, and it's updating the opaque depth buffer. So I'm at a loss right now.

amber saffron
#

Even when rendering in the opaque queue, if transparent shader doesn't have the code to sample from the decals buffer, it wont do it

wintry valley
#

It updated the ZBuffer no matter what, in Opaque or transparent. It should be a transparent so you can see under it, just need some way to update the ZBuffer information onto the decal

#

The decal render queue is set to 3001 in these images, to draw right after the water (3000)

amber saffron
#

I haven't looked into how URP does decals, but if it's like HDRP on opaque decals, they are drawn in a custom buffer after the opaque depth pass

#

Ah wait, that's not decal "projectors"

wintry valley
#

Correct me if I am wrong, but there is a setting in HDRP that says Affects Transparent, correct?

Also correct, this is not decal projector. This is ShaderGraph/Decal

mental bone
#

Speaking of decals. How would you guys to skinned mesh decals? Im not a fan of the render the mesh into uv space and paint on a temp rt aproach, yet I can seem to think of anything else

amber saffron
#

Either use the projector to project to the depth and underlying geometry, or use a mesh, but it won't project

wintry valley
#

Where do I find the component for Decal Projector? Is it in a package I need to import?

amber saffron
wintry valley
wintry valley
regal stag
#

I think 2021.2, or at least that's the earliest the docs page appears

wintry valley
#

Also, I was reading through that doc you posted and saw this. This wouldn't apply so long as I am force writing to depth texture, correct?

amber saffron
amber saffron
wintry valley
amber saffron
#

And like mentioned, even if the water does depth write, if the transparent shader code doesn't have what is needed to sample from the decal buffers, then it won't do it

regal stag
#

Force writing to the depth buffer isn't exactly the same thing as the depth texture though

amber saffron
#

You could technically be able to do it yourself

regal stag
#

I guess it would also depend whether the decal is rendering using the DBuffers or a screen space method

#

If you're on earlier versions I'd assume it's just screenspace atm?

wintry valley
#

I am currently on 2020.3.34f1

#

URP 10

#

We are probably going to be updating our client to 2022 after the next update in a few weeks, so I can mess around with the other settings for now so I know what to do when we update.

regal stag
#

Are you handling the decal yourself then? Or is the decal graph still a thing in v10?

wintry valley
#

The decal shader exists, but not the decal projector.

amber saffron
wintry valley
regal stag
#

Are you sure it's a decal target, and not just a shadergraph named decal?

#

What appears in the Graph Settings?

wintry valley
#

I am assuming its using screen position based on this clip-space section

regal stag
#

Yep

amber saffron
#

So, this is "just" a regular transparent shader named "decal", not a "real" decal

wintry valley
#

It functions perfectly like a decal on opaque geometry, but transparent it does not

#

But it is not a decal projector

amber saffron
wintry valley
#

In the frame debugger it did the pass for the water, the decal after

regal stag
#

I think atm you are writing the water to the depth buffer but those changes aren't appearing in the depth texture because it's already been copied / generated using opaque passes.

#

You would need to write a custom renderer feature to DrawRenderers() directly into _CameraDepthTexture

meager pelican
#

Oy.
And your water should not be thought of as "transparent" in your case, it should be thought of as "blended opaque" e.g. see through dirt, and in an opaque queue. Or wait until you upgrade everything.

wintry valley
#

They are all under the same render loop, so could it be that it writes to the depth buffer which is used later, but not in the same render loop?

amber saffron
#

Looking at the screeshots of the framedebugger higher, everything makes sense to me :
Water is drawn first, wrinting into depth buffer
Decal is drawn after, with ztest, causing it to not display where the water mesh is above

regal stag
amber saffron
#

Yes, I saw that, but to me this rendering is expected, and I guess the issue is still about some parts of the decals disappearing

regal stag
#

Ah true

amber saffron
#

If I can give some suggestion @wintry valley :
Based on the current look, you could render your decals as opaque alpha clipped, that would force them to render before water and in depth.
The missing parts would the be rendered in the water with a small blending effect that would maybe even be nice to see

wintry valley
#

Here's the render order with the frame debugger viewed. Opaque > Water > Decal

wintry valley
amber saffron
wintry valley
#

The water isn't flat though, it has a compute shader that moves the vertices for waves. In theory, yes

amber saffron
#

Well, if you really want perfect water height matching decals, you can go the route of writing you own rendererfeature, that:

  • renders water in a custom depth buffer
  • project decals vertically on this depth buffer, and stores in a screen space decal buffer
  • then in the main loop render the water with the water shader, sampling this decal buffer
wintry valley
#

I'll write that down and give that a shot. I appreciate it a lot. Thanks to @regal stag and @meager pelican as well! Appreciate all 3 of you!

fervent flare
#

In Unity 2021.3 the smoothness property in shadergraph does not seem to do anything?

#

can anyone give me a hint as to what changed?

#

you cannot use PBR properties in shadergraph anymore ?

mint wave
#

hello i recreate a simple lambertian in shadergraph iv'e got something like that
to get my direction light i use something like that for my custom nde
Light mainLight = GetMainLight();
direction = -mainLight.direction;

#

oups i change my normal vector to world

#

and it seem to be good

#

but i probably can do that easyli with this half3 LightingLambert(half3 lightColor, half3 lightDir, half3 normal)

#

in lghting.hlsl

amber saffron
restive radish
# mint wave hello i recreate a simple lambertian in shadergraph iv'e got something like that...

I my game, I do this to use custom light edited from lighting.hlsl:

  1. Copy lighting.hlsl to folder XXXX
  2. Generate the code for the shader graph and save it into the folder XXXX
  3. Search for all places with #include ".../lighting.hlsl" and change to #include "lighting.hlsl" (that will link to the copy in your XXX folder).
  4. Edit the UniversalFragmentPBR function as you wish, and you will see the changes even during play mode (in editor, not in release).
#

Using this method, you can, for example, change PBR to BliinPhong (very slight gain), or toon lighting, for example.

mint wave
#

i see exactly what you mean

restive radish
#

is your plan to add bands to the lighting?

mint wave
#

no my plan it's to replace shadow by hatches

restive radish
#

ohh, ok

#

well, you can also do the same to shadows.hlsl

mint wave
#

greaaat

restive radish
#

I don't know what part of the code you change that, but feel free to experiment

mint wave
#

i find some code who perform that, but i really want to do on my own

restive radish
#

I think that way is more powerful than creating a custom function node on shader graph

mint wave
#

probably its way more efficient

#

I still have a lot of shadows, on how to quantify the shadows to replace them by points or stripes

restive radish
#

It also took me a while to get proper shadows on a 2d character on a 3d world, because it can get messy when lighting or camera hits from different directions. I messed a bit with shader for that, then gave up and found a way easier way.

#

especially nice for point lights

mint wave
#

an easier way ?? sound interresting ๐Ÿ˜‰

hearty obsidian
#

could someone explain to me why the triplanar node uses world position/normals by default?

#

afaik moving any object using triplanar mapping in world space will result in an undesired effect, so I'm assuming I'm misunderstanding its uses. Would like clarifications on what it is that I am missing, if that makes any sense

amber saffron
#

No

hearty obsidian
restive radish
amber saffron
#

You shouldn't have clicked that.

#

It compiles all the shader variants and then will try to open the humongus code in a single file

#

Next time for a shadergraph, click "View Generated Shader"

kind juniper
#

I'm not sure if it's normal for it to be 8 kk lines...๐Ÿค”

#

I think it's only supposed to include your code and whatever dependencies it has. Unless you're using every single node there is and in many different combinations?๐Ÿค”

#

Several thousand lines, sure, but millions?

amber saffron
#

I think that's the result of "compile and show code" ...

restive radish
kind juniper
#

So you're saying that every shader in the project compiles into 8kk lines of code?

restive radish
#

usually unity strips unused variants, but that button compiles all of them

kind juniper
#

Hmmm

restive radish
#

I guess unity only does automatically for shader features, though.

#

I leave that to people that know more

hazy zinc
#

@kind juniper okay! so, here it goes... will this lag or not? it lags a lot even an editor, its supposed to be smooth. the animation is shader-based, not animator-based.

kind juniper
#

Or shader graph(if it is)

#

Interesting.

open jackal
#

So I have these sliced sprites. I'm trying to apply emission by applying the second sprite on the first sprite. Problem is, I'm not able to drag them into the shader graph after slicing them. All youtube videos I found told that I needed my spritesheets sliced before animating. How do I make them work with my shader graph?

kind juniper
#

It's really subjective and case dependent. Can't generalize. I had some issues with it myself, but I think I did not troubleshoot it properly and made too hasty of assumptions.

hazy zinc
kind juniper
#

Try profiling. Maybe it's not the shader's fault(or rather not just the shader fault)

hazy zinc
kind juniper
kind juniper
hazy zinc
#

Again, the target is mobile

kind juniper
#

It's supposed to be faster

hazy zinc
kind juniper
#

Especially if you don't employ any optimization techniques on birp.

hazy zinc
astral spade
ripe grove
#

is it possible to make unlit shaders receive shadow? without custom lighting

rare flax
#

https://youtu.be/m6YqTrwjpP0
hey guys im trying to follow this tutorial where it needs me to create a Pipeline Asset, but the Create dropdown is changed and the Rendering section doesnt have the same options, can someone help?

In Unity 2019, we introduced a few changes to the Lightweight Render Pipeline, including a name change! It is now called the Universal Render Pipeline - but what exactly is it? How do you use the URP? Well let's check it out!

The Universal Render Pipeline (URP) is a prebuilt Scriptable Render Pipeline, made by Unity. The technology offers graph...

โ–ถ Play video
karmic hatch
#

Certainly doesn't look too expensive at any rate

lavish plaza
# meager pelican I think <@197764673137803264> is correct. It was my first thought as well. The ...

Hey thanks for the input. I was asleep when you sent this. I'm in a tough spot with this effect. I have tried screen and world space dither on this before and it causes a TON of visual noise. I'm trying to mimic the look of the shadows in total carnage, where they were part of the character sprites. This means it is acceptable for two objects casting shadows to have shadows overlap and look weird when they overlap. The problem is when one object casts a shadow onto another actor's shadow receiver as well as its own.

hazy zinc
lavish plaza
#

I'm thinking that maybe if instead of using a camera to create the depth texture, I could have a custom script that records depth in r, and an actor ID in g. Actors and their shadows would get matching IDs. Then I could use that ID channel to only draw shadows when the IDs line up. I'm gonna start by trying to just cast 512x512 rays in a c# script to generate the texture. This sounds like a good way to kill performance so let me know if there is a better way.

meager marten
#

hello, im not sure how to word this but is there any way to move uvs in runtime? the effect im trying to achieve has the selected uv vertices move to the right, but i dont know how thatd be changed in runtime in unity

meager marten
#

nevermind, found a solution, used 2 uv maps, one with the top line at the start, another a bit further on, then used a lerp mode between both uv maps in shader graph

latent rampart
#

I need it for rendering bounds. I'm currently using GL.Lines to render the bounding box but this seems like an easier implementation.

latent rampart
#

hmm maybe I should just stick with GL

fervent garnet
#

Hi how would I change a color's value (hsV) there is a saturate and Hue nodes but no value

#

I tried this but it does not seem right

meager pelican
meager pelican
#

Maybe try setting it to a value between 0 and 1 directly.

viscid pike
#

Hello, I'm trying to make my first vegetation shader in HDRP but I have this weird behavior were the grass work well as a GameObject but is black and not moving when placed as a detail on the terrain (Vertex Lit). Using 2021.3.7 HDRP

#

Anyone have an idea of what going on?

meager pelican
# meager marten hello, im not sure how to word this but is there any way to move uvs in runtime?...

I'm not sure if you're updating texturing uv's, or vertex positions on the model...your pic shows what looks like a vertex move to me. If those are UV mappings they're out of bounds.

Doesn't matter, though, there's two ways to update either of them:

  1. Update the mesh itself using a c# script. It has UV's and verts in the model. Look at unity docs about mesh data.
  2. Pass offsets to a custom shader, setting the offset values on the material. You may have to flag the verts with a flag to know what one you're updating. You can flag it with vertex colors indicated what vertex number you have so you know how to apply offsets.
    For either, that is done in the vertex() function/stage of the shader, although texture UV's can be done in the fragment stage too, it's probably slower unless you have to do it per pixel for some reason.
sly breach
#

how can i check if the renderer is using a particular shader pass ?

astral spade
white pivot
#

why i cant chnge the shader?

signal niche
#

Hi for shader graph how do I reference the texture as UI's Image source image?

kind juniper
kind juniper
blissful marlin
#

I'm trying to animate a render texture in HDRP, the material animates just fine, but the render texture is static. Does anyone know what could be causing this?

#
Shader "CustomRenderTexture/CausticsShader"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _Tex("InputTex", 2D) = "white" {}
        _TimeX("TimeX", float) = 1
        _TimeY("TimeY", float) = 1
        _Speed("Speed", float) = 1
    }

    SubShader
    {
        Lighting Off
        Blend One Zero

        Pass
        {
            Name "Caustic Shader Pass"
            CGPROGRAM
            #include "UnityCustomRenderTexture.cginc"

            #pragma vertex InitCustomRenderTextureVertexShader
            #pragma fragment frag
            #pragma target 3.0

            float4      _Color;
            float       _TimeX;
            float       _TimeY;
            float      _Speed;
            sampler2D   _Tex;

            float4 frag(v2f_init_customrendertexture IN) : COLOR
            {
                float time = 0;

                time = sin(_Time.x * 20) * _Speed;
                // Scroll UV coordinates by time
                return _Color * tex2D(_Tex, IN.texcoord.xy + time);
            }
            ENDCG
        }
    }
}
kind juniper
#

Where do you actually update/render to the texture?

tacit parcel
#

well.. maybe except a compute shader..

regal stag
upper nova
#

I made a scan line shader, I was wondering if there was a way to rotate the final result?
I could change the frequency of the Checkerboard UV but it only scrolls UP/Down or Left/Right.
The rotate node (both UV and Rotate About Axis) just change the color of the input and not rotate it.

Is there a way to do this in the shader graph?

amber saffron
upper nova
meager marten
astral spade
tacit parcel
#

Wait, that feature was available from unity 2017? and I only heard about it today ๐Ÿคฆโ€โ™‚๏ธ

mighty flax
astral spade
#

how

#

I don't know anything about shaders.

unkempt torrent
#

you must have some parameters in your drunk shader, just lerp them from 0 to desired value, it will make the smooth transition

proper ermine
#

Is there a way to inspect a sub graph from a shader at a particular point?

#

For instance... That group "Head" can I see the subgraph in there with those inputs?

I'm finding it hard to debug without being able to see in it :/

proper ermine
#

So I copied the entire subgraph, pasted it into the main shader and just hooked up the inputs into the slots there.

I managed to fix it this way but if anyone knows if it's possible to look into a subgraph at a point so you can see the results with the inputs, I'd much appreciate such information

sharp flint
#

hey guys,

i have a problem i want to render an mp4 file over a shader called Unlit and then play that video back in a loop as a affect infront of the camera but i always get this error if i try to play

Unexpected timestamp values detected. This can occur in H.264 videos not encoded with the baseline profile. Timestamps will be skewed to correct the playback for
craggy jay
#

hello, i'm trying to make a smoke trail effect in shadergraph by sampling 3d perlin noise with the world position, which is working perfectly. However I'm trying to make it move along the object by scrolling it's UVs in a specific axis, but since I'm using the world position to get the perlin noise, I can't really do this. Does anyone know how I can go about making this scrolling smoke trail effect?

#

mainly, i'm looking for a way to convert world coordinates to uv coordinates and vice versa

#

my current idea on doing this is to first get the perlin noise, then convert it to uv coordinates and then scroll the uvs

#

but there doesn't seem to be any way to do that

#

also if it helps, i'm using the built in trail renderer as my object

karmic hatch
craggy jay
#

the object is never moving, i'm doing a raycast that creates a trail renderer immediately from the starting point and end point (can also have reflected points off of walls and such), i'm just trying to make the illusion that is is moving

karmic hatch
craggy jay
#

yes and no? i can discard one axis and then reimplement it later, which is what i was messing around with when I was using the tiling and offset node

#

i think i could just get the noise from the uv coords itself, but then it would warp it because it gets stretched along the line?

#

oh wait, there's a texture mode that lets me tile it

#

oh i'm dumb lmao, i can just tile it and it works perfectly fine for what I need

#

i'm just using the uv now and not thinking about the world position at all

tight phoenix
#

I'm (still) working on my thin film shader and I think I am very close, but am making a mistake somewhere I'm unclear about.

{
    float3 L = inLightDir;
    float3 V = inViewDir;
    float3 N = inWorldNormal; // at least one of these three is not getting the correct input.
    float d = inDistance;

    float cos_ThetaL = dot(L, N);
    float thetaL = acos(cos_ThetaL);
    float sin_thetaR = (IOR1 / IOR2) * sin(thetaL);
    float thetaR = asin(sin_thetaR);

    float u = IOR2 * 2 * d * abs(cos(thetaR));
    float3 color = 0;

    float shift = 0;
    if ((IOR1 < IOR2)!=(IOR2 < IOR3)) shift += 0.5; //this doesn't appear to do anything.

    for (int n = 1 + shift; n <= steps; n++)
    {
        // Constructive interference
        float wavelength = u / n;
        color += inline_spectral(wavelength);
    }
    color = saturate(color);
    Out = color;
}```
#

Im pretty sure at least one of my 3 world coordinate references is incorrect because when I rotate around the mesh, the fresnel colors do not change at all, only when I rotate the mesh itself do they change, which is not the expected output

#

my other hangup is the output and expected output differ slightly

#

In real life as the thin film distance increases in size it seems it goes from black to white to yellow and then starts to repeat the colors. The Shader seems to start blue, do one rainbow, and then had a dark blue gap before starting to repeat colors. Once it starts to repeat colors it looks 1:1 identical, its only the start that's a little different.

#

I havent been able to figure out why that is the case or correct it out of the shader

#

my outpuit vs a calculation of the expected output vs a real like photo of an output

#

theirs kinda turns greyish while mine goes nuclear white

#

and mine starts blue while theirs starts black

#

I noticed in the For loop, the more times it loops, the more blue the starting color becomes

#

actually the more blue the ENTIRE thing becomes

#

maybe this in in part causing the problem?

craggy jay
#

is there a way to keep track of a variable that decreases overtime within shadergraph? or do I need to create a separate monobehavior for that?

#

like having a thing gradually disappear after 2 seconds or something like that

harsh marsh
#

Is there a way to get Scene Color to work in shader graph for the built-in render pipeline since it's now supported as of unity 2021?

karmic hatch
craggy jay
tight phoenix
#

is there a way to achieve this same result without using an if statement?

karmic hatch
karmic hatch
#

You could do it with a step function but the step function is step = value < 0 ? 0 : 1 so it's the same thing

tight phoenix
pale python
#

hey

I wanna be able to allow players to draw on some texture without changing the original white sheet/background.

how do I add a node texture as an overlay to another node texture ?

tight phoenix
#

Out = w < 400 ? float3(0,0,0) : Out = bump3y(c1 * (x - x1), y1) + bump3y(c2 * (x - x2), y2);

#

do I need brackets or double == or something?

karmic hatch
#

oh you don't need the second Out =

#

it's [variable] = [bool] ? [value if true] : [value if false]

pale python
#

anyone with shaders exp ?

tight phoenix
craggy jay
karmic hatch
#

Worth noting that you can also do it manually, with time * frequency -> sine, then you can control how fast it goes

craggy jay
#

ye, i'm just taking time and then dividing it by the duration i want, then plugging it into a sine function

karmic hatch
#

Also bunp I made this a while back when you and the other guy were working together; it's mostly physically based (using the thin film phase difference); the one thing that's not physically based is I assumed that red, green, and blue were discrete wavelengths (can be changed in the graph) and that the thickness that each wavelength has irl creates a dropoff following a particular ansatz function I chose (should work in the large limit anyway).

craggy jay
#

awh, damn the time isn't tied to when the object is created

karmic hatch
#

here's the shader on a bubble (for the cube demonstration i made it opaque and unlit)

tight phoenix
karmic hatch
#

The discrete wavelengths mean they do line up again so you get the large-scale waves you can see there but for low thicknesses it seems to work well

tight phoenix
#

compared to what im currently getting, yours looks like those outputs

tight phoenix
karmic hatch
tight phoenix
#

at least on this particular iteration, which is like the 4th completely different method Ive tried to approach this from

tight phoenix
proper ermine
#

Why does my sprite in game not match the preview from my shader?

#

It has orange line where the head connect to the body and where the ears connect to the head

karmic hatch
karmic hatch
lavish plaza
#

Nvm I think I can make an output buffer with the info I want to visualize and draw it from c# since this is a compute shader. I will try that.

pale python
# pale python hey I wanna be able to allow players to draw on some texture without changing t...

3 hours ago I posted this, I don't think it's too hard but I'm new to shaders in general and especially "Unity graph shader" so that is why I'm struggling with it.

I'd appreciate it if anyone could give me a hint or something on ways to achieve my goal or what to google.

All I'm asking :
Is there is a way to put a Texture2D on top of another Texture2D as an overlay or photoshop layers or is there is any better way to do that?

#

I'll take a look; the title looks promising , maybe its what I'm looking for, thx in advance โค๏ธ

pale python
#

it was thx!! โค๏ธ .. yes but not for my problem unfortunately, because it relies on URP High-definition , i'm building a mobile project, I can use hd in there. :S

lavish plaza
#

For things like bullet holes or blobby shadows I just instantiate a plane that has an image on it and place it where the hole or shadow should be.

pale python
flint bloom
#

I'm trying to combine a gpu-based culling system with indirect instanced draws. I wonder if I need to modify the data stored in the indirect argument buffers (e.g. change the number of instancing due to culling), how can I navigate this indirect argument buffer in the compute shader?

From the cpu side, I know I have to offer a GraphicBuffer or ComputeBuffer for the indirect argument. But how do I know where it gets bound to? Thanks!

static shard
#

Hello, why do I get this error while coding shaders?

Invalid subscript "vertex "
I get it at the highlighted line

v2f vert(appdata v) {
    //v.vertex.y += 0.1f * sin(v.vertex.y + _Time.y);
    v.vertex.y += 0.1f;
    
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex); //THIS LINE. v.vertex causes the error, why?
    o.uv = TRANFORM_TEX(v.uv, _MainTex);
    return o;
}
#

this is my struct

struct appdata {
    float4 vertex : POSITION;
    float2 uv : TEXCOORD0;
};
flint bloom
#

you prolly can't write to appdata v without declaring it as inout

static shard
#

the code didn't give an error at the previous line

#

so I think I can

#

I used "v"

#

before the error

#

but, let's give it a try

#

it gives the same error

flint bloom
#

oops

static shard
#

oh, my bad

flint bloom
static shard
#

yeah

flint bloom
#

oh nice

static shard
#

another question

#

how do I start the shader?

#

I modified vertez position but it doesn't seem to work

#

even if the code does not give errors

#

I mean, when I am in the editor, does the shader affect the object or do I have to start the enviroment?

#

like this

flint bloom
#

did you use any variables related to "_Time"?

static shard
#

it just doesn't do anything

static shard
#

v.vertex.y += 1 * sin(v.vertex.y + _Time.y);

flint bloom
#

try play the game and check the Game window

#

if you want it to be effective under Scene View, you want to find an option called "Always Refresh" and have it ticked on

#

should be on the top right of the Scene View tab

static shard
#

there's not

flint bloom
#

i'm not on unity rn, but should be folded under one of these items

static shard
#

found it

#

but it doesn't still work

flint bloom
#

then prolly problems from elsewhere

static shard
#

okay okay

#

I will find a way

#

thank you, William

flint bloom
#

gl ^^

kind juniper
static shard
#

okay so, how can I change that?

kind juniper
#

If you have a custom shader, you need to use a material that uses the shader.

#

Create a new material, assign it to the object. Select the right shader for the material.

static shard
#

how can I do that?

kind juniper
#

Sorry, you'll have to research that. That's one of the very basic things when working with unity. You need to create a new material asset in the project.

static shard
#

okay

#

thank you very much

unique lichen
#

heres what is happening

kind juniper
#

Please don't ping random people. Just ask your question and someone might answer. I just happened to be online now, but if I weren't, no one would answer you probably(since you pinged me specifically).

kind juniper
#

Is it with the cube? The terrain?

unique lichen
#

The textures will apply to unity cube but not my blender model

kind juniper
#

Did you uv-map your mesh properly? It looks like there's no uv data or it's broken.

unique lichen
#

No I don't think so

#

Never heard of "uv-map"

kind juniper
#

Well, then you've gotta do that. That's one of the basics of 3d modeling.

#

That or use a shader that doesn't rely on uvs. Like one using triplanar mapping.

unique lichen
#

Do you know where I could a texture that uses triplanar mapping?

kind juniper
#

Try googling a bit.

unique lichen
#

Alr thx

#

SO

#

So*

#

I don't know why but the texture works for the Unity cubes and what so. But not my blender model

kind juniper
restive radish
#

in real time, is it more efficient to change a shader or the whole material? For reference, that's for trees, so it would only apply to one or two trees at a time.

#

I wonder if changing shader would just create new materials for those trees, and then it would be better to use some shared material for those trees instead

amber saffron
proper ermine
#

Can someone help me understand why this might be occurring on my image?

#

I thought maybe my alpha is wrong? So I ceiled it but it still does it?

#

Okay so it only happens where sprites overlap...

ember sedge
#

I've downloaded a water shader graph from the asset store out of inability to write shaders, it looks great but I can't figure out how to convert it to work in World Space.

I am aiming to get the edges of neighbouring ocean plane meshes to match seamlessly, however I just can't comprehend how to convert it to work in World Space - if I simply switch from 'object' to 'world' I get weird distortions, and the entire thing shifts around when moving the camera.

I'll pop in a screenshot of the vertex displacement, if anyone has any ideas would be much appreciated :)

amber saffron
# ember sedge
  • Keep the Position node in object space.
  • You want to change the UV input of the "Tiling and Offset" node :
    • Create a new "Position" node, and set this one in World space
    • Swizzle the output to keep "XZ" coordinates, and connect it to the "UV" input of "Tiling and Offset"
proper ermine
ember sedge
amber saffron
ember sedge
proper ermine
#

I will try it, I'm pretty new to this but have noticed that when I put 2 in front of each other it goes translucent

proper ermine
amber saffron
paper loom
#

hi can someone help me here

amber saffron
paper loom
#

sorry sir I'm uploading it now in github ๐Ÿ™‚

#

here's the link

paper loom
kind juniper
long sand
#

Hi, sorry for popping up with a random question but:

UNITY_SETUP_INSTANCE_ID(IN);
           UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
#if  defined(UNITY_SETUP_INSTANCE_ID)
           int d2 = unity_InstanceID;
            #endif```
why does the code above fail with undeclared identifier 'unity_InstanceID'
#

what am I missing?

kind juniper
soft harness
#

Are IF statements bad?

kind juniper
long sand
#

unity_InstanceID is a unity defined variable

#

I have no clue if I am supposed to have it at that point, I am following the examples

soft harness
kind juniper
soft harness
#

Ok so not today

long sand
#

this is the function that unity executes to enable it:

#
 void UnitySetupInstanceID(uint inputInstanceID)
    {
        #ifdef UNITY_STEREO_INSTANCING_ENABLED
            #if !defined(SHADEROPTIONS_XR_MAX_VIEWS) || SHADEROPTIONS_XR_MAX_VIEWS <= 2
                #if defined(SHADER_API_GLES3)
                    // We must calculate the stereo eye index differently for GLES3
                    // because otherwise,  the unity shader compiler will emit a bitfieldInsert function.
                    // bitfieldInsert requires support for glsl version 400 or later.  Therefore the
                    // generated glsl code will fail to compile on lower end devices.  By changing the
                    // way we calculate the stereo eye index,  we can help the shader compiler to avoid
                    // emitting the bitfieldInsert function and thereby increase the number of devices we
                    // can run stereo instancing on.
                    unity_StereoEyeIndex = round(fmod(inputInstanceID, 2.0));
                    unity_InstanceID = unity_BaseInstanceID + (inputInstanceID >> 1);
                #else
                    // stereo eye index is automatically figured out from the instance ID
                    unity_StereoEyeIndex = inputInstanceID & 0x01;
                    unity_InstanceID = unity_BaseInstanceID + (inputInstanceID >> 1);
                #endif
            #else
                unity_StereoEyeIndex = inputInstanceID % _XRViewCount;
                unity_InstanceID = unity_BaseInstanceID + (inputInstanceID / _XRViewCount);
            #endif
        #else
            unity_InstanceID = inputInstanceID + unity_BaseInstanceID;
        #endif
    }
kind juniper
# soft harness Ok so not today

Of course if you want to squeeze every bit of performance, it's still relevant. But sometimes there's just no better alternative.

kind juniper
long sand
#

I think it all work through unity macros, but you are right I am not sure where it's declared, although i think it's declared as static

#

which I guess means global?

#
#if UNITY_ANY_INSTANCING_ENABLED

    // A global instance ID variable that functions can directly access.
    static uint unity_InstanceID;

kind juniper
#

There would be no point in calculating it here, if it was coming from unity.

#

Aaah, okay

long sand
#

the code I am copy and pasting is all unity stuff

kind juniper
#

Then I guess the define is not enabled

long sand
#

but it is otherwise the compiler wouldn't fail right?

#
#if  defined(UNITY_SETUP_INSTANCE_ID)
           int d2 = unity_InstanceID;
            #endif
#

my code is around the define

soft harness
#

Would that be better than running it on every pixel?

kind juniper
long sand
#

oh wow thanks for the help

kind juniper
#

It definitely wouldn't be slower.

soft harness
#

That's all I need

kind juniper
long sand
#

yes you are right, it's not defined

long sand
#

another question: can I do

material.SetBuffer("_TerrainBlendParams", blendBuffer);
                   Graphics.DrawMeshInstanced(mesh, submeshIndex, material, batch, batch.Length, null,
                       shadowCastingMode, true, layer, Camera.current);

and expect the buffer to be usable inside the sahder?

#

unfortunately render doc shows me I am not able to bind the buffer

kind juniper
#

Logically thinking it should be bound.๐Ÿค”

long sand
#

yes render doc shows the varialbe in the shader

#

StructuredBuffer<float4> _TerrainBlendParams;

long sand
#

thanks I try now

#

same

kind juniper
#

Hmm

#

Try using material block then I guess

long sand
#

yeah I did that too ๐Ÿ˜›

#

it's all a bit too empirical haha

kind juniper
#

Did it work?

long sand
#

nope

kind juniper
#

Hmm

long sand
#

I tried that before start the chat

#

I wonder at this point if it's compatible with Graphics.DrawMeshInstanced

#

but I would be surprised otehrwise

kind juniper
#

Just to make sure, you did create the buffer properly, right?

kind juniper
long sand
#

I have seen examples using the same code just with normal gameobject

#

if it works with that it should work with everything

#

but I have never seen examples specifically with DrawMeshInstanced

paper loom
kind juniper
long sand
#

no I always used the same code with DrawMeshInstancedIndirect and I cannot use gameobjects for my case but I trust that example works

kind juniper
#

I'm sure you can arrange a small test case with regular gameobjects

long sand
#

what would it prove if it works?

paper loom
kind juniper
kind juniper
paper loom
#

that is the best I can do

kind juniper
# paper loom

What's the reference name of the DirtMask parameter?

paper loom
kind juniper
paper loom
kind juniper
#

And yet in your code you bind it to "DirtTexture"

#

Btw, you should be getting warning/errors in your console when attempting to bind a texture to a property that does not exist.

paper loom
#

so in the settextture i should put "_Dirtmask"

paper loom
kind juniper
#

Weird

paper loom
#

Thank u ur a life saver it works now

#

I guess I have to study shader graph can u recommend references on where to study?

kind juniper
paper loom
#

Thank you sir I owe you one

mortal creek
#

Hi! I can't get the Scene Color node on shadergraph to work. I've configured my project as the tutorials suggest. Opaque texture is active on the URP asset and the surface on the shader is set to transparent. All I'm getting is the camera background color as output, not the colors on the render buffer. Any ideas?

restive radish
#

How do you usually pack your channels for complex shaders? Is there any standard? I usually use two textures:

  • Color + Alpha
  • Normal + Ambient Occlusion + Height

Metallic and Smoothness I leave out since they don't match much the pixel art style on the textures of my meshes.

mental quest
tight phoenix
#

carpaint dragon test with it

restive parrot
#

can somebody help me make a shader? i want to make a shader that would blackout my scene

thin crater
#

Hi, I've got this basic toon shader

#

The editor writes that error

#

What does it mean? I've not written code

#

Tried to compile, errors multiplied:

#

What could it be? I've never received an error like that... Also restarted editor, it didn't work

karmic hatch
thin crater
#

No, it was a random bug with a gradient property. I removed it, added it again, and it got fixed...

karmic hatch
#

Very strange

craggy jay
#

is there a way to get the sprite color modifier in the shadergraph?

#

like when you use a sprite renderer, or particle renderer, you can set the color and opacity of the material, but it's applied on top of everything

#

is there a way to access that color before it's applied?

knotty juniper
craggy jay
#

oh okay! is there a way to disable the vertex color multiplication at the end of everything?

#

i'd like to implement my own vertex color thing

knotty juniper
craggy jay
#

i'm using shadergraph to make my own shader

#

nvm, i'm just going to use the unlit shader base for shadergraph

#

works perfectly for what i want

soft harness
kind juniper
#

Or by using it?๐Ÿค”

soft harness
#

by using it

#

so for context, i wrote a raytracing volumetrics script, but as you can imagine it's quite performance heavy. but i'm also using interlacing, which if you know how that works it means i only need to render half the pixels per frame. so what i did is change the volumetrics script to only run on half the pixels, and that worked!

#

with literally no comprimise

#

from 15 to 20 fps

kind juniper
dim yoke
toxic flume
#

What do you suggest to implement water shader and river in voxel games?
Using a big water texture and tile it, then assign each tile to each voxel?
I have seen some voxel games use one tile texture for each voxel but it is
repetitive and not impressive

amber saffron
west knoll
#

Hi, i'm having trouble with normal and alpha channel. I need to have a normal with one mask in the alpha channel but if i set the texture type to normal seems like the alpha channel change.
Now i'm trying to reconstruct the normal map directly in the shader (using shader graph) using the R and G channel for the normal and the alpha for the mask i need and keeping the texture type at Default. But the reconstructed normal is not working properly.
Anyone have experienced the same problem?

amber saffron
toxic flume
west knoll
cosmic prairie
restive radish
restive parrot
#

How can i make a blackout shader. I have never used shaders before so I need help. Thanks

restive parrot
grizzled bolt
restive parrot
#

something like this, but i have managed this with lighting but i want to manage something like this without a lighting but with shader

#

@grizzled bolt

#

to have sort of like nearvision

grizzled bolt
restive parrot
#

that works

sacred patio
#

Hey guys, I've been getting back into unity, and I was wondering if there's anything crucial that I might've missed when creating a vertex shader
I did some vertex painting on the wings and the movement isn't working on the mesh, though it shows up in the preview

kind juniper
toxic flume
cosmic prairie
#

or are you doing some fancy mesh compression where you only send bytes for vertex coordinates?

sacred patio
# kind juniper This

Oh got it, it was set 0. Rookie mistake
Although it's super buggy, and plays only if I move the windows, is there a reason for it somewhere in the settings?

kind juniper
#

If you press play, it should work properly

amber saffron
#

Or enable animated materials in the scene view.

sacred patio
toxic flume
#

But it is like an island, a voxel shape Island.
I would like to simulate waves towards that island

#

In my mind, I should send data like the direction towards that island for each voxel

dim yoke
mental quest
dim yoke
mental quest
dim yoke
mental quest
dim yoke
#

I think cg shaders works on urp atleast, dont know about hdrp

mental quest
#

I fixed it by adding this to Pass {}

Stencil
{
    Ref 1
    Comp Equal
}
dim yoke
#

Didnt realize the mask would use stencils, makes sense

tight phoenix
#

@karmic hatch https://www.shadertoy.com/view/NttcRr
I am trying to reimplement your SSS cube a second time. The first time I was not satisfied with the results I got, trying to remake it EXACTLY 1:1, not 'close' not 'similiar', EXACTLY identical.
Its the only way I can be sure I am getting the same results as yours is if its exactly exact, anything less than exactly identical is useless and worthless to me.

A few questions:

  • What 'space' are surface vector, sun direction, position in? Are any of them normalized?
    I am having trouble translating your version's color and normal and position and direction values, yours are all based off of a For Loop checking if a ray hits the cube or not, I have an actual cube so I don't need to do that but I can't figure out how to replicate the values the loop would have given me if I had needed to do that
#

the old implimentation looks nothing like your original implimentation and its full of mistakes, 'close enoughs' and is just completely worthless fucking trash because its not perfect and I have no idea how to fix it

#

Also if the absorption color is too bright, I get pink errors, which shouldnt be possible ergo there must be a huge mistake here

#
{
    subsurface = Remap(subsurface, 10., -0.2);
        
    vec3 subColor = 1.2*tanh(exp(-subsurface*ABSORBCOLOR));
    return vec4(subColor, 0)/(1.-0.7*dot(direction, SUN))*0.4;
}```
```    MY CODE
float3 subColor = 1.2*tanh(exp(-Subsurface*AbsorptionColor));
    Out = float4(subColor, 0)/(1.-0.7*dot(ViewDir, SunDir))*0.4;```

Why would this return broken pink? How can I prevent it from returning broken pink? It returns broken pink if the ABSORBCOLOR is too bright. (I remap externally before passing into my own code)
#

their color is (0.4, 0.6, 0.9), mine is the same, theirs doesnt return purple error, mine does

#

ergo there must be a difference im not accounting for but i cant find it

#

starting to get really agitated

#

going into mental health crsisi because its not perfect and identical despite being a perfect copy paste

#

taking a break

mental quest
tight phoenix
#

replaced SG's remap with Panzer's remap helped, I guess whatever SG remap does is not equivalent to this

#

im more comfortable with custom nodes now so I am doing more and more in that instead of with nodes, nodes I cant trust the output

karmic hatch
karmic hatch
tight phoenix
tight phoenix
#

though it did improve the look

karmic hatch
tight phoenix
tight phoenix
#

it looks a lot better than the first time I tried to adapt this though so its definitely an improvement

karmic hatch
tight phoenix
#

everything is in object space now but that means if I rotate the mesh, the main light rotates, which is not how it should work

karmic hatch
#

MainLightDirection transforms as a direction not a position

tight phoenix
#

changed, no difference

#

I swapped it because it wasnt working with direction

#

view direction is still in world space, does that need to be object as well?

karmic hatch
#

Yes everything in object space

tight phoenix
#

why am i putting everything in object space, couldnt it all be in world space if the end result is the same?

karmic hatch
#

It could, but object space also makes it independent of scaling and whatnot

tight phoenix
#

putting view in object space seems to have made it 1:1 to your implimentation

#

Im not fully clear on how it differs from the first time I did this, other than that I used custom nodes instead of rebuilding the math as nodes, gif in 1 sec

high hemlock
#

I'm developing a voxel game and have begun working on a greedy-mesh algorithm to decrease the number of vertices used in each chunk mesh. Since fewer vertices exist, now the UVs are being stretched. Since varying portions of the chunk mesh have different levels of UV-stretching, I can't simply have the tile texture repeat x-amount of times across the board. From what I've read, my only solution to this is to create the shader myself.

#

Here's essentially what I want the end product to result in:

#

In addition, the texture map has over 10,000 unique texture tiles on it. In some way, I have to tell the shader to use its given UV coordinates, and then repeat the said texture based on- I imagine world space? Thanks.

tight phoenix
# karmic hatch Awesome :)

I will play with the values in hopes of getting it looking closer to this, but first shower and lunch time, I might be back if I get stuck again, thank you as always for the help

full salmon
#

I've got this rectangle hugging the terrain with raycasts - is there any way I can make sure it gets drawn on top of the ground layer?

kind juniper
pearl frigate
#

Hoping someone can help me. I am using a nice grass shader with my procedurral terrain. It all looked just fine a second ago, i chose to update my networking setup and boom. It's like Unity is not rendering the material properly or something.

Here is a picture of it now, and also for reference how it looked before. I changed nothing regarding the grass...

#

I am really hoping there is just some known way to get Unity to get its shit together with this? ๐Ÿ˜‚

Once again, i changed NOTHING regarding the grass. Only updated my networking system. So this behaviour seems odd..

I have tried restarting btw. Still no luck.

distant pollen
#

Ayo, quick question as I'm new to this stuff..
How do I make it so that my sprite won't so stretched up?

#

it should be looking like this

tight phoenix
distant pollen
#

worked like a charm

#

thanks!

tight phoenix
#

the front face is burning white and the backside barely transmits anything, no matter what values are provided

#

there is no value for 'density' or 'less transmission' that isnt also 'burning wash out the front face'

#

am I just using it wrong?

#

is there a step you are doing that im not that somehow changes this?

tight phoenix
#

I cant get the bellow look

#

something is critically different that is completely altering the appearance

#

it was like this before and its still like this now and I cant figure out to fix it

#

getting agitated again

#

why wont it just @#$@#^@&ing work

#

why wont it be this, what am I missing

lavish plaza
#

I'm writing a shader that is supposed to edit a rendertexture before another rendertexture/material is using for its main texture. Can someone help me troubleshoot why my red pixel at (1,1) will not show up?

The writing shader:

            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog
            
            #pragma target 5.0

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            float4 _Color;
            
            RWTexture2D<uint2> _ShadowTex : register(u1);
            RWTexture2D<uint2> _ShadowTex_ST;
            
            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                                
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                _ShadowTex[uint2(1,1)] = float4(1, 0, 0, 1); // red pixel at 1,1 does not appear
                
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);
                col = col * _Color;
                // apply fog
                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
distant pollen
#

Hey, I'm trying to change that Vector4 in my code, but I get this error, any ideas why?

Here's the code btw:

private IEnumerator OutlineFadeIn()
{
    for (; material.GetVector("OutlineRGBA") != new Vector4(1f, 1f, 1f, 1f);)
    {
        material.SetVector("OutlineRGBA", material.GetVector("OutlineRGBA") + new Vector4(0.1f, 0.1f, 0.1f, 0.1f));
        yield return new WaitForSeconds(0.01f);
    }
    yield return null;
}
#

oh.

#

I might know why

tight phoenix
#

What is the formula for the length of a cube of known size's intersecting ray from surface normal out its back?

#

like if a ray from the viewpoint hits the surface normal, what is the length between it and passing out the back of the cube, represented as a color on that surface

#

expected output is nearly black at the edges, and oversaturated white at the poles if its rotated 45 degrees, since that would be the longest possible length through a cube corner to bottom opposite corner

#

this is the distance between the dead center point of the cube to its surface

#

I need the distance between the opposite face of the cube to its surface ๐Ÿค”

#

am I correct in my assumption that if this was representing the distance between the cube front and cube back, it would NOT be a circle?

#

can anyone confirm that such a formula even exists?
a cube of known size, what is the length of a ray intersection from any two points on its surface?

#

am I just wasting my time googling for it?

#

why is this so hard to find?