#archived-shaders

1 messages · Page 92 of 1

flint sequoia
#

this is what i have for now

arctic snow
#

hey everyone, Im wondering how can I apply different textures to different faces? its applied on cubes (such like minecraft) and I want to have a top- & bottom texture and one texture around it. Can anyone help me? This is what I've got rightnow: (only side texture shown and not top/bottom)

livid fox
#

I have this simple shadergraph to adjust texture tiling by object scale ... it works fine in editor but as soon as I enter play mode the texture loses all tiling / looks like it assumes a scale of 1. Googling this it sounds like the issue might be related to (URP?) batching but have been unable to make any headway with that ... help?!

dim yoke
livid fox
arctic snow
dim yoke
#

Same blocks would have overlapping UVs but that is totally fine

elder plover
#

ive had a problem with marching cubes interpolation in compute files ive been trying to get the marching cubes to look like the first photo but the second photo is the only result id get
https://hastebin.com/share/eqikamojay.cpp

ivory sun
#

hey, doing some shield with bubble effect etc around and I have problem, it look good from outside of obj with shader (shader is transparent btw) - ss no. 1. but from inside there is no effect visible - ss2, any idea why?

#

and if I get render face = both the effect is kinda broken, it works from inside but is not like from above results :#

hushed silo
#

you need to have the object render twice

#

put two material slots on the renderer and have one set to backface one set to front

ivory sun
ivory sun
#

maybe should use isfaced or something

agile token
ripe imp
#

I think my URP asset is not used when actually rendering frames... I have set the same one across all qualities as well as the default in the graphics tab, and it only has one UR data attached, where i got 2 features attached. But when I look in play mode, or even in the frame debugger, they dont have any effect.

What did I miss? It should say something at any point about stencils as thats literally all i override in the features, but its all empty! Its Unity 6000.0.28f1 LTS

#

its on a fresh URP 2D core project, so version incompatibility is not the reason.. im really puzzled, any help?

regal stag
ripe imp
#

OMG that actually worked, thank you, thank you thank you, shaders are still black magic to me lol

#

not working quite how i want it, but at least theres proof it works!

ripe imp
#

i got it working how I want, but the vision cone mesh seems to correctly display itself hidden only once i walk away from the 0,0,0 position. When free-roaming with a 3d camera in the scene view, the angle of the camera seems to affect it as well? its a generated mesh with the Sprite-Lit-Default material with ZWrite turned to 0, no other changes.

Why would it depends on the world position?

ripe imp
#

ok turns out i had to change the render queue to 2999 from 3000, but why that is is still a mystery for me, maybe it dynamically assigns the queues and with elements like the walls it was rendering too late hence the all-white cone...?

ebon basin
#

I had a question about the Shader Graph. If I've a height map for my texture, where would I input this texture into? The fragment has an input for normals and AO, but I'm not seeing an input for a heightmap. Also, I'm trying to apply this map via the triplanar node, so I was wondering if there's any extra steps to be expected using that over using Sample Texture.

#

I've noticed applying a normal map to a Triplanar node seems a little off, so I was wondering about that too. Maybe I should use a secondary Triplanar node for the normal itself?

kind juniper
ebon basin
kind juniper
#

Did the standard lit shader had such a property(map slot) in unity?🤔

ebon basin
#

Not entirely sure how it works, but it does make the textures pop out a lot

#

but that illusion does seem to become reduced the closer you are

#

pretty neat considering

kind juniper
ebon basin
#

Some magic if it's just about changing UVs

kind juniper
#

It's weird that there's no node or input for that by default, considering the standard shader has it.

kind juniper
ebon basin
kind juniper
#

Oh, there was one. Interesting

ebon basin
#

now to figure out how to get it working with triplanar ;p

kind mural
#

😅

#

okay, so where we're at

#

this is a depth frame at one point in the Frame Debugger, which would suggest that the shader works?

#

but the tools clip into walls regardless in the final result

#

the render feature set up - depth override pass into regular render over

#

the shader (a bit of a messy hodge podge, but should be getting the job done):

Shader "Custom/DepthOverwriteShader"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
            ZWrite On
            ZTest Always
            Lighting Off
            ColorMask 0

            Pass
        {
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag

            #include "UnityCG.cginc"

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

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

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
                float color : COLOR;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert(appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                o.color = o.vertex.w;
                return o;
            }

            fixed4 frag(v2f i, out float outDepth : SV_Depth) : SV_Target
            {
                outDepth = 5;
                fixed4 col = pow(Linear01Depth(i.vertex.z), .85);
                return col;
            }
        ENDCG
        }
    }
    FallBack "Diffuse"
}
ivory sun
ivory sun
#

if I set only 1 material, set both render mode, use isFrontFace where for true=>normal shader, false=> one minus from normal and it works BUT its red.... :# it works fine outside and inside but inside color is red :# not blue that is stored in variable and used . I attach a graph for that, one with texture and checking isface etc, one is basic moving/animated fresnel effect and they are connected

kind juniper
#

The fact that you're using the red color for alpha is also weird btw.

ivory sun
#

i mean only that "one minus" makes me see effect from inside of object xd u are right that because of that its red but idk how to fix it or make it in other way to see effect from inside

#

fixed alpha, but what about seeing it from inside without using isFace front + minus one ?

midnight cedar
#

I keep getting Unity crashes for the most basic custom Bloom shader in BuiltIn RP on a new proj.

If I do Graphics.Blit or CommandBuffer.Blit to any texture thats not the "OnRenderImage" destination texture it crashes.

#

I've tried Unity versions from 2022.3, 2021.3 and even Unity5 and they all crash

low lichen
#

I usually get this when I accidentally have an infinite loop in a shader.

midnight cedar
#

Yes, its a CG shader but there are no loops in the shader

#

Err I do have a loop sorry

#

Hmm, I ported this from HLSL which was working perfect there in custom RP. But I'm getting it to work in BuiltIn and everything is the same

#

Maybe for shader ints don't compile the same in CG as they do in HLSL for Unity

midnight cedar
#

So its not the for loop. Its a tex2D sample in the for loop thats the issue.
Graphics.Blit or cmd.Blit should auto set _MainTex prop/const in the shader correct?

#

Or rather a combo of both. Ugg I hate how broken the old CG shader compiler is

low lichen
#

Can the contents of the texture affect the loop condition?

midnight cedar
#

So everything is fine. This was working perfect in HLSL.
My classic XY pass Bloom works just not my nicer Radial Bloom I want to use

#

So the radial Bloom uses nested loop. The loop exits just fine I think BUT I'm confirming more

#

Ok well got it to start working. For some reason it just can't handle as many iterations with CG shader.

low lichen
#

The loop doesn't have to be infinite to get that error, it just needs to take longer than 10-30 seconds, something like that. How many ring counts were you using when it was crashing?

midnight cedar
#

16

#

In HLSL I could do 32 with no issue

low lichen
#

So, 16 * 8 = 128 iterations per pixel. It's a lot, but I wouldn't expect it to take many seconds.

midnight cedar
#

ya and last I tested this in custom SRP on a slower GPU than I have now

#

CG shaders must be a lot slower in terms of its output

low lichen
#

In Unity, only HLSL is supported. When you use CGPROGRAM it defines a HLSL shader with a few include files automatically included for compatibility, such as defines for fixed.

midnight cedar
#

you mean for the output

#

As old Unity versions didn't support HLSL

#

Both compilers in Unity are just translating to other shader langs anyway

#

Honestly I'm confused as to why this is so slow in CG

#

I'm running this on a RTX 3060 and its not that high rez

low lichen
# midnight cedar Both compilers in Unity are just translating to other shader langs anyway

No, it's been a very long time since Unity supported CG. It's an old language that was abandonded by Nvidia in 2012.

Cg and HLSL share a history and it's why they are basically identical in syntax, with some minor differences, like a few built-in functions and types present in Cg but not HLSL. Unity used to use Cg and a Cg compiler, but that hasn't been the case for a long time. Instead, they use a HLSL compiler for both cases, but use compatibility include files to make Cg files compile correctly in a HLSL compiler.

#

I don't know why you feel you need to convert your HLSL shader to CG. Are you trying to port this shader to an older Unity version?

midnight cedar
#

The CG or HLSL compiler in Unity3D compiles out to GL, Metal and other console shader langs. So I'm not sure why you're saying this. Yes the native Nvidia and D3D shader compilers created CG and HLSL langs but other game engines have used these as translation langs

midnight cedar
low lichen
midnight cedar
#

I haven't decided yet. Just GLES2 platforms mostly or non-NEON ARM32 SoCs

low lichen
low lichen
#

You can support those platforms on the latest Unity version and you don't need to use CG shaders for those platforms.

midnight cedar
#

non-NEON ARM32 target ended after Unity5 maybe. I'd have to look

#

This included Tegra2 chips for example

#

Also I don't think you're right about shaders in Unity. Unity maybe have used CG directly on Windows but that was never the case on other platforms

#

This is very easy to see if you compile and look at your ASM shader gen

#

This is what is going on. I've used these shader langs to much. The legacy compile is not the Nvidia CG compiler as its way way to buggy

#

The HLSL one in Unity is much better but its still a translator outside D3D platforms

low lichen
#

Unity has hlslcc, which converts DirectX shader bytecode to different shader languages. It doesn't have any Cg compiler or converter, because it doesn't need one, Cg is so similar to HLSL, they can just compile it with an HLSL compiler if they polyfill the missing types like fixed.

