#archived-shaders

1 messages Β· Page 222 of 1

devout pier
#

material rendering mode = opaque:

#

the back fin bleeds through when on fade

#

is there a way to disable this?

#

while keeping the material type of fade

patent plinth
#

enable both faces

carmine karma
#

Hey!

slim steppe
#

Why is this happening to a double sided transparent object? @regal stag

amber saffron
#

Transparent objects render their faces "as they come", without depth testing, resulting to this kind of thing

slim steppe
amber saffron
#

First : what render pipeline are you using ?

amber saffron
#

Hum, sadly I don't think URP has any built-in option to help you fix this :/

slim steppe
#

;-;

slim steppe
outer whale
#

That was weird. All of the sudden I started getting notifications for this channel

amber saffron
#

Ideally, you want to draw the back faces first, then the front faces.
You might be able to do this with a render object feature, by isolating these objects in a dedicated layer, and rendering them before transparent + forcing culling to front face

teal breach
#

Please also don't tag specific community members if it's a general question πŸ™‚

#

The draw order for transparency comes up often, is there a good resource we can pin somewhere?

whole salmon
#

Actually, I meant "both" - but I think I resolved it by copying the shader (in the file system) and opening it and editing the name in the text file, then adding that to a new material and using that material for the one-off font that I wanted that shader on.. My issue was that copying the shader without editing the name in the shader file was leading unity to ... do weird things with more than one shader with the same name

#

"name" in the shader file, not the name in the meta file / unity editor

split coyote
#

Keep in mind that the vertex order is editable in a 3D-modeling package, so you actually have quite some control over this, when within the same mesh. If you can afford the overdraw you can have a couple of inside pieces giving the impression of interior depth as well. I probably would have solved this in another way if it's meant to fade out though. Like with a rendertexture or dithering.

#

If you keep the backface culling, and instead add those faces in the mesh, you can easily sort simpler shapes.

tidal cypress
#

does anyone have an example of a simple depth map shader that actually works?

eager folio
leaden radish
#

how can i fix my shader failed to compile?

#

it was working few mins ago now it says failed to compile

iron vine
#

you may have accidentally added something

teal breach
leaden radish
#

well i added one unity store assets after that it said that

#

i deleted that and now it compiles again

#

but the art assets for that package are good looking kind of wanted to use that

toxic flume
#

Is GetTexture slow?
I want to create a new material with new shader in specific situation in the game
I mean replace the old material with the new one. Both use same main texture.
So first, I get it with material.GetTexture and then set it to the new material with new shader, any better solution?

meager pelican
meager pelican
# devout pier the back fin bleeds through when on fade

Well, as has been explained above (I think), transparents don't set the depth texture, and additionally, they draw over top of things that are behind them (further from the camera/deeper).

So that's what you're getting. Are the yellow fins opaque like a 2nd material? Or is it "just" stacking transparents on top of each other?

Like Remy and Frell mentioned, there are "tricks" depending on what you want to happen.

The dither is a really easy solution, though, if it is acceptable. Since it is an opaque process and won't suffer from the same problems as transparent stuff (at least not in screen space).

See here: https://dev.rbcafe.com/unity/unity-5.3.3/en/Manual/SL-CullAndDepth.html

Where the transparent shader does depth writes, and only depth writes, first.

The solution in that link is to render "nothing" to the color buffer but update the depth buffer using "ColorMask 0" and "ZWrite on" in the shader. This sets depth clipping for those "behind" pixels.

Then you make another pass and draw it "for real" and only the front sides get drawn, which should omit your yellow fin and any deeper pixels than the front sufrace, as they will get clipped as being occluded.

That link is assuming built-in pipeline. URP/HDRP will probably require a hand-written shader, but I'm unsure of that. Maybe you can set the colormask and zwrite in Shader Graph....IDK. And you need either multiple passes or some of that new fangled render features stuff piled on top with extra frosting.

signal flume
#

Could someone help me with how I could convert this shader graph into shader lab code

smoky pewter
#

anyone have any ideas as to where i can find a quick water shader for SRP?

#

currently all the ones im seeing only work with urp or hdrp

tidal cypress
noble bobcat
#

any clue on why this might be happening?

#

i wanted the texture to scroll

#

but instead it is distoring

#

even tiling is doing it

dim yoke
#

It should be set to repeat (from import settings of texture)

kind juniper
neat hamlet
#

people use SRP when they mean BIRP for some reason

tidal cypress
#

how do I copy default asset to edit (I want to edit the sun texture)

steel notch
#

Is there a way to take some perlin noise, define a gradient, and then color a model based on mapping that gradient to the perlin noise?

#

so the perlin is sorta like a height map?

stone minnow
#

Any theories on how this nebula effect was produced? I am not really seeing ray marching artifacts and I am wondering if its a true volumetric effect or just some clever solution?

#

EVERSPACEβ„’ 2 is a fast-paced single-player spaceship shooter with deep exploration in space and on planets, tons of loot, RPG elements, mining, and crafting. Experience a thoughtful story, set in a vivid, handcrafted open world full of secrets, puzzles, and perils.

This live stream is part of our weekly communication with our community to showc...

β–Ά Play video
steel notch
#

and height defines color

steel notch
#

So I have a very basic shader here. Literally just makes some noise, colors it and then applies the texture. When I apply it to the default models (such as the sphere) all is working. However when I apply it to my own models, for some reason they're always black.

#

In fact, it seems that I can't make these models anything but 1 solid color.

#

So I assume something is off with them.

#

Any tips?

#

Going to assume something something fucked UV mapping

teal breach
neat hamlet
#

the color you're multiplying with isn't the basecolor

steel notch
#

huh?

neat hamlet
#

oh wait I misread

steel notch
#

np

neat hamlet
#

you can quickly generate lightmap uvs for your model in import settings, and then use UV1 to see if it shows up then

#

if it does, its your original uvs

steel notch
#

kk 1 sec then

#

ya definitely the original UVs then

#

not going to lie, a bit unfamiliar with the concept

#

can I get a tl;dr on whats with the solid color?

#

I assume it's only sampling from the single pixel on the bottom left

#

instead of wrapping the whole texture around itself?

neat hamlet
#

well it looks like youve got no uv map at all, so theres no data to sample on

steel notch
#

Ye, suboptimal.

signal flume
#

Could anyone help me with how this node translates into shader lab?

#

specifically just world space view dir

regal stag
# signal flume Could anyone help me with how this node translates into shader lab?

It's the vertex position subtracted from the camera position, both in world space (_WorldSpaceCameraPos - positionWS), assuming a perspective projection (orthographic uses the forward axis of the view matrix instead). Can see the function in the URP ShaderLibrary source : https://github.com/Unity-Technologies/Graphics/blob/d0828e062dbffe99c6c07062e841ed4eff68fb37/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl#L95

signal flume
#

Thank you

lavish ibex
noble bobcat
languid zodiac
#

Hi. How to measure the performance of the shaders? And I need something more accurate than just measure the fps πŸ˜‰

fervent tinsel
#

@languid zodiac if you need something built-in, could start with unity profiler's gpu module

#

oh wait, you mean like regular shaders... yeah that's harder

languid zodiac
signal flume
#

Does anyone know if shadows rendering over a shader is a generic issue, and how to fix it?

torpid sapphire
#

Does alpha clipping shaders breaks batching ? For example, having multiple trees overlapping with alpha cutout, seems to increases my batches count a lot even if they all have the same material and are statics

dim yoke
tidal cypress
#

why is my depth texture only applying 1 color to everything at once

#

also how to I remove an object from the depth calculation

tidal cypress
#

oh... its only sampling the depth of the pixel in the bottom left of my screen

white smelt
#

How do I sample render texture in a compute shader

regal stag
#

You can override the preview type on the node via the Node Settings tab of the Graph Inspector, if you're in Unity 2021.1 / SG v11+ that is (at least I think that's when the option was added)

#

Oh it might be a 2021.2 beta thing actually

thin creek
#

Will the Shader Graph 12+ version work properly on Unity 2020.x ?
Just need a ZDepth property

#

Anyone tested?

tacit parcel
#

Why does my shader behave differently on mobile when using LoD? It works fine with LoD on editor

