#archived-shaders

1 messages Β· Page 12 of 1

calm idol
#

Using a gradient I mean

#

I tried multiplying the colors like (i think) you would in Blender but you can't connect those nodes so I'm kind of lost

#

Nevermind! I needed to use Sample Gradient instead of Gradient

tight phoenix
#

Sample Gradient with that image as your Time, yeah

calm idol
#

I was assuming it would be the opposite..

tight phoenix
#

the probuilder cube likely doesnt

calm idol
#

ok yeah, manually overlapping the UV's worked

tight phoenix
#

Im trying to fix distortions that occur because of my projection method

#

I have the base UV, and then a rhomboid derived from that base UV that has directions mapped to that area of the cube

#

but I can't figure out what those vectors should be to fix the distortion

#

I keep getting weird shit like this that doesnt fix it

#

input coordinates creating and placing the rhomboid on the correct face of the cube

#

trying (and failing) to map the correct directions that I need to distort the UV to remove the existing distortions

#

the above makes this, but this doesnt fix the distortion

#

and I dont know how to make it fix the distortion

#

I could use some help because I am unable to proceed with this

#

diagram of what im trying to do

#

make it not stretched

paper loom
#

hi I'm having a problem in my clean up game when I fast draw a straight line the line is broken but when I slow draw a straight line it works fine

#

can someone point out whats the problem

kind juniper
#

Not sure how it's related to shaders though...πŸ€”

paper loom
#

I will try to convert it to input touch

kind juniper
# paper loom I will try to convert it to input touch

That's not gonna help. You need to understand that the game does not run infinite times per a unit of time. If you want a continuous line regardless of mouse speed and frame rate, you'll need to calculate the direction of the mouse movement and set all the pixels between the previous and the current position.

worn harbor
#

Hey, can someone help me ? I'm trying to replicate the clouds from sable (see picture below) i already have a toon shader a post process outline and a basic procedural skybox with some tweaks. I'd like to add the clouds in the skybox in the shader, but i have no idea how to achieve the shape of theses clouds :/

prime estuary
#

Hi guys i was trying to make some stencil shaders from and old tutorial but in URP. im really new to shader graph and can't figure out how to copy them over ( i just included what i put in the shaders otherwise they are default)

#
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200


        Stencil {
            Ref 1
            Comp equal
        }

and 

Shader "Custom/Stencil Mask"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" "Queue"="Geometry-100"}
        ColorMask 0
        ZWrite off
        LOD 200

        Stencil{
            Ref 1
            Pass replace
        }
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types

vocal yoke
#

Hello everyone, I'm having a little bit of problem I want my pattern to glide, but it doesnt looks like it does,, what am I doing wrong?

#

Well to move, I just need a very small animation

#

It's like Delta time isnt working

kind juniper
#

You don't have any value that increases over time.

#

Delta time is around the same value every frame(considering you have stable performance)

patent plinth
#

how can I fix this,

#

the outline supposed to be like the rocks on the left hand side

#

Man, shader is just too alien to me πŸ₯²

#

Pretty sure that happens due to the object gets scaled down or up... at least not the standard 1

regal ferry
#

Hey,
I've got a problem with my shader, for some reason it gives me an error message and breaks my scene.
kr Denis

kind juniper
#

Is there a method ApplyMeshModification?@regal ferry

gusty canyon
#

For some reason my shaders are all of a sudden different in game than in editor

#

does anyone know what could cause this?

#

I literally haven touched them in like a month

#

All I can find online is people that having trouble with water shaders

#

cant find anything like this anywhere

karmic hatch
# tight phoenix I could use some help because I am unable to proceed with this

you need to scale it along that axis, probably by sqrt(3)/2 or something. Assuming your UVs are something like UV.r = dot(position, normalize(1,0,1)), UV.g = dot(position, normalize(-1,1,1)); you can get the new basis vectors as i.r = dot(normal, normalize(1,0,1)), i.g = dot(normal, normalize(-1,1,1)) (then normalize i), and j = cross(i, (0,0,1)). Finally, we can say the scaled UVs are (mult * i * dot(UV, i) + j * dot(UV, j)), where mult is our scaling factor which you could derive from geometry and probably has a sqrt(3)

#

(basically, it should generate the basis vectors in UV that are now along and perpendicular to the diagonals of the cube, transform the UVs into that basis, scale along the diagonal axis, then transform back)

karmic hatch
gusty canyon
#

wdym

#

look at the grass

#

its swaying like 20x more in game view

#

this just started happening today

regal stag
#

Maybe related to batching

gusty canyon
#

and I havent touched the shader in literally a month

gusty canyon
regal stag
#

Are the objects marked as static?

gusty canyon
#

hey I did change that recently

#

yea

#

thats gotta be why

#

but why?

regal stag
#

That would mean they are statically batched too. It combines the meshes into one, which is likely changing the scale of "object space"

gusty canyon
#

ohh

#

didnt know it did all that

#

thanks

#

I was very confused on how it would magically change from editor to game view

regal ferry
#

nothing else

wary horizon
#

If that isnt possible, looks like im going to have to make a shader and apply it on all objects

kind juniper
regal ferry
#

i upgraded my project and re imported the shader, now its working

#

probably the shader was done in another version

ocean cairn
wary horizon
#

Can i use a normal texture sample in an unlit graph?

#

im using cel-shading so im calculating my own lighting

kind juniper
#

Should be able to

wary horizon
#

this is the full thing

#

how ?

kind juniper
#

Somewhere in your light calculations you should be taking the surface normal into account. That's where the normal map sample should come into play

wary horizon
#

err

kind juniper
#

Is CalculateLights a default node?

wary horizon
#

its a subgraph

kind juniper
#

ah

#

Instead of the normal vector you should sample the normal map I guess

#

Or maybe multiply them? Not entirely sure

#

Try using just the normal map first

wary horizon
#

neither worked, tried adding, multiplying and just plugging the sample straight in

kind juniper
#

Isn't there a special node for normal map sampling?πŸ€”

wary horizon
#

I dont think so?

kind juniper
#

Hmmm

#

Did it have any effect at all?

#

Also, did you do it for both of the normal vector nodes? You have 2

wary horizon
#

i put it on the top one now, and it works

#

though when its completely in shadow, the surface is smooth, which i dont particularly want

kind juniper
#

Also, select the "normal" mode in the sampler

#

"type"

wary horizon
#

its fine in light

#

completely smooth in shadow

kind juniper
#

Well, that makes sense. There's no light to apply to the bumpiness.

#

An additional light source from different angle might be needed for that. Pretty sure that's normal for default shaders too.

wary horizon
#

let me check again with the default shader

#

default shader, in shadow it is still visable

kind juniper
#

Hmm

#

perhaps it's because of the "saturate node"

#

that clamps the negative value to 0

#

try remapping the value instead: (v + 1) / 2

wary horizon
#

you'll need to say that again, but so a noob can understand

#

replace saturate with remap?

kind juniper
#

basically, your value is between -1 and 1. But saturate clamps it to 0-1

zenith heron
#

