#archived-shaders

1 messages · Page 48 of 1

lyric vortex
#

Ok I have checked the _CameraOpaqueTexture, it seems correct. It is updated correctly. So why my scene color node returns the value of the first frame ?

obtuse basin
#

so i have a really newbie question about shaders. i don't know the first thing about programming them yet but i picked up a shader asset that lets me palette swap my sprites by changing the material. i got it working just fine in a 2d urp project but now im' trying to use it on a spriterenderer in a 3d urp project and it's not changing the colors with material. i'm pretty sure i set it up right, do some 2d shaders not work in 3d even on 2d assets like spriterenderers?

lyric vortex
#

@regal stag I can reproduce my refraction problem on a simple 3D URP project. I have only one plane with the refraction shader, and the skybox shader on the scene.

regal stag
lyric vortex
regal stag
#

If they're lit for example the 2D and 3D lighting systems are completely different.

lyric vortex
regal stag
#

A way around that might be to use a Realtime Reflection Probe, though that might not perform well?

obtuse basin
lyric vortex
#

How can it be backed if it can dynamically move ?

regal stag
lyric vortex
regal stag
#

Can you show a screenshot?

lyric vortex
#

Editor scene before play:

#

Game playing:

regal stag
#

That's not the refraction, that's reflection.

lyric vortex
#

Game playing cubemap changed:

#

Ah ok sorry because it's named refraction in the unity water shader example.

regal stag
#

The material looks grey, which also means the Opaque Texture is disabled on the URP asset

lyric vortex
#

it's enabled on the main project, I try to enable on the test project too

regal stag
#

The problem isn't the refraction / Scene Color, it's the reflection cubemap sampled by the Lit Graph - visible when the Smoothness is larger than 0.

lyric vortex
regal stag
#

Placing a Reflection Probe in the scene set to Realtime could work. If you just want the skybox in it, remove all layers from Culling Mask.

lyric vortex
regal stag
lyric vortex
#

Which shader backed something ? The skybox shader or the plane shader ?

steady nexus
#

Hey

#

I don't know if it's the right chat

#

But...

#

Someone know how can I export shading nodes from Blender to unity or compact nodes into an image/file .png?

#

.
I tried something called "baking" but it turns my glass texture into a non-transparent texture with very bad color instead of the original.

At the same time I found another video where they use a Blender extension called "nodes exporter" which copy and paste the nodes as they are from Blender to Unity, but I can't find it online to download it

grand jolt
#

Hey, I've been trying to work on recreating t3ssel8r's famous pixel art style in unity 3d. I created a pixelation effect but it doesn't look nearly as good.
``
Shader "Hidden/NewImageEffectShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_pixels("Resolution", int) = 512
_pw("Pixel Width", float) = 64
_ph("Pixel Height", float) = 64
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always

    Pass
    {
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag

        #include "UnityCG.cginc"

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

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

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

        float _pixels;
        float _pw;
        float _ph;

        sampler2D _MainTex;

        fixed4 frag (v2f i) : SV_Target
        {
            float _dx = _pw * (1 / _pixels);
            float _dy = _ph * (1 / _pixels);
            float2 coord = float2(_dx * floor(i.uv.x / _dx), _dy * floor(i.uv.y / _dy));

            fixed4 col = tex2D(_MainTex, coord);
            return col;
        }
        ENDCG
    }
}

}
``

#

Does anyone know how i can create his shader?

lunar valley
lunar valley
#

You could also try to progressivelly down and then upscale your renderTexture, but make sure you do it with point filtering

cosmic sphinx
# grand jolt Hey, I've been trying to work on recreating t3ssel8r's famous pixel art style in...

I think t3ssel8er doesn't decrease the resolution with shader - he just decreases the real game resolution. You can see in his editor window that the selected resolution is just small (e.g. 640x360 or 960x540). In shaders, he mostly adjusts the color so the color palette is reduced to a small number of choices. He is either rounding those up to certain thresholds or using some kind of look-up-table.

steady nexus
lunar valley
steady nexus
#

Is a plugin that I need to install, or is it something that is already on unity?

rare wren
#

BiRP can be used, but not all features might work iirc

steady nexus
#

Ok

buoyant geyser
#

It’s heavier than traditional downsampling but it has a lot of benefits in clarity

#

You’ll get a similar level of smoothness to bilinear filtering while retaining an accurate color palette like you would in point filtering

lyric vortex
#

What is the fastest/most efficient way to create a water with reflection shader ?

lunar valley
lyric vortex
# lunar valley there is none, you will need to specify your needs so that we can answer properl...

I'm trying to render as best as possible water spots (drawn using a water shader on a plane) in a golf terrain. Constraint, this must run on mobile devices. If reflection is possible without eating all the gpu then I will use that. Currently I'm using the Scene color node in my shader, the problem is that the reflected image is not dynamic (you can see my previous discussion, yesterday with @regal stag)

lunar valley
lyric vortex
near karma
#
[numthreads(10,10,10)]
void NoiseMain (uint3 id : SV_DispatchThreadID)
{    
    Density[ id.x, id.y, id.z] = 5;
}

This shader creates an array of floats, but only the very bottom layer is '5' the rest are '0'. I don't understand, the buffer is sized correctly. I don't see any reason for this to be happening, although I'm new to compute shaders.

low lichen
near karma
#

Is there a thread limit?

#

I didn't imagine it would be this easy to hit

#

But it still sets some values so...

low lichen
#

If numthread is 10x10x10 and the dispatch count is 10x10x10, that means the thread count will be 100x100x100, since they are multiplied together. Is Density 100x100x100?

near karma
#

no, lol

#

I'll look into .Dispatch and numthreads promptly

#

Huh...

#

I changed the dispatch threads to 1x1x1 and now I only get a single row of 5s along the x axis.

near karma
#

This is very confusing

#
densityShader.Dispatch(noiseKernel, 1, 1, 1);
[numthreads(10, 10, 10)]
void NoiseMain (uint3 id : SV_DispatchThreadID)
{
    Density[ id.x, id.y, id.z] = 5;
}

Really not sure what else to share, it's outputting a row of 5s on the x axis among many 0s, but it was outputting a whole plane of them when dispatched with 10 x 10 x 10.

#

Now it only does the x axis row, even if I change it back

#

I've been fiddling with dispatch and numthreads and I see no rhyme nor reason to what make what work how. I've gotten a bunch of solid planes to render again, but I still can't get a solid cube

lunar valley
near karma
lunar valley
near karma
outer lake
#

I want to use vertex weights in my shadergraph but idk how, what's the input called?

buoyant geyser
#

I'm writing a transparent fog shader, the shader needs to be in a non-transparent render queue so that i can receive shadows

#

The issue is that when i enable any sort of alpha blending in the shader, the render order is broken and the fog renders behind everything else

#

alpha blending on

#

alpha blending off

#

all i changed between the two screenshots was this:

before: #pragma surface surf BackFace keepalpha decal:blend
after: #pragma surface surf BackFace keepalpha //decal:blend
#

what could be causing this, and is there any way around it?

#

the tilesets in the image are in the geometry queue, the fog is in the alphatest queue

#

interestingly the fog does blend over the character model, the rest of the environment is (tilemap) sprite renderers and the fog itself is a quad mesh renderer

#

the sprite renderers here have a custom shader that's setting them to be in the geometry queue, though

#

turns out i had manually set the sorting layer of my tilemap shader in the material, it was ignoring the shader

#

though it seems im still unable to make the shader recieve shadows

#

the renderers are set to recieve shadows, the object im using to create those shadows is in the light's culling mask, and the light is set to hard shadows but im getting nothing

#

even if i disable the alpha blending on the fog shader, still nothing

#

is there something specific i'd need to do with this shader to make it recieve shadows?

#

the relevant shader code

shrewd spoke
buoyant geyser
#

yes! thank you this worked

lunar valley
#

somewhere in the internet, maybe...

indigo citrus
#

what is the PBR graph in URP?

broken vigil
#

So, let's say I want characters in my game to have faces, which is a bit of a radical idea, but I've got a vision.

What's a good practice for making animated 2D faces on 3D models? Right now, my ideas are to have a texture which has all the different face sprites on it, and swap between them using UVs, but I'm torn between using Decals to project it directly onto the model, or using an invisible copy of the head, which has the face rendered onto it.

I don't want the faces to be a part of the skin texture/material itself, since that feels like it would make it harder to edit freely, and wouldn't let me have the faces be transparent as easily.

Is there some resources I can look into for this kind of "2D face on a 3D model" thing?

full void
#

I have a quick question on texture arrays. Is it possible to tile the textures in a grid? What I'm trying to achieve is a shader that let's me move around a grid of images generated by loading many tiles into a texture array but I'm having serious difficulties with the second axis. Right now I'm able to do this

#

but what i'm trying to achieve is this

