#archived-shaders

1 messages · Page 93 of 1

kind juniper
#

Who "they"?

hollow harness
#

Im took a vertex lit shader from library, Im using a decal shader on it , it works fine untill Im removing he shadow caster pass from the vertex lit shader

#

when shadowcaster pass is inside

#

after removing the shadoiw caster pass from the shader

#

the decal is not falling the cube , because the shader of the cube isnt writing to the depth now after removing the shadow caster pass

kind juniper
#

Ok, so it needs to be a decal? Because that's already no the "cheapest way to write to depth".

hollow harness
#

But i dont need that pass, I want a single pass shader for my mobile project

kind juniper
#

Not to mention, that having it "lit" makes it a lot more heavier. You don't need it to be lit to write to the depth buffer.

#

I'm also not sure how writing depth and decals are related.
Maybe add some more context to your question.

hollow harness
#

this the shader for that cube

hollow harness
#

later I found that it is because the shader of the scene objects isnt writing to depth

kind juniper
hollow harness
#

yes

kind juniper
hollow harness
#

when Im using a regular diffuse shader or vertex lit shader that has shadow caster pass, the decal is working on the cube

kind juniper
#

Changte z write to ZWrite On

hollow harness
hollow harness
kind juniper
#

The shadow pass probably writes to depth by default, regardless of the keyword

hollow harness
#

yes

#

you are write

kind juniper
#

But that adds one extra draw call

hollow harness
#

But dont want that pass in my shader

kind juniper
#

Well, then remove it lol

hollow harness
#

otherwise I will get double number of setpass call which will degrade performance

hollow harness
#

and now

#

decal isnt working

kind juniper
#

And set Zwrite to On

hollow harness
#

tada

kind juniper
hollow harness
#

owh

#

srry

#

set that on

#

still decal not working now

#

even if I remove that keyword

kind juniper
#

Okay. Then a few things to check:

  • What render path are you using? Deferred or forward?
  • Does the cube render before the decal?
hollow harness
#

forward rp

#

render queue of the cube is 2000 while the decal object is 2601

kind juniper
#

Hmm. Okay. Might want to look at the frame debugger then.

hollow harness
#

after increasing the render queue of the cube more than decal's one

kind juniper
#

Well, that's not gonna work obviously.

hollow harness
#

Idk what should I do now

#

here Im stuck

kind juniper
#

I told you: investigate in the frame debugger.

hollow harness
#

what is with it?

kind juniper
#

You can see the order of the draw calls as well as whether they write to the debth buffer. You might even be able to see the depth data at different stages.

hollow harness
#

when shadow caster pass is enabled

#

when disabled

hollow harness
#

I was trying to find an alternative

kind juniper
#

It seem like both write to depth buffer though. I wonder if the decal shader needs some extra info

hollow harness
#

without shadowcaster pass

#

this new thing appaers

kind juniper
#

Ah I see. It seems like this writes to the depth texture.

#

I wonder if it's because of forward+ path

#

Can you change it to regular forward

hollow harness
#

yeah forward use depth prepass

kind juniper
#

regular forward does not

hollow harness
kind juniper
#

Yes, that

hollow harness
#

I was using forward rendering from the beginning

kind juniper
#

Hmm... I thought it was forward+

hollow harness
#

when using deffered, the decal is invisble even with the shadow caster pass

#

when using legacy vertex lit rendering path , the decal works as it was working with forward rendering path

#

but both needs shadow caster pass on the cube

#

without that , even if I put Zwrite On, the decal doesnt show up anymore on the cube

#

meanwhile the shadow caster pass :

#

though Im not ready to have draw calls in my game becomes double

kind juniper
#

Might need to have a look at how the decal shader works.

#

Perhaps it uses the same mechanisms that shadows do in unity.

hollow harness
#

I have to find some alternative decal solution then which works with builtin pipeline

kind juniper
hollow harness
#

hmm I have to test the performance on mobile then

kind juniper
#

Did you actually have a performance issue in the first place?

hollow harness
#

actually I already have more than 50 setpass call

#

as far I know ,I have to keep that very limited , like below 30

#

performance is not that bad , on samsung a10, I get more than 40 fps

#

using shadow caster pass will make it double , like 100 set pass call, which doesnt look good anyway

kind juniper
#

This is very vague. While setpass calls count has impact, it's not the only factor

#

You should use the profiler to see if you're gpu or cpu bound and what the bottleneck is

hollow harness
#

yeah , But I wonder if there would be any alternative solution without the shadowcaster

kind juniper
#

As I said, you'd need to learn how your decal shader works.

hollow harness
#

here is the decal shader I found

kind juniper
#

It seems to be using the camera depth texture.
So you'll need to figure out how to make your cube shader write to the same depth texture.

hollow harness
#

how should I do it?

kind juniper
#

Hmm... It seems like the shadow caster pass is exactly what renders to it

hollow harness
#

so, there is no other way except shadow caster pass?

kind juniper
#

Seems like it

vague pilot
#

Hey im trying to implement depth testing in my raymarching shader and i dont really know what to compare so ive got the distance from the raymarch hit point to the camera but what depth needs to be compared to it is it the linear eye depth? (which is what ive done but doesnt seem to be what i need)

vague pilot
#

i solved it this way now but if there would be another option to do that i would appreciate it becuase this looks like very expensive calcs

zinc verge
#

made a cell shader in blender and now my materials arent importing

heavy summit
#

some things are not showing through this shader of the waterfall. the waterfall has a shader set to transparent settings

#

are there some things i could check to troubleshoot? i am new to unity

#

oh i see, i didnt use the alpha channel and only changed opacity, now something seems to be working at least

quartz slate
#

I would like some help for my shader graph. I would like to make my gradient noise seamless. is there any ways to make it mirroring in the middle?

grand jolt
#

Hi, I've been following a tutorial for writing shaders in URP but once i add blinn-phong lighting method, I only get a black color in result, I think this is because of the difference in versions of unity since im using unity 6, And the tutorial uses 2021.

I tried researching if there were any changes on the method but i couldn't find much other than another person asking a similar question to mine, Is there something i need to change/add in order for it to work?

struct Attributes {
    float3 positionOS : SV_POSITION; // Vertex Position Object Space
    float3 normalOS : NORMAL;
    float2 uv : TEXCOORD0;
};

struct Interpolators {
    float4 positionCS : SV_POSITION;
    
    float2 uv : TEXCOORD0;
    float3 normalWS : TEXCOORD1;
};

Interpolators Vertex(Attributes input) { 
    Interpolators output;

    VertexPositionInputs posnInputs = GetVertexPositionInputs(input.positionOS);
    VertexNormalInputs normInputs = GetVertexNormalInputs(input.normalOS);

    output.positionCS = posnInputs.positionCS;
    output.uv = TRANSFORM_TEX(input.uv, _ColorMap);
    output.normalWS = normInputs.normalWS;

    return output;
}

float4 Fragment(Interpolators input) : SV_TARGET {
    float4 colorSample = float4(1, 1, 1, 1); //SAMPLE_TEXTURE2D(_ColorMap, sampler_ColorMap, input.uv);
    
    InputData lightingInput = (InputData)0;
    lightingInput.normalWS = input.normalWS;

    SurfaceData surfaceInput = (SurfaceData)0;
    surfaceInput.albedo = colorSample.rgb * _ColorTint.rgb;
    surfaceInput.alpha = colorSample.a * _ColorTint.a;
    
    return UniversalFragmentBlinnPhong(lightingInput, surfaceInput);
}
worn hatch
#

why is it acting like its smooth even though i put smoothness to 0?
Whenever i remove the normal connection into the fragment the issue goes away but i'm not sure what im doing wrong here

kind juniper
kind juniper
rough lotus
oak aspen
#

Does anyone know if using canvas shaders in unity 6 forces a UI redraw? Say I have an effect going on a few buttons continuously, would that be redrawing the ui constantly? I'm asking because Unity (in the docs) makes it a point that you can do animated backgrounds etc.

kind juniper
oak aspen
random rose
#

Hey guys. can someone please help me with shaders. ive got an asset from the asset store but initially everything was pink. i've followed the process to convert the materials to URP and set all of the shaders to URP - Lit but everything has gone from magenta to white.

kind juniper
primal hatch
lost wasp
#

apologies, but is there any way in unity to just use a texture for reflections

#

like in old games, where they just project a texture onto geometry

rich vine
#

Is there a way to make noise be based on world position and still stick the object? So that you can break up tilling on duplicated modular pieces.

amber saffron
rich vine
amber saffron
#

Just be sure to set the position node to "absolute world"

rich vine
#

@amber saffron When I plug the world pos into the UV of the noise, the noise gets a lot smaller on the scene objects. But in the preview it stays the same, which makes it quite difficult to work with. Do you know if there's a way to get this synced?

amber saffron
rich vine
#

Do you know if there's a way to mess with the detail, distortion etc for the noise like you can in blender? Or do you have to manually mix a bigger noise with a smaller etc to get more details?

warm moss
rich vine
zinc verge
#

anyone know how to transport blender materials to unity

#

because my materials have the texture baked in

#

and i dont feel like making every material compatible with unity

#

well more like i dont know how

rich vine
grizzled bolt
zinc verge
#

well it doesnt work becauase i made my own shader

#

and unity doesnt recognise blender nodes

#

but i had the idea just to replace the cell shader and make a more simple material for ingame

rich vine
# zinc verge

You have to bake the texture in blender, then import that into unity

#

if its because youre doing a cell shader thing, you have to recreate that in unitys shader graph

#

Works a lot like blenders shader system, but just A LOT more manual

fast igloo
#

Is there any easy tool for the creation of terrain shaders in unity

#

Or just any documentation about terrain shaders?

zinc verge
#

ok so my outlines use emission shaders so they also dont work

#

except for the lower arms

#

who's outline took the shader of the arm

#

and i cant "unoutline" the model because its part of the mesh

lost wasp
finite rover
#

How do I convert my shadergraph to rendergraph, so I am able to turn off Compatibility Mode?

#

Nevermind, I just realized I can turn it off without my shadergraph being impacted

static leaf
#

Hello everyone.
I am following this tutorial and I am at 4:24.
At this point in the video: https://youtu.be/F8bAI6dIrto?list=PLsaDw3p1XpJiGHPnA8gZH6gO2gQYz3JH1&t=264

We add a new reference type to our .hlsl file for our Custom Function node.
In the video it works as expected, however when I try to do the same, I receive a couple errors about being unable to resolve Light and GetMainLight()

Am I missing something, or have these references changed at all in Unity 6?

Unity only provides a Main Light Direction node for custom lighting. If we want more fine-tuned control and support for color and additional lights, we'll need to delve into the world of ✨custom HLSL code✨. With Shader Graph's Custom Function node, we unlock plenty of new opportunities!

