#archived-shaders

1 messages · Page 238 of 1

silent fulcrum
#

Yay thanks!!

drowsy linden
#

What does this error mean?

res[ //Here
                ((id.y * 8 + y) * width) + //get y position in flattened array
                (id.x * 8) + x  //add x position
            ] = textureToRead.Load(width - y, width - x); //Read texture
brittle owl
#

not sure if this is a shader issue or a particle issue, i made a shader in shader graph that has transparency but it doesnt render transparency when i use it for the material of a particle

#

here are my shader settings

drowsy linden
# drowsy linden What does this error mean? ``` res[ //Here ((id.y * 8 + y) * wi...
#pragma kernel ReadFileToArray //id 0

Texture2D textureToRead;
Buffer<float> res;
uint width = 256;

//Read a chunk of the texture
[numthreads(8,8,1)]
void ReadFileToArray(uint3 id : SV_DispatchThreadID)
{
    for (uint x = 0; x < width; x++)
    {
        for (uint y = 0; y < width; y++)
        {
            res[
                ((id.y * 8 + y) * width) + //get y position in flattened array
                (id.x * 8) + x  //add x position
            ] = textureToRead.Load(width - y, width - x); //Read texture
        }
    }
}

So it looks like res is defined as const? how do I define it as mutable?

shadow locust
#

rw_structured_buffer

#

is what I've always used

#

maybe there's an RW_Buffer

astral summit
#

Nvm figured it out 👍

drowsy linden
#

Ooooh right the RW thing

drowsy linden
#

there may be a few problems

drowsy linden
#

frocing platform preprocess gives the same result...

gentle parcel
#

Could I get some help figuring out why I cant get the LOD's cross fading working?

#

The function im using to access the LODFade is

if(unity_LODFade.x > 0) {
    LODFade = unity_LODFade.x;
}```
#

Despite this it seems to just flicker between culled and rendered when I zoom in and out

#

Does it work with sprite renderers?

#

I dont see why it wouldn't but it seems to only be working on 3D objects

#

I'm guessing that's why. Does anyone have a work around?

mortal thunder
gentle parcel
#

Yeah. . . I’m making an RTS so I have a lot of objects on screen

#

Otherwise yeah it’d be pretty ridiculous to have so many

#

The thing is LOD’s work but not the fading part

#

Like it’ll cull them

#

But it doesn’t seem to return a unity_LODFade.x value

mortal thunder
#

What if you just fade it by distance of player or camera. when it reaches a value of 0 or something disable the gameobject? I'm just making guesses here.

gentle parcel
#

I thought of that but then I remembered I’m using a orthographic camera so it’d have to be based on camera “size”

#

But not too sure how to get that into a shader

mortal thunder
#

Add a fade value modifier that you could adjust in a c# script?

gentle parcel
#

That could work I’m not too familiar with how those interact though. Is it just like a component? Or how would I start that

#

Actually nvm lemme google it first it’s prob really easy isn’t it

glad siren
#

Texture rendering depth in wrong order at certain angles

mental bone
gentle parcel
mental bone
#

How ever Im not sure how that will help

#

The size will be the same for all sprites

#

Unless you want to LoD All of them when you zoom out

gentle parcel
#

I’m sure I can figure something out 🤷‍♂️.

gentle parcel
#

So that helps

mortal thunder
gentle parcel
#

😂 well you bounced ideas at the very least

twilit shard
#

I am trying to disable srp batcher for one shader to be able to use gpu instancing on that shader. I copied the shadergraph shader over and added a property but it is still compatible with srp batcher:

twilit shard
# twilit shard

nvm I am stupid. Just delete the cbuffer declaration and you are g2g

glad siren
#

Is there any way to make Shadergraph Properties look more like URP shaders (in the inspector I mean) and have a neat UI like this ?

abstract adder
glad siren
edgy crane
#

Hello beautiful people. I'm currently playing with shader graph right now to make a distortion effect for water. I followed some tutorials on youtube but I want to really at least understand what I'm doing. I am playing with the Screen position and Screen Color nodes but I can't manage to distort what's behind a simple square. Can somebody take a look and tell me if I did something wrong ?

glossy crane
#

Hi all, is it possible to write shader in built in RP to get visual like HDRP?

mental bone
#

Possible ? Yes in a way. If you write a custom lighting solution as well

#

At that point you might want to write your own render pipeline

fervent tinsel
#

biggest difference would be that dynamic light falloff.. if you only do baked lighting, then it would be easier

dim yoke
#

And at that point you could just choose hdrp 😄

fervent tinsel
#

or URP

dim yoke
#

Making shader (from scratch) that has even visuals like birp default shader, you have to put in a lot of work so it’s not gonna be easy anyways

glossy crane
#

I see. Let's say if I intent to create something performant for mobile, like water shader.. I tried with URP +shader graph once.
And it took a lot of draw calls when testing it on mobile device. The testing device is of course is a budget phone (xiaomi redmi note 6 pro). But a game like wild rift looks fine and great with decent visual and fps. Any advice?

thorn tapir
#

Hey can I use a shader to interpolate or tween between two sprites smoothly?
all thats changing is the color of the sprites, but I want a smooth gradient transition between the two

#

actually nevermind I got it, it was really simple
just a blend node with a slider for the opacity

#

and an overwrite mode on the blend

white sundial
#

i decided to copy some shader from one project to another
but it just doesnt work

#

thats the preview

#

any ideas?

night hare
#

What rendering pipeline did that project use?

white sundial
#

urp

#

I imported it to this one

night hare
#

You cannot transfer a URP Shader to BiRP

#

From what I know

#

search the internet for a method

white sundial
#

urp to birp?

#

what?

night hare
#

built in render pipeline

white sundial
#

can't I just import URP anyhow

distant zealot
#

Hi yall! As you can see, my texture is behaving a bit odd. The image on the left is the original png, and the checkerboard bit is the transparent area. In Unity, despite checking "Alpha Is Transparency", the texture's got this weird brown/black area on it. Anyone know what I need to change to make ths mesh actually transparent where the texture is?

#

also, is this the correct channel?

knotty juniper
formal rivet
#

Hi, does anyone know what the max texture count for hdrp shaders is? I saw some DX11 thing that said that 16 is the max but I seem to be able to make shader graphs with more textures than that

drowsy linden
zenith heron
drowsy linden
#

Ok sometimes software asks me to file a bug when really I did something dumb

zenith heron
#

oh it does

drowsy linden
#

so i was wondering if it was real or not

distant zealot
knotty juniper
knotty juniper
onyx nexus
#

does anybody know how to make a shader so the closer you get to an object it disapears

shadow locust
#

The camera node and the object node in shader graph give you the camera and object positions

#

Simple enough to go from there

drowsy linden
# drowsy linden uh oh

so what causes this? my code is

#pragma kernel ReadFileToArray //id 0

Texture2D textureToRead; //texture to extreact heightmap data from
RWBuffer<float> res; //resulting flat array
uint width = 256; //width of the image

//Read a chunk of the texture
[numthreads(8,8,1)]
void ReadFileToArray(uint3 id : SV_DispatchThreadID)
{
    [unroll(256)] for (uint x = 0; x < width; x++) //columns
    {
        [unroll(256)] for (uint y = 0; y < width; y++) //rows
        {
            res[
                ((id.y * 8 + y) * width) + //get y position in flattened array
                (id.x * 8) + x  //add x position
            ] = textureToRead.Load(width - y, width - x); //Read texture
        }
    }
}

meager pelican
# onyx nexus does anybody know how to make a shader so the closer you get to an object it dis...

A follow up to the previous tutorial, I show you how to use dithering in Shader Graph to fade out meshes when they are close to the camera.

Previous Tutorial
https://youtu.be/iTlSwQ4b-uM

(づ ̄ ³ ̄)づ ~(˘▾˘~)

TWITCH ( ͡° ͜ʖ ͡°)
https://www.twitch.tv/PabloMakes

TWITTER (ಥ﹏ಥ)
https://twitter.com/PabloMakes

₪ ₪ Time Stamps ₪ ₪
00:00 - Int...

▶ Play video
drowsy linden
#

hmm. Can I force my froject to use Vulkan instead of DirectX?

distant zealot
drowsy linden
knotty juniper
drowsy linden
#

well maybe unity wont crash my graphics card as often because it seems to overload the D3D swapchain often

frail violet
#

how does one make a depth mask with Unity 2020. In unity 2019, I was able to use the depth mask shader example, but that shader code doesn't seem to work in Unity 2020

lean lotus
#

How I increase this so its not an issue for now?

gentle parcel
#

Would anyone be able to help me? I'm messing with shaders and despite the fact that im editing the float attached to the alpha value it doesn't seem to actually change the alpha value.

#

It remains completely opaque in other words

#

I'm confused it seems like I can feed it a gradient and the dark spots will cut holes but I cant actually effect alpha directly

icy totem
#

Is it possible to make shader tiling?

gentle parcel
#

Yeah, I recommend just looking it up on youtube plenty of guides there on that

dim yoke
#

You can untoggle alpha clipping if you use transparent

gentle parcel
#

Hmm let me see

#

Ahh yes it was opaque. Thank you!

mortal thunder
#

So, I figured out my previous issue with my shader and now I'm trying something different... I want to create some sort of Vertex Wave Effect along the edge of the Noise. Any chance someone can help me out? I'm not using Shader Graph for this project...

ornate silo
#

It will create an imperfect wave effect that isnt super jagged

mortal thunder
ornate silo
#

Are you trying to create a texture?

#

I'm sorry I dont actually know what a vertex wave effect was I just thought you meant you wanted a texture that looked wavey

ornate silo
#

Ah my bad then

thick jungle
#

How I can reference a HDR color via script?

edgy crane
ornate silo
#

Does unity have a built in simplex noise or perlin noise for 3d?

ebon ivy
#

Does anyone have a sprite shader that does Zwriting and cutout alpha?

#

The standard one appears to use a transparant render queue which messes stuff up

knotty juniper
ebon ivy
#

After some more googling

#

What I'm looking for is a sprite cutout shader for URP

jade locust
#

I currently try to figure out saturation and value (brightness) and I have a strange error. As you can see i currently pass out 3 values to check them I get:
maxChannel = 0.6313726 as intended
minChannel = 0.4941176 also correct
but delta = 0.4196079

#

The intended result should be 0.137255 but I cant figure out why the value becomes 0.4196079. Does someone know?

#

The hex code for the color that i try to test is: A1957E

meager pelican
# jade locust I currently try to figure out saturation and value (brightness) and I have a str...

Well, you're using halfs...you might want to try floats for fun but I don't expect that's the problem.

But let's see. For color A1957E that's max 0.6313726 and min 0.4941176 as you said. Check.
Delta (max - min) should be 0.137255. Check.
Now, how do you know it is 0.4196079? Where did that come from and how did you get it?
S and V you don't use (yet).
So I'm assuming you're checking the red channel result? But that could be color corrected or otherwise messed with later in the shader or even in the pipeline (like gamma correction).

unreal verge
#

@regal stag Hey Cyan, I've been working with your Blit Render Feature and have been updating it to work with RTHandles under Unity 2022.1.0b14.2951. It's working for the most part, it's just not completely bulletproofed yet. Ping me if you're interested.

edgy crane
#

Guys, let's say I have a sprite

#

I want to apply a shader so that the top of the sprite ( and the top only) shift by a pixel or two

#

How should I proceed ?

#

Something like this (my art skills are beyond this world I know I know)

spark stone
#

error: Parse error: syntax error, unexpected TVAL_ID, expecting TOK_SETTEXTURE or '}'

#

line 15

bronze wraith
#

anyone know how to make this kind of toon face shadow?

tame topaz
jade locust
#

If I add the two channel's I get a result around 0.88 and I really don't know why.

#

I didn't exit the saturation and the value yet because I noticed that the two values are incorrect.

bronze wraith
#

user manual didnt say anything about this

dim yoke
night sequoia
#
    {
        
        float4 frag(v2f_img input) : COLOR
        {
            int pxIndex = input.pos.x*_Scale; 
            int pyIndex = input.pos.y*_Scale;
            uint matSize = 4;
            float4x4 mat = { 1, 8, 2,10,
                    12,4,14, 6,
                    3, 11, 1,9,
                    15, 7 ,13,5
                    };
            mat = mat / (matSize * matSize);
            int pxIndex = input.pos.x; //x index of texel
            int pyIndex = input.pos.y; //y index of texel
            float4 base = tex2D(_MainTex, input.uv);
            float c = (base.r + base.g + base.b)/3;
            //get which index of dithering matrix texel corresponds to
            int mati = pxIndex % matSize;
            int matj = pyIndex % matSize;
    
            //quantization
            if (c > mat[mati][matj]) { c = 1; }
            else { c = 0; }
            return c;
            return lerp(_BackgroundCol, _ForegroundCol, c);
        }
    }
#

Beginner here, why does this say that theres an unexpected Tval_ID in this part?

#

specifically the line float4 frag(v2f_img input) : COLOR

low lichen
night sequoia
#

thanks bro

night sequoia
#

nvm that still has the same error

#

ill send the whole script

#
{
    Properties
    {
        _MainTex("Texture", 2D) = "white" {}
        _BackgroundCol("Background", color) = (0,0,0,0)
        _ForegroundCol("Foreground", color) = (0,0,0,0)
        _Scale("Scale",float) = 0
    }
    SubShader
    {
        
        float4 frag(v2f_img input) : SV_COLOR
        {
            int pxIndex = input.pos.x*_Scale; 
            int pyIndex = input.pos.y*_Scale;
            uint matSize = 4;
            float4x4 mat = { 1, 8, 2,10,
                    12,4,14, 6,
                    3, 11, 1,9,
                    15, 7 ,13,5
                    };
            mat = mat / (matSize * matSize);
            int pxIndex = input.pos.x; //x index of texel
            int pyIndex = input.pos.y; //y index of texel
            float4 base = tex2D(_MainTex, input.uv);
            float c = (base.r + base.g + base.b)/3;
            //get which index of dithering matrix texel corresponds to
            int mati = pxIndex % matSize;
            int matj = pyIndex % matSize;
    
            //quantization
            if (c > mat[mati][matj]) { c = 1; }
            else { c = 0; }
            return c;
            return lerp(_BackgroundCol, _ForegroundCol, c);
        }
    }
    FallBack "Diffuse"
} ```
mortal thunder
#