void surf (Input IN, inout SurfaceOutput o) {
    float2 uv = IN.worldPos.xz * 0.025;
    float3 n = IN.normals;
    float4 sea  = tex2D(_SeaTex,  uv + float2(_SinTime[1], _CosTime[1]));
    float4 sand = tex2D(_SandTex, uv);
    float noise = sin((IN.worldPos.x + IN.worldPos.z) * 0.0888) * 0.5;
    float sandStart = IN.worldPos.y + noise - 2.5;
    float sandEnd = sandStart + 0.5f;
    float4 g = lerp(sea, sand, clamp(sandStart + sandEnd,0,1));
    
    sea = tex2D(_MainTex, uv);
    sandStart = IN.worldPos.y + noise - _SandLevel - 1;
    sandEnd = sandStart - 2.5f;
    g = lerp(g, sea, clamp(sandStart + sandEnd,0, 1));
    
    float4 r = tex2D(_RockTex, uv);
    o.Albedo = lerp(r.rgb, g.rgb, saturate(pow(n.b * (1 + _GrassAngle), 16)));
    o.Alpha = 1;
}```
[Shortened to save space]
#

Here's on mobile, notice that the texture always become rock texture on LoD mesh

grand jolt
#

Why do the splatmaps Unity terrain generates have this effect?

#

If I paint close to the edge, it creates a line of pixels on the very edge.

grand jolt
#

Huh, it stopped appearing once I applied the same custom renderer to all terrains.

dim yoke
sly breach
#

is there a way to scale a number range at a certain position between 0 and 1 ? right now im sampling two gradients ( the first one 0.5 value is shifted to 80% and the second one is to 20% )

#

but i suspect its isn't very performant compared to a math function

stark vessel
#

anyone know how to make a transparent mat in HDRP that you can see particles and other transparent objects threw? having glass act as a cloaking field for particles is not ideal and I figured this would not be a problem in HDRP but I guess it is

amber saffron
stark vessel
#

yes

amber saffron
stark vessel
#

for basic windows I can live without it if I must but part of the reason we switched back to HDRP is I was told you could get refraction or similar distortion effects on trasparent objects. I have seen videos of it. just cant find anything explaining how its done

amber saffron
# stark vessel yes

Ok, well then, no.
But, you can think it the other way around : if your particles and transparent objects shaders are set to the "before refraction" mode, they will be visible in the object with refraction

stark vessel
#

that would require me to use the actual refraction effect in HDRP, not scene or HD scene color?

amber saffron
#

iirc, it will act the same, the HD scene color samples the same buffer as refraction materials

stark vessel
#

ok, will give it a try. thanks

#

trying to create a blackhole shader effect similar to this. https://www.youtube.com/watch?v=8e6vftYaAIc

Liking this video is the EASIEST way you can support Shader Graph Mastery, it helps a lot with the Youtube Algorithm.
This Black Hole is made with Unity VFX Graph for the galaxy ring around it and Shader Graph for the warping effect.

I've been using Unity's High Definition Render Pipeline these past few months & have many more graphic projects ...

β–Ά Play video
cyan maple
#

hey everyone I just finished a tutorial after downloading the universal shader pipeline and made a triplaner shader, and Im at the end but my final output node dosent have anything to connect to and I get the error no output selected, I assume I should have a starting node thats a texture output so Im geussing I messed up and the graph is made in the wrong location, am i missing something super obvious here?

#

did I mess up by doing everything in trigraph instead of the material?

amber saffron
cyan maple
#

so the node that says fragment is my end point? the tutorial was using the other pipeline.

amber saffron
#

the node that says fragment is my end point
I don't get it

cyan maple
#

thank you for the help

amber saffron
#

Really ?
A vector4 is automatically cast to a vector3 and the .a value is thrown away

stark vessel
#

I cant figure out how to set a vfx graph particle to be "before refraction" no option that I can see for the particle, I tried setting it to a shader graph mat that was set that way and it didnt work... this is what I am stuck with

amber saffron
#

iirc, it's in the inspector, when the output block of the graph is selected

stark vessel
#

ah, thanks... now I am getting somewhere

stark vessel
#

progress, still fighting me in some odd ways.

cyan maple
cyan maple
#

since my first picture was really undreadably small, Im sure its something stupid Im missing.

pale nest
#

Hihi, I'm wondering if it's possible to make a shader in shadergraph that would take an objects geometry and make a cutout to display a flat texture like so:

#

I don't quite know what kind of effect is called so I'm not sure where to start researching- if someone could point me in the right direction or an idea to achieve it I'd greatly appreciate it!

kind juniper
#

Are you actually using universal render pipeline properly?

tidal cypress
#

why is this only setting the screenPosition variable to the lower left corner?

dim yoke
rigid terrace
lime kite
#

how to lern shader language in unity?

kind juniper
lime kite
meager pelican
# tidal cypress why is this only setting the screenPosition variable to the lower left corner?

You screwed with the o.vertex by adding in the results of the wave function. Which may or may not be OK to do. (I realize you're doing vertex displacement, but IDK what the function resulted in).
Just as a test, try commenting out the wave() function call line.

ComputeScreenPos takes the clip-space result, just as you're doing it so it should work if all the math is OK.

Also, I have no idea if your frag() is messing up the result, but that's a different question, I suppose. You're assuming that it is wrong output in the vert() per your question.

tidal cypress
meager pelican
#

OK, you have multiple inputs to the frag()
But your v2g o should be set from the vert().

You have too many things going on at once to test.

How do you know that o.screenPosition (after commenting out the wave() function) is wrong?
What do you mean by "no luck"?

tidal cypress
meager pelican
#

Is the water still on the screen?

#

Just flat?

tidal cypress
#

yes. for context its only sampling the bottom left corner of the depth texture when changing to water color for some reason

meager pelican
#

IDK...I haven't read that article you're following.
IDK about that math at the end of the frag() either.
Black is black.

#

So...

#

Let's output some info for testing.

#

Change the frag(). Output the values of the screenPos result

#

But you'll have to scale it

#

So...

tidal cypress
#

black (0,0)

meager pelican
#

return fixed4(o.screenPosition.x/width, o.screenPosition.y/height, 0, 1);
or something...where width and height are your screen width and height

#

Comment out the other stuff in frag()

tidal cypress
#

thats display from above

#

normalizing it probably doesn't matter much

meager pelican
#

OK, fair enough. I was still working toward that when you added this info. πŸ˜‰

#

And you commented out the += wave() line in the vert()?
IDK, it looks like it should work.

One thing though...it depends on the math and the technique...but it's common to add vert offsets in object space too/instead.

#

You could try just adding a 1.0 to the Y value manually, hard coded, and see if it moves up.

#

But that's a bit beside the point. I'm just trying to isolate variables.

#

Anyway, those calls SHOULD work, from what I can see. Maybe someone else will spot the problem.

pale nest
meager pelican
tidal cypress
#

wait... why the heck is screenPosition a vec4...

meager pelican
#

I was just reading that. And it might be returning UV coordinates for a texture sample! So they'd be from 0 to 1. Still, I'd have thought you'd have more than just black.

But you're also returning 0 alpha, and IDK what queue you're in.

#

Or that alpha is a larger number due to perspective divide.

#

So you're getting really small results. IDK, so isolate the xy part.

#

Might still be black, which is throwing me.

tidal cypress
#

it's green

#

note the corner is also the same green so no beans

meager pelican
#

Frack. The comment here above the function is confusing:
https://docs.unity3d.com/Manual/SL-BuiltinFunctions.html
The following functions are helpers to compute coordinates used for sampling screen-space textures. They return float4 where the final coordinate to sample texture with can be computed via perspective division (for example xy/w).
So it sounds like CSP is returning the actual integer values, and the w is a perspective divide number. Oy. But we don't want to sample a texture with this anyway that I know of, so we don't need to normalize it.

tidal cypress
#

why is it a float 4

meager pelican
kind juniper
#

Did you try xy/w?

meager pelican
# tidal cypress why is it a float 4

I think (they should document this better on that page)...
The x and y are the x and y screen locations, the z is the depth and the w is the magic "perspective divide" depth number that makes a 3D frustum work. The further away it is, the more it gets moved toward (0,0) in clip space.

But I'm unsure from that document what the xy values really are.

Docs say Computes texture coordinate for doing a screenspace-mapped texture sample. Input is clip space position.

#

So yeah, what dlich just said. But still, I think you're after the actual pixel int value. Like pixel 396 of 1024.

#

but IDK if that's what you want

#

tex coords are 0 to 1

kind juniper
#

I think the screen space position needs to be calculated in the fragment shader as opposed to be passed in from vertex

#

It probably gets interpolated in a weird way and you get weird results too

meager pelican
#

That makes total sense, dlich. I didn't even think of it. Doh!
Because rasterization...

#

The vertex stage has no idea about pixels yet.

kind juniper
meager pelican
#

That makes more sense. Reds and greens

tidal cypress
kind juniper
#

share it with backticks

meager pelican
#

Sorry @tidal cypress, I missed that. I just followed the yellow brick road.... Good catch dlich.

tidal cypress
#

great, but the coords repeat every tile

#

also theres a weird white line down the middle

kind juniper
#

Share the updated code properly

tidal cypress
#

oh that

#
           fixed4 frag (v2g o, g2f i) : SV_Target //from https://roystan.net/articles/toon-water.html
            {   
                /*float existingDepth01 = tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(o.screenPosition)).r;
                float existingDepthLinear = LinearEyeDepth(existingDepth01);
                float depthDifference = existingDepthLinear - o.screenPosition.w;
                float waterDepthDifference01 = saturate(depthDifference / _DepthMaxDistance);
                float4 waterColor = lerp(_DepthGradientShallow, _DepthGradientDeep, waterDepthDifference01);*/

                float4 screenPosition = ComputeScreenPos(o.vertex);

                half depth = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(screenPosition));
                depth = LinearEyeDepth(depth);

                return float4(depth/10 + (i.col.rgb/4 - 0.1), 1);
                //return float4(screenPosition.xy/screenPosition.w,0,1);
            }
kind juniper
#

You didn't apply the other fix from earlier.

#
The following functions are helpers to compute coordinates used for sampling screen-space textures. They return float4 where the final coordinate to sample texture with can be computed via perspective division (for example xy/w).
tidal cypress
#

proj coord takes a vec4

#

so im assuming it deals with all that stuff

kind juniper
#

Why do you need UNITY_PROJ_COORD though? Is it from a tutorial?

tidal cypress
#

yes

kind juniper
#

Hmmm... then I'm our of clues. Is the math correct(the same as in the tutorial)?

tidal cypress
#

Im pretty sure it is

kind juniper
#

Can you link the tutorial?

tidal cypress
kind juniper
#

Interesting. They seem to be computing screen position in vertex shader and it works for them...

tidal cypress
#

theres a lot that works for them

meager pelican
#

OK, and we're back to computeScreenPosition being in the vert().

#

lol

kind juniper
#

Why don't you just use their shader btw?

#

it seems to be open source

meager pelican
#

Which could work...

#

(vert)

tidal cypress
#

because theirs requires me to build it all the way up and it doesn't have all the features I want

kind juniper
#

build all the way up? Wdym?

tidal cypress
#

paste in his code

#

its annoying

#

because I have no way of knowing if he set up one step wrong

kind juniper
#

Here's how they get the depth value:

// Retrieve the current depth value of the surface behind the
// pixel we are currently rendering.
float existingDepth01 = tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.screenPosition)).r;
// Convert the depth from non-linear 0...1 range to linear
// depth, in Unity units.
float existingDepthLinear = LinearEyeDepth(existingDepth01);

// Difference, in Unity units, between the water's surface and the object behind it.
float depthDifference = existingDepthLinear - i.screenPosition.w;
#

Quite different from what you have.

kind juniper
tidal cypress
#

yes

#

its happened to me with almost every tutorial like this. the guy who makes it changes something down the line and forgets to update the steps above

kind juniper
#

If the tutorial has source code, you can be 99.9999% sure that it works. Heck, if you don't trust it, just test it.

tidal cypress
#

you underestimate how lazy I am

kind juniper
#

Well, that's a different problem. And we don't like helping lazy people here.πŸ˜…

tidal cypress
#

fair enough

#

I'll deal with this in the morning

#

anyways the depth texture is working, but all the planes are sampling from the same location

meager pelican
#

lol
We've spent more time screwing with this, all three of us, than it would take to start with a working tut.

But we've confirmed something....
ComputeScreenPos WAS NOT 0.
And we found that it CAN work in the vert() per the tut. (I guess Unity always knows what it needs for that calc, vert or frag)

And the rest is you (@tidal cypress) debugging your math/calcs.

tidal cypress
#

for some reason it's like the o.vertex variable is relative to the plane's location, not the world's

kind juniper
meager pelican
#

o.vertex is going to be clip space in the vert() shader. Vert() shaders output clip space.

tidal cypress
#

I have no clue what clip space means

#
            v2g vert (appdata_base v)
            {
                v2g o;
                o.worldPos = mul(unity_ObjectToWorld, v.vertex);
                o.vertex = UnityObjectToClipPos(v.vertex);
                //o.vertex.y += wave(v.texcoord);
                o.uv = v.texcoord;

                o.screenPosition = ComputeScreenPos(o.vertex);
 
                return o;
            }
meager pelican
#

-1 to 1 in x and y, (0,0) is the screen center.
Z and W get more complex to explain.
Z is a depth of some type.
W is the "perspective divide" where you divide XY by W and get it "squished" from a pyramid type frustum into 2D "flat" screen space-ish type of thing (NDC may not be the exact term in this case either).
It gets a tad complicated terminology wise.

kind juniper
meager pelican
#

Yeah, as long as the function call works in vert() ...and I should I guess...then it should get interpolated OK against the flat 2D results.

So yeah, frag.

#

Whatever the hell is in XY, it should be lerped properly for the polygon being shaded.

#

And Z is a depth. (Which was also decoded in the vert, so that result should interpolate).
W is the perspective divide value.

meager pelican
eager folio
#

Rotating a cube via shader is actually pretty difficult. πŸ˜„

grand jolt
#

What happens when terrain renderer gets a regular material not written for terrain?

#

Does it keep invoking the ForwardLit pass for each 4 layers?

meager pelican
#

You mean Unity's version of a procedural sky shader? (That specific one).

OK, fair enough.

IDK of a specific link though.
No apology necessary, but the clarification was helpful. πŸ™‚

low lichen
#

If the shader doesn't read the splatmap, it can't know where the layers are supposed to be.

grand jolt
#

I know how splatmapping works.

#

I'm feeling too lazy to implement quad tree rendering for my terrain.

#

I have 1 shader graph into which I pass the splats in a texture array.

#

And I wonder if it will fuck my shit up and render the material 4 times for 32 layers in total if I use the material on the renderer itself.

low lichen
#

You're wondering if Unity is detecting if a shader is a proper terrain shader, and if it's not, it will draw the terrain 4 times?

grand jolt
#

No.

#

Darn it.

#

How it does rendering is it draws a patch in a new draw call for each 4 layers for each 4 layers after the first ones.

#

Cause a splat is 4 channels.

low lichen
#

You mean when you have more than 4 layers?

grand jolt
#

Yes.

#

That's what I said.

low lichen
#

To be fair, you didn't mention 32 layers at first, so I assumed by 4 layers you meant the 4 channels of a single splatmap

#

I don't know the answer, but my guess would be yes, it would treat it like a regular terrain shader.

grand jolt
#

It's just there is literally no way for me to test if the shader is being invoked by the base or additive pass.

#

I see some people on Unity forums just don't give a fuck and use a graph but like I wanna find out if it will turn my single pass mega terrain shader into quadruple drawcalls for no reason.

#

Stupid how the terrain lives fully on the C++ side.

#

With the terrain turned off, I have 5 draw calls.

#

With a simple PBR graph - 17 calls.

#

With a Terrain Lit shader - 27 calls.

#

πŸ€”

#

And the number of verts changes depending on the material.

#

Very weird.

#

Oddly enough, the number of layers doesn't impact the drawcall count.

#

Wtf.

meager pelican
#

IDK either. But those are pretty small #'s, Beat. Not that I object to you asking at all, but you may not notice much difference.

Incidentally, draw calls aren't always the prime factor.
I mean, it's more about CONTEXT switches, that show up between draw calls. Not every set of draw calls is a context switch. Sometimes, like for various batching, it's the same context but done in "groups" due to buffer size limits or whatever. IIUC.
https://gpuopen.com/learn/understanding-gpu-context-rolls/

And for fun, check these stats:
https://pcper.com/2015/08/what-exactly-is-a-draw-call-and-what-can-it-do/
They're talking about some games in 2015 with 50,000 draw calls. That's pushing it....back then.

And note that various APIs can handle draw calls better, like DX12, depending on your needs.

Like many things, running some test cases in various ways if you can...and timing them with benchmarks....helps you decide. It's hard to test all device types though.

Sometimes you're more limited by the # of vector registers you have available that stops some thread groups running, limiting your throughput.

The only way I've found to analyze all this crap is to use the GPU manufacture's GPU analysis/debugging tools.

2 cents.

GPUOpen

Learn what a context roll on our GPUs is, how they apply to the pipeline and how they're managed, and what you can do to analyse them and find out if they're a limiting factor in the performance of your game or application.

What Exactly Is a Draw Call (and What Can It Do)? Mantle, Vulkan, and DirectX 12 all claim to reduce overhead and provide a staggering increase in β€œdraw

#

P.S. I assume a material change will result in a context change. At least that's a safe assumption.

grand jolt
#

@meager pelican well, it's just I wouldn't want it to call my single pass shader multiple times.

#

I have my own constant grid terrain renderer but that breaks as soon as you make a small hill cause not enough detail for the slopes.

#

It'll make a difference for me if it's a hacky thing that I shouldn't use in prod or something I will do in next projects.

#

Btw I tried to make reconstructing normals from height work using code from Battlefield Bad Company 2 but it produces shaky results...

#

I checked the theory and everything seems correct

#

But it just doesn't produce normals as smooth.

#

Here it's obvious they sample it in frag cause Sample is only available in frag.

kindred forum
#

can anyone help me get started w/ creating a custom Shader Graph node that emits Unscaled Time?

#

worst case I will use Shader.SetGlobalFloat but I'd prefer doing it w/ a custom node if possible

tidal cypress
#

anyways this really isn't what I need because it changes with perspective, which doesn't make sense for sea foam

#

so I need a way to get every frags distance from the nearest intersection or geometry beneath it

low kettle
#

so i was messing with procedural generation with shader graph and i cant figure out how to calculate the normals from that. if anyone could point me in the right direction id rlly appreciate it

tidal cypress
low kettle
#

idrk what that means sorry but just the normal calculations that mesh.RecalculateNormals would do

tidal cypress
low kettle
#

yeah

tidal cypress
#

because they should really be in a normal cs script

low kettle
#

yeah ik but i want as many frames as possible

tidal cypress
#

you just edit the mesh once, then never need to generate that ever again

low kettle
#

true

tidal cypress
#

it's loading chunks, you only need to generate them once

woeful geyser
#

Is it possible to get mesh data after applying bone transformations on him?

low kettle
#

sorry i just

#

yeah ty

meager pelican
meager pelican
cyan maple
meager pelican
#

Surface normal from 3 points is calculated by making 2 vectors on the triangle from the 3 points, and taking a cross product, if the points are ordered counter-clockwise it is:
Given float3 a, b, c
float3 normal = normalize(cross(b - a, c - a));
@low kettle@grand jolt

low kettle
#

thank you!

meager pelican
meager pelican
# tidal cypress so I need a way to get every frags distance from the nearest intersection or geo...

Uh, holy frack.
Doing a depth-based (or ray from camera/eye) can be done. But otherwise, you're basically doing some kind of ray tracing, or screen-space to world-space, across the screen unless your scene is procedural-math based (like SDF's). Or some other really expensive maybe not real time kind of thing.

I mean...one mesh doesn't know about any others in a shader unless you pass them all. All it has is the depth buffer, g-buffer, etc.

tidal cypress
#

uhh can I just send a ray down from the frag for a few units then see if I hit anything?

meager pelican
#

OK, that's ray tracing/marching.

#

But you have to have your scene in GPU memory to pull it off.

OR

You'd have to do what I mentioned....use the depth buffer to calc the world-space position of any other background pixels (which would exclude much/most of the current mesh) and then do a nearness check relative to some saved value. Basically casting around on the screen near the object.

tidal cypress
#

it seems like my ground planes aren't being included in the depth calculation

meager pelican
#

Wait.

#

Are you just needing the distance to the ground plane?

#

You can pass in the ground plane's Y coord.

#

Calc distance from that.

#

Is this the water thing?

#

That's the depth buffer calc from the background data, along a ray from the camera, maybe refracted a bit.

#

That's what those formulas did in the tut.

#

But that's WAY different than "any and all nearest geometry"....it's just one ray.

tidal cypress
#

it should be good enough

meager pelican
#

Yeah, you can do that. The tut was doing that.

tidal cypress
#

which tut?

meager pelican
tidal cypress
#

so how do I send in the vertices of an abject into the shader?

meager pelican
#

OK, then it's not a plane you want, but the scene depth Y value distance between the water and the bottom (in other words, bottom is irregular, not a plane).

OK, tracking now.

So, you also don't want eye depth, you want world-y depth. That's harder, and not accurate to the eye, but it can be done.

So you're talking about casting rays "down" along the Y....

But another way it can be done is to have a 2nd camera (this is not uncommon) to calc Y depth from above. So you position a camera pointing straight down the Y axis, and take an "image" of the scene using that, and store the depth into a single-channel render texture.

Then, "all" you need to know is the x, z value of the world-space spot the ray hit the water, and that's your x, y value to lookup into the height map texture that you generated from that other camera.

#

Sort of, in theory. I mean there's info on the net for it.

#

Computing the right position to look up is likely more complicated than that.

tidal cypress
meager pelican
#

What is this terrain?
Is it a unity terrain? Or a mesh? Or what?

tidal cypress
#

a default plane

meager pelican
#

How are you making hills and valleys?

tidal cypress
#

cs script

meager pelican
#

Height map? You already have a height map?
Use that.

tidal cypress
#

no

#

it's the perlin cs function

#

and theres also a bunch of stuff done to the heightmap

#

unless you mean to generate a texture from that, but I don't know how I would pass that to the water

meager pelican
#

The texture is a shader property. Google it.

tidal cypress
#

yeah ok that should work

meager pelican
#

Then you don't need to screw around with 2nd camera and ray tracing...you already had the data in C#. πŸ™‚

tidal cypress
#

how to I fix the problem with unity's awful texture scaling

meager pelican
#

Too vague to answer....

tidal cypress
#

for example, the reason I have this awful blending is because the texture is blurred by scaling, then I sample a color from the triangle center

grand jolt
#

@meager pelican but a 4 tap cross should give better results than 3 taps πŸ₯²

tidal cypress
hallow shadow
#

Does anybody know how I can fix this?

tidal cypress
#

define shadowcoord correctly

hallow shadow
#

float4 shadowCoord = TransformWorldToShadowCoord(WorldPos); this is how it's defined - can you help me in finding what's wrong about it? I'm sorry, I'm a beginner at this

tidal cypress
#

if it is, when it's called it should just be shadowCoord, not x.shadowCoord

hallow shadow
tidal cypress
grand jolt
#

Which shaders do you guys think would be better to emulate this art style on a 3d enviroment?

I thought about using default shaders but could also use toon shaders. The lighting details are more visible with default shaders tho.

tidal cypress
#

turn up the bloom

sharp ginkgo
#

can someone please give me an idea of how to fix this? It's a .vrm model I'm trying to export. Whenever I activate an expression, these red spots appear all over the face as I rotate the screen. All I did since this started was add some blendshapes, but I suppose a lot could happen between blender and exporting from Unity.

#

When the face is in the original, neutral sate, it is normal.

patent plinth
#

looks like overlapping geometry

sharp ginkgo
#

that's what i think it looks like too, but I don't see anything that would be overlapping. It's just a single face mesh there

patent plinth
#

you can delete the overlapping texture with image editor.. I'm using vrm as well for my current game

sharp ginkgo
#

I will take a look at that, I'm still kinda new so I might be missing something

#

thanks for your input!

patent plinth
sharp ginkgo
#

Ohh I'm not using vroid anymore; I have working versions of this model already, but basically what I did was opened up the working fbx in blender, added a bunch of blendshapes to the head and then replaced the head on the model with the updated one. Did the whole process of transferring from FBX -> Prefab -> VRM, and now whenever I activate any expressions at all on this updated model, the head does this

patent plinth
#

as long as you're using the same UVs it will still be the same

#

or just deflate the neck part a little bit in blender

#

either way, this is not shader related question

patent plinth
sharp ginkgo
#

Hmm okay I will try this, thank you! I first thought it might have been the VRM mtoon shaders breaking it

sharp ginkgo
#

update: I actually fixed this issue by making both of these boxes white under the shader

#

not sure why this suddenly needed to be done since it was working in past iterations, but poi_shrug I suspect this is a temporary fix and something is causing the shading to mess up

grand jolt
#

does anyone have a good tutorial i can watch on shaders? I'm a bit confused. I got a free asset on unity for Lava flowing shader. I've got it to work using the prefabs they've given. However I would like to try to get it to work by using the shaders and mixing them together to get desired effect?

heavy ether
#

hey, does anyone know if its possible to modify light/shadow direction in URP Shader Graph? im trying to change the shadow direction for specific objects, so that its different from the default directional light value

meager pelican
#

You might be able to pull some tricks....like use a 2nd camera, and between camera renders, screw with the lighting info on the C# side to change directions, but for things like point lights, that probably won't work.

meager pelican
meager pelican
# grand jolt Which shaders do you guys think would be better to emulate this art style on a 3...

Nice.
You might be able to pull it off with the "default shaders"...a lot of it is asset creation and settings.

But, since you didn't indicate what pipeline you want to work in, I'm not sure how to answer.

If you want to have control over the whole art style, you end up writing all custom shaders AND custom lighting. In the built-in pipeline there's surface shaders and custom lighting functions that can be auto-inserted into the results (you still have to write them, but there's syntactic hooks for it).

For URP or HDRP, I'm unsure, but can almost guarantee you'll have to hand write shaders.

And since you asked this question this way, I'm going to assume that you're not familiar with hand-writing your entire shader system. So unless you find an asset to emulate all this, IDK what to tell you.

This is why many AAA studios, if they use a third party engine at all, end up writing a ton of custom shaders AND have a 10x ton of artists in the mix. There's usually more artists/modelers than programmers, IIUC, and most all the shaders are custom.

So they have complete control over everything, and don't do any "extra stuff".

But that's not to say that if you're willing to compromise that you can't get a great look with standard shaders. You can.

#

If you want to use standard shaders, you might try the art-asset-workflow and the lighting sections of this discord.

meager pelican
left stump
#

Ey people i'm working on a real time GI Shader, but i have a small problem, i'm checking for a pixel on texture and not 50 pixels for example any idea how to grab 50 pixels and do a and set it has 1 pixel
any idea how to do this
i'm using Amplif

olive brook
#

hey guys. I'm writing a very simple blur effect. .trying to do it all in one PASS. what do u think? I managed to make a blur over x axis. now how could I make it blur circular ?

#

Im doing a simple box blur

#

calculating y just like x, in the same PASS , will result in this... which is bad...

grand jolt
#

is there a way to make bullet holes using shaders?
if so would it be the easiest way to make dynamic bullet holes?

patent plinth
#

What you want is decal

grand jolt
#

yeah found it

#

thanks

#

oh and also

#

do you have an indetail shader tutorial?

#

it would help a lot

meager pelican
# grand jolt is there a way to make bullet holes using shaders? if so would it be the easiest...

That's the 2nd or 3rd time so far today someone wants a magic link to a shader tutorial that explains everything....and really...they don't exist. (No offense meant).

BUT

There are some links in the pinned messages above in the toolbar:
Such as https://thebookofshaders.com/
and https://developer.download.nvidia.com/CgTutorial/cg_tutorial_chapter01.html
(both are getting dated, the cg one is fairly old but worth reading)

And there's several low cost online classes about GPUs and programming them, I've personally taken one from Udemy, and there are others. And of course many books available...e-book or paper.

And you can cobble it all together from various tutorials and videos on the net. Just google "what is a GPU" or "Introduction to GPU programming."

You won't find any single-simple answer here or "best one" because, frankly, we all have our own opinions and different ways of working/growing.

grand jolt
#

thank you!

meager pelican
#

Graphics researchers waiting in the water fountain line at SIGGRAPH Yellowstone.
Computer graphics as a field is broad, deep, complex, and intimidating. More than half a century of rapid progress driven by academic research and industry practices underly it. Parts delve pretty far into physics, math, signal processing, systems programming (and...

ebon jetty
#

this might be painfully obvious, but how do I get rid of these "shader unsupported" messages in my server build? using URP

olive brook
#

guassian

tawdry depot
#

im a bit new to shaders and whenever i plug in my sprite texture it stretches like this

#

any help is appreciated :)

hollow talon
grand jolt
#

What would I do if I wanted to make a ps1 style resolution for my game?

#

For aesthetic purposes, of course.

slow rain
#

Hey guys, I'm working in Shader lab and need to only use a small portion of my mask map(The blue portion in this case). The tutorial video suggest I do this

// Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            fixed4 mask = tex2D(_MaskTex, IN.uv_MaskTex).r
            c.rgb = c.rgb * (1 - mask) + _Skirt * mask;

The second line, getting the mask value would be fine if it wasn't red. I need to get a mask value that has a mix of rgb. Any assistance would be appreciated!

hollow talon
#

how exactly you want to get a mix of rgb? The grayscale value of the mask texture? @slow rain

slow rain
hollow talon
# slow rain https://gyazo.com/cb04b49e9e346301e5eb2b02c910ffbc I just want use the violet (p...

Normally, a mask should be single value in one of the channels (r, g, b or a), so you sample the texture, then use any channel you like. For this texture, you could draw the violet part in red channel, and the blue part in blue channel and then easily use it as mask

But if you really need to use this one, what I can suggest is to filter the colors that match the pink.
It is r = 1, g = 0, b = 0.91.
first sample the mask texture
fixed4 mask = tex2D(_MaskTex, IN.uv_MaskTex);
Then, you can use step() to get pixels that are r = 1, and combine it with b > 0.91
float m = saturate(step(1, mask.r) + step(0.9, mask.b));
use saturate to clamp the values between 0-1
now you can multiply the color with 'm' to mask out. But strongly advise to try using separate channels, this is not a good way to handle this I believe.

sharp ginkgo
lunar flicker
#

So i created a URP unlit sprite shader graph and this happened

#

anyone got any idea why

slow rain
hollow talon
hollow talon
slow rain
#

@hollow talon I have another question as well. They actually did fixed4 mask = tex2D(_MaskTex, IN.uv_MaskTex) instead of MainTex for the second parameter, do you have any clue why?

lunar flicker
#

fixed it

hollow talon
slow rain
#

@hollow talon on the second step, should it be b or mask.b?

hollow talon
#

Yeah, should be mask.b, oops πŸ˜…

slow rain
#

No worries, I do the same. lol

#

hey @hollow talon , how did you decide on those values for the pink?

hollow talon
#

I colorpicked it on GIMP

slow rain
#

Could I possible hop in a call with you and pick your brain?

hollow talon
#

Can I see the shader?

slow rain
#

Script or inspector?

#

@hollow talon Sent.

slow blade
#

Hello, I'm trying to make stars in a sky box shader but I get this weird smear around where z=0. I didn't find anybody with the same bug and don't see what I'm doing differently than example and tutorials I found online

#

This is my shader graph

kind juniper
slow blade
#

Consider donating to help me keep this channel and website alive using :

https://paypal.me/supportTheGameGuy πŸ’–
or
Support me on patreon : www.patreon.com/the_game_guy πŸ’–

I have been learning about shader graph and its kind of amazing and we can do whole lot of stuff using shader graph and I started with a simple gradient shader for my skybox ...

β–Ά Play video
#

I only changed the noise function

#

It's my first time using shader graph in Unity but I have a bit of experience with those of unreal engine

kind juniper
slow blade
#

Yes, the noise moved but the smear stayed in the same place

kind juniper
#

What if you change the noise scale? Does it affect the smear?

slow blade
#

No

kind juniper
#

Does it happen with the voronoi noise too?

slow blade
#

What change is if I modify the world position before the tiling and offset nde

slow blade
kind juniper
#

Hmmm

#

Interesting

slow blade
#

I feel like if the world position received by the shader is wrong for some reason

kind juniper
#

I wonder what values are passed for world position, since it renders as the background...πŸ€”

slow blade
#

All exemples I found online used the world position this way

kind juniper
#

hmm

#

it could be sampled with the camera far render planeπŸ€”

slow blade
#

I don't know if it change anything but the project was not in urp at first

slow blade
kind juniper
#

No. If I get it right, the far plane is just used to get the z position of the world position

slow blade
#

I'm not sure how it would work but I'll look into that tomorrow

kind juniper
stark vessel
#

I have ran into that problem as well. could not find a way around it. the uv projection is just weird in unity. I think the work around is to go with triplanner mapping but that is a bit of a pain.

lofty ice
#

Hey πŸ‘‹ Can be reflections anyhow adjustet from the shader itself?
[URP] - 11.0.0 - ShaderGraph LIT shader

#

For example here, there's a reflection probe and i'm trying to make the white spots (the reflection) make green

dim yoke
# lofty ice Hey πŸ‘‹ Can be **reflections** anyhow adjustet from the shader itself? [**URP**] ...

You can get the reflection by using Reflection Probe node but on lit shaders, those reflections are calulated internally and I'm pretty sure you can't manipulate them (atleast not easily). If you're making unlit shader, you can get the reflection using that Reflection Probe node, manipulate the given color and use that to calculate the color of fragment but it seems that's not the case. Correct me if i'm wrong but from my experience I'd say it's not possible to manipulate reflections of lit shader.

patent plinth
#

I think what you want is Specular map

dim yoke
#

I'm not very familiar with Specular maps... If I'm not mistaken specular map is not way to manipulate the reflection itself but tint it with some color am I right (or does it tint only the shine that comes from lights)? If so, yes, it can be used to make the reflection more greenish.

kind juniper
#

afaik specular maps are usually grayscale(storing 1 value in 1 or all channels) that defines the reflectiveness of the materials at certain uv point. So, for example, if you have a texture of a floor tile that has both metal and concrete for example, the concrete part would have a value of 0 in the specular map, while the metal one would have a higher value(possibly close to 1 depending on how reflective you want the material).

#

Ah. My bad. That's for the legacy specular shader I guess..?πŸ€”

#

The standard one seems to have a separate slot for the map.

patent plinth
#

My attempt to create procedurally generated stylized/toon rock shader... This would be very handy

The texture are just simple noises and parallax mapped

civic fern
#

looks good!

#

so im trying to have a 2d game like a .. sigh .. LIKE a metroidivania imagine, but with 3d models for the characters as its way easier to animate them

#

i just took a blender course so i have a 3d model to test out, but, using the (2d preset) URP, with a new URP>Lit material, only the base color map seems to change the character at all. i have metallics, normals, and rough maps but putting them in the material does nothing. halp!

lofty ice
# dim yoke You can get the reflection by using `Reflection Probe` node but on lit shaders, ...

Hey thanks for the reply πŸ‘
Potentially i would be happy to disable the internal logic and then implement the probe myself (via the siad ReflectionProbe node).

Only solution that doesn't require custom base shader would be to disable the probes somehow, but i'm not sure how they work.

If they would be a keyword πŸ‘ that would be awesome. But that doesn't seem to be the case.
https://forum.unity.com/threads/anyway-to-disable-environment-light-inside-my-shader.522659/
https://forum.unity.com/threads/turn-off-receive-shadows-on-custom-pbr-graph-lwrp.657814/

I'm bit afraid to implement Smoothness in Unlit myself, but that would solve many issues indeed 🀟 Ty for the direction.

kind juniper
civic fern
#

well how do i modify it so it does

#

its absolutely possible

kind juniper
#

What's the problem with using the 3d preset?

civic fern
#

my game is 2d..? idk, i don't really remember adding it at this point

#

honestly i was just referring to how my project was set up, i didnt know URP had something specific

kind juniper
#

URP has a 2d preset for 2d lights. It's still experimental though. I assume that you're using that preset.

civic fern
#

yeah, i thinhk ima swap off of 2d lighting entirely

#

its too experimental and the pitch shadows don't look good

#

i have no idea how im gonna do proper lighting, but thats a problem for a different dayt

kind juniper
#

You should decide if you want to use 2d or 3d assets and switch to the appropriate renderer. Combining both might require you to write a custom render pipeline.

#

If you care about lighting and shadows that is.

civic fern
#

true, i just cant imagine 3d shadows looking good on a 2d game like how would that even work

#

ori did it .. i wish i could have a copy of the ori proj file so badly.

twilit geyser
#

Hey guys πŸ™‚ Can someone explain the distance node to me? I expect it to work differently than it does. I'm using this simple shader on a sphere and would expect the point at (1 | 0 | 0) to be pitch black, because the distance node checks for that point exactly and the distance should be 0?

However, when I look at the shader on my sphere it's a lighter gray without having a point fully black it seems. Why not?

regal stag
# twilit geyser

Does the sphere actually overlap the point in the world at (1,0,0)? It's hard to tell the scale from this image

twilit geyser
#

Ah, because the radius is 0.5 not 1

civic fern
kind juniper
civic fern
#

oh, weird

#

idk it looks right

#

project settings > graphics > scriptable render pipeline settings

#

is where i put it but nothing changed so you're prolly right

kind juniper
#

As I said, that's the RP asset, not the actual renderer asset.

civic fern
#

where's the thing i should change??

#

sorry for being fussy im out of practice

kind juniper
#

In the URP asset that you're using

#

take a screenshot of the asset

civic fern
#

two assets

#

the URP needs another bit

kind juniper
#

This is what I'm talking about

#

But it seems like it's already 3d(forward) renderer.πŸ€”

civic fern
#

yea i just made a new one for it

kind juniper
#

Do you have a 3d directional light source in the scene?

civic fern
#

i think so

#

yeah i do

#

something else is kinda weird tho

kind juniper
#

And your normal maps still don't work?

civic fern
#

in the screenshot you can clearly see something is lighting him up from the top right

#

but nothing's doing that, moving every light source to his left doesnt change it

regal stag
#

If it's a directional light then moving it won't change anything, you need to rotate it

kind juniper
#

What do you have in your hierarchy?

civic fern
#

its a point light

kind juniper
#

Try disabling them instead of moving.

civic fern
#

yeah ive done that not

#

nothing

#

ill try moving him now

#

i tried moving him super far to the right and it didnt change. i guess there MUST be some sort of global 3d light somewhere, but the closest i have is a disabled global 2d light

kind juniper
#

Take a screenshot of your hierarchy.

regal stag
#

If you change settings on the 2d lights do they still affect things? If so the renderer might not be assigned properly

civic fern
#

ok! would you like me to search through every component or something

#

yeah the 2d lights work as expected on everything except the 3d model. which maks esne

kind juniper
#

So you're still using the 2d renderer.

regal stag
#

Well in 3D Renderer the 2D lights shouldn't work at all

civic fern
#

oh, interesting then

regal stag
#

The wrong URP asset is probably assigned in project settings. Each quality setting also has an override for it which you should check

vocal narwhal
#

which render pipeline asset is actually assigned in the graphics settings?

civic fern
#

the one i took screenshots of

#

under "scriptable render pipeline settings", if that's what you mean

#

ive tested the orc in a new project with the 3d preset and he works as intended

kind juniper
#

Take a screenshot of your quality setting with the current quality level selected.

civic fern
#

where do i see that?

kind juniper
#

Project settings - quality.

civic fern
#

...

#

πŸ˜”

#

that had 2d listed, damn

#

ty guys lmao

#

works now

#

or at least it changed and the orc is dark and there are no more 2d lights

#

i do have one more question

#

ttying to make it like the 3d test project (using an autodesk interactive shader so that i can use my roughness map) just makes the orc come out pink with URP

#

is there a way to make URP read a roughness map, or should i just go without for all my future models?

#

i'm illiterate. i found it lol, dw (question answered)

lofty ice
olive brook
#

hey, boring part of the shaders. anyone knows some bit about shader variants ? let's say I have a shader with following keywords system ( an imaginary system )

#pragma AAA key1 key2
#pragma BBB key3 key4

where the final variants would be

key3
key3 key1
key3 key2
key3 key1 key2
key4
key4 key1
key4 key2
key4 key1 key2

so from BBB only one can always be active ( a.k.a. defined ) and from AAA all possibilities should be possible

how to achieve that ?

#

or in a real example :
I have

IS_GUASSIAN
IS_MASKED
QUALITY_HIGH
QUALITY_MID
QUALITY_LOW

as u understand, all the QUALITY_* should be available in the final build because the quality can sure change. but other keywords could be optimized away

sacred dirge
#

guys

#

i cant edit the node for color in the shader window, when i click on it it just selects the master node

narrow breach
#

Hello everyone sry for that but I have several questions :/

https://stackoverflow.com/questions/54739349/unity-2d-area-color-inverse-effect/69708377#69708377

Is this possible with shader graph ?

Is it possible to use the alpha channel of a texture rather than the mesh ?

Thanks.

#

I understood how to modify a "texture" with shadergraph but I can not do this kind of effect area through sprite

patent plinth
#

Pretty sure shadergraph has InvertColor node.. never used it or knew if thats the node you're looking for

narrow breach
#

this invert the color of a sprite but that not what i want, i want to made a effect that invert color trough a texture

kind juniper
#

You'll need to sample scene color or something if you want to invert everything else.

#

There's a scene color node

#

Although it's not the same way they did it in the regular shader. Honestly, I don't completely understand how that shader worked, but the important point is the blending mode that it used.

civic fern
#

hey guys, can someone help me create a shader that creates a colorable outline around my 3d models towards the camera?

patent plinth
civic fern
#

https://www.youtube.com/watch?v=MqpyXhBIRSw like this, but with 3d? i really like this effect but after the changeover i have no idea where to go

Thanks to NVIDIA for sponsoring!
Learn more about NVIDIA Studioβ–Ί https://nvda.ws/38AaA8K
Razer Blade Studio laptopsβ–Ί https://www.razer.com/studio

In this video we create outline effect using 2D Shader Graph!

● Learn more about 2D Shader Graph: https://youtu.be/5dzGj9k8Qy8
● 2D Glow Tutorial: https://youtu.be/WiDVoj5VQ4c

● Get Gothicvania Ch...

β–Ά Play video
narrow breach
#

strange grey square in my render :/ I will inquire

patent plinth
#

no no.... dont do that.. see my post above

#

see that Red turns into green... is that what you want?

#

@narrow breach

narrow breach
#

i try

kind juniper
#

He wants the scene color overlapping the object inverted.

#

Not the texture color inverted.

patent plinth
#

oh.. well. I've no idea then ahahaha

#

πŸ₯² misread the post

narrow breach
#

np

kind juniper
kind juniper
civic fern
#

sounds cool but also. what

#

duplicate the renderer?

#

do you mean duplicate the forward renderer data

kind juniper
#

yeah. Duplicate the object

#

No

#

The object that you want to have an outline

civic fern
#

oh, i wouldnt call that a renderer

#

ok so in the material i make

#

i make it put in the object twice

kind juniper
#

There's a renderer component, so technically it's a renderer.

civic fern
#

oh, ok

#

so i make a material that takes in the renderer component twice .. make it render one of them last in an unlit colour ..

#

can i do this in shader graph?

kind juniper
#

Yeah, you just parent that "duplicate object" to the real object and do everything else that I described.

civic fern
#

aie aie aie

#

alright thats a start ig haha

kind juniper
#

No shader graph involved.

civic fern
#

oh. what

kind juniper
#

It's just a duplicate object that is rendered behind the real one with one color

civic fern
#

so every time i make an object i have to put two renderers on it

#

i'd prefer to do it in a shader/material if possible

kind juniper
#

Well, if you want to go the simple way, yes.

civic fern
#

im working on something quite big here so id prefer upfront time sink for future ease of use

kind juniper
#

I imagine it shouldn't be too complicated with a shader graph either.

civic fern
#

sounds better, hah

narrow breach
#

the "scene color" node don't work like i want x|

kind juniper
# civic fern sounds better, hah

You just need some way to extrude the object edges along the normals and color them in whatever color you want.πŸ€·β€β™‚οΈ

civic fern
#

alright that sounds good

kind juniper
narrow breach
#

yes

#

hum the "texture"

#

the shader i don't know :/

kind juniper
#

The shader graph needs to be transparent. You're using an older version of the shader graph, so I'm not sure where that setting is...

narrow breach
#

oh

kind juniper
#

It could be the master node

#

check if there's a transparent master node

narrow breach
#

like a PBR graph ?

kind juniper
#

I don't know if PBR can be transparent. Is there anything else?

#

It probably can though

#

Actually, thinking about it, it should've worked with an opaque shader too.πŸ€”

#

Make sure that the rendering order of your inversion material is higher(later) than other materials in the scene.

narrow breach
#

i don't really understand :[

kind juniper
#

I think I know what might be the issue

#

Take a screenshot of your render pipeline asset

narrow breach
#

ok i use urp sorry x(

#

mb

kind juniper
#

I'm talking about URP

#

Take a screenshot of your URP asset@narrow breach

narrow breach
kind juniper
narrow breach
#

don't change anything :/

kind juniper
#

Hmmm... Then I guess your shader is not transparent. What unity/shader graph version are you using?

narrow breach
#

unity 2019.4.10f1

kind juniper
#

Ah, okay, so it is transparent

narrow breach
#

Note: In Universal Render Pipeline this Node returns the value of the Camera Opaque Texture. See the Universal Render Pipeline for more documentation on this feature. The contents of this texture are only available for Transparent objects. Set the Surface Type dropdown on the Material Options panel of the Master Node to Transparent to receive the correct values from this node.

kind juniper
#

Take a screenshot of your camera inspector

narrow breach
kind juniper
#

Just to be sure, set the opaque texture to true

#

The last thing that I can think of is inputting screen position into the scene color node input

narrow breach
kind juniper
#

Or try the UVs for a test

narrow breach
#

UVs ?

kind juniper
#

Yeah, the object uvs. Although that's probably not gonna change anything. I think the problem is with the rendering order.

#

or this

narrow breach
#

ah yes it's doesn't work :/

kind juniper
#

And if that doesn't work, then it's definitely the rendering order. 99%

narrow breach
#

how can i change the rendering order ?

kind juniper
#

in the material settings

narrow breach
#

i think its because "Scene color" doesn't support URP

kind juniper
#

might also need to adjust the order in the sprite renderer.πŸ€”

kind juniper
#

Take a screenshot of your sprite renderer and material

#

It might also be precisely because of the sprite renderer.πŸ€”

narrow breach
kind juniper
#

Try a regular mesh renderer with a quad mesh instead and see if that works.

kind juniper
narrow breach
kind juniper
#

Yeah, could be the sprite renderer. Try a quad instead.

narrow breach
#

like this ?

kind juniper
# narrow breach like this ?

Yeah, just make sure that it's in the right position and all of the previous fixes applied(I see that you removed the screen position node).

regal stag
#

The Scene Color node / Opaque Texture doesn't work with the 2D Renderer

kind juniper
#

Aha. I thought that that might be the case, but it wasn't mentioned in the docs...πŸ€”

narrow breach
#

ok i try smtg

#

ok final question

#

so this "handmade" shader work properly but Is it possible to use the alpha channel of a texture rather than the mesh ?

kind juniper
#

Maybe you can try discard if the alpha value is lower than a threshold. I'm not sure if that's gonna work though.

#
if(col.a < someThreshold)
    discard;
narrow breach
#

that discard everything but that a start

kind juniper
#

put that in the fragment shader

#

just before you return col

narrow breach
#

yes

#

at 0 it not discard anything

kind juniper
#

Do you have alpha set as transparency in your texture import settings?

narrow breach
kind juniper
#

Okay...πŸ€”

#

Aah

narrow breach
kind juniper
#

The problem is that you only sample the bottom left of the texture:

#

try o.uv = v.uv

#

I'm not sure why it was done like that... Maybe there's an important reason for that but I can't figure it out.

narrow breach
#

damn

#

dud

#

it works

civic fern
#

i've worked on this shading thing for a while and ive got an idea buuuut

#

can anyone help me make something like this?

#

i'd like to make my own version for practice and, obviouslty, cause then it wont cost money, and also so its more customisable

#

but obvs i have no idea where to start

patent plinth
#

pretty sure, there are tons of this on youtube, heve you checked there?

kind juniper
civic fern
#

interesting but also I Am New and have no idea how to manipulate post processing more than the component

patent plinth
#

if this effect will be scene wide, I'd go with custom renderer...

#

Pretty sure Unity has an example for that

#

otherwise sahdergraph

civic fern
#

eh, it might be. ideally i'd prefer a material i can put on an object renderer to apply the outline

#

ill look for it on YT again

#

oh thats right, yeah i saw theirs but it didnt work with URP

regal stag
#

The same example has a post-processing sobel version too

wary horizon
#

Heyy..

I have no idea aboutr CG shaders but i hope someone can help me out! I found this shader many months ago and it works fine.

But if i scale my object past its original size, the outline breaks and has cuts... (im not sure how to explain it, but the screenshot should make it apparent.)

Does anyone know a good way to fix this? Heres the shader:
https://mystb.in/CopyrightsHarvestSubscribers.properties

patent plinth
regal stag
wary horizon
#

you just said words that are way over my head my friend

#

these are Synty models

#

and i cant remember where i got this outline shader from, was atleast 8 months ago

kind juniper
civic fern
#

im overwhelmed for today haha

#

ill prolly just buy that package tomorrow

#

ty all for your help todayu

kind juniper
regal stag
civic fern
#

i tried that one and it does look good but it just .. doesnt work

civic fern
#

idk why. plus, its not a material i can just add on although i guess thats not too much difference

wary horizon
#

So we saying im outta luck?

kind juniper
civic fern
#

fair nyff

wary horizon
#

Since my knowledge on CG shaders is less than 1%

civic fern
#

oh, nvm, i got it working

#

only works when i press play though .. meh

wary horizon
# kind juniper wdym?

wdym wdym? I dont know anything about scripting shaders, So i am none the wiser to know how to fix it

#

Or atleast band-aid it

#

if at all possible

kind juniper
kind juniper
wary horizon
#

I am using URP yes

kind juniper
#

Then it's not CG. It's HLSLπŸ˜›

wary horizon
#

😭 see what i mean

#

I am dumb

kind juniper
wary horizon
#

Thats alot of engine editing just for a little thing like this

kind juniper
#

outline is a pretty big deal. I wouldn't call it a little thing.

fast skiff
#

how can i write .compute code and some editor behaves a little more helpful than a texteditor?

kind juniper
#

There's an hlsl plugin for VS that is a little more helpful than a plain text editor.

#

As for how you write, well, you just write it.

wary horizon
#

Is there a simple way to fix what i already have then? Or no? I can't imagine Synty releasing these models if they cannot work with an outline shader

kind juniper
#

Why not? Why would they even thing about something so specific? Besides, there are more than 1 way to implement an outline.

frozen stag
#

Where should one start to look for writing shaders? I'm a total noob, I had a class of old and simple OpenGl in past but that was that, I'm wondering if it's feasible with a reasonable effort to write some sort of flickering/trail effect for a 3d mesh or that would require too much time, since I don't have plenty, doing all things by miself

narrow breach
#

@kind juniper thank you it works perfectly

violet bough
#

I'm not at all experienced with writing shaders in code, but i needed a billboarding shader and for some reason this works but also flips the sprite on it's head

OUT.vertex = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) - float4(IN.vertex.x,IN.vertex.y,IN.vertex.z,0));

#

in the vert function

#

anyone know why?

#

and how i can achieve the desired result?

kind juniper
#

Mvp Matrix calculation... I think it'll be easier to just flip the uvs lol

violet bough
kind juniper
#

You need to flip the uvs. In the fragment shader do uv.y = 1 - uv.y before sampling the texture. I think that should be enough.πŸ€”

violet bough
#

worked

kind juniper
# violet bough worked

Remember that it's a workaround and you should really find the proper solution with the matrices...πŸ˜…

violet bough
#

yeah lol, probably gonna use a shader graph solution i found

#

a lot of people are having problems with this

#

from my research

lusty badger
#

It depends. If you stick the time node into a texture sample that isn't in wrap mode then it would be horrible and not work but most of the effects you're gonna use that for are procedural and are basically functions with their domain going to infinity so you can manipulate the UV however you like. At least that's my take on it.

iron vine
#

Hiya, I'm trying to create an effect like this. I have a shader which allows me to draw a texture in photoshop and adds emission, but I was wondering if there was a better way to animate different textures, as at the moment I am constantly rotating different materials with different textures, which is seriously affecting perfomance. Any ideas?

fervent tinsel
#

I thought Ubit meant the facial animation

#

but it could be that small display below too... bottom line is... question is just too vague

iron vine
#

Yeh sorry I meant the facial animation

#

I can do the trail

#

But yeh atm I've just got a texture for each expression and a corresponding material which just cycles through

#

Probably a terrible way to do it

fervent tinsel
#

could do effect like that with gradient mask which you then feed the mask threshold value in shader

iron vine
#

But I wanna animate loads of expressions

fervent tinsel
#

like, you could control how much the mouth and eyes open through that

iron vine
#

How so?

#

That’s an example of one of the textures

fervent tinsel
#

you have a gradient mask, in shader you compare when the color value is over your treshold, if it's over, you give it emissive color, if it's under, you draw it black

#

you can add smoothstep etc to make the border smoother too

#

this is essentially how SDF rendering works - if you know of that Valve's text rendering paper

iron vine
#

So I set my texture to be the gradient mask?

#

No idea I’m very new to shadergraph

#

Thanks for the tip though I’ll give it a look

fervent tinsel
#

basically imagine you'd have something like this for eyes (I just put quick linear gradient but you could make it round etc)

iron vine
#

I see and then scale that

#

And then cutoff

fervent tinsel
#

then when you check is the value is above or below the value you want, you draw it black or white for the mask

#

after mask you get eyes half way through

iron vine
#

Can u do this in shadergraph?

fervent tinsel
#

or whatever value you put there

#

yes

iron vine
#

Awesome ty

#

I'll try it tmrw

#

May have to come back for further guidance

fervent tinsel
#

if you need more expressions, you could have one 4 channel mask texture with different gradient masks which you could then mix and match on shader

eager folio
#

@iron vine instead of multiple textures, you can also use sprite sheets; the flipbook node makes it really easy.

lapis lodge
#

you guys know of any extensions for VS to work with .shader?

kind juniper
kind juniper
#

Yeah.

lapis lodge
#

thanks

vapid junco
#

Hi everyone, I'm following a tutorial (found here: https://www.youtube.com/watch?v=84rZ-rCRsZk&ab_channel=DanielIlett) for making sprite outlines with Shader graph. The problem is that it only draws within the boundary/canvas of the sprite itself, and for pixels that sit flush against the borders there are no outlines. (Keeping the sprite flush to the edges as much as possible are required for the project though)

I tried changing the vertex positions and clamping the sprite to the center so the bounds would be larger and allow for more outline thickness as it grew, but I ran into all sorts of problems which I couldn't solve. I'm very new to shaders (and shader graph), so I'm quite stumped tbh lol.

Any help or direction would be much appreciated, thanks all.

Create an outline effect in 2D for SpriteRenderers using Unity Shader Graph! You can also read this tutorial here: https://danielilett.com/2020-04-27-tut5-6-urp-2d-outlines/

πŸ’» Get the source on GitHub:
https://github.com/daniel-ilett/2d-outlines-urp
✨ Get the "Bandits - Pixel Art" pack on the Asset Store:
https://assetstore.unity....

β–Ά Play video
#

here are where the outlines are to appear

violet bough
#

Hey guys, I am trying to lerp between different materials based on time of day. I want to do it like this guy does it: https://youtu.be/ERA7-I5nPAU

He basically has one script that controls his daynight cycle and has different materials assigned to different times of day, and then he has a folder with the ones that he assigns to different models and they change depending on the time of day. How does he do it?

Date of Recording: 2020-11-14

I took a bit of a break from the usual tech updates this week to record a making-of video detailing what it's like to create a scene from start to finish in the Unity-based pixel art game engine I've been developing.

I found some neat modifier stack tricks in Blender for creating procedural, non-destructive detail...

β–Ά Play video
#

I am gonna screenshot it, but how would you go about doing something like that?

#

the daynight cycle contains materials for all of these ones

#

but in different colors

#

for different times

#

he doesn't have to change the materials by hand, he assigns the coloured ones here and then has ones in the files that change depending on time of day

#

how

#

does he do that

violet bough
#

he has sepperate materials that are assigned to objects and then lerped

#

maybe sharedMaterials?

grizzled bolt
#

I don't quite follow

violet bough
#

sorry, gonna try to explain again

#

He has materials that are designed for different times of day.
He assigns them to a script

#

like this

#

then he has sepperate materials

#

that he assigns to his objects

#

and they change

#

depending on the time of day

grizzled bolt
#

I'm pretty sure the script overrides the materials assigned to objects

violet bough
#

but he doesn't have references to those objects

#

in the script

#

it's in a sepperate object

#

DayNightCycleController

grizzled bolt
#

Where's that in the video?

violet bough
#

i slowed it down and screenshoted it

#

i'm gonna try and find it

grizzled bolt
#

Yeah it's a good question

#

I'm not entirely sure how he did it
Probably there is a better way than finding each object to lerp
But if it was modifying shared materials, it probably wouldn't be using pre-existing materials

#

to switch to, I mean

violet bough
#

hmm

#

hmm

#

do you think i can assing a material to this?

#

or can i only modify it

#

@grizzled bolt

kind juniper
#

I think you can just reference the materials that need to be lerped. Not the objects. Then do the lerp thing on them at runtime.

violet bough
#

but will they be changed if they are assigned from the inspector?

kind juniper
#

Yes, for sure.

violet bough
#

so to be clear, what you mean is that the script should have inspector slots for the materials that need to be changed and the custom materials

kind juniper
#

The renderers I. The scene still reference these material assets. Assuming you don't create instances of them, they should change with the material assets.

kind juniper
violet bough
#

and then how do i change the materials with lerp? if i do :

Material custommaterial; // assigned in inspector (to be changed)
Material lerp1;
Material lerp2;

custommaterial = Material.Lerp(lerp1,lerp2,0.5);
#

won't this just change it in the script

#

won't it just generate a new one?

#

or do i have to call the function on the custom material?

#

custommaterial.Lerp(lerp1,lerp2,0.5f);

kind juniper
#

It also does not return anything. It chages the material that the method is called from.

violet bough
#

oh ok, this makes much more sense

#

thank you very much

tidal cypress
#

is there a way to add fog with another pass so I don't need to mess with my main shader?

grizzled bolt
#

Guess I'll try it out

kind juniper
#

Does it not just lerp all of the material properties?

meager pelican
grizzled bolt
#

So if day/night cycle is done that way, the cycler script needs a reference to every object's renderer to apply the lerped change, I suppose

#

Using some system of shared materials seems way more convenient

kind juniper
grizzled bolt
kind juniper
#

Why not? shareMaterial returns a Material all the same. It's just the one that's in your project folder as opposed to a new instance.

grizzled bolt
kind juniper
#

the same as with renderer.material, just renderer.sharedMaterial.πŸ€”

#

renderer.sharedMaterial.Lerp(matA, matB, t);

grizzled bolt
kind juniper
grizzled bolt
#

Oh yea it does work, even if modifying assets live is weird

#

I'd rather use global properties than mess with altering the materials

#

Especially if there needs to be logic for meshes with more than one material

violet bough
#

so no sharedMaterial

kind juniper
#

You don't need to.

#

As I mentioned previously, sharedMaterial is just a reference to the material asset, so you can reference it directly.

violet bough
#

i haven't tried it yet

kind juniper
#

It should.

violet bough
#

ok i'm gonna try it

grizzled bolt
#

@violet bough

{
    // Blends between two materials

    [SerializeField] Material material1;
    [SerializeField] Material material2;
    Renderer rend;

    void Start()
    {
        rend = GetComponent<Renderer>();
    }

    void Update()
    {
        // ping-pong between the materials over the duration
        float lerp = Mathf.PingPong(Time.time, 1f);
        rend.sharedMaterial.Lerp(material1, material2, lerp);
    }
}```
#