#
                {

                    v2f o;

                    
                    o.vertex = UnityObjectToClipPos(vertex);

                    o.uv.xy = ((vertex.xy) * 8 + float2(_UVOffsetX,_UVOffsetY)) * _UVScale;

                    o.uv.z = ((floor(vertex.x*8) + _UVOffsetX )*_UVScale) + 3.5;

                    return o;
                } ```
#

with this code

#

has anyone else had experience with this? thanks in advance

broken vigil
#

Is there a way to access unity's SSAO Texture in a custom renderer feature, or access the texture in an HLSL file for use in shadergraph?

#

or make a custom one from the depth texture or whatnot

indigo citrus
#

hey

#

I was following this tutorial to have an energy shield

#

his results are like this

#

but this is my result...

#

I have an almost 1 to 1 shader graph, but we use different unity versions so I can't copy exactly

#

for some reason the color is not being applied

amber saffron
indigo citrus
indigo citrus
#

it's like this now

#

I think emissions are disabled in my scene... because I tried adding fire from particle pack and it looked very bland

amber saffron
#

What if you just disable alpha clip ?

shadow kraken
warm rapids
#

I've got this project to make an outdoor scene with a set amount of deliverables. One of the deliverables is 3 Shaders/Materials made within Unity. I've been working on one that will let me add moving grass to the scene, but I am not sure what I could do for the other two. If anyone has any suggestions or resources for any shaders I could use to enhance this scene, that would be great.

shadow kraken
indigo citrus
#

it's either all bloom or no bloom

shadow kraken
#

That's correct

indigo citrus
#

how do I make only the object emit then?

shadow kraken
warm rapids
#

So for a clouds shader, I would make the clouds material in shadergraph and then apply that to a skybox right?

shadow kraken
#

You can use the bloom threshold to limit it

indigo citrus
#

right

#

so I can make the world have a limited amount, but the object have a lot?

cosmic prairie
#

oh nv

shadow kraken
cosmic prairie
#

m

indigo citrus
cosmic prairie
#

the stronger the emission the stronger the bloom

#

enable hdr in camera

#

give your object a lot of emission

#

and crank up the threshold

amber saffron
#

@indigo citrus Like I said, what does it look like if you disable alpha clip on the material ?
I'm not sure but it looks like emission is ignoring alpha.

One other option would be to use unlit transparent, with additive blending

cosmic prairie
#

looks like the alpha is ignored

indigo citrus
#

not sure why

cosmic prairie
#

multiply emission with the value u use for alpha

tacit parcel
# indigo citrus it's like this now

I think the shader itself still has some problem
There's no gradient from the edge of the sphere to center, and the sphere doesnt seem to react/intersect with the level
Maybe you need to activate some depth buffer or something

cosmic prairie
#

alpha clip shows that it uses the depth buffer correctly

indigo citrus
#

at least it glows now

cosmic prairie
indigo citrus
#

1 sec

amber saffron
#

Because you are only using emission and don't care about the surface color, I'd really recommand giving a try to the unlit method

indigo citrus
#

same thing

indigo citrus
cosmic prairie
#

eh

amber saffron
#

Yes

#

For example, unlit with alpha blend, and plug what is currently emission into the color output

indigo citrus
#

sorry about that

indigo citrus
amber saffron
indigo citrus
#

what does it do excatly?

#

not really sure

amber saffron
#

It will not render pixels where alpha is bellow the clip value, reducing a bit the cost of the shader

indigo citrus
#

I see

indigo citrus
#

how do I make the power of the fresnel go from 4 to 6 and back over time

#

also I want to be able to increase the power property by code

cosmic prairie
amber saffron
indigo citrus
amber saffron
cosmic prairie
amber saffron
amber saffron
cosmic prairie
#

so per thread group it can sometimes optimize? is this gpu / graphics api dependent?

amber saffron
#

When talking of opaques, for example in HDRP there is a depth prepass, and opaque objects are rendered afterwards with a equal depth test.
So the clipping is done early on in the depth only pass, and cost is reduced but the ztest in the subsequent passes

indigo citrus
proud hinge
#

Can someone help me with a small code🥹

amber saffron
#

time.sin -> in
-1 ; 1 -> range in
power min ; power max -> range out

amber saffron
indigo citrus
#

I'm lost

#

I started doing this 3 hours ago I really don't know any of that

amber saffron
#

Remap node

#

It will do exactly what it sounds like, remap a value from an input range to an output range

indigo citrus
#

this doesn't breathe in

#

oh wait

#

actually it does

#

it's my editor lagging

proud hinge
#

Im not able to do this as asked in my assignment

amber saffron
proud hinge
#

Okay

indigo citrus
#

thanks remy

buoyant geyser
#

Is there a way that I can apply a Gaussian blur effect to the lighting and shadows applied to a surface shader?

#

Trying to get a pseudo volumetric lighting sort of effect, but the hard shadows being cast on the fog doesn’t look great

minor pewter
indigo citrus
#

the texture is not being emitted

#

(I'm using URP)

#

I want the orb to have a texture with the provided pattern

lunar valley
indigo citrus
#

I want the pattern on the energy sphere

lunar valley
indigo citrus
#

look I started this 4 hours ago

#

never touched it before

vague sinew
indigo citrus
regal stag
#

Is the texture assigned on the Material?

indigo citrus
#

how do I check that

#

ah

#

got it

regal stag
#

Would be the material asset assigned to your sphere. Will be listed under the MeshRenderer component.

indigo citrus
#

works now

#

thanks

#

I thought I only needed to assign the texture once

cosmic prairie
indigo citrus
#

I see

regal stag
#

Be aware that as Let'sBlend is hinting at, using a Vector4->Alpha will take the red component so this will only work provided the Color has some red values.
I tend to keep Color and Alpha calculations with separate chains as it makes things clearer.

indigo citrus
#

yeah I see

regal stag
#

Would probably multiply these ports instead

indigo citrus
#

yeah I see

grand jolt
#

So I have a simple parallax shader using shader graph, and I have artifacts at the corner that I don't know how to handle

amber saffron
grand jolt
#

Got it, I was looking at research articles on POM, and everything was way over my head 😅

vocal narwhal
#

A common way to work with it is to use a trim, literally covering it with another mesh 😆

amber saffron
#

Yes, indeed, because you usually apply POM to flat surface, you can hide the end of it with a mesh 🙂

grand jolt
#

Got it lol

grand jolt
#

Is this effect basically why Parallax isn't used in games very frequently?

amber saffron
#

It's also because it's a bit costly, and works only for flat-ish surfaces

amber saffron
grand jolt
#

That makes sense, thanks for the explanation!

grand jolt
#

Yeah... That's complicated lol
I would have to rewrite this using a shader, not a shadergraph, and the research papers AMD released years ago are gone, so that's unfortunate

#

The Tatarchuk paper on POM i mean

#

The only implementation I found is in the unity core HDRP shaders and a forum post & video from 2009

#

I might try my hand at tessellation as well, that seems quite useful

amber saffron
grand jolt
#

Also, thanks for finding it! I was searching all over google at couldn't find it

glass coyote
#

hello! is there a good terrain shader for webGL?

#

that usees splatmaps or paintable layers

glass coyote
#

never mind

toxic flume
#

Can I have a cut out shader for sprites? I mean with sprite renderer with sort order like standard sprites

grizzled bolt
toxic flume
#

They both have sprite renderer with sprite and a cutout shader

#

Solved, I should have added

 ZTest Always
 ZWrite Off
 Properties
    {
        [PerRenderData]
        _MainTex ("Texture", 2D) = "white" {}
        _CutoutValue("Cutout Value",Float) = 0.5
    }
    SubShader
    {
        Tags
        {
            "RenderType" = "TransparentCutout" "Queue" = "AlphaTest"
        }
        LOD 100
        Cull OFF
        ZTest Always
        ZWrite Off

grizzled bolt
#

Does ztest always actually work? I'm not sure if I understand what it does but it seems to make it ambiguous which one is drawn first

silk wharf
#

Hello there, How can I make a specular lighting effect into a sprite shadergraph ? I though of using the dot product between the world position and directional light but it doesnt show the result, also I noticed that using a standard Vector3 instead of ligh direction still does get displayed into my sprite, what could I be doing wrong?

#

Here is how my graph looks

grizzled bolt
silk wharf
#

Is this how the graph should look like based on what you said?

grizzled bolt
silk wharf
#

Is the normal vector inside the functions 2D renderer doesnt support?

#

I noticed that by setting the Z value of my vector to be 1 instead of 0, now I get color on my material, but it covers the whole sprite

#

like it goes from gray to black on the whole sprite

#

this is the current result

grizzled bolt
grizzled bolt
#

Maybe "fragment distance to light position" is more what you're after

silk wharf
grizzled bolt
#

Unclear what "highlight" means exactly

silk wharf
#

Something like the white spots here for example

grizzled bolt
#

You'll need also a normal map for that

silk wharf
#

I am using shadows with a shape light and the normal seems to be projected onto the background of my scene as I move

#

I assume I need to ignore background to receive shadows somehow to fix that

grizzled bolt
#

You'd have to implement normal mapping manually to your custom lighting

grizzled bolt
silk wharf
grizzled bolt
silk wharf
#

Alright, thanks I will ask for that there

#

But I still need to figure this highlight thingy out, I thought of another solution but not sure on how to implement it

#

I don't need my specular to be highly accurate or realistic, I just need some sort of visual indicator of the metal shining, it can be a simple shape over the sprite

#

I thought of using a sphere mask and map it over the sprite, and set its offset based on the direction of the light / a specified vector

#

Does that sound suitable? or is it an overly complicated idea?

grizzled bolt
silk wharf
frozen dawn
#

how do i increase shadows render distance

lunar valley
frozen dawn
#

yeah there is something but how do i use the tier that i want and choose the shadow render distance

frozen dawn
#

i dont understand this

#

oh iam stupid sorry

scenic ice
#

Hey guys. I'm working on a 2D over-world map that needs to have Fog of War on it to hide the areas of the map that haven't been explored. What I'm thinking as of now is to have the map as a seperate Layer under the fog then having a shader where I can define coordinates where the fog shows through. I'm not really well versed in shaders so anyone who can give me some advice on this would be appreciated.

#

I would like to make fog of war like this.

solid scaffold
#

Hello guys, any idea how I can avoid this on my line renderer :

latent mirage
buoyant geyser
#

Is there any feasible way to apply blur to a shader's lighting model? I'd like to soften the lighting and shadows on my fog shader, but it doesn't seem like unity supports this in any way with the built in render pipeline

#
{
    half NdotL = abs(dot(s.Normal, lightDir));
    half4 color;

    color.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten);
    color.a = s.Alpha;

    return color;
}``` This is the current lighting model im using for this, but it doesn't seem like theres any way to sample neighboring positions to average the lighting or whatever
#

