#archived-shaders

1 messages · Page 177 of 1

fervent tinsel
#

I'd look for some shader grid examples or people asking about it

#

you'll typically see that kind of issue on those too if they are generated

low lichen
#

@grand jolt But I think derivatives is the solution there. That's what's used by the shader to determine what mip level gets used.

grand jolt
#

Sounds complicated 😓

low lichen
#

fwidth is pretty simple to use actually. You give it any scalar variable in the fragment shader (could be world position or uv or distance from camera, whatever) and it will tell you how different the value is in neighboring fragments

#

So in your case, if you give it UV, the value you get back for the pixels closer to the camera is going to be much smaller than the value of the pixels further away from the camera

#

Then you can pick some multiplier to add to that and use that to drive a lerp between what color the pixel is supposed to be and a blend between the two colors

#

Which is like a cheap blur in your case.

#

TLDR; fwidth can tell you how much you should blur the current fragment

brittle owl
#

Hi guys! I was wondering if there was a way to fade in and out objects in URP? I looked online and it seems like people recommend changing the MeshRenderer's alpha value, but it seems like there is no color property in URP's MeshRenderer. I'd appreciate any help.

low lichen
#

The default color property name in URP was changed to _BaseColor instead of _Color

brittle owl
#

o

#

So is it now hidden from the Inspector? Or was it always like that?

low lichen
#

MeshRenderer has never had a color property

#

You might be thinking of SpriteRenderer

brittle owl
#

Probably lol

#

thanks a lot

#

Wait just making sure, if i were to change that _BaseColor property, would it work outside the editor?

#

in builds?

low lichen
#

Sure

undone brook
#

I have a mesh and I'm trying to color its surface(everything that points directly upwards in object space) with a different color. I thought that this would work but the bottom is affected as well. I'm guessing it has to do with me having a misunderstanding about how normals work. Could somebody clarify?

regal stag
#

Looks like Comparison doesn't allow Vector3s as the yellow connections are being converted to blue/cyan ones

undone brook
#

Aw shit good spot

regal stag
#

Should probably Split and take the Y value only

undone brook
#

Thank you

low lichen
#

I would use a Dot node instead. Then you can pick your own threshold of what counts as pointing up

#

And you might be more interested in the world normal than the object normal

#

I can't imagine many normals being exactly equal to 0,1,0

undone brook
#

Top parts are flattened but yeah I'm sure I could be running into issues

regal stag
#

Yeah, I wouldn't use equal. Could test if the Y is greater than 0.9 or something

undone brook
#

I'm looking into dot product

low lichen
#

If you get the dot product of (0,1,0) and the normal, the value you get back will be 1 if they are equal, 0 if they are orthogonal and -1 if they are opposite

#

And everything in-between is in-between

undone brook
#

I see, that's really cool

#

its purpose is to see how "aligned" vectors are?

brittle owl
#

Think so, yea

low lichen
#

Dot product is used for many things in math, it just happens to have this property of being able to compare vectors.

undone brook
#

Thank you @low lichen & @regal stag

raw dock
regal stag
#

Nice! Yeah that's me, glad it helped

grand jolt
#

Heya I have a very important issue regarding billboarded sprites in VR. I have a plane with a shader that is billboarded to always face the camera, and it works just fine

#

However, whenever the camera rolls, the billboard will squish itself

#

This is a massive issue because I am making this shader for VR, and people always tilt their heads in VR

#

Here's an example of what I mean

#

No camera roll/tilt:

#

Camera roll/tilt:

#

I essentially need the billboard to ignore the camera's Z rotation

#

but I am unsure on how to accomplish this in the shader, I am using Amplify as well (which is very similar to shaderforge)

#

Any help would be massively appreciated

#

Any game that has billboarded grass or vegetation should also have this issue, so this is has to be a very common problem

solar sinew
#

Has anyone found a way to set the stencil buffer through shader graph? Could I use the custom function node for that?

regal stag
#

I don't think a custom function would work. The stencil is part of the Shaderlab syntax, not hlsl

fervent tinsel
#

do you need it for URP or HDRP?

solar sinew
#

URP

regal stag
#

You can override stencil values using the RenderObjects feature on the Forward Renderer if you are using URP

#

It only really filters per-layer though

solar sinew
#

yeah that's what I'm currently experiencing

#

It seems like this is the probably the best way to achieve a cross section effect:

I· Duplicate our model in the scene and apply a material with the first shader on first model and apply a material with the second shader on the second one. Make sure the two game objects have the same position and rotation.

II· Control the cross sectioning parameters (Plane position and normal) of two shaders through code, to do that we can create a quad/plane object in the scene and attach a simple script on it that map the plane normal and position to our two materials. The script might look like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//[ExecuteInEditMode]
public class CrossSectionPlane : MonoBehaviour
{
    public Material mat1, mat2;
    void Update()
    {
        mat1.SetVector("_PlanePosition", transform.position);
        mat1.SetVector("_PlaneNormal", transform.forward);
        mat2.SetVector("_PlanePosition", transform.position);
        mat2.SetVector("_PlaneNormal", transform.forward);
    }
}

source: https://codeburst.io/unity-cross-section-shader-using-shader-graph-31c3fed0fa4f

#

I wish I could avoid having duplicate objects in the scene

regal stag
#

I feel like the example they've used could just be combined into one shader using the plane as a mask, instead of clipping.

#

Oh but the top part is transparent I guess

solar sinew
regal stag
#

You wouldn't need duplicate objects though, you can actually just assign multiple materials to the same Mesh Renderer. Or use the RenderObjects feature with an Override Material.

grand jolt
#

No one knows the solution to my problem? 😭

solar sinew
#

@grand jolt what does your graph look like?

grand jolt
#

One sec lemme load it

hearty stump
#

@grand jolt in the shader when you get the plane to face the camera you should split that and ignore the Z axes

solar sinew
#

yeah I was gonna suggest split node

grand jolt
#

everything to the left is entirely for the visuals

#

(this is amplify)

#

Not sure if shadergraph has a billboard node

#

you can do operations on the node

#

Do you have to create the billboard logic in shadergraph or is there a node for it like in amplify?

solar sinew
#

https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Billboard

Billboards can be set through its Type either as Cylindrical where only the object X and Z axis are aligned with the camera ( useful when rendering trees ) or as Spherical where all axis are aligned.
Also, through the Ignore Rotation parameter an object's initial rotation can be either completely ignored and overridden, or it can be used as a delta rotation over the billboard final calculations.

grand jolt
#

Mhm I've checked this documentation already

#

The rotation has to be cylindrical

#

Whether ignore rotation is on or off, it will still cause the issue

solar sinew
#

Based on this node being unique I'm not sure if you can split it

grand jolt
#

Would breaking it into xyz components work or nah?

#

I was also possibly thinking that if I could just recreate the billboarding logic on my own, and then working off of that, that would work

#

i could even make a custom node

solar sinew
#

Yeah that was my thought - since what is controlling the vertex offset is a vector 3 - XYZ coordinate

hearty stump
#

it will work, amplify is not like shader graph it doesn't need a split node to get the child of a node

solar sinew
#

In Shadergraph I would do Split -> Combine output vector 3

grand jolt
#

I can break into XYZ

#

but im not sure if this will work

#

unless im using the wrong node

#

did you mean like this?

solar sinew
#

worth trying

grand jolt
#

no bueno

solar sinew
#

figures

grand jolt
#

Well the entirety of the billboard logic is based on the camera's inputs

#

so me changing the output of the billboard node probably wont work right?

#

I need to actually change how the billboard is reading in the camera inputs

#

to ignore its Z

solar sinew
#

can you override all of this in the camera

grand jolt
#

How would I?

#

you mean this cam?

#

that's my main cam for the scene

solar sinew
#

wait hold on

#

I have a plane with a shader that is billboarded to always face the camera, and it works just fine

#

Can you freeze the z rotation of the plane in the inspector?

grand jolt
#

Hm

#

Wouldnt that still have to be done in the shader?

solar sinew
#

I mean you could add a rotation constraint component

grand jolt
#

let's try it

#

like this you mean?

solar sinew
#

it constrains the child's rotation to that of it's parents

regal stag
#

I doubt any changes on the cpu side will help, since the shader is modifying the vertices on the gpu

grand jolt
#

yeah

#

this has to handled in the shader

regal stag
#

You likely need to look into handling the billboard yourself, I guess the built-in amplify node expects the camera not to roll?

grand jolt
#

This rotation constaint is more during runtime when you might have physics moving the object

#

It must expect the camera to not roll

#

but that seems odd

#

Camera roll in games is extremely common

#

especially in VR

#

I think I mentioned this earlier

#

any game that billboards grass or vegetation will have this EXACT issue

#

so im confused as to why this doesnt seem like a more common problem

#

the funny thing is that this issue can be solved in a particle system

#

there's an "Allow Roll" option in the render settings

#

right in the middle under Flip

hearty stump
#

when you used break to component node you have set the billboard to a vector3 and you set z = 0 but you didn't plug it in so it will take the default value from the rotation i assume that is what happening

solar sinew
#

it should take the value 0

#

right?

grand jolt
#

it should take 0

#

I already tested that too

#

if I put in 1 instead, it will just move the plane back

#

but the issue still persists

solar sinew
#

what if you made a subgraph for the billboard node - set that subgraph's output as a vector 3, then split and combine

#

?

#

not sure

#

did you see this stipulation listed on the documentation?

NOTE: Billboard node should only be connected to vertex ports.

grand jolt
#

by subgraph do you mean my own graph for billboarding?

#

Yes its connected to the vertex port

solar sinew
#

I'm not sure. Amplify is more different than I thought/has some interesting nodes

grand jolt
#

I think it's actually very similar to shadergraph

regal stag
#

I'm pretty sure they are using the node correctly, I'm guessing it just doesn't have proper support for camera rolling. It does seem odd, but must be an Amplify thing. I can't find much resources on it.

grand jolt
#

I can't either

solar sinew
#

Yeah I'm struggling to find much either

grand jolt
#

and I'm not sure why

#

it seems like something people would run into really quickly when doing anything VR related

regal stag
#

You could perhaps look into billboarding with a C# script (transform.LookAt kinda thing), instead of shader related

grand jolt
#

wouldnt that be a lot more performance taxing?

regal stag
#

Or try and handle the billboarding yourself. I've used this in shadergraph, but I don't think it will be much help for Amplify :

grand jolt
#

I'd prefer to do it in a shader ideally

#

Those nodes all exist in Amplify

#

they are just called different things

solar sinew
grand jolt
#

Yep

#

I'm using 2015 VS community edition and it's ass, doesn't load

#

so i need to get 2019 tonight

#

quick question, will 2019 vs community edition work with unity ver. 2018.4.20f1?

#

It's the version required to be used for VRChat

regal stag
#

Should mention, the billboard thing I posted above would go into the Vertex Position input on the master node in shader graph. But looking at Amplify, I think "Local Vertex Offset" is, well an offset, so I assume will be added to the original vertex position. I guess you might need to subtract the vertex position to account for that?

grand jolt
#

So I think what I will do is recreate the billboard effect in Amplify as a series of nodes, but I am going to take a break for now

#

I may be back later if I run into a wall again

#

do you mind if I @ you then?

regal stag
#