Does anyone have experience with VRChat ShaderGUI's?

shell walrus
#

Is it possible to break up lines in shadergraphs in later unity versions? i.e like pins in substance designer?

shadow locust
south pecan
#

Hi, does anyone know a good tutorial to get this kind of flat color shader? I'm new to Unity.

sinful cairn
#

I've got an HLSL that I was using in a custom function in Shadergraph in an older project, but it no longer works in 2020 with the latest shadergraph for that unity version. It complains about the #if as an invalid conditional, but also doesn't recognize GetAdditionalLightsCount. Is there a replacement for this? And is there a place I can see what custom lighting functions are available?

void AdditionalLights_half(float3 WorldPos, out half3 Color, out half Attenuation, out half LightAmount)
{
#if SHADERGRAPH_PREVIEW
    Color = 1;
    Attenuation = 0;
    LightAmount = 0.5;
#else
    int additionalLightsCount = GetAdditionalLightsCount();
    
    float attenuation = 0;
    half3 direction = 0;
    half3 color = 0;
    float lightAmount = 0;
    
    for (int i = 0; i < additionalLightsCount; ++i)
    {
        Light light = GetAdditionalLight(i, WorldPos);
        color += light.color;
        //attenuation += light.distanceAttenuation;
        attenuation += light.distanceAttenuation * light.shadowAttenuation;
        lightAmount += (1 - (light.distanceAttenuation * light.shadowAttenuation));
    }
    
    Color = color;
    Attenuation = attenuation;
    LightAmount = lightAmount;
#endif
}
#

Even better, is there a node that does the same thing? i.e. gets the amount of light shining on the fragment from point lights /spot lights / etc.

regal stag
# sinful cairn I've got an HLSL that I was using in a custom function in Shadergraph in an olde...

v10+ should use #if defined(SHADERGRAPH_PREVIEW) (or #ifdef SHADERGRAPH_PREVIEW), not just #if.
It will also only work in URP (forward path). And if you want this to work with point/spot light shadows, you may need to add a third parameter to the GetAdditionalLight function (half4(1,1,1,1) should do).
I've also got some similar functions/subgraphs here : https://github.com/Cyanilux/URP_ShaderGraphCustomLighting/blob/main/CustomLighting.hlsl

To see which functions are available check the ShaderLibrary for the pipeline. Should be in the package folder, or see the github, e.g. URP : https://github.com/Unity-Technologies/Graphics/tree/master/com.unity.render-pipelines.universal/ShaderLibrary (mostly Lighting.hlsl, RealtimeLights.hlsl (if 2021.2+) and Shadows.hlsl)

sinful cairn
#

That got rid of the error for the #if, though GetAdditionalLightsCount is an undeclared identifier, and yet in that first link I can see it being used exactly as I'm using it, so not sure what's going on there

#

Line 152

regal stag
# night sequoia ``` Shader "Custom/Dither" { Properties { _MainTex("Texture", 2D...

This is missing a lot of shader syntax. Such as Passes, CGPROGRAM and ENDCG tags for the hlsl section, #pragma fragment and #pragma vertex to define the shader programs and there's no vertex shader either, though it may be in an include file which isn't being included either, like #include "UnityCG.cginc".
You should check the template when you create a new unlit shader, and look up some beginner shader tutorials

regal stag
sinful cairn
#

@regal stag Got it working, was missing the CUSTOM_LIGHTING_INCLUDED defines at the top, like in your code

#

Or at least, no more errors. Still gotta test 🙂

regal stag
#

Those defines are used to prevent the hlsl file being included multiple times in the generated shader, if multiple Custom Function nodes are used

sinful cairn
#

Well, adding them got rid of the error about GetAdditionalLightsCount being undeclared

#

Thanks for the help, I'll have a closer look at your shader code to try and better understand it all

dim yoke
#

You can try to learn lighting, shadows and outline post processing effects separately tho. I think it would be easier to do that in built in render pipeline because birp shaders are somewhat easy to write and shader graph on the other hand doesn’t give much control over lighting and shadows. (That’s also such simple art style you don’t need any special features of srp)

lean lotus
#

Hey so im trying to get world space normals by applying a CameraToWorld matrix to the _CameraDepthNormalsTexture that is generated by unity by default in a compute shader after getting the normal by running it through DecodeDepthNormal, but for some reason, applying the transform to the normal calculated(so the normals dont move with the camera) causes normals facing a certain way to flicker, why is this?

#

specifically the transform causes vectors facing in the -Z direction to flicker a lot

lean lotus
#

this is what its doing and idk why...

south pecan
edgy crane
#

Hey guys, I have this effect right there but I would like the shift to be progressive along the X axis, like a wave (this is for a 2D water texture). I can't get what I'm looking for but I guess it involves Sine. ANy help is appreciated ❤️

grand jolt
#

Is it bad if I rely on branch prediction and branch on the same uniform like 8 separate times(not nested ifs)?

#

Since the uniform is the same across the wavefront, I'm good even on mobile GPUs, right?

meager pelican
#

Well, it's not "crossing the streams" type of bad. I mean they ARE uniform. That said, if you have to do it 8 times, one wonders if you cannot further optimize things.

grand jolt
#

Well, I didn't want to write the same code 8 times for each possible layer value. So I made a macro that switches on the layer and samples the correct textures that have that layer index in their name.

#

Can't put samplers in an array.

meager pelican
#

OK, texture sampling. Now we're into DTR....Dependent texture reads?

#

Or maybe not.

#

Does one texture depend on the results of another texture's read/sample?

grand jolt
#

No.

meager pelican
#

OK, good.

grand jolt
#

It's all to sample a bunch of textures and floats that have the layer index in their property name.

meager pelican
#

But based on a uniform?

grand jolt
#

Based on a texture mask value.

proud wharf
#

Why doesn't it work?

meager pelican
#

I'm stupid, spell it out, Beat.

grand jolt
#

The layer index is encoded in the texture channel.

#

We decode it back and round it to layer index.

meager pelican
#

That sounds like a DTR to me. Like is often done in terrains.

#

So you need the results of one sample to make another one.

grand jolt
#

Yeah. And I figure branch predictor can handle the same condition being tested for each layer property innit?

meager pelican
#

DTR's are the bane of optimizations everywhere. But I'm no expert, Beat. I know that I'd research DTRs though.

proud wharf
grand jolt
#

I can't get rid of DTR. The mask sampling will stay.

#

It's the branches like if(layer==0) float4 a = _AlbedoTex0

meager pelican
grand jolt
#

That worry me.

meager pelican
#

I see. Well, once you get the result the IF probably isn't going to be much, it's "just" computational. It will have to evaluate them all but it should be "just math" basically.

#

It doesn't look like it's doing a ton of stuff, just an assignment, or not.

grand jolt
#

Yeah, but if I do the ifs again for every single layer texture like albedo, normal separately, would it be free?

#

Theoretically it should all get optimized down to 1 if.

meager pelican
#

Well, it still has to do the work. But it could be waiting on other results.

meager pelican
#

It it set at compile time?

grand jolt
#

Because all the ifs depend on the same layer value.

meager pelican
#

That doesn't make it "free", it just avoids excess execution of an "else" side.

#

Which is a good thing.

#

LIke

grand jolt
#

I know. That's what I want.

meager pelican
#

OK, then sure.

grand jolt
#

It's just that this is gonna be used in Standard, URP and HDRP projects for PC, consoles and mobile and VR 👀

meager pelican
#

Wow. I'd benchmark my a$$ off

grand jolt
#

I only have a weak laptop that can run HDRP demo in 12 FPS 🥲

#

Not exactly a benching setup 😂

meager pelican
#

So just to be clear...

#

And I'm sure you know this, and want comforting confirmation that I cannot give, but...

#

If you have

#
big bunch of true stuff;
} 
else {
big bunch of false stuff;
}

with a uniform you can get decent performance by executing **either ** the true side or the false side but not both. Whereas if it isn't uniform you get the performance impact of both if any one or more cores has to follow a different path then all cores have to wait for it while masked off.

#

Otherwise, if's are ifs, for simple things. Like a bunch of if's in a row.

grand jolt
#

Yeah.

meager pelican
#

My guess is 8 simple if's lined up aren't too bad unless you have to go out to texture memory and do more sampling for each of them or something.

#

Sampling is slow, but the time is hidden by time-slicing all the work across the "wave(s)", so it sets up the sample, and then goes off and does another set of pixels, then returns back...latency hiding.

#

But if you have to "stack" samples, that's where you get the performance hits, hence DTRs.

All IIUC.

#

But if's are if's, really. Much like a cpu, if you're following uniform paths. The trick is to remember that all cores share one program/instruction counter.

#

You know all this Beatrate!

grand jolt
#

Yeah. But idk how smart the HLSL compiler is so I guess I'll combine the layer if bodies together myself in a giant macro with layer as the parameter.

meager pelican
#

I suspect that
[branch]
doesn't really mean much anymore (there's a Unity version of it something like [UNITYBRANCH]), but you might want to see if it makes any difference in what you get for results.

#

The optimizers will move texture reads up top IF they can. That is if there's not DTR's that need the results of a prior texture sample.

grand jolt
#

Alright.

#

Thanks.

jade locust
# jade locust I currently try to figure out saturation and value (brightness) and I have a str...

Good Evening I currently search for a way to get saturation and brightness (value) in a Render Feature shader URP. I already tested a few but somehow as soon as I try to add or subtract the results are just wrong. I replay on my old post where I show my tests, if you have any idea what could be wrong or have any confirmed working solution I would love to see them :). I only need the brightness and saturation to check for black or white colors on the screen and afterwards manipulate the color.

pliant falcon
#

hi there
quick question, how can I create PBR shader graphs? is there a package that's required for that?

dim yoke
pliant falcon
#

aight I'll try taht

wary jackal
#

Hi, I'm making a surface shader and sampling a few textures. I'm not sure why, but the tiling and offset aren't working. The Main Texture offset works, but the Scroll Texture 1 and 2 don't work. Can anybody explain this?

shadow locust
#

I mean you'd have to show the actual shader code, no?

wary jackal
#

You're right, but I figured it out anyways 🤦‍♂️

#

I was attempting to use the MainTex uv instead of creating a new UV for the scroll textures

#

I was assuming that it was something that automatically worked, but I guessed wrong.

grand jolt
#

where can i talk about menu please ?

frosty linden
#

Can anybody explain me how it's possible to have that many variants out of 12 shaders used and 15 variants? I've upgraded from Unity 2019 recently and I don't remember having such issues before.

#

I've tried the preload shader option already but it's not changing this number

#

I only have 2 models in my game at the moment, coming from Daz3D and I'm using one hair shader and one skin shader purchased on the unity asset store. I don't get where those variants are coming from.

#

Plus my project only seem to have those 2 shaders too. I don't understand what's happening

arctic flame
#

hey everyone

#

in unity's shader language how to i affect one component of a vector?

#

i tried to seperate like this but it didn't work correctly once i did that

#

for that matter how do i simply multiple the two vectors component wise? they don't seem to be doin that

regal stag
# arctic flame

You're mistakingly using the comma operator again. It should be = float2(IN.screenPos.x, IN.screenPos.y) or just = IN.screenPos.xy

arctic flame
#

oh, right, yeah.

#

i remember now

#

it considers it to be two sequential statements doesn't it

regal stag
#

Yea something like that. Carpe explained it before. Can search to find it.
(I wanted to link but I'm on mobile and can't see a way to copy the message link)

arctic flame
#

mm

#

i forgot from last time

regal stag
#

Also multiplying component-wise is what the * operator does

regal stag
# frosty linden Can anybody explain me how it's possible to have that many variants out of 12 sh...

I don't use HDRP but the HDRP/Lit in particular is going to have a lot of variants. It uses multi_compile and shader_feature so it only needs to do certain calculations if the keywords are enabled, usually done automatically by the material inspector. Could be things like enabling alpha clipping, normal maps, etc.

Afaik you shouldn't need these shaders in always included, (which I assume includes all their variants). The shader will be included in the build as long as it's referenced by a Material in the scene. And then with shader_feature, only the variants being used will be compiled so that number is usually much smaller.

