#archived-shaders

1 messages · Page 206 of 1

tired canyon
#

🤞

light epoch
#

well i did some googling and it turns out surface shaders dont work in urp

#

idk what that means but thats why

meager pelican
#

🤞

light epoch
#

so im making this shader in shader graph

tired canyon
#

nope

light epoch
#

but idk what fmod is

#

says this but

#

idk how to get that in the shader graph

wary jackal
#

I'm getting a weird error. "Shader error in 'Custom/Terrain': undeclared identifier '_MainTex_ST' at line 54 (on glcore)"

o.uv = TRANSFORM_TEX(v.uv, _MainTex); It has something to do with this line, but _MainTex_ST doesn't even exist in my program...

It was working before and now it's not

light epoch
#

nvm found it

#

modulo i think

meager pelican
#

Umm.

#

You can define it manually, what type of shader is this again?

wary jackal
#

unlit

#

just vert/frag

light epoch
#

yep modulo

#

how would i do

#

matrix[index] in a shader graph

#

i have to recreate this line

wary jackal
#

huh, so I just kinda typed float4 _MainTex_ST; above that line and it works

meager pelican
#

But if you're in SRP (and you are because you're using SG), I'm unsure.

#

Or you're not, but not is.

#

getting confused. lol

light epoch
#

wait who r u responding to

meager pelican
#

IDK anymore.

#

It's Saturday of a long week.

#

lol

light epoch
#

o

wary jackal
#

lol i'll shut up for a minute

meager pelican
#

LMAO

#

It's not you.

#

OK, so Mateu you're in vert/frag and standard pipeline. Unity should have defined that, see that link above.

wary jackal
#

Okay, thanks i'll check that out

meager pelican
#

@light epochMaybe just use a custom node. Or wait for Cyan to type something, that always works....;)

light epoch
#

im trying to use a custom node rn

meager pelican
#

But you have to have an array passed in it looks like.

light epoch
#

ive never done this before

wary jackal
#

@meager pelican okay it's fixed. Not sure why that fix works, but it does so thanks 🙂

regal stag
wary jackal
#

@regal stag yeah I just did that, so it's just kinda a thing you have to do?

meager pelican
#

Unity will hook it up IF IT IS THERE, and that's what that link is telling you. But I couldn't remember if it was automatic or if you had to define it.

wary jackal
#

Apparently I had to define it. Well, that's one problem down a million more to go 😄

meager pelican
#

Defining it locally would just leave you with zeros or worse.

regal stag
# light epoch i have to recreate this line

There's a Matrix Split node, which would give you each row or column, but if you want it based on an index like that you probably do need a custom function (so you don't have to awkwardly chain branches or something).

I guess use a Matrix4x4 matrix and Vector1/Float index input, and one Vector1 output output in the Custom Function, and use output = matrix[index] for the body. You shouldn't really need the clip part, as that can be handled by passing the matrix[index] result into the Alpha Clip Threshold port on the master node/stack.

light epoch
#

thanks man, how would i do the clip?

regal stag
#

As long as the c.a is the value passed into the Alpha port. And the rest after the subtract is passed into the Alpha Clip Threshold port, it should handle the clip.

light epoch
#

oh i didnt even read that last sentence my bad

regal stag
#

It might not like the space in the function name

light epoch
#

ah that fixed it

#

lmao

#

what would _ScreenParams be?

regal stag
#

I think that's the Screen node? Yeah, it's screen width & height (put into a Vector2)

meager pelican
#

Assuming that's from your source file, that's passed in by Unity automagically.

#

So in SRP it is

light epoch
#

wait so width divided by height

#

?

#

i had the screen node but i was multiplying them

meager pelican
#

Nah, it's a vector 2 multiply.

#

x * x and y*y

#

multiply node

#

using float 2

regal stag
#

Put the Width and Height outputs from the Screen node into a Vector2 node, then Multiply with Screen Position node

meager pelican
#

They should put a float2 output on that.

light epoch
meager pelican
#

Careful

regal stag
light epoch
#

shaders are so confusing to me im sorry

meager pelican
#

Your source shows him doing a perspective divide (dividing by .w component). IDK why since that's often automatic. But it depends on your shader.

light epoch
#

i know c# not hlsl or shaderlabo or whatever it is

#

im trying to do a stipple transparency shader

regal stag
#

The Default mode on the Screen Position is already handling the perspective divide so should be okay

wary jackal
#

Okay I have this. I think I'm getting somewhere... but how would I change from green to brown using a lerp function?

meager pelican
#

Yeah, you usually don't see it in vert/frag either, it happens after the vert() but before the frag(), usually.

#

What is green and what is brown? White = green?
So you put brown as color 1 and green as color 2 and lerp based on the result you're showing (so 1= green).

regal stag
regal stag
wary jackal
#

thx @regal stag

light epoch
#

this isnt working

#

lemme try to clean it up and screenshot the full thing

#

the code im trying to recreate is ``` void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;

        // Screen-door transparency: Discard pixel if below threshold.
        float4x4 thresholdMatrix =
        {  1.0 / 17.0,  9.0 / 17.0,  3.0 / 17.0, 11.0 / 17.0,
          13.0 / 17.0,  5.0 / 17.0, 15.0 / 17.0,  7.0 / 17.0,
           4.0 / 17.0, 12.0 / 17.0,  2.0 / 17.0, 10.0 / 17.0,
          16.0 / 17.0,  8.0 / 17.0, 14.0 / 17.0,  6.0 / 17.0
        };
        float4x4 _RowAccess = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
        float2 pos = IN.screenPos.xy / IN.screenPos.w;
        pos *= _ScreenParams.xy; // pixel position
        clip(c.a - thresholdMatrix[fmod(pos.x, 4)] * _RowAccess[fmod(pos.y, 4)]);
    }```
meager pelican
#

You did the divide, but it didn't go anywhere.

light epoch
#

i did that bcuz u said i didnt have to

meager pelican
#

I pointed it out that "he" was doing it in the original.

light epoch
#

still doesnt work

regal stag
#

You don't need to do the Subtract at the end there

#

And put the A output in the Alpha port

#

Well, that might end up as the same thing I'm not sure, a little tired

light epoch
#

still doesnt work

#

its frustrating cuz like

#

im getting nothing at all

regal stag
#

I also just realised what you're doing and there's actually a Dither node that should handle this for you.

light epoch
#

id be happier if there was at least a result i didnt want but theres literally no result

meager pelican
#

OH! The lookup array is a dither lookup?!?!?! lol

regal stag
#

Yeah lol

meager pelican
#

LMAO. We haven't see the source, so good catch.

light epoch
#

i dont think i used dither right

regal stag
meager pelican
#

You need to plug those values into that matrix too. Or pass that matrix in if you're not already.

#

Right now it looks like an identity matrix, but that might be just what SG displays.

#

But IDK what they use in their dither node, you might have blue noise or something, so different values, if that matters.

regal stag
#

According to the docs it's the same matrix, that's how I recognised it

meager pelican
#

Looks like the alpha for "in".

light epoch
#

wait so what do i do

wary jackal
#

lmao I've been here the whole time thinking my code is off only to realize my directional light was at an angle and not straight above ;-;

regal stag
#

I know Daniel Ilet has a tutorial on using the dither, should help : https://www.youtube.com/watch?v=VG-Ux8RHMoA

Learn how to create a dithering transparency effect similar to the one used in Super Mario Odyssey using Unity Shader Graph! This tutorial is also available in text format here: https://danielilett.com/2020-04-19-tut5-5-urp-dither-transparency/

💻 Get the source on GitHub:
https://github.com/daniel-ilett/dither-transparency-urp
✨ ...

▶ Play video
light epoch
#

well what i want is for it to dither away as your camera gets close to it

meager pelican
#

He probably passed some inverse 01 distance to it instead of alpha.

#

or remapped.

regal stag
light epoch
#

that would fade out the entire object though

#

you see in the video only the part near the camera fades out

meager pelican
#

so after some value, you get 1 otherwase a scale from 0 to 1.

#

as you get closer

light epoch
#

with the far part of the object staying fully opaque

regal stag
light epoch
#

oh alright

#

omg i got it

#

thx guys

wary jackal
#

Well, here are my crappy shaders in action. I'm pretty proud of it lmao

light epoch
#

@regal stag @meager pelican i wanted the shader for my mirrors, thx guys

#

the model is temporary dw

tidal wraith
#

Why does the standard shader not upgrade to urp?

meager pelican
#

It does last I knew. Did you run the upgrade routine from the menu?

#

It upgrades to the urp lit shader. @tidal wraith

slim steppe
#

Hi i've never really coded shaders could someone please try to help me? My goal is to make a unlit object be visible through other objects but with a lower alpha value. I did some research and think it has to do with the z buffer but just "turning it off" makes it completely visible.

meager pelican
#

The reason you're not getting an answer on that right off, is that you're dealing with two things that are kind of mutually exclusive, so it's not an easy solution. You're correct that "behind" is a thing that deals with the depth buffer. BUT...it gets more complicated when dealing with transparent things because...wait for it...transparent things don't update the depth buffer! At least not usually. And if they do write something to the back buffer, they end up doing a "blend" with the background pixel, so you don't know the alpha value of the original transparent pixel, and by the time it is over, it's blended with the background.

So in order to do what you're doing, you have t dedicate a render texture, or ?5?, to transparent pixel layers, and then decide on what pixel goes where, and keep track of the alpha, and then when it's all over and the smoke clears, you have to blend it all back somehow to one output buffer.

I think. If I understood you correctly.

#

Then again, you may be talking about a "behind the object" mask, for opaque. I cannot tell, depends on what you mean by "lower alpha".

#

If you are talking about that, there's a tutorial that shows it. I'll find you a link.
But first, what pipeline are you using?

#

@slim steppe

#

That uses a dither, but you can probably manage an alpha blend. Haven't tried it.
I know the Bracky's one is out of date and doesn't quite work anymore without tweaks.

#

But the one in this link uses URP and it uses Shader Graph so you won't have to write code.

wary jackal
#

Idk why, but it doesn't appear the UnpackScaleNormal function is working for me... I have this: i.normal = UnpackScaleNormal(tex2D(_NormalMap, i.uv * _NormalScale), _Steepness); but nothing's happening

wary jackal
#

Writing out the code that UnpackScaleNormal does manually works

#

just not the function

misty flame
#

In compute shaders, to initialize an array, do you do
structType arr[length]; or structType arr = new structType[length];

vocal narwhal
#