midnight cedar
#

fixed is just float10 so ya

low lichen
#

fixed was a 12 bit fixed point integer in Cg, but Unity polyfills it as a half.

midnight cedar
#

I don't think thats true for ARM GPUs

#

fixed in Unity will produce lower bit floats on ARM GPUs for sure. I've writen water effects and can see the difference

low lichen
midnight cedar
#

Yes but it for sure wasn't a half quality

low lichen
midnight cedar
#

Half quality isn't any different from float in most cases or in these effects I tested

low lichen
#

16 bit isn't any different from 32 bit?

midnight cedar
#

Not for many applications no. A user will never notice a difference

#

It depends on your use case of course

low lichen
#

It's clear what fixed is here:

#

It's either a float or half, depending on the target platform.

#

In Unity, you write shader programs using the HLSL programming language.

Unity originally used the Cg language, hence the name of some of Unity’s shader
keywords (CGPROGRAM) and file extensions (.cginc). Unity no longer uses Cg, but these keywords and file extensions are still supported. Note that all shader program code must be valid HLSL, even if it uses the Cg-related keywords and file extensions.

The only difference between using HLSLPROGRAM and CGPROGRAM is in the files that Unity automatically includes when it compiles the shader program. This is for backwards compatibility reasons. For more information, see Built-in shader include files.

midnight cedar
#

That doesn't mean UNITY_FIXED_IS_HALF is enabled on all platforms

#

It depends on if the GPU reports half = fixed performance caps

low lichen
midnight cedar
#

So older GPUs like Tegra2 probably doesn't report this. Or many low end mobile GPUs

low lichen
#

To reiterate:

The only difference between using HLSLPROGRAM and CGPROGRAM is in the files that Unity automatically includes when it compiles the shader program. This is for backwards compatibility reasons.

midnight cedar
midnight cedar
#

@low lichen

midnight cedar
low lichen
midnight cedar
#

This is what Unity is doing

midnight cedar
jaunty reef
#

anyone have a water shader

low lichen
jaunty reef
#

for urp

low lichen
midnight cedar
#

You test the GPU and then select the shader variant depending on hardware

#

Even the code snips you have shared of Unity's shader foundation suggest this.
As they all seem to be able to not always have half on even in GLES

#

I'm guessing ChatGPT is thinking this is right from other conversations captured online.

#

But regardless it hardly matters

low lichen
#

This is by default not enabled, as far as I know.

midnight cedar
#

But that doesn't mean fixed is half with that off

#

From the code you shared it only flags fixed as half with that on

low lichen
#

Notice, it doesn't mention this player setting, which is the only that that determines whether it's defined. Because it doesn't know. It still pretends to though, suggesting it's defined based on the target platform, which is wrong.

low lichen
#

#if !defined(UNITY_UNIFIED_SHADER_PRECISION_MODEL).

#

So, if the unififed precision model is not enabled, and the target platform is GLES or GLES3, fixed is defined as half.

midnight cedar
#

aww, you're correct

#

IDK why Unity isn't checking GPU support

low lichen
#

ChatGPT can be very useful. It helped me figure out an issue I missed just yesterday. But it's very bad at this sort of thing, obscure knowledge about an obscure topic and can easily lead one the wrong path.

low lichen
midnight cedar
#

o1 model understand far more and is so much more accurate as code gen for APIs I don't use often

#

4o gets D3D9 caps questions I ask it wrong for example while o1 doesn't

#

Google sucks so bad anymore I just have to use AI to search much of anything if I'm trying to be fast

low lichen
#

GitHub search is pretty decent these days.

#

When it comes to specific information like this, I wouldn't trust anyone to know it off the top of their head, not even o1. You have to look at the source to get the answer.

midnight cedar
#

Some APIs have horrid docs and AI can reduce pages and pages of endless fluff into a couple lines

#

For example used it to better understand FMOD API DSP stuff quick

low lichen
#

To bring it back to the original topic, if you're seeing a difference in how your shader works when using HLSLPROGRAM vs CGPROGRAM, the reason for that difference can be found in the HLSLSupport.cginc file, because as we have established, that is the only difference between the two when it comes to Unity.

#

Which is good, you don't have to hunt down some obscure difference in shader compilers or anything.

midnight cedar
#

Well before I was using a custom SRP. So it wasn't builtin or URP at all. IDK if that could effect stuff or not.

low lichen
#

Did you also swap out .hlsl include files from SRP to their .cginc equivalents?

midnight cedar
#

Yes, my custom RP mostly had its own stuff outside pulling in some CoreRP shader includes for standard const etc

midnight cedar
#

Also had good DOF

#

And OIT shadows

#

This used per-pixel sorting after pixel shaders rendered themselves into ArrayTextures.

#

It was very fast

#

The OIT objects also could cast OIT shadows within all their layers

#

My method was fast enough for games actually. I had better screenshots but idk where they are

#

Here is the custom RP matching Blender materials

#

Also cool transparent effects it supported

#

And motion blur

#

And SSR etc

warm moss
#

This isn't a portfolio channel.

midnight cedar
#

O well, got into a show and tell mood

#

@low lichen Was able to adjust stuff to be good performance. Thanks for the tips

errant forge
#

Figured this is the best channel to ask.
I have this water shader, pretty simple. But why do the normals only work with the directional light that already comes in with the scene? (I increased the normal scale so you can clearly see the difference between the directional and the spot light).

#

Is it some config I need to toggle?

amber saffron
errant forge
#

Pretty simple normal animation

amber saffron
#

Or maybe the spot orientation is not good to allow you to see the direct specular lighting, like you see for the directional.

errant forge
amber saffron
errant forge
#

It's the wave

#

lemme disable the waves

amber saffron
#

There is def. a pattern here :

#

I guess you're using URP ?
Check that the additional lights are per pixel in the current URP asset

errant forge
#

Oh it's definitely the light type

amber saffron
errant forge
#

It works with a point light

#

ops wrong image

#

idk why the inspector says it's a spot light, but with a point light it works it seems

#

Guess the problem is the spotlight, which I won't use I guess

amber saffron
#

Like I mentioned, it's probably that you didn't find the matching angle to see the direct specular reflection, a spotlight is nothing more than a "constrained" point light

errant forge
#

I'd love to make it work

#

The player will have a flashlight

#

But I guess that's just how light in real life works lol

amber saffron
errant forge
#

Thanks!

amber saffron
#

Specular lighting depends on the light angle and the view angle, so if you don't have both with the proper "range", you won't see it.

velvet nacelle
#

hello i am a noob with shaders i was using 2 packages one is a toon shader and another was a curve shader that curves the world ... the problem is i can only use one material of the ethier one is there any easier way to use both on the same object

amber saffron
gloomy gust
#

how can i create a color replace shader ?

#

something that takes in an array of colors and an array of colors to change into

#

and then changes those colours

gloomy gust
amber saffron
gloomy gust
ivory sun
#

how easly add deph intersection to shader? Cuz i got kinda complikated one shader and idk how to add at the end deph intersection additionaly :/ tried reproduce just that step from https://storyprogramming.com/2019/09/17/shader-graph-force-shield-with-hits/ and multiply it with my own alpha that worked before and cant get that effect

Using Unity 2019.2.1f1, LWRP 6.9.1 and Shader Graph 6.9.1. You can get the article’s code and shaders here. I saw the tweet by Cyanilux and found out that Shader Graph&#82…

slender ore
#

Is it possible to make a simple fog that is applied onto plane to feed it information about real time lightning and get that effect of volumetric lightning. Basically something similar to what HDRP fog can do with lightning but in URP shader

gloomy gust
#

why isnt this working?

#

there arent 317 lines

warm pulsar
#

ah, welcome to hell

#

That line number is from wherever your custom function got put

#