if this isn't feasible, could it be done in the finalcolor function?

grand jolt
#

Okay, how can I blur the background and foreground in my shader graph?

#

This is making me lose my fucking mind, I cannot figure it out, the edges are to hard, and I know there is a node I can use

buoyant geyser
#

can't speak for shader graph but in a traditional shader you'd either implement a guassian blur function or just sample neighboring texcoords and average the color

#

if nothing else i'd imagine you can make a custom node that implements this or something

grand jolt
#

yeah, feels a bit overkill though since I just need to soften the edges on a rgb

buoyant geyser
#

fundamentally that's how blurring works, you average to nearby colors

#

there might be some fancy edge softening thing im not aware of

remote nexus
#

Filled Font Shader?

lunar valley
pale python
#

hi,
is it possible to make a sample2D from float3 or float4/fixed4 ?
I mean can we reverse this
float3 color = tex2D(_tex, uv); ... instead of outputting float3 from tex2D , we output tex2D from a float3 , is it possible ?

low lichen
pale python
low lichen
#

This can be done with a Blit.

pale python
#
fixed4 main(v2f i) : SV_Target
{
    // Sample the main texture.
    fixed4 color = tex2D(_MainTex, i.uv);
    
    //  some other code that changes the value of "color" and makes it a completely different thing   
    ....

    // for this step , I need the sample2D from the final value of "color" ( if possible ) to be able to move on the next step

    // Return the final color.
    return color;
}
#

@low lichen that is what i meant 😄 , I think its gonna be expensive to go bk to c# then shader again

low lichen
pale python
low lichen
#

But what do you mean by "current" value? You already have code that is modifying color. You already have color. Why do you want to put it in a texture just so you can sample it again and get the same color?

pale python
low lichen
#

Still doesn't make sense to me. Are you going to sample it with a different UV value?

#

Are you going to sample it multiple times to calculate some average?

pale python
low lichen
# pale python is it possible to extract the sample from color ?

What you're saying makes no sense. sampler2D represents a texture object, with a resolution, texture format, filtering options. What kind of texture would you expect if I tried to convert a float4(0, 0, 0, 0) to a sampler2D? What would its resolution be?

pale python
#

tex2D(sample2D,uv) ===> float4

low lichen
#

That function is the equivalent of saying readTexture(texture, uv) => color

pale python
#

yea I dont know what is happening there but I think maybe we could somehow reverse it

#

im new to shader so I dont know

#

or how would anyone sample the updated color value ?

low lichen
#

A 2D texture is a grid of pixels, where each pixel has a color. tex2D lets you read from that grid of pixels. You're not sampling a color, you're sampling a texture.

#

Maybe it's best if you explain from a high level what you're trying to do.

#

And disregard how you were planning to do it for now

pale python
mental fern
#

Is it possible to make a shader that only lets the game display colors from a color palette of my choosing? I'm making a game using graphics based on the NES and I'd like to limit the game to only display the colors from the NES palette.

buoyant geyser
meager pelican
# mental fern Is it possible to make a shader that only lets the game display colors from a co...

It might be simplest to just use a LUT. See "LUT" in the article linked below:
https://www.nesdev.org/wiki/PPU_palettes#LUT_approach

NESdev Wiki

The NES has a limited selection of color outputs. A 6-bit value in the palette memory area corresponds to one of 64 outputs. The emphasis bits of the PPUMASK register ($2001) provide an additional color modifier.
For more information on how the colors are generated on an NTSC NES, see: NTSC video

grizzled bolt
#

A LUT works for the whole screen but it's got its own quirks

tropic badger
#

- Can i iterate through a passed texture to get every pixel's value? My texture is 1xN, where N is defined at runtime. Every pixel represents a world-space position, and i need to retrieve this data from the texture

prime shale
#

@low lichen

#

Thats peobably the closest you might get

pale python
#

in this example , i used uv coord as 0.7,1

prime shale
#

one thing I notice with your problems is that you seem to treat the GPU almost like another CPU in that you play hot potato with data all the time

#

lmao

#

going back and fourth constantly

#

anyways

prime shale
pale python
#

i really dont know the difference , iam really new

prime shale
#

whats the frame of referneces?

#

in the sense that I'm assuming with the screen

#

you want to get the final values from a shader right

#

you can only do that "blit" operation on the CPU

#

so my question is

#

do you want to know what the value of the pixel is on the CPU side? or the GPU side?

pale python
#

gpu side

prime shale
pale python
#

i actually know the value on both

prime shale
#

like the pixel coordinate?

pale python
#

yes

prime shale
#

or the color itself?

#

ah

pale python
#

like i know the x value would be 0.7 and y is 1

prime shale
#

well for the sake of simplicity, because your problems tend to be very confusing

#

say you wanted to display the exact value at a certain pixel coordinate

pale python
#

it will be something like that , cpu and gpu will have the same data

prime shale
#

on the shader side

#

so you have a texture2D that you are sampling that has your final colors within it

#

and to display the specific value on that texture2D across all pixels

#

or effectively get the color value from that single pixel

#

its as simple as

pale python
prime shale
#

tex2D(myFinalTexWithColorSampler, float2(0.7, 1))

pale python
#

how do i get myFinalTexWithColorSampler ?

prime shale
#

but in my code snippet

#

you instead input a CONSTANT

#

and thats how you have consistency

prime shale
#

do you mean how would you get your final color from a shader onto a texture2D?

pale python
#

i was trying to reverse tex2D(_MainTex, i.uv) ==> float3 to float3 ==> tex

#

but I learned that tex2D only reads pixel from MainTex , it's not really converting

prime shale
#

true

#

its a texture sampler

#

it only samples from a texture

#

a texture which is made up of a bunch of float4s in an array

#

its only reading though, it doesn't convert

#

if you want to convert that is a different story, and that goes back to what I suggested earlier which is that if you wanted to sort of do something like reconverting, you will need to use a Graphic.Blit

#

which is a bit involved

prime shale
pale python
#

thanks for explaining that , so u are suggesting that i create texture using graphic.blit then read from it using tex2D ?

prime shale
#

so say that you have a shader pass

#

that computes like a crazy rainbow that changes across many pixels

#

and you want to convert basically that float4 into a texture2D

#

yes? @pale python

#

reading back above looks like @low lichen was on the money with suggesting blit, but you confused the hell out of him

#

so whoops

#

looks like you disapeared for a bit @pale python but I'll continue with the explanation

prime shale
#

and you want to convert that into a texture2D, in that case you would use a blit

#

so in the C# side

#

you have to write a section of code that creates a render texture at a set resolution

#

so you can use something like rendertexture.gettemporary

#

then use
Graphics.Blit(sourceRT, myTempRT, myMaterialObject, 0);

#

so sourceRT is the original texture that your screen is currently seeing basically

#

myTempRT is the render texture that will obtain the colors

#

myMaterialObject is a material that has your shader on it

#

and then 0 is the pass index, for the pass that you want to compute the color from

#

after that blit operation, myTempRT is the texture that you are looking for

#