that's what the rgb channels look like

deep glacier
#

any way to make it, well

#

normal, so it displays as the sprite and not just a misshapen blob?

vocal narwhal
#

use the alpha channel

deep glacier
#

fixes the shape but then it's entirely white

vocal narwhal
#

You use the alpha channel to clip the image by feeding it into the alpha output

#

you don't just directly use the alpha value as the albedo

deep glacier
#

aha

#

it's fixed in the shader

#

still a blob in game

#

oh well, i'll figure it out

#

thank you for your help

#

@vocal narwhal if you still able to help, it says this:

#

i have actually given it one

vocal narwhal
#

It looks right to me, not sure what the issue is 😐

deep glacier
#

damn

light epoch
#

hwo do i make a custom shader reflect absolutely no light

#

its bright

#

the shader is

#
{
    Properties
    {
        _InactiveColour ("Inactive Colour", Color) = (1, 1, 1, 1)
        _MainTex ("Main Texture", 2D) = "black" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100
        Cull Off

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float4 screenPos : TEXCOORD0;
            };

            sampler2D _MainTex;
            float4 _InactiveColour;
            int displayMask; // set to 1 to display texture, otherwise will draw test colour
            

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.screenPos = ComputeScreenPos(o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                float2 uv = i.screenPos.xy / i.screenPos.w;
                fixed4 portalCol = tex2D(_MainTex, uv);
                return portalCol * displayMask + _InactiveColour * (1-displayMask);
            }
            ENDCG
        }
    }
    Fallback "Universal Render Pipeline/Lit" // for shadows
}
#

i didnt write it, i got it from a youtube vid

#

i wanna get rid of that shininess

wary jackal
#

I don't see anything there that's rendering light?

#

@light epoch then again, I don't know a whole lot

light epoch
#

yeah um

#

i think im a bit confused

#

for some reason when i turn off post processing on the mirror camera but not the player camera it looks fine

wary jackal
#

then it might be a post processing effect, but it's not part of the code you sent

#

I bet you it's a bloom effect or something? Do you have that selected?

umbral panther
#

whats the correct RenderType tag for the depth+normals pass? the docs say "When the DepthNormals texture is rendered in a separate pass, this is done through Shader Replacement. Hence it is important to have correct “RenderType” tag in your shaders." but none of the docs actually mention which rendertype to use and "Internal-DepthNormalsTexture" seems to just use "RenderType"="Opaque" (followed by a number of non relevant looking tags)

wary jackal
#

How do I access a depth texture? I want this for A: Fog, and B: changing the color of the water based on how far from the ground it is. I have no idea how difficult this would be to implement

umbral panther
#

@wary jackal there are some examples of Youtube videos talking about that... https://youtu.be/vTMEdHcKgM4?t=757

I got a bit tired of my simple heightmap-based planets and decided to experiment with generating them using the Marching Cubes algorithm instead, so that I could add a 'terraforming' ability for shaping the world with caves and tunnels and so on. I hope you enjoy!

If you'd like to get early access to the project files (they'll be made freely av...

▶ Play video
wary jackal
#

Yeah I've seen that, that's actually where I got the inspiration haha

umbral panther
#

I think he's using _CameraDepthTexture which is a builtin shader variable

#

you can probably just use it without doing anything special

wary jackal
#