(and can also include expansions of macros and #include directives)

#

anyway, I don't see a function namd colorReplace_float anywhere in that HLSL!

#

You typed in colorReplace as the function name. _float is appended because it's looking for a regular-precision function

#

(it can also look for _half when doing half precision)

#

You should rename that function to ReplaceColors_float and then punch in ReplaceColors as the function name in the Custom Function node

#

also, can you even use float4 arrays like that in the Shader Graph?

gloomy gust
#

i dont see arrays as an input option either way

#

yeah

low lichen
# slender ore Is it possible to make a simple fog that is applied onto plane to feed it inform...

Add depth to your project with Analytical Volumetric Lighting [URP] - Performant Raytraced Volumetric Lights asset from Akidevcat. Find this & more VFX options on the Unity Asset Store.

warm pulsar
#

I happen to have tackled the same problem very recently

#

I needed to deform a mesh with a variable number of effectors

gloomy gust
#

I ended up just doing this LOL

warm pulsar
#

I wound up using a structured buffer

#

Unity does support the concept of "vector arrays" on a material, but I don't think the Shader Graph can use them at all

gloomy gust
#

really annoying and hard to extend but it works so

warm pulsar
gloomy gust
#

i see

gloomy gust
#

wrote a little script for easier management of the colors

warm pulsar
#

You could use a little texture for this

gloomy gust
#

i just gave up in the end LOL

#

im gonna just make new textures for each chroma i have planned instead

gloomy gust
warm pulsar
#

you'd need to sample it correctly so that you aren't measuring between two pixels or something

slender ore
warm pulsar
#

e.g. a 4x4 texture could provide 16 colors

#

instead of doing a normal unwrap, you'd put each face on the appropriate chunk of the palette directly

gloomy gust
#

it would maybe maybe sense for the rest of the model

#

but the face looks like this so idk if that would work lol

warm pulsar
#

you could also do a second UV map that's used for the palette

#

UV0 would be for the base texture, and then UV1 would look up a tint value from a palette

low lichen
# slender ore That is a affect I am trying to achieve but would need some tutorial or at least...

This is a source I've used for figuring out the math. It's a bit complicated, but not too expensive. The more difficult thing is to get all the lights that overlap each pixel in an efficient way.
https://ijdykeman.github.io/graphics/simple_fog_shader

warm pulsar
#

ooh, that looks neat

#

oh, I've done something very similar before! I needed to deform a mesh to fit into a cone shape

#

switching coordinate spaces can make problems a lot simpler

gloomy gust
kind juniper
fallow herald
#

I made a scanlines full screen shader, but I want it to also have the lens distortion effect that the post processing volume uses. It looks strange that the scanlines are straight and the game graphics are distorted. Changing the injection point didn't help.

Does anyone know of any techniques to recreate a lens distortion effect in a full screen shader?

midnight cedar
foggy river
#

Hi, docs say

#
Surface shaders automatically set up an instance ID, but custom vertex and fragment shaders don’t.
#

I am using a surface shader. So how can I access this instance id? I tried using v.unity_InstanceID wrapped in #ifdef INSTANCING_ON but it didnt work

#

I just need a random number for each instance...

hushed silo
#

anyone know if there are any hyper performant (and nice) skybox aurora borealis approaches out there?

dim yoke
# hushed silo anyone know if there are any hyper performant (and nice) skybox aurora borealis ...

From quick search it seems like raymarching is often used for aurora borealis effects but that's obviously far from performant. Far more performant would be some sort of skybox shader based on couple prebaked textures and lerping between them but I don't think that would be easy to get looking any good. I think good middle ground would be this type of mesh based approach which could use particles to initialize the meshes and a shader to displace the vertices https://www.youtube.com/watch?v=SNP5QqAQqn4. You could develop more sophisticated vertex displacement for more squickly and natural looking waves though. Also the tutorial relies heavily on the procedural noise functions which are quite bad for performance, instead you could use prebaked seamless noise textures for better performance.

hushed silo
#

hmm yeah. I was hoping to avoid geometry for the simple reason that my skybox has a horizon / fog gradient I'd like it to mix in with, (and also generally trying to avoid transparent objects) - also many of these geo ones wind up looking very ribbony rather than nice evolutions

sharp frost
#

Hey all,
Anyone please clarify me what does it mean. Is this single shader generating too much draw call or its as showing me as per the object(shader assigned on more then 500 objects).

sick kernel
#

Hello, I am big noob in shaders and trying to make a texture warp horizontally with a sin wave. My code:

            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);

                float wave = sin(float(v.uv.y) * _Frequency * 6.2826) * _Amplitude;
                o.uv = v.uv + float2(wave, 0);
                return o;
            }```

But no matter what I set frequency to, the texture only spans one wavelength, changing frequency simply shifts the wave up or down vertically, it does not add more tops and bottoms like expected. Am I doing something wrong?

Thanks for any help
grizzled bolt
sharp frost
grizzled bolt
slender ore
eager folio
graceful holly
#

In the BatchRendererGroup docs, Unity says Set the most significant bit 0x80000000 in each [Shader Property Value] which instructs the shader that the data is an array with one value per instance, indexed by the instance index. ... what's the alternative here? Are there other options? How does it read the data if I don't set that bit?

amber dove
#

How Would I Go Around Making a Shader To Look Like These Mach Diamonds? (sorry if dumb question im new to shaders)

warm pulsar
#

So the MSB is a flag that says "I have values for these instances"

#

check the "accessing DOTS instanced properties" section on thatp age

#

You don't have to do this; it's just how the access macros described on that page work

karmic hatch
graceful holly
midnight cedar
#

It's better to make your own SRP if you want to start doing advanced stuff imo. Then you can handle shadows more how you want

hybrid parcel
#

Any idea on how fog in built-in RP might be achieved?

kind juniper
tacit parcel
vestal hinge
#

Hi everyone, I'm currently working on a project that uses producral generation. To do so we are using Graphics.RenderPrimitives, however right now the current implementation of this code is a basic Unlit shader for rendering textures without lighting.

I was wondering if anyone had any resources on how I would go about moving this over to the shadergraph (URP)?

#

To elaberate on this, specifcally I am talking about the input side of things. with the vertex ID and instance ID in the vertex function.

kind juniper
vestal hinge
#

Ill have a look, I may have missed them. Will they work then just with a normal shader in the same way as the custom .shader file?

brazen nimbus
#

Hello there ! I'm looking to use the simple noise node combine with the view direction but I get this stretch part on one of my axis. Any idea if theres a way to sample 3D UV into the simple noise or if there's a trick to avoid that OR if it's possible to scale a cubemap ? Thanks in advance ! :)

amber saffron
warm pulsar
#

You need 3D noise here, yeah

vestal hinge
# kind juniper They should, yes.

Hiyan sorrt for the late reply, something came up. But continuing my question, your right in saying that the instance ID is a node in the shader graph, but I am unsure on how I would access the transform data that would have been in the compute buffer.

StructuredBuffer<float4x4> _ObjectToWorldMatrices;
StructuredBuffer<int> _Triangles;
StructuredBuffer<float3> _Positions;
StructuredBuffer<float3> _Normals;
StructuredBuffer<float2> _UVs;

I have these buffers in the text based shader, but the properies accessable in the shadergraph are only indevidual variables rather then buffers.

I assume their is a way of doing this, but I am still unsure as how.

#

Would this be the "hybrid per instance" option on the single parameters?

kind juniper
vestal hinge
#

Unless I am looking in the wrong place then no, I don't think they are listed.

#

With custom function nodes, I am setting the buffers inside a materialPropertyBlock, would these just be readable on the GPU using the same names they where called when assigning? (Sorry this is more a question about when and why the data is loaded and how do you read it.)

warm pulsar
#

I've done this

#

struct Foo {
  float4 whatever;
}

StructuredBuffer<Foo> Items;

void GetItem_float(float index, out float4 result) {
  int i = (int) index;
  result = Items[i].whatever;
}

(indexing with a float is very silly, but i don't think the shader graph knows what an int is)

#

then you just set a buffer on the material (or on the material property block) with a matching name

#

in this case, "Items"

vestal hinge
#

Oh awesome! Thanks thats exactly what I needed, I thought that might be how it worked but I'm glad it is ^-^

#

Thank you

kindred stratus
#

Hi all! I'm currently working with parallax occlusion mapping in a URP shader graph. I however stumbled onto a persisting problem that i can't get rid of. When my plane is rotate 180 degrees, the parallax mapping works just fine, but as soon as i rotate the object, the parallax starts changing direction. and i have no idea how to change this.

The shader graph is quite complex as its an adapted version of a vertex painting tool. But perhaps someone knows whats causing my issue?

thin lintel
#

hey guys, does anyone know why sometimes after saving a script, my shaders keep compiling infinitely? as I'm typing this it's been about 5 minutes. only thing that seems to fix it is forcing Unity to close. I only have 3 different versions of this "parallax sight" shader.

#

also this appears when I re-launch the editor

warm pulsar
#

When the object and camera line up just right, that can cover up an incorrect conversion

#

e.g. if you forget to convert from object space to world space, it'll still work if the object is at [0,0,0], unrotated, and unscaled

kindred stratus
steel notch
#

How do you make these overridable inputs?

icy charm
#

how do i make a custom rendering pipeline. i am pretty experienced in shader programming but i have never really used unity. i want to make a renderer for a black hole it needs to be ray marching based since i also want a volumetric for the accretion disc. it would be nice if someone could tell me how to make this possible and pass the necessary information to the shader. (GLSL if possible since i have more experience with that)

warm pulsar
#

ah, but this isn't that simple -- it's defaulting to UV0/1/etc. but also letting you plug in a value

#

I swear I've done this before. I think it had to do with the "use custom binding" setting on the property...?

warm pulsar
#

That just lets you put a custom label on it.

#

you can then branch based on whether or not anything was plugged in, but there's no dropdown here

#

(I tried the names and nothing special happened)

lament adder
#

Hi I'm having a bit of trouble, I want to update a material parameter when I click a certain amount of time

#

But the material does not seem to update in game, even tho it does in the inspector

#

I tried changing the parameter, or swapping materials but it both ways did not work

#

I can see the material swapping and changing states in the inspector but not in game

fallow herald
warm pulsar
#

If you're doing this:

public Material material;

void Update() {
  material.color = // ...
}

and you drag in the material from the Project window, then that's going to change the original material asset

#

This will work as long as the renderers are using that asset.

#

But if you ever access renderer.material on them (maybe to set another property?), they're going to get their own copies of the material

#

These copies have "(Instance)" appeneded to their names and have nothing to do with the original asset

lament adder
#

Ill check it out when I get back on it, ty

warm pulsar
#

Causes a lot of noise in your version control system

#

You could do something like this:

[SerializeField] Material material;
[SerializeField] List<Renderer> renderers;

void Start() {
  material = Instantiate(material); // now we have a copy
  foreach (var renderer in renderers) {
    renderer.sharedMaterial = material; // doesn't try to make a copy at any point
  }
}

void Update() {
  material.color = // ...
}
#

If each renderer needs its own material because each one customizes something, then just iterate over the renderers and mess with their .material

ebon moss
#

can I code a custom node for shader graph and save it as its own asset so that I can use it in the future, or will I have to copy and paste it each time?

ivory geyser
#

Hi Guys! I want to change the surface type from Opaque - Transparent of a instanced material in runtime. The material is created using the Shadergraph - PBR lit material. How should i proceed?

kind juniper
mental bone
ivory geyser
# kind juniper Change the surface type to transparent.🤷‍♂️

I need to change them in realtime. Because these are Ready Player Me assets which gets downloaded in runtime & gets loaded in cache. I found a way to override some settings which i want. Only thing which was pending from my end is switch from opaque to transparent in realtime at the start of the scene

ivory geyser
kind juniper
ivory geyser
#

Ready player me doesnt give me slot to override two materials. Thats the blocker i have. They are using similar method in their default shader & applying same methods. When i try to override with mine its not switching to transparent eventhough its a minor change or no change from their shader

kind juniper
jovial iron
#

Does anyone know how to access the camera color target in URP? I have tried _CameraColorTexture and _CameraOpaqueTexture like has been suggested online, but I get "undeclared identifier" errors

regal stag
vestal hinge
#

Hi all I was wondering if anyone knew what reason it would be that I can't connect a vetor2 output of a custom node:

void GetInstanceData_float(uint instanceID, uint vertexID, out float3 position, out float3 normal, out float2 uv)
{
    const float3 objectPosition = _Positions[_Triangles[vertexID + _StartIndex] + _BaseVertexIndex]; 
    position = mul(_ObjectToWorldMatrices[instanceID], float4(objectPosition, 1.0f));
    
    const float3 objectNormal = _Normals[_Triangles[vertexID + _StartIndex] + _BaseVertexIndex]; 
    normal = mul(_ObjectToWorldMatrices[instanceID], float4(objectNormal, 1.0f));

    uv = _UVs[instanceID];
}
#

If anyone knew what could be causing this I would appriciate the hlep

regal stag
chrome loom
#

Hello, I have a problem with trying to change vfx's property via code. I've sent some screenshots showing mentioned code, vfx and some other things that may or may not be connected to the issue. I'd be glad if You could provide help

regal stag
frail cloak
regal stag
chrome loom
rich tiger
#

I am logging shader variants in a build, and am seeing what I believe is the same shader varaints being uploaded multiple times:

1a) Uploaded shader variant to the GPU driver: Universal Render Pipeline/Lit, pass: ShadowCaster, stage: vertex, keywords <no keywords>
2a) Uploaded shader variant to the GPU driver: Universal Render Pipeline/Lit, pass: ShadowCaster, stage: fragment, keywords <no keywords>
1b) Uploaded shader variant to the GPU driver: Universal Render Pipeline/Lit, pass: ShadowCaster, stage: vertex, keywords <no keywords>
2b) Uploaded shader variant to the GPU driver: Universal Render Pipeline/Lit, pass: ShadowCaster, stage: fragment, keywords <no keywords>

^^these are the same exact variants, right? Or is it possible they just show up with the same text but are actually different variants?

I am using addressables, and I understand a potential issue is the duplication of shaders. However, I think I am doing things correctly to avoid this:

I have created a Shader Variant Collection with what I believe to be most of the shader variants used in my scene. That SVC is added into a separate addressable group along with all of the shader files it references (that can be added; some built in ones cannot be added). This includes the URP Lit shader. I am also warming up this shader variant collection before loading any of the other addressable assets that depend on these shaders. As far as I understand it, that is the correct approach when using shaders with addressables.

#

This is on Unity 6000.0.24f1

#

In an iOS build

#

Also, if this were just happening once it would be no big deal, but the LIT shader (plus some other shaders) appear to be duplicated 100's of times, to the point where it is crashing the app due to too much memory being used.

lethal summit
#

I'm pretty much done implementing a virtual texturing system, however I've been noticing my calculated mipmap levels seem very wrong:

#

I'm using this formula that I've found from multiple sources:

float CalcMipLevel(float2 uv_px) {
    float2 dx = ddx(uv_px);
    float2 dy = ddy(uv_px);
    float delta_sqr = max(dot(dx, dx), dot(dy, dy));
    return max(0, 0.5 * log2(delta_sqr));
}
// Usage in pixel shader:
uint2 virtual_texture_res = uint2(16384, 16384);
float mip = CalcMipLevel(normalized_uv * virtual_texture_res);

https://community.khronos.org/t/mipmap-level-calculation-using-dfdx-dfdy/67480/2
https://bgolus.medium.com/distinctive-derivative-differences-cce38d36797b

#

Each of those squares is a 256x256px texture. I was under the impression that the calculated mipmap level should keep the screenspace texel density relatively constant. But it clearly isn't, so no amount of mipmap bias will fix it.

Any help or insight would be greatly appreciated.

ebon moss
#

how do you convert a shader file into a shader include so that I can use it in shader graph?

warm pulsar
#

the extension should be .cginc

#

A .shader file is written in ShaderLab, which contains HLSL code

#

The shader include file should be only HLSL code

#

If you have a shader that includes a function you want to use, then you should just copy that function out into another file

warm pulsar
#

As you get towards the pole, ddy(uv_px) is going to get rather large (since the planet is curving away from you)

#

It goes to infinity as you approach the edge of the sphere

lethal summit
#

yeah but it still feels like the mips are too aggressively low res in the distance

#

I tried using min instead of max and its much better North-South, each tile is never larger than 256px which is ideal for me

warm pulsar
#

This might be where anisotropic filtering comes in

lethal summit
#

I think it is using anisotropic, but I guess given I'm implementing a virtual texture that magic doesn't quite automagically work

#

East-West feels like lowres mips come in too soon

warm pulsar
#

I'd modify the shader so that each pixel displays the derivative

#

might help you visualize what's going on

vestal hinge
grand jolt
#

If i have a lot of shader, should i manage gpu memory or unity does it automatically

kind juniper
grand jolt
kind juniper
wintry willow
#

I have a question about making a material with only certain parts transparent. I have a .png that I'm using as a texture atlas. when I apply my texture to a unlit/Transparent material. The parts of the mesh that are supposed to be transparent are, but, I can also see faces of my mesh through other faces that shouldnt be transparent. The Alphas from my png are correct for what I want to do so I dont really know whats going wrong.

kind juniper
kind juniper
wintry willow
kind juniper
wintry willow
kind juniper
wintry willow
#

there Isn't a selectable one in the menu I was talking about earlier. Can I just make a new one

kind juniper
rapid marsh
#

I'm trying to use a refractive glass material as a helmet in hdrp, and emissive materials aren't emissive through the glass, any fix?

smoky widget
#

Hi! Is there any way to use Occlusion Queries in Unity through the GPU?

I have GPU driven pipeline that I'm working on and I would like to perform occlusion culling into the vegetation without going through the CPU and one of the tools i found was the use of Occlusion Queries

low lichen
rich vine
#

Hi, im quite new to unity but very comfortable in blender, so im very familiar with 3D terms etc. Im trying to learn the shader system in unity. Can anyone recommend some tutorials for HDRP and how to "break" repeating tiles etc? 🙂

smoky widget
hushed silo
#
            {
                float4 positionOS : POSITION;           // Object space vertex position
                UNITY_VERTEX_INPUT_INSTANCE_ID          // Instance ID for GPU instancing
            };

            struct Varyings
            {
                float4 positionCS : SV_POSITION;        // Clip space position (for depth)
                float3 worldPos : TEXCOORD0;            // World position for circle checks
            };

            float4 frag(Varyings i) : SV_Target
            {
                // Calculate normalized depth centered around _CameraY
                float heightDifference = i.worldPos.y - _CameraY;
                float normalizedDepth = saturate(0.5 + heightDifference / _NormalizationRange);

                // Output the normalized depth in the red channel
                return float4(normalizedDepth, i.insideCircleValue, 0, 1);  // Red channel = normalized Y
            }```