I think could also look into the ShaderVariantCollection if you need preloading. But I'm not that familiar with it.

frosty linden
#

So basically, 1 hour for 120M so 2M per minutes... let's round the total to 4billions, I'll need 2Billions minutes to complete the build.

#

How is that possible lol

#

There must be some kind of cache or configuration I missed.

#

HDRP/Lit has 118 variants

#

I'm still FAR from those 4billions found by the script...

#

214 variants for my hair shader

#

21 for the skin

#

Where does the rest popup up from? Are there any logs?

#

I don't know how to code shaders so everything is purchased and I don't dare to modify the code. But again, it's hardly possible for my project to reach 4billions variants. I'm also 99,99999% sure no project in the world would have that many variants. So how the hck does Unity reach this number?

regal stag
# frosty linden HDRP/Lit has 118 variants

Those variant numbers are only including the ones currently compiled by the project. Unticking the "Skip unused shader_features" option might show you the full amount.
Either way, you shouldn't need these shaders in the Always Included Shaders list.

frosty linden
#

Ok, I'll try to empty the list and give it another shot

regal stag
#

I'd probably leave the ones Unity adds there by default or it might break things. But the last 3 you shouldn't need there.

frosty linden
#

is there a way to restore the default settings ? already emptied the list :x

regal stag
#

Eh, maybe by deleting the GraphicsSettings file in the ProjectSettings folder under your project. That might cause it to regenerate it with defaults, but not sure. Should probably back-up just in case. Would need to reassign render pipeline asset too.

frosty linden
#

Got it, I'll just fill it manually since I have the screenshot actually

stray orbit
#

hello, is there a list of correct names for the references for each texture you use like the smoothness or normal texture?

#

like you have _MainTex for certain shaders not sure if it's only sprites but i know it's used in those

jade locust
#

I currently try to figure out saturation and value (brightness) and I have a strange error. As you can see i currently pass out 3 values to check them I get:
maxChannel = 0.6313726 as intended
minChannel = 0.4941176 also correct
but delta = 0.4196079.
I try to debug the values that's why I exit these 3 :) and it's a shader for a Render Feature. I tried to swap the variables around have the delta be the b value or the g value but result is always the same. Max channel and min are correct and delta is around 0.41. can anybody help me with that?

amber saffron
#

How do you debug this ?

#

If you're looking at a rendered color using a color picker, there is maybe some linear/sRGB conversion.
Taking (roughly) your numbers :
( 0.6313^2.2 - 0.4941^2.2 ) ^.4545 = 0.4241

Pretty close to the 0.4196 you've stated.

jade locust
#

So I guess I will have to calculate it backwards to get the accurate saturation

#

Are 2.2 and .4545 fixed value's?

amber saffron
#

Not really "fixed", it's just the closest aproximation to do gamma/linear conversion 😅
.454545.... is 1/2.2

#

Note that : (.6313 - 0.4941)^.4545 = 0.4054 is also close-ish to your result

#

So my understanding is : you might have the proper delta value, but once rendered and displayed by unity with gamma correction, you are reading the wrong value back

jade locust
#

Okay thanks 😅. I do use a colour outline effect but the white in the eyes is hard to notice with the outlines. I have a colour full style so there actually no black and white on the screen elsewhere. So I try to calculate that the shader ignores colours with low saturation

jade locust
hushed urchin
#

Is it possible to set DisableBatching for shader graph?

polar coral
#

yo guys. do u have some advice on how i would tackle this problem.
my internship mentor wants me to make the textures more realistic. but like all bosses they dont really have an idea on how long something takes.

so do u guys have any tips / advice on making a good texture for the gray garden path parts. kinda scifi. like a smart pipeline. good result and not a lot of stupid mindless work.

one thing im already gonna do its the edge tear/effect and stuff which my best example for something that is smart rather then heavy in work

sinful cairn
#

What's the trick for making shaders work on flat ground planes? My shaders work fine on walls, but when placed on the ground they're just a solid colour.

#

And we're talking a simple shader here, just a Tiling and Offset, to Fraction, to Rectangle, and out to the Fragment Base Color

#

But instead of a white rectangle with a black border, I just get solid black if it's on a floor panel. But if the surface is a wall, it works fine

frosty linden
sinful cairn
#

@shadow locust
I'm importing sketchup files, so there's no UV mapping happening (AFAIK). Though this never seemed to be a problem when I was last working on this project
So guessing I have to "project" the existing UV differently in the shader?

shadow locust
#

IDK anything about sketchup but yeah if there's no UV map on the mesh then the shader isn't going to know how to project the texture onto it

#

UVs are how the shaders know how to project textures onto the 3D model

sinful cairn
#

So by default, if there's no UV, it projects onto XY, and not XZ
Since UV is just a vector2, not sure how I'd change that

shadow locust
#

if there's no UVs the whole model just has 0,0 as the UV coordinate pretty sure

#

which means the whole thing will be whatever color is in the top left corner of your texture

sinful cairn
#

So something else must be going on, because when I import other sketchup files that are vertical, procedural nodes map to them just fine

shadow locust
#

you can inpsect the UV map of your model in Blender to rule that out

sinful cairn
#

I've got a hacky fix. I get the fragment's position in relation to the object, extract the X and Z, combine those together to make the UV, offset it by 0.5,0.5 with a Tiling and Offset node, and then the Rectangle node can correctly map to it

kindred jackal
#

Hi all, I'm trying to write my own hlsl lighting shader (based on this tutorial: https://nedmakesgames.medium.com/creating-custom-lighting-in-unitys-shader-graph-with-universal-render-pipeline-5ad442c27276) and I can't seem to access the main light from my shader code:

https://www.paste.org/121725

Unity keeps throwing an error, that the identifier "Light" is undefined. Shouldn't the necessary hlsl shaders from URP be automatically included by unity? Or am i missing some include statement or something?

#

The shader graph is configured as follows:

regal stag
kindred jackal
#

I see, ill give that a try, thanks!

lean lotus
#

Hey would it be faster to use a compute shader to copy 3 textures
or would it be faster to use 3 invocations to Graphics.CopyTexture?

soft jacinth
#

having some trouble with this object space shader, basically trying to sample a color based on the position.

#

but with the way my map generation works, I have integer values for the position.. so the entire level is the same color!

#

as you can see above only by offsetting the objects manually do I get proper color lerping

#

I've tried adding a tiny digit to the object space to virtually offset it but no luck.. any idea appreciated. 🙂

stiff arch
#

hi, need someone to point me in a right direction:
a) a way to pass a world position vector to the shader and use it in it's space correctly, relative to the world position
b) a way to displace vertices or adjust the texture (make transparent) at a certain spot

need those things to create a destruction system. namely gore system. being able to show a mesh under a mesh at specific points.

dim yoke
soft jacinth
#

sorry for the confusion there, and thanks anyway! I'll figure it out when I know the technique I want. 😆

dim yoke
soft jacinth
#

The original idea was to get an objects position and apply a color by sampling a gradient. The banding I'm referring to is for example X has color blue, X + 1 is color red, and X + 2 is color green..

#

which actually I'm not getting multiplying after the fraction, so that's why I didn't mention it with the current example.. I've been trying lots of different node setups. The one pictured above is giving me a flat color, and only changing per-object if I offset the object so it's not an integer

#

which the fraction is doing, so because there is no floating point value it stays solid until I give it an offset to work with.. it makes sense why it's not working I guess I'm just not sure how I would go about fixing it.

#

and that's where I settled in realizing, this is probably not the method I'm after anyway, the result if it were "working" would give me harsh solid colors which I need to blend between so the tiles don't stand out.. splatmapping is probably the way, so it's all good. 🙂

past kraken
#

how to make colored emission effect like this (sprite is white, but emission is not white) in unity's shader graph?

soft jacinth
#

what you see is bloom I think

#

set the emission property to a blue HDR color + bloom

soft jacinth
#

If you create a standard lit graph the emission field should be exposed to you @past kraken

#

or go to the graph inspector

#

under material

#

lit/sprite lit depending

past kraken
#

i know how to do it.

#

dont think sprite renderer supports non-sprite shaders

soft jacinth
#

how to make colored emission effect like this (sprite is white, but emission is not white) in unity's shader graph
This question has been answered then.
To make a sprite shader emit you need to do the above.

grizzled bolt
#

@past kraken If you want to give an "emission intensity" to an unlit shader which doesn't support "emission" to get bloom glow, you can multiply the base color to increase color values above 0-1 range

past kraken
#

lit does not have emission property too btw

soft jacinth
#

your question is too vague to be answered properly.. try to formulate it

past kraken
#

anyway, emission is not working

soft jacinth
#

anyway, try introducing bloom

past kraken
#

you think i dont know how to do this?? sprite is not working with emission

#

only by multiplying base color

prime badger
#

I was watching this tutorial https://www.youtube.com/watch?v=jcNJbR85gK0&t=135s where he creates a old TV pixel shader. In my project/game I want to have this shader as a universal shader where the camera view is pixelated (like an old tv) but I'm not sure how to convert what he has done to act upon what my (FPS) camera is viewing in real time. Can anyone help me with this? (my knowledge of shaders is pretty limited)

This Shader is available in Asset Store: https://bit.ly/lwrp-materials-3

This is a quick tutorial on creating an old TV effect using shader graph in Unity 3D LWRP/URP

Checkout my assets for more Tuts!


                        Materials and Shaders

...

▶ Play video
#

I am using the universal render pipeline if that is important

#

I basically want my view to look like your viewing through a vintage pixelated camera throughout the game

past kraken
#

But it is painted in purple

#

Not white!

#

But circle is white

#

And it is glowing purple!

swift yoke
#

compute shaders constantly telling me to use uints but there's no SetUint wtf

merry oak
#

Out of curiousity and fear of blowing up my dad's computer, I figured I should ask if there's anyway for me to damage my GPU with shaders. I've started very recently and just had to restart the computer because the whole screen went black.

zealous lotus
#

Is there no Particle/Additive shader for URP?

timber carbon
#

hey is there a way to get urp shadows in a unlit shader?

wise willow
#

Why is there no command buffer setcomputetexturefromglobal like there is with the other compute shader methods?? Is there some alternative for this?

#

Settexturefromglobal has no version in the command buffer methods that I can see

#

Hmm maybe it is BuiltinRenderTextureType?

#

I think I have it figured out

worthy verge
#

anyone know how to make a shader that's flat shaded but still recieves shadows?

naive forge
#

does someone know what's wrong with this shader? when I enable MSAA in the URP renderer, I'm getting a white outline around my meshes when they are in front of fog

past kraken
#

there is literally no sense asking here questions

#

no one will answer

dim yoke
dim yoke
worthy verge
#

Well I want something to be unlit, but still have other objects cast shadows onto it

#

By flat shading I mean like the default unlit shader

dim yoke
worthy verge
#

I assume I'd have to write my own thing? Just write the part that draws the shadows but not the part that shades the object I assume? I'm just using the default pipeline.

dim yoke
# worthy verge I assume I'd have to write my own thing? Just write the part that draws the shad...

here's https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html example of shadow receiver/caster shader. the example code seems somewhat complicated because it uses some extra stuffs implemented earlier but the shadow receiving/casting itself isn't all that complicated. using UsePass command, it's very easy to do the shadow casting and the receiving isn't that hard either using the helper macros (maybe 3 lines of code?)

grizzled bolt
#

@worthy verge If you mean flat shading as in drawing or painting rather than shader terms it sounds like you want a toon shader of some sort

#

Plenty of guides and ready-made solutions if you search around

dim yoke
#

I'm using RWStructuredBuffer<bool4> in compute shader and I'd like to get the data to c# side after dispatching the shader. I'm not able to figure out how to get boolean array out of that buffer

lean marsh
#

I am trying to build a simple 2d tile based lighting system (none of existing solutions handles my needs) and while getting illumination with the ligthing is working, getting it to work with colors is a different story. The main issue is that I want the color to blending into the tilemap as if the color is a transparent layer on top of the tilemap but every calculation I have tried just screws up the color (it always end up much lighter than it should). Is there any major reason to not just apply the color on a separate sprite that is rendered on top of the tilemap? I am trying to get the effect of something like this (showing both is dark and light):

meager pelican
#

Which is the one you want?

#

In general lighting is:
albedo * lightColor * attenuation

#

then there's + ambient

lean marsh
# meager pelican Which is the one you want?

They thing is I want both. I want colored light to still effect the tilemap even when it is full day brightest but then during the night, I want the colored light to both effect the color and illumination (I am obviously not going for realistic lighting)

#

so the albedo part I think is not relevant for me (there is not reflection needed for me)

#

and in my lightmap, I am using the alpha channel to indicate the strengh (which I think is the attenuation part) but when I try mainTex.rgb *= (lightColor.rgb * lightColor.a); it just washes away the color of the light to much (I give it a darkish green and it show up as super light relatively speaking)

dim yoke
# dim yoke I'm using `RWStructuredBuffer<bool4>` in compute shader and I'd like to get the ...