Don't know if I'll be much help with Amplify, but sure. Might also be offline, it's getting late here

grand jolt
#

So all that matters is the logic

#

you can usually perfect translate shadergraph to amplify

jade hinge
#

how would i deploy this random range node so that it only happens once a start?

undone brook
#

Is there any way to create height based fog on a lit graph? Can't think of a way not to have the faked fog be affected by lighting. I'm thinking of going the unlit way and implementing the light/shadows before the fog.

brittle owl
#

Hi guys! I was wondering if there was a way to fade in and out objects in URP? I looked online and it seems like people recommend changing the MeshRenderer's alpha value, but it seems like there is no color property in URP's MeshRenderer. I'd appreciate any help.
Okay so, using
obj.GetComponent<MeshRenderer>().material.GetColor("_BaseColor").a
and obj.GetComponent<MeshRenderer>().material.SetColor("_BaseColor", fadeColor)
seems to let me change the base color of my objects, but I had a question. First of all, does this change the material property for every object using this material? And also, I'm using an outline shader, and this transparency thing only works on objects set to "transparent" instead of opaque. When an object is set to transparent, it seems to show all the outlines that are normally hidden behind it. How do i go about fixing this?

summer shoal
#

Hi, does somebody know how I apply CullOff on HDRP Shaders?

rugged verge
#

Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Color ("_Color", Color) = (1,1,1,1)
_Distortion ("Distortion", Range(0,1)) = 0
_Alpha ("Alpha", Range (0,1)) = 1.0
_Speed ("Speed", Range (0,1)) = 1.0
...

For Shader properties:
Is there a type for "Float2" or do I have to have two separate properties for this (for X and Y coordinates)

rugged verge
#

shader code is so fascinating, once you get something to work, it feels lovely

#

I'm still a noob to shaders, but writing shaders is so beautiful

brittle owl
#

one day i’ll learn actual shader code lol

#

but for now it’s shader graph all the way

mossy night
#
        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            float3 localPos = mul(unity_WorldToObject, IN.worldPos);
            o.Albedo = sin(localPos.x*8);
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }

I can't figure out why float3 localPos = mul(unity_WorldToObject, IN.worldPos); won't give me the local position. The material on these two cubes using this shader should show the same black/white pattern if it was using local space, but instead it changes with the cube position, as if I was using world space.

#

multiplying by a constant matrix seems to work. Is unity_WorldToObject not filled in or something?

mossy night
#

I read that unity_WorldToObject doesn't work with dynamic batching, but I disabled that and it still doesn't work

mossy night
#

finally got it to work with a vert section

tall rampart
fair sleet
#

Can somebody tell me if I got this right?
In clip space the far plane is at z = -1 and the near plane is at z = 1

meager pelican
fair sleet
#

Let me get this straight
in OpenGL the z coordinate of the clip space is from 0(near plane) to 1(far plane)
in DirectX the z coordinate of the clip space is from -1(near plane) to 1(far plane)
This applies in the fragment shader, correct?
If you sample the depth texture and make it linear with Linear01Depth() it should always be from 0 to 1, right?

thick fulcrum
#

as I understand it using the linear01depth macro should give you that, while lineareyedepth is in "world space"

supple kiln
#

hello i m looking to do particle system with compute shader do you have any exemple to give?

teal breach
#

Is there a minimal template for a vertex/fragment shader in URP?

meager pelican
#

@supple kiln If you're doing it "for fun" and want to do it yourself, you "roll your own" however you want to do it. Any of the compute shader examples will get you started processing a buffer of some sort, then look up some form of procedural generation or billboarding to draw the particles at various locations. You'll want shader experience.
Or "for real" just use VFX Graph, that's what it's for. 2-cents.
@teal breach Maybe try going after URP source and just look at the unlit shader. It's on github, google is your friend.

teal breach
#

thanks CarpeFun

regal stag
#

Doesn't have shadowcaster or depthonly passes though. So won't support casting shadows or depth prepass (in order to appear in depth texture)

teal breach
#

still useful - I haven't written a shader for a few weeks and it's the macros/features I forget!

#

pragmas, etc

regal stag
#

That's why I prefer working with shadergraph 😄

#

Sometimes gotta use code though, if you want stencils, geometry shaders etc.

teal breach
#

exactly 😄

#

in my case, a custom pass

fair sleet
#

How can I convert a position in clip space back to world space in a fragment shader?
If I multiple the position with this matrix will I get the correct result?
Matrix4x4.Inverse(Camera.current.projectionMatrix)

regal stag
#

Why not just pass the world space position through to the fragment?

fair sleet
#

I can't.
This is a shader made with your Blit render feature.
I'm getting the position using the depth texture. I'm relatively certain this part works but I don't get the correct result so maybe I am multiplying by the wrong matrix?

regal stag
#

Using unity_CameraInvProjection and the _InverseView matrix property sent in via my Blit Render Feature (if the checkbox is ticked)

fair sleet
#

Is this a correct way to calculate the position? This runs in a frag shader

// screen color
float3 color = tex2D(_MainTex, i.uv);

//get linear depth
float linearDepth = Linear01Depth(tex2D(_CameraDepthTexture, i.uv));
if (linearDepth == 1)return color;

//calculate pos in clip space
float3 pos = i.vertex;
pos.z = (linearDepth)*2-1; // -1 is near plane, 1 is far plane for directx

//convert clip space to world space
pos = mul(_InverseView, pos);
regal stag
#

No idea really. Converting from clip space to world would likely include an inverse projection matrix as well as the inverse view though.

Like, Inverse Projection * Clip = View, Inverse View * View = World. Unless I'm mistaken.

#

That's basically what I'm doing in mine. The first part is the converting to view, which could likely be moved to the vertex shader to be more efficient, but can't do that in shadergraph. Then the second part is setting depth in view space (so it doesn't need to mess around with the clip space z differences I think?)

fair sleet
#

right,
how to I get this inverse projection matrix?

regal stag
#

I think just unity_CameraInvProjection. Seems to be a built-in thing. Might be somewhere in the URP library

fair sleet
#

I added pos = mul(unity_CameraInvProjection, pos); but it didn't work

regal stag
#

Might need to be a float4, with w=1. Idk. That's what I'm doing in my setup.

fair sleet
#

It didn't do anything, I think it assumes w=1 for float3

true steppe
#

Hey there! Is somebody familiar with Blender to Unity textures?

#

Because I just baked a texture in blender, and it works just fine there, but in unity its messed up.

solar sinew
#

@regal stag #archived-shaders message

I’ve only just realized that what he is doing via script is flipping the normal of the clipping plane only where the two objects intersect. facepalm

How could I set it up so the clipping object would display a different material depending on what object it was intersecting?

I saw you mention the render objects feature with an override material or just having multiple materials on the mesh renderer - but which mesh renderer? The clipping object right? Not the object being clipped?

Would I need to UV map for multiple textures/materials based on the object being intersected/clipped somehow?

Thanks for all your help on this. It’s been surprisingly more complex than I thought and very interesting.

crisp stream
#

@true steppe what do you mean? Do you have some screenshots of it?

regal stag
#

@solar sinew Not too sure what you mean by "clipping object". If you mean the object with this CrossSectionPlane script then no. I think that's likely just an empty gameobject with the transform to show where the clip will take place and send the position + forward vector into the shader. It could have a visible plane mesh, but that isn't important, just for visualisation purposes afaik.

In the tutorial example you linked, they have a heart and a hologram version. I think they have it set up as two gameobjects, but since they are the same transform and mesh, it could just be two materials on the same MeshRenderer.

solar sinew
#

Ah okay - one thing I was wondering is what I would need to change in the graph/script to use a sphere rather than a plane. Should I use a vector4 to control the sphere’s radius as well? Or because I would be modifying position transform the property should stay a vector3?

regal stag
#

For clipping based on a sphere you'd need a vector4 yeah, xyz being the position and w being radius. I guess you could also use a vector3 and vector1, but it makes sense to pack them together in the same property. Can always split it in the graph later.

solar sinew
#

After I achieve the cross-section visual effect I’m going to integrate this shader with my camera system; setting the sphere’s position based on a raycast from the camera. In that case should the raycast from the camera be a vector4?

regal stag
#

When setting it in C# you do something like material.SetVector("_Sphere", new Vector4(raycastPos.x, raycastPos.y, raycastPos.z, radius));

solar sinew
#

Got it 👍

#

Would the sphere’s normal also be a vector4?

#

Probably not

regal stag
#

You wouldn't need a normal for the sphere

solar sinew
#

Oh right

regal stag
#

The normal is needed for the plane since in order to define a plane it needs a point and normal to determine it's direction. A sphere just needs the point and radius.

#

Unless you want to also be able to say, clip inside sphere vs clip outside sphere, that could be an additional vector1 to send in.

#

In terms of getting a sphere to clip in the shader, you'd use a Distance node with this sphere xyz, and world space Position. Then Step with the radius. That could be used as the alpha input with a alpha clip threshold of 0.5.

solar sinew
#

I want to be able to clip inside the sphere - and make the object being cut appear to have thickness rather than just a hollow object. (I don’t know why I initially said hole in the mesh)

I was asking about whether I needed a sphere normal because I would want to flip the parts of the sphere (display the backface) intersecting my wall object to make it appear to the player that they are viewing the wall’s interior

regal stag
#

Right, you want an actual surface where the intersection takes place. That's a much more complicated effect.

For the plane it's fairly common to have back faces enabled on the mesh so that when the plane clips it, it makes those backfaces visible. They won't be lit correctly since the normals of those faces won't point in the right direction. I guess you could set the normal of the back faces to the _PlaneNormal sent in though.

For a sphere, I'd need to test it. I'm a bit unsure how you'd calculate it off the top of my head

solar sinew
#

Yeah I’ve been trying to figure it out - most tutorials examples use a plane. I have seen examples where they’ve used a cube (three intersecting faces) but a sphere is more complicated

regal stag
#

Also, for texturing the plane one - Remy has done a graph that does that, I think using a matrix sent in. #archived-shaders message

solar sinew
#

Ooo

regal stag
#

Hm or maybe it wasn't a matrix looking at the script. Maybe the matrix was constructed in the graph? I seem to remember a matrix being involved when I looked at it, but I might be misremembering.

#

Might be easier to do it with stencils rather than culling (don't have to mess around with faking surfaces (including normals/uvs) with back face geometry, as there's a real sphere being drawn, just stencilled out a bit)

solar sinew
#

My initial approach used stencils. The method I was using had two render objects features - one for a mask layer, and another for a see-through layer.

One concern I had is that because my player can pivot the camera around the house (think animal crossing house camera behavior), I would need to be changing what layer the closest walls were on whenever the player rotates the camera. Otherwise the sphere just acts as a mask for the closest wall and the furthest wall

regal stag
#

Oh right, the stencil approach might not work for that use case. It's kind of a fake effect as the scene is rendered completely normally, just overlaying part of the sphere cut out where it would intersect. It wouldn't actually remove the geometry allowing you to see through the walls. :\

#

Personally I think the culling approach is fine with a flat colour, but I guess it depends on the art style too

solar sinew
#

We have a more toon-look so I was imagining the interior of the walls either being a flat color or very simple texture

#