hey so I have this shader that gives a normalised depth texture, which I'm using in a command buffer. However, when objects are on top of each other etc. it doesn't really work, I think because command buffer isn't really doing proper depth sorting etc. Is there a way to render all objects over each other and just take per pixels highest depth to combine them all together somehow?
vestal hinge
#

Hi all, I was wondering if anyone knew if their was an issue with RenderPrimative and shadows casting with the shader graph. I have converted my render primitive shader over to using shadergraph and enabled lighting to it, this can receive shadows cast by other objects (as shown in the screenshot with the cubiod gameobject) and also lighting is being correctly calculated based on light direction (faces facing away from the light source get darker). However, the render primitive mesh doesn't seem to be able to cast any shadows itself, my guess is that the depth of the material isn't being written somewhere so the light doesn't consider it an opaque object in the scene.

Does anyone have any experience with this?

#

This is the error, the cliff should cast a shadow in the same way as the cuboid

rough lotus
#

I have a collection of RenderTextures that I want to write to my ComputeShader. Can I just put the textures into an ComputeBuffer like I would any other type, or is there a dedicated thing that is designed to store multiple RenderTextures?

#

like how Texture2DArray is used with Texture2D

vestal hinge
# vestal hinge

Replying to myself here, I found the issues. RenderParams uses a different bool for casting shadows then the material. The shader was set up to do so but the render params wasn't so it couldn't rendender shadows.