Okay, I looked on the unity docs and found this:

    SubShader {
        Tags { "RenderType"="Opaque" }
        Pass {
            CGPROGRAM

            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct v2f {
                float4 pos : SV_POSITION;
                float2 depth : TEXCOORD0;
            };

            v2f vert (appdata_base v) {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                UNITY_TRANSFER_DEPTH(o.depth);
                return o;
            }

            half4 frag(v2f i) : SV_Target {
                UNITY_OUTPUT_DEPTH(i.depth);
            }
            ENDCG
        }
    }
}```
#

I don't really know how that works though, it appears as if Sebastian's method is pretty easy

umbral panther
#

so you don't use that directly. grab the code from his video...
float nonLinearDepth=SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, i.screenPos);
float dstToTerrain = LinearEyeDepth(nonLinearDepth);
float dstToWater = i.screenPos.w;
float waterViewDepth = dstToTerrain - dstToWater;
//from 13:09
looking at SAMPLE_DEPTH_TEXTURE_PROJ it seems to basically be a wrapper around tex2Dproj which seems to want a float4 where it samples at screenPosArg.xy / screenPosArg.w, if i'm reading the docs correctly. Which probably means you can just grab whatever you call SV_POSITION

#

and use that as screenPosition (i think)

#

_CameraDepthTexture is something that unity renders automatically (depending on certain things, so you might have to figure out how to force that on if it doesn't get enabled by default), but otherwise its builtin

wary jackal
#

thanks, also, why does he use the w value of i.screenPos?

umbral panther
#

i'm actually unsure i feel like it should probably be i.screenPos.z / i.screenPos.w, but maybe its a typo or I'm overlooking something obvious about the projection matrix or the PrimitiveAssembly or Rasterization pipeline stages

wary jackal
#

wouldn't y make sense, as that's height? or am I missing something

umbral panther
#

usually, you don't want height you want distance along the camera forward direction

#

unless your camera looks straight down, or you for some reason want to color it based on the depth of the ground from the water's surface

wary jackal
#

yeah that's what I wanted

umbral panther
#

since usually a view ray will not go straight down, and you want to shade it based on the view

wary jackal
#

I wanted to shade based on the depth of the ground, hence why I was thinking y value

umbral panther
#

one thing to watch out for doing that, make sure both quantities are in the same effective units otherwise odd things will happen

wary jackal
#

Odd things always happen anyways 😛

umbral panther
#

but that wasn't what that video was showing

wary jackal
#

Then... what was it showing? It looked to me like it was the height from the ground to the surface

umbral panther
#

in that case you don't need the depth texture at all, just color the ground based on world y coord

#

it was showing the distance through the water

wary jackal
#

hm... okay. Anyways, in my case how would I access the world y coord? Considering the terrain is one object and the water is another

umbral panther
wary jackal
#

ahhhhh, that makes sense, okay I was thinking kinda backwards. I bet his affect would look a lot better, but I would like to try mine out for now

umbral panther
#

if your REALLY REALLY sure thats what you want, render a new pass and sample the texture

#

where the new pass render's the y coord... probably

wary jackal
#

Ya know, it probably makes sense just to do it his way lmao

#

it would look better anyways

umbral panther
#

pretty much

#

main use for y-based coloring would be for a super simple terrain shader- you could color things based on slope and altitude

wary jackal
#

yeah I kinda have that but it uses dot products for coloring... I don't really like the result though

#

It also changes between a normal map, so the brown parts have textures while the green doesn't

abstract oasis
#

anyone know what this means

round patrol
#

hey all. whats the difference between the shader graph instance and this rainbow coloured S version of the shader graph?

#

how do you create one of these rainbow S versions of a shader graph?

white cypress
round patrol
# white cypress thats a shader written in code. Assets > Create > Shader

Thanks :). This asset has both the shader graph and code versions but the code versions are throwing errors. They are both the exact same(intended to be) and all of the materials for URP are using the code shader resulting in pink. I have to manually go through and change them all to point towards the graph version. There is 3 different shaders, one for base, grass, and foliage with alpha. do you know if there is an easier way to swap all the materials rather than manually select each material and change it to use the graph versions?

white cypress
#

don't think there's a way other than writing an editor script

cosmic quail
#

hello... im having trouble setting up a basic passthrough shader. this is my code so far:

void OnRenderImage(RenderTexture inputTex, RenderTexture resultTex){
        Graphics.Blit(inputTex, null, effectMaterial);
    }

the screen is black. im not sure what to try

cosmic quail
#

nvm i didnt have a shader on the mat

devout quarry
#

In shadergraph, if you have a subgraph, are the contents of that subgraph calculated every time for each instance of the subgraph in the graph?

vocal narwhal
#

One would presume the contents of the subgraph are evaluates as if they are inline. Perhaps it becoming a method which is called into whenever the execution evaluates it.
You should be able to check the shader source for one with a subgraph to see if this is the case

devout quarry
#

Yeah I think it would be inline… I would love a ‘register local variable’ functionality for this, I’ve requested in many times but it seems like they’re not even considering it, not sure why.

#

I’ll check the generated shader code to be sure

vocal narwhal
#

Ah, I am picturing the sort of layout you're saying, I would hope it would not run multiple times if you have multiple outs from one function

#

it should evaluate once and then use the result, if it doesn't, I'd have to seriously evaluate my understanding of the graphs

devout quarry
#

Ah hold one I’ll make a quick drawing

#

So for example my use case is a water shader where I really only want to calculate the depth of the water once, but use that value throughout my graph multiple times for several graphical effects. The depth of the water is calculated in a subgraph.

#

Option 1: subgraph is evaluated once but the downside for me is that this is really messy with wires going all over the main graph

vocal narwhal
#

I would expect that to be evaluated once

devout quarry
#

Option 2: subgraph is evaluated 3 times taking a performance hit (?), but it is not messy although having the same subgraph node + its input ports is redundant

#

Option 3: a new ‘register local variable’ node where the local variable would ideally take up as little space as a regular property, only a single evaluation + the graph is cleaner than options 1 and 2

vocal narwhal
#

That second layout of nodes is the one I would look up on... I don't have intuition about whether it would evaluate 3 times. If they were say a single "world space position" node, I wouldn't expect it to be evaluated 3 times, but in this scenario, I don't know. You've opened up a can of worms in my expectations haha

#

at least you can avoid the second scenario now in shadergraph with the redirect/elbow node

devout quarry
#

Yeah I would hope they optimise something like a ‘world space position’ node but I’m not sure about a custom subgraph :/ it is not clear through the UI/UX of shadergraph (I hope they add a performance overlay like they said years ago) so to be sure I’ll have to check out the generated shader code. Thanks for the input 🙂

vocal narwhal
#

The joys of visual scripting

devout quarry
#

This is also something that they could make more clear through good UX, have some visual indications of nodes/graph parts that are performance heavy, or grey out parts of the graph that are not evaluated, stuff like that

vocal narwhal
#

Shadergraphs' generated code looks like a nightmare now, I swear it never looked this bad?

#

Oh, I'm looking at the wrong one 😅

#

This basic test

#

Reuses it, so at least my expectations there are founded

#

Duplicated subgraphs with the same input

#

evaluated 3 times

#

not duplicated

#

reused

#

What I expected, though, frankly I still don't know what the rules are 😄

devout quarry
#

Thanks for checking, so in my option 2 image it would probably not be reused?

vocal narwhal
#

Yup, almost certainly don't do that 😄

#

Use the redirect node though if you're on a version that supports it, I was desperately trying to find it in VFX graph the other day and it was so sad

devout quarry
#

Yeah redirect node is nice but still feel like with all the wires it’s not very clean. I’d love the idea of being able to register/calculate a variable somewhere, so the graph is more ‘compartmentalised’.

meager pelican
#

Yeah, you'd think there would be a "set blackboard variable" node or whatever that sets a local variable's value, and the graph would evaluate the dependencies and make sure that it got executed before it is first used.

#

It's probably hard to evaluate those inter-dependencies though. I mean, you could set up race conditions.

devout quarry
#

Looking from the unreal4 forums it seems like their material editor does not have this either but someone made a PR and they are adding it or have added it

#

I wonder where ASE got the idea from then, I have never used ASE but their UX seems much better

meager pelican
devout quarry
#

At least shadergraph will be doing that as well soon 🙂

meager pelican
#

Good. I had anticipated that.

vocal narwhal
#

Have they made it so it tells you when you're trying to drag a fragment-only thing into the vertex graph yet? I swear there are so many basic things that they don't have

#
  • can't drag a thing here *, zero feedback
devout quarry
#

Not sure, there is vert/frag interpolation but I don’t think I’ve seen such feedbacks :/

toxic flume
#

Can we have 3d blend trees?
X and Y and weapon type?
or I have to define a blend tree for X and Y movement and some states for weapon type? So I will have a blend tree for each weapon type.
Each weapon type has different stance (idle, run, etc.)

echo solstice
#

Can someone help me?

#

Which tool you use for create shader codes?

devout quarry
#

@echo solstice you can hand-write them, then you would just use a regular code IDE, or you can use visual tools such as shader graph (from Unity) or amplify shader editor (3rd party)

echo solstice
#

But I need to arrange my code. Keep code at a margin.

devout quarry
#

Yeah that would work, you can write shader code wherever, even in notepad, but your visual studio might have some nice syntax highlighting for shader code or maybe plugins that provide that. I know that my IDE (Jetbrains Rider) works quite well with shader code. Auto formatting is nice as well.

echo solstice
#

Sometimes I type 100% correct codes

#

But doesn't work

#

I gave the code to my friend

#

And he gave me it

#

But his one is same but arranged properly

meager pelican
# vocal narwhal * can't drag a thing here *, *zero feedback*

It knows about it. Some nodes only work for frag dependencies, for example, the VFACE node cannot be hooked up to a dependency that goes into the vertex stage, since it is only available for fragments. You'd think they'd put an icon on it so you could tell easily. Or a color code. But meh.

devout quarry
vocal narwhal
#

It knows, but it doesn't give any feedback at all :'(

devout quarry
meager pelican
echo solstice
#

No console error

#

It says GPU problem

echo solstice
#

Perfectly

#

Can you please tell me a good tool for shader coding except visual studio?

mild ember
#

Can anyone give some tips for Lerping Shader Graph variables inside script? Vector1's as floats.
I got it lerping correctly except theres one problem. The speed accelerates way too fast, it goes faster than the wanted amount. When the lerping is done it goes to the wanted value and it looks very clunky.

meager pelican
safe flume
#

Hi does anyone know how to recreate this??

#

Ive been trying to look for a tutorial but cant find one

meager pelican
tired canyon
#

Has anyone had an issue where shader graph has a height of 0

#

I can force it via the UI toolkit to have a height

#

But normally when it opens it's just a grey box

regal stag
timid minnow
#

Hrmm, trying to make a radial blur style effect in Shader Graph. Pretty simple overall up to this point:

#

But in the bottom left, I need to plugin the logic for the offset, which should be outward from the center of the screen... how might I accomplish that?

#

I intend to create this sort of effect:

#

huh, looks like maybe taking screen position and multiplying by a small negative value is giving me the effect I want!

#

now to figure out how to elegantly fit a bunch of samples into shader graph...

woeful geyser
#

Why is UV a float4 in fragment shader? What is z and w in there?

#

Or it is color?

regal stag
tranquil nest
#

i think to start learning shaders for unity but im confused what language is unity now suport (HLSL, GLSL, CGFX)?

tired canyon
#

which lets you embed hlsl snippets

#

if you need to do something a node doesn't let you do

devout quarry
tranquil nest
#

i don plan to use urp or hdrp

misty flame
#

I'm trying to follow this article on raytracing in URP http://blog.three-eyed-games.com/2018/05/03/gpu-ray-tracing-in-unity-part-1/ but it uses
private void OnRenderImage(RenderTexture source, RenderTexture destination)
and assumes that the camera calls it every frame but that doesn't happen in URP. What can I do to replace OnRenderImage? I've been thinking that I could use this https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@10.1/manual/urp-renderer-feature-how-to-add.html but I'm not sure how I'd make it call a method and I'm still kinda confused by it

tired canyon
#

I'm pretty sure HDRP has a raytracing mode built in to it

lean lotus
#

if I were to take the motion vectors from a camera, then output the motion vector texture to the screen, then move the camera, what kind of result should I get? trying desperately to implement temporal reprojection but I dont understand it

meager pelican
# misty flame I'm trying to follow this article on raytracing in URP http://blog.three-eyed-ga...

Cyan has a post about post-processing in URP. In that post, he talks about custom render passes and how to wire it up to a custom material. It's abut 1/2 way down, here's the link: https://cyangamedev.wordpress.com/2020/06/22/urp-post-processing/
Of course, you'll have to have a custom material for URP that implements your ray tracing. If you're following that tutorial, I suggest you filter out all the mesh objects with camera layers so unity doesn't draw them, since you'll be passing meshes in from Unity's side to the ray tracer.
And your shader will have to be a custom URP shader, 3-eyed-games shader is for the standard pipeline, so yours will look different. He uses a compute shader, so you'll have to research that, but if you read Cyan's post you should be able to modify his C# and have it call the compute shader and then blit the result back out.

That much will at least get you wired up to start. I'd suggest making your first compute shader just set the destination texture to something, like red, and then making sure you get it all functioning. Then add the ray-racer to it.

That ray tracer is fun tutorial, good luck.

The Universal Render Pipeline (URP, previously known as Lightweight RP) uses an integrated Volume system for Post Processing effects, sometimes referred to as Post Processing V3 / PPv3. These effec…

misty flame
#

Thanks I'll try that out

#

I think I'm gonna learn a bit more about compute shaders until I try that though

meager pelican
#

The 3-eyed-games one is a compute shader.

#

But if you're following along, it's not that bad. Looks a lot like C, but it's HLSL. There's some difference....;)

wary jackal
#

Okay I'm having some troubles... In this video: https://youtu.be/vTMEdHcKgM4?t=757 at around 12:30 he does a depth view through the water to change the color of the pixel of the water. I've basically copied the code and done everything that I can think of to make it work and my water just turns solid white... Any help? Here's the code.

NOTE: I commented a lot of the lighting out just to make my life easier for writing this (I will add it back in once I get this working)

I got a bit tired of my simple heightmap-based planets and decided to experiment with generating them using the Marching Cubes algorithm instead, so that I could add a 'terraforming' ability for shaping the world with caves and tunnels and so on. I hope you enjoy!

If you'd like to get early access to the project files (they'll be made freely av...

▶ Play video
meager pelican
#

I'd output distToTerain and see what it looks like. (Good work spelling it correctly, lol) and then same for distToWater.

#

I'm not sure your screenpos is correct either.

#
    o.pos = UnityObjectToClipPos(v.vertex.xyz);
    o.screenPos = ComputeScreenPos(o.pos); // using the UnityCG.cginc version unmodified
     
    // fragment shader
    float2 screenUV = i.screenPos.xy / i.screenPos.w;

From https://forum.unity.com/threads/what-does-the-function-computescreenpos-in-unitycg-cginc-do.294470/ post #7

#

@wary jackalThings I would check.

wary jackal
#

Probably a dumb question, but how would I output the distToWater and distToTerrain? Should I do it as a color?

tired canyon
#

If anyone feels like they have 2 cents to contribute

woeful geyser
#

Does one know if there is a workaround to eliminate texture bleeding caused by modulo division?

float4 sample = SAMPLE_TEXTURE2D(BaseMap, Sampler, uv % tile);
regal stag
# tired canyon https://forum.unity.com/threads/shader-graph-never-compiled-with-instancing-enab...

I've done a few experiments in SG using DrawMeshInstancedIndirect, but only in URP : https://gist.github.com/Cyanilux/4046e7bf3725b8f64761bf6cf54a16eb
My understanding is that the GPU instancing option doesn't actually need to be enabled for the Indirect version. And the shader may need to use #pragma instancing_options procedural:vertInstancingSetup (hacked in with a Custom Function node), in order for SG to properly set up unity_InstanceID. The gist has some more info about how I set it up.

wary jackal
#

@meager pelican well, I tried what you suggested and it's still solid white :/
Although, when I do dstToWater = screenUV I get this result:

tired canyon
#

I will have to check it out

#

Information on doing this is few and far between

wary jackal
#

I think my problem might be that Unity is not doing a depth pass. How might I enable that?

meager pelican
#

You should see that it isn't if you output the depth (dstToTerrain).

wary jackal
#

dstToTerrain is just solid white

meager pelican
#

Yeah. You called LinearEyeDepth, which gives you a world-space result back, so it's likely > 1.0. So I guess that's OK. It's not zeros.

#

And distToWater? Also solid white?

#

Or black?

wary jackal
#

so, I changed dstToWater to a float2 and set it as screenUV, just to mess around. I then set color.rg as dstToWater and got weird results

tranquil nest
wary jackal
#

lemme record, 1 sec

meager pelican
#

screenUV (IDK where that variable is) should be black on the lower left corner of the screen, and red going to the right, and green going up, and yellow in the upper-right.

wary jackal
#

yes that's correct.

#

I'm getting really strange blue pixels though

meager pelican
#

That's OK right now. IDK what the other pixels are...z-fighting or some other effect on top of the water...but doesn't matter.

#

Do you have 2 water planes by chance?

wary jackal
#

no just the one

#

well, I have the shader attached to multiple objects, would that change anything?

meager pelican
#

What else is it attached to beside the water? But no, it shouldn't theoretically.

wary jackal
#

It was a couple of 3D objects. I just deleted them

meager pelican
#

Give me 5 minutes to open Unity and make a project and load up your shader. Secs.

wary jackal
#

okay cool

#

Want me to upload it as a file again?

meager pelican
#

Or pastebin it. 😉

wary jackal
tranquil nest
#

@meager pelicanyou use shadergraph?

meager pelican
tranquil nest
#

@wary jackal I see you are using a programming language, can you tell me which language is best for me to start learning for unity, cgfx, hlsl or glsl

wary jackal
#

I'm using hlsl. If you're using unity just stick with that it's kinda standard. I'm also brand new (I only started learning like two weeks ago) so I'm probably not the best person to ask

#

I like hlsl though, it's pretty similar to C#

meager pelican
#

The new stuff is all HLSL in unity. Not OpenGL.
So not to be contrary, but if you're using unity to learn shaders, I'd do HLSL.

tranquil nest
#

is it very different from glsl?

tired canyon
#

Just learn hsls

tired canyon
#

If you learn one learning the second is like 20x easier

#

They are all basically the same thing

wary jackal
#

It's never good to be fussy over the language you use. Use the language that allows you to get the results you want

#

(In this case it's hlsl)

misty flame
#

I've been trying to go through this video but I don't understand a lot of it after going through the compute shader. A lot of the syntax changes between .hlsl, .compute, and .cs and I'm not sure why he's doing a lot of the things he's doing. The only thing I understand is the general idea of using the compute shader to calculate the vertices, put them into a buffer, and render them using a shader. Does anyone know any resources I can use to learn more about this stuff? https://www.youtube.com/watch?v=EB5HiqDl7VE

✔️ Works in 2020.1 ➕ 2020.2 ➕ 2020.3
🩹 Fixes:
► Make sure your source mesh has read/write enabled in it's asset importer inspector.

Compute Shaders are scripts that run on the GPU! They're very powerful, allowing you to leverage the GPU's unique abilities and generate meshes to draw procedurally. There's not a lot of information on using them, ...

▶ Play video
meager pelican
wary jackal
#

what do you mean it isn't working?

meager pelican
#

lol

#

Nothing. Let me play with it, but what settings?

wary jackal
#

uh... wdym by settings? like my project settings?

meager pelican
#

No, the material settings on the water....

wary jackal
#

oh

meager pelican
#

The stuff you pass in.

#

So we can both see the same results.

wary jackal
#

Well, most everything is commented out so all of the material settings don't do anything rn

meager pelican
#

OK

#

Gimme a min or 5

wary jackal
#

haha

#

okay

#

The only settings that would actually do anything are the wave strength and speed

#

@meager pelican if you want my terrain shader I can also provide that

meager pelican
#

I'm good. Got some cubes and spheres. lol

wary jackal
#

You good?

meager pelican
#

Yeah, VS was screwing up (it does that sometimes). Sec. Still messing with different depth options.

#

Get some coffee....

#

lol

wary jackal
#

Yeah I've just been messing around with the terrain shader, trying to make it look better

meager pelican
#

About your earlier question, you can tell if the camera is rending to a depth texture in the inspector. It has an info message as to what type it renders to (in play mode, below target display).

wary jackal
#

I don't see the message

tired canyon
#

Particularly the properties

#

I don't quite understand the comment at the top

#

I did attempt just adding the pragma statement to my custom function but it doesn't seem to have changed anything

#

But maybe it is more order sensitive than I thought

regal stag
#

Not using any properties (unsure if that breaks it), but am using that PROCEDURAL_INSTANCING_ON boolean keyword

meager pelican
#
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Camera))]
public class TurnOnDepth : MonoBehaviour {
    public DepthTextureMode mode;
    void Start() {
        this.transform.GetComponent<Camera>().depthTextureMode = mode;
    }
}```
wary jackal
#