Yeah I’m thinking using the sphere as a culling object is the way to go. Going to work on this sphere math now

hearty aurora
#

anyone good with shaders?

#

i have a problem i cant seem to fix

low lichen
#

Just ask the question and if someone has any idea and has the time to answer, they will

#

I'm sure you've done this before

hearty aurora
#

so i have a shader for the particles mats, so i have a mat with the shader then i give it a texture and then i give the mat to particle and the particles become invisible

low lichen
#

What shader is it?

hearty aurora
#

its a unlit shader graph

compact pine
#

how to make mobile friendly refraction? I'm still kinda new to shader programming

#

and shader graphs seem like something that's performance heavy

hearty aurora
#

mentall NVm i fixed it

low lichen
#

@compact pine The only way to do a mobile friendly refraction is if the thing being refracted is pre-baked

#

Like a baked reflection probe

compact pine
#

if I understand correctly I need to know the exact texture for that?

low lichen
#

Know the exact texture? I don't follow

compact pine
#

ok sorry. so my game generates its map

#

can I still use this?

#

I guess I don't really understand what baking means here

low lichen
#

I mean what you're refracting isn't what's actually behind the thing

#

Because the thing that makes refraction costly is getting that texture of what's behind an object

#

Especially on mobile

#

What do you want this refraction for?

compact pine
#

making an ice map

#

And it's just a visual effect. Can probably do it without refraction.

#

so like it needs to refract obstacles

low lichen
#

Sounds like there's no way to bake it

#

An example of something you could bake is if it's a static scene with one window in a static place. Nothing is going to change behind that window, so you might as well make it a pre-made texture rather than dynamically fetching it every frame

#

But since your map sounds like it's procedurally generated, that's not an option

compact pine
#

well thanks anyways. can try to fake it with textures I guess

shrewd mist
#

Is it possible to make a transparent lit urp shader throw a shadow?

brittle owl
#

for some reason, blit refuses to show up as a render feature all of a sudden

#

it was working fine earlier today

#

upon opening my project, i recieve this error in my renderfeature asset, and i notice that none of the custom render features show up

#

oh, it seems like it broke because i had script errors on an unrelated script, weird

fast skiff
#

Hi, I know there was a way to get copies of unity built-in shaders in your project, but don't remember how this worked.

sonic bear
#

I have never touched actual shader code before, so i have no idea why this error is occuring

#

I miss the shader graph

#

I thought i had declared it

pastel loom
#

where was it declared?

sonic bear
pastel loom
#

but it doesnt look like its a known part of the shader itself

sonic bear
#

what?

pastel loom
#

i might be wrong, as im pretty new to shader stuff tbh-

sonic bear
#

Well you see i have pretty much no idea as i would just use shader graph
but being i have to use unity 2017.x
that doesnt exist

pastel loom
sonic bear
pastel loom
#

ahh

#

sorry for not really helping- i dont know like, anything about shaders

sonic bear
#

and look at that, here i was thinking that making proceedrual terrain in unity 2017.x would be a nightmare...
I was only half right!

pastel loom
#

whaa- thats so confusing

sonic bear
#

Basically it's just plopped into the middle of a terrain object as i am too lazy to make it so that the character spawns on top of it, so they clip

pastel loom
#

maybe use raycasts to check where the player could spawn without clipping?

sonic bear
#

No i know how, it's just currently i have done a ton and that is something for another day

pastel loom
#

ah

tranquil cipher
#

Hi folks, i can render the opaque texture and the depth texture to 2 planes as u can see.
what next is i want to exclude the 2 plane from those textures, so in the 2 planes only the scene ground plane and the cat girl is visible. Is there a way to achieve this ?

cosmic prairie
#

render the planes as transparent and zwrite off would be the simplest way

topaz oriole
#

When I press ''Show in explorer'' it shows this

paper anchor
#

@paper anchor I had the same issue and couldn't solve it. Switched to blitting to the texture array instead.
@low lichen I'm sorry but I am not sure how I could exchange my system with a blit... because I need the compute shader to have access to the whole array of RenderTextures at runtime, since each thread independently picks one of the slices to draw on based on other input info... maybe you mean blitting to a Texture2DArray? Would that work on Android? But if I have like 20+ rendertexture slices in the rendertexture array then I expect the overhead to be massive since I do this each frame...

rugged verge
#

Any tips to make an outer glow shader without Shader Graph without bloom? I want to use ".shader" coding. One way I thought of is just doing Gaussian blur, but there might be a better way.

low lichen
#

@paper anchor You mind if I ask what you need 20+ slices for?

sleek granite
#

If you have the distance function for the shape you want to add a glow to, you can just resize that slightly, make the edges a bit soft & add color to it

odd oriole
#

I'm trying to use a depth mask in URP, but instead of seeing the background on the GO with the mask I get gray. Do you have any idea what that is?

shrewd mist
#

Is it possible to make a transparent lit urp shader cast a shadow?

hearty stump
#

@shrewd mist yes it is possible but it won't be an lit shader any more since the lit and Unlit are the ones you should use if you want to make the performance shader fro mobile

shrewd mist
#

I'm not planning to ship to mobile

#

So how can I do it?

primal eagle
#

so you cant do a lit shader?

#

i had an unlit shader for a while and pushed it to its limit but then i realized lit is 10x easier

shrewd mist
#

I was just asking whether it's possible to make the standard urp lit shader cast a shadow

#

But if that is not possible, is it possible to write your own shader for urp that does that?

primal eagle
#

oh

shrewd mist
#

With the surface type transparent

primal eagle
#

ohh

hearty stump
#

@shrewd mist in shader graph i have no idea how to turn the lit master node to cast shadows.

#

but for the shader code you need to calculate it and add the cast shadow attribute in the shader pass

shrewd mist
#

Alright, looks like I have to get into shader programming then x)

#

I thought I can maybe avoid it since it's kind of a big topic

hearty stump
#

you can just use the PBR master node since you are looking for shadows

fast skiff
#

Hey, does anyone remember, where you can find Unitys built-in shader scripts? like "Mobile/Bumped Diffuse" or just "Standard" - so can do a copy of the .shader file and put it in my project?

low lichen
storm sparrow
#

GUYS anyone else noticed that we cant change the colors in shader graphs in latest LTS version 2019.4.13
we cant change the color in properties or the albedo or emmison or basically anything that requicres the color pocker box in shader graphs

#

Pls tell me how to fix this if i am wrong

fervent tinsel
#

@low lichen @fast skiff https://unity3d.com/get-unity/download/archive click on the "Downloads (Win)" or "Downloads (Mac)", you'll find built-in shaders for every single Unity release here (except for alphas and betas which has similar link on the specific alpha/beta download page)

#

no need to go for unofficial 3rd party repos for this

fast skiff
#

@fervent tinsel thank you, but wasn't there a folder (that came with unity) where i can get shader duplicates from?

#

or did that change after Unity 2017?

fervent tinsel
#

@fast skiff I've never heard of such thing, afaik it's always been like this with Unity

#

you refer to the decompiled c# code repo now?

#

if so, that's a totally different

topaz oriole
#

Is there a way for me to edit the material in Photoshop? It is a Microsoft Acces file

#

It's a file from the Assets store

regal stag
#

It's not a Microsoft access file, it's just they probably use the .mat file extension for something too and it's assuming that's what it should be opened with. In this case unity's material files can be opened with a text editor - but since you are referring to Photoshop you probably want to open the textures (probably .pngs or something), not the material file.

fast skiff
#

@fervent tinsel can't remember exactly. i created a shader for seasonal textures with Unity 2017 and got copies of different regular shaders to "upgrade" them to be seasonal too.

#

like "Mobile/Bumped Diffuse", etc. made a "Seasonal/Mobile Bumped Diffuse" from the copy.

#

AFAIR they where stored in some library folders of unity and someone back then told me where to find and how to get the copy in my project for modification.
But I can't remember how it worked exaclty. Maybe it really was downloads? have to check your link @fervent tinsel

topaz oriole
#

@regal stag Thanks very much, I was looking for the textures indeed haha. Stupid of me

fast skiff
#

point is: just need a triplanar shader with normal map support. I have a regular one (only diffuse), so i need to look up how the "Standard" or any other of the regular shaders is scripted correctly, then I can add the normal maps myself to the .shader script.
Don't need HDRP/URP yet, working on the basic code. So no ShaderGraph, just want that script updated by myself, as I can't calculate correct UV-values for procedural meshes.

meager pelican
#

Alright, looks like I have to get into shader programming then x)
@shrewd mist
Shadows on transparent objects have been a problem in all pipelines, but with URP it's "new" and not well documented yet. For your web searches, what you're looking for is a "ShadowCaster" pass. What it does is render the object again, with a simple depth shader, using the light source as the camera position, into a shadow map. But transparent pixels are hard to handle, as you say, you'll have to customize the pass. And you're not going to get "greyscale" shadows. What you end up with is just the object depth value from the light's perspective, not any intensity of light. Google is your friend.

shrewd mist
#

Thanks CarpeFunSoftware!
I'll try my best, this seems to be a hard one

#

So, when I want to create a regular shader graph I use "Create > Shader > PBR Graph", right?

meager pelican
#

If you want PBR lighting, yep. :)

You can then "view source" and go from there, edit it if you want.

shrewd mist
#

I will try to recreate the regular lit shader and then add what you mentioned

regal stag
#

I think the PBR graph will automatically have shadows with transparent surface too, so just need to replicate the textures and stuff

shrewd mist
#

@regal stag That would be great!

meager pelican
#

SG is a code generator. So you can see what it outputs.
Yeah, like Cyan said, it will already have a pass that you "just" need to customize

shrewd mist
#

@meager pelican Where's the "view source" you were talking about?
I completed my regular transparent lit shader, but where is an option to see the code?

hearty stump
#

@shrewd mist right click on the master node in SG and click on generate code

shrewd mist
#

Ah great, that works!
And now I just edit that?

#

Ah no, I probably have to save it to somewhere

grand jolt
#

Anyone know if theres a particular channel I should be outputting specifically for coat masks?

shrewd mist
#

Weird, I just noticed that that my shader graph shader doesn't even cast a shadow when it's opaque

low lichen
#

@grand jolt What is a coat mask?

#

😷
🧥

zenith meteor
#

Hey people i am in a huge pickle i want to make a terrain mesh blend shader but for the love of me no one made any online on hdrp or urp on shader graph does anyone of you have ANY pointers on this?

shrewd mist
#

Okay, great thanks to @hearty stump , @meager pelican and @regal stag , even though in the end I solved my problem in a different way entirely :D

river jasper
#

Question: Anyone here, knows a Unity "Default" Shader, with all possibilitys ( indeed: important are: Smoothness, Second Albedo + Second Normal Map )

What can fade 2 textures ?

#

( Height, Occulusion and other are not important, but second albedo / most important: 2 Albedo Textures, and 2x Second Normal Map ).

amber saffron
#

@river jasper The unity default shader does what you're asking for ... Or is it for URP maybe ?

river jasper
#

no, i need to change 2 textures in Runtime.
now: i got Shaders for changing Albedo 1 to Albedo 2.
Also i got a Shader, can change from Albedo 1, to Albedo 2, or 1 to 3 and so one.

but following Problems:

    • none of this shaders, have a smoothness,
    • none of this Shaders, have a second Albedo or a Normal Map option.