I'm using Unity 2022.3.0f1, although these steps should lo...

▶ Play video
regal stag
static leaf
#

@regal stag They are indeed showing up in Rider. However, they show up on the Shader graph error too.

regal stag
#

Also are you using the #ifdef SHADERGRAPH_PREVIEW block? I feel like it shouldn't error in graph with that

static leaf
# regal stag What render pipeline / graph target is being used? Afaik this setup only works i...

I am using URP on an Unlit Opaque shader.
The hlsl file I have looks lik this:

#ifndef ADDITIONAL_LIGHT_INCLUDED
#define ADDITIONAL_LIGHT_INCLUDED

void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out float Attenuation)
{
    #ifdef SHADER_GRAPH_PREVIEW
        Direction = normalize(float3(1.0f,1.0f,0.0f));
        Color = 1.0f;
        Attenuation = 1.0f;
    #else
        Light mainLight = GetMainLight();
        Direction = mainLight.Direction;
        Color = mainLight.Color;
        Attenuation = mainLight.Attenuation;
    #endif
}
#endif
regal stag
#

It should be SHADERGRAPH_PREVIEW, not SHADER_GRAPH_PREVIEW

static leaf
#

Got it, thank you!!
I had that way before, but I still saw the error in my IDE so I thought it didn't work and I must have undid the change.
That changes the error in the graph at least, so thank you!

hollow harness
#

what does "_LightColor0" refer to?

regal stag
hollow harness
regal stag
#

_WorldSpaceLightPos0*
Same thing, but stores position/direction. I think the W component is 1 if it's a directional light

hollow harness
regal stag
hollow harness
hollow harness
regal stag
hollow harness
proper kestrel
#

Hi, I am using Unity 2022.3 and am using a shader graph to call a custom function in an HLSL file that makes use of Buffers and StructuredBuffers. When running in DirectX, the shader works fine. But when I try to run it using Vulkan or Metal, accessing the Buffers completely break the shader (i.e., the preview is blank and when running the game, everything is black). Does anyone have any tips on how to resolve this?

warm pulsar
#

Well, I've gotten StructuredBuffer to work on my macbook that's using Metal!

warm pulsar
#

(no clue why)

#

I pass in the number of items with a shader property

jovial iron
#

Thank you so very much, I now have it working:

#

some beautiful 2D screen space object differentiating outlines

proper kestrel
# warm pulsar One important thing -- you are not able to query the size of the buffer on Metal

I was about to give up for now, but kept trying since you said you got it working. I'm not querying the buffer for its size, but I did update all my Buffers to be StructuredBuffers which appears to have fixed half of my problems (not really sure why). I have a simpler example scene that now renders correctly using the shader. However, my main scene is still all black... And my shader graph preview is still broken. There seemingly isn't anything different between the scenes as far as that specific renderer/shader are concerned, so I find it odd that it's still all black.

spare citrus
#

I have URP lit shader but i want to disable "receive shadows" on my model. but there is no such button. how to achieve this?

warm pulsar
#

That's a property of the mesh renderer, isn't it?

steady gate
#

I think I have a clipping problem with my shader, it appeared after I implemented shadows, would anyone know why passing shadow coords to the GetMainLight() function and using the shadowAttenuation value would cause this?

#

It's not always visible, but when I move the camera it appears at certain distances and it kinda scans over the object

#

So I guess it's some kind of clipping issue

steady gate
#

I found a video of someone else having the same issue

#

seems to be caused by light.shadowAttenuation

waxen merlin
#

Hi, I have a couple of questions regarding the 'half' type in hlsl shaders. I have a R16G16SFloat rendertexture and would like to store the current time (which I pass into the material) in one of these channels.

  1. It seems that the shader is still storing the values in the 0.0 to 1.0 normalized range... is that expected/correct?
  2. If the answer to (1) is yes, then should I expect all the precision of a half float to then be used across that range, or will it still be limited to the approx. 3 decimal digits of precision? https://docs.unity3d.com/es/530/Manual/SL-DataTypesAndPrecision.html
  3. Also is it possible to get the shader to store it as a specified float outside of the 0.0 to 1.0 range?
zenith dragon
#

I just don't understand shaders at all yet, shouldn't this behave like the default 2d sprite unlit material?

#

For me the whole sprite becomes a solid color with this shader

#

I was watching a tutorial from Brackeys, I don't understand what he did differently

kind juniper
warm pulsar
frigid jay
waxen merlin
frigid jay
west fulcrum
#

Anyone knows why particles doesn't fade in/out when using VFX Graph with 2D renderer? 🙂

manic niche
#

if I have 4 seperate values that arent related in any way, is it better to go for readability and use 4 floats or combine them into a single float4? (I'd imagine the float4 is more performant but maybe it isnt cuz I only ever use single components)

low lichen
#

It can matter when you are passing in arrays/buffers of floats, with hundreds or thousands of values.

final path
#

Is there any way I can change the surface type of a given material using code? The solution below only works in the editor, unfortunately it doesn't work after making a build. I also tried to specify two versions of the material (transparent and opaque) as parameters and swap them in a given renderer, but that didn't work either.

        private const string SURFACE_TYPE = "_SurfaceType";
        private const string BLEND_MODE = "_Blend";
        private const string ZWRITE = "_ZWrite";

        public void ChangeMaterialToTransparent(Renderer renderer)
        {
            Material[] materials = renderer.materials;

            for (int i = 0; i < materials.Length; i++)
            {
                Material material = materials[i];

                if (material.HasProperty(SURFACE_TYPE))
                {
                    material.SetFloat(SURFACE_TYPE, 1);
                }

                material.SetFloat(BLEND_MODE, 1);
                material.SetInt(ZWRITE, 0);
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                material.shader = material.shader;
            }

            renderer.materials = materials;
        }

        public void ChangeMaterialToOpaque(Renderer renderer)
        {
            Material[] materials = renderer.materials;

            for (int i = 0; i < materials.Length; i++)
            {
                Material material = materials[i];

                if (material.HasProperty(SURFACE_TYPE))
                {
                    material.SetFloat(SURFACE_TYPE, 0);
                }

                material.SetFloat(BLEND_MODE, 0);
                material.SetInt(ZWRITE, 1);
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Geometry;
                material.shader = material.shader;
            }

            renderer.materials = materials;
        }
    }
amber saffron
final path
rich vine
#

Anyone know why when I plug a position node with "absolute world" space into the UV of a simple noise. This kind of stretching happens?

manic niche
#

ur plugging xyz into xy and therefore z gets discarded

rich vine
amber saffron
manic niche
#

use a split node and plug yz into the noise. it should now properly work on the right side and stretch on the left.

rich vine
amber saffron
rich vine
manic niche
rich vine
manic niche
amber saffron
rich vine
rich vine
warm pulsar
#

Also consider triplanar mapping.

#

The rough idea is that it uses XY, XZ, and YZ coordinates to get three samples, then blends them based on how well the surface aligns to those planes

#

You'd have to implement this yourself -- there is a Triplanar node, but it wants to sample a texture

#

If you do go with 3D or 4D noise, keep in mind that it can get very expensive

#

especially 4D noise (XYZ + time)

#

A couple of 4D simplex noise calculations in the fragment shader can bog your game down very quickly

fierce pebble
#

Hello some questions on the render graph api would love it if someone could help ❤️
when making a shader that is injected into the renderer graph with a renderer feature, how can I have multiple inputs ? can we only get the “_BlitTexture” ?

I followed the docs example (at the bottom of the page is the shader code ):
https://docs.unity3d.com/6000.0/Documentation/Manual/urp/renderer-features/create-custom-renderer-feature.html#example-implementation-overview
Image
what if i want the depth or any other texture that was generated in the renderer graph
the docs don't explain this at all, i tried setting them as variables in the matterial in but I could not figure it out, I can set static textures in the code but how should one get other frame datas like these in the shader at the same time ?
https://docs.unity3d.com/6000.0/Documentation/Manual/urp/render-graph-frame-data-reference.html

drowsy shuttle
untold forge
#

Where are the docs for HLSL functions in unity? As in functions like TransformObjectToHClip

kind juniper
#

Other than that look through the source code or google/lookup tutorials.

untold forge
#

I was looking through their github packages but i thought there has to be a better way than this

#

Guess not

kind juniper
untold forge
kind juniper
gloomy gust
#

with like the white thick panes as you rotate across

#

I wanted to make some stylised glass stuff

#

what sort of methods would I have to use in shader graph for something like that?

drowsy shuttle
warm moss
steel notch
#

Trying to analyze Legends of Runeterra's visual style/shading since I think it's super impressive.

#

It seems that almost the entire board is unlit, and all shadows are drawn in except for the ones cast by the cards on the board.

gloomy tendon
#

How do I check the stencil buffer in shader graph?!

#

or for a URP material?

gloomy gust
#

how can i flatten a shader in camera space?

warm pulsar
#

(sad!)

#

But if you're asking about doing stencil-testing (to completely skip fragments), I'm not aware of a way to do that in the shader graph

#

If you're writing a shader using ShaderLab, then it's very straightforward -- add a Stencil block to the subshader or pass

steel notch
warm pulsar
#

I wouldn't expect it to be possible

#

When writing a shader by hand, at least, the Stencil block isn't part of the HLSL at all

#

it's part of the ShaderLab code

gloomy tendon
#

The only way I found to read stencil is add a pass block to the completed shader graph shader code (copy and save)! Because it is outside of the main shader code... But now that is breaking AO for the object so notlikethis

#

I just want to limit the area of the screen that I draw an object to (like within a hole) but sure seems hard currently in URP

gloomy gust
#

how can i make the outline material im using take the whole UV instead of the 3rd materials UV? rearranging the materials is not possible for me

low lichen
gloomy gust
#

sub mesh i suppose

warm pulsar
#

Each material in the list corresponds to a sub-mesh

#

If you add extra materials (as you did here), it re-uses the last sub-mesh

#

So you can't add a fourth material that uses all of the submeshes

gloomy gust
#

thats annoying

#

how does the quick outline package do it then?

warm pulsar
#

What render pipeline are you using?

gloomy gust
#

URP

warm pulsar
#

I've done outline effects by using a renderer feature

gloomy gust
#

they append to the end of the materials list and it works as intended

warm pulsar
#

Actually, yeah, you should be able to use a custom pass for this

#

You can tell Unity to render objects on specific layers and provide a material

gloomy gust
warm pulsar
#

That would make using a custom pass a lot more annoying

#

In that case, consider duplicating the renderers

gloomy gust
#

is the custom pass meant to be more sweeping