and in the next pass (or another shader), you can create another sampler2D _MyTexture field, and on the C# side you'll have to use Material.SetTexture("_MyTexture", myTempRT)

#

and then of course you would use tex2D(_MyTexture, i.uv) or tex2D(_MyTexture, float2(0.7, 1) to sample colors from it

#

and that is how you would effectively convert a
float4 > tex2D

#

this is also a core concept used in post processing effects, since often they are multipass and need to retain computed color values from previous passes

pale python
prime shale
#

I think its also important to mention honestly that if you are doing this, but only care about a single pixel then your probably best doing all of this on the CPU

#

and it'd likely be faster and much easier

#

but other than that I have no idea why you'd want to be converting it back into a texture

opaque timber
#

anybody use shader graph that knows why this could be happening or how to fix it? i'm using urp and i changed a few values on the shader graph but now it's just flickering between the old version and the new one. i couldnt find anything online after a quick google

i can post my graph if necessary

rustic peak
#

Hi All

#

Any tips for updating a shader I created in ShaderGraph in 2019 to 2021 Unity? Half of the windows are 'greyed out' and I don't know where to start...

I followed a tutorial (https://www.youtube.com/watch?v=WvvvzupH18s&t=1491s) but now I'm guessing I'll have to learn about shaders to build it again from scratch. Any starting points you can recommend to help me learn this simple transition shader I created? 🙏

Learn how to create a simple shader to switch between scenes in interesting ways using just a gradient image!

Get the files to follow along at https://drive.google.com/file/d/1DkK85TqgAMLqtc45L_DnhApcPcQ8WVi5/view?usp=sharing

Wishlist 'Scoot Kaboom and the Tomb of Doom' right now at http://bit.ly/scootkaboom !

Get my new Udemy course 'Learn T...

▶ Play video
grizzled bolt
tropic badger
#

- I've passed a texture to a shader. Its dimension is Nx1. Now i need to iterate through this texture and get every pixel's XY values. Is there any alternative to the c# method GetPixel()? I use integer coordinates for this, which are constant 0 for Y and 0-N for X

meager pelican
tropic badger
#

- I didn't even think about converting integer coordinates into uv ones

meager pelican
#

Well, in the shader, sure.
In C# probably not. Not sure what you're doing.

tropic badger
#

- It's in cg, yes. What i'm doing is just passing data to the shader. I was told to use textures for this, since there are no arrays or collections in general

meager pelican
#

But samplers work with UV's which are % of the width/height. This makes them resolution agnostic.
And given the various sampler states that can average out samples....you get sampling by %.

#

You CAN pass an array to a shader. But may not want to. What is the use-case?

tropic badger
#

- I have a player that may fly near obstacles. When it gets closer to them than a certain threshold, it starts blending with the obstacle's color. This would have never been a problem if i had only one obstacle, but player will almost always be near at least 2 of them

meager pelican
#

How many of them on screen at one time (max)?

tropic badger
#

- Defined at runtime

#

- From 20 to possible infinity

meager pelican
#

100, 1000, 10000?

#

Oh, ok

#

You probably don't want a texture for that.

tropic badger
#

- But i will cull those that are further away than this "certain threshold" anyway. So i think it won't get higher than 50 in the worst scenario

#

- because when there are 50 obstacles around the player, they're 99% dead

meager pelican
#

You probably want an acceleration structure around this scene data, and a radius to search. Iterating through that many scene items, even once, might be impractical per frame. If you have several 100 K of them.

#

Although that sounds a bit unweildly. I mean, 100K of them? Really?

#

Besides, human perception is probably not going to notice the difference if you have a "lag" time for the color change of a few frames.

#

If you're at, say, 30 fps.

tropic badger
meager pelican
#

well, OK, I was going to say more, but nm.
Can you support structured buffers on all your target platforms?

tropic badger
#

- I'm afraid i don't even know what it is. You can call it my first "real" experience with shaders

meager pelican
#

Are you targeting older mobile?

tropic badger
#

- I may sacrifice them if absolutely necessary, but preferably yes

meager pelican
#

But you could also pass two arrays, one for positions, one for colors

#

You'd set them each frame

tropic badger
#

- Will look into it, thank you. Can i ask you for an "in a nutshell" version of what it is and how it works?

meager pelican
#

A StructuredBuffer is similar to an array, but it has elements that are a struct. So for the relevant data types that are common across C# and shaders, you can use a struct to hold the data and access the elements of the struct at each array element. An array of structs, basically.

So you can define

    float4 WSlocation;
    float4 Color;
}```
And create a structured buffer in C# (they're called compute buffers in Unity, but are not limited to compute shaders only).
https://docs.unity3d.com/ScriptReference/ComputeBuffer-ctor.html

I used float4 rather than float3 because GPU's like things aligned on a float4 boundary.  And you can use the .w component to pass additional data if you wish.   But you could also break that out into a float3 followed by a float, but you may as well read all 4 floats at once for efficiency.
#

You can then access elements by index. In the shader you define the buffer
StructuredBuffer<MyObsitcle> obsticles;
and then you'd access them in the vertex shader I'd suppose (faster than per pixel).

if (obsticles[i].location - myLocation) > threshold) {
   accumulate color change, blah, blah
}
end loop stuff```
#

And you'd pass that accumulated color change to the fragment stage in an interpolator perhaps.

tropic badger
#

- I see. Awesome, thank you a whole bunch

meager pelican
#

If you need the color changes per pixel or per polygon, what we discussed makes sense.

#

But if you want it per-mesh, you'd only have to pass the net-color change to the object, since you're passing the entire dataset in C# anyway.

#

In that case, no reason to burden the shader with the overhead.

tropic badger
#

- It's per pixel for sprites. I originally thought to pass colors to vertices and let the interpolators do the job, but as more and more implementation details appeared i decided to go with fragments instead

meager pelican
#

Up to you. It's similar to pixel-lighting vs vertex lighting, I'd suppose.

#

Vertex would be faster if you can pull it off

#

And yet...another thought....just for fun. 😉
So there is a possible implementation difference between arrays and structured buffers in that you probably get better cache coherence by breaking out the positions into their own array (packs all the locations together in memory)...and having another array to just hold the color or whatever else. @tropic badger I doubt it will make much difference in your implementation since you have one player object that you need to do this for. But if you were shading everything in the scene this way, having the location accessed faster in your conditional would be an advantage.

severe flint
#

hi, in the newest unity version there isn't a PBR graph option when creating a shader anymore, what is the equivalent now?

meager pelican
#

You mean like "lit graph"?

severe flint
#

yes

meager pelican
severe flint
#

ok thanks

waxen raft
#

Could anyone tell me why my triplanar shader does this when i input object space into the position node?

#

its like it works on surfaces that are horizontal, but not vertical

regal stag
rustic peak
grizzled bolt
waxen raft
rustic peak
waxen raft
#

Nevermind I figured it out, thanks!

opaque timber
tropic badger
#

@meager pelican hey, may i borrow you if you still recall the problem of mine?

- I did the buffer thing and double checked that the data is passed correctly (see screenshot), so the fault must be on the shader's side. In a nutshell, i define a float4 that defaults to the player color, and in case distance from the fragment's world position to any value in the buffer is less than something, i set the float4 value to the obstacle color. The code is below

- Setting world position of a fragment

o.worldPos = mul (unity_ObjectToWorld, v.vertex);

- And the actual code

// sample the texture
float4 col = _PlayerColor;
int width = buffer[0].x; // 0th element contains the buffer's length

for (int index = 0; index < width; index++)
{
    float dist = distance(i.worldPos.xy, buffer[index + 1]);

    if (dist <= _BlendignRadius)
    {
        col = _ObstacleColor;
        break;
    }
}

return col;
#

- OMG. All this it was a tiny typo in "_BlendingRadius"

#

- I hate it

#

- But now it does the opposite. As if the player is always near an obstacle

#

- Turned out to be another type, damn it. Fixed, sorry for disturbing

onyx jungle
#

Hello! anyone familiar with this kernel error: "unity kernel keyehistogramclear error"

#

occurred when I switched build platform to WebGL 2.0

#

From my understanding its probably an incompatible post processing effect but no Idea how to fix

tropic badger
#

- I've got a blending problem. On the screenshot, you can see "lines" between the circles which i want to avoid. I don't know why do they appear. My shader algorithm is as follows:

Before drawing a blended color, check if distance from this fragment to the new circle's center is lower than distance to the last circle's center;
Upon drawing, return a lerped color and update the last distance info;

- On paper it should work, but in reality it doesn't. How else can i blend these circles, or change in the current approach to make it work?

tropic badger
buoyant geyser
#

I have a toggle in my shader, [Toggle(DO_REFLECTIONS)] _DoReflections("Enable Surface Reflections", int) = 0 and it's included in my shader_feature pragma, #pragma shader_feature _PALTYPE_NONE _PALTYPE_INDEX _PALTYPE_MAP DO_REFLECTIONS

#

despite this, toggling this on and off has no effect on my shader,

#ifdef DO_REFLECTIONS

    float2 morph = tan(pow(o.Normal, 5)) * 0.1;

    float2 reflUV = _ScreenParams.xy * _ReflTex_TexelSize.xy * (IN.screenPos.xy / IN.screenPos.w);
    float2 bgUV = _ScreenParams.xy * _ReflBG_TexelSize.xy * (IN.screenPos.xy / IN.screenPos.w);

    float2 reflOffset = _ReflTex_TexelSize.xy;
    float2 bgOffset = _WorldSpaceCameraPos.xy * _ReflScroll * _ReflBG_TexelSize.xy;

    reflUV = reflUV + reflOffset + morph;
    bgUV = bgUV + bgOffset + morph;

    fixed4 refl = (tex2D(_ReflTex, reflUV ) + tex2D(_ReflBG, bgUV )) * tex2D(_ReflMap, IN.uv_MainTex).a;
    o.Albedo += refl;

#endif
#

this code never runs regardless of if the property is toggled

#

any idea why this could be happening? Something im overlooking maybe?

amber saffron
buoyant geyser
#

tried switching back between float and int with no difference

#

ill leave it back on float though

amber saffron
#

Have you tried with #pragma multi_compile __ DO_REFLECTIONS ?

buoyant geyser
#

that fixed it, perfect

#

mind if i ask what that does exactly? Does it compile a second shader for the reflections on/off, and the toggle just changes between them?

regal stag
#

Basically yeah

#

I'd guess that it didn't work before with multiple keywords being specified (_PALTYPE_NONE _PALTYPE_INDEX _PALTYPE_MAP) as one of those might have been enabled, so took priority over DO_REFLECTIONS maybe

amber saffron
buoyant geyser
#

right, i have an enum type with some logic running before the reflection check to change the way the colors are processed

buoyant geyser
regal stag
#

There's also a [KeywordEnum] drawer which might work better with multiple keywords on the shader_feature. It's in that same docs page Remy linked

buoyant geyser
#

yup, that's what im using for the palette property

#

i just needed a seperate toggle for reflections

amber saffron
regal stag
#

Ah okay. If you need each of those palette shader variants to include the option to toggle the reflection it would need to be specified under a different shader_feature/multi_compile

buoyant geyser
#

so every seperate property would need it's own line for that, i get it

amber saffron
#

#pragma shader_feature DO_REFLECTIONS should even be enough

#

The biggest difference is that shader_feature will compile only the required variants (depending on the materials that are rendering), when multi_compile will compile all possible combinations

regal stag
#

Basically use shader_feature wherever possible except if you need to adjust keywords at runtime, then use multi_compile

amber saffron
#

Hey @regal stag , while you're around, I'm a bit curious.
Have you worked a bit with shadergraph and the built-in pipeline ?

The scene color node doesn't work there, and I kind of need it.
The workaround I have in mind would be to use a commandbuffer on the cameras to copy the backbuffer to a RT and assign it to the _cameraOpaqueTexture shader variable.

What do you think ?

regal stag
amber saffron
#

I guess try and see XD

regal stag
#

Yea, guess it's just a cmd.Blit and cmd.SetGlobalTexture right?

amber saffron
#

That's the idea yes. Maybe with some more optimisations accomodate multiple camera and share a common texture between the blits.

amber saffron
tropic badger
#

- The entire shader file or just the blending part?

amber saffron
#

Maybe just the blending part to start with

tropic badger
#

- Sure, let me turn on my laptop. Will laste it here in a minute

regal stag
tropic badger
# amber saffron Maybe just the blending part to start with
float4 col = _PlayerColor;

// this buffer contains red circles positions
// 0th element contains the buffer's length
int width = buffer[0].x; 

// anything closer than _BlendingRadius is solid _ObstacleColor
// anything between upperBlendingRadius and _BlendingRadius is lerped 
float upperBlendingRadius = _BlendingRadius + _BlendingLength;
float lastDist = upperBlendingRadius + 1;

for (int index = 0; index < width; index++)
{
    int i2 = index + 1;

    float dist = distance(i.worldPos.xy, buffer[i2]);

    if (dist <= _BlendingRadius)
    {
        col = _ObstacleColor; // solid color
        break;
    }

    if (dist <= upperBlendingRadius && dist < lastDist)
    {
        float blend = (dist \- _BlendingRadius) / (upperBlendingRadius \- _BlendingRadius);

        col = lerp(_ObstacleColor, _PlayerColor, blend);
        lastDist = dist;
    }
}
tropic badger
amber saffron
#

Just loop for all elements with
lastDist = min(lastDist, dist)
And calculate the color after the loop ?

tropic badger
amber saffron
#

blind coding :

for (int index = 1 ; index < width ; index++)
{
    float dist = distance(i.worldPos.xy, buffer[index]);
    lastDist = min(lastDist, dist);
}

float blend = ( lastDist - _BlendingRadius ) / (upperBlendingRadius - _BlendingRadius );
blend = saturate(blend);
col = lerp(_ObstacleColor, _PlayerColor, blend);
amber saffron
regal stag
tropic badger
tropic badger
amber saffron
#

Im starting to think it's some perceptual contrast brain issue ^^

tropic badger
amber saffron
#

iirc, it can go out of this range, in that case the operation will extrapolate the values

#

Can you try to output
col = frac(blend*10);

just for couriosity

tropic badger
#

- Sure

amber saffron
#

The values seem correct, so I'm really thinking that the issue is from how our brain percieves gradients

regal stag
tropic badger
amber saffron
#

Oh sh*** I've that quesiton to fast and though k with the last lerp argument 😅

amber saffron
tropic badger
#

- I need them

#

- Wait, can it be filtering mode?

#

- Like bileniar or what is it by default

amber saffron
#

No, you're not doing any texture sampling here

#

I wonder if some gamma correction might help.
like doing
blend = pow(blend, 2.2)
or
blend = pow(blend, 0.4545)

(one is linear to gamma, the other is gamma to linear, and I can't for the sake of me remember which is which)

tropic badger
#

- Will try this and cyan's suggestion right after i finish eating. Sry

tropic badger
#

- Unfortunately neither removed this separation. pow 2.2 seemed to make things better, but didn't help much. Thank you for your effort anyway

cosmic sphinx
#

Our brain sees it like this mostly because our perception is based on contrasts. When going away from the center of the circle the color becomes weaker and weaker, and then BOOM, it's increasing again. It creates an illusion of some concave gap.

tropic badger
#

- I doubt that it's an illusion, because i clearly can shot it wiht whatever screenshot tool, pick colors and make sure that they differ. And they do

#

- But as i zoom in, it disappears. Okay, it is

cosmic sphinx
silk wharf
#

Hello there, I am using full screen shadergraphs for the first time, and I am wondering how can I tile a texture according to the screen width and height so It doesn`t streetch irrregularly?

drowsy fiber
#

Does anyone know how to get the UV center in shader graph when working with sprite atlases? I've looked online and cant seem to find a solution besides passing metadata through a custom property.

lunar valley
lunar valley
cosmic prairie
#

just as an idea

tropic badger
cosmic prairie
clever lynx
#

Is there any way to render a Shadergraph always behind another shadergraph?
They are both set to opaque at the moment.
I have tried adjusting the Render Queue on the materials but it does not seem to change anything.
Any idea?

pale python
#

hi ,
how do I save shader with frag function like this on a png file ?

 fixed4 frag(v2f i) : SV_Target
 {
                half4 color = half4(i.uv, 0, 1); 
                return color;
}
lunar valley
#

Do you want to have it outside of unity?

pale python
#

but I dont know how to tell c# to capture the entire output of the shader , its not a texture

lunar valley
#

then you should use a renderTexture

pale python
#

could you please give me a code example ?

lunar valley
#

its exactly what you have above but the output is not the object but a renderTexture instead

pale python
#

I havent uesed renderTexture before , is it something like that ?

 fixed4 frag(v2f i) : SV_Target
 {
                half4 color = half4(i.uv, 0, 1); 
                return renderTexture (color);
}
lunar valley
#

no

pale python
lunar valley
pale python
lunar valley
hollow orchid
#

i created grass in unity . this grass has shader in it just for texture rendering. i placed the grass over terrain with unity terrain trees. But when i run the game fps drops from 300 to 10 fps. the grass has lod system and doesnt take much tris or verts. i think the shader running all at once overiding the culling from lod system. what to do

lunar valley
#

are you painting your grass on unitys terrain?

hollow orchid
clever lynx
lunar valley
#

Grass should be painted in the details tab

hollow orchid
lunar valley
hollow orchid
pale python
#

im still learning , i still dont know the difference

#

i didnt even know that there are types

drowsy fiber
lunar valley
pale python
mint copper
#

Alright... managed to make a basic water shader...

cosmic prairie
# pale python hi , how do I save shader with frag function like this on a png file ? ```cs ...

a shader by default does not really output a texture. if you supply the gpu with a 3d model, a target texture, a shader, and resources for the shader (such as textures, matrices etc..) it will first transform the model into camera space then rasterize it. when the gpu rasterizes a certain amount of pixels will be calculated and written to target depending on the triangles size and position. You are assuming the gpu just magically spits out pixels from a fragment shader into a texture without any or minimal input data

#

so, when you are writing a fragment shader you are not outputting pixels or their position, only calculating their color depending on the already assigned pixel position when the fragment function starts executing

#

what Graphics.Blit does, is it renders a fullscreen quad 3d model with the shader you supply, thats how you get the texture

#

when you create the RenderTexture or Texture you need to assign the size of it, the gpu cannot change the width and height

#

also remember to copy your render texture to a texture2d if u r using that, and also call ReadPixels on Texture2d to copy back to cpu memory from gpu memory (so you can save it as a file, the gpu and it's memory is fast but you can't do IO things there)

stable nexus
#

I have made a shader but the shader dosnt run in editor mode, only when i play the shader runs

#

how do i make sure it always runs

lunar valley
lunar valley
cosmic prairie
cosmic prairie
#

it won't animate by default

#

you have to turn it on, there's an answer in what I linked

stable nexus
#

yeah thanks got it

cosmic prairie
# pale python yeha i tried with graphics.blit the other day but I couldnt as the output is ju...

btw if u end up with the compute shader route I have a full blown image editor using Unity and compute shaders, you can steal code from there if u want https://github.com/Peter226/HueHades

GitHub

An image editor and painter program, made for technical artists - GitHub - Peter226/HueHades: An image editor and painter program, made for technical artists

lunar valley
regal stag
past beacon
#

Can someone please help me why I can not put Out from Branch node into Alpha clip threshold node and how to fix this?

regal stag
past beacon
sweet burrow
#

Did they ever add Stencil to shadergraph URP?

past beacon
woeful narwhal
#

how do i randomly generate a number from 1 and 0, in shader graph

regal stag
woeful narwhal
#

yeah ive seen that but never figured out the seed thing. i just need something that changes to a one or a zero with a random interval

grizzled bolt
fickle fable
#

How can I get a shader to change the colors of different parts of the surface? I want to be able to apply this effect but not just between objects, but between each pixel of every object.

quaint grotto
#

is it possible to include a hlsl file from a package

#

i can't seem to correctly get the right directive location

lunar valley
fickle fable
#

YES YES

#

ANY IDEA HOW I'D DO THAT

lunar valley
fickle fable
#

Not really. The colors in the video are changing because of the player's closing velocity towards those objects.

lunar valley
#

I mean this is gonna give you your stripes: ```cs
float stripe = (1+(sin(i.uv.x)) / 2;

fickle fable
lunar valley
#

You can apply it however you want to

fickle fable
#

Right, but I don't understand what exactly I'm supposed to do with it

lunar valley
#

well I am still a bit unsure what exactly you want to do. So just put it into the base color, see what happens and then do the adjustments you need to make.

fickle fable
#

Ok. Thank you very much, I'll see

fickle fable
lunar valley
#

That was just a code snipped/example adjust it to work for any pipeline you are working with

fickle fable
lunar valley
fickle fable
#

I'm using the Universal Render Pipeline, so I'm editing it by adding the _BaseColor to a percentage to get the effect in that video. So, I think I'm using hlsl.

#

rend.material.SetVector("_BaseColor", new Vector4(originalColor.x + redShift, originalColor.y, originalColor.z - redShift, originalColor.w))

spare snow
#

can anyone help with the shader graph thingy? so basically i wanted to recreate this reflection effect https://www.youtube.com/watch?v=ym1K3of3pys and in minute 6:15 he talks about the "sprite unlit master"... now where the hell is the sprite unlit master?

Learn how to create a water refelction effect in Unity

Download the project starting files at https://drive.google.com/open?id=1OUOcx75_fm-1yZb6rSt8siWEYWJrdUe-

Inspired by Binary Lunar: https://www.youtube.com/watch?v=O1lRGKfCi9o

Get my latest Udemy course 'Learn To Code By Making a 2D Platformer in Unity & C#' at https://www.udemy.com/cours...

▶ Play video
#

and whats the difference between lit and unlit, and should i use lit because i use light in my game?

lunar valley
spare snow
#

alright

spare snow
#

where is it?

lunar valley
spare snow
#

its not there

lunar valley
#

yes it is

#

it might just be called a bit differently

spare snow
#

what i get is this in unlit

#

and this in lit

lunar valley
# spare snow what i get is this in unlit

yeah thats your output node, they have changed it up a bit, in the past it looked like above in the video but now it looks like this, but it is the exact same thing

spare snow
#

but it doesnt do the same thing

lunar valley
#

yes it does

spare snow
#

but according to the video this should give me a mirrored thing

#

this is in lit

#

i can try it out in unlit too just to see if im just horribly stupid xD

lunar valley
spare snow
#

wait...

#

no it doesnt work

lunar valley
#

well thats how he is doing it and I do not have more info than what you have provided me

spare snow
#

yeah i dont know, i did it exactly like he did, but for me its not even showing in the preview

lunar valley
spare snow
#

aaah i got it

#

the problem was acually the difference between unlit and lit

#

i suck T-T

#

lmao but thank you for the help

#

but now its still not showing the thing in the editor, it just shows the thing in the prebview

waxen ridge
#

hello, i am new to shader graph.
I have a grass patch that I want to color with a gradient, which I do via lerp, working fine. I have the vertex color going from 0 to 1 at the top, which I use to interpolate. I also want to add some manual AO / specular highlights, by defining a threshold percentage for each. If AO is set to 15%, I would like to multiplicatively add some color to all pixels that have a vertex color of < 0.15. How would I achieve this?

finite tree
#

(custom lighting)
how would i turn on shadows for point/spot/... lights? (shadows for main directional light work, but for the rest they dont)
shouldnt the selected pragma do that?

regal stag
#

And obviously make sure you're using light.shadowAttenuation in your calculations.

finite tree
#

okay i uncommented the main lighting so everything is there

regal stag
finite tree
#

i use the same function for main as for additional, so i use their attenuations too, but there arent shadows in additional lights

waxen ridge
regal stag
finite tree
#

okay i got it

finite tree
#

oh, but the light gameobjects themselves didnt have shadows on (didnt know each light needs shadows turned on, thought that would be on by default)

#

works now, thanks!

spare snow
#

i want my reflection to keep looping all the time, but its not doing that. https://www.youtube.com/watch?v=ym1K3of3pys in this tutorial in about 17:30 minutes in he does a water ripple effect. but for him the texture keeps looping but for me it doesnt

Learn how to create a water refelction effect in Unity

Download the project starting files at https://drive.google.com/open?id=1OUOcx75_fm-1yZb6rSt8siWEYWJrdUe-

Inspired by Binary Lunar: https://www.youtube.com/watch?v=O1lRGKfCi9o

Get my latest Udemy course 'Learn To Code By Making a 2D Platformer in Unity & C#' at https://www.udemy.com/cours...

▶ Play video
regal stag
spare snow
#

a+#

#

got it

regal stag
#

In the Inspector when the texture asset is selected

spare snow
#

thank you very much

spare snow
#

is there a node that i can use to make the reflection darker than the thing that is being reflected?

worthy marsh
#

does anyone know where i can learn shader code from?

#

(not talking about shadergraph)

prime shale
# worthy marsh does anyone know where i can learn shader code from?

Watch this video in context on the official Unity learn pages -
http://www.unity3d.com/learn/tutorials/topics/graphics/session-introduction

In this live training session we will learn the fundamentals of authoring shaders for Unity and you will learn how to write your very first shader. No prior knowledge of authoring shaders is required. In th...

▶ Play video
worthy marsh
#

i am actually watching this rn lol

#

was checking if there was a better way to learn

prime shale
#

someone else might have some more resources but as far as I know there isn't really too much

worthy marsh
#

thanks

prime shale
#

I would suggest though

#

learning some tutorials perhaps from places like open GL or places that might teach GLSL

#

sure a bit different shading languages, but they aren't too different and all of the concepts are the same

#

for example this is an open GL tutorial that teaches you about doing basic shading

lunar valley
worthy marsh
lunar valley
#

yeah

worthy marsh
#

i was watching it before i started watching the current tutorial (the one provided by unity)

#

problem was that i didn't know that i should tackle introductions to shaders like that

#

i didn't want to get stuck in tutorial hell

#

again

lunar valley
severe hollow
#

Hi! Is there a road map for shadergraph URP? Quite a lot of basics are still missing and would like to know when to expect them 😁

worthy marsh
#

does anyone know how i can "unpack" a float4 ?

worthy marsh
#

like i wanna get the individual float values of a float4

regal stag
#

I think [index] (0-3) also works (but only for reading, can't set that way?)

worthy marsh
#

that is what i am trying the whole time

#

wait

#

nvm

#

i had the wrong variable name this whole time

#

capitalization mistake

#

sorry xD

tidal nymph
#

anyone know why my material's variable is not changing at runtime>?

    void Start()
    {
        Renderer renderer = GetComponent<Renderer>();
        crossHairMaterial = Instantiate(renderer.sharedMaterial);
        renderer.material = crossHairMaterial;
    }

    void Update()
    {
        Debug.Log(crossHairMaterial.HasFloat(this.outlineThicknessUniformName));
        Debug.Log(crossHairMaterial.GetFloat(this.outlineThicknessUniformName));

        crossHairMaterial.SetFloat(outlineThicknessUniformName, outLineThickness);
    }
#

so like i think i am changing the uniform of some shader but i am not sure its the exact on attached to object? idk

regal stag
tender edge
#

i've made my own vertex color blending shader. now i want to control the alpha through script. is there something i need to add to that shader to make it work?

regal stag
tender edge
tender edge
tidal nymph
glossy verge
#

if I want to do a shader that goes from invisible to red to invisible for damage, should I just create the shader and add it to a material and use that material on the enemy that already has a material?

lunar valley
quaint grotto
#

am i dumb or is this wrong

#

im trying to flip it so the bottom half is black top half is white

#

but one minus seems to make most of it white

regal stag
# quaint grotto am i dumb or is this wrong

Looks correct to me. But that's the linear interpretation of the colours. Perhaps you expect a gamma corrected one, could put it through a Colorspace Conversion node with Linear/RGB inputs. or use a Power node.

quaint grotto
#

are you sure that looks correct

#

i was expecting a mirror image

#

why does it look so different by simplying inverting it

regal stag
#

Perhaps you want a Negate then before the Saturate, not One Minus

quaint grotto
#

what do you mean ?

#

saturate(1-dot) ?

regal stag
#

As in Dot Product -> Negate -> Saturate

quaint grotto
#

doesnt work for me you can still see it showing on the dark side of the sphere

#

trying to get that backside much darker because its too blue from the atmosphere so was applying dot product as part of the alpha

#

weird

quaint grotto
#

shader graph really needs to show us the rgba values when we mouse over pixels in the preview windows

#

that would be a god send for debugging

#

this is my alpha input

#

and this is what i get

#

i don't get it

#

it should be only half a sphere

regal stag
#

What blend mode is being used?

quaint grotto
#

unlit transparent and alpha blending

regal stag
#

Can you show the whole graph?

quaint grotto
#

here you go

#

ignore the min opacity node its not connected atm

regal stag
#

What result do you get if you disconnect the alpha and put the Saturate result into the Base Color?

quaint grotto
#

that doesnt look the same as the preview of saturate node

#

which is odd

regal stag
# quaint grotto

If you rotate around the object, is half of it white pointing in the main light direction?

#

Is there even a directional light in the scene?

quaint grotto
#

ok it looks more correct rotating the camera

#

yeh its got a dir light

#

oh there we go it is working

#

seems the camera was in a weird position that was tricking my eyes

#

i thought it was perpendicular to light direction

#

@regal stag works now, thanks 🙂

heady pewter
#

how would you set a shader to work specifically for a camera?

#

like

#

i have some overlay effects on my 2d game, so things like water makes the background wavey and stuff.

#

but now that im trying to put together splitscreen, those shader effects will only show only on one screen, and all other screens will still show the same first screen, instead of their own individual screen

prime shale
#

because that is what your describing pretty much

heady pewter
#

but yeah, was hoping to get post processing effects to be different between the splitscreen camera.
i think because of it, the other players will get the same exact render as the 1st screen. so it ends up not looking through the other camera

#

at least, that's what i suspect

amber cradle
#

Hiya!

I want to make an uber shader for my game. I want to use this shader for every single material in my game and I only have two necessities other than PBR rendering: emissive fresnel and dither-based transparency (material is opaque, alpha cutoff on dither)

I know how to implement the entire shader but I'm wondering- is it better to use keywords to disable dither transparency and fresnel emission (but lose SRP batching due to keywords) or keep it all enabled all the time and gain full SRP batching?

prime shale
#

I would think the SRP batching would be important to keep, but enabling all of the keywords can and might lead to performance degredation down the line with features that you might not be using but are enabled anyway

amber cradle
#

Gotcha.

I'll prep the uber shader and start replacing the shader in my materials in the meantime.

prime shale
#

but yeah, I would experiment and see what works best

#

to verify

drowsy fiber
heady pewter
#

sorry, i don't know

amber cradle
cosmic prairie
quaint grotto
#

i got it working in the end anyway

cosmic prairie
quaint grotto
#

i cant have negatives so i have to saturate

#

negative alpha has no meaning

cosmic prairie
quaint grotto
#

what?

#

saturating first as suppose to second makes no difference

#

order of operations wont change much

cosmic prairie
#

but then you misread what I wrote

quaint grotto
#

what you wrote was not relevant to the conversation your comparisons are not equal

cosmic prairie
#

which is not just flipping it but adding one

cosmic prairie
quaint grotto
#

saturate then one minus vs one minus then saturate is the same is what im trying to say

cosmic prairie
#

but how is that relevant? did I say that's not it? you wanted to achieve this by your description

#

I don't understand you

quaint grotto
#

but -x is just flipping things how does that fix the problem

#

i can do that just by swapping the dot product inputs

cosmic prairie
#

literally what you said

quaint grotto
#

yes which means 0 and 1 not -1 and 1

cosmic prairie
#

Okay I'm just giving this conversation up, no point

quaint grotto
#

its not hard to udnerstand that one minus maps -1,1 to 0,1

#

-x doesnt change anything

lunar valley
meager pelican
# amber cradle i think i might have something from a previous project, gimme a tic

OK, so a sprite atlas is "just" rectangles within a rectangle.
So compute the size of the single-sprite triangle. Then, to get UV's for it, figure out the % thru that you want for that range. In either direction. So if the sprite ranges from pixel/% of (0.5 - 0.75, .5. - 0.75) of the sheet, you can compute a UV by taking the range of values (0.75-0.5 = 0.25) in X and Y and then deciding how to map that to your 0 - 1 range you want for a logical-UV. Or vice versa.

meager pelican
# amber cradle Hiya! I want to make an uber shader for my game. I want to use this shader for ...

Like @prime shalewisely said, bench-marking is the way to go here. I mean you're making a decision early on that will impact all shader calls in your game, so testing is paramount.

That said, if your "switches" are uniform, you probably won't have many problems. There are some tricks. Try to avoid shrouding texture reads inside an IF (but definitely benchmark this both ways) usually you'd put them as close to the "top" as possible.
The switch IFs will be uniform if they're even needed, so it should cause no to little divergence in the execution path of ALL threads on that mesh, so there won't be much performance hit as compared to divergent paths.
Use the [branch] attribute, although modern compilers probably ignore it in most cases.
Best to test on a range of platforms, not all shader compilers/platforms handle things the same way, particularly between desktop and mobile.

I would think you want SRP batching. In your case, though, you'd only have two switches and 4 variants, If F is fresnel and D is dither, you only have F-D-, F+D-, F-D+ and F+D+, maybe not too much of a maintenance nightmare, particularly if you use includes. You can then swap the shader in and object/material at runtime. No ifs or switches necessary, and you'd keep batching of the 4 groups at least.

Or, it might work out that you don't need any IFs at all!!!!! Just let "the math" do it, and calc all attributes but in some cases the fresnel % will be 0 and the alpha will be 1 so solid dither. The real trick isn't the fresnel, it's the dither, since you MIGHT use a dither texture. But in reality you should be using an array to hold the dither cut offs, not a texture. That reduces sampler needs too, and avoids any dependent texture reads. This gives you the math at all pixels, but these days simple math might not be too bad.
/ramble
-2cents-

tacit parcel
warm rapids
#

where can enable this option for Mask Mode on local volumetric fog? I'm watching a video where it's visible in the inspector, but not in mine

cosmic prairie
warm rapids
#

oh yeah that'll be it

#

would something similar be possible in a previous version? i'm not sure how practical changing versions would be currently

cosmic prairie
#

But I'd say create a backup of the project, test out the newest available version, and see if everything works

#

That would be the easiest and probably the best thing to do as you are getting other new features and improvements

cosmic prairie
# warm rapids would something similar be possible in a previous version? i'm not sure how prac...

Actually I was just wondering how the material is rendered in 3D, and found a 3D Blit function, you could use this to render the mask material to a 3d render texture https://answers.unity.com/questions/1431871/graphicsblit-with-a-3d-texture.html

#

I guess it's just rendering a quad for each layer

#

you need to do this every frame, as that's how the material mask type is done too

lone cave
#

i recently switched from standard RP to HDRP and i'm trying to update my shaders, but no matter what i can't seem to refrence HDRP at all
for example i'm getting an error that looks like this: Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.hlsl'. at line 24
does anyone know if they changed or what is happening because ive tried every possible pathway

pale python
#

hi , quick question
how do I add header on the variable like in c# ?

// [Header("title")] <======================== ??? 
_MainTex ("mainTex", 2D) = "blue" {}
low lichen
#

Sorry, that's wrong. There is one, but not listed on that page.
[Header(A group of things)] _Prop1 ("Prop1", Float) = 0

digital anchor
#

Hey guys, I need help with a water shader here.

This block is meant to move a normal map along the sprite to simulate light movement

#

However when I change Normal direction in the editor the texture gets all streched out

radiant charm
#

So I got confirmation that the new Adaptive Probe Volume system was integrated into the "Baked GI" node in shader graph, but if I do a simple passthrough of the Baked GI node to the emissive value of the right sphere, its clearly not showing any APV data unlike the generic sphere on the left. They said its in versions 2022+, and I'm on the latest 2023 release.

amber saffron
amber saffron
digital anchor
#

Well that's just nice. Now's fixed thx

distant bloom
#

Is it possible to let a triplanar worldspace texture drive vertex displacement? I would like to create an array of cubes that change their height depending on a worldspace texture.

shadow locust
distant bloom
shadow locust
#

the first one I know is in the vertex stage

#

I think the triplanar node might only operate in the fragment stage

shadow locust
#

not sure how the triplanar node works exactly

past beacon
#

Hello, I am trying to Lerp vertex position from TapPosition to the origin vertex position over time(TimeElapsed updated in code). TapPosition is initialized in code to the tap.transform.position. I don't understand why during runtime(and preview) starting position of the Lerp is not where Tap is. I have tried different space options Object/World configs but it didn't help. Any idea?

distant bloom
shadow locust
regal stag
distant bloom
shadow locust
#

the point of Sample Texture2D lod is it samples a texture in the vertex stage

shadow locust
#

they're all just numbers

#

the issue is whether the various nodes are allowed to live in the vertex stage or not

regal stag
distant bloom
#

Here's the graph. For some reason I cannot use the same Texture as input for vertex and color.

past beacon
coral otter
#

Hello there,
I got this problem, when I upgraded my universal render pipeline, all my UI components with the shader UniversalRenderPipeline/Particles/Lit literally disappeared from my camera due to the distance.
It's like now there is a distance component in the shader that fade away the particles with this built in shader.
So here is an example with the scene camera next to a star made of this shader on my UI.
And there is at the bottom the game camera that i'm dragging forward. We can see that when it's very very close the particle effect appear again.
However I need this camera very far, and it worked properly before.

Do you have any idea of what URP broke in the shader and how to make it work properly again ?

https://gyazo.com/3feac539b1698127f17ffdbfcc03a308

#

Nevermind, got it, I had to deactivate the fog in Lighting/Environment

dim yoke
quaint grotto
#

how do you make one specific object in the scene glow in post processing

quaint grotto
#

right but bloom applies to the whole scene

#

so wasnt sure if there was another way without post processing

prime shale
#

you can make an object with a material that has a high emissive intensity (and a bloom with a high threshold, and that object can exceed that threshold intensity wise)

#

beyond that you'll have to look into a more custom way

grand jolt
#

Hey everyone 2D sprites arent affected by lighting in the URP. Im not very familar with shader graph/code if theres anything out there that could help... please point me to it.It would be much appreciated

pale python
#

hi,
i wonder if it's bad to have 20-30 [Toggle(KEYWORD)] in one shader , isnt it better than if - else ?

prime shale
#

it can be bad

#

and yes it would be better than if else

#

because if-else is dynamic branching

#

keywords are static

#

but

#

with those keywords you are effectively forcing unity to compile MANY variants of that same shader

#

I would first ask, what the hell are you doing if you need to have 20 - 30 togglable keywords? @pale python

#

with the math I think its like to calculate permutations it would be 2^(amount of togglable keywords that you are compiling)

#

so i.e. you have 30 shader keywords compiled

#

2^30 = 1,073,741,824 variants

#

or

#

2^20 = 1,048,576 variants

pale python
#

well , its a shader but with lots and lots of options , each option gives a completely different result and really creative but im concerned about the performance of the shader after using 30 keywards

prime shale
#

that doesn't really answer my question though, what shader is this?

#

like I said, with all of those keywords if your compiling them using the shader_feature_local pragma is a ton of variants

#

surely with whatever you are doing you can cut down on those variants

pale python
#

oh , i dont really know the difference but the example i saw online was #pragma so i used it

prime shale
#

well either way it needs to create a variant

#

it will bog down your build times and have a memory cost (if I recall?)

pale python
#

#pragma shader_feature_local NAME

#

oh , but not to much i suppose , right ?
also if it's not bogging down the runtime performance , i guess that is ok , correct ?

prime shale
#

ehhh I wish I knew the numbers but I have a feeling it would also incurr a potential runtime cost as well

#

because a different shader variant is basically a completely different shader, which I think can increase draw calls

#

but again, what shader is this that would require this large amount of keywords?

#

surely whatever the heck your trying to achieve there are plenty of ways one can optimize and cut down on the amount of variants you would need to compile

#

from the unity docs

pale python
#

well , it's a shader with lots of options , like it can achieve results like gas, liquid solid and even tentacle , but i guess i could use it as a drawing tool than a shader and as soon as i make my decisions for the shader , i could just duplicat it and delete all the extra keywords and all other if-else statements.

prime shale
#

I've mentioned this before when we talked about variants

prime shale
#

double checking myself with the docs I geuss yes runtime costs will be minimal - none with the keywords, but you will increase memory usage and loading times having to load all of those MANY shader variants

#

I would try to break up your shader perhaps in different shader types to reduce the amount of variants

#

for example with whatever the heck you are doing, you could have a "gas" shader that is specific to rendering this gas and has features specific to it

#

and same for the other kinds

#

rather than one massive "ubershader"

pale python
#

i love the fact that i can change some values and make a much different results but now I understand the cost of that
I will take ur advice , but I'll keep all the keywords in the original shader only just to help me imagine and duplicate and clean up the shader as I make a decsition

prime shale
#

sure yeah, but for the final results I'd advise you to avoid going crazy with the amount of keywords and features you can toggle because it will come back to bite you

pale python
lunar valley
#

I think that _LightColor0 gives you the light color premultuplied with the intensity.

#

or if not you can get it through c# and then pass it over to you shader manually

#

I think so

fathom cypress
lunar valley
#

this is useful if you want your object to write to depth

cedar hull
#

When using a custom shader for instanced rendering, is it possible to not pass a list of matrices, but instead calculate the matrices in the vertex shader (using positions etc)?

#

Thanks in advance guys

lunar valley
cedar hull
fathom cypress
#

hm i dont fully understand, because my object is set to opaque and it works when its in alpha or when its alpha clip threshhold

lunar valley
cedar hull
lunar valley
lunar valley
#
  • its like way faster so
regal stag
fathom cypress
#

i actually am learning all this because setting the alpha on a transparent material was causing weird rendering issues. I posted it in #archived-urp but yea i dont see a difference in game by putting it in either

cedar hull
lunar valley
cedar hull
lunar valley
cedar hull
lunar valley
regal stag
#

If the platform doesn't support compute shaders, I don't think it'll support compute buffers either, those come under the same target. But you can probably use arrays instead (though limited to 1023 elements per call? DrawMeshInstanced has the same limit anyway)

cedar hull
# lunar valley what exactly do you want to do, what do you mean with this

Okay, so lets say I have a buffer with positions and I need to calculate a list of transformation matrices from those positions in order to use it for instance rendering.
So I cannot use compute shaders since it is not supported on the web.
Now, my plan was to calculate the matrices itself in the vertex shader (since the matrices are not needed before the vertex stage in the pipeline), and that way still do it on the GPU

lunar valley
cedar hull
lunar valley
#

I see, the matrecies you use with DrawMeshInstanced cannot be updated on the gpu(vertex shader) do you want these objects move in the vertex shader?

cedar hull
lunar valley
#

I was actually asking if you want these instanced objects to move around over time

cedar hull
low lichen
cedar hull
#

thank you

lunar valley
#

I thought you specifically needed matrecies

arctic wagon
#

hello there, i added block node but it seems inactive guys can you help please

regal stag
arctic wagon
#

oh thank you mate

#

I am grateful

finite tree
#

hello, changing an exposed variable changes all of the materials with the same material as well (the variable has override enabled and hybrid per instance)
so i found out that gameobjects need to have it as an (Instance) like this

#

but how do i do that? for now i made a workaround script that turns a material into an instance so it can have its own local variables, but im sure i should do that trough the editor somehow

finite tree
regal stag
regal stag
finite tree
regal stag
finite tree
regal stag
finite tree
#

tried closing and reopening unity, they stayed instanced (2021.3.25f1)

regal stag
#

Hm okay, maybe they are being saved with the scene 🤔

finite tree
#

That would be cool if its the case UnityChanCheer