#

They change the Texture in Runtime - okay. But the 2th Normal Map, cant be addet.
Also there is no Option, to add a first Normal Map.

i hope you understand, me is german is a little hard sometimes to explain such things in english 🙂

amber saffron
#

Is it for doing a "smooth" change ? or a pure texture swap ?

river jasper
#

yeah.

#

smooth, in runtime.

#

if i just want to change the Texture in 1 hit, i can change the material, this is no problem.

#

so for example: if i want to change the "Material" - no problem.
if i want to change the Texture of the Material - no problem.
but this all is a "Switch" / "Swap".
i need this smooth, with 2 overlapping textures 🙂

amber saffron
#

By smooth I meant "the base texture should gradually change to the 2nd texture in a certain amount of time" VS "the base texture changes to the 2nd texture in one frame"

river jasper
#

yes, take a moment, i write you a PN 🙂

amber saffron
#

No PM please if this can be answered here

thick fulcrum
#

fun in shader graph, I've got a shader setup which was using camera depth (for a water shader). Got some nice displacement going, normals etc. all setup, using camera depth to reduce displacement near to shoreline.
That all works, but then I decided to swap to a baked depth texture due to obvious limitations / quirks of cam depth.

It works up to a point, I can either do vertex displacement or the surface color. BUT not both together, which I'm assuming is because I'm sampling the texture in both fragments but I'm making sure the sampling is separate (or appears so in the graph). Which worked when i was using _CameraDepthTexture but not now I'm using my own.
Is this a bug or am I perhaps overlooking something?

meager pelican
#

You can't "bake" a cameraDepthTexture if the camera moves. It's relative to the camera pos. But you can compute depth based on camera pos and world-pos distance. Or I'm not following.

thick fulcrum
#

hard to explain... the depth aspect works fine, I've just swapped from using the _CameraDepthTexture to a static baked depth texture. Which I have setup, gets world position etc all aligned.

Problem is I can either use it in vertex displacement OR when I'm adjusting colors... not both as I could when using _CameraDepthTexture
If that makes it any clearer

meager pelican
#

So depth is Y depth from water? Or you want to know how to calc that?

#

There's the water-depth, and then there's the "camera scene depth regardless of water".

#

And figuring out what your "camera view ray" is going through is a bit tricky.

#

In the former, you know the pixel world-space pos and you know the "bed" worldspace depth from the plane, so you can add/subtract that all up to get the Y depth.

#

But your view ray is going through a stuff at an angle.

#

😉

thick fulcrum
#

no everything "works" just not together, I will do a simplified shader which will hopefully explain the problem or it will work and I'm barking up wrong tree 😄

fast skiff
#

@river jasper did something like this for seasonal textures in unity 2017 - maybe it still works? but not sure, if they had normal maps

river jasper
#

Short:

VERY THANK YOU TO REMY HELPS ME OUT

Thank you, this is one of the Reasons, i love unity so much. Most of us, stand together!

fast skiff
#

@river jasper sorry it is only for Diffuse channel.
If you know how to get copies of the included unity shaders, you could maybe modify it, so it can blend with normal textures too

#

@river jasper Do you want that shaders?

river jasper
#

All Problems solved, but very thank you 🙂 Remy help me out.

#

Works perfect 🙂

fast skiff
#

ok, fine 👌

#

@fervent tinsel You where right! it was always needed to download them. Thank you!

hearty aurora
#

hello aynone here?

#

can someone help me, i cant really explain my problem btu i can show you

#

please tag me

devout quarry
#

In URP 10 I get an issue with "#if SHADERGRAPH_PREVIEW", the error I get is: "invalid conditional expression" anybody know how to fix this?

regal stag
#

Is it any different if you use #ifdef instead of #if?

devout quarry
#

yup, just tried that and it's fixed

#

thanks

karmic delta
#

Can you add emission to vertex/fragment shaders? Or only surface shaders?

solar sinew
#

I thought I answered this question for myself a while ago but the more and more tutorials and write ups I look at the more confused I am.

Is a sphere's normal vector a vector 3 or a vector 4?

jade hinge
#

a normal is a line that is perpendicular to a surface

#

a sphere as infinite hypothetical normals

#

that said, normals are negerally v3's

honest bison
#

Need some help with a vertex fragment shader

low lichen
#

@karmic delta Emission is just a color that you add at the end after you've calculated your lit Albedo color

#

half4 finalColor = half4(litDiffuse.rgb + emission, alpha);

#

@honest bison Ask away

honest bison
#

I've got a bunch of lighting and reflection to bring together and I am not sure how to do it.

#

I have diffuse light, specular reflection, fresnel in the vertex program, which I am sending to the fragment. In the fragment I am sampling albedo and metallic/roughness. the roughness is being used in a texCUBElod. I know about all these things, but just not how to bring them together in a meaningful way.

#

I am trying to make a cheap PBR type material.

#

Doing most of the calculation in the vertex program.

#

No normals.

low lichen
#

Specular highlights and fresnel are similar to emission, just added to the diffuse light at the end

honest bison
#

Single light.

#

I have added them all together - but then when I add with the albedo its too bright.

low lichen
#

Which part is making it too bright? The fresnel?

honest bison
#

That is the vertex lighting

grand jolt
#

Alright who here has a big brain and could help me out 😛

#

I've run into a sort of math issue

low lichen
#

@honest bison That's just the diffuse light or also the specular and fresnel?

grand jolt
#

I need to convert a directional vector into a euler angle

low lichen
#

@grand jolt In a shader?

grand jolt
#

Mhm

low lichen
#

What do you need euler angles for in a shader?

grand jolt
#

I'm currently in Amplify

#

I am making a shader that makes a mesh always face the camera's position

#

and no I don't mean billboarding

honest bison
#

That is the lambert, phong, and fresnel

grand jolt
#

it's essentially a LookAt but in the shader

#

But this could also theoretically look at a player or another object's position if I wanted to

#

but that isn't the goal

#

So far I've created a directional vector by taking the world space camera pos subtracted from the object's world space pos and normalized it

#

I have a rotate about axis node that takes in a rotation axis (currently 0, 1, 0) an angle, a pivot, and vert positions

low lichen
#

Using Euler angles in a shader makes little sense to me. It's just a human friendly format for rotation, while Quaternions is what Unity actually uses internally

grand jolt
#

Sorry maybe I am messing up my terminology

#

Just for clarification

#

if I plugged in a time node into the rotation

#

it would look like this

#

(i put the shader on a simple cube)

#

Anyways

low lichen
#

Do you just want to rotate it on that axis?

grand jolt
#

yep

low lichen
#

Not all axis?

grand jolt
#

correct

#

otherwise i'd just billboard

low lichen
#

Then you just need to calculate the angle needed to get the right rotation

grand jolt
#

so basically i just need the angle to be that which always matches towards the camera

#

yep

#

that's the part im stuck on

low lichen
#

And this is basically in 2D because it's only on that one axis, so you should be able to use Atan2 to calculate the angle

grand jolt
#

Im pretty sure this is important

#

but the input for rotation angle on that node doesnt seem to be between 0 and 360

low lichen
#

It's probably in radians

grand jolt
#

maybe

low lichen
#

Which Atan2 returns

grand jolt
#

im about to test

#

yea it has to be

#

because 6.28319 seems to be a full 360

#

so how do I use atan2 to get the angle i want?

low lichen
#

Don't need the * Mathf.Rad2Deg, though

grand jolt
#

oh yeah im on the amplify wiki as well

#

i see it

#

I'm just not understanding how to actually calculate the angle, whether its degrees or radians

#

all I have is a directional vector based on the camera and object's world pos

low lichen
#

In this case, you would probably give it the X and Z of the direction

grand jolt
#

of that vector?

#

Fuck me, you're right

#

I don't care about the shading because it's going on unlit shaders

#

What are the chances you've ever played VRchat or worked with VR in Unity?

#

I don't know if you care, but I can tell you why I am doing this

low lichen
#

100%

grand jolt
#

VRchat?

low lichen
#

I've played it and messed with the SDK

grand jolt
#

if you've ever played in VR, you might have noticed how bad particles and billboarding is

#

it just fucks up wildly

#

and I've been asking around a bunch of discords trying to find a solution and no one knows

#

in VRC if you rotation your head left and right, billboarded sprites will just wobble left and right as well

#

which makes no sense

#

and its even worse if you tilt your head

#

Like here's a light shaft that's billboarded right?

#

If you tilt your head in game

#

it squishes

low lichen
#

Makes sense now why you want to do this in a shader rather than in script, since you can't use scripts

grand jolt
#

👍

#

exactly

#

Anyways

#

I was showering and I was just thinking

#

why not, instead of having the quads face the cameras view

#

just have the quads face towards the cameras position

#

I went to a bunch of worlds as well just to make sure I wasnt the only one with this issue

#

alot of big worlds also have this exact problem

#

and I think this will fix it

#

This new shader isnt affected by camera roll, or the angle you face your camera at all

#

it just looks at the camera's position

low lichen
#

Particles have a billboard facing mode that does the same thing

grand jolt
#

Really?

low lichen
#

Not sure if it also ignores camera tilt

grand jolt
#

Tried looking for that

#

Particles have an "Allow roll" option

#

that you can take off

low lichen
grand jolt
#

Huh

#

Where is that O.o

#

Im in a particle system right now

low lichen
#

In the Renderer part of the particle system

grand jolt
#

not seeing it

#

I might be blind

#

oh

#

i see it

#

you have to be specifically in billboard

low lichen
grand jolt
#

you've been extremely useful

#

Now I have to test it in desktop, and then in vr

#

to see if it truly works

mild nebula
#

Hi! I'm new on Shader Graph, and I already have an issue. I can't edit the color of a Color Node. When I click on the black area, nothing happens, the color window does'nt open..
Any idea of what happening, and how solve it ?
Thanks

supple kiln
#

Hello,

I want to do a unity particle system with computer shader.
When i click with my mouse on the scene i do particle.

At this time when i click on the scene nothing happen and my mouse position is always 0,0.

Here is my code : https://hatebin.com/jgkwwgrqqq

Description of what i want :

  1. Get the position of the mouse in the OnGUI () function, use the Camera.ScreenToWorldPoint () function to convert the screen coordinates of the mouse into world coordinates.

  2. In a Compute Shader, animate the particles using the pseudo-random number generation formulas described here http://www.reedbeta.com/blog/quick-and-easy-gpurandom-numbers-in-d3d11 /, generate a random position (3 float-s) for the particles.

  3. Optionally apply physical parameters (gravity, etc.) passed via a Constant Buffer.


  1. In the OnRender () function use the DrawProcedural () function to draw the particles as points.

  2. In the Vertex Shader, we must then index our StructuredBuffer of articules using a parameter of the main function with the semantic “SV_InstanceID”.

  3. Rather than displaying a single point, we add a Geometry Shader to generate a square of the size specified via the Constant Buffer.

  4. Use the “life” of the particles as a transparency factor. Use additive blending - Blend one, oneMinusSrcAlpha.
    For the rendering to be correct, we will pre-multiply the RGB components by the Alpha in order to make the composition of the colors independent (no need to sort the particles).

amber saffron
#

What's the question here ?

supple kiln
#