yeah I was in play mode

#

I'll try that

#

brb

meager pelican
#

You can change that last enum to just say ".Depth" if you don't need normals.

light epoch
#

yoo when did they add this to shader graphs??

meager pelican
regal stag
light epoch
#

so shader graphs are now super powerful compared to the old ones?

regal stag
# light epoch so shader graphs are now super powerful compared to the old ones?

I wouldn't say it's that much different really. A couple things renamed (Albedo -> Base Color) but it's mostly the same ports. They also had vertex/fragment stages before but it wasn't as clear.
The main purpose of the change is now a graph can target both URP, HDRP and VFX Graph at the same time (assuming they are installed).

meager pelican
#

@wary jackal I've got it, (or I'm close). Hang on.

light epoch
#

o

wary jackal
#

sick

#

Well, I gtg but when I get back I'll continue

#

thanks for the help

meager pelican
#

That's Fine.. This is close:
https://pastebin.com/exep6wRU
It has some issues. I've done this depth stuff before, but ....I'm just brain cramping I guess. This is close.
P.S. You accidentally misspelled "_ShallowColor", if you care.
New pastebin above (edited). But after that one, I implemented the "colDepthFactor" because I was having fun playing with this.
So just do this (line 131):
float waterViewDepth = saturate(dstToTerrain - dstToWater) * _ColDepthFactor;
if that was your intent for the variable.

woeful geyser
wary jackal
#

@meager pelican thanks so much, I'll look into that in a bit. The amount of time you spend helping people is just insane, so thanks again

meager pelican
#

Was fun.
May have to sign up for fiver though. lol.

#

I'm still having fun screwing with it.

wary jackal
#

Dude you should you've carried me so hard so far

#

To be fair though, I have no money so I wouldn't be able to pay 💔

meager pelican
#

Nah, you're doing great.

#

I understand...

#

Wasn't expecting it.

#

Didn't mean that.

wary jackal
#

Lmao ik I was just kidding around

#

btw, what is the difference between "Pastebin" and "M's Pastebin"

#

also why do you calculate the screenUv?

meager pelican
#

IDK. There's several. There's hastebin too. And others.

Alternative line to try (this deactivates alpha in the two colors, but keeps it for the tint that controls all):

#

You did that, I left it. 😉

wary jackal
#
                float dstToTerrain = LinearEyeDepth(nonLinearDepth);
                float dstToWater = i.screenPos.w;
                float waterViewDepth = saturate(dstToTerrain - dstToWater);

                float4 waterCol = lerp(_ShalowCol, _DeepCol, waterViewDepth) * _Tint;
                return waterCol;```
I have this and it just turns invisible, as far as I know my alpha's are all solid


Oh, I did it because you said to do it earlier .-.
#

wait nvm one of em wasn't

meager pelican
#

IDK, if that's what I meant or not, but moot....you can delete it.

wary jackal
#

hm, now it's only showing the deep color

meager pelican
#

Check the updated pastebin, and also I implemented the depth factor that I don't see in your post above.
make sure you have the tint color set to something like white and nearly 1 alpha for starters.

wary jackal
#

Oh I didn't see that you updated it

#

Would you mind sending the link again? I'm confused as to which one is updated

meager pelican
#

Depens on when you grabbed it. 😉 but I also added a line in the comments above. So:

                float dstToTerrain = LinearEyeDepth(nonLinearDepth);
                float dstToWater = i.screenPos.w;
 
                float waterViewDepth = saturate(dstToTerrain - dstToWater) * _ColDepthFactor;;
                //return fixed4(waterViewDepth.xxx, 1); // debug code
 
                float4 waterCol = lerp(_ShalowCol, _DeepCol, waterViewDepth) * _Tint;  // ??????
                return waterCol;```
or you could change that nest-to-last line to:
```float4 waterCol = float4(lerp(_ShalowCol, _DeepCol, waterViewDepth).rgb * _Tint.rgb, _Tint.a);```
wary jackal
#

Yeah that's exactly what I have and it's not working. Do you think it could be because of my terrain? idk

meager pelican
#

Show me what you get?

wary jackal
#

Like a picture?

#

It's just solid blue

meager pelican
#

Huh. Maybe depth scale.
Put a sphere in the middle of the water. Or a cube that has been scaled up on the Y axis.

wary jackal
#

okay

#

something's working

meager pelican
#

And you can lower the tint alpha to make it more transparent.

wary jackal
#

yeah

#

I have to go eat dinner but i'll be back later

meager pelican
#

LIke I said, "close". I still don't thing it's blending the way you'd want it to.

#

I'll be back tomorrow sometime. 😉 Enjoy dinner. 🙂

#