Now this is getting very weird. I somehow managed to get some values out of the buffer using struct of bytes but the result seems very odd. In the compute shader I do this Result[id.x] = bool4(true, false, true, false); so it should give true and false alternating. When I use this to output the data:```cs
struct Bool4
{
public byte x,y,z,w;
}
public void GetData()
{
Bool4[] bool4Array = new Bool4[resultBuffer.count];
resultBuffer.GetData(bool4Array);
for (int i = 0; i < bool4Array.Length; i++)
{
Bool4 bool4 = bool4Array[i];
print(bool4.x != 0);
print(bool4.y != 0);
print(bool4.z != 0);
print(bool4.w != 0);
}
}

I get `true, true, true, true, false, false, false, false, true, true,...` (4 `true`s and 4 `false`s in a row) as result. I'm not able to figure out why would that happen in any case
dim yoke
# low lichen A `bool` is 4 bytes in HLSL

That's ridiculously dum, thought 1 byte per bool in c# is wasteful 😅 . Actually this means I should not use bools at all and use ints with value of 0 or 1 instead (I didn't actually need bool4 but because stride size must be multiple of 4 I thought that would fix it...) if they both consumes exactly same amount of memory. I'm basically trying to do Conway's Game of Life using compute shader so in theory only thing I need per cell is one bit but that doesn't seem to be possible even on C# side. Thanks a lot. I wouldn't have figured this out myself 🙌

timid plover
#

you could use the rest of the 31 bits for parameters (eg. colors etc.)

#

and the stride comes from the underlying graphics api it's not specific ti hlsl

meager pelican
#

It all depends on what you want, YMMV.

spice tinsel
#

Hello, I am trying to make an enemy fov effect. I am creating this mesh that you can see in the picture (the orange thing). What you see behind the enemy is a zone sprite. I want to use the mesh as a mask that only displays the zone sprite on the places they collide. How do I do that? I hope this makes sense

knotty juniper
#

that will give you the first hit in each direction you raycast

spice tinsel
#

I am already doing that

knotty juniper
#

you still need to build a mesh from that points

spice tinsel
#

I have the mesh done

#

I just want to use it as a mask that shows the sprite only in the places that they overlap

knotty juniper
#

so you need a sprite maks that works based of a mesh an not a texture

spice tinsel
#

yes

knotty juniper
#

mmm either we can make it work with the normal mask component or you could copy and modify the build in maks

spice tinsel
#

I can maybe convert the 2d sprite into a cylinder

zealous sequoia
#

I want to write a raytracer like thing using compute shader, but with some special functionality - I want it to generate 3D dots (I guess simple quads) to simulate how a lidar works and to visualize a point cloud like in the image. Only problem I have - how do I pass scene geometry data to compute shader? I found GraphicsBuffer, but it's poorly documented and I couldn't find any examples with it.

knotty juniper
swift yoke
#

how performance heavy is sending data to a compute shader? cpu -> gpu only
I know that it's much quicker than gpu -> cpu, but is there still a fair cpu cost do say, doing it every second vs every 5th of a second etc

dim yoke
twin wadi
#

Hey, Small question. I have made a shader that I use for a bunch of objects in my scenes, now I want to make multiple materials for them and everything, but I want to randomize which colors go on which buildings. What would be lighter performance wise in this situation. Writing a script that just changes the RGBA Color value's or swapping the material itself using a script?

swift yoke
#

is there any good way to release a buffer next frame?

knotty juniper
twin wadi
#

so it doesn't really matter? 🤔

#

oh yea I am using URP

knotty juniper
#

the batcher will handle that just fine

#

having a lot of different texture will mess with the memory but just some new materials are fine

twin wadi
#

ah okay cool, yea there will be only 1 texture so everything should be fine, thank you

zealous sequoia
swift yoke
zealous sequoia
#

ah oke sorry

#

Afaik sending data between those must be done only if necessary

timber carbon
#

hey is there a way to input 3 ints per vertex into shader graph instead of having to input floats?

#

mainly because im trying to do bitwise compression for vertex data however I cannot get compression working with floats so it would be much better if i could input ints instead of floats into vertex stream

proud wharf
#

Who knows if it's possible, when using a position in a shader, to move the texture only pixel by pixel? And if so, how?

#

Or maybe someone has a detailed guide on how to make grass move on contact with it in 2d in pixelart

honest onyx
#

hey... I cannot get Polybrush painting to work on Standard even with what I am almost positive is the correct shader.

#

i'm probably noobing. any ideas? I'm on a newish mac using the latest unity release

hollow talon
#

I am planning to make a procedural UI tool, I wonder which way makes more sense, using shaders or generating meshes

gentle hull
#

I want to make an "outline" of selected 3d objects. Are there any tutorials anyone can recommend?

swift yoke
#

is there a drawback to having compute shader buffers last a long time?
Like let's say I have an array of positions I need on the GPU in a buffer, and I know this array won't change for 10 seconds, but I need that array on the GPU throughout.
Would there be a drawback to just not releasing the buffer for a while and so, I should just send the same data each frame, or is it fine to have buffers last a long time on the gpu? And if so, how long? Can they be on there for hours without being released, as long as you do release them at some point?

fossil cloak
fossil cloak
gentle hull
merry oak
#

I'm trying to make a shader with multiple passes, but the first is the only one that happens. I know that the second pass's code isn't faulty because it works when I comment out the first pass.

merry oak
#

I checked in the project settings and I'm on URP.

modern lintel
#

hi im a beginner how do i make a chroma aberration shader

#

or can someone send me a chroma aberration shader

proud wharf
#

Is it possible to create a shader that, when in contact with another shader, will distort it?

cosmic prairie
#

kindof

#

I think you could achieve something with the depth and stencil buffers

#

it will only work tho if the objects overlap on the screen

grizzled bolt
#

You need to define "contact"

cosmic prairie
#

or you could inflate the distorter

cosmic prairie
grizzled bolt
#

I don't think shaders can know when another shader is near specifically, but that's not usually necessary

cosmic prairie
#

especially if the distorter is a simple shape like a sphere

low lichen
pliant falcon
#

Hi there
does anyone know a way to overcome the thread group limit for compute shaders? Or is that a hard limit?

sacred rock
#

I was asking a while ago about some trouble I was having reading Texture3D in a compute shader. I’ve now realised that my problem isn’t Texture3D, but rather Texture*D<float>. If I have some texture, 2D or 3D with a format of Alpha8, R8 (or as far as I can tell any other scalar format), then I only seem to get values of 0 from it.
I’ve now realised that if I use <float4>, then it works as intended. Texture3D has nothing to do with it.
Anyone out there had experience of being able to read scalar values from a texture in a compute shader?

lament scarab
#

Do switching from Built-In to HDRP break things, just like switching from Built-In to URP did to my project?
Or are Built-In Shaders compatible with HDRP?

azure geyser
#

Does anyone know if it is possible to add shaders to the Always Included Shaders list in the Graphics settings through an editor script?

south pecan
#

Hi, I followed a tuturial on Toon outlines in Unity but I'm not shure why it doesn't work. I work in Unity 2020.3.30 urp, and followed everything from beginning to end (with the changes in the comments). But it's unclear to me why I get this result. Does anyone know what the problem might be? Would be a great help. 🙏
The thickness doesn't seem to change no matter how much I change the settings. And I don't see any difference on screen.

#

I don't know if I missed something.

#

Also looked at the material pass index but to no avail.

abstract adder
#

I'm trying to achieve a sort of "ambient occlusion" on my top down tilemap. The effect I'm looking for is like in Prison Architect, around every wall there's a bit of a darker area. I'm using a mesh for every wall tile that I set the vertex colors on to fade it out towards the end. Now I'm having issues where the meshes overlap. I've tried with writing to the stencil buffer, but I can't get it to work well even with aggressive alpha clipping (which would look bad anyway). Anyone have an idea for this which doesn't include picking a different mesh depending on neighbor tiles or combining the meshes into one?

lament scarab
#

Do switching from Built-In to HDRP break things, just like switching from Built-In to URP did to my project?
Or are Built-In Shaders compatible with HDRP?

sacred rock
pliant falcon
sacred rock
# pliant falcon I've stumbled upon a repo which uses a high number of thread groups and somehow ...

Is it simulating hydraulic erosion by any chance? That seemed to be something that hit a few people here: https://forum.unity.com/threads/thread-group-count-is-above-the-maximum-allowed-limit-maximum-allowed-thread-group-count-is-65535.828420/

timber carbon
#

Hey I've been trying to get a shadow caster working in my unlit shadow for a while now but I cant get it working. It says there 300 shadow casters currently in the scene however there is no visible shadows.
https://pastebin.com/w07zARtr
https://pastebin.com/gUYtBp8V

sacred rock
pliant falcon
dire sail
#

hi everybody. I'm trying to apply a shader to pixelate a sprite after its been animated using a rig. Unfortunately, the shader seems to be applied before the deformation is calculated - as you can see in the image: the skin texture of the character is very pixelated, but the edges where the rig applies deformation are still smooth. What's the secret here?

The point of this shader is to undo the smoothing and stretching caused by the rig and return it back to 64x64. It's a 'Sprite Lit' URP shader

novel owl
#

Hey there, in the last days I tried to create a custom shader graph to use as my skybox. When I apply the shader graph as the skybox it works just fine. The only problem is, that when I make unregular object in the skybox (not for example a gradient, but stars) they appear mirrored on the x-Axis. I supposed it is a problem with the method the texture is formed to the sphere of the skybox about I am not really sure. Can someone explain why the problem appears and how to solve it? Thanks

lament scarab
#

Do switching from Built-In to HDRP break things, just like switching from Built-In to URP did to my project?
Or are Built-In Shaders compatible with HDRP?

frosty copper
#

Hello. Is there any way I can modify this shader to display exact luminance at st position... e.g. instead of random shades, it displayed every 2nd square as black on the bottom row, the rest being white.

#

it is just the brick sub-graph in the shader graph samples that I want to modify

#

Can I have fine grained control over the cells

nocturne otter
#

im new to learning how to write shaders and im having an issue with one of the passes where when i set the tag for lightmode to "ForwardAdd" it makes the object kind of transparent. any reasons why

#

actually ForwardBased not add

keen patio
#

what is this model's name called?

robust inlet
#

I have a camera problem that don't render into cubemap, where I can ask about it?

little marlin
#

hi, so im new into unity, also new into graph shader, i just making bunch of simple testing. so my question, everytime i connect my other function shader to base color, why is my inspector not updating the information ? since my color shader are not connect anymore. or it just how graph shader works ?

wary jackal
#

Hey, so I'm wondering how I can get the local position in a surface shader accurately. This includes scale, rotation, and position. Right now I have the scale and position figured out, but when I rotate my object, the local position gets all whacked out. This forum post was the only thing I found, and it was slightly unclear. Has anybody dealt with this before? https://answers.unity.com/questions/561900/get-local-position-in-surface-shader.html

wary jackal
#

It's pretty obvious to tell though that because your colors aren't connected anywhere to your output, they're not going to do anything.

little marlin
#

wait, wrong config, wait a sec

little marlin
wary jackal
#

Wdym it shows all of it? all of what?

little marlin
#

i mean, if i dont connect it to block nodes, it shouldnt show to exposed properties right ?

wary jackal
#

No, the exposed properties are the properties you choose to show up in the inspector

#

If you don't want a value to show up in the inspector, don't expose it

little marlin
#

wait, so thats mean, properties always shown no matter if its being used or not ?

wary jackal
#

Yep

little marlin
#

ah okay", so i had to uncheck exposed later if i got final version of my shader ? is that right ?

i mean, on unreal i dont had to check or uncheck the "exposed" tick button if i dont connect the shader to block nodes output

#

okay", its clear for me. thank you for answer that

wary jackal
#

np

empty pendant
#

Hey there, not sure where to go for this and this is my best guess. Could anyone please help on how I could get a GIF as a material into unity that I can place on objects?

amber saffron
little marlin
#

Hi, im following somebody tutorial on internet, and currently he using node called swizzle, my question is, how to only get 1 or 2 output from swizzle, node, what does it means green out, blue out, red out, etc ? i'm aware iam using old version of shader graph, but is it possible to get the same result like the newest version of swizzle nodes ?

hardy knot
#

which one is the new one? id assume that if you actually use a vector4 as input in the second one it would look similar to the first one

#

as for what the terms mean, swizzle reorders the vector so you can say the red output gives what originally comes in from the blue input

#

basically the first pic says: create a color that uses the red input value for each output channel but green stays green

little marlin
little marlin
hardy knot
#

they have the value of whatever comes in as red

#

do you have a screenshot of the 4 in -> 2 out? doesnt really make sense and the docs also dont show such an option

#

like if (1,2,3,4) comes in, the output in that example would be (1,2,1,1)

little marlin
#

so this is comes from Ben cloward youtube channel, he did sample normal texture, then connect to swizzle node (new version, cause he did mention he using 2021 unity shader graph version)

little marlin
hardy knot
#

oh yeah i was on some older docs page, the newer one shows the mask

#

i think you could do it with a split connectoed to a vec2 or in case of the z output just use the z directly

#

he doesnt seem to use it to reorder but just to "filter" it out

little marlin
hardy knot
#

shouldnt be, what you put in the mask determines the output, mask length = output length and you can use x,y,z,w in any order to determine which input value should be used for that ouput

little marlin
#

i mean if someday i want to swap the orders of input to output and still only need two output using my current shader graph version

meager pelican
#

The position will be interpolated across the triangle.

grizzled bolt
dire sail
# grizzled bolt Pixelating the texture itself independent of deformation is tricky because the o...

hey, thanks for the reply. If you say upscale, do you mean downscale here, to "pixelate" the entire screen? I would like to avoid it because I might need to limit the pixelation to certain parts of the individual sprites (the edges for example) so as to preserve facial details. Not to mention this would also pixelate any shading etc. and not allow any objects I might want at a higher resolution. Isn't there a way to apply a shader just to the character after the deformation?

grizzled bolt
#

Another option that comes to mind is to render to render target textures which aren't limited to the mesh outlines, whether you render the character or multiple parts of the scene onto that render target to get varying resolutions of pixel filters at once on screen

#

I can't think of a way to "extend" the mesh outline to allow the pixels go outside that border while keeping UV maps intact somehow

dire sail
#

Would the render target approach get around the issue with the outlines? I would imagine this would involve the finished rendered image, only separated onto layers that are then composited to make up the finished screen? If so, this sounds like what I need

grizzled bolt
#

The quad can be the size of the enemy, or encompass all enemies as a "layer"

#

Every rendertarget needs a camera for rendering it so it's not totally cheap

dire sail
#

actually, I might need different render targets per character for purposes of proper occlusion I think. Either way, it's worth a shot

grizzled bolt
dire sail
#

I'll see what I can come up with, thank you very much!

lament scarab
#

Does switching from Built-In to HDRP break things, just like switching from Built-In to URP does?
Or are Built-In Shaders compatible with HDRP?

lusty badger
#

Hi, I'm working on a VR (single pass instanced) game and I have some matrices being set with C# and it looks different in each eye.
Are there any shader built-in equivalents to these two "functions" that internally use the eye index for stereo rendering?

var viewFromScreen = GL.GetGPUProjectionMatrix(camera.projectionMatrix, true).inverse;
viewFromScreen[1, 1] *= -1;
material.SetMatrix("_ViewFromScreen", viewFromScreen);
material.SetMatrix("_WorldFromView", camera.cameraToWorldMatrix);

I tried using UNITY_MATRIX_P and UNITY_MATRIX_I_V but either I used it badly or it's not what I want.

This is how they're used in the shader

float4 viewPos = mul(_ViewFromScreen, float4(input.texcoord * 2 - 1, depth, 1));
viewPos /= viewPos.w;
float3 wpos = mul(_WorldFromView, viewPos).xyz;
lusty badger
latent thistle
#

hello, i'm under the water..

i did a custom toon shader, but currently, my shadows are not cast

i use a lit one to have the basic shadow, get a main light function to the the main light, then i use a diffuse (ndotl) that i input in a additional light fonction that also do a diffuse on the additional after that i add the main diffuse to the result and input it in a light ramp and finally put in emission node of the fragment shader

#

i can't find how do have my shader with point/spots lights..

latent thistle
#

like that i do not have a shadow for the red spot

grand jolt
#

how would i do this in URP with our shadergraph material?

#

ok found it the setting is now called "Render Face"

latent thistle
#

howx can i get shadows for additionals lights ?

formal canyon
#

these icons should all be in circles. it worked until I switched to using a texture-atlas. this has messed up the uv coordinates (makes sense). how do I get the coordinates from 0-1 again for the texture I am showing?

#

o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.coord = v.uv; //how to transform this?

dim yoke
#

Anyone knows how to use RenderTexture in compute shader with RenderTextureFormat.R8 format which is supposed to be 8 bit integer. Using Texture2D<float> I managed to get it working but Texture2D<int> always gave me blank texture. I used int buffer earlier so I think it’s not about my compute shader returning wrong values

formal canyon
#

I had issues with some of the texture formats, maybe not supported

rancid silo
#

Do You know some actual shader tutorials

#

For Unity 2020.1 lat

#

Lts

nocturne otter
#

@rancid silo Freya holmer does great tutorials and explanation

latent thistle
#

anyone to help me please ? 🥺

dim yoke
knotty juniper
latent thistle
# knotty juniper what renderpipline do you use? in hdrp you need to enable the shadows for each a...

urp; every light has shadow enalble, just my additional light handling do cast shadow and i can't find how to do that; my code is currently that :

void AddAdditionalLightsSharp_float(float Smoothness, float3 WorldPosition, float3 WorldNormal, float3 WorldView,
    float MainDiffuse, float MainSpecular, float3 MainColor,
    //returns
    out float Diffuse, out float Specular, out float3 Color) {

    float mainIntensity = GetLightIntensity(MainColor);
    Diffuse = 0; MainDiffuse;
    Specular = MainSpecular;
    Color = MainColor * (MainDiffuse + MainSpecular);

#if defined(SHADERGRAPH_PREVIEW)
#else
    float highestDiffuse = Diffuse;

    int pixelLightCount = GetAdditionalLightsCount();

    //Light mainLight = GetMainLight(shadowCoord);


    for (int i = 0; i < pixelLightCount; ++i) {
        Light light = GetAdditionalLight(i, WorldPosition);
        half thisDiffuse = light.distanceAttenuation * light.shadowAttenuation * GetLightIntensity(light.color) * saturate(dot(WorldNormal, light.direction));


        thisDiffuse = light.distanceAttenuation * light.shadowAttenuation * saturate(dot(WorldNormal, light.direction));

        thisDiffuse = light.distanceAttenuation * light.shadowAttenuation * GetLightIntensity(light.color) * saturate(dot(WorldNormal, light.direction));



        half thisSpecular = LightingSpecular(thisDiffuse, light.direction, WorldNormal, WorldView, 1, Smoothness);

        Diffuse = MainDiffuse;
        Specular += min(MainSpecular, thisSpecular);

        if (thisDiffuse > highestDiffuse) {
            highestDiffuse = thisDiffuse;
            Color = light.color;
        }
    }

    Diffuse += MainDiffuse;

#endif
}``` but that's not the solution
#