At this time when i click on the scene nothing happen and my mouse position is always 0,0.

amber saffron
#
Vector2 mousePos = new Vector2();
Debug.Log(mousePos);

This will likely always log 0,0

#

Mouse position for event is only valid if Used in EventType.MouseMove and EventType.MouseDrag events.

stoic zenith
#

RTFM

supple kiln
#

but my main issue was when i click none particle spawning.

amber saffron
#

I think we should move this discussion to an other thread, as it's not purely shader related, maybe #archived-code-general ?

keen scaffold
#

Anybody know what's causing the above error? ^

#

I've had nothing but trouble since upgrading to Unity 2020. VS keeps un-attaching, keeps saying files are missing, etc. The main thing is that I can't use a bunch of nodes in ShaderGraph any more. Anyone get any idea what might be producing this error? Can't find anything helpful anywhere on Google

amber saffron
#

I've never seen this before.
Aside from upgrading the editor version, did you check that the packages version are also upgraded and updated to latest available ones in the package manager UI ?

keen scaffold
#

Yep, running the latest URP and Shadergraph and Unity version 😢

#

The strangest thing is, previous shaders I've made in SG work fine - the nodes don't show this behaviour

#

So adding in a multiply or subtraction node into an old shadergraph works fine

regal stag
#

Is it maybe something to do with the "Offset" property? Might not like that reference

keen scaffold
#

Please ignore my stupidity 😂

#

It was in fact me changing the reference names

#

If anyone ever has the same issue, it's just general noobishness

grand jolt
#

yeah your offset property ID cant be the same as it's inspector name

#

so itll need to be _Offset

regal stag
#

I'd assume the problem was more that "Offset" is used as something else in the shaderlab syntax so it didn't like it, but could be wrong. I'm sure the inspector name and reference can still be the same.

normal shuttle
#

Hi, in a post-processing shader - when is Vert function called? Four times for entire screen since it is a quad? Shader newbie here, sorry for the dumb question.

regal stag
#

Yeah, usually a fullscreen quad so four times. In some cases I think a single large triangle can be used instead but don't really know if there's any advantages of that over a quad.

normal shuttle
#

@regal stag Thanks 🙂

undone brook
#

What's involved behind rotating a gradient? I have a vertical gradient I'd like to pimp up a bit. Right now it draws the gradient based on screen pos, vertically. I'd like to draw it from bot left corner to top right.

#

Ok I'm going to attempt (x + y) / (screen width + screen height) as t, does that seem to make any sense?

regal stag
#

I think you just need (x + y) * 0.5 for a diagonal gradient. Assuming the screenPos/uv is in the 0-1 range.

undone brook
#

I'll give it a shot and report back

#

@regal stag Yeah that works flawlessly. Thank you 🙂

meager pelican
#

Probably 6 times, 2 triangles, unless it's a triangle strip. Interesting question, and might be implementation specific, would enjoy discussing.

#

I should test it but I'm being lazy.

regal stag
#

Oh yeah, that makes sense. I assumed 4 since it's a quad but it is probably 6

meager pelican
#

Yeah, usually a fullscreen quad so four times. In some cases I think a single large triangle can be used instead but don't really know if there's any advantages of that over a quad.
@regal stag three verts, and no 'seam' in the middle that could give you iffy stuff with floating point.
Performance impact/savings is minimal.

#

With a quad, it might be a triangle strip. So the GPU has the previous two points, it switches them around, and adds a "third" (the fourth of the quad) point for the 2nd triangle.
But I'm not tech enough to know if the GPU caches the results of the previous two verts, or if it just recomputes them.

solar sinew
#

Topic: Sphere Cross-section with a wall
@regal stag I've been looking at @amber saffron's graph that you previously linked: #archived-shaders message

I'm still trying to wrap my head around how to approach it with a sphere. I'm looking at his subgraph for texturing the intersection area and replaced the plane position vector3 node with my vector4 _SpherePosition node. but I'm struggling to figure out what changes need to be done for other aspects of the graph like the tangent vector

low lichen
#

I've heard that a fullscreen triangle is an improvement over quad on mobile tiled renderers because when the renderer is determining what triangles are in what tiles, both triangles from the quad will be counted in the diagonal seam instead of there being one triangle in every tile.

meager pelican
#

Yeah, the seam can have "duplicate processing" in it. OTOH, those that have run tests, and I think it was on mobile and reported here, said they didn't see any significant difference.

I like FST's. But...the vert() functions are different, because you have to fix up the UV's for the resulting points since the original ones are way off the top and right of the screen.

amber saffron
#

@solar sinew Using a vector4 input for sphere position and radius I guess ?
If you plan to generate world space "UVs" from this, it can be enough.
The normal is obviously a radius of the sphere. You could than estimate a tangent by using Normal cross World UP, and the bitangent with Normal cross Tangent.
As for UV coordinates, that's "simple" trigonometry by calculating two angles formed by the pixel position, sphere center, and a defined origin vector

exotic pilot
#

Hey I got a bit of a shader code problem, and I dont really know how to fix it
Im working on character creation for a game Im working on, and the shader I was using for the skin color used the "color" option for the overall hue of the texture

#

Im now using a different shader, and it uses "Main Color" instead of just "Color"

#

and here's a bit of the code from my character creator that deals with changing the hue of the skintone

#

I have no clue how to switch it over to use "Main Color" instead, even looking it up and trying mostly everything out there on google I haven't found much of a concrete solution

#

I tried tackling the issue from the otherside by changing the shader itself I was using to use "Color" instead of "Main Color", but Im not super well versed in shader programming

honest bison
#

I've written a vertex fragment that looks right in a test scene, but then in my game scene the vertex lighting doesn't seem to be working - just comes in as grey. Any ideas what I am missing?

solar sinew
#

@amber saffron sorry but what do you mean by World UP? Just a direction vector increasing along the y axis?

honest bison
#

Alright, some progress. The lighting in the shader I wrote looks fine in unbaked scenes - but no lighting in baked scenes....

#

Still not sure how to overcome this.

honest bison
#

Alright, just switch light to mixed and bake again.

#

Thanks for the help!

amber saffron
#

@solar sinew Yes, that's what I meant. If you have the normal vector in world space, "world up" is 0,1,0

solar sinew
#

Perfect just making sure

#

I thought maybe it was a typo and you meant world UV as in “world space” UVs. Glad to know it wasn’t a typo

fair sleet
#

How do I convert a position in world space to view space? This doesn't seem to work:
center = Camera.main.worldToCameraMatrix * t.position;
In the docs for worldToCameraMatrix it says:
Note that camera space matches OpenGL convention: camera's forward is the negative Z axis. This is different from Unity's convention, where forward is the positive Z axis.
but I'm not sure how to make it fit Unity's convention

amber saffron
#

Not 100% sure here, but shouldn't you use center = mul( Camera.main.worldToCameraMatrix, float4(t.position, 0) ).xyz; instead ?

fair sleet
#

this is in c#

#

position is a vector3

#

I want to do the proccesing here so I don't have to do it in the fragment shader

regal stag
#

@fair sleet Could be wrong but I think the fourth component should be 1 to transform points correctly (0 would be directions). I would guess that as t.position is converted to a Vector4 it's w component defaults to 0. Maybe try:

Vector4 test = t.position;
test.w = 1;
center = Camera.main.worldToCameraMatrix * test;

Or, I think there's a MultiplyPoint function inside the matrix which handles that for you. (also MultiplyPoint3x4 which is faster but can't handle projections - I think that's fine in this case though since world->view is just translate/rotations).

fair sleet
#

thanks!
I will try that

amber saffron
#

My bad, read to fast and focused on shader code due to the channel 😄

keen scaffold
#

So I've followed this tutorial step by step multiple times. I've combed over every single aspect of it and followed it to a tee. I'm almost 100% sure that I've not made any mistakes in replicating exactly what he's done

#

No matter what I adjust, the water stays opaque. I can't get the refraction / transparency to display. So it always looks like this:

#

I'm also using the latest version of Unity, URP and ShaderGraph

regal stag
#

I assume it's using Scene Color? Is the Opaque Texture option enabled on the URP Asset? (and not overridden on camera)

keen scaffold
#

Amazing! It was the URP asset

#

I never would have figured that out ❤️ thank you!

#

And yeah, it uses Scene Colour

#

It's strange, as it appears incredibly pixellated if you step away from it now

#

Any thoughts on this? ^

#

It looks very cool - just not what I'm after

regal stag
#

Probably something to do with how the distortion is handled

keen scaffold
#

Hurrrrmm

#

It's a step in the right direction! Thanks Cyan

#

Wish I could repay the favour. Can I endorse you or provide some art or something?

#

You're always helping folks

solar sinew
#

So true^

rustic talon
#

Hi everyone, im trying to do an affect that follows a curve (quadratic bezier), as this ability

#

the problem is that i want that the endPoint of the curve is given by the mouse position, so i dont know how exactly will be that curve, and I dont know hot to create an effect that is controlled by the script that generate the curve...

solar sinew
#

In reference to estimating a tangent and bitangent:

Given the normal of a sphere is its radius, should I be using the vector1 radius (w coordinate split from my Sphere vector4 property) or the vector3 output from the Normal Vector node?

Since the UV coordinates are a trigonometric conversion of the n-vector into world position coordinates - those coordinates should be the same as the vector3 output from the Normal Vector node right? (depending on what coordinate space that node is set to)
Edit: the UV coordinates are the output of the 3x3 matrix using the normal, tangent, and bitangent?

It's been a while since I've thought about sphere math. I'm using this page as reference: https://en.wikipedia.org/wiki/N-vector

Also I just want to double check - the sphere center is the sphere's defined origin right? and both of those values are the sphere's position vector3 (split from my vector4 property)?

The n-vector representation (also called geodetic normal or ellipsoid normal vector) is a three-parameter non-singular representation well-suited for replacing latitude and longitude as horizontal position representation in mathematical calculations and computer algorithms.
G...

rustic talon
thick fulcrum
#

@rustic talon just a suggestion, either pass in mouse click position and then do the math in shader or pre-calc it in c# and just pass over what is needed. might be able to get away with a sin wave based on distance or you will need to look up some maths.

vale peak
#

Hey guys! I'm trying to write a basic shader for UI elements (Textmesh pro text) that blocks/hides any other UI elements behind it (all are in world space)
This is a current example:

#

I'm new to shaders, so any advice/tips/links help!

thick fulcrum
#

daft question but why not just control the alpha of the text / disable the one behind?

vale peak
#

That would work!
I don't need to turn the object off entirely or anything, just 'hide' the text behind.
I'm trying to do this with a shader and I know little about them.
I guess I'm having trouble figuring out how to test the current value in the Z buffer against any other object to see if I need to 'hide' the current text

thick fulcrum
#

if you can't just tweak the apha on the shader, I make use of CanvasGroup to hide and unhide bits of the UI. you don't have to disable it, it does have an alpha parameter and you can toggle interactivity (raycast hits) etc.

vale peak
#

ahh so could I potentially just raycast forward from any object, if it hits another text element, change the alpha value to hide?

thick fulcrum
#

pretty much

vale peak
#

gotcha. Thanks for the assist!

thick fulcrum
#

np 👍

low lichen
#