Check that the terrain is writing to the depth buffer (don't have zwrite off).

misty flame
#

In a compute shader, what defines id? I've tried messing around with the number of threadgroups and I don't really understand that either. Right now it seems like the id loops through every pixel on either the Result texture which is built in or every pixel on the screen. Is the Result texture that comes with the template compute shader needed in every compute shader?

meager pelican
#

No, that's "just" the output. They way they call it determines the #invocations along with [numthreads]
It's a bit hard to explain. Have you seen the Microsoft documentation on it? Maybe we can start there, there's pics that help show it all.

#

Sec:

#

So it is common to see
[numthreads(8,8,1)]
At the start of a kernel.
Then, when they call it from C#, they decide how many of these 8x8 groups they're going to invoke, and by how many rows, columns.

wary jackal
wary jackal
#

yeah, aren't all terrains?

meager pelican
#

Sorry. My bad.
The terrain isn't a vertext displaced mesh, it's a normal mesh, that looks like it has hills and lakes and stuff?

#

Are you sure you have a depth texture going on the camera? Remember that script for the camera, is that on there? On the same camera as the terrain is on?

wary jackal
#

Yeah

#

Ik it works because the default material works

#

it has something to do with the actual shader

meager pelican
#

OK

wary jackal
#

I think somewhere inside the shader I need to tell it to write to the camera's depth texture

meager pelican
#

ZWrite On

wary jackal
#

oh really?

#

that's it?

meager pelican
#

Well, assuming you didn't hose up the z value, sure.

#

😉

wary jackal
#

nope, didn't work, maybe I'm typing it in the wrong place?

meager pelican
#

If you were, you'd get an error.

wary jackal
#

hahaha I wrote it in the wrong script

meager pelican
#

sec, let's see what Aurcereal is saying.

misty flame
meager pelican
#

Show me the kernel function (first few lines). What SV are you using?

misty flame
#
#pragma kernel CSMain1```
#

I don't really understand the SV tbh but it's SV_DispatchThreadID

meager pelican
#

OK

misty flame
#

Does the SV determine what id is?

meager pelican
#

The sematic does, yes. So SV_DispatchThreadID is one of the many variables. See that documentation link I posted for you? There's a bunch of SV_whatever's listed on the left panel. They all give different values depending on what you want, and those pics kind of break all that down.

#

So there's a "group" running of let's say 8 x 8 cpu cores processing things. So 64 cores in a group.
Then there's how many groups you want run in total.

wary jackal
#

so, ZWrite On doesn't do anything, as it's enabled by default I believe. Maybe it's another setting?

#

Sorry I don't want to interrupt

misty flame
#

It's all good but yeah that makes sense on the groups. And there are 4 semantics. The SV_GroupThreadID has id be determined by the id of the numthreads[(8,8,1)] from what I can tell.

wary jackal
#

Copy and pasting some code and I'm set to go. No idea what the code does but that's not the point

misty flame
#

So using SV_DispatchThreadID makes sense

#

Thanks I get it now

meager pelican
wary jackal
#

No, it was further down.


Here's the copy/paste of the relevant section:
Code (CSharp):

            // shadow caster rendering pass, implemented manually
            // using macros from UnityCG.cginc
            Pass
            {
                Tags {"LightMode"="ShadowCaster"}
     
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #pragma multi_compile_shadowcaster
                #include "UnityCG.cginc"
     
                struct v2f {
                    V2F_SHADOW_CASTER;
                };
     
                v2f vert(appdata_base v)
                {
                    v2f o;
                    TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
                    return o;
                }
     
                float4 frag(v2f i) : SV_Target
                {
                    SHADOW_CASTER_FRAGMENT(i)
                }
                ENDCG
            }

meager pelican
#

I was looking at the wrong tab, sorry. lol

#

Had the water shader and it is transparent, which would explain it.

wary jackal
#

great now my lighting is kinda screwed up

#

(For the water, the terrain is fine)

meager pelican
#

The blend on the water is probably not right yet, but we got depths working.

#

And didn't calc any lighting for the water, it was all commented out.

wary jackal
#

Yeah, I commented it back in

meager pelican
#

OK, so now you have shadows. Did you get depth too?

wary jackal
#

Yeah for some reason if you want depth you need shadows... I don't really understand it but it's all there in the forum

#

if you scroll down long enough

meager pelican
#

OK, out of the dim recesses of memory, that makes sense. Because there's a depth texture that has virtually nothing to do with the depth buffer. lol.

#

But the shadow caster pass is used to write a depth. Normally that's done for a light, but I guess they use it for the camera too to update the depth texture.

wary jackal
#

Yeah that makes sense

meager pelican
#

This is a good reason to have a fallback line in your shader. I should have put one in, but that wasn't what we were working on, ATM.

wary jackal
#

Yeah I suppose so, I haven't really learned much about passes and shadows yet

#

so, the light is moving depending on where the camera is. I didn't change anything in the lighting code yet it's doing that

#

Hang on, I'll have to come back to this in a couple of minutes. I gotta go do something.

meager pelican
#

OK, but comment out or delete that extra code, and just add:
Fallback "Diffuse" to the end of your shader, before your last }

#

That way, you always get Unity's version, and your shader stays up to date, and you don't have to chase any possible bugs there.

wary jackal
#

Okay

cosmic quail
#

maybe a dumb question.. but when sampling the depth texture of a camera, can it return 0? I know the value is supposed to be between 0 and 1, but do i need to check that the depth of a position is not 0 before dividing by that value?

brittle owl
#

hi! im trying to fake 2d animation fps. how would i go about changing the fps of an overlay camera?

#

(without any rendertexture stuff cause i tried that and it has problems)

full salmon
#

Quite a simple question, I think here is the right place. When you're looking at a mesh in the editor, one of the view types is "normals", which I refer to in my head as "pretty rainbow mode". Does anyone know (or can use their greater experience to infer of reverse engineer) how the colours used in shading are derived from the surface normal? It seems like hue is changing all around the sphere, with no change to brightness and some variation in stuaration.

#

I'm thinking of making a sort of instant-gratification machine for my kids and pretty rainbow mode would be a useful addition.

tired canyon
#

Red Green and Blue are each used to represent a different axis

#

It's fixed

#

I forget which direction is which

#

But say Red is the X axis, Green is Y and so on

#

The color it shows you is indicating the direction the light came from after reflecting off that surface

full salmon
#

Ah ok, that makes sense, thanks!

meager pelican
# cosmic quail maybe a dumb question.. but when sampling the depth texture of a camera, can it ...

Use the macros to read it. Different platforms store that depth-data differently, and it's usually in a special format. Just FYI. But that said, after it is decoded by the macros, a depth of 0 isn't likely in the fragment shader because it would be clipped by the near-plane of the camera, so it doesn't happen. That's why the camera depth plane is something like 0.03 or whatever the default is. Unless you do something funky in your shader and get NaNs that get treated as zeros or some weird thing.

meager pelican
# full salmon Ah ok, that makes sense, thanks!

Yes, but vectors are in 3D space, and 1/2 of them are in the negative quadrants.
So it is perfectly possible to have a surface normal vector (pre normalized) that is (-1,-1,-1), but that color is "black" and so are all the others up to (0,0,0). It is common to multiply it by 0.5 and then add 0.5 to compensate. But you lose 1/2 the color resolution (on the original values of RGB) in a sense, because you're stuffing a -1, +1 range into a 0, +1 range.

#

Make sure you normalize that result again to get a unit length vector.

full salmon
#

This turned out to be really simple to get what I want

meager pelican
#

Nice. but can't remap take a vector3? Or no?

#

Leme look.

#

If it cannot, you're faster with vector math.

regal stag
#

Yeah, you can remap with a Vector3

full salmon
#

nice!

meager pelican
#

And if you want an actual normal, you should run it through a normalize.

#

That will help your color intensity too.

full salmon
#

I'll try that but I want prettiness over accuracy 😄

meager pelican
#

In CG, the saying is "if it looks good, it is good". 🙂

full salmon
#

😄 like it. Looks great now and super simple, thanks!

meager pelican
#

And for the budding Cyan's out there, it would be interesting to see what code gets generated for the two methods.
On many GPUs, there's a multiply-then-add instruction that basically can do both in one cycle. And the compiler will substitute it where it can during optimization.
So for Shader Graph, it might make a function call to do remap and result in a call and a whole bunch of instructions. But if you were doing a "rainbow world" and you had to do that for every pixel, you'd want the fastest calc.
So you may find that
float3 newColor = normalize(surfaceNormal.rgb * .5 + .5);
compiles down to many fewer instructions. Or maybe the compiler will figure it all out and inline the remap to boot! IDK. Wound be interesting to test. And you may not need the normalize, I'm unsure.

full salmon
#

I ended up taking it out purely on aesthetic judgment.

livid moat
#

hey guys
having a little question on shader graph

I have a time node which outputs the pure time value, then I'm multiplying it by a speed variable and using the result of this multiplication to move a texture offset.

I'll need to change the speed variable in runtime, however, when I'm changing it, the texture offset changes enormously.

like, if it was flowing with a normal speed and I decided to cut the speed by 2, the offset will change to something entirely new, and then continue 2 times slower

#

guess I realize why this happens, but I don't know how to solve this problem. I simply don't know where else can I apply the Speed variable rather then multiplying time by it

meager pelican
#

You need deltas

regal stag
livid moat
#

ohh

#

lol why am I so stupid today

meager pelican
#

So you're NEXT FRAME delta-xy will be scaled by the rate, and added to your current xy.

livid moat
#

such a simple solution

huge thanks

meager pelican
#

It's the same idea as Time.deltaTime. That's probably what you want to scale, in fact, since it's frame-time relative already.

#

😉

tired canyon
#

hmmm

#

ooh cyan you are here

#

I'm running in to the same issue that I was having previously

#

which is that unity_ObjectToWorld is read only now

#

I am definitely getting compilation now

#

with instancing enabled

#

so that's a win

regal stag
tired canyon
#

if I use unity_objectToWorld

#

I get a compilation error telling me to use the macro

#

if I use the macro I get a compilation error that out params require an lvalue

regal stag
#

I guess use UNITY_MATRIX_M then instead

tired canyon
#

that gives me the first error

#

out parameters require l-value arguments

#

it seems like they have taken some steps to stop people from modifying those matrices?

#

I'm running on the latest version of things

#

idk what version you were using to test

regal stag
#

I'm on 2020.3, but also URP and I think you're using HDRP so things might be different anyway

tired canyon
#

ah yea that might be the difference between HDRP and URP

#

@regal stag TY! I can't adjust the matrices the way that you could in URP but I am at least getting access to instance values!

marsh kindle
#

Hello, anyone try this wobble effect? if yes, did it work properly? cause i have some problems on the X axis
https://www.youtube.com/watch?v=eIZgPAZx56s&t=167s&ab_channel=BinaryLunar

In this video we will show you how to create a Potion Liquid Wobble Shader Graph using Unity 2020.3 URP.
Download project files (Patrons Only): https://www.patreon.com/BinaryLunar
00:00 Intro
01:00 Create new unity URP project
02:00 Creating Glass Material
03:10 Creating Liquid Wobble Shader Graph
03:35 Creating the fill nodes
05:50 Coloring the...

▶ Play video
royal gazelle
#

I have a some quads that overlap on the same plane. They're z-fighting so I thought I could incrementally increase the shader's Offset values? Can I access that value from a script? Does that sound sensible?

#

Or if I can change it, will it change it everywehre

meager pelican
#

Just offset the transform.position by .001 increments in the transform in the direction orthogonal to the plane. If that works for you. Otherwise, you'll need to pass in the offset and/or calculate one in the shader, and in either case you'll need a custom shader.

royal gazelle
#

@meager pelican Thanks, I'll try offsetting them first and see how long it takes for them to get an unreasonable distance away from the wall. I tried 'ZTest Off' and that almost works (I don't care which order they go above each other for a minute), but TextMeshPro means I'd have the dig around in that shader too

#

standard shader zfighting

#

ztest off

royal gazelle
#

@meager pelican thanks, adjusting the position works fine

meager pelican
# meager pelican And for the budding Cyan's out there, it would be interesting to see what code g...

If anyone else is curious, I ate my own theoretical dog food, and did a compiler output test of the SG remap vs the a hand-coded URP frag() math, just because I was curious as to the real-world results.