or if i should tranform my entire shadergraph into a full code shader

knotty juniper
latent thistle
knotty juniper
#

the example code of "AdditionalLights_hlaf" looks like somting like it

#

@latent thistle

latent thistle
#

my function is kinda similar

#

but

#

this one is under 2019

#

and urp has change..

regal stag
#

If you're in v10+ you should add a third param to your GetAdditionalLight function. It's required to calculate the shadowAttenuation value. Technically it's for supporting the baked ShadowMask mode but if that's not important can just use a value of 1. e.g. GetAdditionalLight(i, WorldPosition, half4(1,1,1,1));
There's also _ADDITIONAL_LIGHTS and _ADDITIONAL_LIGHT_SHADOWS keywords which should be created in the Blackboard if using an Unlit Graph.
https://github.com/Cyanilux/URP_ShaderGraphCustomLighting

latent thistle
#

oh

#

you are here

#

you have to know that i love you so much guy

#

i read a lot on your blog

knotty juniper
#

he has a blog 🙂 never knew thanks 🙂

latent thistle
latent thistle
#

he his here 😂

#

daniel ilet too is strong for tutorial

#

ned makes games too and also roystan

latent thistle
#

okey, i'm totaly retarded, i was editing the wrong function since a moment... si my last code was right 😂

#

thank you all

latent thistle
topaz patio
#

how make shader?

wary jackal
wary jackal
#

Hey, I'm really confused as to why my texture isn't being applied to my custom mesh. Everything's working fine on the sphere, but as far as the custom mesh, only one color of the texture is ever displayed. (It may be hard to see in my picture, but the normal sphere is doing everything perfectly) As far as I know I'm doing everything properly. Here's the shader code. Literally all it's doing right now is sampling the texture and displaying it as the albedo, yet it's not working. It's just a standard surface shader.

EDIT: Yes, I do know that the material is also being updated on the custom mesh. changes I do to one affects both.

Another edit: I'm beginning to think it's because I'm not setting the UV's when I generate the mesh. I don't know how to do that so currently I'm looking into that.

aaaand another edit: After a lot of research I got something working. It's not perfect, and there's a lot of distortion, but at least I'm getting a texture applied to the custom mesh. The problem was that I wasn't setting the uv's. Now I just have to figure out how to get good uv's.

        fixed4 _SteepColor;
        float _Sharpness;
        float _ColorChange;
        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
        sampler2D _StoneTex;
        sampler2D _GrassTex;

        struct Input
        {
            float3 worldPos;
            float2 uv_GrassTex;
            float2 uv_StoneTex;
        };


        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 grass = tex2D(_GrassTex, IN.uv_GrassTex);
            fixed4 stone = tex2D(_StoneTex, IN.uv_StoneTex);

            o.Albedo = grass.rgb;
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            // o.Alpha = c.a;
        }```
normal rose
#

Good night and sorry to disturb but who can help me I really appreciate it I would like to know a way to create a shader or a material that when looked at from behind it becomes invisible and when I look from the front I can see the object

vernal glen
#

Something like this @normal rose ? https://www.youtube.com/watch?v=S5gdvibmsV0

A tutorial on the see-through-objects effect used in my game Treasured. It uses Unity, URP and Shader Graph.

Note: this was created with Unity 2019. It might not work for newer versions since they have not been tested.

Social Media:
Twitter: https://twitter.com/HuntersonStudio
Twitter: https://twitter.com/Casualdutchman
Twitch: https://www.twi...

▶ Play video
#

Not exactly sure off top how you could specify whether looking at front or back though of the object just yet...

normal rose
#

thank you so much

#

I hope this helps

normal rose
#

the object from the front is seen like this

#

when the player is behind it has to disappear

#

😢

vernal glen
normal rose
#

ok thanks for helping me

#

no problem

#

sorry if i sounded thick

dim yoke
# dim yoke Anyone knows how to use `RenderTexture` in compute shader with `RenderTextureFor...

According to this post https://answers.unity.com/questions/1842555/how-do-int-textures-work-in-computeshaders.html writing to Texture2D<int> isn't possible for some reason. Reading from int texture seems possible so I think i'm going to use Texture2D<float> in the compute shader and Texture2D<int> in the fragment shader drawing the render texture assuming there's no problem in changing the format of texture between different shaders. Atleast it seems to work and doesn't give me any errors.

hybrid mantle
#

Hi i don't know what is this on the shader graph. is there someone to helps me ?

sacred rock
hybrid mantle
sacred rock
hybrid mantle
#

Okay thanks you 🙂

hardy knot
#

nah xinaes you are right its just to make the graph more clean, it has no functionality otherwise

#

besides changing the path of the connection you can also use it to make it look better if you want to connect the same output to multiple inputs

hybrid mantle
#

thanks for the answer 🙂

sacred rock
# dim yoke According to this post <https://answers.unity.com/questions/1842555/how-do-int-t...

I wonder if you have any insight for me... I am singularly failing to ever read any non-0 value from a Texture2D<float> in a compute shader. I haven't tried <float2>, but <float4> works ok. (I also just tried <int> on my mac, which hits runtime assertions along the lines that TextureFormat.R8 isn't compatible with <int>, I imagine this would be similar on other platforms - expecting R8 to be an unsigned normalised byte).
But really, this has been driving me somewhat nuts and if you can just confirm that you are actually even able to read scalar <float> (or any other scalar number type, but preferably from an 8bit source) from a texture in a compute shader that's some new information for me. It also might be possible that, like me long ago, you have some code that seems to work and doesn't give any errors, but that when you get down to the details of trying to get any useful results from it you eventually hit the same issue.

dim yoke
# sacred rock I wonder if you have any insight for me... I am singularly failing to ever read ...

This is how I initialize the rendertexture:```cs
texture = new RenderTexture(resolution, resolution, 1, RenderTextureFormat.R8);
texture.stencilFormat = GraphicsFormat.None;
texture.depthStencilFormat = GraphicsFormat.None;
texture.enableRandomWrite = true;

and this is the compute shader:```cs
#pragma kernel Randomize
RWTexture2D<float> Result;
int Resolution;
float Coverage;
float Time;

[numthreads(8, 8,1)]
void Randomize (uint3 id : SV_DispatchThreadID)
{
    float2 p = float2(id.x, id.y + Time);
    float3 p3  = frac(float3(p.xyx) * .1031);
        p3 += dot(p3, p3.yzx + 33.33);
    Result[id.xy] = step(frac((p3.x + p3.y) * p3.z), Coverage);
}

Also reading from Result in compute shader doesn't seem to be a problem. Currently I'm actually using the same texture render texture (declared as Texture2D<int> Result) in fragment shader without problems.

sacred rock
# dim yoke This is how I initialize the rendertexture:```cs texture = new RenderTexture(res...

Thanks. I'm not actually using RenderTexture (and not trying to write), so given that's a variation I haven't tried it may be worth giving it a go. Ideally I'd rather not to have to change other code to make a RenderTexture, but it might at least help to put my mind at rest. I think perhaps there's a bug in Unity.
I have just been testing with a fragment shader, where I was able to read from my Texture2D<float> and also write to a RWStructuredBuffer, so there's a chance that as a hack I end up using a fragment shader to do work that should logically be in compute shader. (edit: I may be less inclined to use this workaround since Unity is spewing out lots of spurious warnings about missing bindings).

formal canyon
#