All is good now!

rugged narwhal
#

trying to get a specular shader texture and by base colour looks like it had no opacity ( not plugged in the normal and specular map yet) but i dont know why my base colour is so faded

warm pulsar
#

Does it look more correct with a smoothness of 0?

#

I'm not used to the "specular workflow". I also don't quite understand how it differs from using metallicity, to be honest..

#

But it looks like the reflection of the skybox is overpowering the albedo

warm pulsar
#

Okay, what about just making the base color solid red?

#

Simplify it until it starts behaving properly, basically

rugged narwhal
warm pulsar
#

What happens as you adjust the "Specular Color" from gray to black?

rugged narwhal
#

i eneabled global volume settings and it seemed to be better

#

i think it might be a HDRP sky and volume issue

warm pulsar
#

Oh, I see

#

There was no light source

#

You only had the ambient light and reflection probe

#

Hence the skybox showing up so clearly

#

If you're using the HDRP, you might as well do normal physically based rendering instead using SpecularColor :p

rugged narwhal
#

im using HDRP and getting all this volume stuff set up is a pain in the chuff. its really hard to understand and i cant seem to find much videos on it surprisingly, i want to jsut deleate the sky and all the sky lighting since my scene is inside

warm pulsar
#

If you want an indoor scene with zero external light, set up your environment like this

rugged narwhal
warm pulsar
#

If you decide you want a little ambient light, you can switch to "Gradient Sky"

#

and then add a Gradient Sky component that's set to a solid color

#

Also, delete the directional light

#

You should wind up with a gray sky that doesn't actually provide any light.

rugged narwhal
warm pulsar
#

Click the camera dropdown in the top right of the scene view. Turn on "Overide Exposure" and adjust the slider until the scene looks lit up

#

What exposure value do you get?

#

If the scene only lights up with a very low exposure value, that means you're getting a tiny tiny tiny amount of light from something (maybe the clouds, idk). It will be irrelevant once you light up the scene normally

#

By default, the scene view camera can adjust to some wild exposure values (way beyond normal human vision)

rugged narwhal
warm pulsar
#

hm, okay, that's a very intense light

#

Did you bake lighting at any point?

rugged narwhal
#

no all i have is a scene with just a map model i made in blender

warm pulsar
#

you can go to the Lighting window and clear baked data if it exists

rugged narwhal
#

oh wow lol. there was a tone of baked lighting for no reason

#

now its dark

warm pulsar
#

that'll do it

#

you can also kill the volumetric clouds volume component

#

since you won't need those

rugged narwhal
#

i didnt realise i needed to add volumetri clouds to the global volume and then disable them to get rid of them, i though it it wasnt in the volume it wouldnt be active

#

not that it matter much but how would i get a pitch blacksky instead of grey?

warm pulsar
#

For the game camera, you can change its clear color

#

The default is "Environment", meaning that the color comes from the skybox

rugged narwhal
#

lol project crashed and i lost it all its not even in my projects anymore that was weird

warm pulsar
#

Actually -- I think that having a sky type of "None" already makes it black?

#

It just doesn't appear that way in the scene view

rugged narwhal
warm pulsar
#

presumably the project is still there, just not known about by the hub

rugged narwhal
rugged narwhal
warm pulsar
#

add the project to the unity hub

#

the hub will have lost track of the project if you moved or otherwise renamed it

rugged narwhal
#

got it back just have to redo the volumes

hushed silo
#

anyone know why this material isn't instancing? I thought you could change a float in a material property block and still instance

#

does shadergraph not support property instancing?

warm pulsar
#

I'm pretty sure I've done that...

regal stag
rich vine
#

Has anyone gotten any idea why my main preview dosnt work? I've tried unity 2022 as well, but the same issue still. Im using HDRP pipeline.
When I connect a texture its just white so dosnt work either PLEASE HELP!

hushed silo
hushed silo
latent rampart
#

If I wanted to make half of my model (and the models in it) semi-invisible, like if I'm doing a cross section, would a shader be the appropriate way to do that?

warm pulsar
#

well, a shader is how you do all rendering!

#

You could definitely write a shader that makes everything on one side of a plane half-opaque

latent rampart
#

Doesn't seem like a huge issue with that, but setting a material doesn't seem like a good way around it, because I would need half a model to be rendered normally and the other half transparent

warm pulsar
#

You could make a pretty simple thing in the Shader Graph that cuts the alpha for only part of the model

#

transparent rendering problems could get really nasty though

latent rampart
#

I could just make it not visible entirely

warm pulsar
#

A cutout shader that uses dithering would behave better

latent rampart
#

making it transparent is optional

warm pulsar
#

Oh yeah, in that case, it gets very simple

#

Imagine a shader that discards any pixels whose world position has a X value less than 0

#

the one issue is that you'll see holes in the model wherever this process happened to cut through a solid object

latent rampart
#

well it needs to cut through a solid object

warm pulsar
#

here's how it'd look on a cube

#

It behaves better when rendering double-sided

latent rampart
#

I would need double sided rendering

#

I'm guessing that's done on a per material basis

warm pulsar
#

Yeah, that's a property of the shader itself

#

It can skip back-faces (the default), front-faces, or neither

latent rampart
#

gotcha

warm pulsar
#

A dither effect can work pretty well

#

This is all in an HDRP project, but there's nothing special going on here

latent rampart
#

oh yeah, that works nicely too

#

thanks, I'll look up how to do it later, just wanted to get an idea of how simple it was.

fringe karma
#

Am I using InverseLerp incorrectly? I think my setup's correct in terms of what logic I want (it seems to work correctly), but I can't debug properly because the inverse lerps just produce the magenta effect that usually appears when you screw something up

#

or does inverse lerp just not work with non-float values?

#

maybe because it's outputting a vector3 the lerp nodes afterwards aren't receiving a proper input and that's potentially causing problems

#

actually since normal maps are directional, maybe instead I need some slerp-based functions instead of just lerping

#

I'm trying to compare four corner values (the top four) against the centre value (bottom) and figure out which values are the most different

#

I'm detecting differences in normals for an outline shader, and unlike a roberts cross this is capable of telling me whether the difference is more or less than the pixel currently being rendered

#

it works better with the depth check, but I don't think I've got it 100% right for the normals check

rugged narwhal
#

anyone know how i can fix this?

fringe karma
#

alright I partially fixed it by manually forcing the lerps to read the inputs as floats

fringe karma
fluid mauve
#

Help please. Same texture, same shader idea but lips conture look much worse. Why? What i do wrong? Or its because URP?

#

Its some kind of smoothing or else?

warm pulsar
fringe karma
#

I think I need to revert that change I made

#

to ensure that all the axes are lerped properly and that values aren't being ignored

ebon moss
sharp frost
#

I have created shader for leaf's for the mobile. But it look dark. How can is resolve it?

#

Or do I need to create double sided mesh?

kind juniper
sharp frost
#

Yes it's lit, so I need an unlit shader.

Do I need to create an unlit shader with a custom function node to achieve good results?

kind juniper
sharp frost
kind juniper
#

SSS?

sharp frost
#

Yes

kind juniper
#

Subsurface scattering you mean?

#