Hand coded...is 3 instructions (due to the need to have a half4 returned with alpha 1.

dcl_input_ps linear v1.xyz
dcl_output o0.xyzw
0: mad o0.xyz, v1.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000), l(0.500000, 0.500000, 0.500000, 0.000000)
1: mov o0.w, l(1.000000)
2: ret ```

the Shader Graph remap node produces not-bad code, but larger:
```ps_4_0
dcl_input_ps linear v1.xyz
dcl_output o0.xyzw
dcl_temps 1
0: dp3 r0.x, v1.xyzx, v1.xyzx
1: sqrt r0.x, r0.x
2: div r0.x, l(1.000000, 1.000000, 1.000000, 1.000000), r0.x
3: mad r0.xyz, r0.xxxx, v1.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
4: mul o0.xyz, r0.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000)
5: mov o0.w, l(1.000000)
6: ret ```

and a basic "just do the math in Shader Graph" (Normal-->Multiply-->Add--> to _Base Color output) produces:
```ps_4_0
dcl_input_ps linear v1.xyz
dcl_output o0.xyzw
dcl_temps 1
0: dp3 r0.x, v1.xyzx, v1.xyzx
1: sqrt r0.x, r0.x
2: div r0.x, l(1.000000, 1.000000, 1.000000, 1.000000), r0.x
3: mul r0.xyz, r0.xxxx, v1.xyzx
4: mad o0.xyz, r0.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000), l(0.500000, 0.500000, 0.500000, 0.000000)
5: mov o0.w, l(1.000000)
6: ret ```

All above are frag shader portions.
Looks like the math-version in SG is about the same as the Remap version, so the optimizer fixed it up, figured out the math, and the end result isn't identical, but it's similar.  IDK enough about IL to tell the cycle cost/speed of it all, probably really close.  And some of this might be SG overhead that's a few instructions that are just "standard" for SG.

The by-hand version wins out over both though.
If I did all that correctly.
brittle owl
#

hey, how do i have a different a different renderer on a different camera in urp?

#

i want SSAO on one camera but not on another

regal stag
brittle owl
#

oh! i didnt see the place where you can add the renderer to the urp asset

#

thanks!

nimble ermine
#

Has anyone come across a shader not compiling in the editor but also not giving an error code? When I save my shader in Visual Studio and move back to the Unity editor it flashes the color I would expect from the shader and then immediately turns white as though it can't compile. But there is no error code given so I don't know where to fix my shader code

meager pelican
#

Captain, shaders that can't compile turn pink...

nimble ermine
light epoch
#

do you guys ever wanna do something but dont even know where to start? google is giving me nothing

#

i wanna have a scan transition kinda, between two materials or gameobjects

#

like this maybe

#

where it scans down to transition between the circle and square

#

i cant even find anyone else attempting this on google

wary jackal
#

Sounds cool. you want to do this in a shader?

meager pelican
#
  1. Default layer 1, everything that isn't impacted by the effect....to background render texture with main camera.
  2. Layer 2 "blue circles" layer....with camera to render texture.
  3. Layer 3, "Black boxes" layer....with camera to render texture.
  4. Post processing shader that has some "line" equation and a wipe effect that either overlays texture from #2 or from #3 over top and blits the results of the 3-combined textures to the destination/output.
light epoch
#

im working on a different effect right now with a hologram thing and a toggle

wary jackal
#

https://www.youtube.com/watch?v=cWpFZbjtSQg
The section about slicing might help, but I don't think it's what you want. I would just listen to CarpeFunSoftware

Experimenting with portals, for science.

The project is available here: https://github.com/SebLague/Portals/tree/master
If you'd like to get early access to new projects, or simply want to support me in creating more videos, please visit https://www.patreon.com/SebastianLague

Resources I used:
http://tomhulton.blogspot.com/2015/08/portal-rende...

▶ Play video
light epoch
light epoch
#

i have that shader in my assets but it doesnt work in urp

#

i tried to recreate it in shader graph but i couldnt get it to work

wary jackal
#

Uh, well lucky coincidence I guess

light epoch
#

yeah

wary jackal
#

That's the first thing I thought of when I saw your graph 😛

#

How might I have it so that the normals are only able to be seen if the directional light is being applied to it? I don't like the way the water looks when there's not direct light on it...

#

I'm pretty sure my lighting code is pretty terrible, so I might need to go back and rework some of it

light epoch
wary jackal
#

Make it turn from a cube to a circle, I want to see that

light epoch
#

@wary jackal

#

its my first attempt at making a shader myself

wary jackal
#

I think it looks pretty decent

light epoch
#

thx

#

is it possible to apply multiple shaders to something

wary jackal
#

no

light epoch
#

bruh

wary jackal
#

because you can only have one material

#

I could be wrong though, I'm also very new

light epoch
#

idl ike to transition between these

#

its pretty ugly rn

wary jackal
#

So, idk if this would be possible, but do you think you could add like a diffuse map on the outside so it doesn't look so blocky when you transition?

#

I don't think diffuse map is the right word

#

falloff map might be the right word

light epoch
#

i dunno what that means lmao

wary jackal
#

So, you want your shader that transitions as well as the other shader, right?

light epoch
#

yeah

#

or a new way to transition

wary jackal
#

Can you combine the two shaders?

light epoch
#

i could try

wary jackal
#

That might be hard. Another thing you could maybe do is make the outline of the portals their own separate object?

#

That way they can have their own material

#

Sorry I feel like I'm not helping all that much

light epoch
#

im just trying to merge the shaders rn

wary jackal
#

Make sure you have a backup of your other shaders. You don't want to create a new one that doesn't work and not have the old ones

light epoch
#

how would i do this in shader graph

#

i dont understand this

wary jackal
#

I believe what that's doing is getting your view distance from the portal and changing the color based on that

light epoch
#

i have no idea lmao

#

i didnt write that shader

wary jackal
#

Actually it's the view angle

#

not the view distance

light epoch
#

i dunno how id do that in shader graphs tho

wary jackal
#

Sorry I don't use shader graph

light epoch
#

my shader is entirely based on the alpha clip threshold and alpha so it should be able to work independently of all of that stuff

wary jackal
#

I know nothing about shader graph unfortunately. I write all my code .-.

crisp ridge
#

Weird question... if anyone have an idea go ahead...
In my code I initiate 3 colors

        colorBridge = GetHexColor(coordBridge, d, colorBridge_Normal);
        colorCorner = GetHexColor(coordCorner, d, colorCorner_Normal);

And to keep thing simple I assign them that way
o.Albedo = colorBridge;
It work well visually, but if I use ColorHex, I get about 2x the FPS than if I use colorBridge or colorCorner
Any idea?

meager pelican
#

You said you wanted a wipe effect.... with several objects....

#

@light epoch that's different than vanishing/fading in/out of two objects placed in the same location. It's a wipe.

#

You have to decide on what you want.

light epoch
#

anything smooth, i wanted a wipe ideally but i settled for a different effect

meager pelican
#

@crisp ridgeAre you talking about shaders?

light epoch
crisp ridge
#

Yes...

wary jackal
#

@light epoch it's certainly smoother, but I thought you were going to with the effect you just made?

light epoch
#

that is the effect i just made

wary jackal
#

The transparent kinda glitchy one?

crisp ridge
#

@meager pelican Full simplified code, I remove everything else

{
    float2 positionWS = d.worldSpacePosition.xz;
    ComputeHexData(positionWS);
            
    float3 colorHex =  GetHexColor(coordHex, d, colorHex_Normal);
    float3 colorBridge = GetHexColor(coordBridge, d, colorBridge_Normal);
    float3 colorCorner = GetHexColor(coordCorner, d, colorCorner_Normal);

    o.Albedo = coordHex; // performant
    o.Albedo = colorBridge;// performant
}```
Other variable are define as Global
light epoch
wary jackal
#

Yeah it just happened so fast I couldn't really see it

light epoch
#

i could slow it down 1 sec

wary jackal
#

yeah do that, all that work would go to waste if you don't

#

Oh also, you need to make the scaleup smoother, I think you did it by hand which is why it looked weird, but it was pretty choppy

light epoch
#

its not growing its moving closer to the camera

wary jackal
#

oh

#

may I ask why?

meager pelican
#

OK, I see what you're doing.
And you want to test performance of colors? Should be the same. They all get assigned to floats, red, green, blue. Assuming the color calc is the same for all. IDK what that's all about.

So...since you're only assigning one of them, comment the others out. Test them one at a time isolated, not with all three in the code.
It may be performance, or it may be the way the optimizer is dumping your unused code.

light epoch
#

the mirror is whats used to move

#

u cant turn ur head

wary jackal
#

wait really?

light epoch
#

yeah

wary jackal
#

wait hang on. Explain the game to me pls

light epoch
#

cant turn ur head, u have to use the mirror to turn the right way and go through puzzles

#

theres a normal world and mirrored world kinda

wary jackal
#

That sounds really cool

#

So when you choose you can walk through the mirror?

#

Or you can put the mirror through yourself?

light epoch
#

you walk through it

#

after picking a spot

wary jackal
#

Ah okay, and do you get another mirror once you walk through?

light epoch
#

yeah theyre infinite atm

wary jackal
#

That sounds like a really cool concept

light epoch
#

u use the same mirror but just move it

#

u can see how the text is affected

#

by the mirror movements

wary jackal
#

That looks really cool. As far as a game design perspective, it looks extremely challenging. You're going to have to make a really good tutorial level if you want your players to be able to solve puzzles

light epoch
#

yeah i know

#

im taking it really slowly

#

before i introduce the concept of like

#

differences between the normal and mirrored world

#

level design is by far the hardest part of this all

#

which is why im working on polish before i even get to that point

wary jackal
#

Yeah, just from that first little "turn around" part it kinda blew my mind

light epoch
#

lmao

#

i got the idea to make this when i was

#

maybe

#

12 years old

#

nah more like 10 or 11

#

and i had no idea how to even approach it

wary jackal
#

Was that a long time ago?

light epoch
#

im 15 now

#

so for me yes

wary jackal
#

Okay, so a decent amount of time

#

Well it's cool that you're approaching something you never thought possible

sonic berry
#

Hey guys I have a question about creating material and stuff, is that the right place ?

light epoch
#

i approached it in unreal engine but it just didnt have the capabilities i needed

wary jackal
#

Flaze it probably is

light epoch
#

i couldnt use an oblique clip plane so it was kinda wonky

#

well not with blueprints

#

and i wasnt gonna attempt c++

wary jackal
#

c++ isn't so bad

sonic berry
#

I'm having this problem where my material is bugged

wary jackal
#

The chess board?

sonic berry
#

yes

wary jackal
#

Doesn't look like it's bugged, it just looks like it's wrapped around the board in the wrong way

#

I could be wrong though, I only see that one picture

sonic berry
#