normaly when mapping a texture uv coordinates go from 0-1, when a texture atlas is used this changes. is there a way to get the 0-1 range for that quad again in shader code?

little marlin
#

is there any equivalent panner nodes on unity ? i found it on amplify shader, but cant find it on shader graph itself

grizzled bolt
little marlin
#

but how, do i move the speed, by the location, i mean on panner by amplify shader itself, there's speed that give us to move those coordinates by the time i set. how do i reach that using tiling and offset ?

grizzled bolt
little marlin
#

did i do it wrong ?

regal stag
#

The Tiling And Offset would go into the UV input on the sample

little marlin
#

ah finally, okay, it moving on the direction i expect based my vector value, thank you for the help

sacred rock
#

scalar value in compute shader

dim yoke
#

Am I misunderstanding something or are ComputeShader.SetBuffer and ComputeShader.SetTexture almost 0 cost operations? Do they really move some data or do they just give the reference to buffer or texture as I think they do?

sacred rock
dim yoke
#

thanks 🙌

south pecan
#

Hi, I work in Unity 2020.3.30 urp, and followed this tutorial from beginning to end (with the changes in the comments). But the thickness doesn't seem to change no matter how much I change any settings. I checked debug mode and all multiple times, but don't see any difference in thickness. I'm not certain if have to make any changes for Unity 2020.3.30. Does anyone know what could be wrong? Would be a great help. 🙏

merry rose
latent thistle
#

small tool question about shader; i'm using visual studio with reshaper but there is no autocompletion and autoindent is totally fuc***
Do anyone has a fix to have this feature that work properly ?

gentle yew
#

Good afternoon everyone!

I am using custom shaders from the Mix and Jam team on Youtube to make a painting effect, similar to that from Splatoon.

All I want to achieve is the painting effect using mouse.

I have narrowed down the problem to the shader mask "not updating" or rendering in both the camera view / Editor view, yet when I select the object that I am painting on with the custom shader - I can see that the mask is being updated in the editor during run time, as I send a ray to the surface of the object.
I am a beginner and do not know how to debug to see where I could have gone wrong in the render process - whether it is coordinates, perhaps the scaling of the mask or if the texture position(world space) to screen space transfer is haywire because my camera moves or project settings to adjust for the custom shaders.

I have made a new clean project and reintroduced the scripts and the only minor changes to the original code have been changing the input system, other than that - only 1 compile error that relates to the scripted assignment of a shader (Which happens on the original project and works still)

Been stuck on this for the last couple of days and could really use the help. Screenshots below.

Apologies for the essay.

wary jackal
merry rose
wary jackal
wary jackal
lone stream
#

Hi guys is there anybody know what causing this shader error? i'm only getting this on ios/Metal. Using Birp
mismatching vertex shader output type(s) or not written by vertex shader

lean lotus
#

Is there an easy and fast way to get the scale of a mesh out of a localToWorld unity matrix in a compute shader, or should I send it in seperately?

lean lotus
#

but can I access it quickly in a compute shader from the matrix itself or would it be better to just send it as data

shadow locust
#

oh sorry i forgot we're in shaders

#

yeah it can be extracted from the matrix in the same way, jsut don't remember if there's a HLSL function for it or not

lean lotus
#

thx!

stiff delta
#

ive been trying this for ages and im so frustrated because it wont work

#

and it just doesnt work for some reason

#

everything he does, i do

#

but then when i modify the hdr intensity it only changes color

#

can anyone help me figure out what im doing wrong

#

bloom materials in general just dont work for me

stray orbit
#

Hello, has anything changed with shader graph in 2021 because i have a texture input and color input that should be exposed in the inspector of my material using the shader but they are not

#

exposed is on in both

#

oh never mind i did not save yet so it did not yet get applied

#

ignore my question

dim yoke
stray orbit
#

yeah i figured that lol

#

was a dumb mistake

loud turtle
#

Where is the Custom Render Texture?

neat hamlet
#

in 2021.19 its closed to the bottom, no longer in shader

tired elm
#

hey all, i was hoping someone could help a newbie. i am trying to recreate the 'overlay' blending mode for some sun ray sprites in my project. i have downloaded this, installed the package. https://github.com/zigurous/unity-blend-shaders/packages/656602

but i how do i access these options? thank you in advance

GitHub