Subsurface scattering is a complex effect and is usually applied in high fidelity rendering(so it's definitely not an unlit shader).
And it's pretty heavy as well, so if you use it for all your trees you're probably gonna get a slide show.

sharp frost
#

oh! okay then I will stick with unlit shader. thanks you for all details.🙏

#

because I am creating this one for mobile.

karmic hatch
sharp frost
hushed silo
regal stag
hushed silo
#

I think this got it thanks 🙂

bleak vale
#

i think this has something to do with unity 6 reworking cameras since this doesnt work in the testing scene either

#

this is supposed to be pixellated

amber saffron
bleak vale
#

i do not know how to convert this to a urp shader

amber saffron
bleak vale
#

ok cool

amber saffron
#

Do you want to the B&W dither effect, or only need the pixelation effect ?

bleak vale
#

just pixellation

amber saffron
#

Well, you could do it without post then 😄

bleak vale
#

oh fr?

amber saffron
#

In you URP asset, you can reduce the screen percentage of rendering, and set interpolation to "none" for a pixelated upscale.

#

"Render Scale" and "Upscaling Filter : Nearest-Neighbor" here.

hollow harness
#

hi, here i have a simple geo shader, although i still don't understand them....is there a way to extrude out the triangles using a color mask, i mean, suppose i have a texture with a green circle, now if i want to extrude only the triangles of the plane which have fallen under the green zone, what should i do?

https://pastebin.com/pygQ3juX

amber saffron
hollow harness
amber saffron
wary tangle
#

I'm new to shaders and working through the Creative Core Pathway. I want to add my company's logo to a coffee mug but when I do that it also puts a mirror image on the other side. I tried resizing the image used for the base map, but it doesn't seem to make a difference as both images seem to start from the handle of the cup (as opposed to being a wrapping issue). The weirdest part to me is I even tried editing an image file that already displayed the unity logo as I wanted my logo to appear, I did a simple C&P, and it still caused the mirror image on the back of the mug after. I'm really at a loss, and if anybody could shed some light on the matter I'd appreciate it.

hollow yarrow
#

I'm just playing around with Unity and wrapping my head around materials and textures.

I've managed to apply a texture to a material and then apply that to some 3D objects.

I'm unsure why but I can't seem to apply it to the plane, it's just pure white?

warm pulsar
#

You could test this by using a shader that displays the UV coordinates

warm pulsar
#

This is blowing out all of the details

hollow yarrow
#

Is it super bright by default?

warm pulsar
#

notice how the lit areas are pure white on this capsule

#

You're using the HDRP, so it used physically-accurate lighting. The sun is set to like... 100k lux by default

#

This is fine if the camera is exposing correctly

hollow yarrow
#

Yeah I used HDRP then removed it because it was complicating the texture/material learning.

#

lol ye

warm pulsar
#

Okay, so your sun is still configured for 100,000 lux illumination. You don't want anything nearly that strong for non-HDRP rendering

hollow yarrow
#

What would you recommend for a realistic environment? Outdoors?

warm pulsar
#

Try 1 or something

#

Other render pipelines do not use physically accurate lighting, so the units are very arbitrary

hollow yarrow
#

What's the difference between HDRP and standard? I assumed the HDRP was hyper HD or something

warm pulsar
#

The high-definition render pipeline is an alterantive way to render your game, along with the universal render pipeline

#

Both of these are replacements for the built-in render pipeline -- which is what Unity has used for a long time

#

They're both "scriptable" -- you get a lot of control over the rendering process, and it's easy to add new renderer features

#

HDRP is good for high-fidelity graphics on modern PCs and high-end consoles

#

URP is used to cover a much wider range of hardware, including mobile devices

hollow yarrow
#

I don't know what I'm making yet but assuming I'm a beginner trying to make something you can walk around in like Skyrim

warm pulsar
#

URP is my default choice

#

If you are following a tutorial, use whatever it calls for

hollow yarrow
#

Where do I set this, on the scene?

warm pulsar
#

It's easiest to just create a project with the 3D URP template

#

You can install the URP package and then plug in a few assets manually

#

but if you haven't really done anything yet, I'd just use the proper template

hollow yarrow
#

I created it using the 3D HDRP and then cleared all the stuff away that I needed

warm pulsar
#

I've done that before

#

I swapped a game jam project from HDRP to URP because we realized we were using literally no features of the HD pipeline

hollow yarrow
#

So I'd have to add the folders/files back

#

To get the URP stuff

#

It's not a setting or something within the scene or lighting

warm pulsar
#

It's part of the project settings

#

You can actually use multiple render pipelines in the same game -- you'd just assign different "render pipeline assets" to different quality levels

#

the asset contains all of the configuration needed to use the pipeline

#

I've never done that before, but it's...possible!

hollow yarrow
#

Nothing here for me?

#

How do you set a texture size, I can't see a "tiling" option on the plane itself (only the material but I don't want to change this)

wary tangle
warm pulsar
#

Huh. So it shouldn't be mirroring at all

#

And your UV tiling+offset settings are the default values

#

Oh -- I bet that's the inside of the mug

wary tangle
#

Probably, but the image I started with and the image after editing accounts for the inside or whatever that is.

#

See my confusion?

sonic nacelle
#

I've decided to use Default RP because it's much easier to add a material to the camera. Should I be using urp instead and just try to figure out how to get a material on the camera there? I also remember shadergraph materials bugging out on ui with urp so I would have to use shaderlab anyway

warm pulsar
#

"add a material to the camera"?

#

i don't understand what that means

warm pulsar
#

So both the front and back share the same UVs

wary tangle
warm pulsar
#

You would need to redo the model's UV map

#

Right now, the front and back faces look at the same place on the texture

wary tangle
warm pulsar
#

It wouldn't change! So that's odd.

sonic nacelle
warm pulsar
#

In the URP, you can do this with a FullScreenPass renderer feature

#

It works with the Shader Graph

warm pulsar
#

I forget exactly when that changed. I remember that I used to be unable to use it properly.

sonic nacelle
#

Ok cool I guess I’ll move to that then

untold forge
#

Im having an issue where im using a toon shader with custom lighting node in hlsl, but the direction light cookie is barely doing any effect... any way i can make it stronger?

untold forge
#

Aaah the darkness is based off of the alpha value

#

Its good to read the documentation sometimes 🦧

hushed silo
#

I have these meshes that join in my terrain, and the meshes calculate normals by angle. In order to get rid of seams I extruded the mesh down. you can see that the normals themsleves work against each other, however, I have a steepness effect which is in the vertex stage, and used to lerp different textures on

#

anyone see what's going on?

hushed silo
warm pulsar
#