Hm, let me check

#

From one angle it is not displaying basically

wary jackal
#

Can you take a short video?

sonic berry
#

yes

wary jackal
#

From what I see in the pictures it looks like "Cull Front" is enabled somewhere

sonic berry
wary jackal
#

It looks like the shader isn't rendering the front of the object.

wary jackal
#

Let me see your settings for your material

meager pelican
#

What material are you using? Custom shader?

sonic berry
#

I basically imported a fbx, and a png

meager pelican
#

What shader. What material?

sonic berry
#

I created a material

#

to add the png

wary jackal
#

What shader is it using?

sonic berry
#

unlit/texture

wary jackal
#

try the default shader?

#

see what happens then

meager pelican
#

That's Unlit-Normal, basically.

wary jackal
#

oh

#

still, doesn't hurt to try

meager pelican
#

Check the texture import settings.

sonic berry
#

Standard ?

sonic berry
meager pelican
#

And the FBX could have issues with UV mapping.

real pilot
#

Does anyone know offhand what precisely the nonlinear function is that unity's Depth/Zbuffer value is?
I am trying to write out a depth from a raymarch compute shader which I can then use with eg particles for proper occlusion. The nearest I've been able to get visually is this:

float a = (CameraMaximumDistance + CameraMinimumDistance) / (CameraMaximumDistance - CameraMinimumDistance);
float b = 2.0 * CameraMaximumDistance * CameraMinimumDistance / (CameraMaximumDistance - CameraMinimumDistance);

float ze = (dot(hit.position - ray.origin, CameraForwardVector) - CameraMinimumDistance);
float zn = a - b/ ze;
gl_depth = 1.0 - sqrt(zn);

And that sqrt() irritates me immensely. It is so close to looking correct that I'm sure no-one would actually notice, but I can't believe that's actually how the depth buffer is meant to be constructed!

sonic berry
#

That's this one

#

That's my png import settings

meager pelican
#

@sonic berry Well, it looks like there's an intentional line going down one side, and the vertical edges are "striped".
And your import settings look OK to me.

real pilot
#

Standard RP, compute shader multikernels doing the raymarching, with a final texture copy to a RenderTexture that's then blitted in a command buffer.

#

I really just want to know the nature of the non-linearity

sonic berry
#

That's when I import it without doing anything

#

When I select it in the pannel on the left, I get these settings

meager pelican
# real pilot I really just want to know the nature of the non-linearity

The NATURE of it? Oh. Seems like they wrote an article or two about it when the switched methodology. But basically it is encoding a high-precision float into a float2, and decoding it. And IIRC the depth calculation is nonlinear from the clip-space or NDC perspective to preserve precision. Let me see if I can find you something. But you should look into the include files or download shader source if you haven't already. There's things like DecodeDepth...macro or function.

And watch for blits, as they often don't copy depth buffers over.

real pilot
#

Oh I have it working with my own material to do the depth buffer copy, it looks right, I just don't have any logical basis for the 1 - sqrt(zn) line that I tried in desperation!
I'll dig through the includes, cheers

wary jackal
#

@light epoch this probably isn't the place to ask the question, but how do you get the videos to show in discord without having to download them?

light epoch
#

just send it like a file

wary jackal
#

Yeah that's what I do

light epoch
#

send one

wary jackal
#

okay

#

One moment

#

For me it shows a download

#

does it for you?

#

Maybe it's the file type

light epoch
#

its the file format

wary jackal
#

k lemme figure out how to change that

sonic berry
#

I see here that it is expected that the texture should go around the board, there is a clear line, so why isn't working! 😦

wary jackal
light epoch
#

that works

wary jackal
#

nice

#

Thx for the help

#

oh also what do you think of the water?

light epoch
#

looks good

meager pelican
wary jackal
#

what is a S W A G?

meager pelican
#

Silly Wild Azz Guess.

wary jackal
#

ah lmao

#

I figured it was something like that

#

Okay so this is kinda stupid, but it does look kinda cool. Should this be one of those "it's not a bug it's a feature" moments?

meager pelican
#

I like how your water/terrain is coming.

sonic berry
wary jackal
#

oh thx @meager pelican

sonic berry
#

i created a board myself.... but the texture is not working when clamped

meager pelican
#

IDK.

#

Could be the model.

sonic berry
#

How does he make it look like that, it's crazy

meager pelican
#

If you're using stock shaders it should work.

sonic berry
#

I payed 10 buck for this, i'm pissed

sonic berry
meager pelican
#

Did you try the standard shader like @wary jackal suggested?

wary jackal
#

He did.

#

@sonic berry are you able to contact the creator?

sonic berry
#

I will...

meager pelican
#

I like glow in the dark water. But that's me....

wary jackal
#

"Feature"

meager pelican
#

Yep. lol

wary jackal
#

I mean, I can get it to not do that but it's not as stylized and the normal maps look ugly

meager pelican
#

That's not bad, but what you're "missing" for water is reflections. But that gets even harder, and is often not done in "stylized water". Up to you. But at night it would reflect any light source or mood or whatever. Otherwise it is a black mirror, basically.

#

With waves or not.

wary jackal
#

Yeah, but I think ima focus on getting shadows and stuff

meager pelican
#

I would agree on that priority for that style if it was up to me.

#

I mean, reflections are expensive too.

wary jackal
#

yeah

#

do reflections always involve ray casting?

meager pelican
#

"Sort of". I mean you need a logical "ray" to the point, and you need a reflection ray to the "source" for the reflection even if it is a map from a reflection probe. (Which have their own encoding).

wary jackal
#

The two things I want to do are get shadows working and making a skybox that fits the style

#

I would like to make a game eventually lmao

#

Oh jeez I don't even want to think about 3d modelling

devout quarry
#

A step or smoothstep can make it look more stylized as well. And for reflections you could re-render the geometry at a lower resolution with a secondary camera and use that for planar reflections but not sure if that would work if you have a spherical planet.

meager pelican
#

@sonic berryYou're in the standard pipeline, right?
Let's make you a shader to show the UV mapping of the mesh. There's already debug-views for the surface normals that you could check. If you go to the scene view tab/screen, there's a drop-down box that has options for what you want to view and you'd look for one that shows "normals".

But there's probably isn't one for UV mapping.

#

If you want.

#

@sonic berryYou can also check the import settings on the FBX model....like recalc normals, and any other things if related to UV's.

wary jackal
#