🔲🔳 Shaders for blending objects in Unity (based on Photoshop's blend modes). - Package com.zigurous.shaders.blending · zigurous/unity-blend-shaders

meager pelican
# tired elm hey all, i was hoping someone could help a newbie. i am trying to recreate the '...

You'd have to use that in the standard (built in) pipeline, not URP or HDRP.

There's a shader for each type of blend. You'd put that shader on a material that you create. Then assign that material to an object.
Here's a list of the shaders in that package:
https://github.com/zigurous/unity-blend-shaders/tree/main/Shaders

GitHub

🔲🔳 Shaders for blending objects in Unity (based on Photoshop's blend modes). - unity-blend-shaders/Shaders at main · zigurous/unity-blend-shaders

tired elm
#

@meager pelican thanks so much for your response. i made the material and attached the shader. apologies in advance if this is a stupid question, but do you possibly know why it is coming out this colour? thanks again

meager pelican
#

That's an error color. What pipeline are you using? (if you're in URP or HDRP, that won't work for those shaders. Or there's another error of some kind, check the console log, or click on the shader in the inspector and check for errors showing on the inspector panel).

tired elm
#

i just imported the shaders, made a material and attached the overlay shader. i think i need to go back and watch some more tutorials, as i actually have no clue about pipelines😅

dull pewter
#

Is there an easy way to turn a standard shader into a URP shader?
Shaders are pretty much magic to me.

river seal
dull pewter
#

yeah, I'm using ECS and finding it through code, is it still possible to do that? I seem to be getting a an error regarding a "Redefinition" inside the shader, but I can't figure out the problem since it's not misspelled...maybe I should just link it and let you guys see

river seal
#

but I'm pretty sure that's possible

#

you have a bunch of materials you need to change over to URP?
Doesn't Unity have a built in thing for that?

dull pewter
#

https://pastebin.com/nN74ibJm
This is the code for the shader and it's complaining about _MainTex_UV at row 46 for some reason....
I suspected it might be because this shader might be made for the basic rendering pipeline and not URP

#

It's not the material I wish to change, it's the shader itself and the code inside the shader that potentially needs changing to work with URP I believe.

river seal
#

also you've got enable GPU Instancing checked on the material right?

river seal
river seal
loud turtle
#

Why i cant see a Stylized Grass material?

latent thistle
#

anyone has idea to do a radial distortion effect for post process ?

latent thistle
#

To have a speed effect for a space shuttle

young charm
#

Hi, my shaders aren't working in builds. On google they said I should add the shaders to the always included shaders list, but this didn't solve it and I can't find another solution

hardy knot
#

are you using shaders that do not support your target platform?

young charm
#

No they support my target platform

cunning geyser
#

hey guys is there a way to make a material that cut trough other objects, like a window, its see trough and lets say i apply it to a box and whats inside in the box is invisible but i can see trough the box?

gleaming pagoda
#

aleksih.

dim yoke
#

How is it possible my ComputeBuffer doesn't get cleared even though I call buffer.Release() on the end of run and next time create new buffer? The newly created buffer seems to memorize the values from the last run buffer. Things gets even weirder when I try to create different sized buffers: the values of new buffer seems to get copied from the last time the same sized buffer was used.

river jasper
#

DId anyone knows a good - free -, ANIMATED Billbord Shader (Advertisements , not Grass or Trees), for Built In RP ? ( no Shader Graphs plz. Shader code).

or a Place i can get a source ?

chrome osprey
#

Hello, i hope this is the right place to ask, i am a student and just starting to use unity, my team agreed on to implement a celShader, and i found this youtube video: https://www.youtube.com/watch?v=lUmRJRrZfGc&t
I copied all the code from his github, and everything works fine in his githb project, however, when i try to implement everything in my current project, i cant get it to work, i changed the render pipeline in the project settings, and when creating a new material i select the shader file (he used) but all my materials still end up pink, i really hope someone can help me with this, i cant continue working until everything is fixed

Tons of games use a stylised cel-shading art style to help them stand out graphically, including hits like Zelda: Breath of the Wild, Persona 5 and Okami. In this tutorial, we'll unlock the secrets of cel-shading in Shader Graph by using our own custom lighting and end up with an effect that supports multiple lights!

👇 Download the ...

▶ Play video
grizzled bolt
grand jolt
#

hi, im new to shaders. i was wondering if anyone could advise me some good learning materials (websites, videos, books) for 2d shaders in unity. I researched this on my own, but in the plethora of links, i cant find a decent place for a beginner like me

#

and many of these articles are complicated. I thought shader programming was easy, but its harder than ai

chrome osprey
#

for some reason closing and opening fixed my problem, works now

plain pike
#

Hi, I upgraded my unity from 2020.3 to 2021.2.7 and upgraded all the things in Renderer Pipeline Converter, yet all my materials are all really buggy. How could I fix this?

meager pelican
meager pelican
inner dune
#

how can i use unity surface shader with custom vertex/geometry shaders?

wary jackal
#

@inner dune It's pretty simple. You need to add vertex:vert in the pragma, and then you can add your vertex shader

#
 
....

void vert (inout appdata_full v)
{
 ....
}```
fossil palm
#

Hey folks, I'm new to shaders and working on a school assignment. I'm running into an issue I don't quite understand. I'm trying to add a transparency value to a shader, but I'm getting this weird clipping effect with objects behind the shaded object. Anyone able to point me in the right direction to understanding why any alpha is clipping part of my tree away?

#

Was just a tags issue:
Tags { "Queue"="Transparent" "RenderType"="Transparent" } fixed it

wary jackal
#

This has been frustrating me for a bit. I'm working on a water shader, and I've been doing pretty well so far. But the scrolling normal maps are just driving me crazy. I only want the normal maps to break up the lighting, but I have no idea how to do that. As you can see, when when I have the normal map, it affects everything (like normal maps should, of course). Here's the code for the normal maps. It's very simple.

            fixed3 normal1 = UnpackNormal(tex2D(_Water1, IN.uv_Water1 + (_Time[0] * _ScrollSpeed2.xy)));
            fixed3 normal2 = UnpackNormal(tex2D(_Water2, IN.uv_Water2 + (_Time[0] * _ScrollSpeed1.xy)));
            fixed3 totalWaterNormal = normalize(normal1 + normal2);
            o.Normal = totalWaterNormal;```
river jasper
dim yoke
sacred rock
amber saffron
young charm
south pecan
#

I'm new to Unity and have some trouble with shading. I would like to put the position to world instead of view, but when I put it on world I get a lot of stretching. Does anyone know a good method or tutorial that can help me with this?

#

on view

#

on world

grizzled bolt
#

If I had to guess you're looking for the Triplanar node

hard gale
#

Guys anyhelp on how to make a shadergraph, like where we can apply a papery overlay texture on top of a base texture and then scroll it a bit with time, like a paper doodle effect on a 2d sprite

swift yoke
#

how can I get a new instance of a custom compute shader?
So I have a compute shader that takes in positions and alters them
I want 2 different objects to both use 2 different instances of this shader (since they will be giving in different positions)
Right now, I have to drag an drop the shader in a serialised field since idk how else to tell unity to use it, and so the 2 objects are pointing to the same shader and it's overwriting the values

cunning geyser
#

Hey is there a way to make a material that is see trough and if its intercepts with some other object it "cuts trough it", like a window

sacred rock
sacred rock
swift yoke
#

actually I think I found the problem, it's because of the material now, the cshader is fine but each instance points to the same material and that's causing problems

tribal bramble
#

anyone know why im not seeing Unlit Graph as an option here?

young charm
#

I'm pretty sure you can set the shader to unlit in the shader graph itself.

wary jackal
amber saffron
# wary jackal Yes, but as I was stating in the description, I only want the normal map to brea...

Looks like you're using surface shaders ?
If so, and without doing your own custom lighting to fake this, it's a totally expected result from normal mapping.
Maybe a solution could be to just reduce the normals intensity, as they appear to be very strong.
An easy way to do it is to use UnpackNormalWithScale(fixed4 packednormal, float scale) instead of the UnpackNormal(fixed4 packednormal) you currently have.

wary jackal
amber saffron
wary jackal
wispy current
#

When i add URP pipeline in my project , even cubes became invisible, why?

wary jackal
#

Alright, well I did the UnpackScaleNormal with some depth and stuff involved and it honestly worked really well. Thanks a lot for that

keen patio
#

how to repeat the Hilbert curve numers after N frames?

wanton grove
#

How do I get the distance from the nearest vertex in shader graph?

shadow locust
#

in the fragment stage?

wanton grove
#

Well I'm going to plug the values into the fragment

shadow locust
#

Not sure really 😅

wanton grove
#

Yeah I'm not even sure it's possible.

wary jackal
# grand jolt hi, im new to shaders. i was wondering if anyone could advise me some good learn...

The catlike coding website is really good for shaders, albeit a bit complicated. Shaders in general are not the easiest thing in the world to learn. The absolute best way to get better at them is to just do it (sounds stupid I know). But just experiment around with the shaders, look at other people's code, follow shader graph tutorials and convert them into shader code, etc. You'll have to learn the basics first, but once you get there it's pretty awesome.

teal breach
#

For the Texture2D sample node in shadergraph, what do the actual different modes do? I see white, black, bump, grey. The documentation is really vague here, but seems to suggest the bump mode will do some normal map decompression (so assumes a certain texture format). What about the others? Are these default values?

teal breach
regal stag
# teal breach For the Texture2D sample node in shadergraph, what do the actual different modes...

The texture modes determine the default value when a texture is not assigned.
It's the same as the string at the end of the property definition in ShaderLab. e.g. _Name ("DisplayName", 2D) = "white" {}.

Put the following values in the default value string to use one of Unity’s built-in textures: “white” (RGBA: 1,1,1,1), “black” (RGBA: 0,0,0,1), “gray” (RGBA: 0.5,0.5,0.5,1), “bump” (RGBA: 0.5,0.5,1,0.5) or “red” (RGBA: 1,0,0,1).
(From https://docs.unity3d.com/Manual/SL-Properties.html)
Shader Graph apparently doesn't give access to the "red" option.

humble hearth
#

So I just learned how to use shaders, I'm trying to create an outline shader that I can add to any game object to give it an outline (My games a 2d sidescroller btw) I originally tried to create 4 copies of the original image, make them black, and offset them, but that didn't give me the result I wanted, so now I'm trying to have one image that gets scaled with a slider to create the outline, my problem is I don't know how to adjust the size of it in a shader (I only started using shaders yesterday so im still quite new). Some help would be much appreciated

dull lintel
#

Hi everyone, is it possible to rewrite the URP lit shader as a shader graph? Or at large parts of it (I understand that looping over additional lights is tricky)? Does anyone have a resource for doing something like this, or has it been done already? I'd like to be able to essentially recreate parts of the URP lit shader, but in an unlit graph, so I have more control over parts of it.

south pecan
grizzled bolt
fervent tinsel
#

so... Unity broke built-in SG target on 2021.3? 🤔

#

actually.. it works if I also import URP package (just having SG and core wasn't enough)

night isle
#

trying to make an outline shader

#

howevedr

#

i need to be able to stop adjacent sprites from having an influence on the current one somehow

#

and also render the outlines outside the bounds

#

eg. below the rocks

#

maybe a second pass but i have no clue if thats possible that way

restive walrus
#

Hi. So as I understand GPU instancing doesn't work with additive lights in ForwarsAdd pass, is there a way to fix it?

#

It just says that draw call can't be instanced because an object is affected by multiple lights

#

I use built-in render pipeline

night isle
#

ok i got it working with multiple passes but because im using _MainTex_TexelSize sometimes its 1 pixel, sometimes 2

#

is there some easy way to be able to say exactly 1 pixel

dim yoke
#

hard to tell without knowing more about implementation of that outline effect but usually partial derivatives are used when we want to have pixel width lines and things like that

night isle
dim yoke
#

what are you offsetting atm? the mesh itself? uvs?

night isle
#

yeah the mesh itself as to not get outlines from adjacent sprites in the same texture

grand jolt
#

i just started learning shaders from brackeys cartoon water tutorial and I installed the universal render pipeline package but his looks a lot diff then mine (i cant figure out where to connect things)

night isle
dim yoke
night isle
#

so youd see these black lines

#

but i do have a workaround for tha

night isle
dim yoke
#

if you do that in fragment shader, yes

night isle
#

yea i do

#

could you point me to some resources that explain how to do that?

dim yoke
night isle
#

ahh ok i see

#

partial derivative sounds a lot more complicated than it is lol

#

was expecting calculus

#

ok i forgot that offseting uvs also has this problem, that now i cant draw outside the bounds

meager pelican
night isle
#

this seems its for 3d though?

dim yoke
night isle
#

maybe

#

ok well turns out it scales by its pivot which is a problem if the pivot is on the bottom edge

harsh dagger
#

I wanna try and attempt a thermal overlay - similar to those of thermal scopes in CoD
How would I achieve this? I'm thinking (though may well be wrong) that smoke could be placed on a smoke layer or render layer and then the opacity of the smoke could be adjusted or smoke inside the view could be ignored

#

I also want that cool visual effect via a render texture and im gonna try and work that out

sterile helm
#

How to solve pink water shaders?

night isle
sterile helm
dim yoke
night isle
#

yea ive looked at that but it doesnt really do anything

dim yoke
#

have you tried increasing it and applying the changes? so that doesn't make the outlines work any better?

night isle
#

yea no change at all

#

only thing i have found is to leave a 1px gap around every sprite but thats rather impractical

dim yoke
#

oh wait, this is weird. it seems to kind of leave more space around the texture but it doesn't expand the mesh outside of the certain rectangle area

night isle
#

one solution is to put a world space canvas and an image and then use the outline but thats

#

well

#

using an image and a canvas

kindred crystal
#

anyone with knowledge of how to use commandbuffers have some insight into this question?

dim yoke
night isle
#

yea but the pivot is different for different sprites

#

some sprites have it at the center, some at the top, some at the bottom

#

i mean i got a crazy idea

#

probably not a good idea

#

but make all the spriterenderers run some method on a canvas to draw their sprite as an image

#

and update it every frame

knotty juniper
night isle
#

ive looked at that a while ago and i cant remember what it was but it didnt work

#

ok yea it just doesnt work with spritesheets

south pecan
meager pelican
#

@night isleYes, it is. Sorry. Some of those techniques may work in 2D space though either object or screen (alpha clipping in a sprite quad, which can be extruded in 2 directions instead of 3, still not ideal I suppose).

meager pelican
lean lotus
#

Hey so im having a pretty big issue with a compute shader(and it being a black box is making this incredibly difficult)
Basically, I have one kernel that I believe stalls the program for a solid second(when I turn it off the stutters go away), but only once every like couple seconds(despite the fact that every frame it is fed different data, and it runs EVERY frame), with a very consistent time interval between the stutters, I believe its reading from out of bounds data(in previous instances it would display things that no longer physically existed)
Is there a way for me to profile this at all to see whats happening? Cant use unities profiler because the extent that it tells me is "There was a spike here, what caused it? compute shaders, which kernel? shrug you got 12 kernels, pick one"
and I cant really use nsight, because of the fact it only happens for one frame every 1-2 seconds
Any ideas for something I could do, or just trial and error it?
https://cdn.discordapp.com/attachments/905926809789562890/964991951139135618/ezgif.com-gif-maker_21.gif

night isle
#

but using ddx or ddy is only possible in the fragment part of the shader

meager pelican
lean lotus
#

hrmmm
problem is getting the right frame, and last I checked they dont do compute

meager pelican
#

Dang

lean lotus
#

it seems to be good on the first run after a code recompile
but after the first going into and out of play mode it breaks

#

hrm shifted all my code into a fresh unity project and it works?

lean lotus
#

welcome to unity

meager pelican
#

Uhmmm....IIRC, you use a debug build with shader pragmas included for debugging. Not in engine. Otherwise you capture engine frames, not game frames.

kindred crystal
acoustic flame
#

I have this blood splatter particle system that generates a random pattern based on noise, but every particle in the system has the exact same pattern, is there a way to change the offset of the noise when a particle is created?

meager pelican
#

You write your own skybox shader. Unity will call it at the right time, between the opaque and the transparent passes.

kindred crystal
#

ah -- yeah we do have a custom skybox shader

#

the problem i'm running into is unity only draws the skybox on fragments where depth is max (afaict)

#

so if i alpha out or drop fragments in our post-processed texture containing the opaque objects, the clear color comes through behind it instead of the skybox

meager pelican
#

I have no idea what you're saying, sorry.

I mean, if a tree is at the midpoint between the skybox and the camera, it SHOULD block out the skybox. So the only place you want a skybox to show up is where you DON'T have geometry, which is why they draw it between opaque and transparent passes. This avoids drawing unnecessary pixels where the skybox is occluded, and is faster. Takes advantage of an early-z test in hardware, the fragment shader stage never even needs to be called for occluded pixels.

meager pelican
#

You may need to...write depth in your post processing shader to a NEW depth buffer, either copying it from the old or dropping it out to the far-plane. Then you don't have to have some kind of other pass.
But IIRC, having a bunch of depth buffers is a PITA. And IDK if I can tell you how to do that. But you shouldn't have to save/restore type of logic, just replace type of logic. Maybe.

kindred crystal
#

hmm okay, thanks!

dim yoke
# night isle ok i got it working with multiple passes but because im using _MainTex_TexelSize...

Back to the original issue, in order to make it always one pixel width, you have to offset the outline by exactly the amount of one pixel on the screen. I think 2f * Camera.main.orthographicSize / Screen.height should give you (with multiple screens and cameras that may get messed up tho. Calculating that in shader using screenparams and orthoparams could be bit safer in that way but if you need to do that in every of those 4 passes, thats going to add bit of overhead. The amount of overhead is going to be very negligible anyways because the vertex count of those sprite meshes are very low) the amount of units (meters) one pixel on the screen covers. If you offset the outline by that amount (note that that’s the offset in world space. If you offset by that amount in local space, you will get varying results between objects) on every direction, you should in theory get one pixel width outline (in practise you may get some edge cases very rarely). You could use global shader properties to give that value for all the shaders at once. Using 4 extra passes just doesn’t sound the most efficient way but that’s most likely not going to going to be a big performance problem either. I think that’s pretty close to what the default UI outline effect does too (actually just read some posts about the UI outline being very slow on mobile platforms but those posts were years old so that’s most likely not the case anymore. You can always use profiler if you’re worried)

night isle
#

yea ive actually looked at the ui outlines code and im pretty sure its just duplicating verts and offsetting them sort of like i am

#

i havent actually thought of trying to get the exact pixel size somehow so ill definitely try that now

#

i have no clue how i havent thought of this

#

i literally played around with the _ScreenParams variable

dim yoke
#

That’s the way youd do that with partial derivatives too. Partial derivatives are just very useful for getting the amount to offset to get exactly one pixel width offset (using partial derivatives you can very easily get the amount of offset on local space for example)

night isle
#

i might just be overlooking something obvious but what

dim yoke
night isle
#

oops

#

my ba

#

D

#

oh yes i think this works

#

ok its not quite right

#

its not 2f *

#

it seems to be around 0.25 but not 0.25

dim yoke
#

I think you’re now trying to offset them in local space

night isle
#

thatd be it

dim yoke
#

You can first transform the local space position into world space, offset that value and then transform it from world to clip pos

#

You can use unity_ObjectToWorld and UNITY_MATRIX_VP matrices for those transformations

night isle
#

still, its sometimes a bit too small

dim yoke
night isle
#

but then theres even more missing edges

#

perhaps its just a matter of getting it as close as possible

#

2.85 seems to be it

#

tried changing resolution and aspect ratios etc and 2.85 * (unity_OrthoParams.x / _ScreenParams.x) seems to give 1 pixel

#

2.83*

dim yoke
night isle
#

haha yea, ive been on and off trying things for the whole day

#

actually

#

might be to do with my custom projection i just realised lol

#

ok ok ok ok ok

#

can you see it

#

it is 2 *

dim yoke
#

No idea what that means but yeah, just multiply that weirdo number by 2 and you get somehing like 2.8

night isle
#

but i stretch everything since my camera is at a 45 degree angle

#

welp thank you either way, would not have been able to do this otherwise

dim yoke
#

Np

night isle
#

that number is root 2 i think

#

yea it is

shadow locust
#

const float RootTwo = 1.41421356f;

#

use that so your code is readable

dim yoke
night isle
#

yea, its an interesting setup

#

sort if isometric

#

but then theres actual 3d aswell

night isle
#

little update incase anyone ever looks at this: since my camera can rotate the world space conversion actually sort of breaks this, so i removed that

dull lintel
#

How do includes work for shader graph custom functions exactly? I've seen custom functions that can seemingly reference anything in URP without manual includes, but I'm running into issues where I'm trying to use structs like InputData and BRDFData but they aren't recognized identifiers. Then when I try to include the URP .hlsl files with them, it seems to redefine symbols and cause errors that way. Anyone have experience working around this stuff?

#

Nevermind I just forgot to block things out of SHADERGRAPH_PREVIEW, lol

hoary merlin
#

So, i'm not sure if this is a shader issue or a particles issue, but i'll post this here anyway:

I created a shader that moves vertices up and down in object space. Everything's fine when I apply the material to a mesh and scale it up and down, as intended. Here's what it looks like.

#

However, if I import the mesh and material into a particle system, it stops working as intended when i scale the particle start size.. If i have understood the pproblem correctly, it is switching to world space for some reason. Is this is a shader issue or a particles issue?

#

I'm very new to shaders and particles, so I'm not sure what I should be doing here, or how i can troulleshoot

grizzled bolt
hoary merlin
grizzled bolt
hoary merlin
#

Interesting, thank you. I'll look it up and see if it helps solve the problem

dim yoke
#

If the x and y rotation of the camera is not the same, youd need to multiply both axes by their own multiplier. unity_OrthoParams.x / _ScreenParams.x and unity_OrthoParams.y / _ScreenParams.y should actually always be equal to each other so you could just pick either of those and use for both axes. Only the multiplier should vary when rotating the camera

night isle
#

its not the multiplier, its that the object rotates in world space however it stays upright relative to the camera

#

essentially i want to disregard the world rotation

#

and scale too i suppose since i dont use scale

#

extra performance aswell by saving a few matrix multiplications i guess

dim yoke
#

I don’t quite understand what you mean by that so could you visualize how you’re rotating the objects and how you would like to get the outline for those rotated objects?

night isle
#

i just meant that i dont actually care about the world position of the object so im doing everything in object space

keen sparrow
#

Heyas,
Recently I made (through Shadergraph) a shader that projects a grid on a flat plane mesh. During runtime I'd like to be able to have certain areas of tiles displayed in green or red (areas determined at runtime as well). I considered making a seperate mesh for the highlighted area, but I wondered if there's a good way of doing this through the shader itself.
Is there a way of mark areas (through script, during runtime) of my grid and changing the displayed color based on that (and how performant would this be)?

grizzled bolt
#

@hoary merlin Multiplying the flapping motion by size via custom vertex streams works to constrain the motion to particle size

hoary merlin
meager pelican
#

Last I knew, SG didn't support reading compute buffers or whatnot directly. Although you may be able to pass data that way with a custom node.

#

Read/sample the texture at grid-color-pixel centers to avoid fuzzy edges.

#

You'll have to pass in grid size info.

#

You could even pull it all off with a quad.

meager pelican
#

That's in SG, not just VFX, too? Hmm

shadow locust
#

lemme check

keen sparrow
# meager pelican Are you deforming the individual points in the plane, or does it stay "flat"? I...

The individual points of the plane can be deformed, so it's not entirely flat no. The grid can be "any" size, but is always rectangular and of a single layer. Not sure if that matters at all.
I'm not that experienced with shaders, so in laymen: on creation of the grid I'd have to create a texture2d of the same size (in pixels), and multiply individual tiles to the colour of the corresponding color.
I use a subgraph (shown below) to create the grid graphic, how would I tie the node's positions (and scale) to the texture's pixel-positions?

meager pelican
#

I'm not 100% sure in your use case. IDK if the colors "deform" with the object or not. You could project them logically flat by "zeroing" out, say, the Y coordinate if the plane is height mapped on the Y for example.

As to the plane, you cannot tell for any individual triangle where it is at unless you pass more info, since a plane is composed of many triangles. UV's might help here.

So you could pass the world space size of the entire grid's dimensions, and offsets, and then compute world-space pixel locations zeroing out the Y value to make it "flat" and then computing its locaiton in the grid for (x, y) (really x, z with Y zeroed out in 3D space) and then do your lookup to get color.

I'm spitballing here.

#

And if you can do all that, you should be able to just color the plane directly, inserting the grid as you go, rather than projecting some grid "on top" of the already shaded plane. But then again, maybe you want to. IDK.

lament jolt
#

for some reason in urp the render texture is grayscale when read from a shader

meager pelican
hoary merlin
#

or directly drag and drop the texture into the graph

static elbow
#

Hello! I'm trying to learn shader graph and I have a question. Why if I separate one component of UV coordinates it looks different to linear grayscale gradient? So for example float value of 0.5 mapped to something like 186 on 0-255 RGB not 127. Am I misunderstanding something or is my setup wrong?

static elbow
sterile zinc
#

Hello, is there a way I can have one parameter that can effect multiple shaders? For example I'd like to have a dissolve effect on a character that has multiple materials/shaders

dim yoke
sterile zinc
#

though I'm completely clueless about scripting

dim yoke
#

You can just call Shader.SetGlobalFloat(”PropertyName”, thevalue); on any script

sterile zinc
#

I'm talking about URP's shader graph where you can expose certain parameters in the inspector

sterile zinc
#

I'm just the 3D artist on the project I'm working on

#

In Blender there's the "drivers" system, where changing one value can affect any other value

dim yoke
#

So you’d like to do that in editor without any scripting right? Atleast I don’t know a way to do that

edgy crane
#

Hey guys, is there a way for a Shader to consider collision with a moving object though shader graph ?

sterile zinc
dull lintel
#

Is there an easy way to tell if a vertex is part of a front or back face (if you're rendering double sided) in the vertex part of a shader? I'd like to inflate the inside-facing faces of a mesh a little bit to avoid z-fighting.

#

Or is there a better way to do something like that?

shadow locust
dull lintel
#

Can't be camera-dependent unfortunately, since there may be faces on the outside of the mesh that still face the camera.

#

I know there's SV_IsFrontFace but I'm not quite sure how to use it in this context.

meager pelican
# dull lintel Is there an easy way to tell if a vertex is part of a front or back face (if you...

No, no easy way, since one vert is just a point in 3D space.
IsFrontFace is available to pixel/fragment stage, but not vert stage.
If you use a geometry stage, you can tell (and even set the value) like @shadow locust said, if it is facing away from the camera. You may also be able to do that in the vert() stage the same way after transforming the vertex normal, but be aware that vert normals aren't necessarily the same as polygon normals (the 3 points) like when you're using smooth normals.

There is no such thing as a camera-independent back/front face, as the camera view direction basically defines the result. Of course any polygon on a mesh can be either back-facing or front-facing, but should not be both, and I don't remember how any edge cases work but they should be well defined.

dull lintel
#

Gotcha, I'll give that all a shot, thanks!

meager pelican
# dull lintel Gotcha, I'll give that all a shot, thanks!

To do it in the geometry stage (slow), you need all 3 verts, and you can do some formula to calc the normal direction. That combined with the camera view direction will get you a result. Google is your friend here.

You could also research "flat shading" as they often use the same normal across a polygon. As an aside, you can also calc a flat surface normal with ddx/ddy, I think catlikecoding does that in one if their tuts, but it is only available in the frag stage.

proud coral
lethal fern
#

Is there a way to disable parts of a shader based on whether its in the scene view or not? I have a distance based dithering effect in a shader and I would like to disable it in scene view so I can work with the objects up close

lethal fern
#

if anyone uses the search function and finds this later I solved it using a custom render feature

using UnityEngine.Rendering.Universal;

public class SceneViewFeature : ScriptableRendererFeature {
    private SceneViewRenderPass _sceneViewRenderPass;

    public override void Create() {
        _sceneViewRenderPass = new SceneViewRenderPass();
    }

    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) {
        renderer.EnqueuePass(_sceneViewRenderPass);
    }
}
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class SceneViewRenderPass : ScriptableRenderPass {
    public SceneViewRenderPass() {
        renderPassEvent = RenderPassEvent.BeforeRendering;
    }
    
    public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) {
        if (renderingData.cameraData.camera.gameObject.name == "SceneCamera") {
            Shader.EnableKeyword("SCENE_VIEW");
        } else {
            Shader.DisableKeyword("SCENE_VIEW");
        }
    }

    public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { }
}

Obviously this only works for urp/hdrp but in builtin you can just use OnPreRender and have a similar body to OnCameraSetup

latent thistle
#

hey anyone can help me ? i try to add additional lights for my cel shader; but i have a shdow issue; the main shadow looks good, but additional one no; I did my shader with a lit output.

teal breach
#

can you show where you are doing the color calculations for your custom lighting?

cosmic prairie
#

w8 it has straight parts

#

damn

dim yoke
#

I'm currently having some very weird results with my compute shader performance. I have two kernels which I can choose between. The first one simply draws to a texture (which is actually just buffer of ints but that shouldn't matter in this case) with given color property and the second kernel draws to texture with color randomized per every pixel separately. So the second kernel does exactly the same as the first one but in addition to that, it does some extra calculations to calculate the pseudo random color. But still for some very odd reason dispatching the second kernel seems to be faster than dispatching the first kernel (stats window shows better fps when using the second kernel and CPU time seems bit lower)

latent thistle
# teal breach can you show where you are doing the color calculations for your custom lighting...
void AddAdditionalLightsSharp_float(float Smoothness, float3 WorldPosition, float3 WorldNormal, float3 WorldView,
    float MainDiffuse, float MainSpecular, float3 MainColor,
    //returns
    out float Diffuse, out float Specular, out float3 Color) {

    Diffuse = 0; MainDiffuse;
    Specular = MainSpecular;
    Color = MainColor * (MainDiffuse + MainSpecular);

#if defined(SHADERGRAPH_PREVIEW)
#else
    float highestDiffuse = Diffuse;
    int pixelLightCount = GetAdditionalLightsCount();

    for (int i = 0; i < pixelLightCount; ++i) {
        Light light = GetAdditionalLight(i, WorldPosition, half4(1, 1, 1, 1));

        half thisDiffuse = light.distanceAttenuation * light.shadowAttenuation * saturate(dot(WorldNormal, light.direction));

        thisDiffuse = light.distanceAttenuation * light.shadowAttenuation * saturate(dot(WorldNormal, light.direction));
        half thisSpecular = LightingSpecular(thisDiffuse, light.direction, WorldNormal, WorldView, 1, Smoothness);

        Diffuse += min(MainDiffuse, thisDiffuse);
        Specular += min(MainSpecular, thisSpecular);

        if (thisDiffuse > highestDiffuse) {
            highestDiffuse = thisDiffuse;
            Color = light.color;
        }
    }

    Diffuse += MainDiffuse;
#endif
}```
verbal pagoda
#

How do I send an integer or float to the shader for each vertex in my mesh? I know how to set a property, but in my case, the variable that defines colour changes based on every point in the mesh.

The example I have is that I have one galaxy object, composed of points (vertices) that represent stars. Each star has a temperature and that temperature should go through a black body function in the shader to get the resulting colour. I have the function, just need to figure out how to get the temperature of the star into the shader for each star (for each vertex, vertex = star)

low lichen
#

Otherwise, you can make a ComputeBuffer of your data where each vertex ID is an index into that buffer.

verbal pagoda
#

Yes, using a MeshRenderer.

#

merging another mesh's vertex data? but i'm just trying to attribute one number (temperature) for each vertex

#

if there's another way to render so many points other than using meshrenderer i'd like to learn, new to unity, have more experience with openGL

low lichen
#

You will have to choose some built-in vertex attribute to store your data in, like vertex color or a UV channel.

verbal pagoda
#

alright, i'll look into it. thank you

#

any good doc on vertex streams somewhere?

low lichen
#

But are you sure you can't modify the original mesh?

#

Are you not generating the vertices in code?

verbal pagoda
#

the vertices are generated in code, and the positions of them are sent to the shader. I don't know how to send the temperature of each vertex to the shader as well, that's my problem. I have a function in the shader that converts temperature to color, and that's what I'm using to colour the points (stars) of the mesh

#

but if i send the temperature as a property to the material, it colours all the stars the same, so i want to find out how to attribute temperature for each vertex point

low lichen
#

You can just store the temperature in something like the red channel of the vertex color attribute

verbal pagoda
#

kind of like attributing normals or colours, but i can't attribute colour unless i do the calculations on the cpu and then send that colour data to the shader

low lichen
#

You don't have to store color in the color attribute

#

It's just 4 floats, you can store whatever you want

#

Same with normals and UV

#

All that matters is how your shader interprets it

verbal pagoda
#

hmm, but i guess i need to figure out how to store integers that go up to 100 000 with 4 floats?

#

or is it okay to just make one of the floats 100 000 already? it won't get clipped to something between 0 to 1?

low lichen
#

You don't want to store temperature in a float?

#

It won't be clamped

verbal pagoda
#

okay, then that's fine. don't know why i believed otherwise. thank you!

fervent flare
#

I'm not experienced enough with shadermath to understand any of the breakdowns online

latent thistle
#

for my main light i do

#if defined(SHADOWS_SCREEN)
    half4 shadowCoord = ComputeScreenPos(TransformWorldToHClip(WorldPos));
#else
    half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
#endif
    Light mainLight = GetMainLight(shadowCoord);

how can i do something similar for my additionals lights ?

keen sparrow
#

Heyas,
I'm looking to make an inner-glow shader for flat meshes (quads, planes, etc) in Shadergraph preferably. The meshes face-up and consist of squares in any arrangement (see artist rendition below).
I figure this should be pretty easy, but all tutorials I find are for 3d objects which doesn't work here since all vectors face in the same direction. Also adding 'glow' to any shader google search makes finding anything useful impossible. :p

PS: Thanks for the help yesterday, CarpeFunSoftware. Took some effort, but managed to get it to work.

dim yoke
#

Any ideas of how unity draws this 🔽 one pixel width grid? I used partial derivatives to get one pixel width lines but still I get occasionally some edge cases ⏬ especially when I use very dense grid and zoom close to the plane (I believe it's due to floating point inaccuracy + the grid line landing exactly between two pixels on the screen). I'm using orthographic camera and the lines are always horizontally and vertically as in the images below

meager pelican
# keen sparrow Heyas, I'm looking to make an inner-glow shader for flat meshes (quads, planes,...
lethal fern
#

anyone know why including a shader could cause this when building?

knotty juniper
lethal fern
#

as in adding it to this list

knotty juniper
lethal fern
#

but 309 billion?

#

and if i dont include it the shader just renders black

#

is there a different way around that?

knotty juniper
#

its mostly needed if you have some code that will use some shader variant that unity does not reference directkly

lethal fern
#

oh gotcha

#

so i removed it from there but how do i fix the rendering black issue

knotty juniper
lethal fern
#

still renders black

knotty juniper