dusky arrow
#

Is this accurate? Is HClip Y in the range of -1 to 1 and then when multiplied by projection params becomes 1 to -1?

gloomy gust
warm pulsar
#

I...actually don't know if this even does anything meaningful right now

#

i should check that

#

It explicitly renders everything on the "World UI" layer that's in a transparent render queue

#

It does so after post-processing happens

gloomy gust
#

oh right

gloomy gust
#

this just looks like it kinda explodes the faces lol

#

is there a way to like join up the shapes somehow?

gloomy gust
#

is there a way to make the outline object render beneath the actual renderer?

warm pulsar
warm pulsar
gloomy gust
#

is there a way to always make one render on top of the other?

warm pulsar
#

Messing with the render queue of transparent materials will let you control the order they draw in

#

You can do the same for opaques, but since they write to and check the depth buffer, the render queue shouldn't really matter

#

You could use stencils to stop a shader from drawing on any pixels that another shader has touched

gloomy gust
warm pulsar
#

sure, but transparents render after opaques :p

gloomy gust
#

oh

#

i suppose that makes sense

#

how can i use a stencil?

#

is that annoying to set up

warm pulsar
#

You could render the outline shader before the character, but then:

  • if ZWrite is off on the outline, everything in the game will draw over it
  • if ZWrite is on on the outline, it'll still be able to cover up the character
#

You'd have to modify the shaders if they don't have properties for stenciling

gloomy gust
#

thats fine, is there a lot to modify?

warm pulsar
#
Stencil
{
  Ref 16
  WriteMask 16
  Pass Replace
}

This sets a single bit in the stencil buffer

Stencil
{
  Ref 16
  ReadMask 16
  Comp NotEqual
}

This only lets the shader draw on pixels where that bit hasn't been set

gloomy gust
#

im using shadergraph

warm pulsar
#

uhhh good luck

#

💥

gloomy gust
#

😭

warm pulsar
#

that still doesn't let you do anything with stencils, for some reason

#

I used a really nice outline effect in an HDRP project. I dunno if it could be adapted for URP

#

it didn't expand the faces outwards -- it just drew the mesh repeatedly with a small offset

gloomy gust
#

would appreciate any resource i can try and modify ;-;

#

i want to distort the outline to get a cool effect too

#

so i was thinking of distorting the mesh with like noise or whatever

warm pulsar
#

That was plain ShaderLab, iirc

gloomy gust
#

damn

#

i think i found a stencil tutorial for unity

#

Hey game dev enjoyers!

Here we are: the mighty tutorial about the stencil buffer that I’ve been working on for weeks now. I hope you’ll enjoy it ;)