This is the test script that worked

#

The renderer itself uses material0 as its material which gets permanently overwritten regardless of what it looks like once the script runs

violet bough
kind juniper
violet bough
kind juniper
#

And Your terrain component? What material does it have?

violet bough
kind juniper
#

Does it have it at runtime too?

violet bough
#

yes

kind juniper
#

Hmm... Well, I'm not sure about terrain, but have a try with a mesh renderer. Maybe terrain creates an instance of the material anyway.πŸ€”

violet bough
#

ok

#

tried it with a capsule

#

doesn't work

kind juniper
#

Weird. Are you sure that your code runs?

violet bough
#

yes

#

logging "lerp"

kind juniper
#

okay

#

Can you take a runtime screenshot of the renderer that has the material that you expect to change?

violet bough
kind juniper
#

Interesting

#

Gonna give it a try

violet bough
#

ok

#

thank you for the patience and help so far :)

grizzled bolt
# violet bough

This doesn't look right
It should bounce between 0 and 1 every second

violet bough
#

that's every frame

grizzled bolt
#

Ah, of course

violet bough
#

i can confirm it does go from 0 to 1

kind juniper
#

Works for me

violet bough
#

what did you do?

kind juniper
#
public class MatLerper : MonoBehaviour
{
    [SerializeField] private Material target;
    [SerializeField] private Material matA;
    [SerializeField] private Material matB;
    void Update()
    {
        var t = Mathf.Sin(Time.time);
        target.Lerp(matA, matB, t);
    }
}
violet bough
#