@keen scaffold That pixelation based on distance looks like an artifact from ddx/ddy/fwidth

#

I'm having a hard time actually finding any documentation or articles about this artifact

#

There appear to be 2 version of derivates, coarse and fine. Whether the fine variant is less pixelated, I don't know.

low lichen
#

Derivates is cheaper, but looks almost unusable. Surprised Shader Graph doesn't have another version that is higher quality.

thick fulcrum
#

Just a quick thank you guys!
some of you helped me solve some problems with my shader graph water, it's now starting to take shape I can hopefully build on this and achieve what I'm after. Short clip of what I've got so far: https://www.youtube.com/watch?v=y0Ol8C33W5Q&feature=youtu.be

Water shader made in Unity Shader graph, height map generated waves for vertex distortion including normal re-creation.
Baked depth map to control wave height near shoreline and water color / opacity.
Reflections from Unity script, distorted with normal map for extra effect.

▶ Play video
keen scaffold
#

That's great, dude! Fantastic job 😄

tranquil fern
#

I have a sphere and I want to have a gradient effect on the alpha. By this I mean that the center is alpha 1 and the edges are 0. When looking at the sphere it's a circle, but this doesn't seem to help me come up with a solution.

regal stag
#

Fresnel Effect maybe?

tranquil fern
#

I forgot to click save asset...

#

I wish cmd+s would also save whatever graph I'm working on

#

Silly question perhaps, but is there a way to invert the fresnel?

regal stag
#

It's 0 in the center and 1 at the edges (90 deg angles), so One Minus will invert it

tranquil fern
#

Of course. It's just numbers 😅 Thank you

#

Can shaders be used to make something smaller in size? As in, instead of changing the scale?

#

I don't need this or anything. I'm just curious

regal stag
#

You can modify the vertex positions. If you multiply the position (object) by a value, and output it in the Vertex Position on the master node, it will scale it

tranquil fern
#

Hey that's pretty cool

regal stag
#

Nice

tranquil fern
#

This is what I'm working on. It's some sort of... Thing. Not exactly a black hole, but it will pull everything in like a black hole. Still trying to figure out how to make objects shrink as they near it

#

Preferably even stretch out, that'd be super cool. Maybe add a bit of a twirl to it so things get sucked into a spinning ball of somethingness

#

So if you have some suggestions for these things I'd be a happy boy 😄

regal stag
#

Hmm, haven't really done stretching stuff like that before. Not sure if this will work but my first attempt would be something like : Pass in the black hole's position and lerp between that and the vertex position, both in world space, with the T as a mask based on the distance from the black hole pos. (oh and transform that position back to object space for the master node input)

tranquil fern
#

Hmm yes, and strengthen over time

#

Basically inversed explosive force as the value

regal stag
#

I'd use a property rather than time for better control

tranquil fern
#

Update the shader prop with the new position every update?

regal stag
#

Depends if the black hole needs to move around

#

If it stays in one place just need to set it once, otherwise yeah every frame. Same with a strength/radius property.

tranquil fern
#

Maybe I can make it a grenade that suspends at its peak .y velocity or something, and have it suck everything in around it

regal stag
#

Or maybe something you throw then activate with another button press?

tranquil fern
#

For the swirl I think it's better to use a trail renderer

#

Hey, that's an even better idea

#

Like those c4 things

heavy ether
#

is there an efficient way to limit the count of instances drawn by Graphics.DrawMeshInstancedIndirect on a per frame basis without recreating or clearing the compute buffer?

#

i'd basically would like to draw fewer elements than the buffer might have set in it in a given frame

#

argsOffset allows to set the start position, but there's no way to set an end position?

#

would perhaps a solution be to just fill the buffer starting from the end and then to draw specific count set argsOffset to (total count - target draw count)?

low lichen
#

@heavy ether You wouldn't want to change the instanceCount argument? You haven't mentioned it, so I'm just making sure you're aware of it.

heavy ether
#

ah, right, of course, thank you

#

i thought that was meant to be set to the total buffer lenght

#

but you're right, thanks

low lichen
#

👍

white vault
#

Literally just downloaded unity, got me code for a ps1 style shader, so how do i integrate the code then? 😄

#

i cant find nything pls halp

tranquil fern
#

@regal stag What would "vertex position" be? Is that a position node set to world?

regal stag
#

Yea position node. World space in this case since you want to compare with the black hole's position which will likely be passed in with world space too

tranquil fern
#

Ah right. And transform that position back to object space for the master node input. Which node would do this?

regal stag
#

Transform node

tranquil fern
#

haha

#

This used to be a capsule

#

This is what I understood from your suggestion earlier

#

As a test I just copied the position values to a Vector3 input

regal stag
#

Basically that yeah, though since you want objects further away not to stretch more, should probably set T to something like saturate(radius - distance) ?

tranquil fern
#

Radius being the radius of the hole?

#

It doesn't quite make sense to me that the whole object moves. I think I need to normalise Remap the distance

regal stag
#

Would be the radius that objects would get stretched in

#

So objects outside that radius should stay with their normal vertex positions

#

Oh and it would need saturating/clamping

tranquil fern
#

I put this on any object that I want to be affected by the hole. But maybe I should instead put it in a bigger sphere around it that warps anything inside of it

#