(btw, there's a Remap node that might be simpler here)

#

Perhaps you can display the normal vector directly on the surface? That'll help visualize what's going on

hazy rock
#

hlo all, relative shadergraph newbie here. experienced swe, contributed to a (never finished) digital conversion of one of my tt titles once, have played with mapmagic2 and another proc terrain generator whose name escapes me. mm2 doesnt work on macos (which i now live on) and so im trying to roll my own shadergraph-based proc terrain generator. any tips on blags or vids that are good starters?

#

i grabbed the free asset eden shadergraphtoterrain or whatever its called, and i am perplexed that the sample graph does what it does, but the shadergraphs i create for the purpose don't seem to be acheiving the same quality results

#

eden sample shadergraph:

#

eden sample shadergraph output:

#

my shadergraph:

#

my output:

#

i was hoping i could slap down a bunch of voroni noises at diff scales and then a cone and get an island shape

obsidian heath
kind juniper
kind juniper
# hazy rock eden sample shadergraph:

Well, how are they using this shader? It doesn't seem like it's displacing any vertices, so they probably use it to generate the height map, that they then plug into the terrain component. This would require some setting up and/or additional C# code. Are you doing the same thing they do?

hazy rock
#

well i think i figured out my f-up -- my shader wasnt a custom material shader? i built a new one of that type and now everything is working like i expected 🤦‍♂️

#

this happens to me more frequently than not -- i ask for help on a discord, and in the process of asking the q, i start thinking of what kinds of things i would ask if i actually knew the subject and was trying to figure out what this idiot (me) was doing wrong 😆

hazy rock
#

helll yeahhhhhhs

hollow harness
#

does geometry shader support lightprobes?

hollow harness
#

does opengl 3.1 on mobile support tesselation?

warped linden
#

Hi everyone, I'd like to ask for some help
I have an object that appears everywhere in the scene
I made a fade effect from the lower right corner

But I want the objects everywhere to have a consistent fade-out amplitude

#

here is my node
I can't use texture cuz it wiil be rotate
I need the same effect from screen

kind juniper
warped linden
kind juniper
#

Not according to that screenshot with X and check.

#

According to that screenshot the way you want it has nothing to do with screen space.

warped linden
#

I try object position too,
but I want to align screen right corner in any rotation

#

so I'm researching how to combine these two

  1. align screen right bottom corner
  2. calculate by every object position
kind juniper
#

I'm not sure what you mean by "align screen right corner".

#

Do you want the effect to disregard object rotation or something?

warped linden
#

like this

#

No matter how the object rotates or wherever it goes
the gradient will always align to screen right corner

#

it's not a shadow. the gradient will cover on it

kind juniper
#

Maybe get the screen space position relative to the object center

warped linden
#

Do you have any ideas for which node I should use?

kind juniper
grim heron
#

Hello everyone. I am trying to build on a grass terrain for VR and following procedural rendering and compute shader tutorial from Daniel Ilett.
The code from the tutorial is converted to Unity 2019.1;
https://youtu.be/uHDmqfdVkak?si=wwiCxuFgZx85ym2C

I attached the convert script on the plane imported from Blender, the code is running now while there is nothing generated on the game environment.

Is there anything i should be aware of? or is there any alternatives or reference I can look in to for producing grass?

Ever wanted to add grass to your game? There are many ways of implementing grass in Unity, and while one technique could be great at one thing, it might suck at another. In this video, I'll go over six grass rendering methods and explore what makes each one great in certain situations.
Made with Unity 2021.3.0f1 and URP 12.1.6.

👇 Do...

▶ Play video
junior dune
#

i did get the intuition behind how dot products gives the shading , but i dont get why are we multiplying light color and not adding

kind juniper
# junior dune

Because you want to calculate the intensity of the light based on it's angle. There's nothing to add in here. light color + light intensity wouldn't make any sense.

junior dune
#

thanks a lot

kind juniper
#

But yes, you got it.

hushed silo
rough quest
#

hi, I have a game i developed a while ago, and now i re-booted it by finding my old package file. however, everything is purple. i can't figure out why or how to fix it. this project is around 2-3 years old.

If i try to change the shaders, something happens, but not quite really fixes the issue

#

here's an example of trying to use another shader.

honestly i have no idea if its an issue with shaders or what, i have not used unity for years, and i'd like to fix this if possible, it was a cool little game

#

any help is really appreciated

hushed silo
#

looks like they are using legacy shaders. are you using the same render pipeline as it was set up in?

rough quest
#

i haven't done unity in years

hushed silo
#

ok so if you are importing a package there's a good chance that you don't have all the original project settings and this is messing up your shaders

#

ie you could have started a project in urp and then imported a game that's not urp into it

rough quest
#

okay, and if the project exists in unity cloud, can i somehow import it?

#

i don't see any options to download it/import it, but its there

mossy merlin
#

Is it possible to use shader in the same Sprite like the picture I sent you to make 2 luminescence?
I want the sign to be a little light-emitting and the writing on the sign to be light-emitting.

rare wren
mossy merlin
rare wren
mossy merlin
#

Aha, then I'll have to do two! Thank you for your answer !!

hollow harness
#

I have a geometry shader where there is something hull and domain...when I keep it normal, in build(for android) the shader returns pink...but when I comment out those 2 lines(hull and domain), the shader works fine, but the Tessellation is gone by this way...any fix about this?

warm pulsar
#

Gimme a ping later

#

Can you get a screenshot of the Graphics in the Project Settings window, as well as a screenshot of a broken material’s inspector?

rough quest
#

i was lucky enough to have a backup from the project back at home so i just asked somoene to upload it, and it works

#

had to install an older editor for it to work, that might have been the reason it broke, dunno

warm pulsar
#

Ah, excellent (:

#

It looks like the project is using very old shaders. Modern versions of Unity might not include those anymore

gloomy gust
#

How can I make an effect like this in game? (big blocky outlines)

#

i made these effects in photoshop but i think it would be a cool effect in the game

lone bison
#

I get these weird lines in my project, seems to be caused by mipmaps. The world map is split into 2x4 pieces, combined into a Texture2DArray which is then used in a shader graph shader. I already tried:

  • Changing a lot of import settings
  • clamping the UVs
  • crying
low lichen
lone bison
low lichen
lone bison
#

yes the lines dissapear when turning off generate midmaps

low lichen
lone bison
low lichen
# lone bison The texture array itself does not generate midmaps it seems to reuse the midmaps...

I believe this answer points to the problem, though it doesn't give a solution that can be done in Shader Graph.
https://stackoverflow.com/questions/14765517/how-to-eliminate-texture-seams-from-mipmapping

#

Essentially, the problem is that the GPU is trying to estimate which mip level to sample from by comparing the difference in UV values in neigboring pixels. When it compares pixels that are on the border between textures, the calculated UV suddenly jumps massively, so it ends up using the smallest mip, which is probably a light gray color.

#

The values you'd want to pass in there should be DDX and DDY of the original, unmodified UV, but first scaled to match the scaling of the tiled UVs.

low lichen
#

I assume the original UV is scaled up to make each tile texture smaller on the sphere. That scale should also be applied to the UV before it gets passed into DDX and DDY.

#

Otherwise, the GPU will use too high resolution mip level.

lone bison
#

wow so 3/4 lines disappeared but one remains

#
void calculateTextureIndexAndUV_float(float2 uv, out float textureIndex, out float2 newUV, out float2 ddxF, out float2 ddyF)
{
    const int columns = 4;
    const int rows = 2;
    
    float columnF = uv.x * columns;
    float rowF = (1.0 - uv.y) * rows;
    
    int column = (int)floor(columnF);
    int row = (int)floor(rowF);
    
    column = clamp(column, 0, columns - 1);
    row = clamp(row, 0, rows - 1);

    textureIndex = floor(row * columns + column);

    newUV = float2(columnF, 1.0 - rowF);
    
    ddxF = ddx(newUV);
    ddyF = ddy(newUV);
    
    newUV = frac(newUV);
}
low lichen
lone bison
low lichen
#

It seems the most common solution is to hide the seam by having the mesh vertices match where it is.

#

By having the mesh split where the seam is, it means there won't be any triangles that cross that border, and since the GPU only processes pixels together that belong to the same triangle, it won't end up with two neighboring pixels with vastly different UVs.

#

But if you want to use this workaround, you have to rely on the UVs of the mesh and not the value you calculate from the Position.

lone bison
low lichen
regal stag
#

Would calculating ddxF/ddyF with abs(newUV - 0.5) also work? Not sure off the top of my head

lone bison
low lichen
low lichen
lone bison
#

oh wow, it does work

warm moss
#

Though for some reason the fix proposed in the article doesn't really work for my terrain shader.

atomic elm
#

Hi, I'm trying to overlay a texture in Shadergraph using the Blend node. For the overlay texture, I'm using its R channel as its alpha. Is there a way I can change its alpha clipping value? I know you can set the base texture's alpha clipping using the Alpha Clipping Threshold in the main graph, but is there a way to do that separately as well?

tiny flower
#

Material 'M_General_Wall_Plaster_DarkBlue (Instance)' with Shader 'Shader Graphs/S_General' doesn't have a texture property '_MainTex'
UnityEngine.Material:get_mainTexture (). How can i fix this error I keep getting, i assumed it was in the shader graph?

eager folio
warm pulsar
#

(or don't try to access the mainTexture property on your material)

limber pebble
#

How can I make a shader that flattens the model based on the camera direction?

I want to make an effect similar to "Mr. Game and Watch" in Smash

kind juniper
#

That is assuming there are no issues with your shader.

hollow harness
warm pulsar
#

oops, that's not a real variable

#

there we go

#

If you're using the shader graph, then it'll look significantly simpler, too :p

#

You're moving the vertices to the center of the stage, removing the part that lines up with the camera's forward vector, and then moving them back to where they started

austere pier
#

If you notice there about about 3 ish different effects; the horizontal flickering you see first, the scanline flickering you see second, and lastly that horizontal line that runs down the screen

lament karma
#

maybe some color distortion too, like saturation change.

austere pier
#

Stacking with random intervals?

static leaf
#

What's a good way to to make conditional changes to a shader in the shader graph at run-time?
I think I can utilize a branch node some sort but I am trying to highlight specific cells for my shader rendered grid during certain game events. Like when a player moves, selects, casts ability, etc.
Then I planned on making a MB script to handle the shader updates based on those specific game actions.

gloomy gust
static leaf
#

@gloomy gust The outline coloring? I think you want "Inverted Hull Outlines". Check out #1 on this shader video.
https://www.youtube.com/watch?v=vje0x1BNpp8&ab_channel=DanielIlett

It's time for not just one shader, but 10! In this video, you'll learn about 10 different shader effects, what they are useful for, and how to make them in Shader Graph!

👇 Download the project on GitHub: https://github.com/daniel-ilett/10-shaders
💖 Huge thanks to my Patreon supporters for March 2022, especially: Jeremy Gooch, Morrie...

▶ Play video
dapper arrow
#

the frame debugger shows batch cause as different materials which defo isnt true

echo moatBOT
kind juniper
dapper arrow
#

yuh

kind juniper
# dapper arrow

Can you expand the keywords section and take a screenshot with comparison?

dapper arrow
#

Aight

kind juniper
# dapper arrow

Hmm... Seems to be the same. Can you take a screenshot of the object inspectors? With the renderer and the material visible.

gloomy gust
static leaf
tacit parcel
dapper arrow
#

gpu instancing gives up if the shader has multiple passes. That's the reason I created 2 different mats and shaders. The Mask shader draws nothing. Its just for stencil

kind juniper
dapper arrow
#

oh

kind juniper
dapper arrow
#

Mhm

#

Srp batcher is disabled too

kind juniper
#

I'd go through all the info in the frame debugger and make sure that there are no differences whatsoever

dapper arrow
#

I'll dig into it more

#

I have another unlit billboard shader and instancing seems to work right for it

#

I tried to check if it does something different with the GPU instancing setup
But everything was more or less the same

kind juniper
#

Maybe something with the mesh settings🤔

sharp frost
dapper arrow
dapper arrow
dapper arrow
cosmic thorn
#

Ive made a destruction shader using a bunch of unity stuff, and while it itself is performant, the way i add more is by applying paint, to a mask texture, but this is done with the CPU which is also the most performance heavy task in the entire thing, so i was wondering if it would be worth offloading the painting process to GPU if the texture res is just about 64x64

amber saffron
gloomy gust
dapper arrow
cosmic thorn
dapper arrow
#

Fixed it

sharp frost
sharp frost
#

So SRP will not work in that case, right?

dapper arrow
#

In my case I had two transparent materials on the same object with same render queue that is the default 3000 which was messing up instancing
Now one of the two shaders have queue 3001 and it seems to work as expected

dapper arrow
#

Until your shader is handwritten

kind juniper
#

Oh, wait, it's different materials

sharp frost
kind juniper
#

My guess is that it has to render one object with mat1 and mat2 before rendering any other object to preserve the correct rendering order, and thus it can't batch/instance objects in this case.

dapper arrow
dapper arrow
kind juniper
# dapper arrow

Yeah, now that I look at that frame debugger screenshot it looks like that's what's happening

dapper arrow
kind juniper
#

You see that there are 2 draw calls for one object first.

dapper arrow
dapper arrow
kind juniper
dapper arrow
#

Yuh, that's exactly what I am doing now

kind juniper
#

Mystery solved I guess

dapper arrow
#

Yep

#

Although 😅

#

There's another issue that I needa tackle now

#

If you could help

sharp frost
#

One question:
If I have 2 boxes and both have the same material and mesh but the light maps are different will SRP Bathing work?

dapper arrow
#

Srp batcher only cares about the shader you're using ig

sharp frost
dapper arrow
#

I have two overlapping cubes in the middle

#

And they only seem to draw over each other when both shaders have the same render queue

kind juniper
dapper arrow
kind juniper
dapper arrow
#

The question is why is this happening
If the mask is on a different render queue, wouldn't it still write 1 everywhere
And wouldn't the other shader still check for stencil equals 1

#

Just want to know the reason that's happening

kind juniper
#

You should look at the frame debugger to figure it out.

dapper arrow
#

Mhm, alright

#

Thanks 🙂

kind juniper
# dapper arrow

I can also spot an error popping in your video. Seems to be related to rendering too(d3d11)

#

Could be relevant

dapper arrow
#

Oh, those are just some old broken shaders

#

I have to clean the project up

#

I found the reason

#

It's just this

#

I'll read the solutions in there
Hope something works

steel notch
#

How do I get the equivalent of Unreal's Scene Texture: Custom Depth node in Unity?

#

I want to do some depth culling in a transparent shader.

civic lantern
#

Jesus I can't even find docs for that node on the first page when searching this

steel notch
#

It's this.

#

From what I understand, this requires a custom depth buffer.

#

And the shader only compares against that.

#

And you can here.

regal stag
steel notch
#

Is there any way to do this in Unity URP?

#

Surely shaders can write to custom textures and then read from them at later points, no?

meager sentinel
#

so if I'm using Sprite Custom Lit my preview turns black (I guess preview just doesn't know anything about _ShapeLightTextureX and can't sample light textures)
is there anything I can do about it or now I have to customize previews and provide global lighting?

the problem is that even prefab viewing in context is broken

#

sometimes i wonder if developers even tries their own features
the whole 2d renderer feels like proof of concept with half-baked features

who decided that global lighting fallback has to be black?

hushed cairn
#

i'm probably being really silly but i have an issue where if i make changes to my camera shader in the inspector, they automatically reset when i go into play mode? no idea why

warm pulsar
#

"camera shader"?

warm pulsar
hushed cairn
crisp vale
#

looking to create an RGB mask shader for a large asset im making. I need to add dirt/leaks etc. to the large asset and I need it to be driven by masks. Any resources on how to do this? I know how to do it in Unreal, but not sure how similar it is using the Unity Shader Graph

kind juniper
gloomy gust
#

How can i make a portal effect here?

#

should i use a shader on this texture, or use a vfx system

warm pulsar
#

I'd want a shader that makes the texture a little wobbly

#

and then have particles coming out of the portal

gloomy gust
warm pulsar
#

So, you normally do this

#
fixed4 color = tex2D(_MainTex, i.uv);

you sample a texture using the interpolated UV coordinate at the pixel you're rendering

#

that was a five-dollar sentence right there

#

you use the UV map to sample the texture

#

But what if you distort the UV values?

#
fixed4 color = tex2D(_MainTex, i.uv + sin(i.uv.x));
#

This would cause the UV coordinate you use to get...distorted

#

it gets pushed around

#

if you included time in that formula, it would get distorted over time

#

(are you doing shader graphs here?)

#

i just spent all day writing HLSL and i'm cooked

gloomy gust
#

im no good at shader writing

warm pulsar
#

okay, so you'll want to use the Tiling & Offset node

#

you can start by just plugging UV0 into its input and then doing nothing else

#

next, consider a constant offset

#

And then, a variable offset!

#

It might help to look at the actual effect of the distortion on the UV coordinates. This is showing the difference between:

  • The original UV coordinate
  • The distorted UV coordinate

for a very distorted image (too distorted, even!)

I made it so that negative differences are green and positive differences are red

#

The distorted UVs move faster than the originals for a bit, then slower, then faster, etc.

#

this squishes the image (where the distorted UVs are ahead of where they should be) and stretches the image (where they're behind where they should be)

#

the distortion is strong enough that it actually goes backwards several times

#

that middle column sure is weird looking

gloomy gust
#

how can i make this more of a rounded square instead of a circle?

gloomy gust
#

why is it not transparent? it's like a weird red color lol

warm pulsar
#

I'm guessing you're finding the distance from the center

amber saffron
karmic hatch
stray orchid
#

how can i add normal maps to each texture?

amber saffron
# stray orchid how can i add normal maps to each texture?
  1. Change the shadergraph target type to a lit shader, this seems to be an "unlit".
  2. Don't use "normal from texture" with normal maps, but use "SAmple Texture 2D" with "Type" set to "Normal".
  3. Blend the normals the same way you blend the colors, and plug into the "Normal" output of the fragment stage.
stray orchid
#

holy smokes it all works thank u so much

dusky arrow
#

What does "Ztest Off" do? Is it even valid?

smoky widget
#

is there any way to check if a subgraph is being used at all in the project? Want to do some cleaning but im not sure if certain subgraphs are being used and i have too many shaders to go one by one

warm moss
harsh marsh
#

Trying to write a billboard shader for instanced meshes in URP (using code because it seems all hacks for getting InstanceID working w/ shader graph only works for directX) but it doesn't work on instanced geometry (if I apply the material to a normal object it works fine aslong as there's no instanced geometry in scene)

#

My vertex shader:

float3 grassWS = mul(positionBuffer[instanceID].TRS, IN.positionOS).xyz;
OUT.positionHCS = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(grassWS, 1.0)) + float4(IN.positionOS.x, IN.positionOS.y, 0.0, 0.0));
#

positionBuffer[instanceID].TRS is a 4x4 matrix

warm moss
# dusky arrow What does "Ztest Off" do? Is it even valid?

ZTest is used to specify z testing - how you want the shader to test its depth against the depth buffer to decide whether to render a pixel. So ZTest LEqual would mean "only draw when the depth is less than or equal to the depth value in the depth buffer". Usually to turn off depth testing, ZTest Always is used. Perhaps this option used to be called ZTest Off in the past and you encountered a very old shader.

harsh marsh
amber saffron
warm moss
#

Fair enough 😆

warm pulsar
#

an alpha of -1 will cause Blend SrcAlpha OneMinusSrcAlpha to do...very weird stuff!

#

-1 times your color plus 2 times the exisitng color

warm pulsar
#

Always, False, and Off all produce the same results for me

#

(no z-testing)

hollow harness
#

what are the built in variables in Input of a surface shader?

gloomy gust
#

How can i make the transition between the portal and the wall less jarring?

#

looks pretty out of place lol

kind juniper
gloomy gust
kind juniper
gloomy gust
kind juniper
#

Then it's probably 0-1. You can test it out. If not, then you could remap the object(pixel) position instead.

gloomy gust
kind juniper
#

It's mostly just simple math. You could probably ask chat gpt or something for an example.

gloomy gust
#

not entirely sure if i've done this right lol

kind juniper
#

Get the math down first. It will be easier to get a correct answer and confirm it on paper. You can worry about nodes later.

gloomy gust
#

i think i've achieved my desired effect here!

gloomy gust
#

why wont it let me conect these two?

#

are they not of the same type?

kind juniper
gloomy gust
#

sorry i know the text is probably illegible 😅

#

how can i make this useable for the vertex stage?

kind juniper
#

Yeah. Can't see shit.

gloomy gust
kind juniper
#

Ah, it's mostly math. So it's probably normal from height that is only for pixel shader.

gloomy gust
#

curiously enough i can just do this

#

but i imagine this doesnt work. the preview has become invisible

kind juniper
#

You can, but does it do what you expect?

#

Figures

gloomy gust
kind juniper
#

What are you planning to achieve anyway by plugging normals into vertex positions?

gloomy gust
#

well i wanted to make a ripply effect for my portal

#

but instead of like making the texcture ripple i wanted the actual shape to ripple

civic lantern
#

What is the geometry of the portal? Is it a flat plane?

kind juniper
#
  1. You'll need to modify vertex positions.
  2. You'll need enough vertices in the mesh for the effect to look decent.
gloomy gust
kind juniper
#

If it's the default plane mesh, I think it only has like 10 x 10 (or 11?) vertices, so it's gonna look very blocky.

civic lantern
#

Yeah I would go with something like this

#

Obviously with denser geometry if needed

civic lantern
gloomy gust
#

i found a tutorial. i'll try and follow that

#

i assumed i was working with a single quad plane

#

idk why

kind juniper
#

Get the delta of the position from object center and use it in a sine node or something. Then add the result to the z position.

kind juniper
#

To be honest, that's probably gonna be more then enough, given the context. You can't really notice that the geometry doesn't change in your scenario.

crisp vale
#

trying to set up a vertex blend shader for meshes. I have created this shader and I installed Polybrush, yet when I go to "paint vertex colors on meshes" it doesnt do anything. completely lost here. am I missing something?

worn hatch
#

why is it that when i make this simple white metal material fully rough it's not fully white and when i make it fully smooth its black?
I assume it's a general scene lighting issue but I'm not sure what I'm supposed to be doing here.

#

oh, if i turn off environment reflections it looks much better hm

prime shale
#

I know you already solved this but you need reflection probes (or the skybox environment fallback reflections) because without any then there is nothing to reflect, so when you make a material very reflective and metallic it will just appear black

sinful copper
#

Am I missing something with this? If I rotate the main light at all it doesn't seem like anything is actually changing (note if I use a custom vec3 param in place of this the lighting does work). This is with URP Unity 6.

#

note I've also tried it with the built in main light direction and that doesn't work either.

vague pilot
#

Hey i am attempting to create a raymarching shader and im having trouble with depth comparision when the raymarched sphere approaches the screen borders sth weird happens with depth comparision (img) https://pastebin.com/VJgch66z i dont understand why this is happening tbh would appreciate your help

kind juniper
crisp vale
kind juniper
kind juniper
#

Or documentation

hollow harness
#

what is the cheapest possible way to have a shader write to depth?

kind juniper
hollow harness