could it be that it's on the same entity?

kind juniper
#

Gonna try with ping pong

kind juniper
#

Yep, works with ping pong too

#

Just to be sure, your DayTerrain and GoldenTerrain mats use the same shader, right?

violet bough
#

yes

kind juniper
#

Okay

violet bough
#

they only use a different texture

kind juniper
#

aah

#

I don't think textures are gonna work

#

it only lerps properties.

violet bough
#

well it samples the texture for a pallete :/

kind juniper
#

No can do.πŸ€·β€β™‚οΈ

#

At least not with material lerp

violet bough
#

rip, at least we got to the problem, thank you :)

violet bough
#

ok @kind juniper tried it, it works now

#

hmm

#

but for some reason

#

not with terrain

kind juniper
#

I guess terrain instantiates the material at some point.

#

Might need to access it via the terrain.

violet bough
clever saddle
#

I wanna ask something about compute shader

#

The boundsize passed in is a float,How does it calculate in float3?

kind juniper
#

@clever saddle If it works, then I'd guess that it implicitly converts it to float3 with all components having the same value.πŸ€”

#

Does it work?

clever saddle
#

@kind juniper Yup.It works.For example,if the boundSize is 2,it will convert to (2,2,2),right?

mild fossil
#

hey folks. Is there a way to reference a cubemap without 3d geo? I'd like to have a screen noise overlay that's in 3d space, so that when I rotate my camera view, it doesn't feel like noise on my glasses/visor. Right now the world moves in relation to the camera but the noise does not. But figuring out how to talk to a cube map in shader graph is beyond me. Any advice?