WARNING: Please make sure to follow the instructions of the “IMPORTANT” chapter (it's only 30 seconds long no worries), otherwise you would not be able to use the stencil buffer.

The shader and ...

▶ Play video
#

idk if this is the thing i want to do

gloomy gust
#

this appears to work? but afterrendering means it ignores the post processing stuff

warm pulsar
#

doesn't look so good on the actual game camera :p

gloomy gust
#

made it so it renders the transparent (outline) first

#

then renders the player on top

#

okay it seems to kind of shatter a bit while its moving lol

tacit parcel
solid scaffold
#

does anyone know how to only apply s shader too the top of a sprite. i have this tree i want to be affected by wind but its moving the bottom and i dont like that

#

followed this tutorialhttps://youtu.be/aKzUsxLJ4SU?t=418

In this video you will learn how to create vegetation wind movement shader graph that can be apply to any sprite in your scene in addition to creating simple script to control the wind in your scene.

Download project files (Patrons only): https://www.patreon.com/BinaryLunar

Music : Lost In The Forest - Background Music No Copyright

Vegetati...

▶ Play video
steel notch
#

and multiply the distortion by this mask.

#

This makes it so the values for the distortion near the bottom of the sprite are forced to 0, which those at the top have full influence.

dusky arrow
#

Why are the Z and W in the form of 1 + 1/textureWidth instead of just being 1/textureWidth? Because I dont see in what situation you would use them

gloomy tendon
#

Also I am not clear which stencil bits are in use by the URP pipeline if any...

timid vine
#

i have to learn shader/graph for becoming a unity vfx artist right?

kind juniper
timid vine
#

tyy

calm crystal
#

I'm making a shader in shader graph that reveals a colored texture behind a grayscale texture from the hitpoint (the player shoots the object) outward. This worked until I added a glow effect to the reveal edge. What happens now is that when the player shoots the object the entire object turns to the glow color, does anyone know why?

neat orchid
#

How hard is learning hlsl if you know shader graph?

steel notch
supple kayak
#

Hi! I followed a tutorial online on creating gerstner waves, the tutorial used the built in pipeline and since I used URP I thought it would be easiest to work in the shader graph since it does all the conversion automatically.
This has quickly turned into challenge since its quite difficuilt for me to work with bigger shaders with all the nodes and its hard to keep track of everything.
So I looked into converting this custom shader into URP and I followed this guidline from Unity https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@14.0/manual/urp-shaders/birp-urp-custom-shader-upgrade-guide.html
and this is the shader so far
https://pastecode.io/s/ux99sxrb
However I still dont get anything on the shader, not even the white color in the frag shader that I wanted to test out
Any help would be greatly appreciated

regal stag
gloomy tendon
#

Writing big shaders in the shader graph is indeed silly - better to add some custom functions for the complex parts with the relevant node

supple kayak
supple kayak
gloomy tendon
#

you can write a custom function node in shader graph for the GerstnerWave part and then make a graph and debug it there

neat orchid
#

And know shader graph

regal stag
supple kayak
#

hmm ye I am currently looking at your github template examples for these passes, but im not sure which one to pick lol

regal stag
#

If you plan on making this water transparent, you can move it into the Transparent queue which should mean depth priming isn't an issue

regal stag
supple kayak
#

omg that worked haha no way, so do I also need to set the renderType to Transparent in the shader code?

regal stag
supple kayak
#

in the tutorial I followed that Unity created which converts built in to URP, they still keep the tag in the shader, so they probably still use it for something

regal stag
#

Yea maybe, and even if it's unused currently might change in the future so probably best to keep it

supple kayak
#

also one quick thing I want to ask, the tutorial says that I need to do this
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
but am I supposed to do this after I do all the changes with the vertex position or before I do all the changes. I dont really understand what this function serves

gloomy gust
#

@warm pulsar https://i.imgur.com/AiSYfC7.gif
i think i finally got my effect! I used quick outline as a base and then made some changes using intelligence of the artificial variety 🥸

#

i realised i could shade smooth for easier look

regal stag
supple kayak
#

aaaaah I see now, so thats what that is for. Alright I think I got it from here! Huge thanks for your help. I also see you have some tutorials for URP on your website so Ill be sure to check that out

regal stag
supple kayak
#

Yeah that might come in handy, thank you!

gloomy tendon
#

I can't understand why if I use the stencil buffer for masking in URP the AO does not work on the geometry drawn with a stencil buffer check.

regal stag
#

Because I think that removes objects from depth texture/normals textures which are used to generate the AO

#

Well, assuming you remove that layer from the default layer masks at the top of the Renderer asset

gloomy tendon
agile shore
#

Hey all. I have a little experience with shader graph (not much though) and am very stuck. I'm using this video: https://www.youtube.com/watch?v=jlKNOirh66E to essentially create a line art shader. I've got to the point of using screen position and reading the scene depth from that and (I think) have managed to grab the scene depth of neighbouring positions by writing a simple custom function that returns each of those positions to me by adding or taking one away from the x and y values (though I'm not entirely sure this works) but am confused as to how I would then sample this against my Sobel matrices to then return a value (screenshot mainly to show how i have my matrices atm, one for vertical and one for horizontal)

It’s shading time. Watch me try to make a shader that renders real-time 3D in the hand drawn style of Moebius. There be crosshatch, outlines, sobel filters, we’re in for a bumpy ride.

Support the channel on Patreon to get extra content, and access to the Discord server and to the source code of every project!
https://www.patreon.com/UselessGame...

▶ Play video
#

(The part about sobel weights is around 2 minutes in btw)

steel notch
#

I was today years old when I learned Shader Graph has a swizzle node.

fringe karma
#

Is there a way to draw renderers to a buffer using the same vertex data but custom fragment data, without having to alter whatever shader's currently on the object?
I'm trying to make a camera-space thermal vision effect, but I want to access script and layer data on the objects being rendered. My original plan was to find every renderer whose data I wanted to store, and write to a custom buffer using a solid colour material whose colour represents whatever data I want to include. But I realised if I do that, then it'll render as the exact mesh regardless of whatever vertex stuff is being done on the renderer's normal material.

#

If the vertex and fragment calculations for say opaque objects are handled during the 'render opaques' phase, if I set the pass to occur after rendering opaques would it pick up on the altered geometry created by the vertex shaders?

kind juniper
fringe karma
kind juniper
fringe karma
#

but yeah I may also need to research more on replacement shaders, because part of this effect will involve some opaque objects becoming transparent

kind juniper
#

You might need to modify the vertex buffer in a compute shader if you want it to be kept. That's how animations/skinned meahes work.

fringe karma
fringe karma
#

then again I haven't actually started researching vertex buffers

kind juniper
fringe karma
fringe karma
#

ah crap I've ran into another issue of how I'm going to handle applying these effects to transparent objects

#

because if some objects end up needing to be transparent, then I still need to store data on objects that are behind them. Maybe I need to make two separate buffers that store the same data, one for opaque objects and one for transparent ones?

kind juniper
#

If you modify the vertex buffer, that has nothing to do with the actual rendering.

tacit parcel
#

it might matters actually, like when an object is behind another object, but vertex shader 'push' it forward into camera, then it might end up to be not behind anymore

tacit parcel
fringe karma
#

also URP allows better use of projectors compared to built-in, and I'll need heavy use of those for stuff like blood splatters and footsteps

fringe karma
#

actually for now I've ignored the 'doesn't account for vertex differences' issue to get my thermal vision somewhat working. And it somewhat works! I'm pleased with the custom buffer that saves heat data so that different objects actually visually change based on their current heat value. But there are still plenty of issues, like how the overlay effect won't apply to parts of this particle system that don't have another object behind them

#

another example

neat orchid
#

So if I have a 10m far culling plane on my camera, what should be more performant:

  1. Using tessellation displacement for my terrain

  2. Using a very high poly terrain with a poly count equal to the tessellated parts in 1

#

I know that tessellation adds an overhead but do polygons outside of the render plane matter at all?

#

I ask because 2) would make vertex painting and sculpting in unity better because of the denser vertices.

low lichen
neat orchid
#

Or find a way to chunk it after importing to unity

#

Right now I'm using digger to export terrain meshes and it has settings for chunking. By default, you have chunking

#

But the problem is when you wanna sculpt it near the seam of 2 meshes

#

So you are basically saying that poly count DOES matter beyond render distance?

kind juniper
stable crest
#

hey so I've been wondering how I can recreate this ghosting/trail effect I've seen on some PS2 games (ICO and Nightmare before Christmas), is it a shader or do they render the mesh multiple times with less opacity each time is what I'm mainly wondering. What would be the best way to replicate it? (Specifically the effect on Oogie Boogie and the Queen)

low lichen
# neat orchid So you are basically saying that poly count DOES matter beyond render distance?

Yes, the GPU needs to shade all the vertices of the mesh you are drawing to calculate the positions of the triangles and then the pixels those triangles occupy. So no matter what, all the vertices will be shaded (meaning the vertex shader is run). But after that, only the triangles within the camera frustum will result in fragments that will be shaded by the fragment shader.

#

Usually most of the time spent drawing an object is in the fragment shader and not the vertex shader, especially at high resolution where the number of pixels increase greatly but the number of vertices always remains the same. So it might not make a big difference to have a bunch of vertices outside the frustum, but there will be some measurable difference.

low lichen
# stable crest hey so I've been wondering how I can recreate this ghosting/trail effect I've se...

My guess is that it's rendered multiple times at different opacities. Crucially, each render is animated on a different frame, to get the trail effect.

This is something that is generally not achieved with just a shader, but something that would also need scripting to make it work. The script will need to store some number of frames of animation and then issue a draw call for each of those frames at different opacities.

stable crest
#

I tried recreating the effect in blender all day and the only thing that came close was compositing multiple render layers with 1 frame delay and different alphas so I thought it might be something like that

neat orchid
#

But I shouldn't have too many meshes either

#

I guess the onus is on me to experiment and figure out the optimal chunk size and displacement technique

#

Which is what I feared 😁

low lichen
neat orchid
#

It even looks good lol

#

I'm not using it for generating the terrain or something

#

I'm using it cause the textures look sweet with it

topaz marsh
#

Is there a way to check Shader compile errors from other platforms. I have a Shader that compiles on Windows editor and build but is pink on Android. Probably just something that is not supported on Android. I just cant get any errors in the console even when connected.

thick elbow
#

why are my materials pink UnityChanHuh

gloomy tendon
#

I am writing to the z buffer only in a material to hide stuff behind, but it seems to block the skybox also. Is the skybox after opaque?

gloomy tendon
neat orchid
#

Sometimes you can convert them (somewhere in the edit menu, google it)

#

But if they're unsupported for your RP, there's nothing you can do

warm pulsar
#

If they're from an asset pack, they were probably meant to be used with the built-in render pipeline, but your project is using anothe render pipeline

#

and yes, there are converters to switch out the shaders on these materials, if Unity recognizes them

normal depot
#

Hello. I started learning shader graph yesterday and I have been dealing with this problem since then. I want to get a transparent shader that shows whatever is behind it, and in all the tutorials I have seen these are the nodes necessaries to achieve that. But I don't get it, all I just see is a gray circle.

#

I made sure this option is set to true, as that seemed to be the problem for a lot of people

warm pulsar
#

What's the render queue on the material?

normal depot
normal depot
warm pulsar
#

You'd calculate a color for your surface and convert that to HSV

#

hue-saturation-value

#

you can then compare the value to a threshold

#

and use to control a Branch node that either picks:

  • scene color
  • the original color
tacit parcel
dusky arrow
#

how do I access this in a shader?

warm pulsar
#

You can set the default render queue in ShaderLab

#

it's a tag -- "Queue" = "Whatever"

kind juniper
queen vortex
#

Hello everyone, I have a small problem, I'm trying to get the GetVertexBuffer from my mesh, and pass it to my shader, it seems like I managed to do it, but when I play, nothing appears, what could I be doing wrong?

https://hastebin.com/share/hevohoteki.csharp

steel notch
#

So what's with URP/HDRP not supporting multi-pass shaders? Are they not a fundamental aspect of shader code?

#

Are multipass shaders something these engines (Unity, Unreal, Godot) tend to avoid? Why?

kind juniper
kind juniper
#

SRPs do it with the drawing objects feature or whatever it's called now. There might be other ways. I'm not really familiar with unity rendering pipelines to that extent.

#

I guess scriptable render passes is the replacement to shader passes.

#

And now there also seems to be the render graph API, which also allows to do it. A lot of new stuff to learn.

civic lantern
#

AFAIK you can also just stack multiple materials on the renderer to get multiple "passes"

#

Doesn't work well if you have submeshes, though

kind juniper
#

And potentially less performant.

topaz marsh
fluid inlet
#

if I have a full-screen shader in unity for HDPR pipeline how do i apply the shader to the pipeline to use it?

civic lantern
fluid inlet
civic lantern
#

Ah. One of the shader gurus here will surely know

civic lantern
#

Custom passes might be relevant too

#

Depending on what effect you are after

warm pulsar
#

I recently figured out normal reconstruction from depth...but i'd imagine the HDRP can just give those to you, especially if you're doing deferred rendering

civic lantern
#

Idk why normal reconstruction from depth never occurred to me

warm pulsar
#

"Fullscreen" is one of the shader graph presets

civic lantern
#

Does it sample the immediate neigbors only?

warm pulsar
#

You pick the horizontal and vertical neighbor that's the closest to your depth (and thus the most likely to be valid)

#

Given these depths, you can calculate tangent vectors and then compute a normal vector

#

except it's not being done in a compute shader, of course

#

because I'm doing it in VRChat pain

#

I'm building my own decal shader

#

I started with something that can just put colors onto surfaces, but now I can actually compute texture coordinates and sample color and normals (both using triplanar mapping)

rich ridge
#

my tile palette is broken, it's takin the wrong item

warm pulsar
#

Your tiles are too big for the grid

#

(or maybe these are just corner-centered tiles and I'm getting confused by that)

warm pulsar
neat orchid
#

What's it called when you apply a texture like snow only on the up facing normals

#

I know how to do it but I don't know what it's called

warm pulsar
#

Nothing comes to mind

neat orchid
#

It has no name?

#

Lol

warm pulsar
#

it reminds me of triplanar mapping, in that you use the world normal to control how you sample the texture, but that's a stretch

neat orchid
#

Yes, quite

#

I heard someone call it an environment mask or map but it's not that

civic lantern
#

Yeah I cant think of a name either. I think I have read "sky mask" somewhere

#

Vertical mask, dot mask?

queen vortex
kind juniper
# queen vortex Yes, I noticed the error, I fixed my code and fixed other parts too, but still, ...

The issue is likely that you're issuing a render command yourself, while omitting a lot of the data the shader would need to render the object properly. Like the object to world matrix, position and other stuff. I'd recommend reading the documentation thoroughly and understand how shaders and rendering in general works before using such low level api.
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Graphics.RenderPrimitivesIndirect.html

queen vortex
#

What I'm trying to do now is instead of creating the vertices and indices by hand, I'm trying to access the GPU's copy of an object's mesh, and pass that data to my shader to render

kind juniper
#

I don't see a compute shader involved anywhere in your code.

queen vortex
kind juniper
#

So what code changed between it working correctly and not working at all?

queen vortex
#

Now I'm using Mesh's ready-made buffer, but it doesn't seem to be working

#

In the case of the GPU copy of the mesh

kind juniper
kind juniper
#

Okay. Did you try debugging the contents of the buffers?

queen vortex
kind juniper
#

What about count?

queen vortex
#

So it seems correct to me

kind juniper
#

Okay. Then no clue. It does seem weird to me that it did work as is previously. But I've never used this api in unity, so donno.

queen vortex
kind juniper
#

If you could use a shader debugger tool, like PIX, you might be able to figure something out.

queen vortex
kind juniper
#

I've never used it with unity though. You'll need to figure out where to get the shader pdbs/debug data from.

small halo
#

I have an old shader that I'm using in unity 6 via compatibility mode. It's a post processing shader that applies a posterize effect to the scene. I'm trying to get it to apply to everything except the skybox.

Here's what I'm doing currently:

    float4 FragRGB(Varyings input): SV_Target
    {
        UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
        float4 screenColor = SCREEN_COLOR(SCREEN_COORDS);

        float2 screenUV = input.positionCS.xy / input.positionCS.w;

        // Sample depth texture
        float depth = SampleSceneDepth(screenUV);

        // Test if skybox
        if (depth >= 0.999)
        {
            return screenColor;
        }

        // ...

It's not working however. I figured the skybox would be the furthest thing in the scene so I test the depth texture. Am I on the right track?

queen vortex
#

Hey, sorry to ping you and revive an old message, but do you know how exactly I read the information after getting the layout?

small halo
queen vortex
# queen vortex Hey, sorry to ping you and revive an old message, but do you know how exactly I ...

Nvm, i got it, i have to use ByteAdressBuffer to read, for anyone in future, this is the code :


ByteAddressBuffer bufferVertices;

void SampleMeshData_float(float vertexID, out float3 position){
    uint vertexSize = (3 + 3 + 4 + 2) * 4; // 48 bytes
    uint vertexOffset = vertexID * vertexSize;
    
    position.x = asfloat(bufferVertices.Load(vertexOffset + 0));
    position.y = asfloat(bufferVertices.Load(vertexOffset + 4));
    position.z = asfloat(bufferVertices.Load(vertexOffset + 8));
}```
steel notch
#

So I'm trying to do some Half Lambert Lighting and used the Shader Graph Feature Examples graphs as a basis for custom lighting.
It seems to work fine, but when I enable shadows on the mesh, I get this odd banding.

#

Shadows Off

#

Shadows On

#

Any idea why this is happening?

#

(Ignore the rocky sphere in the back, it's using standard lighting as a comparison.)

grizzled bolt
# steel notch Shadows On

Shadows have to be projected based on whether a polygon is occluded from the light source, which always happens at a specific angle
Non-projected shading can have whatever smooth ramp you want instead
Usually the shading matches the shadow so the jagged border is concealed

#

The jaggedness itself happens because shadow casting is limited by shadowmap resolution, as well as the geometry normal prior to any smooth interpolation

steel notch
grizzled bolt
steel notch
#

These guys?

#

Like the other side of the mesh?

grizzled bolt
steel notch
grizzled bolt
steel notch
#

But how would you get it to both cast and receive withoust projecting shadows onto itself? Windwaker for example did it.

tough void
#

Hey guys i'm having a little trouble understanding something about the pipelines, I learned to write HLSL shaders for built-in pipline, but it seems everything has moved to URP. I am trying to understand how can I keep doing HLSL shaders for URP instead, I do not want to use shader graph. Any shader i write seems to work completely fine in URP project but i'm a bit unsure if i'm doing the right thing.

lunar river
#

I am not sure if this is the correct locate to ask. But I am trying to create a 2D top down game. I want to add water similar to how forager did it. Not sure how to do it. Do I create sprite then animate it?

I was thinking maybe I have to create a shader but not sure how to make it interact properly with the bottom tiles.

kind juniper
lunar river
kind juniper
lunar river
neon gale
#

Ami missing something, or is there no Perlin Noise node in Shadergraph? Perhaps i missed a package? URP

lunar river
stable crest
kind juniper
kind juniper
lunar river
neon gale
steel notch
#

The sphere isn't even casting a shadow down in this case.

#

Do you know how I get rid of this copy?

neon gale
steel notch
#

Trying to implement Half-Lambert lighting

neon gale
#

wouldn't that just be Bert? 😁

steel notch
#

I hate you

neon gale
#

!LOL 🙂

kind juniper
grizzled bolt
# steel notch Do you know how I get rid of this copy?

It's not a "copy", but that both sides of the mesh are in the way of the shadow
The casted shadow should be blended with the directional light attenuation
So you'd probably want to apply your custom light ramp only after you've multiplied the casted shadow and light direction together, or use a blending method that doesn't stack them like "darken"

steel notch
#

wouldnt this bottom region still end up dark though?

#

Well actually... hmm.

#

If I do all the calculations within that standard 0 to 1 lambert range, then I can just remap to half lambert.

#

This bottom shadow will be be 0 with everything else on the opposite side of the mesh.

#

But then wouldn't the shadow get affected by the shifting and look spread out?

#

Ugh

grizzled bolt
# steel notch But then wouldn't the shadow get affected by the shifting and look spread out?

No
With directional attenuation to 1 to 0 range occurs evenly across the whole mesh as per normals
With casted shadow attenuation it happens only across the penumbra / shadow terminator which by comparison is usually an extremely quick transition
Which means the shadow terminator will likely still clash with your soft half lambert shading
Games that use that type of shading (Source and Valorant apparently) for that reason do not have the characters receive any projected shadows at all
Instead opting only to get shadowing from baked probes
Wind waker does not seem to use half lambert style light attenuation that'd risk exposing the shadow terminator at 0.5 attenuation, even if the characters also don't seem to receive projected shadows except via probes of some sort

steel notch
grizzled bolt
steel notch
#

Damn this sucks.

tacit parcel
# steel notch Damn this sucks.

I think the easiest way is to clamp the bottom of light attenuation, so instead of having 0 - 1 light range, you have 0.5 - 1 light range, this should be different from your half lambert lighting as half lambert, remap from 0 - 1 to 0.5 - 1

grizzled bolt
# steel notch Damn this sucks.

I recommend analyzing more carefully how old stylized games did their thing for ideas of how you want to buid your own stylized look
Most of them got by with very sparse shadow casting and looked fine
Unity's and other modern games' shadow shadow casting techniques have specific limitations especially especially when it comes to hiding the shadow terminator

#

It never mixes very well with toon shading, so workarounds are worth looking into
Or even alternate shadow techniques like stencil shadow volumes

wild hamlet
#

Hi 🙂
I'm using Unity 2022 and did this on shader graph
But I can't make the alpha work, it always displays me the black area. I tried to come up with multiple solutions but none of them work. I'm pretty sure this used to work on my previous projects, do someone has any idea to solve this?

steel notch
#

Alright I saw the google symbol 😛

#

But I feel anything involving stencil tomfoolery will be tough in URP

grizzled bolt
steel notch
wild hamlet
#

I'm using it for particle system, would this work as a sprite unlit?

grizzled bolt
#

Sprite graph is inteded for sprite renderers, not particle systems

steel notch
#

Pretty sure the Sprite graph just does some vertex coloring/applies masking values.

grizzled bolt
#

Could, but it's not intended

steel notch
#

Aka stuff the Particle System can control too.

grizzled bolt
#

Or so I assume anyway

grizzled bolt
wild hamlet
#

Is vertex color entirely handled by particle system?

grizzled bolt
wild hamlet
#

Alright, I'll check that thanks!

grizzled bolt
# steel notch fun

Like I implied you don't really need much in the way of shadows, especially likely not fancy custom systems just to have nice stylized lighting
But it's important to understand the benefit of features available to you, like probes
In Wind Waker when a character goes into a building's shadow, the shadow is not projected onto the character but the whole character is simply darkened
Very simple and apparently good enough for most

steel notch
#

The card shadow.

#

The rest of the board seems to be unlit to me.

#

Relying solely off the painted art style.

grizzled bolt
# steel notch The card shadow.

If it's all top down it doesn't seem like you need to worry much about how the shadows look on the underside of things, or even at shallow angles

steel notch
#

😛

wild hamlet
#

It worked! 🥳

rough lotus
#

I'm using the texture shown at the bottom right, to map the white pixels to a buffer in my compute shader, and those values are written to my tilemap system.
Right now I'm using the full resolution texture for this, but as the tilemap has far less resolution than the texture, would it be worth using a mipmap instead?

grizzled bolt
# rough lotus I'm using the texture shown at the bottom right, to map the white pixels to a bu...

I believe you'll be sampling the texture only for each tile, so it doesn't really matter (unless your source texture had noise or small details that can cause eccentric results)
If the texture was huge, you might be able to save some memory by not loading it in full resolution, but it's not
(Based on my knowledge sampling a lower res mip level directly would save VRAM, but to not load the full texture into RAM you'd need some type of texture streaming, but again that's likely less than a marginal issue here)

rough lotus
#

ah, if its only really good for making it more optimal then I wont worry

#

I wasnt sure if a lower resolution texture might produce a better result in the tilemap. The higher resolution texture has a lot more information thats going to waste

#

One concern is that I'm doing a very basic check where as soon as any pixel is white, that tile is marked as being filled.

[numthreads(8,8,1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
  uint width, height;
  Layer0.GetDimensions(width, height);

  float l0 = Layer0[id.xy].x;

  if (l0 == 1.0f)
  {
    int2 gridCoord;
    gridCoord.x = id.x / (width / MapWidth);
    gridCoord.y = id.y / (height / MapHeight);

    int bufferIndex = gridCoord.x + gridCoord.y * MapWidth;
    Result[bufferIndex] = 1;
  }
}```
#

so even the smallest overlap will fill the tile. But if it was lower resolution, theres less chance for that to be the case

grizzled bolt
steady gate
#

How can I modify the ShadowCaster pass from blurring the shadow edges? I don't want the smooth transition

low lichen
#

You can disable soft shadows globally, but not per shadow caster.

steady gate
#

Aha thanks

cyan maple
#

hey guys, i got recommended to try and use channel packing for my textures, but I can't find any documentation on them for URP. Is this a shader thing? How do I get it to work?

neat orchid
# cyan maple hey guys, i got recommended to try and use channel packing for my textures, but ...

In this shader tutorial, I show an advanced technique for packing data into texture channels that allows you to represent all of the texture data needed for a material in just two texture samples. Using this method saves both texture memory and performance, but since you're packing non-normal data in with the normal map, you do lose a little bi...

▶ Play video
#

Guys, do triple a games make all of their own shaders?

cyan maple
cyan maple
#

how do I enable it? the UI just looks the same as the regular lit shader

neat orchid
#

What do you mean by enabling it?

#

There is no enabling or disabling

#

You just stuff textures into channels

#

Unless you mean doing that in unity

cyan maple
#

so say I generate the required channels in R, G, A colors

#

it should be in a single image/texture right?

#

and I just drag and drop the same image into the metallic/occlusion/smoothness inputs?

neat orchid
#

No, single texture, 4 channels

#

You can switch between channels and see what each one contains

#

You would usually pack textures like that in photoshop

#

There are probably online tools for it or something

cyan maple
# neat orchid No, single texture, 4 channels

yeah so if I've got it right, I should have a single texture containing metallic/occlusion/smoothness in the R/G/A channels - then in Unity I drag and drop the same image into the metallic/occlusiom/smoothness maps? Does that mean the shader is only doing one texture read or have I got my understanding wrong?

neat orchid
#

You should drag the individual outputs into the channels they need to be in

#

So if metallic is in red, you drag R to metallic

#

G to occlusion or whatever the channel are

cyan maple
#

I found the Complex Lit shader form Unity's documentation which seems to support channel packing already, but I wasn't sure how to put those RGBA channels through

warm pulsar
#

a shader would have a single Texture property that you throw this packed texture into

warm pulsar
cyan maple
#

like thiua\

warm pulsar
#

Where did you see that?

civic lantern
#

But why would it use the Base Map? Isn't that for color?

#

Very confusing

warm pulsar
#

oh, I searched for "packed" instead of "packing" and instantly gave up

#

also, that's very poorly named

#

it has nothing to do with the actual "base map" texture

#

I see what they're getting at tho

#

So you do assign the same texture to multiple properties

#

When you do that, the texture still only has to get loaded onto the GPU once

#

I think the idea is that it checks the red channel of the Metallic map, the green channel of the Occlusion map, etc.

#

So grayscale textures work as expected

#

But a packed texture will also work correctly

cyan maple
#

so uh

#

I just put the same texture into the different properties and it should just samples the same texture once

#

it's a bit weird that there's no normal map property, I would have thought that it would be a common thing to want to pack

kind juniper
static leaf
#

Hey guys, I have sort of hit a wall and I could use some help.

I am trying to control my shader via code which will be triggered by in-game events that take place.
In this basic proof of concept attempt, I simply want to update a grid to shade the tiles different colors.
The problem is, as far as I can tell my calculations are correct, and I am passing the right values, but the shader is only ever updating the last tile in my grid to be colored by the highlighting, regardless of where I click.

In this case, I clicked where the mouse is, and it colored the last tile. It always colors this same tile, regardless of input position.
My grid is comprised of a UV node to start which we then plug into a tile node, with the grid size. We then split that off to our custom function node for the highlighting work, and a fraction node for generating the rounded rects which we are using for grid tiles.
Happy to share the shader graph file or pictures of it, if it helps!
Just trying to understand if I am even in the right ballpark, and if so, what might cause the highlighting to only ever be applied to this particular spot?

#
void GetHighlightData_float(float2 scaledUV, out float4 highlightColor, out float highlightIntensity, out float4 debugColor)
{
    // Initialize outputs
    highlightColor = float4(0, 0, 0, 0);
    highlightIntensity = 0;
    
    // Get grid position
    float2 gridPosition = floor(scaledUV);
    
    #ifdef SHADER_API_D3D11
    // Loop through highlight buffer
    for (int i = 0; i < _HighlightCount; i++)
    {
        HighlightData highlight = _HighlightBuffer[i];
        
        // Check if current grid position matches highlight position
        if (gridPosition.x == highlight.position.x && gridPosition.y == highlight.position.y)
        {
            // Set full color with alpha
            highlightColor = highlight.color;
            // Ensure intensity is properly scaled
            highlightIntensity = saturate(highlight.intensity);
            break;
        }
    }
    #endif
    
    // Update debug visualization
    debugColor = float4(
        gridPosition.x / 10.0,  // R shows X position
        gridPosition.y / 10.0,  // G shows Y position
        highlightIntensity,     // B shows if we found a match
        1                       // Full alpha for debug
    );
}
grizzled bolt
rough lotus
#

I've got this strange jittery issue (I click to update the texture which is why some tiles get tinted white) that only seems to occur around the edges of the texture

#

I'm not too sure why that could be happening. Thats the shader code, which is pretty much the same as how it was previously

#pragma kernel CSMain

RWTexture2D<float4> Layer0;

int MapWidth;
int MapHeight;

RWStructuredBuffer<int> Result;

[numthreads(8,8,1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
  uint width, height;
  Layer0.GetDimensions(width, height);

  float l0 = Layer0[id.xy].x;

  int2 gridCoord;
  gridCoord.x = id.x / (width / MapWidth);
  gridCoord.y = id.y / (height / MapHeight);
  int bufferIndex = gridCoord.x + gridCoord.y * MapWidth;

  Result[bufferIndex] = l0 > 0.0 ? 0 : -1; //-1 means no match
}```
#

Thats the actual C# code that calls the shader

  public void GenerateZonesFromLayers(TerrainLayer[] layers)
  {
    ComputeShader cs;
    TextureHelper.LoadComputeShader(out cs, "LayerZoneCompute");

    TerrainLayer layer0 = layers[0];
    cs.SetTexture(0, "Layer0", layer0.LayerMask);

    cs.SetInt("MapWidth", _mapWidth);
    cs.SetInt("MapHeight", _mapHeight);

    ComputeBuffer outputBuffer = new ComputeBuffer(_mapWidth * _mapHeight, sizeof(int));
    cs.SetBuffer(0, "Result", outputBuffer);

    TextureHelper.Dispatch(ref cs, 0, _texSize);

    int[] outputData = new int[_mapWidth * _mapHeight];
    outputBuffer.GetData(outputData);
    for(int x = 0; x < _mapWidth; x++)
    {
      for(int y = 0; y < _mapHeight; y++)
      {
        _map[x, y].Zone = outputData[x + y * _mapWidth];
      }
    }
    outputBuffer.Release();
  }```
warm pulsar
rough lotus
#

thats where it comes from, when I create a new TerrainLayer. It just reads a texture2D as a placeholder texture

    TextureHelper.CreateRenderTexture(out LayerMask, texSize);

    var testTexture = Resources.Load<Texture2D>("tex/test2");
    Graphics.Blit(testTexture, LayerMask);```
#

I'll generate the LayerMask texture later, but theres no need until the shader is working correctly

#

the only thing that changes is the property when I click on a tile, but thats unrelated to the zones

#

this isnt the first time I've encountered this same jittery effect when using a texture in a shader this way

rough lotus
warm pulsar
#

Kind of both, really

#

I don't see why there are red tiles at all

#

(is the problem that the red tiles are changing?)

rough lotus
#

not at my PC now, but the shader that creates the white colour when I click, is exactly the same as the one that creates the red color. But it reads the zone property not the isClicked

#

it just figures out which tile the current pixel is inside

#

its something like this

  int2 gridCoord;
  gridCoord.x = id.x / (width / MapWidth);
  gridCoord.y = id.y / (height / MapHeight);
  int bufferIndex = gridCoord.x + gridCoord.y * MapWidth;
  
  int zoneValue = TileBuffer[bufferIndex];
  
  if(zoneValue == -1)
  {
    Result[id.xy] = float4(0,0,0,0);
  }
  if(zoneValue == 0)
  {
    Result[id.xy] = float4(1,0,0,1);
  }```
rough lotus
steady gate
#

Are there any good resources on shader keywords?

#

I kinda have difficulty understanding them and deciding if I need them

civic oxide
#

Heya, can someone explain to me what exactly CommandBuffer.DrawProceduralIndirect is supposed to do exactly? Is it just rendering one part of an index/vertex buffer or is it rendering all of it with the indirect args?

low lichen
civic oxide
#

documentation isn't exactly helpful

low lichen
#

But in the case where you only have one set of arguments in one buffer, you'd always set the offset to 0.

#

That's different from the index/vertex offsets I mentioned.

#

There are two different versions of DrawProceduralIndirect. A version where you provide an index buffer and a version where you don't. The arguments mean different things depending on which one you're using.

civic oxide
#

can you walk me through it please?

#

or link me to some actually helpful documentation?

low lichen
# civic oxide or link me to some actually helpful documentation?

The docs explain what the arguments mean for each one.

When providing an index buffer:

Buffer with arguments, bufferWithArgs, has to have five integer numbers at given argsOffset offset: index count per instance, instance count, start index location, base vertex location, and start instance location.
When not providing an index buffer:
Buffer with arguments, bufferWithArgs, has to have four integer numbers at given argsOffset offset: vertex count per instance, instance count, start vertex location, and start instance location.

https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rendering.CommandBuffer.DrawProceduralIndirect.html

#

If you don't intend to use instancing, you can ignore "per instance", "start instance location" and set "instance count" to 1.

#

I can probably explain better if I know your intention with this method.

civic oxide
#

say I have a list of unique meshes I want to render in one single command (unless I am completely misinterpreting drawprocindirect) and I put it all into their big respective buffers - vertices, indices, and the commands ofc - would I be doing this?
cmd.DrawProceduralIndirect(indexBuffer (my triangles), Matrix4x4.identity, material, -1, MeshTopology.Triangles, commandBuf (indirect args), 20 (5x4 bytes), matProps (which I have set my indices, vertices, and other stuff I'll need in the shader));

civic oxide
#

also want to give myself better ways to cull with the computebuffer parameter for my args

low lichen
civic oxide
#

yes yes

#

wait so there's no real way to render everything all at once with the indirect args? Something similar to OpenGl's glmultidrawarraysindirect

#

I have to like, loop through all my commands with the offset?

low lichen
civic oxide
#

so with this I just set the command count to the amount of commands I have - and that acts like multidraw?

low lichen
civic oxide
# low lichen Yes, assuming your args buffer has multiple commands in it.

Nice! one last thing, can you please explain to me more in detail the properties of the IndirectDrawIndexedArgs struct? Mainly the baseVertexIndex; while I was experimenting with it, I found it has no impact to what rendered. I assumed it meant the offset to each index because all the indexes in a combined buffer would lead to the start of the vertices buffer rather than their respective vertices, however it had no effect when I attempted to change it...

The thing I was trying to do was take two different meshes, combine their vertices and indices into their respective buffers, and make two commands for them so they would both render with the one command - which was the RenderPrimitivesIndexedIndirect method - however if the two meshes I set in the inspector were different, it would work fine but using two different meshes would absolutely break the meshes rendered with the second command. It was obvious that the problem was the indices of the second command/mesh where using the vertices of the first, however changing the basevertexid did literally nothing

#

Also sorry for bothering

low lichen
#

The equivalent argument in D3D11 is documented as:

A value added to each index before reading a vertex from the vertex buffer.

civic oxide
#

which makes sense and is critical for my use

#

however is doing nothing

#

I've tried using the correct offset values and have tried using some random constants

#

to no avail

low lichen
#

Oh, but I don't think it will change what you get from SV_VertexID in the shader. That apparently always acts as a counter starting from zero.

civic oxide
#

that's what GetIndirectVertexID(svVertexID) is supposed to be used for aparently

low lichen
civic oxide
#

ooooh so I should be using the args directly in the shader myself?

#

makes so much sense

low lichen
#

I've never had to do that, but I've never used baseVertexIndex or multi draw.

civic oxide
#

though honetly thought it'd be trivial to have the engine be doing that for you, but what the hey, this is a function designed for flexibiltiy anyway

#

Anyways thank you so much! You have been such a great help.

grand jolt
#

How would I fix this issue? I want the face in the middle to not be visible while maintaning transparency everywhere else

grizzled bolt
grand jolt
#

I really need to do it this way for my uses

grizzled bolt
grand jolt
#

I just need it to be seperated basically

#

would you know what I could do?

grizzled bolt
neat orchid
#

Are you making these meshes? If so, can you just separate the middle part as a child object and disable it?

#

Or not have it at all, depending on what you need it for

pliant chasm
#

Hello, im still learning, so im having a hard time understanding some things about shaders.
I have a 2D URP project and im trying to use dither transparency controlled by alpha clip threshold. If my shader is set to "Lit" which is for 3D, alpha clip threshold at 0 means fully visible while getting to 1 is more dithered until invisible at 1. On the other hand, as a "Sprite Lit" shader, everything is the same but alpha clip threshold 0 is already dithered for some reason. That is not what I want. I want the "Lit" behavior but on a "Sprite Lit" shader. I have tried many workaround to no avail.

astral turret
#

been playing with the example https://toqoz.fyi/thousands-of-meshes.html

at this point though, I'm scratching my head at shaders. I like the instanced shader they tossed together to give them unique colors, but those alone won't support a sprite on the material. (I've at least tracked down that it's probably a property of shaders).

is there a shader people like to use with sprite rendering? one that (presumably?) has a z coordinate as well?

astral turret
#

I wonder. Feels like a tall order to do sprites, individual scales, colors and rotations, all crammed in a shader that I can push into a bulk mesh render.

remote delta
#

Any shader expert here? I need a shader to be made, i can pay for the help

echo moatBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

remote delta
warm pulsar
#

Click the link in the bot message.

astral turret
#

hm. is there a summary of the features the in-house shaders support? instancing, alpha blending, et cetera? I'm even just at the point of trying to navigate this, but I figured I'd ask...

grand jolt
vagrant glade
#

Working in shader graph and trying to offset just the alpha channel of a texture on the XY axis. Is this possible? From what I can tell, the Tiling and Offset node could possibly help, but I have no clue how to modify the pixel positions on the 2D output from the alpha channel or math nodes. Alternatively, just being able to offset the XY position of any 2d output from a math node would be helpful

vague pilot
#

Hey, is it possible in a hlsl shader to sample from sth like a shadow map if there is a shadow rendered by unity at a specific position (in screen or world space) in urp and how would you do that?

austere pier
#

hello, i bought a shader that is supposed to do a wind distortion, but the sample scene i got looks like this:

#

vs that ^

#

its not telling me a specific error either, so im not sure whats wrong

kind juniper
kind juniper
grand jolt
#

any hints how to make my simple square spriterenderers do this, what keywords/shader nodes are related to this effect?

#

I just want box spriterenderers that mixes with other when they touche

kind juniper
#

It also depends if you want it to render just like in the screenshot( only the border of the mesh?) or is it just a simplified example, and you actually want textures to be rendered in that area somehow.

grand jolt
#

they wil literally just look like white boxes with edges

#

when the edges touch, the touching and overlapping parts are not visible

kind juniper
#

Then the easiest way I can think of is either:

  • merge the individual rectangle meshes and use a mesh renderer to draw the combined mesh.
  • render all the sprite renderers into a mask render texture and use that in screen space or something.

The drawing of the outline is a separate issue.
If using combined meshes, you'll probably need to adjust the uvs of the mesh and use the uv values to determine how close to an edge a pixel is.
If using the mask approach, you could sample several pixels to the sides to see how close to the edge you are. That's probably gonna be way more expensive than the first approach.

Maybe there's a simpler way, but I can't think of anything else.

grand jolt
#

this sounds easy though, might worth the try if desperate

tranquil jackal
#

so I want to display point data with a shader. Aka to have small bubles or squares at the data I have. I cannot use compute shaders or VFX graphs. I thought I can save my position data into texture, and then combine that texture data with position somehow and do something with that data, like adding extra visuals or etc. But I failing to do it. Maybe someone have to suggest different approach?

hollow harness
#

#pragma multi_compile_fog what does this means?

kind juniper
# hollow harness ```#pragma multi_compile_fog``` what does this means?

Usually, anything starting with a # is something that tells additional info to the compiler. You have #define which are very common in C++ code to define a certain keywords, set it's value or define a macro. #pragma on the other hand seems to adjust the behavior of the compiler.
In this case, it tells the compiler, to compile several variants of the shader for different fog types:
https://docs.unity3d.com/2018.4/Documentation/Manual/SL-MultipleProgramVariants.html

hollow harness
#

for example I just use exponential fog in my scene, so I dont need that fog compiler to include the other modes which are unnecessary, in such case which practice are better to write shader efficiently

#

@kind juniper

kind juniper
#

Is there a specific reason you want to avoid using the multicompile?

hollow harness
mighty jay
#

Hello, I picked up a PS1 Style shader graph for URP on github but it doens't have support for normal maps, I'm new could someone please tell me if there is a spot for me to hook up my normal map + normal strength variables from the blackboard so that they appear ingame ?

violet crater
#

does anyone know how to fix this error for a shader?

tribal hemlock
#

Hello guys, why are one of my shaders staying pink even though they are not supposed to? (I am using URP)

static leaf
tribal hemlock
#

I will check the shader again.

static leaf
#

The other possibility is, if you just switched to URP, you may need to run the material conversion to update all your project materials to be URP materials.

#

Edit > Rendering > Materials > Convert

static leaf
#

Maybe re-create the material and re-apply the shader. Idk what else would cause the magenta coloring like that.
Hard to say since I don't know the timeline of when you created this material & went to URP. It may or may not be the actual issue.

warm pulsar
#

it knows that "Standard" should be replaced by "URP/Lit"

#

that's all

#

It has no idea what to do with this third-party shader

tribal hemlock
#

And i got URP like 2 weeks ago

warm pulsar
#

you just wrote the shader today?

#

do you mean you just created the material today?

tribal hemlock
#

No, I wrote the shader today.

warm pulsar
#

okay, so you need to write it in a way that's compatible with URP, then

tribal hemlock
#

Oh okay.

warm pulsar
#

If you use the Shader Graph, that should be straightforward. If it's a ShaderLab shader, then I'm not familiar with how that works -- I only hand-write shaders in the built in RP

#

If it's ShaderLab, then right click on the shader asset and reimport it. You should see shader compilation errors in the console.

simple pond
#

hello i made a fullscreen shader in unity hdrp but this shader is not used in the build version. does anyone know why?

warm pulsar
#

How are you using the shader?

#

It might not be getting included in the build if Unity doesn't think anything is using it

simple pond
#

i use it with custom pass
a simple shader that provides thin stripes on the screen

warm pulsar
#

Okay, that ought to be pulling the shader into the build

#

You could double-check by forcing the shader to be included

#

Project Settings > Graphics

#

then put it in the "Always Included Shaders" list

#

(you have to manually change its size, very silly)

vague pilot
devout quarry
# agile shore Hey all. I have a little experience with shader graph (not much though) and am v...

Hey a bit of a late response, but you could check out this tutorial of mine, it does not use shader graph but should show you how to make an edge detection shader

https://ameye.dev/notes/edge-detection-outlines/

agile shore
#

Oh cool, thanks!!

simple pond
warm pulsar
#

mmm, compiler problems

#

the generated shader is invalid, hm

north kelp
#

I'm getting sprite popping/swapping when my camera moves or zooms out, and i'm 99% sure it's coming from some internal issue where a material with multiple instances and sprites are deciding to coalesce to the same sprite image regardless of assignment. Is this a thing? If so what's the best practice for material assignments versus unique sprite needs?

The material in question is just Sprite-Lit-Default, but i remember running into this in the past with a custom material which i solved by making a unique material per texture (which felt super counter-intuitive, but did solve the problem). Thanks in advance!

hearty obsidian
#

Can we stop unity from autogenerating a material with every graphs in 2022+?

inland ibex
#

Hey guys. I'm working on a 2D game that uses sprites and I have a question. I'm pretty sure it's possible to have a black and white sprite and then create shader that replaces the shades of gray with a color palette. Then apply that shader on the material my sprite is using.

I thought maybe that's something I can use for my butterflies, instead of creating dozens of sprites to cover multiple color variations.

But is it possible to have the material display different colors on different butterflies at the same time or I would have to create one material per color palette?

static leaf
# inland ibex Hey guys. I'm working on a 2D game that uses sprites and I have a question. I'm ...

Just wanted to post an update in here and ask a question while I was at it!

I am working on making a shader for my game and I thought it would be a fun challenge for myself to learn shaders. So far so good, I can render planes with their own materials on them for individual grid highlighting. I was just curious what suggestions people had for controlling the rendering of this on a per player basis. For example, if I want to enable or disable showing this shader, on a per player basis in a multiplayer game, what would be the best approach?

Imagine this grid is being used for a turn based game, and we only want too show it to player 2 because they are choosing a target for some ability they used, or something along those lines. I am not sure what to look up from here that will help me reach my goal so I thought I would ask here.

My fallback plan is to just do the below approach, and render each grid to a different player camera.

Thanks!

#

My bad, didn't mean to reply to you with that. I think to solve your problem though @inland ibex you will want to apply the color variance from the shader itself. Quite possible to do with shader graph.

Edit: Maybe something like this:

https://www.youtube.com/watch?v=firdoL0pjiI&ab_channel=AETuts

This is a quick tutorial on making a material that assigns a random color from a gradient based on the position of the object.

This material is part of the URP Material Pack Vol 2:
https://bit.ly/lwrp-materials-2

Checkout my assets for more Tuts!

 ...
▶ Play video
grizzled bolt
simple pond
dusty birch
#

Has anyone here successfully implemented compute shaders in a mobile game?

#

How widely are they supported on mobile devices in 2024?

low lichen
# dusty birch How widely are they supported on mobile devices in 2024?

They are supported in OpenGL ES 3.1 and up. So, the answer to your question can be found by asking how many devices support OpenGL ES 3.1 or above. Surprisingly, there's not really a good resource for this, but I would guess the majority of phones made after ~2016 will support ES 3.1.

dusty birch
low lichen
dusty birch
shell wadi
sharp frost
#

Hey all, I don't want snow tree effect on distortion as this tree is ahead of plane? How can I resolve it?

vocal narwhal
vocal narwhal
#

Perform different logic based on whether the difference is positive or negative

#

(in front or behind)

dusty birch
shell wadi
robust mango
#

hi, it is not really shaders, but I am not sure where to post. I am trying to display a cylinder in wireframe, but there are too many polygons in it. Are there cylinders with less polygons ?

rough lotus
fading pike
#

Hey im using a psx shader in my unity game and it seems to not be reacting to light i have hdrp render pipeline any help?

grand jolt
#

I have a multi sided sprite shader for a game, and for some reason it isn't receiving shadows/lights or casting shadows. Could anybody help me?

topaz marsh
#

Hay, does anyone have any clue how to implement MSAA using the RenderPass/SubPass system in a custom SRP?

steel notch
#

Me: "Why do my decals look strange? They seem to not be fully transparent. How odd."

  • Spends the next hour researching and trying things. Eventually takes a break and closes Unity.
  • Comes back 3 hours later and opens Unity.
  • Problem gone. Seemingly no reason why.

We take those.

tacit parcel
latent rampart
#

So I'm trying to make a very common shader, an edge shader. Anyone have recommendations for a solid modern tutorial for this? It seems there are a lot of ways to do it, just not sure which direction to pick.

latent rampart
#

Ok there are fewer options than I thought, most tutorials are for outline shaders, which won't work, and the rest are shaders that are done at the scene level... but I want it on a per mesh basis instead.

steel notch
#

Do you mean when the mesh intersects another, something happens along that border?

#

Or do you mean something happens on the edge of the mesh, like an outline?

latent rampart
#

@steel notch like an outline, but from what I've seen of outlines, they are projected away from the mesh (or behind it?) and I don't know how that interactions work with a transparent shape in something similar to voxel terrain.

#

I guess the closest thing would be stormworks building UI:

latent rampart
#

intresting

#

according to this edge detection is a full screen pass, bummer

#

So one of the outline methods is my only option

solid scaffold
#

does anyone know how i can make a compute shader that adds shadows to tile maps sorta like terraria but doesn't rely on light but only on distance from the edge of clumped tiles. maybe it would render black square cells with certain amount of alpha depending on how far from the edge it is and then blur it all. OR have a reference to a website where i can learn where to do it.

grizzled bolt
warm pulsar
barren sage
#

I'm Trying to make the sprites glow. but Why they have some outlines if I use my Glow Material?

#

It's Default Material

#

and this happens when I change Material

#

This is the Material / Shaders info

mental bone
#

It seems the shader graph is set to opaque

turbid pivot
#

this is my shader graph

#

followed a brackeys tutorial and its the same

#

yet isnt working

#

all settings the same

#

right i somewhat fixed it

#

but on the emission nothing is happening

#

no blue

ebon moss
#

where should I look for info about #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE

#

I'm trying to access shadow maps from code in URP

humble fjord
#

Is there anyone familiar with the RGB mask workflow in Unity?

#

I want to use rgb mask workflow for my model in unity. For example I want the red color to be rust, the green color to be dust, the blue color to be scratches.

#

how can i do this in unity?

#

And what tutorial can you recommend?

neat orchid
#

Otherwise you can pack your rgb texture and sample twice, once for regular base color and once for your rgb mask, and blend in such a way that your mask overrides the base

#

I.e. mask is white, no mask part is black

tacit parcel
# humble fjord I want to use rgb mask workflow for my model in unity. For example I want the re...

you sample the mask texture, then multiply red channel with rust texture, green with dust, and blue with scratch, then you add them together, but you need to care to make sure the rgb channel for one pixel to never exceed one.

Or, you ignore the red channel, and interpolate from rust to dust using green channel, then interpolate from that result to scratches using blue channel, that way you dont need to worry about 'oversampling'... Also you can use the red channel for one more texture slot

humble fjord
#

i got it

#

thanks guys

wooden kite
#

Is there any way of making a Shader Graph for using in TextMeshPro?

grizzled bolt
dim yoke
devout quarry
# latent rampart So one of the outline methods is my only option

for per-object outlines, you could use several of those outline options from the article

  • vertex extrusion (does not run as full-screen pass)
  • blurred buffer (runs as full-screen pass)
  • jump flood algorithm (runs as full-screen pass)

even edge detection (runs as full-screen pass) can do per-object outlines though

So yeah all those outlines can still do per-object outlines 🙂

To make a selection between the outline types, it would depend more on things like

  • do you need different outline widths between the objects in the scene, or all the same?
  • what should happen if outlined objects overlap?
fading pike
warm pulsar
#

a "psx shader" is probably designed to only support vertex lighting

#

and also might not care about anything beyond a single directional light

turbid pivot
#

im trying to make a shader that does textures base on height

#

i can set 2 textures and then set the height limit for the first

#

rn ive got this but as you can see its scuffed

#

because from the top its just black

#

the white only shows from the side

#

this is what im aiming for (i got this with a terrain script)

#

but start small so 2 colors yk

hardy juniper
turbid pivot
#

I've got like no experience

#

I did a position module

#

split the y I think

#

then multiplied it with the color

hardy juniper
#

well you will lerp between the two colours using the height. you should define a min and max that you can inverse lerp the current height with.
then you get 0->1 to then lerp the colours.

#

if using shader graph there is probably a node for inverse lerp with clamping

turbid pivot
#

yeah I'm using graphs

#

I'll try it when I get back on my pc

#

ty

latent rampart
#

@devout quarry I tried a few things, tried some on the asset store, nothing quite does what I want. I reverted back to using a kind of bounding box made of GL lines.

devout quarry
#

But if that bounding box works, all good of course 👍

turbid pivot
#

my tree textures are pink

#

i used the default unity tree shader for the tree gameobject

hardy juniper
supple kayak
#

Hello! Does anyone know a way of using the Scene Depth node inside shadergraph for the vertex shader? Basically I am working with Gerstner Waves and I want to set the amplitude based on how "shallow" the water is. For this I need to know the scene depth when setting the vertices. Is there maybe some workaround? I am using URP with a transparent material

regal stag
# supple kayak Hello! Does anyone know a way of using the Scene Depth node inside shadergraph f...

Can use a Custom Function node. I think this should work :

#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
RawDepth = SAMPLE_TEXTURE2D_X_LOD(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(uv), 0).r;
//LinearDepth = Linear01Depth(RawDepth, _ZBufferParams);
//EyeDepth = LinearEyeDepth(RawDepth, _ZBufferParams);
supple kayak
regal stag
#

You might also need to do this to prevent SG previews breaking

#ifdef SHADERGRAPH_PREVIEW
LinearDepth = 0;
//EyeDepth = 0;
#else
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
float RawDepth = SAMPLE_TEXTURE2D_X_LOD(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(uv), 0).r;
LinearDepth = Linear01Depth(RawDepth, _ZBufferParams);
//EyeDepth = LinearEyeDepth(RawDepth, _ZBufferParams);
#endif
supple kayak
regal stag
#

No that should be defined by the DeclareDepthTexture.hlsl include

supple kayak
#

hmm well now its throwing me an error, but inside of the DeclareDepthTexture hlsl file
"Shader error in 'Shader Graphs/GW_Island': undeclared identifier '_CameraDepthTexture' at /UnityProjects/Tranquil-Waters-Unity-/Library/PackageCache/com.unity.render-pipelines.universal@14.0.11/ShaderLibrary/DeclareDepthTexture.hlsl(15) (on d3d11)"
and
"Shader error in 'Shader Graphs/GW_Island': syntax error: unexpected token '(' at /UnityProjects/Tranquil-Waters-Unity-/Library/PackageCache/com.unity.render-pipelines.universal@14.0.11/ShaderLibrary/DeclareDepthTexture.hlsl(8) (on d3d11)"
I mean I have the Depth Texture enabled in my URP settings, so I dont really know what can be causing the problem. Its also not allowing me to open the hlsl file in a IDE to check

regal stag
# supple kayak hmm well now its throwing me an error, but inside of the DeclareDepthTexture hls...

Hmm maybe try as File mode and use this as a .hlsl file instead.
Inputs "UV" (Vector2) and outputs "Out" (Float). Function Name "SceneDepthLOD"

#ifndef SCENEDEPTH_LOD
#define SCENEDEPTH_LOD

#ifndef SHADERGRAPH_PREVIEW
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#endif

void SceneDepthLOD_float(float2 UV, out float LinearDepth)
{
#ifdef SHADERGRAPH_PREVIEW
LinearDepth = 0;
//EyeDepth = 0;
#else
float RawDepth = SAMPLE_TEXTURE2D_X_LOD(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(UV), 0).r;
LinearDepth = Linear01Depth(RawDepth, _ZBufferParams);
//EyeDepth = LinearEyeDepth(RawDepth, _ZBufferParams);
#endif
}

#endif // SCENEDEPTH_LOD
#

(mostly to move the #include out of the function body as that might be causing some errors)

supple kayak
#

Yes! That worked, huge huge thanks

latent rampart
#

@devout quarry What I needed just wasn't there. I was kind of looking for something that just paints on the edges of a material so the seams between objects are more visible. My example was from Stormworks, in-game all those cubes that make up the boat are seamless but in editor each has a sharp black seam. Maybe I just need to have a custom texture for each shape to get a similar effect? Kind of a pain to do it that way though. My bounding box selection is kind of a temporary solution at the moment until I sort out something better.

devout quarry
#

You could just make a shader in that case for a cube that shows black edges? For the white you could just a texture.

But for non-cubes this would get more difficult.

#

Otherwise I'd say use edge detection (if you want to get inner-object lines)

latent rampart
#

@devout quarry yeah I have some other shapes that are more complex, edge detection looks better for sure. Per your prior information, I should be able to do edge detection and enable it just for the objects I want.

sonic nacelle
#

I'm on the latest version of URP. Why can't I find this asset type?

warm pulsar
#

what unity version are you on?

#

this will affect which version of the URP package is available

sonic nacelle
#

2021.3.6f1

#

@warm pulsar

warm pulsar
#

Yeah, that won't have the fullscreen graph (or the relevant full screen pass renderer feature)

#

I believe that was part of URP 14, which requires Unity 2022.3 or newer

sonic nacelle
#

guess it's time to upgrade?

warm pulsar
#

I vaguely remember DIYing this in a 2021 project

#

but if you have no major obstacles to upgrading, i'd consider it

sonic nacelle
#

I mean I do have low storage space but honestly if I can manage to upgrade I'd have less space taken up because then I can delete the android module

#

that thing takes up like 15 gb

#

wait no it's 6

#

woah what in the world is 6000

#

That definitely breaks the previous naming convention

warm pulsar
#

version numbers strictly increase with each release

#

therefore, making the new version be 6.x.x would be wrong, because that's less than 2023.x.x

#

hence 6000

sonic nacelle
#

oh is it like a completely new type of version

#

I was expecting like 2025 or 2024 or something

warm pulsar
#

@royal bloom the shader graph would be pretty simple

royal bloom
#

i never touched them before

warm pulsar
#

something like this

royal bloom
#

it would be lit right?

warm pulsar
#

Yes.

royal bloom
#

so behave like the normal material

warm pulsar
#

a lit shader graph lets you create something that looks a lot like URP/Lit

royal bloom
#

do i have to select transparent here?

warm pulsar
#

do you want to be able to actually see through this shader?

#

i thought the idea was to fade between the texture and a solid color

royal bloom
#

true

royal bloom
#

like will i have the other options on the material

warm pulsar
#

No. You will have to re-implement those.

#

not terribly hard, but a bit of busywork

royal bloom
#

at this point it might be easier to just duplicate the face mesh in front of the face by like 1mm

stoic flint
#

anyone knows why im getting these white dots artifacts at distance? i have mipmapping enabled for the textures already..

#

close to camera is fine

#

this is what the shader is doing

  float noiseValue = tex2D(_NoiseMap, uvNoise).r;

  // Smooth texture blending
  if (noiseValue < _Treshold1)
  {
      return tex2D(_Texture1, uv1);
  }
  else if (noiseValue < _Treshold2)
  {
      float blend = (noiseValue - _Treshold1) / (_Treshold2 - _Treshold1);
      return lerp(tex2D(_Texture1, uv1), tex2D(_Texture2, uv2), blend);
  }
  else if (noiseValue < _Treshold3)
  {
      float blend = (noiseValue - _Treshold2) / (_Treshold3 - _Treshold2);
      return lerp(tex2D(_Texture2, uv2), tex2D(_Texture3, uv3), blend);
  }
  else
  {
      float blend = (noiseValue - _Treshold3) / (1.0 - _Treshold3);
      return lerp(tex2D(_Texture3, uv3), tex2D(_Texture4, uv4), blend);
  }
wispy fog
#

how can i use nature/soft occlusion shaders if i am using a urp 3d template?

warm pulsar
#

I want to capture the look of a "brilliant diamond" with a shader. I'm trying to figure out what makes it look like this.

I'm guessing there's a ton of very complicated refraction going on.

warm pulsar
#

If it looks identical with mipmap 0, that suggests it's not actually picking the right mipmap

#

I know that tex2D selects the mipmap based on the derivative of the UV coordinate

stoic flint
#

yeah i tried it before and yeah its a mipmap problem

#

seems likee derivative getting fkd or sth by gpu?

warm pulsar
#

I wonder if it's getting confounded by the branching

stoic flint
#

probably

#

im not sure

warm pulsar
#

any warnings in the console when you compile the shader?