Hello, I was wondering what I could do to take a float4 input (rgba), and change each individual value (I just thought of using a function, but I'm curious if there is any other way). Thank you very much for your time.

wary horizon
#

well, both in and out need to be -1, 1?

kind juniper
zenith heron
#

thank you very much, dlich

#

bless

kind juniper
karmic hatch
kind juniper
#

Ah yeah, that might be useful too. Not sure if it's used in the standard shaders though.

wary horizon
#

I don't do shaders very much, i just followed a tutorial and now tweaking it for my usecase

karmic hatch
wary horizon
#

remapping makes it very bright most of the time, but still in shadow its pretty much smooth

karmic hatch
kind juniper
wary horizon
karmic hatch
kind juniper
wary horizon
#

that makes light not affect it at all

kind juniper
wary horizon
#

in the sample?

kind juniper
#

Yes. And you didn't apply the same changes to the bottom route

#

Both saturate and normal vector are still there

wary horizon
#

I'll change those now

#

yea that looks alot better! though is there a way to clamp the max amount of light it recieves?

#

this isnt great

karmic hatch
# wary horizon yea, want the full graph with the additions from dlich?

For diffuse lighting, you want
diffuseColor * sunColor * sunBrightness * saturate(dot(normal, sunDirection))
For specular highlights,
specularColor * sunColor * sunBrightness * saturate(dot(normal, sunDirection)) * pow(dot(reflect(normalize(viewDirection), normal), sunDirection), <something large like 50>) * fresnel(<power to taste>)
For diffuse ambient lighting,
diffuseColor * ambientColor * ambientBrightness * 0.5 * (1 + dot(normal, up))

#

Then just add them all together

wary horizon
wary horizon
kind juniper
#

Yeah, maybe it was not the saturate's fault. but the bottom route not using the normal map...

#

Perhaps it's so bright due to the remapπŸ€”

wary horizon
#

lemme test again with saturate

karmic hatch
#

just a matter of copying if you have the surface normal

wary horizon
#

nah its still mega bright with both saturate / remap

zenith heron
#

can I use something like UnityEngine.Color.RGBToHSV in a .hlsl file for a shader?

kind juniper
#

might be able to write a custom function that does that though.πŸ€·β€β™‚οΈ

zenith heron
#

well yeah

#

good thing I have some source code

kind juniper
kind juniper
hushed meteor
#

Hello, i downloaded model with textures from mixamo, and just extracted textures, but hair of characters looks like this, i tried do transparent rendering mode, tried alpha channel, and don't understand how to fix that, can you explain please?

zenith heron
#

oh well

kind juniper
#

Doing it on the shader side, you do it once per pixel drawn. That's a huge waste.

#

potentially millions of times

#

While there probably won't be any tangible difference, it's still quite a waste.

kind juniper
hushed meteor
kind juniper
hushed meteor
#

thank you

grizzled bolt
grizzled bolt
# wary horizon

I don't believe you can combine a world space normal vector with a tangent space normal map like that

#

Not totally confident what the correct process is but probably will have to convert them to same space first, then combine using normal blend

hushed meteor
hushed meteor
#

where i should use glossiness texture? I rad that specular map and glossines map is almost the same, but my downloaded model already have specular map, so where then i should put glossiness?

tight phoenix
#

I must have done it wrong because the noise no longer tiles across the faces

kind juniper
hushed meteor
#

@kind juniper yes, model call Sophie from mixamo

tight phoenix
kind juniper
tight phoenix
karmic hatch
karmic hatch
karmic hatch
tight phoenix
tight phoenix
#

its sorta kinda almost working, but the seams are pretty visible

#

the faces do look way less stretched though

#

let me try your uvs instead of mine

#

it does stretch the face on the faces to remove the distortion

#

but doing so also destroys the tiling

#

im starting to think what I want just isnt possible

#

hm wait

#

I might have been looking at the wrong side of the cube

#

Ah no even from the right side, it still breaks the tiling

#

it does exactly what I wanted, which turns out to not be the answer to my proble

#

XY all the way down

#

the strethching isnt that bad, maybe I can hide it with some clever use of the noise

tight phoenix
#

https://answers.unity.com/questions/1837941/shadergraph-how-do-i-get-an-objects-rotation-value.html
Is there a way to get the objects current rotation in the scene in Shadergraph?
This thread is all that turns up when you google it

#

and this thread doesnt answer it

#

XY problem

#

I need to use world space coordinates for a look

#

but I need the world space coordinates to rotate to the object spaces's current rotation

#

hmm maybe I dont need it πŸ€”

karmic hatch
#

If the scaling is equal in all directions, I think the object to world (direction) node acting on a unit vector would act like the rotation (if you normalize afterwards)

wild elm
#

Hello hello! Is there any way to have Complex Lit from URP render with the deferred lightning?
It always falls back to forward, and in a scene with some lights you notice the pop in of lights appearing, like it would happen on the forward lightning 😦

tight phoenix
#

how can I change this so that instead of sliding forward/backward on that axis, it squishes the sides?

#

so that the faces that arenot the face thats moving , instead of just panning, they squish, keeping their current exterior edge

#

XY Im trying to simulate refraction between the interior and exterior face of the cube

#

I tried using a Refract node but it didnt work, results were not what I wanted

#

I have a physical resin cube in front of me IRL and when looking straight through it, the back face looks to be about 1/2 of the way of the actual size, and the side faces are that length but squished

tight phoenix
#

getting all kinds of strange results

#

but not getting any closer to 'the back face of the cube appears closer and the sides are squished'

tight phoenix
#

example of wwhat I mean sorta, except this one is monotone, its not a set of UV coordinates

#

and I cant figure out how to get UV coordinates out of it instead of a monotone black to white

#

I have no comprehension of any of this

#

it just does what it does

grizzled bolt
grand jolt
#

Can someone help me shader graph or shader code. I have no idea how it works. I want to clip off 6 sides of an object like a box and any part of the mesh that is out of that cube area would not be rendered.

knotty juniper
grand jolt
#

I would prefer to write the HLSL so maybe I could understand a bit more.

knotty juniper
# grand jolt I would prefer to write the HLSL so maybe I could understand a bit more.

here is a example for having just one clipping plane
https://www.ronja-tutorials.com/post/021-plane-clipping/
a box is just 6 planes combined

grand jolt
#

Unity does not like float4

knotty juniper
grand jolt
#

I'm trying to set a plane property

#

From the example shader I just added a line

#

_Color is the default code that unity generated... I added _Plane and it does not like it being a float4

knotty juniper
regal stag
grand jolt
#

Okay looks like it's working so far

grand jolt
#

Okay not what I was going for

#

Umbrella shader

#

Put that on the asset store

#

Is there a better way to do this with vectors?

float n = 0.4;
distance = abs(IN.worldPos.x - dir.x);
clip(-(distance - n));

distance = abs(IN.worldPos.y - dir.y);
clip(-(distance - n));

distance = abs(IN.worldPos.z - dir.z);
clip(-(distance - n));```
knotty bough
#

So I made what I expected to be an edge glow shader in ShaderGraph. Now it works fine for sphers, but not for cubes or planes. I'm hoping someone could elaborate as to what I did wrong.

karmic hatch
knotty bough
#

Hmm... I see. Back to the drawing board I guess

karmic hatch
#

Tbh from geometry alone I don't think it can be done for any arbitrary mesh.

knotty bough
#

Well I specifically want to do it for planes

karmic hatch
#

Can you just use the UV of the plane?

knotty bough
#

With the caveat that the plane would be of any shape

karmic hatch
#

ah

knotty bough
#

Basically I'm trying to implement an xcom like movement outline

#

So I'm generating the mesh of the appropriate shape

karmic hatch
#

Idk if there's any way for a pixel near the outside of the plane to know it's near the outside

knotty bough
#

And I'd like to have it's edges have an nice emission glow

#

Hmmmm

#

I mean surely there has to be right?

#

There's plenty of stuff like toon outline shaders

#

I guess I just gotta go look for that

#

And how they do it

karmic hatch
#

Toon shaders for 3D objects work by using the normals of the mesh but they won't work for a plane

#

You could just have it offset the object in a few different directions and paint those offsetted copies to be emissive

vapid plover
#

Im looking into getting some basic water in my scene (more than just a tinted transparent plane), but so far every single tutorial is all about shadergraph... is Shadergraph that essential to learn in Unity? If so, why isn't it build in?

tight phoenix
karmic hatch
vapid plover
#

So as a beginner-coder I dont have much choice other than shadergraph to get some basic water on par with some RTS Map builders from 10 years ago? >_>

karmic hatch
#

you can definitely write a shader yourself

grizzled bolt
karmic hatch
karmic hatch
knotty bough
tight phoenix
karmic hatch
#

max(abs(position.x), max(abs(position.y), abs(position.z)))

tight phoenix
#

Im trying to achieve this - how from the in face it looks like the backface is much closer than it is, and the side gets squished

#

I have lots of methods that get me the back face UVs

#

but not any to then distort them

karmic hatch
#

I think i would calculate the refracted ray direction, calculate where it lands on the cube, and then go from there

#

If you've got the position where the ray lands you have everything, really

tight phoenix
#

front and back visualized - I dont actually normally add them together like that

tight phoenix
karmic hatch
#

I think there's a refract node?

meager pelican
tight phoenix
#

it only takes in a direction and the surface normal

#

but all I have is two sets of UVs

#

and I tried putting the min both ways, no dice

karmic hatch
#

Direction is the view direction

tight phoenix
#

I've gotten this part before figured out, but now I only have one single place to pass in another value

#

and I have two sets of Uvs, I cant pass in both

karmic hatch
#

If you can calculate the UVs as a function of position on the surface of the cube, you can take the fragment position and the refracted ray, jump along it to where it intersects the next face of the cube, and then get the position, and from there get the UVs again

tight phoenix
#

give me a second to try to understand it

#

this is the positions of ray in and ray out

#

but neither takes into account the view direction,which is the thing firing rays

karmic hatch
tight phoenix
#

the second one is inside out

#

easier to see when its set to Lit

#

these are the UVs that need to get distorted as if they are being refracted

karmic hatch
# tight phoenix the second one is inside out

How does it work? Maybe you could scavenge it and pass in a different view direction to get the refracted version (if it uses the view direction inside. If not, that would also be interesting)

tight phoenix
#

this is what I have, but I have a real dice on my desk, it should be sort of the opposite of this

tight phoenix
#

view direction is used

#

"direction" that is passed in is just 2 or -2, its not actually direction

karmic hatch
#

Excellent, so just make a copy and instead of view direction, pass in the new refracted ray, and if all goes well then it should work

knotty bough
tight phoenix
#

end result is wacky atm

karmic hatch
tight phoenix
#

or should I pass in the inside out version and then use it AGAIN on the inside out version?

tight phoenix
karmic hatch
#

the second vector3 input is surface normal though, no?

#

for the refract node

tight phoenix
#

what should be plugged in here

#

Im not understanding

karmic hatch
#

the object space normal vector

tight phoenix
#

the result is identical to if I had passed in a position object space to the cube map at the very end

#

nothing happens at all if I play with the index of refraction value

karmic hatch
#

Does it work if you set both refractive indices to 1?

tight phoenix
#

that is the result of 1

karmic hatch
#

But if you just bypass the refract node with the view direction, does it go back to working?

tight phoenix
#

here is the shader if you want to look yourself, it seems more productive since Im a blind ape trying to do anything

tight phoenix
#

it was never working by my definition of working

karmic hatch
#

Does it show the interior of the cube?

tight phoenix
#

Since that is what it was before in the subgraph

karmic hatch
tight phoenix
#

Yeah fair point

#

speaking of crazy - this is my refract

#

in case maybe I made some super error here thats breaking everything

#

but to my knowledge thats standard

karmic hatch
tight phoenix
#

yeah

karmic hatch
#

if the two refractive indices are both the same it should just return the view direction so idk why it's acting up. Maybe try negating the view direction going into the refract?

tight phoenix
#

the indexes are just a division

#

iunno if thats what you expect it to be

karmic hatch
#

yeah that makes sense

tight phoenix
karmic hatch
#

hmm

tight phoenix
#

I would expect it to do -something-

#

since its completely opposite values

karmic hatch
#

what if you negte the value coming out of the refract?

tight phoenix
#

or in this case, remove the negate because it already was

karmic hatch
#

yes

tight phoenix
#

without the exit negate (and with not a negated input) it does this wild thing
without exit negate but negating the input view direction, it looks the same as it would if I had skipped the refract entirely like before

#

changing the IOR values just make the above look even more messed up

karmic hatch
#

are both values 1?

tight phoenix
#

:OOO

#

they were both 1

#

negated input and not negating output produces the refraction expected

karmic hatch
#

ayy amazing!

tight phoenix
#

It looks just like the dice on my desk when I move it around

tight phoenix
#

working as intended πŸ‘Œ πŸ‘

karmic hatch
#

wonderful :)

#

looks great!

worldly karma
#

for some reason, the normals look weird along a specific world axis, on specific sides of the mesh. i'm trying to make a triplanar shader. i've been stuck on this problem for hours. the shader works with the default cube / sphere in Unity, but not this specific mesh.

#

this is smoothness = 0

tight phoenix
karmic hatch
#

that looks really good :)

tight phoenix
karmic hatch
#

sure, why not

tight phoenix
#

Im getting very close to being feature complete on all these shaders and putting it all together into one GPU melting final product

grand jolt
#

I'm setting a shader on material at runtime and I have a property on the shader that needs to be set. How do I set the property?
Also my gameobject has these properties, that's how I get the shader in the script. Do I need to create a new shader instance for every object?

#

I guess each object generated in the script could share a property and I could change the shader to make calculations from that.

knotty bough
#

I have a feeling this might be a Unity bug, but I'm getting this issue specifically in the complied output of the shader

#

Any thoughts?

#

All the googling I've been doing seem to be leading to completely different anwsers

grand jolt
#

Does it go away if you use the output?

knotty bough
#

Nope

#

Also

#

I just figured it out

#

Typo in the name

#

for custom funciton

#

an hour of trouble shooting

grand jolt
#

uggh

knotty bough
#

And ofc I figure it out the moment after I ask for help -_-

grand jolt
#

That's why we call it help.

#

It happens a lot, if I'm having trouble when I go through the process of explaining the issue I get a better understanding and often solve it.

round patrol
#

looks clean to me.

#

Maybe the shadergraph itself its ignoring uv's and generating them unless i specifically tell it to use the mesh uv's

#

Nope. I've tried using the UV's and it's still not working

#

I've tried quads and traingles in blender, I've tried tris and keep quads import settings in unity. It makes no difference, all the same result. In the shader I've tried UV0, UV1

#

I figured it out I think...

#

Yup it's working now. I was using the Tiling and Offset nodes Tiling x and y values to scale the texture size, rather than scaling the texture itself. I was effectively ruining the UVs by tiling them rather than the texture. Big whoopsie

knotty bough
#

And I just realized why sobel approach won't work

#

Relies on camera perspective

#

Meaning it won't correctly wrap around if hidden behind geometry

#

Out of all the programming tasks I had this week

#

I never imagined that it's "just make an outline for a procedural plane" that would be my absolute timesink -_-

grand jolt
#

Okay how do I make it look like stuff? It just looks like...crap. Like vertex color or something.

rain moat
#

Can someone help please how to convert a game object to HDRP textures? When I click on convert all built-in materials nothing happens, when I click 2nd option then it says I need to select a material

grand jolt
#

Okays that's easy but it all has the same light.

kind juniper
rain moat
kind juniper
rain moat
#

I changed to HDRP/Lit

kind juniper
rain moat
rain moat
#

Thanks again @kind juniper I've found one model and just only one model free on asset store that converted into HDRP without issue dogohappy

#

Actually you're helping me for a 2nd time ThinkHmm insane!

#

A couple of days ago I had other issue with a script and you were helpful as well

grand jolt
#

I don't understand how to get vertex color working. The previous image I posted worked because if fall back to another shader because mine failed to compile.

void vert(inout appdata_full v, out Input o) {
    UNITY_INITIALIZE_OUTPUT(Input, o);
    o.vertColor = v.color;
}
void surf (Input IN, inout SurfaceOutputStandard o) {
    float3 position = IN.worldPos - _Center.xyz;
    float n = _Center.w;
    clip(n - abs(position.x)); 
    clip(n - abs(position.y));
    clip(n - abs(position.z));
    o.Albedo = IN.vertColor.rgb;
    fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    o.Alpha = c.a;
}```
round patrol
#

Is it possible in shader graph to wrap/repeat scale a texture without scaling UVs? Or will I have to manually loop the texture to a higher resolution in an image editor?

grand jolt
#

I have this spotlight aligned with the camera and it seems to draw a line based on the angle of the camera. If I look to the right it shows a full light spot, if I look to the left the light is obscured. Why is this happening?

worldly karma
#

Only 1 of you will have your questions answered. It's a game of elimination.

grand jolt
#

Pick me.

worldly karma
#

Hmm... I guess the spotlight could depend on the receiving mesh, and the render distance of the camera... I'm not sure.

grand jolt
#

It's strictly based on angle I can get really close and it still happens.

worldly karma
#

Now, answer the 20 questions I've asked that got buried and forgotten. lol

grand jolt
#

I'm guessing I didn't configure mesh nromals properly.

#

Mesh is procedurally generated.

worldly karma
#

That's likely the issue

grand jolt
#

Is there any automatic computation of normals?

kind juniper
kind juniper
worldly karma
#

$5 to whoever can solve my shader graph problem.

grand jolt
#

yo what is wrong with unity? Like I can't use the kayboard half the time. Focus on controls suddenly stops workin...lol how old is this engine?

grand jolt
#

Yes it block my job. I need to figure out the actual math.

#

Does a normal have to actually be a unit vector?

kind juniper
kind juniper
kind juniper
grand jolt
kind juniper
#

Why not?

grand jolt
#

squares are slow

kind juniper
#

Did you even try it?

grand jolt
#

yes

kind juniper
#

Well,then good luck figuring it out.πŸ˜…

worldly karma
grand jolt
#

It's easy when you know the math. I unfortunately have to figure it out the hard way.

worldly karma
#

The normals of the default cube appear just fine. But the normals in the x-direction of the custom mesh appear too glossy / gray

kind juniper
#

Which side exactly is the x- direction on this screenshot?

worldly karma
#

The side with the flat gray color

kind juniper
#

It just looks like there's no texture there at all

#

Is it uv mapped?

worldly karma
#

Both sides appear like that. There is a texture there.

#

Yes, it's UV mapped.

kind juniper
#

Are you using triplanar or uvs here?

worldly karma
#

It just looks super glossy.

#

triplanar mapping, but the mesh is UV mapped properly. the mesh actually looks fine without normal maps.

kind juniper
#

If you're using triplanar, the uvs are not used, so that doesn't matter.

#

Can you share the shader setup?

worldly karma
#

without normals, shader graph setup

#

i can share my github repo, if you'd be willing to take a look.

kind juniper
#

Hmm

#

Can you take a screenshot of the normal map texture?

worldly karma
grand jolt
#

I thought normal was a surface normal

kind juniper
kind juniper
worldly karma
#

it does, it's just super weak. i had to increase the normal strength in shader graph

worldly karma
#

freepbr

kind juniper
#

Doesn't look normal. Does it look the same way if you open the file with an image editor?

worldly karma
#

yes

#

that was a scrnsht from photoshop

#

maybe that's the issue.

kind juniper
#

Hmm... Try any different normal map and see if it works

#

Any that looks "normal"

grand jolt
#

Vertex normal is actually an average of all the surfaces that use the vertex.

#

(β•―Β°β–‘Β°οΌ‰β•―οΈ΅ ┻━┻

kind juniper
grand jolt
#

So it's like a huge pita to do so naturally there are no easy to find solutions.

kind juniper
#

Didn't you find the solution already? The average of surface normals.

grand jolt
#

It's a huge pita

#

This is the most promising thing I found and I just found it and I'm reading it.

kind juniper
#

Pita is middle eastern bread. What do you mean exactly?

grand jolt
#

Pain In The Asset

kind juniper
#

On the basic level, you'd just get the directions of all connected vertices to the current vertex and average them.

#

That would be your normal

#

I think.

grand jolt
#

That would fail on a flat surface I imagine.

kind juniper
grand jolt
#

Yeah I could do it but it's on the todo list for now and I'll just use the builtin.

worldly karma
kind juniper
#

That or do it in 2 passes: calculate the normal per triangle, then calculate each vertex normals from the triangles

grand jolt
#

It still needs awareness of adjacent vertices or surfaces.

#

I would need to go over every triangle and for every corner I would need to add the surface normal to a list then after thats all done I would need average then normalize. At least I think that's right.

#

Okay actually it's easy.

patent plinth
#

Any idea how to force shader made with ShaderGraph NOT to be compliant with SRP batcher?

This is my use case, I have vegetation shader that will use instance instead of SRP.. but the thing is, SRP batcher keeps taking over

#

sorry for bad english

#

But is there any way to do it directly in ShaderGraph?

grand jolt
kind juniper
#

(1+1+1)/3 == 1

grand jolt
#

They are not normalized.

valid badger
#

Hey there, I've got a shader which has the following property, how would I go about accessing this property in code?
_Overlay ("Overlay", 2D) = "white" {}

My first thought was material.GetTexture("_Overlay"); - But that is returning a NPE so it isn't a texture, I have no clue how to get a property type of 2D

EDIT : In the inspector it's labeled as _Overlay Overlay (Texture)

kind juniper
#

GetTexture should work. What's NPE?

valid badger
#

Running this on the material, I'm getting an output to say that _Overlay exists and is set, but when I try to actually get it, its null

#

I'm not sure if this is a shader/material problem or a C# problem

kind juniper
#

Hmm

#

Is it global property perhaps?

#

Try Shader.GetTexture?πŸ€”

valid badger
#

Nope- not a global property

#

I’ll ask the guy who set it up later when he’s awake. Maybe he can shed some light on what I’m missing

regal stag
# patent plinth But is there any way to do it directly in ShaderGraph?

I know using the Override Property Declaration in a property's settings can cause it to break SRP batching compatibility. Unless they've changed how that works.
Maybe set up a Float/Vector property, keep it Exposed but switch it to Global.
That way, I think it should keep it in the ShaderLab Properties section, but wont be defined in the PerMaterial cbuffer - which breaks compatibility.

patent plinth
#

@regal stag I declare your from now on to be a shader GOD!..

It works!.. Thanks!

#

I literally wait for 2 hours just for this πŸ˜† .. thanks so muhc

#

Lets hope they would not change this in the future, or it will break my game hahaha 🀣

#

what's funny tho, setting the MaterialPropertyBlock as suggested in the docs to break SRP compat didn't do anything...

restive radish
#

I'm having a small problem with transparent shader. Basically, the transparent shader shows some of the inner face on areas supposed to have no transparency. Below is the difference of the same shader in opaque and transparent.

#

The shader is just this:

#

for context, I change to transparent when I change to a see through material (opaque + dithering doesn't give a very good effect)

restive radish
#

Never mind, fixed with depth write forced enabled

oblique cloud
#

spotlight look like this any help?

#

any idea?

#

it acts as a billboard

oblique cloud
#

any 1 got a basic light shader i can use?

#

that works with multiple light sources and spotlights

#

?

#

anything helps

grand jolt
oblique cloud
#

spotlight

#

but lights work in general like that

grand jolt
#

I didn't think the actual lights were visible in the scene.

patent plinth
kind juniper
oblique cloud
#

alr

grand jolt
#

Is it same issue I just had last night? Does your mesh have correct normals?

oblique cloud
#

hmm

#

ill try that

restive radish
patent plinth
#

ah I see... if you somehow upload it to Sketchfab, lemme know πŸ˜† ... I'll download it for sure πŸ™‚

restive radish
patent plinth
#

very neat!.. well, one could just hope πŸ™‚

#

thanks anyway!

kind juniper
oblique cloud
#

custom edit

kind juniper
#

Is it a graph or regular shader?

oblique cloud
#

regular

#

vertex

#
o.vertexLighting = float3(0.0, 0.0, 0.0);
    #ifdef FORWARD_BASE_PASS
        #ifdef VERTEXLIGHT_ON
        for (int index = 0; index < 4; index++)
        {  
        float4 lightPosition = float4(unity_4LightPosX0[index], unity_4LightPosY0[index], unity_4LightPosZ0[index], 1.0);

        float3 vertexToLightSource = lightPosition.xyz - o.worldPos.xyz;    
        float3 lightDirection = normalize(vertexToLightSource);
        float squaredDistance = dot(vertexToLightSource, vertexToLightSource);
        float attenuation = 1.0 / (1.0 + unity_4LightAtten0[index] * squaredDistance);
        float3 diffuseReflection = attenuation * unity_LightColor[index].rgb * _Color2.rgb * max(0.0, dot(o.normalDirCalc, lightDirection));     

        o.vertexLighting = o.vertexLighting + diffuseReflection;
        }
        #endif
    #endif
#

fragment:

#
float3 normalDirection = normalize(i.normalDirCalc);
    float3 viewDirection = normalize(_WorldSpaceCameraPos - i.worldPos.xyz);
    float3 lightDirection;
    float attenuation;

    if (0.0 == _WorldSpaceLightPos0.w) // directional light?
    {
    attenuation = 1.0; // no attenuation
    lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    } 
    else // point or spot light
    {
    float3 vertexToLightSource = _WorldSpaceLightPos0.xyz - i.worldPos.xyz;
    float distance = length(vertexToLightSource);
    attenuation = 1.0 / distance; // linear attenuation 
    lightDirection = normalize(vertexToLightSource);
    }
    half3 ambientLighting = ShadeSH9(float4(normalize(i.normalDir.xyz), 1.0)) * _Color2.rgb;
    float3 diffuseReflection = attenuation * _Color2.rgb * max(0.0, dot(normalDirection, lightDirection));

    float3 specularReflection;
    if (dot(normalDirection, lightDirection) < 0.0) 
    // light source on the wrong side?
    {
    specularReflection = float3(0.0, 0.0, 0.0); 
        // no specular reflection
    }
    else // light source on the right side
    {
    specularReflection = attenuation * _SpecColor2.rgb * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), _Shininess2);
    }
    float4 results = float4(i.vertexLighting + ambientLighting + diffuseReflection + specularReflection, 1.0);
#

may help

rare root
#

hey, i was wondering what is actually considered metallic? i thought it was gloss + some other stuff but i think thats probably wrong

restive radish
#

metallic is related to how reflexive a material is, while glossiness is how smooth the surface is

#

a smooth material will be more shiny, but not necessarily reflect the environment around

#

obviously, a metal still needs to be smooth to reflect properly, but a non metallic smooth material won't reflect the environment

restive radish
rare root
#

ok nice, i think i understand that

#

so to have more realistic metallics i want to maybe use something like image based lighting to get the reflections of the environment ?

#

and also change the reflection colors to the albedo colors?

restive radish
#

Basically, yes. For example, the metal of a shiny car, or a mirror, would have something like 1 and 1 in both metallic and smoothness, while a wood with smooth paint would have 1 smoothness, but zero metallic

#

most objects have zero metallic, it's basically used when you want the environment (most of the times, the sky) to be reflected

#

however, lots of objects are smooth, like plastic, smooth paint and other surfaces

#

latex might have a bit of metallic to look cooler

rare root
#

coolcool, then i think i know what to look for to implement it UnityChanCelebrate

restive radish
#

I don't use it in my shaders since reflection clashes with the stylized style

#

it's useful for realistic style, among other mixes with cartoonish

rare root
#

yeah, im looking to just learn it for non stylized/more realistic look and then se if i can use it in anything else i do

grand jolt
#

hey trying to make a sprite shader but it looks weird after i add the material with this

regal stag
grand jolt
#

Ooh.. makes sense thank you^^

rare root
#

is there a unity macro or function to get the skybox texture?

#

for world reflections

regal stag
rare root
#

nice thanks

#

that worked nicely

restive lava
#

also, something that has been bugging me for months is: i have a water shader, i made it transparent but it stops receiving shadows, so is it possible to make transparent objects receive shadows? i'm using BiRP by the way

regal stag
tight phoenix
#

Im having some trouble fixing this bright burn out spot (the solid green)
It's happening because my values are exceeding 1 when it goes into the Arccosine
minmaxing it prevents it from breaking, but im losing the 'HDR' color potential that only shows above 1

#

How can I still use the arccosine but retain the high values after?

#

Arcsine needs the values to be between -1 and 1, but I need the values to go higher than that by the time it reaches the end πŸ€” maybe I can try to move all my value adjustment to be beyond the arcsine

karmic hatch
#

can you just multiply by something afterwards?

tight phoenix
#

trying to bring it down before the arcsine and then back up again totally changes the appearance

#

Im very happy with how this looks, except all the bright green area is a value of 1

#

ideally it would be a value higher than 1

#

the arcosine is the bottleneck preventing this as far as I can tell

#

Maybe I need to not use Arcosine and instead impliment what it does but in respect to my use case?
I looked at the doccumentation and its just acos(#) so Ill have to google what the acos formula is

regal stag
#

Is the Arccosine important? What happens if you just remap the dot product output a bit instead. Like from (-1, 1) to (3.14, 0)

tight phoenix
tight phoenix
#

there is a bit of difference but its not major

#

though the color burn out is still hapening so ill have to look further down the line

regal stag
#

Maybe you have a saturate/clamp somewhere later?

tight phoenix
#

I assume I put them all in in the past because the shader was breaking in other ways

#

ahh I found the problem I think

#

im adding a maximum here

#

because if I dont maximum it, the add totally blows out the entire appearance

#

actually the opposite, it looks way worse without the maximum

#

ill see if I can do some pow/mult here to fix it

tight phoenix
#

the color green was also causing a lot of the burn out as well since you can barely see it turn into yellow at high values, but also it was clamped

regal stag
#

Nice, looks great!

vast vigil
#

does anyone know how to get rid of these files in the final build? they're adding a huge amount of file size to my webgl build, despite the fact that we don't use filmgrain or any other post processing. I have the checkbox checked to remove unused post processing but its still being bundled

#

2021.3.6f1 version

zenith heron
#

In hlsl, if I wanted to use a function that returns a value (rather than outing a value) for utility purposes, could I set up some sort of (0f, 0f, 1f, 5f) for the return value, rather than making a new float4? Also, do utility functions that never get used in shadergraph need to have the _float suffix in their names? Thank you very much for your time.

karmic hatch
zenith heron
#

Thank you very much for helping me out. By the way, by the mention of _[type], one would assume that many suffixes exist. In that case, why do some functions go by the suffix _float? Thank you very much for your help.

meager pelican
#

@zenith heronIDK what the last expression is, but if that's a float4 you need a constructor call as in:
return float4(0, 0, 2., 5.);
otherwise it is just a parenthetical expression that won't evaluate to a float4.

#

The suffix notation is a shader graph enforced standard for the return type

zenith heron
#

oh ok

meager pelican
#

You may also find it easier to use the .xyz or .rgb notation rather than the [0], [1], etc. for vector components. xyz is the same as rgb...you can use them interchangeably. By convention when dealing with colors you use .rgb.

zenith heron
#

ohh ok

#

makes more sense to use that

#

by the way, hlsl finds the fs in my numbers and sees them as errors. Is there no float suffix indicator such as float x = 5f or something? What about float x = 5F? Thank you very much for your time.

#

Hello, where can I report shadergraph errors? Unless these sorts of errors may be caused by the user and yet be seen as internal errors by Unity.

meager pelican
karmic hatch
#

Do you need it at all? I know GLSL whines if you don't put a point after ints when you want them to be floats, but HLSL seems perfectly happy with it.

meager pelican
#

For constants the compiler will usually substitute the proper value IIRC. I think it is smart enough to do that. But you can get burned in expressions that might assume ints. Maybe try something with an int like:

float myvalue = 1/three;```
and see if you get burned by int math.
karmic hatch
#

just looked it up and hlsl does indeed do 1/3 = 0

indigo token
#

Using Amplify shader

tight phoenix
#

Can someone explain to me what Arc Cosine actually does
Like pretend I have to compute it by hand on paper.
Acos(#) is a black box, it means nothing to me, input goes in, result comes out

#

I tried to google it but I cant find an explination stupid enough for my dumb brain, and I asked in basic code because I forgot they're all elitists who only want to argue WHY you want to know something, and never actually explain anything

#

aparently the reason why you want to know an answer is more important than the answer itself, even after I gave them the #$%#$^ing reason repeatedly

atomic glade
tight phoenix
#

and now im being followed by the person who is now harrassing me across channels great

#

blocked

atomic glade
#

Even before calculators people literally looked it up in a chart

tight phoenix
#

i guess ill just go to an entirely different platform to get an answer

wary horizon
karmic hatch
tight phoenix
#

I guess that explains why its so hard to find an answer or formula

#

when its not a formula, its a look up table of magic numbers

atomic glade
#

But I guess that's "elitist"

grizzled bolt
atomic glade
honest bison
#

How would I create a reflection on the surface of a sphere?

grizzled bolt
honest bison
grizzled bolt
#

To make it work with custom skies or in realtime you may need to modify that process or replace it with your own

honest bison
#

Cosine(1 radian) = .54... ArcCos(.54... ) = 1 radian

honest bison
#

I am hoping I wont need to write my shader graph into a shader file.

grizzled bolt
honest bison
#

ArcSin and ArcCos will only give you a value over pi radians, or 180 degrees.

valid badger
#

Is there a way to see a model's vertex colors in the editor?

honest bison
valid badger
grizzled bolt
meager pelican
# karmic hatch just looked it up and hlsl does indeed do 1/3 = 0

Yeah, but in the case of float4 foo = float4(1,1,1,1); the 1's would be auto-promoted to floats, I think. But in the case of float foo = 1/3 I think that ends up being evaluated as float foo = (cast to float) (int 1/ int 3 truncated via int division) so it's a bit different than your original question.

meager pelican
# honest bison True, I guess before I worry about this question, I will need to have my custom ...

In a BiRP shader, you can sample the default cubemap for environmental reflections. Each draw call gets a default cube map that represents (I think) the closest reflection probe, or maybe a couple of probes are mapped in.

Anyway, I assume since you're dealing with SG you're NOT in BiRP (although it sort-of works for that too). But if you don't have a node for it already, you can write a custom function because IIUC URP will also "send" you a default probe.

In BiRP, the code to do that is:

       v2f o;
       o.pos = UnityObjectToClipPos(vertex);
       // compute world space position of the vertex
       float3 worldPos = mul(_Object2World, vertex).xyz;
       // compute world space view direction
       float3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPos));
       // world space normal
       float3 worldNormal = UnityObjectToWorldNormal(normal);
       // world space reflection vector
       o.worldRefl = reflect(-worldViewDir, worldNormal);
       return o;
  }
        
   fixed4 frag (v2f i) : SV_Target {
      // sample the default reflection cubemap, using the reflection vector
      half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
      // decode cubemap data into actual color
      half3 skyColor = DecodeHDR (skyData, unity_SpecCube0_HDR);
      // output it!
      fixed4 c = 0;
      c.rgb = skyColor;
      return c;
}```
This is from here: https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html
#

Note how they compute the necessary reflection vector in the vert() stage...so as to only do it 3 times per polygon, and then in the frag() stage they decode the results after sampling the reflection probe. In SG, the reflection vector would be a custom interpolater if it isn't natively available otherwise.

honest bison
azure lichen
#

Hey, how can I change the shader when it's greyed out?

#

I want to change the shader to something so the tea pot is rendered through the box

kind juniper
azure lichen
#

Because all guides I've previously seen always said to just drop it into the assets

kind juniper
azure lichen
#

Just reimported in case it matters that it's still a packed prefab

#

You meant the material in the inspector, right? Or is there a separate tab for the material?

kind juniper
#

Select the teapot root asset. It should bring the fbx import settings, which have the material tab.

azure lichen
kind juniper
#

Yes, click it

#

Just for your info, all this does is just create a new material, assign it to the renderer and set whatever properties it can understand from the fbx file(like the textures). You can totally do it manually.

azure lichen
#

Could it be pink here because I made a mistake in the shader code?

kind juniper
#

Yes. Pink means a broken/incompatible shader.@azure lichen

azure lichen
kind juniper
azure lichen
#

Yea, it's a custom shader, not too complex either

Shader "Custom/AlwaysOnTop"
{
    Properties
    {
        _Color("Color", Color) = (1,1,1,1)
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Metallic("Metallic", Range(0,1)) = 0.0
    }
        SubShader
        {

            ZTest Always

            Tags { "RenderType" = "Opaque" }
            LOD 200
            CGPROGRAM
            // Physically based Standard lighting model, and enable shadows on all light types
            #pragma surface surf Standard fullforwardshadows
            // Use shader model 3.0 target, to get nicer looking lighting
            #pragma target 3.0
            sampler2D _MainTex;
            struct Input
            {
                float2 uv_MainTex;
            };
            half _Glossiness;
            half _Metallic;
            fixed4 _Color;
            // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
            // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
            // #pragma instancing_options assumeuniformscaling
            UNITY_INSTANCING_BUFFER_START(Props)
                // put more per-instance properties here
            UNITY_INSTANCING_BUFFER_END(Props)
            void surf(Input IN, inout SurfaceOutputStandard o)
            {
                // Albedo comes from a texture tinted by color
                fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
                o.Albedo = c.rgb;
                // Metallic and smoothness come from slider variables
                o.Metallic = _Metallic;
                o.Smoothness = _Glossiness;
                o.Alpha = c.a;
            }
            ENDCG
        }
            FallBack "Diffuse"
}

Its purpose is just to layer the object with that shader on top of everything

kind juniper
#

Hmmm... I don't see how exactly is it different from the standard shader

#

What's the part that makes it render on top?

azure lichen
#

The "ZTest Always" iirc

#

Using Unity 2019.4.28f if that matters

kind juniper
#

I see. In this case, you might as well take the URP lit shader template and add that line to it. Might be simpler.

kind juniper
# azure lichen The "ZTest Always" iirc

Oh, btw it seems like the ztest is exposed as the shader graph property in the shader graph now. So you could create a shader graph and adjust that property in it.

#

In 2021 though.

azure lichen
# kind juniper In 2021 though.

I've just inserted the ZTest into the URP lit shader as you said before and it works. Now also my AR apk works as intended as well. I've got stuck on that single issue for way too many days now. Thank you alot. You have no idea how happy I am that this runs now πŸ˜„

#

Yea, Apparently there were a lot of solutions to my issue by using the 2020 or 2021 version of Unity, but then I'd have other compatibility issues on other ends which I wouldn't be able to fix

kind juniper
azure lichen
#

It's mostly related to Vuforia at that point. I've been trying some of the 2020/2021 solutions that I found, but I'd usually run into compatibility issues, even after building up everything from nothing again. First starts with things like ARCore bugging, then Gradle, then Vuforia because of ARCore, etc.

Well, at least it's working now.

zenith heron
#

Hello, where can I report shadergraph errors? Unless these sorts of errors may be caused by the user and yet be seen as internal errors by Unity.

clever saddle
#

I create a surface shader and a material.It displays purple.I tried do upgrade to URP.But it doesnt work. says"Custom_NewSurfaceShader material was not upgraded. There's no upgrader to convert Custom/NewSurfaceShader shader to selected pipeline"

#

How to write a transparent surface shader in Unity?What kind of shader ppl usually use for transparent shader?Unlit?Or standard?I know how to write transparent in unilit.But could anyone show me an example of transparent surface shader?

unkempt mist
#

Sorry for not responding to this for a while, but would this be in a Compute Shader or shader graph?

kind juniper
kind juniper
#

Anyways, it's definitely not a compute shader, as you don't use it to render stuff.

unkempt mist
#

Like a custom shader or one of Unity's default?

kind juniper
#

Custom shader.

unkempt mist
#

Oh ok, i have no idea how to write a custom shader, and im barely understanding compute shaders.

violet urchin
#

Im trying to setup unity chan toon shader and according documentation i should use "rendering path -> forward", but i am not able to find this option.
Some tutorials also advice to use UTS2 Pipeline asset, but i cant choose it under graphics.
How can i setup this option ?
(i am on android platform)

high sandal
#

Hi there, not sure if this is the correct channel, but I'm trying to apply some shader magic on the camera of a device, and then export said image to a PNG. Is this something that can be done with shaders? I was looking into Custom Render Textures, but I'm not sure if this is the way forward. Does anyone have any suggestions on how to proceed?

rare root
#

ive gotten reflections of the skybox working, but it seems like im not adding it to the rest of the shader correctly. it might be that i have the metallic variable correct.
it doesnt get to that mirror like reflection this way

float3 reflectionDir = reflect(-V, i.worldNormal);
float4 envSample = UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, reflectionDir, _MetallicRoughness * metallicMap * UNITY_SPECCUBE_LOD_STEPS);
float3 diffuseIBL = DecodeHDR(envSample, unity_SpecCube0_HDR);
light += diffuseIBL * _MetallicIntensity; // light is diffuse + specular + fresnel
patent plinth
clever saddle
#

Why my shader is not transparent

rare root
rare root
clever saddle
rare root
#

you still need to write to the depth buffer if you want it to be transparent

#

or not to write to it i guess

clever saddle
#

I added "Zwrite On" or "Zwrite Off",Still doesnt work.Nothing happened.Im new to coding shader.

karmic hatch
#

you need all the keywords to be set for a transparent shader, and then you need to set the alpha to be <1 (and >0)

restive radish
#

Is there any way to scale the displacement of a graph in a similar way to a triplanar node on a texture?

#

I mean, when you scale the object, it just repeat the displacement instead of enlarging it (Update: FIXED)

patent plinth
#

..triplanar node on a texture you mean the offset uv for the texture tilling?

tall glen
patent plinth
#

you're not using some sort of fullscreen effect? like PP for outline effects for example

tall glen
#

this one

restive radish
#

vertex position

tall glen
#

that I linked

rare root
#

ive noticed that my shaders isnt effected by this value. how do i access it?

restive radish
#

you have to either create a custom node, or modify lighting.hlsl

patent plinth
clever saddle
#

It's strange.Wanna make a portal.Why it only works in solid color?

#
#pragma surface surf Standard fullforwardshadows alpha:fade
#

I used alpha fade

rare root
#

oh you are using surface shader lol, i didnt check that when i first looked at it. that would make sense

dense dawn
#

Kinda difficult question but I'm running a compute shader that updates a large image, and the more times it runs the longer each iteration takes, when in theory it should be running on fresh data each time, is there a step I could be missing, like releasing a buffer or something? It gets the the point where I have to force shutdown my computer if I don't stop it in time

tall glen
tame topaz
tall glen
tame topaz
#

Did you bake your scene?

dim yoke
oblique cloud
#

how can i turn passes like these into a for each loop to reducee repetition?

Pass
       {
           Name "Forward_Fur"
           Tags {"LightMode" = "ForwardBase"}
           CGPROGRAM
           #pragma multi_compile_fwdbase
           #pragma vertex vert
           #pragma fragment frag
           #define FORWARD_BASE_PASS
           #define _FURLAYER 0.0
           #include "FurHelper.cginc"
           ENDCG
       }
   
       Pass
       {
           Name "Forward_Fur"
           Tags {"LightMode" = "ForwardBase"}
           CGPROGRAM
           #pragma multi_compile_fwdbase
           #pragma vertex vert
           #pragma fragment frag
           #define FORWARD_BASE_PASS
           #define _FURLAYER 0.0526315789473684
           #include "FurHelper.cginc"
           ENDCG
       }
       pass
       {
       etc...
dense dawn
# dim yoke Have you tried the memory profiler to see if there are some memory leaks happeni...

The memory section on the normal profiler gives this, but I'm not too sure what to make of it:

Reserved Total: 0.64 GB   Unity: 299.3 MB   Mono: 21.3 MB   GfxDriver: 64.8 MB   Audio: 1.2 MB   Video: 0 B   Profiler: 273.0 MB   
Total System Memory Usage: 20.39 GB   

Textures: 1559 / 19.23 GB
Meshes: 276 / 1.6 MB
Materials: 46 / 89.0 KB
AnimationClips: 0 / 0 B
AudioClips: 0 / 0 B
Assets: 2293 
GameObjects in Scene: 8 
Total Objects in Scene: 1354 
Total Object Count: 3647
GC Allocations per Frame: 0 / 0 B```
#

The 19.23 GB looks kinda alarming but I'm not sure if that's normal

dim yoke
uneven frost
#

Hello!
So recently this asset https://assetstore.unity.com/packages/tools/particles-effects/true-clouds-fog-mobile-pc-107379?aid=1011l37no&pubref=indie&utm_campaign=unity_affiliate&utm_medium=affiliate&utm_source=partnerize-linkmaker was made free on the Unity Asset Store. But it is not compatible with URP or HDRP, runs only in the Standard Pipeline. I wanted to port this to a URP project but I only know beginner-level HLSL. Can someone point me in the right direction as to how to make this asset compatible with URP? As these shaders were written before it URP was released.

dense dawn
dim yoke
dense dawn
dim yoke
#

Great

teal breach
#

is there a way to detect, within a shader, if an asset is being rendered as a preview?

meager pelican
teal breach
#

I think that works for the shader graph preview window, but not for the asset preview window

#

(the one that comes up when using the inspector to look at materials/objects, for example)

teal breach
#

If I could switch the logic in the shader I might be able to work around it

teal breach
#

a rather frustrating api change

meager pelican
#

@teal breachHow are you setting that "global"? With Shader.SetGlobalColor?

teal breach
tall glen
clever saddle
#

Is it able to wirte a transparent surface shader?
Is there any ez example code of tranparent surface shader?

rare root
#

so ive been trying to properly apply my metallic reflection. i have the reflection working how i want with roughness and metallic map and whatever, but i cant figure out how to properly apply it.

if i multiply the reflection straight into the albedo like this
float3 output = albedo.xyz * reflection * (light * _MainColor + specularLight + saturate(fresnel) * _ColorRimLight * _ColorRimLight.a * light);
it looks correct if the metallic is equal to 1. but this way it also makes it go black if its 0. but if i try anything else it doesnt get the correct color. ive tried a lot of different things like
float3 output = albedo.xyz * (light * _MainColor + specularLight + saturate(fresnel) * _ColorRimLight * _ColorRimLight.a * light) + reflection * albedo.xyz ;
and
float3 output = albedo.xyz * (light * _MainColor + specularLight + saturate(fresnel) * _ColorRimLight * _ColorRimLight.a * light + reflection * albedo.xyz);

someone said that the reflection should be multiplied with the black albedo but it doesnt seem to look right if i just add it on top
what am i doing wrong?

teal breach
# meager pelican Like in shader graph? IIRC, in a custom node, you can do it with compiler condit...

from digging around, I've also found that this define only works for the thumbnails in the individual shadergraph nodes. It doesn't work for the 'preview' window in shadergraph, which it seems you have to test for using SHADERPASS == SHADERPASS_FORWARD_PREVIEW after making an #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl". I hadn't noticed that before!

#

I just needed it for something else, thought it good to share πŸ˜‰

tight phoenix
#

I am having some difficulty getting a desired look out of this shader im working on.
Pictured first is what I want to see, the interior backface refracted. I have it working but only from certain camera angles.
Pictured second is what happens if you look at it from a certain angle, the "interior" gets completely lost

#

I can't seem to figure out how to adjust the shader so that the interior doesn't get lost at certain angles

#

the coordinates arent the problem as far as I can tell, they never get lost no matter the viewing angle (sorry broken gif)

#

which leads me to believe its getting lost somewhere in here

#

plugging it in to the output one node at a time, it seems to vanish at the dot product

#

my end goal is to accentuate the faces so they are clearly present from all angles

#

I have this that draws a box that I could use to make the faces more pronounced, but I cant figure out how to modify it so that it uses the refracted faces

timid minnow
#

(HDRP) This gets me a nice circular shape... what would I do to achieve a more diamond-shaped version of this?

#

racking my brain thinking about it

tight phoenix
#

you can change its shape by adjusting the tiling in the tiling+offset but till need to be recentered

timid minnow
#

oooh that's very interesting, I'll play with that!

#

I just managed this:

tight phoenix
#

Yeah thats about the same thing

timid minnow
#

not sure which is more performant or better fit for purpose, but it's a start

karmic hatch
# tight phoenix will this suffice?

you can go more general than that too; do (r^p + g^p)^(1/p) and then by changing p, you can get from diamond at p=1 to circle at p=2 to square at p=inf @timid minnow

tight phoenix
#

I figured there'd be a smarter answer, that is the limit of my ability

karmic hatch
#

(btw this is called the p-norm of the vector)

tight phoenix
#

struggling to get the white appearance but on the coordinates of this other texture πŸ€”

#

distance and length don't form the cube

#

hmm maybe I should do what I just showed that person, the absolute maximum?

karmic hatch
#

wdym by "on the coordinates of this other texture"

tight phoenix
#

I want the white appearnce, but with refraction making the surfaces not cubic

#

ah this doesnt work at diagonals

#

all of this is XY

#

what I really want is to make the interior faces at certain angles not vanish as seen above

karmic hatch
#

How do you blend between them?

tight phoenix
#

I don't

#

the white one is not used at all in the method

#

the only reason its there is because I was trying to get it to work like the other one so that I could blend them

#

I guess the problem is that i want to blend them but I dont know how to make the white one respect the refracted ones surfaces

#

this almost works but its got a dumbass cross in the middle of it

#

minimums, adds, maximums none provide the desired appearance

#

maybe subtraction?

#

nope even worse

#

I want this white like this

#

again this is all xy

#

I just want the interior faces to stop vanishing

#

and every attemp of the dozesn ive tried have failed

#

I cant boost the values, I cant negate the washout, I cant do a single #$%#&^ing thing I want do with it

#

and now im starting to go into crsisi because im a stupid fucking failure

#

time to take a break

timid minnow
tight phoenix
#

if it was centered you'd have the same diamond as before

timid minnow
#

Cool, that does work

tight phoenix
#

just discovered a tiny bit of black broken texture in the corner of my mesh

karmic hatch
rare root
#

i have implemented normal map into my shader and now if it doesnt have a map on it kind of loses its smooth shading, to get rid of that i want to use the regular normals instead of from the map. but i dont know how i can switch between those when it has a map and not a map since it would be done differently
float3 N = normalize(i.normal); for without a map and
float3 N = mul( mtxTangToWorld, tangentSpaceNormal); for when i have a map
how can i change this?

clever saddle
#

how to make the black area of texture be transparent like in shader graph when writing a custom shader

distant sparrow
karmic hatch
timid minnow
#

Any obvious reason in Scene view, this tiles correctly based on Object scale... but in play mode it does not?

unkempt mist
#

How come I cant connect the Multiply output to the Vertex Normal?

karmic hatch
#

if so, I don't thin you need to do the tiling and offset bit, just use the UVs directly (they scale with the object)

karmic hatch
timid minnow
#

that's what scene view produces

unkempt mist
regal stag
unkempt mist
#

Oh, I guess that makes sense

regal stag
regal stag
# rare root i have implemented normal map into my shader and now if it doesnt have a map on ...

Usually the normal map texture property is set to "bump", which uses (0.5,0.5,1,0.5) if no texture is assigned.

_BumpMap("Normal Map", 2D) = "bump" {}

That should fix this, since after sampling & unpacking, that results in a tangentSpaceNormal of (0,0,1) - which is equal to the world space mesh normal.

Alternatively, you could also use a mutli_compile or shader_feature in the HLSL code to make the shader generate multiple variants.
#pragma shader_feature_local _NORMALMAP
Could then do

#ifdef _NORMALMAP
float3 N = mul( mtxTangToWorld, tangentSpaceNormal);
#else
float3 N = normalize(i.normal);
#end

But to actually enable the keyword when a texture is assigned you'd need to write a custom ShaderGUI, or could just use an additional property to add a toggle. e.g.

[Toggle(_NORMALMAP)] _NormalMapToggle ("Normal Mapping", Float) = 0
unkempt mist
#

Well, I got this far with my cross section shader, my problem now is that it shows things that are further back than Z0, and culling the back of the camera view will just mess up the effect. Is this the wrong approach to this effect or is there a way I can fix this?

timid minnow
grand jolt
#

When GPU-instancing, I'm guessing all the properties have to match to batch properly, but does that extend to textures that have been assigned?

For example, if I have a material for bricks, and one for wood. Both share identical properties except the textures assigned, would they batch together? or is it effectively 1 per material?

marble thunder
#

How do I use compute shaders? I wanted to reference this white noise generator compute shader.

dim yoke
grand jolt
dim yoke
#

It needs to be the same material reference, not same shader

grand jolt
#

ok, that makes sense

dim yoke
#

If you make exact copy of one material and assign them to two identical meshes, gpu instancing will not realize they are the same material even tho the properties are the same

marble thunder
#

Is it possible to utilize the same material more than once, but modify some property? e.g. color/hue/saturation?

grand jolt
#

I used MaterialPropertyBlocks to achieve that, if your referring to runtime changes @marble thunder

dim yoke
#

Srp batcher on the other hand requires only same shader (so can be any material with any properties if the shader is same)

dim yoke
grand jolt
#

my obsession with optimization sometimes yields results XD

dim yoke
#

If you want only best results, you should only use RenderMeshIndirect and pass all the arguments to the shader as buffers πŸ™‚ (only useful for huge amount of same objects, dont actually do that in every situation, could be useful to something like custom particle effects)

grand jolt
#

im dipping my toes into ECS so gonna try sub-scene everything, also just finished setting up Virtual Texturing, so hopefully that will give me plenty of FPS to play with

marble thunder
#

I'm curious about writing shader code here, which one would be more practical to read? The single line or blocks of code step by step in comment:

dim yoke
dim yoke
#

The order of operations isnt really that important as everyone can pretty quicly figure it out using the basic math rules

clever saddle
#

Is it possible to write a custom shader for portal effect?

marble thunder
#

Sure? You'd probably use RenderTexture better?

#

(The shader could be used to draw the portal rings)

clever saddle
#

How to turn the black area of texture into transparent?

dim yoke
clever saddle
#

I dont know much about Rendertexture...

marble thunder
clever saddle
#

I'm writting this portal effect in unlit shader.How to make the black side transparent?

dim yoke
marble thunder
#

Got it

#

you are on the right path.

#

You can make it a png

#

or just get the value of the red channel and assign to your opacity channel

dim yoke
clever saddle
dim yoke
#

Then you should be able to just set the fourth component of the float4/fixed4 you are returning at the end of the fragment function

clever saddle
dim yoke
#

Ah its surface shader

marble thunder
#
sampler2D _main_texture;
...
const float4 text = tex2D( _main_texture, i.uv );
text.a = text.r;
return text;
clever saddle
#

The last one is surface shader.I dont know how to set it.Cz it display on the scene but not in game view

#

The sec one is unlit shader.Which works well.But Idk how to set it black part transparent

dim yoke
#

And the unlit shader doesnt even have the Blend command

#

Nor does it have ZWrite off

clever saddle
#

There's a slightly background glitch

dim yoke
#

Nice!

clever saddle
#

I got another problem.I'm trying it(red one) in unlit shader.But it didnt visible itself,it just blend with other object

meager pelican
# grand jolt When GPU-instancing, I'm guessing all the properties have to match to batch prop...

It varies by pipeline.

That's what material-property-blocks are all about. But the SRP batcher deals with things differently than does BiRP. IDK about HDRP, but it's likely different than BiRP too.

So IDK what pipeline you're in, but a texture reference CAN be in a Material Property Block.
https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.SetTexture.html

BiRP instances by material...they all have to be the same material but the actual data can vary by the contents of the MPB. In SRP it instances by shader, and God help me I can't figure out why it doesn't use MBPs the same way, but it doesn't (mostly because you could have several materials for one shader, I guess). And there may be differences between hand-written SRP shaders, and SG versions.

grand jolt
meager pelican
# clever saddle Thx.That's a solution 2.It works

Might be depth clipping. Setting 0 alpha can be a problem. You have to make sure you're not writing to the depth buffer. (ZWrite Off) like @dim yoke said.

The other way to do it (and some worry about low-end mobile device capability/speed) is to use alpha clipping and discard pixels that don't pass some test. That way you don't update the depth buffer if you want to write to it.

craggy chasm
#

Hi guys I wanted to know how to make Single pass Instance work on shaders that I have made using the Shader graph.
Currently what happens is i can only see it from one eye and not the other. I have checked the gpu instancing on the material that uses these shader.

gray kelp
#

is it possible to get a gameobject by tag and gets itsposition in shadergraph??

kind juniper
#

Ah, it's the "Object" node

#

If you need access to a position of a different object, you'll need to pass it in as a property from c#

gray kelp
#

k

zenith heron
#

Hello, I am having an issue involving Custom Functions. My Custom Function is called SetPenColor, where I set a pen's color based on the 0-1 hsv value I give it. It involves converting the circle data from the Ellipse node to an hsv, altering the hue, and converting that back into an rgb for usage. However, whenever I drag the circle data onto the Custom Function, a strange error occurs where the Shader Compiler crashes. I was thinking it may have to do with my code, but I can't seem to find any more errors. I wanted to come here to ask for any advice on the matter. Thank you very much for your time.

kind juniper
#

Also, where do you define cMax3 function?

#

And cMin3

gray kelp
#

is there a global paramter that i can pass that will effect all materials using same shader??

zenith heron
#

oh right

#

the custom function code is in the same folder as my shader graph

kind juniper
zenith heron
#

wait should I perhaps delete that shader file on the very right?

#

I was just playing around with it another time

kind juniper
zenith heron
#

it..exists??

kind juniper
#

Although, I don't think that's the cause of the issue.

zenith heron
#

can it use multiple arguments?

#

like 3+

kind juniper
#

abs exists too

zenith heron
#

O:

kind juniper
#

But you can nest them: max(max(a, c), max(b, c)) or something

zenith heron
#

yeah!

kind juniper
#

Ah, your custom function definition is not correct.

#

You must not have a return type.

zenith heron
#

wait really

kind juniper
#

There are examples too.

zenith heron
#

so String allows me to just write the function there?

kind juniper
#

Yeah you can do it, but I think it's not a great practice.

zenith heron
#

what are these

kind juniper
#

That's just for including other files. If you want to use functions defined in different files.

#

Ah maybe not

#

Basically it's a preprocessor definition. I'm not sure what purpose it serves in this specific case. Might be just something they left there.

#

Maybe they toggle it off somewhere so that the function does not compile.πŸ€·β€β™‚οΈ

#

Or so that it doesn't compile twice.πŸ€”

regal stag
#

It's so if you use the include file in multiple Custom Function nodes it only compiles it once. Would cause redefitions otherwise

kind juniper
#

Ah, that makes sense.

regal stag
#

While learning how to use Custom Functions is useful, if you are trying to convert between RGB and HSV there is also a Colorspace Conversion node

zenith heron
#

O:

#

that would indeed save a lot of trouble

#

maybe clear the error hopefully

kind juniper
#

The error is probably due to wrong custom function syntax

zenith heron
regal stag
#

I also can't remember if you're allowed to use the [index] syntax on float4 to set values. I think it might only be read. May need to use .r or .x, .g or .y etc

regal stag
#

I could be wrong but I recall something like that

#

rgba / xyzw

zenith heron
#

yeah xyzw! i remember that

#

i remember thinking w came first too

#

and finding out

#

so

#

I'm setting the values of an argument apparently

#

that's bad right

kind juniper
kind juniper
# zenith heron

The last one is still using indexing. But I'd worry about only when you get the actual error.

zenith heron
#

alpha ranges from 0-1 right not 0-255 unless I'm wrong

regal stag
#

All components are 0-1 in the shader

zenith heron
#

.

zenith heron