@devout quarry yeah I actually am scrolling the normal map in opposite directions (I think i wasn't in play mode when I recorded), i'll have to figure out different directions. I'll have to look into what a step and smoothstep is, as for reflections, I like that idea, but for now I'd like to get shadows working first. Thanks!

wary jackal
#

I've been looking at coding a custom skybox, and I found this tutorial which seemed promising, but upon further reading it just says "copy and paste this code". It seems to get the results I want, but I don't really know how it works, and that is not what I want. Does anybody have a resource I can use to learn, or is willing to explain how it works?

https://gamedevelopment4newbies.wordpress.com/step-3/

light epoch
#

why doesnt this alpha work?

#

im not too sure how this shader works, i added the alpha to it

#

this is the original

#

got it

#

i added Blend SrcAlpha OneMinusSrcAlpha in the subshader thing

wary jackal
#

nice I was just gonna say that

#

So I made this really trash "fog" shader, because I really had no idea what the heck I was doing. It "works" but it's pretty terrible. Any suggestions on making it look better?

light epoch
#

woah

frigid pelican
#

(Gydhia is coming)

cinder forge
#

Did you found a solution for this ? I have the same issue 🤔

cerulean dune
#

Hey ! I'm using some FX in my game, but it doesn't seem to work with URP, and the material appears pink (I tried to upgrade to URP)
The material works with a shader, may anyone could help me with the simple code below please ? :s

Is there something to change so it would work with URP ?

Shader "PolygonArsenal/PolyRimLightSolid"
 {
     Properties 
     {
       _InnerColor ("Inner Color", Color) = (1.0, 1.0, 1.0, 1.0)
       _RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
       _RimWidth ("Rim Width", Range(0.2,20.0)) = 3.0
       _RimGlow ("Rim Glow Multiplier", Range(0.0,9.0)) = 1.0
     }
     SubShader 
     {
       Tags { "Queue" = "Transparent" "RenderType"="Transparent" }
       
       Cull Back
       Lighting Off
       Blend SrcAlpha OneMinusSrcAlpha
       
       CGPROGRAM
       #pragma surface surf Lambert
       
       struct Input 
       {
           float3 viewDir;
       };
       
       float4 _InnerColor;
       float4 _RimColor;
       float _RimWidth;
       float _RimGlow;
       
       void surf (Input IN, inout SurfaceOutput o) 
       {
           o.Albedo = _InnerColor.rgb;
           half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
           o.Emission = _RimColor.rgb * _RimGlow * pow (rim, _RimWidth);
       }
       ENDCG
     } 
     Fallback "Diffuse"
   }```
sleek condor
cinder forge
sleek condor
#

No, because there is another material on the moutain that the one on the ground

cinder forge
#

I don't see why this would solve the issue 🤔

sleek condor
#

One material can be pierce by the stencil buffer, the other not

cinder forge
#

Ok I see. It won't work in my case tough because I have to use the same material for the mountains 🤔

#

If I could find a way to make the stencil test to fail if the z difference is greater than a small number, it might work. The goal here is to not see the road trough the hill :

#

In this case, the road is a lot further away from the camera, if we compare it to the terrain, because it's on the other side of the hill, so the stencil test should fail because of that

meager pelican
#

@cinder forge You can use z-test and stencil at the same time....

#

@cerulean duneUse shader graph and re-write it.

grand jolt
#

Hey guys. Anyone managed to reconstruct the world position using the depth buffer with the Post Processing Stack V2 (Standard pipeline)?

#

I've found some samples over the internet, but so far, no one worked as expected

cerulean dune
meager pelican
grand jolt
#

@meager pelican I've tried so many solutions...lol

#

I'm rolling back the code to the one that "almost" worked

#

It worked in the scene-view

#

But not in the game-view

meager pelican
#

Try this. This is just a goolge (hope it wasn't one that didn't work already). He's doing it in a post-processing "blit"...He'd pass those matrices in each frame, basically builds a matrix to compute it from the depth given the current camera's matrices.
https://stackoverflow.com/questions/39935774/unity-shaderlab-transform-from-screen-space-to-world-space

#

That might suck though, on second look if he's using GL stuff.

#

@grand jolt

grand jolt
#

Gonna check it out

urban sand
#

Hey i have a problem

#

i have texture rendered from a camera

#

can project it right

meager pelican
urban sand
#

yes i cant

#

i am trying to project the dashed line and the inner area to wood

grand jolt
#

hmm

urban sand
#

there is no alpha info on the texture bcs camera doesnt have alpha buffer i guess

#

i found a trick solution

#

just increasing the intensity of the color manually

#

but i would be glad if i know a clean solution

meager pelican
# urban sand i am trying to project the dashed line and the inner area to wood

Thanks for that. Uhmmm that's not quite what I was asking though.
Do you want an outline shader, or do you specifically need this projection methodology to work for some strange reason?

I'm asking because that's not how you commonly do an outline, and further, you'll have to keep the two cameras and object locations in sync as you do the rendering of the first texture, or the top oval won't match the outline of the log (which already shows in your example...the outline is more curved on top than the other object).

urban sand
#

well the dotted area comes from a custom polygon component

#

it is easy to level design that way

#

so i am focusing on taking the texture and projecting it

cold sand
#

Is there a way I can specify max texture resolutions per scene? For example, having a high res texture on a model in a menu vs a lower-res version ingame.

#

I know this is often done through LODing, but I'm not sure if that is the best approach here

meager pelican
#

LOD usually has a much to do with the detail of the model's mesh as it does with the texture (MIP levels). The idea being to swap out lower resolution meshes at greater distances...to a point. You really only need about 2 or 3 models, triangles are relatively cheap.

So with MIPs the GPU automagically selects the MIP level according to the resolution it is rasterizing the object at during the rasterization stage. That said, in a shader, you can specific the MIP level directly if you wish.

In the end, I'd say it will probably be easier, if it works for you, to make sure you're using mipmaps or simply have two versions of the texture. But if you're using mipmapping, you should get lower res versions automatically. There's mip-level settings on the Tex2DLOD function if you want to override them in your custom shader.

https://www.youtube.com/watch?v=8OtOFN17jxM

If that's TMI, then just set the mip level bias in your shader by sampling at a different MIP level.
https://www.youtube.com/watch?v=2G0Sime3OH0

This video is part of an online course, Interactive 3D Graphics. Check out the course here: https://www.udacity.com/course/cs291.

▶ Play video

✔️ Works in 2020.3 ➕ 2021.1

Mipmaps are scaled down versions of textures Unity generates which look and perform better when the texture shrinks on the screen. In this video, I wrap up this series on mipmaps by investigating how the renderer chooses which mip level to use and how you can influence this with SampleTexture2DLOD and mipmap biases. ...

▶ Play video
#

There's also settings for the texture importer (might be hidden). And IDK how/if that impacts the UI either.

cold sand
#

@meager pelican ok, so unity handles the mipmaps automatically. That was actually my next question, if manually setting these was actually necessary. thanks for the information!

gentle hull
#

Hi, I have an unlit shader in shadergraph withe a custom light function. I want to sample information from the ShadowMask for additional lights. I use GetAddionalLight function but don't know how to fill the shadowmak parameter.
I try the following code where lighmapUV is TEXCOORD1 but the result for the shadowmask is not correct
half4 shadowMask = SAMPLE_SHADOWMASK(lightmapUV); Light light = GetAdditionalLight(i, WorldPosition, shadowMask);

meager pelican
#

They compute shadow information in there, there's sample code.

regal stag
gentle hull
meager pelican
#

It looks like they have standard functions for that stuff (it's detailed in the tutorial).

#

Like (just browsing it)

   half4 clipPos = TransformWorldToHClip(WorldPos);
   half4 shadowCoord = ComputeScreenPos(clipPos);
#else
   half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
#endif
...```
#

There's an include file you'll need.

regal stag
sonic berry
gentle hull
cosmic quail
#

hi there. anyone know how i would predict the depth at a certain pixel given its neighbor's normal and depth, assuming they are on the same face?

wary jackal
meager pelican
#

You know what the gradient node is, right? So it's like that, but instead of smooth gradations, it's in "blocks"/"jumps".
So imagine a ramp of 5 white tones, with black, 3 intermediate values, and then white.

Often used in toon shading. It's just a lookup method. You can do it multiple directions (XY) too. He shows them at the bottom of the article.
So you might calculate, say, an N dot L simple lighting, but instead of just multiplying that directly, you'd take the 0-1 result and look up into your ramp texture to get the result.

past kraken
#

Does anyone have glitch effect? I wanna this effect for my UI :)

wary jackal
#

@meager pelican uh, I don't use shader graph, so I don't have nodes. My problem came when I was trying to make my own, and I found this: https://rampgenerator.com/

How is that a texture?

lilac ocean
#

hi everyone! anyone know a possible fix for the shadergraph preview working but the shader not showing anything in the scene view?

wary jackal
#

Chaotic Curiosity is it working in the game view?

lilac ocean
#

it works in play mode too

#

yeah

#

i know it's just a button somewhere, probably

wary jackal
#

Then It's probably a post processing effect

#

Is it? Sorry I don't want to assume

lilac ocean
#

I'm in a brand new HDRP project, if that helps

#

oh i'm totally guessing lol, I thought it's just one of those things

wary jackal
#

I actually don't use shader graph, so I don't really know. I just know that post processing effects only are applied to the game view

meager pelican
wary jackal
#

Yeah I get that. I'm just confused how each pixel has its own alpha like he says

brittle owl
meager pelican
#

It's an RGBA texture, I would guess. IDK, i didn't digest the whole article because I didn't need to in order to answer your question.

wary jackal
#

Hm, I guess I didn't know that that was a thing

meager pelican
#

Yeah, 4 values for each pixel. If that's what he's doing.
Or he's looking up alpha from some grey scale texture and applying it to .a. Or whatever. It's all vectors and values.

wary jackal
#

So, as far as the ramp generator goes, how would I use that as a texture?

lilac ocean
#

found the button to press lol. thanks for the help anyways

#

"Always Refresh" needs to be on to get it to animate in scene view

meager pelican
wary jackal
#

Ah okay

#

I'm pretty sure you have to have the package installed for that

meager pelican
#

Then you just do a uv lookup into it. With x as the 0-1 value, and say 0.5 as the y value.

acoustic raven
#

Is there anyway to render outside of an object with a shader?

meager pelican
#

No, but you can change the size of the object, and then render bigger, and then squish stuff....so technically no, but in reality maybe. 😉

#

Or you use a post-process and render over top of the screen.

acoustic raven
#

I had thought of moving the vertices, but I am not sure how to render the original shape first

meager pelican
#

What pipeline?

acoustic raven
#

none if possible

meager pelican
#

Built-in, URP or HDRP?

acoustic raven
#

Built in

meager pelican
#

Oh! you're in luck. Look at multi-pass shaders. You draw it normally for the first pass in your case to "render it first" and then draw your 2nd pass over top, but you use z-clipping or stencil to make sure you don't overwrite the first one.

Is this an outline or some such effect? Google for multi-pass outline shader or something.

acoustic raven
#

Wow, thanks this might work, I am relatively new to unity shaders, I don't know much about the ins and outs.

#

I wish I new all the tricks. 😦

meager pelican
#

There's several challenges to outlines. We get a question on average every other day. And there's no one answer either.

acoustic raven
#

I am not making an outline

meager pelican
#

Well, OK, but it's not an inline. (pun)

acoustic raven
#

hehe

desert orbit
#

!unmute 467067465235431444

echo moatBOT
#

dynoSuccess Mateu#2340 was unmuted

desert orbit
#

The bot seems to have had a hiccup and didn't unmute you

wary jackal
#

Thanks

acoustic raven
#

Is there a way to pas information between shader passes?

cinder forge
meager pelican
#

Because they have an aversion to blue?

That or there's an error....

meager pelican
#

If you just need a bit, you can use stencil

wary jackal
#

Okay, I have yet another problem. my fog uses the camera's depth texture to work, but because the water is transparent, the fog basically goes right over it... Would I need to render the water on a different camera and then combine the two images to make this effect not happen?

https://www.youtube.com/watch?v=vTMEdHcKgM4 This video at 16:28 appears to have a similar problem

I got a bit tired of my simple heightmap-based planets and decided to experiment with generating them using the Marching Cubes algorithm instead, so that I could add a 'terraforming' ability for shaping the world with caves and tunnels and so on. I hope you enjoy!

If you'd like to get early access to the project files (they'll be made freely av...

▶ Play video
acoustic raven
#

Can you do what he did to fix it?

cinder forge
#

in my terrain shader, I have Stencil { Ref 1 Comp notequal } and in my road shader I have Stencil { Ref 1 Comp always Pass replace } and with this code the road can be seen through the mountain 🤔

wary jackal
acoustic raven
#

It seems like there is a public function in the camera component to render with a shader

#

not sure though

wary jackal
#

I wish I had access to the code for that video, but it's not available for a while :/

acoustic raven
#

I am definitely no expert

wary jackal
#

Also, not only that but my water is transparent, so it can't even write to a depth texture as far as I'm aware

meager pelican
# wary jackal That's what I was thinking, but he doesn't really explain how he did it very muc...

He did a different camera, and rendered the water to his own "depth texture" first.
You and the RubberDucky kinda both have the same problem, but yours is more-specific....you want to pass depth between passes, basically, and Sebastian did that with a separate pass with a depth-only write in an opaque pass. You don't have to render any colors or think about anything other than outputting the pixel depth. Maybe? he rendered terrain too, but maybe not. Like you say, he doesn't describe what he did.

Then, later, when you render the "real" scene, you can take the min() of the two values, the water-depth-texture, or the current-depth-texture, and do your fog calc.

But all that means you need to do a render pass of your water, probably with a named pass.

Is your fog a post process, or what?

wary jackal
#

fog is a post processing effect, yeah

#

It takes the camera's depth texture and does some fancy stuff to get fog

meager pelican
#

Right, but you need water depth before that. So you could render the water-depth after the water even. Or you could output to multiple render textures, and output a depth in one pass, even if you're in the transparent queue.

#

But IDK if that will work on all mobile or not.

wary jackal
#

idc if it'll work on mobile, I wasn't planning on releasing this to mobile (if I even release anything at all). So could I add another pass on the water shader that renders it opaque, store that depth texture information, combine it with the camera's depth texture, and then use that for my post processing effect?

#

Of course, most of the time my water is opaque anyway, so the easiest solution would be to just get rid of transparency altogether... but that feels kinda cheap nevermind it needs to be transparent for one of my effects to work