(I'm googling saturating now. I didn't acknowledge the message because I don't understand it)

regal stag
#

saturate is just clamp between 0 and 1

tranquil fern
#

Because I want the point that's furthest away to not move

#

And I think I want a maximum amount of stretching

#

I picked a challenge didn't I

regal stag
#

Yeah, currently the T of the lerp is basically the amount of stretching. If it's 0 it's the normal vertex position, and 1 is the Destination (black hole pos). (If it goes above 1 I guess it'll end up on the other side of the hole which you probably don't want, hence the saturate/clamp).

tranquil fern
#

So that explains why the entire object is now in the wrong place

regal stag
#

Since that T value is based on the distance, you want it inverted so that further away parts (larger distance) produce a smaller stretch amount (T). That's why I suggested radius - distance though I'm not sure if that's correct or not

tranquil fern
#

Shouldn't I use the point that's furthest away from the black hole as the position?

regal stag
#

Maybe a Smoothstep node would be better here

tranquil fern
#

Actually, I don't know what the "position" node represents. Lemme check

regal stag
#

The position node is the position of the current vertex being drawn

tranquil fern
#

What would help is knowing the point that's furthest away

#

Because I don't know that from any point, I also don't know how far it's allowed to move

#

Oooh.. That's what the radius would be for.

regal stag
#

Using a smoothstep like so gives quite good results (with the first edge as higher value, so it's inverted). saturate(1 - distance/radius) gives similar results.

#

Also multiply reduces the strength a bit, so it doesn't collapse all to a single point. If you're fine with that leave it at 1 though.

tranquil fern
#

Oh that's pretty much exactly what I want

#

I won't look at it yet... I think I almost figured it out. I want to see if I am capable of doing it 😄

#

It'd be sweet if I could debug the values in my shader

regal stag
#

Can output the values as colours (like in the emission or albedo), might help a bit. Like 0 = black, 1 = white. In between will be grey shades

tranquil fern
#

That would totally help if my capsule weren't invisible 😄

#

I'm stubborn and ignorant at the same time.

regal stag
#

Haha right, that's the only problem with also editing vertices. I was wondering why mine was invisible earlier but I just forgot to transform it back to object space for the master node input

tranquil fern
#

I'm getting close... The effect seems inverted. But I can fix that 😄

#

HYPE

#

And now I'll compare what I did and what you did.

#

This is me, in case you want to compare as well 😄 Although this is based on what you told me.. So it's basically also your solution haha

regal stag
#

Yeah I think it ends up as the same solution, mine's just a bit more simplified

tranquil fern
#

What's the 0.8 for?

#

Oh to not make it disappear completely

regal stag
#

Yea, just depends what effect you want

tranquil fern
#

That's really cool

#

Is it possible to "extend" shaders?

#

I want to add the warp effect to existing materials

#

But I also kind of don't want to recreate them

#

Also... Mind if I steal your approach? It sure is a lot tidier.

regal stag
#

Not really possible to extend no, have to recreate.

#

Also sure, I don't mind, It's basically the same maths anyway

tranquil fern
#

Oh I see why it's easier, smooth step flips the value already if your first edge is > second edge

#

I manually flip the value

regal stag
#

Yeah 🙂

#

Smoothstep also clamps for you, so the clamp node you had also didn't really do anything

tranquil fern
#

Learned a lot today. This is pretty cool... I feel like I have a new super power now

#

Is there an easy way to support all the options the default lit shader accepts? I can recreate it of course, but that'd be cooler. For example, the base map accepts a color and a texture. Not sure how I'd do that

regal stag
#

Should just be Sample Texture 2D (RGBA output) multiplied with the colour property

#

I think the default lit shader options aren't too complicated to recreate. It's mostly sampling textures and using the right channels in the correct outputs. That said, I don't know them off the top of my head as I don't tend to use PBR stuff a lot.

tranquil fern
#

Well, it does seem as simple as texture > sample > albedo. They all share the same texture also so that's simple enough

supple kiln
#

Hello,

I want to do a unity particle system with computer shader.
When i click with my mouse on the scene i do particle.

At this time when i click on the scene nothing happen.

Here is my code : https://hatebin.com/jgkwwgrqqq

Description of what i want :

  1. Get the position of the mouse in the OnGUI () function, use the Camera.ScreenToWorldPoint () function to convert the screen coordinates of the mouse into world coordinates.

  2. In a Compute Shader, animate the particles using the pseudo-random number generation formulas described here http://www.reedbeta.com/blog/quick-and-easy-gpurandom-numbers-in-d3d11 /, generate a random position (3 float-s) for the particles.

  3. Optionally apply physical parameters (gravity, etc.) passed via a Constant Buffer.


  1. In the OnRender () function use the DrawProcedural () function to draw the particles as points.

  2. In the Vertex Shader, we must then index our StructuredBuffer of articules using a parameter of the main function with the semantic “SV_InstanceID”.

  3. Rather than displaying a single point, we add a Geometry Shader to generate a square of the size specified via the Constant Buffer.

  4. Use the “life” of the particles as a transparency factor. Use additive blending - Blend one, oneMinusSrcAlpha.
    For the rendering to be correct, we will pre-multiply the RGB components by the Alpha in order to make the composition of the colors independent (no need to sort the particles).

fair sleet
#

So I got this error:
CGPROGRAM block does not contain #pragma vertex, #pragma fragment or #pragma surface directive
I use HLSL not CG, I have no CG blocks. I have checked the preprocessor's output and it still no CG blocks. The only include I have is "UnityCG.cginc". Can somebody please tell me why the compiler thinks I'm writing CG?

#

Nevermind I got it.
I accidentally switched to a regional keyboard and typed ș instead of ; when writing the code
The compiler didn't like the typo

thick fulcrum
#

😆 hate those typos

tranquil fern
#

Why can I sometimes not connect a node to two other nodes?

#

Sometimes I can, sometimes I can't. The types match. If I copy it it works.

thick fulcrum
#

@tranquil fern at a guess you trying to do vertex stuff and mix it with surface colors? I'm bad at explaining this, but there's two sections. in the pbr graph the first three output nodes relating to vertex position, normal etc. can be mixed together. but they need to be separate from the rest, so you cannot have nodes crossing between domains. Hence you have to duplicate some parts of the graph to make it work within the other area.

cunning sundial
regal stag
#

While the colour might not have an intensity, the shader could still be outputting values higher than 1 depending on the calculations (and if HDR is enabled). I think alpha values outside the 0-1 range can also cause bloom issues like that, so good to saturate (clamps between 0 and 1) before outputting.

cunning sundial
#

I see, Ill give that a try then in a bit, thanks!

grand jolt
#

Alright so im super new to shader graphs and im trying to make it so depending on the light intensity it will greyscale depending on the intensity. heres what i have so far. Any help would be greatly appreciated!

cunning sundial
#

While the colour might not have an intensity, the shader could still be outputting values higher than 1 depending on the calculations (and if HDR is enabled). I think alpha values outside the 0-1 range can also cause bloom issues like that, so good to saturate (clamps between 0 and 1) before outputting.
@regal stag That fixed it thanks!

#

Its reduced, but still too intense, even as said, with 0 intensity

summer eagle
#

so im trying to make a shockwave effect for a particle system by using a sphere with the default "stained bump distort" shader, would it be possible to make it so the particles alpha color effects how much the material is distorted or something like that

#

i dont really know anything about shader code

civic jolt
#

Heya, is there any way to make shader graph transparent shaders write to depth buffer? @ me if you reply, thanks

grand jolt
#

I'm trying to wrap my head in Understanding 2d Shaders graphs , do you guys have any tips on how you learned it?

grand jolt
#

I was using a 3rd party written screen space reflection planes render feature + shader in the 2019 versions of URP, and it looked something like this. However, since trying to use it in any newer version, I always get errors like "implicit truncation of vector type" and the SSR doesn't work. Any ideas on what to fix? It seems like all the errors are showing up for the "Compute Shader", while the render feature and other scripts are fine.

#

(P.S. I had added some of my own code to the actual shader file to give the shader blending to overlay over other lit shaded planes as you see here. But the file in question is the "Compute Shader", not the main example shader I edited.)

thick fulcrum
#

I just tried Unities example reflection script + SSR and it seems to be fine, so if it's a paid for 3rd party asset you should probably give them a poke

#

even okay with SSAO... but the beta editor is so damn buggy

grand jolt
#

I tried poking them and they didn't respond. Maybe I didn't provide enough detail, but it's hard to do that through YouTube comments, which is the only place I could find to ask them.

#

I'm hoping to somehow fix it myself like I did with the blend thing before, but yeah.. This is all so confusing.

thick fulcrum
#

I'm not sure what the compute shader adds to the process without giving it a full read. but planar reflections is just a rt grab inverted and then you can do whatever you want with the result in a surface shader. seems overkill at moment, but I'm a noob so 😛

grand jolt
#

Hmmm

#

I was thinking about trying to write my own, but because I'm a real noob it might be kinda hell on earth to assemble.

thick fulcrum
#

have you looked at unities example planar reflections?

grand jolt
#

no? I didn't know something like that existed for URP..

#

Where do I find it?

thick fulcrum
#

sec just looking for link

#

ignore the fact it says lwrp, the planar script still functions correctly while the other examples not so much

#

just drop the planarreflections.cs onto a game object in scene, add a reference point game object then you can use the global texture in your shaders

grand jolt
#

damn, Imma try it. Thanks a bunch! 😄

thick fulcrum
#

np have fun 😉

grand jolt
#

well fuck, I think I just broke my project

thick fulcrum
#

what's happened?

grand jolt
#

I didn't make a backup because they're so large

#

but yeah now I regret it

#

it changed the sripting API and now everything is invisible

thick fulcrum
#

hmm strange let me see if I modified the script

#

or maybe I used the one from boat attack, but think was almost identicle

grand jolt
#

really really hope I didn't ruin my project, because I had some custom stuff in here, and I can't for the life of me transfer my custom player controller to another project and have it actually work.

thick fulcrum
grand jolt
#

Oh that seems to work!

#

at least my project isn't broken anymore

thick fulcrum
#

phew 😄

grand jolt
#

gimme a sec to try the effect ^^

#

What kind of game object do I assign this script to?

#

oh nvm the camera yea

#

ooo this is looking good ^^

thick fulcrum
#

any game object, just an empty one will do

grand jolt
#

Ah awesome

#

I gotta add blending to this tho so I can overlay this over some objects

#

or add it to a lit shader maybe..

#

hmm

thick fulcrum
#

you can use it in your shaders _PlanarReflectionTexture just access that global texture

#

then you can use a normal map to distort it

#

and other fancy effects

grand jolt
#

sorry I'm a complete noob at this 😅

thick fulcrum
#

we all were there at some point, I'm you just a week down the road 😉

grand jolt
#

So would I be able to add this effect to a standard lit shader graph shader?

thick fulcrum
#

absolutely

grand jolt
#

that way I could have shadows and stuff

#

Awesome, I gotta figure this out ^^;

#

Thank you so much! I had no idea this existed!

thick fulcrum
grand jolt
#

Yeah it doesn't seem to catch shadows or direct lights tho, so I'll need to figure that out ^^;

thick fulcrum
#

seems to be a urp10 thing, as I'm sure you could toggle shadows on before

grand jolt
thick fulcrum
#

just a quick note is I would test with mobiles, this was taken from a mobile project (boat attack demo) but no saying how performant it is across a wider spectrum of devices. it may need some tweaking

grand jolt
thick fulcrum
#

doh!

grand jolt
#

Well this is interesting

#

Looks fine in the editor, but in play mode it looks like this

thick fulcrum
#

but tbh if your targeting mobiles, the shadows will be costly to render twice

grand jolt
#

I'm targeting PC

thick fulcrum
#

my shot was in play mode too... ah PC then all is good except the obvious 😄

grand jolt
#

I was just hoping to have this effect added to a Lit shader graph if possible. I have like no experience with shader graph tho, only some limited C# experience. ^^;

thick fulcrum
#

do you have some post processing in the scene?

grand jolt
#

Yeah

thick fulcrum
#

or is it just the default example

grand jolt
#

I have post-processing and the new SSAO render feature

thick fulcrum
#

same

grand jolt
#

Not sure why everything is broken for me

thick fulcrum
#

start switching things off like PP / SSAO see if makes a difference... failing that test in an clean empty project with just the examples unity assets perhaps

grand jolt
#

Ah I had camera stacking

#

That's what broke it

#

I just removed that and now it works

thick fulcrum
#

do you need the camera stacking ?

#

or something you can work around?

grand jolt
#

I may need it later on

#

Is there a way I can add distortion to the effect with a noise texture?

thick fulcrum
#

my experience is limited to using it for water so far, but I imagine the same should work on other surfaces.
I basically offset it with the surface's normal map

civic jolt
#

Where to get/how to make a proper transparent shader that is compatible with hybrid renderer v2?
This is a proper shader (speed tree one)

#

It's even worse when trying to render it as alpha test, it masks using mesh bounds and not alpha test

#
  • I need it to write to depth buffer, eg. be affected by SSAO or other depth-dependant effects
#

I can achieve this with with opaque cutout, but it won't write to depth buffer

#

(transparent objects behind it don't render)

thick fulcrum
grand jolt
#

Oh wow, that's really nice! 😄 I'm not sure how to add manual slider adjustment though for stuff like smoothness. I'm such a noob. XD

civic jolt
#

Ok regarding my question, this seems to be a problem with SSAO depthnormals pass, when switching SSAO to depth mode instead of depthnormals it seems to work

#

Although would be nice to be able to use DepthNormals

thick fulcrum
#

@grand jolt in the shader graph you can alter the property from default to "slider" and then specify start and end values. I just wasn't sure what sort of range it needed as might be dependant on the normal used, a value of 10 for me was ok but it could go way higher before it was "not distorted".

#

@civic jolt that does suck a bit, I've not tried the hybrid renderers as they seem to unstable from comments. Which you unfortunately have to keep in mind that these features are not at a production ready state yet.
One will just have to hope this gets sorted out in a future itteration

grand jolt
#

That looks good to me ^^ I was just wondering if there's a way for me to add alpha blend/transparency sliders as well as make the smoothness and metallic and AO adjustable per material. I already set the "metallic" section to where the color channels separate out into their respective Occlusion, Smoothness, and Metallic fields for Mask Maps, but is there a way to put a slider "in-between"?

civic jolt
#

I kinda need to use hybrid renderer unless I want to write my own instanced mesh render code, which I don't want to do at this time

#

Rendering a ton of objects

grand jolt
thick fulcrum
#

ah yea just add a new property for example smoothness is 0 - 1 range, so create a new vector 1. set to slider and attach that to the smoothness output in graph

civic jolt
#

I just switched (or at least in the process of) to URP and hybrid v2 from builtin and hybrid v1

#

Still have one very important shader that I can't get to work on the new setup

grand jolt
#

So a Float?

thick fulcrum
#

essentially

#

@civic jolt your ahead of the curve and pushing boundries in unity terms 🙂 but I guess it comes at a cost 😦

civic jolt
#

True that ^^

grand jolt
#

I think I'm kinda stuck honestly 😅 I don't know how this works

civic jolt
#

So I need screen space decals, the only shader I found is this one, but it doesn't work with hybrid renderer, any help on if I can adapt it to v2?
I can technically write an instanced renderer to display it since it only uses one mesh if I can't adapt it, but I'd like to try adapting it to hybrid first if possible https://github.com/ColinLeung-NiloCat/UnityURPUnlitScreenSpaceDecalShader

I used a different shader before on builtin

GitHub

Unity unlit screen space decal shader for URP. Just create a new material using this shader, then assign it to a new unity cube GameObject = DONE, now you have unlit decal working in URP - ColinLeu...

grand jolt
#

I would search online but I don't know what to search for

thick fulcrum
#

oh @grand jolt you are correct for setup with texture channel as smoothness, you could add a divide and a value to control the level. but otherwise I think your setup was correct

grand jolt
#

How would that look hooked up?

#

I'm not sure how to "add" them, because putting stuff in-between changes nothing in the inspector after saving the shader

thick fulcrum
#

if you add properties to the graph, check that the material has a suitable value as they don't always update if you change default.

#

damn that sounds odd but hopefully you will understand 😄

grand jolt
#

hhhh this is scary XD Why can't all node editors be easy like Blender, aaaaa

thick fulcrum
#

@civic jolt for the decal shader, I use that one myself now since it's only one working on newer version of unity urp.
The "mesh" it's attached to I believe is just defining the clip / display area, so you could work around that I think

civic jolt
#

Yeah I will write a DrawMeshInstanced thingie to draw cubes from entities if I can't adapt the shader

#

Also unlit URP shader is better at zmasking than lit shader -_-

#

That's SSAO coming through behind it

grand jolt
#

Okiii I'm learning how it works. I finally figured out how to add a float value to change the texture value output like you said. I have like 0 experience with Shadergraph, so I'm learning ^^

thick fulcrum
#

give it a week then you will be teaching me 😄

#

@civic jolt damn that difference is huge, means writing your own lighting I guess into the shaders.. yet more time spent

civic jolt
#

The most painful thing is making a shadergraph, converting it to code, finding the culprit and then fixing it

#

That is if you can even fix it

#

And then fix it every time you change your shader

thick fulcrum
#

yea 😦 and then they update URP meaning new fix needed

civic jolt
#

Hah indeed

grand jolt
#

@thick fulcrum Have you found a way to turn off the AO effect in the planar reflection?

thick fulcrum
#

if I understand correctly, you need to define a second renderer which does not have the SSAO assigned to it. in your URP Asset you add this to the "renderer list", then in the planarreflections.cs code. Where it defines the camera (it creates on on the fly so to speak CreateMirrorObjects()), you need to tell it to use that "renderer". Assuming you have default and the one you created, it should be... ah

#

cameraData.SetRenderer(1); already exists, I think that's what is needed so you should just need to create a new renderer and add to list

tranquil fern
#

@thick fulcrum That makes perfect sense. Thank you.

#

I want to make a dissolve effect, but based on overlap. It'll be a door of sorts and the parts where the character makes contact with it will seem to be dissolving into particles or something, and when past the door it'll be completely transparent. That latter I think I can do with a world position and a parameter which gives a normal for the quad/plane/whatever. The first part I'm not sure about.

I could use the distance from the parameter to decide if something should be happening, but I'm not sure how to displace "randomly" to make it look like bits and pieces (flakes? idk the right word for it) of the character are being sucked in

thick fulcrum
#

I've not messed around with that sort of effect, but I believe most just use a "noise texture" of some description. 🤔 not sure if that would work in this use case though

tranquil fern
#

I suppose I could use noise for alpha

#

And if transparency doesn't look nice I can round it to 0/1

#

Not a bad idea... Thanks 😄

#

Can I also ask for feedback on effects I made?

#

Idk if this is the right place for it

grand jolt
#

@thick fulcrum What I did that seemed to work was making a second Forward Renderer with no AO, and then setting that one as default. Then I set the original Forward Renderer manually for the player camera. Seems to work. ^^

thick fulcrum
#

it's probably good a place as any if it's technical critique your after

grand jolt
#

Looks like the AO no longer shows up in the planar reflections

thick fulcrum
#

so long as it works ^^

grand jolt
#

Ye, I figured this might be an easier fix for anyone else wondering about it. Having AO in the reflections is both useless and performance hungry.

#

Now it's flying

tranquil fern
#

Hm well.. I'm an amateur just trying to have some fun. I made an effect which I think looks cool. But I also know I have no prior experience so there's likely some stuff that can be improved that I'm simply not seeing.

thick fulcrum
#

no good asking me for any critique of a technical nature, I'm just a noob in training...
if it looks pretty, achieves what you want in a reasonably performant manner.. it's good enough for me 😄

tranquil fern
#

The 1080p version of the video doesn't do it justice... Waiting for youtube to process it :p

#

Upside is that I had time to add captions.

#

I'm really bad with lighting... That's one thing I can see wrong with this

grand jolt
#

@thick fulcrum Do you think there's any ways to improve the performance for this by lowering the clipping distance or something for the planar reflection?

#

I'm not sure how to pull it off.. I get 60 FPS otherwise, but it lowers to 30 fps as soon as I look down.

thick fulcrum
#

@grand jolt in the planarreflections.cs file you could try adding to function CreateMirrorObjects() near bottom just after reflectionCamera.enabled = false; try adding reflectionCamera.farClipPlane = 200; or some other value.

grand jolt
#

Awesome, I'll try that

#

I'll use a public float so I can change it in the editor

thick fulcrum
#

I was messing the the downsampling earlier to see if that improved fps, but I didn't see any change... it's one of the things I'd like to look into improve myself. it's just on back burner with everything else 😄

#

simple fix.. get a better graphics card 😆

grand jolt
#

My graphics card is pretty decent tho. I just like to optimize things as best as I can. ^^

fervent tinsel
#

what gpu you have doesn't really matter if you are serious about gamedev

#

what matters is that it does work with the computer spec you want to target

grand jolt
#

ye

fervent tinsel
#

(of course in ideal case you'd have the min spec rig too)

grand jolt
#

Btw the culling distance thing doesn't seem to have any effect, unfortunately.

feral inlet
#

This seems like a stupid question most likely, but how do I expand these???

regal stag
#

They changed it so you click the property then look at the graph's "inspector" window now.

feral inlet
#

OH, thank you lolol

thick fulcrum
#

@grand jolt the only other things I can think of which are quick and dirty would be to have it not render every frame, but a delayed update. this would cause some tearing perhaps though on extreme movements.
unfortunately as it is literally rendering everything twice, it's a costly effect.

#

if you only have some area's which use this, could perhaps save performance by switching it off. Put up some trigger box's near where you want it on and work it that way perhaps

grand jolt
#

Hmm idunno

#

I wish box projection was in URP right now for reflection probes

#

I'd just use that if that were the case

thick fulcrum
#

@grand jolt the resolution multiplier does make a difference, seems you have to disable and enable it to see the change as it's only sent to camera on creation. Also you might want to make sure the reflected surface is excluded from the "reflected layers" list as this could also cause some unwanted fps drop.

grand jolt
#

Good idea

#

Also my computer keeps crashing so I can't always respond back right away XD

thick fulcrum
#

tbh I don't know how you manage with the Unity beta, it crashes when I open it due to a GUI issue which got fixed in 2020.1 but still exists in the beta 😆

grand jolt
#

I'm wondering if I can set the planar reflections to FixedUpdate somehow

#

Any ideas?

#

It's using "UpdateCamera" and "UpdateReflectionCamera" so idunno

errant lily
#

Hey,

I am trying to create kind of triplanar shader(every face would have color based on word position, like top would be green front red etc). I can get these faces from normal vector node + dot product. But When I try to combine left and right side together with add, the colors are different. Any help here ?

cosmic prairie
#

I think what's happening is that the dot product also returns negative values in the black area

regal stag
#

The dot product result has negative values, so you'd need to Saturate before adding

errant lily
#

Ah thats right, didnt count on that... 😄 That should be it. Thanks

regal stag
#

Also you could just Split the normal vector and take each axis instead of a dot product. I think that would be the same result?

errant lily
#

Hm, thats interesting. Should work. Will try. thanks @regal stag

grand jolt
#

Is it possible to get the total light intensity with the shader graph. I’m trying to use the total light intensity with saturation to greyscale things not in large amount of light

cosmic prairie
#

you need a custom fuction node for that (a bit of a pain, at least for me)

grand jolt
#

I thought so but I don’t know where to start with the custom node

cosmic prairie
#

I guess try to look up a cel shading tutorial on yt and see how they access the light values, thats what I always try to do, but stupid me uses the preview packages and it never works or I get tired of wonky mechanics and errors

grand jolt
#

Alright, thanks for the help!

errant lily
#

Can someone explain me how SRP Batcher works ? I got Shader Graph material that is SRP batcher compatible. I have enabled GPU instancing and SRP batching in URP asset. When I have SRP batching enabled I got about 847 batches and saved by batching is - 842. So that's 5 draw calls right?(never seen - before saved by batching) The verts is about 6.5k. In frame debugger i seen 5 SRP batches. the reason for not being batches is srp first call from scriptable render loop job

Without SRP batching enabled 9 batches and saved by batching is 838. verts is 26.5k. In frame debugger with disabled SRP batching I got 4 Draw instanced mesh calls there is no reason why this wasn't draw in one call.

In this particular case the speed is exact but All the meshes in the scene uses same material, so I don't understand why the batches in stats window are so weird and why its not batched all in one call

dense thunder
#

How do I setup normal and specular maps in Shader Graph?

fair sleet
#

Is
c=lerp(a,b,condition)
faster than

if(condition)
  c=b;
else
  c=a;

AFAIK the first one should create 0 branches. Is the hlsl compiler smart enough to optimize the second one into a branchless version?
I've seen lerp used often instead of if statements in shaders but I can't find a lot of information online about this optimization

amber saffron
#

@dense thunder Sample the maps with a texture sample, and output the value to the master node

#

@fair sleet You could also do c=(condition)?b:a;
But in this case I don't think that a branch would be so costly. Depends on the whole context of how a and b are calculated

fair sleet
#

I think you missed a ?

#

if instead of a and b I have some complex calculation that takes,as an example, 30 cycles to compute. Would if or lerp be faster?

low lichen
#

I don't think you can make any assumption, because it varies based on what compiler is used on what graphics library on what hardware

#

But I've heard many talk about how branching is not as expensive as we've often heard

#

Not on modern hardware, anyway

fair sleet
#

So the answer should be "do not worry about it"?

regal stag
#

I think it also depends on the condition as not all if statements / conditionals will produce a branch, (at least from what I've heard. I feel there's a lot of misinformation about this stuff though, so not really sure).

There's a bit of info in the comments of this thread about this sort of stuff, might help : https://twitter.com/bgolus/status/1235254923819802626

dense thunder
#

@amber saffron I've got them working more or less. Texture 2D input set to Normal > Sample Texture 2D > Normal Strength > Normal PBR Master.

Similar for the specular/roughness map. Texture 2D input > Sample Texture 2D > Smoothness PBR Master.

The normals are working fine but the specular seems inverted. Whack an invert node on maybe?

amber saffron
#

smoothness = 1-roughness

dense thunder
#

Never mind they seem to be working alright now

undone brook
#

Organization question! I've a graph that's my "main" shader. It's made with a bunch of subnodes already and it's pretty big. I'd like to have a version that allows for a texture.

-Turning the main shader into a subnode itself feels kind of off.
-Putting the texture directly on the main graph would create unneeded costs, even if the texture field is empty, I think?
-Copying the graph and appending the texture changes. In that case, if I ever changed the main shader, I'd need to go change it in there as well.

I'm leaning towards turning the main thing into a subgraph, but hoping one of you has an alternative that I don't know about.

dense thunder
#

@amber saffron Got another question... Is there a way to add a strength vector to the specular?

amber saffron
#

Why not simply multiply by a float value ? 🙂

dense thunder
#

How do I do that??

amber saffron
#

@undone brook You can add a texture input and sample, with a keyword toggle branch

#

@dense thunder smoothness * value

dense thunder
undone brook
#

@amber saffron I'm not familiar with what you mean when you say keyword toggle branch. Can you elaborate just a tiny bit please?

#

Ah, like add a bool and check against the bool to see if it should consider the texture?

amber saffron
#

yep

undone brook
#

ah yeah that could work

#

@amber saffron Thank you!

dense thunder
#

Did the trick!

amber saffron
#

@undone brook
But the keyword (it's a specific section at the bottom of the input type list in the blackboard) does compilation branching instead of dynamic

undone brook
#

@amber saffron This is very cool stuff. Thank you.

#

Reading through the API to make sense of keywords, I'm not understanding the "Scope" very well

#

I figured global implied that all the shaders using that keyword would share the same value. I think I'm deeply misunderstanding this.

amber saffron
#

Thing more as where the keyword is registered

#

For each keyword, a potential variant of the shader is created.
And to "identify" those variants, the keyword is store is a bit array, to make a mask.
There is a limited number of bits for the global keywords, and an other one for the local ones

#

global keywords can be shared between multiple shaders, while local one are specific for a shader

undone brook
#

@amber saffron Thank you so much! One last tiny question, does the editor expose anywhere the amount of global keywords in use?