glossy matrix
#

was trying to delve into writing shaders, making a circle with smooth edges,

fwidth works when you got close, but would be quite jagged from far, so i capped the val, (with min) - which kinda worked. .

i was wondering if i should use proximity (VPOS) and multiply it based on z value or something?

violet bough
#

i have just fixed a problem in my code

#

because

#

for some reason

#

uv of 1,0 is = 0,0

#

so i can't clamp to 1

#

why?

#

why isn't a uv of 1,0 on the right of the texture

violet bough
#

anyone here know how to pass uniforms to shadergraph?

meager pelican
meager pelican
# violet bough why isn't a uv of 1,0 on the right of the texture

How the result is returned depends on the wrap mode and filter mode the sampler is in (and texture's default is a property on the texture import settings too).

Clamp will clamp to the edge, even smearing pixels to the edges (often results in people getting confused with "lines" in their textures...seen often in sprites).

Add to this the filtering mode that samples nearby pixels, and if they wrap they wrap. So the nearby pixel to 1.0 is going to wrap to 0.0, and then the two get computed together and "blurred".

Best guess, can't tell squat from that graph though.

opaque bay
#

Anyone know how to make a shadergraph shader that works with RectMask2d? I made a shader for my UI icons and they don't get masked by it anymore.

stark vessel
#

anyone know a way to disable specular effects for an object using a lit shader? I know that sounds odd but my blackhole effect for some reason only works correctly if its a lit shader in HDRP. but I cant get rid of the specular effect on its surface and its breaking the effect

clever saddle
#

What is compute shader grammer. Anyone know where to check the API?

kind juniper
astral pecan
#

How do I get keywords from script?

#

Need to know which enum it is currently using in script

kind juniper
#

You could probably get it as int parameter

meager pelican
#

You set it on the material. Check the material's value, that's what gets sent to the shader when it is time to render the object.

@kind juniperis correct, enums are ints. But you can compare them to enum constants as set in C# (either created by you, or canned).

violet bough
#

any idea why this weird shadow thing is happening?

#

i'm gonna send my shader code

#

i use this to get the light values

#

this is the calculate light function

#

i am using urp

#

and these are my setings

sterile wave