#archived-shaders

1 messages · Page 241 of 1

dim yoke
#

ok so do you know how shaders work in general?

sweet cosmos
#

Also there is some work with light, but I don't know how it works

dim yoke
# sweet cosmos Um they take vertices count + positions, make a shape out of it and then apply a...

yeah. so in forward rendering path all the lights are rendered in the shader itself. the shader takes in list of lights as input and using that calculates how to color pixels so they have lighting on them. Per pixel lights are calculated this way. Per vertex lights on the other hand are calculated on the vertex shader (which is used to place the vertices and transform mesh data (position, normal, uvs, etc.) and if you wish some additional data to fragment shader where the data is interpolated per every fragment (pixel)) so the vertex shader uses the light list to calculate how the lights affects the vertex. the lighting data calculated on vertex shader can then be interpolated to light the pixels on the fragment shader. per vertex lights tend to give quite blurry and bad quality lighting 🔽 compared to per pixel lighting ⏬ but can be a lot faster because usually there's fewer vertices than pixels to render

royal crest
#

This did work for the mask but not for the noise ^^' but this is already of great help, thanks!

grizzled bolt
#

You could use a noise texture instead of a noise function to get a traditionally flippable sort

#

Cheaper too

royal crest
#

This could actually be a better solution indeed, thanks for the suggestion! Will try it out

sweet cosmos
#

Besides, I see such events in deferred renderpath

dim yoke
#

on deferred rendering shaders only calculate the base color, normal etc. and stores them in so called G-buffer which is then used to calculate the lights after every opaque mesh is rendered to the buffer

sweet cosmos
wary jackal
#

I removed that. I saw that on somebody else's code and decided to try it. I kinda hated the way it worked. Anyways, even with it removed the artifacts are still there. When you refer to the sampler state settings, what exactly are you talking about? The _MainTex is just the main render texture of the camera, as it is a post processing effect.

sweet cosmos
dim yoke
dim yoke
#

yup. I don't know how to explain the first part (render path and shader stuff)

sweet cosmos
sweet cosmos
dim yoke
# sweet cosmos Asking just to be sure: so there are always at least two shaders on an object, v...

yes. on all render paths everything is rendered using shaders that are made of those two stages (vertex and fragment stage). basically on forward path everything (lighting, textures, shadows etc.) is calculated on the shader itself and on deferred path lighting calculations are done after every shader have ran as a sort of "post processing" effect. forward rendering is pretty straight forward and that's the default rendering path in unity. I'd recommend learning about writing shader (with forward rendering path) as it makes it much easier to understand how shaders works internally (vertex stage, fragment stage, interpolators, passes etc.). Imo this was really good tutorial/introduction to start with https://www.youtube.com/watch?v=3penhrrKCYg&t=2982s (I watched that about 1-2 years ago so i'm not very "pro" with shaders yet).

#

learning to handwrite shader makes it also much easier to use shader graph because most shader graph tutorials just teaches you to make cool effects and not how shaders really work

open anvil
#

yo guys can i ask here about how to properly apply textures to scene . im noob and need help

wary jackal
#

Okay, so I checked out sampler state settings and those don't work in my case because it is a post processing effect that takes the texture from the main camera. Really the thing that I'm confused about is the pixel artifacts. It all seems to be working except for those odd pixels.

#

Oh hey, I just figured it out.

#

It wasn't on the GPU side, it was on the CPU side.

idle copper
#

Hi, what is the easiest way to get the angle between two 3d vectors in HLSL?

west lantern
#

Okay thank you, but would it be easier to learn with the unity shader graph or just by code.

white marsh
#

shader graph is generally thought of as easier to learn, but i personally am a programmer and i want to understand the math and reasoning behind things. and i learn those things way better with code than a graph

dim yoke
#

If you learn handwritten shaders, you don’t need to learn shader graph separately, it’s like 10 mins and you’re pro with shader grpah (assuming you know handwritten shaders already)

west lantern
#

Okay thank you for your time responding me

idle copper
# grand jolt

Awesome, thanks. But uh, how do I normalize the vectors?

grand jolt
dim yoke
#

The problem is that there’s not many tutorials that really teaches shader fundamentals with shader graph. Most of them just show cool effects which doesn’t help much when you want to do something yourself

idle copper
white marsh
#

i personally find there to not be many tutorials for shaders overall. its either super simple things or fairly complicated stuff

#

i sometimes look at other shader tutorials for other languages and programs, like blender for example. since the theory is pretty much the same. and once you know what you need to do its easier to google things

dim yoke
#

Documentation tends to be very poor what comes to shaders

idle copper
white marsh
#

actually this is exactly the reason i have started to document all the stuff i make relating to shaders and graphics

idle copper
#

Also, is there a convenient way using a surface or frag shader to just have a visible pixel of a mesh just not render and have it render whatever is behind it instead?

dim yoke
idle copper
dim yoke
#

discard just ”ignores” the pixel and clip discards if the value you give it (or any component of it) is negative. Clip can be useful when you want to ignore pixels with alpha value less than 0 (usually something like clip(alpha - 0.001) so alpha of 0 gets ignored too)

idle copper
dim yoke
idle copper
#

Wow, that works really well

#

Thank you so much

dim yoke
# idle copper Thank you so much

Np, clip/discard is great way to make some pixels fully transparent because it works on opaque shaders too and allows to do cool effects (like dithering transparency) with minimal overhead

rancid moat
#

Can someone help with setting up GPU Instancing? I have a world made up mostly of these brown cubes, there are around 500 of them.

#

they're literally all cubes, with gpu instancing set up
Does it just not work for Orthographic forward rendering?
There is literally nothing operating on these cubes right now, they are all the same prefab
(Using the standard unity shaders)

balmy snow
#

Can someone help me with shaders because I don't get them I'm making a 3d game third person and i just can't do the water shader

balmy snow
#

I can show you @dim yoke in a call if you want to

dim yoke
#

Why not just show here so everyone can help?

balmy snow
#

ok

#

ill post it later im gonna take a mental break lmao

tired bronze
#

@eager egret Don't crosspost.

idle copper
#

Ight, so I'm back with another question 🎉 .

#

What would be the best way to get something like the camera position or the position of a specific object (like the player) or some other universal but changing value in HLSL?

lean lotus
#

Whats the alternative to byte data type in a compute shader?

#

Also for this, a struct on the C# side of things doesnt allow constant buffer sizes? So then how do I send it in without having to copy all the data to an intermediate buffer? its a bunch of arrays of type int with length 8
as in, this is the structure of the array

    struct BVHNode8Data {
        float3 p;
        uint[3] e;
        uint imask;    
        uint base_index_child;
        uint base_index_triangle;
        uint[8] meta;
        uint[8] quantized_min_x;
        uint[8] quantized_max_x;
        uint[8] quantized_min_y;
        uint[8] quantized_max_y;
        uint[8] quantized_min_z;
        uint[8] quantized_max_z;
    }

Is it possible for me to have this same structure on the CPU and send it nicely? Because I just cant copy all the data to an intermediate structure with them all layed out cuz thatll take too much performance(talking about doing this 30k times at least per frame)
also on the C# side those uint arrays are actually byte arrays but HLSL doesnt have the byte data type

cobalt needle
#

please help how to edit shader like this

#

When i tried to edit it happen

karmic delta
#

Anyone have any idea what's causing this error?

Steps needed to recreate (Unity version 2021.3.1f1 Personal)

  1. Create brand new 3D project
  2. Create Unlit Shader Graph
  3. Right-click newly created Shader Graph and create a Material from it
  4. Material turns pink and gives the error shown in the screen shot.
meager pelican
# lean lotus Whats the alternative to byte data type in a compute shader?

When I last did a BVH acceleration struct it was a b-tree, not an oct-tree. So I only had 1 min and 1 max in the struct, basically.
But there is a way to set/access fixed length data in a struct from C#, it allows interaction with other languages/systems, I just don't have the time to answer now as I have to run off to work. Google is your friend. Maybe see "MarshalAs".

#

That last one looks cool.

cobalt needle
#

wut the many problem. why i set red base col but the preview is purple WHY?

dim yoke
somber snow
#

Is it possible to make an unlit shader that renders itself or other objects shadows?

#

(In shader graph)

sweet cosmos
#

Do a mesh's vertices also store colors inside them? Or the colors are stored in the mesh?

#

Also please give me a good info resource about this if you know one

upbeat topaz
#

is there a way to change the dither matrix size in shader graph?
as I'm trying to make the dither dots be similar-ish in size to the pixel size of the character

low lichen
#

Random find in Unity 2022.1 release notes:

Editor: Now shaders will have SHADER_API_(DESKTOP|MOBILE) define set according to the target build platform.

amber saffron
upbeat topaz
#

ooh sweet, gonna try that

idle copper
#

Hey, what would be the best way to pass a Vector from a script (like the player position) to all materials of the same type?

regal stag
regal stag
# somber snow Is it possible to make an unlit shader that renders itself or other objects shad...

You can use Custom Functions and some specific boolean keywords to make shadows work in an Unlit Graph.
I've got a "Main Light Shadows" SubGraph included in this repo, which handles both for you. https://github.com/Cyanilux/URP_ShaderGraphCustomLighting
If you need additional shadows too, you'll need to write a function similar to the AdditionalLights_float one. Probably with *= light.shadowAttenuation; in the loop instead of adding diffuse lighting.

somber snow
#

After asking that I ventured out to learn how to code surface shaders because the graph was giving me too many headaches, I'm keeping this though, for if I fail misserably

#

Thank you very much!

regal stag
#

Ah okay, if you're planning to use surface shaders I'd assume you're in the built-in render pipeline which would be different anyway. My repo only works in URP

somber snow
#

Different? assuming I am on built-in? oh god, what did I get into xD

#

I guess it's not going to be as straight forwards as I imagined

regal stag
#

If you're using URP, it doesn't support surface shaders. That's the reason for my assumption

somber snow
#

It did let me create a surface shader file, so I assumed it could be done

#

Although, that explains why the material was pink from the getgo

regal stag
#

Yeah, I think the option is always there. But if you apply it to a material it'll be magenta

timid plover
#

how can I visualize the depth buffer of the main camera in urp?

narrow furnace
#

hello hello

#

How do I use a transparent video as a texture in unity URP

#

like I want the transparency to be used too instead of it being totally black

idle copper
#

Greetings. Does anyone know if there is a way to do raycasts in a surface/frag shader that would collide with any mesh in the scene so that I can change thing about a pixel dependent on what information that raycast returns?

low lichen
idle copper
low lichen
# idle copper Okay, thanks. and I'm assuming that giving it access to every visible mesh in th...

You have to think about how you want to encode that data and how you want to use it. You could gather all the triangles of all the meshes in the scene and pass that as a big array to the shader, but then every pixel would have to loop through that whole thing to find what triangles are near it. You could encode it into some kind of spatial tree to speed things up. You could also encode it as a 3D signed distance field, this is what UE5's software Lumen does.

fair imp
#

does anyone here knows about hdrp custom camera passes ?

low lichen
#

But it's complicated to generate this data in a performant way

idle copper
#

Yeah, that sounds a bit advanced

#

But thanks for the help!

grand jolt
#

hmmmmm. Looks very interesting, but it isn't very optimized for games

fair crest
#

how can I transform a black/white gradient into a binary output from a threshold ?

sterile wave
#

anybody using toon chan? why is outline not working in urp v12 ?

grand jolt
#

is there a shader support extension for VS? Or are there other IDEs?

meager pelican
sterile wave
idle copper
marble plover
#

Hey i can't find the Alpha option in the shader graph ? i can add him manually but idk he didnt do anything ?

shadow locust
marble plover
#

where is graph settings ? in the package ?

shadow locust
#

in your graph

lean lotus
#

Also what is the byte equivalent in HLSL? If I wanted to send a struct with several byte variables to it?

lean lotus
meager pelican
# lean lotus Also what is the byte equivalent in HLSL? If I wanted to send a struct with seve...

lol. GPUs are weird. Unfortunately, there isn't one of a scalar type that I know of.
You can fudge it and use bitwise operators on a 32 bit uint, so 4 bytes packed into an unsigned int.
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-scalar
SM 6.2 supports 16 bit scalars, if I read this properly, but some platforms may not. https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types
and IIUC Unity isn't supporting 6.2 yet.

GitHub

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang. - 16 Bit Scalar Types · microsoft/DirectXShaderCompiler Wiki

lean lotus
meager pelican
#

OK, I have to ask...
Is your storage space that limited, data size so big, that you can't take the easy road and just use good 'ole ints or uints? Yeah, you waste space a bit. But how big is big? What if your target platform has 4 GB of memory or more?

lean lotus
#

no its the way it is so it can be very very quickly retrieved on the GPU if theres 30k instances of it

meager pelican
#

The GPU "likes" things aligned on 4 byte boundaries FOR SPEED reasons, and memory access. I get that bandwidth is a concern too, but somehow that is a bit beyond me, they like and are optimized for 4 byte boundaries....actually I think they like 4x4 (16 byte) boundaries best. Like stuff all data into float4s where possible. I've heard that somewhere before.

lean lotus
#

mhm thats why its formated into uint's that I then pack into uint4's

meager pelican
#

Cool, so what's not working?
Also remember that things may need atomic operations if multiple thread write to the same area at the same time.

meager pelican
lean lotus
#

sorry internet went down for a bit
Overall whats not working is getting the correct results to match up with the results from a more gpu friendly approach and I have no clue why

meager pelican
#

The first thing I'd do (and maybe you've already done it) is to create some benchmarks and test hypothesis that it's faster with the bit shifting/masking rather than addressing 30K expanded data.

But OK, let's assume it is faster to pack it all in, so you should be able to pack it all into uints on the C# side, and then unpack it and work with it as uints in HLSL, write it (again shifting and anding, maybe with atomics if needed) and if necessary read it back (but readback is slow from a GPU compared to write).

I have to bail out for the night, I'm up at 4 am....:(

lean lotus
#

fair enough but thats what I have been trying to do
its all fun and games until I get to the writing bit, then the values are not the same D:

warm tinsel
#

I was wondering if someone could help me with some shader trouble I've been having. I'm pretty new to game development/unity so im sorry if this is very basic. I found a asset on the unity store that creates a fog effect in the world scene. I was having a lot of trouble implementing this since I can seem to only put shaders on actual objects, rather than on like a players camera or somehow just in the map. Would anyone be able to teach me the write way to go about these things and shaders in general? thanks! here is the link to the asset I was using: https://assetstore.unity.com/packages/tools/ui-shader-with-fog-195773

Get the UI Shader With Fog package from Multirezonator and speed up your game development process. Find this & other Tools options on the Unity Asset Store.

drowsy linden
#

How do I make an intersection shader in unity 2020? I've followed all sorts of tutorials but the band around where the objects intersect changes width and position as I move the camera, and I'd like it to stay constant relative to the object

obtuse pasture
#

Hi, not sure if this is right place to ask this. Does MaterialPropertyBlock not have a method for checking if a property exists, like Material.HasProperty()? Or is it standard to just use Material.HasProperty() for these checks?

sterile wave
#

why is my outline not showing? i upgraded from 2021.1 LTS to 2021.3 LTS und now my shaders are slightly broken

sterile wave
sterile wave
sterile wave
meager pelican
obtuse pasture
cloud orchid
#

Im having trouble with shaders that use the depth pass on some mobile devices. Is there some devices/GPUs that dosent support it?

#

Im using forward rendering in URP

sweet cosmos
#
Shader "Outlined/Silhouetted Diffuse Texture" {
    Properties{
        _Color("Main Color", Color) = (.5,.5,.5,1)
        _OutlineColor("Outline Color", Color) = (0,0,0,1)
        _Outline("Outline width", Range(0.0, 50)) = .005
        _MainTex("Base (RGB)", 2D) = "white" { }
    }

        CGINCLUDE
#include "UnityCG.cginc"

        struct appdata {
        float4 vertex : POSITION;
        float3 normal : NORMAL;
    };

    struct v2f {
        float4 pos : POSITION;
        float4 color : COLOR;
    };

    uniform float _Outline;
    uniform float4 _OutlineColor;

    v2f vert(appdata v) {
        // just make a copy of incoming vertex data but scaled according to normal direction
        v2f o;
        o.pos = UnityObjectToClipPos(v.vertex);

        float3 norm = mul((float3x3)UNITY_MATRIX_IT_MV, v.normal);
        float2 offset = TransformViewToProjection(norm.xy);

        o.pos.xy -= offset * o.pos.z * _Outline;
        o.color = _OutlineColor;
        return o;
    }
    ENDCG

        SubShader{
            Tags { "Queue" = "Transparent" }

            // note that a vertex shader is specified here but its using the one above
            Pass {
                Name "OUTLINE"
                Tags { "LightMode" = "Always" }
                Cull Off
                ZWrite Off
                //ZTest Always
                ColorMask RGB // alpha not used

                Blend SrcAlpha OneMinusSrcAlpha

                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag

                half4 frag(v2f i) :COLOR {
                    return i.color;
                }
                ENDCG
            }
        }

        Fallback "Diffuse"
}```
#

How can I make this shader add outline but not change the picture made by the shader which worked with the mesh previously on this frame?

#

Is it even possible?

stoic adder
#

Yo so I just started using unity a few days ago so if i say anything hecka dumb excuse me, anyway i want to make a shader graph for my 3d game im working on, but whenever i go to create it and look under shaders I cant figure out what to do to create a shader graph, like it just doesnt show up, is there something I should know?

silk sky
#

URP Lit - I'm using the checker noise to make a simple checker texture, is it possible to avoid to stretch it while scaling the object?

simple violet
#

i'm not sure

silk sky
#

Not working 😐

#

or it kinda does

#

works well on some faces

#

maybe this is sue to the other problem I'm currently trying to resolve

#

the issue is that on some faces the checker is not visible

simple violet
#

idk

#

if only unity wrote down what each node does

#

it's too confusing to read sometimes

dim yoke
simple violet
#

some nodes aren't descriptive enough

#

they need to show examples and show what they do

meager pelican
silk sky
meager pelican
#

The checkerboard node can be thought of as a texture sample based on the input UV (and other things like color and scale).

#

It's actually just math. No need to even read a texture, even better.

silk sky
#

I think I've set it up correctly, now I'm trying to find why I cant see some sides of the shape

meager pelican
#

Is it a mesh cube or what?

silk sky
#

its a default cube

#

I also tried to delete everything from master and still get that issue

#

Now that I'm testing could be due to the absence of light

#

Ok I can confirm that by rotating the light source that texture become visible on the faces

#

now the question is: how can I make it not (or less) light-dependant?

atomic geyser
#

Hi peeps! Shader question that i can only describe as inheritance 😛
I want to make a shader that extends the Standard shader.
It would look to the tune of

float4 frag (v2f i) : SV_Target
{
  float4 standardColor = base.frag(i);

  if(distToVertex(i) > _MaxDistance)
    return standardColor;

  float4 effect = CalculateOwnShader();
  return Blend(standardColor, effect);
}

Idea being the material shader effect only comes into play within a certain proximity.
Any thoughts?

shadow locust
topaz cipher
#

I Try Reconstruct the world space positions of pixels from the depth texture

#

but screenView is different from GameView

#
            {
                float2 uv = UnityStereoTransformScreenSpaceTex(i.uv);
                // uv = i.pos.xy / _ScaledScreenParams.xy;
                float depth = SampleSceneDepth(uv);
                // Sample the depth from the Camera depth texture.
                #if UNITY_REVERSED_Z
                    depth = SampleSceneDepth(uv);
                #else
                    // Adjust Z to match NDC for OpenGL ([-1, 1])
                    depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, SampleSceneDepth(uv));
                #endif
                float3 worldPos = ComputeWorldSpacePosition(uv, depth,UNITY_MATRIX_I_VP);
                
                float2 projection = worldPos.xz;
                if(_ProjectionEnabled == 1) projection = mul((float4x4)unity_WorldToLight, float4(worldPos, 1.0)).xy;

                float2 uv_clouds = projection * _CloudParams.x + (_Time.y * float2(_CloudParams.y, _CloudParams.z));
                float  clouds = 1 - SAMPLE_TEXTURE2D(_NoiseTex, sampler_LinearRepeat, uv_clouds).r;
                
                color = clouds;
                color = half4(worldPos, 1);
            }```
#

my code hope for help and @topaz cipher 😦

arctic flame
#

what is the world space view direction?

#

World and View are seperate spaces, i don't understand

#

could i get some assistance with the order of operations tto replicate that

low lichen
arctic flame
#

yeah, that's right

#

is this person transforming the view direction into a world-space one? i'm not ssure what they mean

low lichen
#

I mean the direction from the world position of the camera to the world position of the fragment

#

So it's world space

arctic flame
#

ok, so simply the view direction in other words

#

i'm not sure exactly where i'm going wrong in trying to replicate this effect

#

i've got my cube here in the normals view

low lichen
#

The view direction can be in any space, so I wouldn't call world space the "default" space for view directions

arctic flame
#

so i'd anticipate purely blue pixels because positive Z (or is it negative Z from view, not sure)

#

since if the pixel normals all faced the view the object should be purely blue yeah?

#

for sure just assigning the view direction to the normal doesn't work because that makes results like this

sweet cosmos
#

Why are vertex function and fragment function separated instead of being a single function?

low lichen
arctic flame
#

not that you need shader graph to do this but here's what i've got in shader graph

#

the vertex normal is being set to the view vector

#

i guess i'm not quite getting what the person in that post is doing, it doesn't seem as simple as what they made out

#

this approach is 'world space view direction', see that all pixels of the cube have normals the same

#

but this isn't right either, i shouldn't be able to see the shine from this angle

#

since the retroreflector is meant to send light back along it's initial path, not bounce it up to be seen from here

#

i'm a little stumped

languid lagoon
arctic flame
#

does BRP have a normals overlay view

#

that shader was made for BRP so I can't even see the normals view on what it's supposed to look like ;-;

low lichen
#

No, but you can edit the fragment shader to output the world space normal as the color

arctic flame
#

@low lichen

#

i have done this now

#

so here's the comparison of the one i found in the Answers post

#

(normal mapped to albedo)

#

and then mine

#

they seem to match? so i don't know what i'm doing wrong

#

okay so with the help of a new project i determined that the shader in the answers page is actually completely broken

#

and presumably the advice he gave is also incorrect

#

so in that case i've got no leads at all on how to achieve this effect

#

his solution only works for the positive Z

#

ok so yeah im clueless i guess, this sets me back to the very beginning

#

i gotta ask if anyone has made a retroreflector and how they did it

silk sky
#

How can I make so the checker texture doesnt get stretched? I've already tried to put the Position note on its UV but doesnt works...

sweet cosmos
#

what are tiling and offset in a material?

forest hearth
#

Hello, I made a 2D shader that adds pixels in an area bigger than the original Image. How can I make sure that it will not be cut by the sprite bouding box ?

forest hearth
forest hearth
#

It's a UI image

forest hearth
shadow locust
#

I don't see why not

forest hearth
#

a UI image is not a Renderer

regal stag
forest hearth
#

okay

stiff delta
#

I'm currently trying to use a bloom material on some mushrooms but it isn't quite working

#

this is how it should look (+ bloom)

#

and this is how it looks when i apply the material

#

the shader graph is rather simple, so im not sure what i might be messing up

#

there are multiple types of mushrooms and they're all in the same spritesheet, is that a problem with maintex or something?

regal stag
stiff delta
#

that worked

#

thanks a lot

#

:)

somber snow
#

Now you can easily add a Retro feeling to your game with this cool Shader Graph and Render Feature combination. With a few Post-Processing effects on top and that's it you got yourself a CRT / Old TV feeling. Enjoy!

Pixel Art Tutorial: https://youtu.be/JZDlCuIpq9I
Cyan Blit Render Feature: https://github.com/Cyanilux/URP_BlitRenderFeature

✦Rab...

▶ Play video
#

Gives me a fully grey screen

#

Is there a better way of creating a shader with the frame as an input? As in, I'm trying to cell shade a fully rendered scene

gritty steeple
#

Hey guys. I'm working with "NOT_Lonely/NOT_MaskedPBR" shader and it seems to be doing some funky stuff with the lighting and light cookies.

vague ginkgo
#

if I have an object with multiple children objects that all have particles is it possible to apply a shader to the entire parent object(like an outline effect)?

terse nexus
#

Hey everybody! I am trying to make my player cast 3d shadows, but although it is effected by light its not casting shadows

willow pike
#

Anyone here have an understanding of how URP decals in shader graph work? I'm faking some shadows with decals and trying to change the render queue on them to render before my emissive materials (so shadows don't appear to wrap around emissives) However the decal shader graph option doesn't seem to allow render queue changes in the graph or on the material. Any ideas?

keen hill
#

im doing an NES style of game where I want to use a color palette and replace certain colors on an image. Does anyone recommend a shader or asset on the store for this?

keen hill
#

welp, doing it by hand 😄

umbral cargo
#

does Unity have an Object type for Shader Graph assets?

#

example, if I use Shader x = AssetDatabase.LoadMainAssetAtPath(someShader) as Shader; then X will be loaded as a Shader

#

but is there some type for ShaderGraphs?

vocal narwhal
#

Does just Shader load it? Because it should...

umbral cargo
#

I'll have to test some more, perhaps it actually does, and it is shadersubgraph assets that are not.

#

thanks

vocal narwhal
dark forge
#

So I'm very new to shaders, and I want to try and do this:

  • Get a list of colors externally

  • Make an array of those colors

  • and for each pixel:

take the base color, compare it to each of the colors in the list, take the highest value of the comparisons then do something with that.

So I'm good with the actual colors part, I know how to do what I want for two colors individually. but I don't know how to make a list of colors and loop through it, in HLSL anyway.

I know you can define public variables in the properties section of the shader, but I'm not sure how to make an array there, if you even can.

shadow locust
#

You can use a texture. What is a texture but an array of colors really

dark forge
#

huh. good point

#

I'll look into that, thanks!

#

how would I loop through the texture though?

dark forge
#

please forgive what im sure is a super newbie question, but this keeps throwing up the error sampler2D object does not have methods

I don't understand what I'm supposed to put here, I've tried putting a bunch of stuff and they'll pretty much always throw the same error.

#

the documentation says it needs a sampler state, maybe i'm just dumb but I cannot figure out what a sampler state actually is

#

I can't seem to find a straightforward answer

grizzled bolt
arctic flame
#

yeah true

grizzled bolt
#

Pretty sure this method works
differs from the particles a bit because particles seem to reflect the sky, not the baked cubemap, at least in my test currently

arctic flame
#

well the problem is still fundamentally that the reflected light is being reflected by the angle of incidence instead of 180 degrees

grizzled bolt
#

Right, this wouldn't be perfect at angled lights

arctic flame
#

is there way to like

#

make the normals not normalised?

#

cos if you made the magnitude of the normal like

#

idk 100

#

then in the vector math

#

the angle would be more advanced towards the camera position maybe idk

grizzled bolt
#

@arctic flame I dunno why I put world view direction to object normal, but it seems to work perfectly well with any view direction to matching normal

#

At least I can't tell just by looking if it's not physically accurate, though I doubt it is

arctic flame
#

what's it look like in like a turn around?

arctic flame
#

ohh yeah ok this is interesting

#

i noticed you did it to the fragment when i was trying to do it to the vertex

#

i don't really know the difference i suppose

grizzled bolt
arctic flame
#

should you do both at once?

grizzled bolt
#

I don't see a reason to

#

If you can get by doing it in vertex stage that's probably cheaper

#

But you may need to do it in fragment stage anyway if you want to combine it with normal maps, not totally sure

arctic flame
#

that's sick though

terse nexus
regal stag
terse nexus
#

I thought that was part of the base renderer which sprite renderer inherits from

#

I figured out a solution XD Just had to turn on debug and check cast shadows which is inherited from renderer

regal stag
#

Hmm, they both inherit from Renderer. But that does seem to have the shadowCastingMode which you might be able to force from a script

#

Ah yeah, or debug inspector

terse nexus
#

thx though ❤️

vernal pewter
#

Hello, does anyone know how can I reset shader on instantiate.
I have a dissolve shader (brackeys tut), but when I instantiate the gameobject dissolve effect is finished so it never shows, is there a way when I instantiate an object to play that shader effect from start?

shadow locust
#

You should be instantiating a prefab, not your object from the scene

vernal pewter
#

That's what I'm doing, but all prefabs have like global time where the dissolve effect is happening.
And it has Time node going into a remap

regal stag
vernal pewter
#

Good idea, I'll try that. Thanks @regal stag

grand jolt
white sundial
#

How to see sphere from the inside? Can I do it with some fancy shader trick?

loud silo
#

does anyone ever tried this ?

uncut snow
#

I'm currently using the triplanar node in urp and noticed that faces that are not flat have a sort of ghost/overlap effect on them. Any way of fixing this?

uncut snow
#

Might just ditch the triplanar and spend some time mapping the scene correctly

knotty juniper
thin crater
#

Hello! I've done (actually copied and modified a bit) this shader from a youtube video:

#

It is used to apply two different textures on a terrain, and it chooses which one to draw based on the height.

#

It also smooths the border between the textures:

#

Now, I've got a dilemma: how can I do the same thing but based on an array of data? I can pass an array to a shader using a color array, but I have no clue on how to do the same effect I'm having there with that color texture.

#

I need to do it to create different biomes and to change the texture in a point of my world at runtime.

dark bloom
#

Does anyone know how to target different mesh topologies (MeshTopology.Points) via shader graph? If I script a custom mesh using the point topology setting, I'm getting an error in shader graph (missing PSIZE output).

#

It's been super hard to find resources on how to use those different topology settings.

regal stag
dark bloom
#

Ah, I was afraid of that. Thanks for the confirmation though - that'll save me a bunch of time chasing a dead end

regal stag
thin crater
#

Well, yeah, that's what I meant: I create a texture from a color array

#

Then I pass it as a texture to the shader

#

And I basically got an array with the values I want (the texture is an array of pixels)

opal radish
#

Which shader should I use in my bullet trail material to fix it being pink?

shadow locust
#

Any shader that's actually supported by your chosen render pipeline

opal radish
#

Is there a way to check?

shadow locust
#

Check what

opal radish
#

That which shaders would be supported

#

This far ive blindly tried everything and none of them seem to work

shadow locust
#

which render pipeline are you using

opal radish
#

Id guess the built in, havent changed anything other than colorspace

shadow locust
#

DOn't guess

#

check

#

you should know which RP you're using...

#

you picked it when you created the project

#

and it will be that unless you changed it

opal radish
#

Okay so built in, it also says so in my "graphics" tab

shadow locust
#

ok then the default Standard shader will work

opal radish
#

Then my problem lies elsewhere

fervent tinsel
opal radish
#

Alright I fixed it, was a different problem altogether, nothing to do with shaders

opal radish
fervent tinsel
#

that's not really a good way to indicate if SRP is active or not... you should just check the SRP Asset being assigned or not

#

I mean even if you'd have URP active, it would show this there

opal radish
#

Yeah it just says "None"

fervent tinsel
#

yeah that's fine then

#

out of curiosity, what was it?

#

(the issue that caused this)

opal radish
#

I had my playmaker script creating a bullet prefab, that for some reason was not pointing to the right prefab anymore

#

So just me being a newbie lul

#

So, the bullet created had the trail renderer, but hadnt had the material set on it

fervent tinsel
#

also surprised people still use playmaker 🙂

opal radish
#

Its just what I used 5 years ago when I last did any projects

#

Works for a hobbyist 😛

fervent tinsel
#

ah, so you aren't all that new to this 😄

#

yeah, 5 years sounds accurate, playmaker used to be really popular

opal radish
#

Yeah but its a good excuse when you make dumb decisions and ask help publicly lul

fervent tinsel
#

probably harder to get help with playmaker issues nowadays in general

#

but whatever works 😄

opal radish
#

A little bit, but its super easy most of the time so rarely need help in anything that-related

quaint coyote
somber bloom
#

I was follow this instruction, and using Universal render pipeline

#

there is a property that can be added, one of them is a property called float

#

but, this property type doesn't exist in my place

#

But, I still think now it's vector1

mental temple
somber bloom
#

Unity: 2019.3.6f1

mental temple
mental temple
# somber bloom what name ?

Unity just changed the name of Vector1 to float, but the functionality is the same. So the tutorial you're following is just using a newer version of Shader Graph.

somber bloom
#

hmm, So, the new version of shader graph is in 2020, because my unity, 2019, is the higest one, (which is 7.4.3), and no higer version is shown

#

however, I guess everything is still fine, then

mental temple
#

Yeah, it should still work

somber bloom
#

Anyway, thanks for the information.

mental temple
#

I know this might be a lot to look over, but if someone with some shader graph knowledge is willing to help me out, I'd really appreciate it!

I'm working on a grid shader, and everything is working great except for transparency. I have 2 colors (one for outline and one for the base color), and I'd like each of their alpha settings to have their own transparency (if that makes sense). Right now, whenever I set this to Transparent, it just becomes completely invisible regardless of either color's alpha setting in the inspector. Any ideas on what I'm doing wrong/need to change?

somber bloom
#

So, Question

#

I got this

#

and the warning says

#

the active master node is not compatible with the current render pipiline or no render pipeline is assigned

#

nevermind, I found out the reason why

mental temple
#

Changed it to this. I realized somewhere my colors were getting set to (3) instead of (4), so I had to work around that like I did in the screenshot below. Now it works perfectly.

somber bloom
#

oh for the lord's sake

#

why did the whole world become untexturized ?

half flower
#

Would anyone know how to dilate an image in shadergraph?

grizzled bolt
#

SDF textures can be dilated/eroded using step or smoothstep nodes

grand jolt
grizzled bolt
#

A blurred texture can be used similarly to an SDF texture, yes, but loses some detail
I believe both operations are pretty expensive to do realtime

cosmic prairie
cosmic prairie
#

Skip to the jump flood part

pure ivy
#

I'm trying to make a custom low poly water shader, I need to flatten the normals on this outlined plane, how would I go about this? (I'm coding it not usign shader graph)

kindred crater
#

Hey anyone there who could help me combine a crossectionshader with a watershader? I'm stuck - It's hlsl

#

cause I'm stupid☝️

#

I have no idea how to even make it transparent - cause if I set it to transparent on the material's options it's still grey

kindred crater
#

I'd even drop some bucks if anyone could help me remotely....

half forge
#

How can i make the noise not stretch

cosmic prairie
pure ivy
#

Alright, I'll try that when I get home, thanks

half forge
grizzled bolt
half forge
#

I'll try that in a second, my friend is rendering a noise texture for me

#

why does it not fill the entire space

#

only 1/4

grizzled bolt
half forge
#

that makes sense

#

but is there no way for it to fill everything?

grizzled bolt
half forge
#

The entire quad

grizzled bolt
echo flare
#

does anyone have experience sampling an sdf inside a custom function node? Most documentation I found uses data type sampler3D but the node only allows you to pass a 3d texture, so how can I sample it?

meager pelican
dim yoke
#

That icon morph thing is really cool, i can imagine quite many ways to use that in loading screen animations for example

echo flare
grizzled bolt
#

It's really nice
I don't know about 3D SDFs in shader graph though

meager pelican
echo flare
meager pelican
#

So you need a sampler, yes?

#

Maybe generate a code sample using the sample3D node, and see what it does?

regal stag
#

UnityTexture3D should also include the sampler, via .samplerstate

meager pelican
#

Or wait for Cyan to answer,

#

lol

echo flare
#

copying the generated node code is smart, do you know where I can find the documentation for these Unity object types like UnityTexture3D?

meager pelican
#

The only thing I know of is Unity's shader graph docs, and the repository where you can dig through code.

echo flare
#

Ok thank you both, the method calls are equivalent float4 Sample(UnitySamplerState s, float3 uvw) { return SAMPLE_TEXTURE3D(tex, s.samplerstate, uvw); }

mighty grail
#

Hi, I am following the official tutorial on shader graph, in which I need to output an alpha channel from 2d texture asset. However, the alpha channel is gray when I try to connect them... How can I fix this? Any help is appreciated! --Using URP unlit shader graph

cosmic prairie
#

You need to set the shader to be transparent or cutout/alpha clipped

echo flare
#

In the graph inspector, under graph settings

echo flare
#

Check it out, I was able to render the sdf of a mesh inside the volume of a cube mesh

waxen path
#

Hey so i'm writing a shader in Shaderlab language and I've written a couple of simple utility functions, i'm now writing a second shader and want to use those same functions, can I make some kind of shared include file?

#

if so.. how rooThink

echo flare
waxen path
#

does the file need any kind of special directives? the normal file has a lot of preprocessor stuff i dont really understand

echo flare
# waxen path does the file need any kind of special directives? the normal file has a lot of ...

Hmm, it looks like you need to declareexport myFunc() { ... } to link it elsewhere. Without looking at your code, I would suggest pulling the utilities into a separate file and import that file. https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords#export

waxen path
#

i've been slowly learning shaderlab by trying to recreate some of my blender shadergraph shader nodes

#

i'll see if this works rooThink

#

Shader error in 'Custom/SkinShader': Unexpected identifier "export". Expected one of: typedef const void inline uniform nointerpolation extern shared static volatile row_major column_major struct or a user-defined type at Assets/Shaders/util.cginc(1)

#

oh do i not use export if im using just include file

#

oooh that works, ty

meager pelican
waxen path
#

oooooo

#

ty

plucky hazel
#

Does anybody know how to write URP unlit shaders to depth-buffer?

#

I'm using amplify shader editor

#

I think Universal/Unlit Shader Template doesn't write to Depth buffer. So the unnecessary parts gets effected by the dof effect.

#

Just like on the top left corner.

#

This is the depth texture from frame debugger btw

echo flare
plucky hazel
#

I think it already is

echo flare
plucky hazel
#

They are just transparent planes with vertex offset

#

Aha, it throwed an error. Maybe this is why?

#

Problem is these objects, they are using an unlit opaque shader.

echo flare
#

the shader error was thrown in a Lit shader by the looks of it

plucky hazel
#

Yet I don't think the error is the problem because the shader mostly works in right way.

echo flare
#

If you give those blue silos a different shader does the problem go away?

#

I'm confused why the brown part is causing a chop in the silos

plucky hazel
#

The others arent blurred because they have placeholder floor after them

#

the floor is using default material

#

So it writes to depth buffer

plucky hazel
echo flare
#

so are the silos not separate meshes?

plucky hazel
#

No, they are not

echo flare
#

oh

plucky hazel
#

We are playing with new artstyles so they are just some placeholders.

#

Which causes this chaotic shot :)

echo flare
#

not sure I can help 😦

plucky hazel
#

No problem, thx for trying

waxen path
#

so im using SurfaceOutputStandardSpecular for my output struct, how can I do what blender calls "Specular tint"

#

does this property have a different name? rooThink

tacit stream
#

Any tip how to achieve this? It's ID to Color shader. Not sure how to handle syntax

            fixed4 frag(v2f i) : SV_Target
            {
                UNITY_SETUP_INSTANCE_ID(i);
                float ind=    UNITY_ACCESS_INSTANCED_PROP(Props, _Id);
                fixed4 color;
                color.r =(fixed) (ind & 0xFF);
                color.g =(fixed)  (ind >> 8) & 0xFF;
                color.b =(fixed)  (ind >> 16) & 0xFF;
                color.a =(fixed)  (255-(ind >> 24));

                return color;
                
                // return UNITY_ACCESS_INSTANCED_PROP(Props, _SelectionColor);
            }
final spade
#

i really need help rn with a transparency code in my game, i didn't change it one bit from the other game i had it in where it works perfectly fine, but in this other game it doesn't work at all, it is supposed to make the black solid color of the camera's view completely transparent to show the desktop, but it won't, and i covered all the bases to make it happen too

final spade
#

ok seriously, i need help from someone on this i'm losing it. it isn't even the code and i have the transparency settings as a full window, the bottom check ticked as disabled, and no custom pipelines, and the camera has no background and yet it just won't work

narrow furnace
#

hello hello, How do I use a transparent video as a texture in unity URP?
like I want the transparency to be used too instead of it being totally black.

amber saffron
near current
#

Hya. I'm running into a little issue with shadergraph I cant seem to work out

#

I'm generating these lines (rectangles) and trying to overlay them on a texture

#

I've tried all modes for the Blend node, but the Add node seems to give the best result, but Only for white shapes.

#

other colors get different opacity, as you can see

#

How do I correctly do this. So overlay the rectangles on top of a texture, with no opacity?

dim yoke
near current
#

0.5 for all channels?

dim yoke
near current
#

This is how the lines are generated btw

dim yoke
near current
#

Yeah, goes to this

dim yoke
near current
#

Ahh, Thanks! it works, awesome

#

and now I can control the opacity through the channel mask

dim yoke
#

masks are super useful when you want to combine different things together

near current
#

yeah, thanks. finally got my shader working then, great!

dim yoke
#

np

steel notch
#

How low are Line Renderers?

#

Would something like 500 of them be considered a lot? I assume they got more intensive the longer they are.

#

?

charred grotto
#

hey everyone, I'm trying to make a custom shader which supports transparency texture
I made everything else I wanted to work, but the transparency is the only part which gives me a headache
Could anyone help me out with this?

dim yoke
echo flare
lone bone
#

Hi, im trying to convert a Godot shader to Unity from a tutorial video im watching, and they use the code snippet:

#

which uses the variable VIEW, which in Godots documentation means the View vector under its lighting section

#

i was wondering if Unity had a similar function, as I cant find one under unitys shader documentation

simple violet
#

might just be view direction

lone bone
lean lotus
#

Is there any updates or talk about updating to shader model 6 or ways to access shader model 6 yet?

little marlin
#

in shader amplify there's node called "Texture Object Node", what equivalent nodes that comes as that on ShaderGraph ?

sly dew
#

so I got this material that has its base color copy from screen space like this

#

however it doesnt show the TextMeshPro behind it. How can I solve this?

#

The shader itself has alpha as well

sly dew
#

I changed the order of shading and I think it works now

dark forge
#

I'm getting the error "array index out of bounds". I'm not using arrays in my program though, so I'm not entirely sure what it's talking about. The only think I can think is that it's mistaking something for an array? I'm using matrices and referencing them with matrix[0][0]. Additionally, I'm referencing float3s like float[0].

#

here's the full error

amber saffron
naive mural
#

Hello, does anyone know if it's possible to include custom tesselation into shader graph? I know you can include custom buffers/function/data structures via .gcinc files via the "Custom Function" node, though don't know how to do it for tesselation at all.

naive mural
#

@mental bone I'm looking to make custom tesselation for the terrain. Phong tesselation, which is currently included in the shader graph, causes severe clipping issues for physcis on a quad based heightmap terrain.

mental bone
#

Im not sure you will be able to do that with shadergraph

#

Im also not sure how you will get a terrain collider at all out of the tesselation since its a purely visual step that happens on the gpu

tight phoenix
#

in Shadergraph is there a way to fill in the clipped area with a color or texture?
I can turn on Two-sided, which sorta does the job, but is there a way to selectively change the backfaces with a different color or texture?

#

my very basic set up atm

#

I can find lots of resources online of people saying 'turn on two-sided' but no one saying how to then change how the backface looks

#

this could all be an x/y problem, what im really trying to do is cap off the cutaway area

regal stag
tight phoenix
tight phoenix
#

Hmm, how do I combine multiple clipping directions?

#

I tried a few math like add, subtract, multiply, but instead of clipping on multiple axis, it just combines them and the resulting clipping plane gets rotated

#

shaders are hard, I can easily describe verbally what I want to achieve, or draw it, but I have no idea how to make the nodes and math to achieve it

#

I want to clip away meshes between the camera and the camera's orbit point

#

I can clip on any one single axis globally, but I can't figure out how to combine multiple clips to create an L shape

#

and it wont necceessarily be on xyz perfectly either ,its got to rotate but thats a later problem

#

I cant find any tutorials for this though and ive been googling a lot

#

How do you clip away from a point in world space? not a flat clip but imagine an L shaped cut away

#

my attempts to clip on mutiple axis don't seem to work, it wont clip on more than one axis

regal stag
#

The Alpha Clip Threshold is a Float port, so you shouldn't really be putting a Vector3 into it. It will only be using the R/X value

tight phoenix
#

Is it possible to clip away an L shaped portion of a mesh some other way than Alpha Clip Threshold?

regal stag
#

If you want multiple planes try using Step nodes and then combine with Multiply, or Min/Max

tight phoenix
regal stag
#

Yea, or Alpha and set threshold to 0.5.
It clips if threshold < alpha

tight phoenix
#

I am not sure where to insert the Step node into my setup

#

Googling it Im not even sure how to use it at all

#

What is my Edge? I assume the clip space is the In

#

I am not seeing how a single value like R/X is going to be able to cut in 3 dimensions

#

Progress 🤔

#

Hm this isnt right, no matter what values I feed it, it wont clip anything at all anymore

#

it works in the preview, it doesnt work on the real deal

#

yeah no matter what values I feed it, it wont clip

#

I think im just too stupid to do this, I should stop trying to do things im too stupid to do

#

this isnt good enough or anywhere near what I need but its all I can do :/

#

I keep googling "clip on multiple axis" and similar terms but I cant find anything

#

no help, no resource, no tutorials

#

all the tutorials are for totally unrelated useless stuff like dissolve shaders or 'cut a hole in this thing based on camera / player data'

#

I dont want to dissolve or cut a hole, I want to clip away everything around a point infinitely

#

like imagine this is 3 infinite planes all moving away from that intersection point, clip away everything

#

what terms should I be googling?

#

I keep trying clipping or clip but its not returning results I need

#

I hate how stupid I am, i can never achieve anything without someone bottlefeeding me every single step

#

im such a stupid worthless hack, ill never achieve anything of any worth or value, all I can do is fail to imitate everyone who is better than me, who are too busy being better than me to extend a hand to a worthless piece of shit like me

#

i keep trying and trying and trying and failing I and I keep reaching out but no one can help me, or no one wants to help me, its just radio silence :/
no one wants to help a worthless piece of shit like me because they gain absolutely nothing but helping a worthless piece of shit like me, I will never ammount to anything

#

i dont know how to be MORE direct, MORE CLEAR

#

HOw. To. Clip. Model. On. Multiple. Axis

#

zero reuslts, tons of results for completely innane unrelated things

#

im fucking miserable and frustrated and angry

#

this proves its possible, someone is doing 3d spacial clipping here

#

so why I cant find a single resource explaining how its done

#

tons and tons and tons of clipping PLANES but not a single resource on clipping any other shape

quaint coyote
#

Is it the right place to ask about render passes

tight phoenix
#

I dont know, this is shaders isnt it, I need a shader to do this

quaint coyote
quaint coyote
tight phoenix
#

Not sphere, cubic, I want to clip away a cubic area

#

I just hit upon the word 'cross section' which seems to be giving new results

quaint coyote
#

I don’t know if you program shaders or use nodes. But there is another term called SDF = signed distance functions

tight phoenix
#

example of what I mean

#

yeah I am familiar with SDF

#

I dont know how I would use it in relation to a shader though

quaint coyote
#

You can try looking that up as well. Because using sdf you can add specific mathematical ops and render or clip out in 3d

#

But for that you might want to sue a custom node or write your shader

#

I learnt about it while I was looking at making clouds. It uses ray marching

#

You March a ray from the camera and till the time that the sign is not negative you keep clipping

#

Btw there is a hack you might want to try

#

If it’s cubic, why don’t you use stencil buffer with an invisible cube. Use the cube to mask out the area you want to clip and use stencil@buffer to clip that area

#

Then use front and back face separation for adding specific textures… what say? @tight phoenix

tight phoenix
#

how do you describe this

#

what words do you use

#

cross section is wrong

#

clipping cube is wrong

#

nothing I try gives me any answers or any results

#

i keep trying and trying and trying and im not getting any results and im getting so fucking frustrated

#

is this not a solved problem?

#

i am not the dfirst person on the planet to want to do a cross section on more than one axis

#

i dont want a single plane cross section

#

why cant i find a single resource, tutorial, anything at all discussing this

#

does no one here have any idea or clue at all how to do this?

#

cutaway is wrong

#

am i just not worth helping?

#

what do i have to do or say, how much do i have to grovel and beg before im allowed to he helped?

#

i cant do a fucking thing on my own because im a worthless piece of shit, i ghet it, are you happy now? now will you help me? how much more put down do i have to be?

#

i guess despite there being several thousand people online, im not worth a microsecond to a single one of you :/

#

clipping cross section cutaway shader 3D ~cube -plane -simple -flat

#

no results

remote osprey
#

Working on getting Keywords to work on the Universal Render Pipeline/ComplexLit shader and finding they may be broken in Unity 2021.3.2f1? Could use some thoughts on this one - thanks all!
https://forum.unity.com/threads/material-setkeyword-and-enablekeyword-for-complexlit-shader-do-not-function-in-unity-2021-3-2f1.1282946/

plucky hazel
#

I can't build my project after I added my shaders to "Always Included Shaders". Does anybody know how to solve it?

peak ridge
#

does anyone know how stencil values are stored in unity's depth buffer? like, if i sample the depth texture they should be encoded in there somehow right?

echo flare
quaint coyote
peak ridge
#

from what I understand, theyre the same thing though? like if you make a 32 bit buffer, 8 of those are stencil and 24 are depth

quaint coyote
#

Guys! Someone needs to help me understand why adding passes in URP to draw rendered to a render texture doesn’t have alpha in render texture

peak ridge
echo flare
# tight phoenix example of what I mean

@quaint coyote made a good suggestion. I've been working on something similar recently, Here is an example of the process https://www.youtube.com/watch?v=Cp5WWtMoeKg

In this coding adventure I explore ray marching and signed distance functions to draw funky things!

If you're enjoying these videos and would like to support me in creating more, you can become a patron here:
https://www.patreon.com/SebastianLague

Project files:
https://github.com/SebLague/Ray-Marching

Learning resources:
http://iquilezles.or...

▶ Play video
peak ridge
#

yeah I've just tested and verified it is in fact stored in the depth buffer and should be extractable

quaint coyote
peak ridge
#

no, the stencil value

quaint coyote
echo flare
peak ridge
#

hmm i may have spoken too soon. cant replicated it now. but the data should be there somewhere since its a shared buffer.
currently i'm just testing modulos with different values and seeing if the noise changes 😛

tight phoenix
#

Im not sure how any of that applies to what I was working on

#

for starters its in HLSL written scripting, which is about 50,000x harder than shadergraph

echo flare
peak ridge
#

I'm trying to get the stencil values in a single-pass postprocess shader by extracting them from the depth buffer.

#

the way everything is worded makes this sound very possible

echo flare
# tight phoenix Im not sure how any of that applies to what I was working on

You can clip a mesh with a transparent shader pretty easily, like you've already done, but meshes are hollow. Unlit shaders give you the illusion of a "fill", but if you want something to look volumetric, the only way I've learned so far is raymarching. You don't need to write the whole shader in HLSL, just create a custom shader graph node with a for loop inside. I've discovered my dinky gpu struggles with this however

peak ridge
#

if you know the depth value that's being clipped to, you dont need to do expensive raymarching.

echo flare
peak ridge
#

? this isnt getting it in a script, this is setting the buffer to an RT to use in a shader

#

and beside the point, that page is wrong, you can easily do a readback to cpu

echo flare
#

I see, does this help? Depth textures are available for sampling in shaders as global shader properties. By declaring a sampler called _CameraDepthTexture you will be able to sample the main depth texture for the camera.

#

But then the depth value returned is in range 0-1 and the format is platform dependent. *On OpenGL it is the native "depth component" format (usually 24 or 16 bits), on Direct3D9 it is the 32 bit floating point ("R32F") format. * So convert the float to a byte array somehow and then take the last byte?

peak ridge
#

apparently cameradepthtexture is not the raw depth buffer. what I have already assigns the depth buffer as needed, though I can't seem to get the last byte of it in shader easily

#

it may be that what the depth buffer is internally and what gets saved to the render texture differs internally

echo flare
#

perhaps Unity is attempting to normalize the buffer values to operate cross platform?

peak ridge
#

maybe. it looks like they do differ, and there's no way to sample the raw buffer

tight phoenix
#

clipping one plane = so easy a baby could do it
clipping more than one plane = impossible, no one can do this

#

if anyone has any insight, im getting nowhere

peak ridge
#

this looks like relatively simple stencil comparisons

quaint coyote
#

Also stencil buffer is a different buffer than depth buffer

peak ridge
#

RenderTexture.depthBuffer

quaint coyote
#

Ohh… then you need to extract the bits out ?

#

Which means how many bits is the depth buffer that it contains stencil buffer too?

robust thunder
#

Does anyone have experience with using global textures in HLSL under Unity? Everything worked fine when using a per-material texture, but I thought global would fit this use case better. I'm calling Shader.SetGlobalTexture("_BlockTextureAtlas", textureMap); from the C# side, then the shader code is as follows:

Shader "..."
{
    Properties
    {
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" }

        Pass
        {
            HLSLPROGRAM

            #pragma vertex vertex;
            #pragma fragment fragment;
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            uniform sampler2D _BlockTextureAtlas;

            struct VertexParams {
                ...
            };

            struct FragmentParams {
                ...
            };
 
            FragmentParams vertex(VertexParams input) {
                ...
            }

            half4 fragment(FragmentParams input) : SV_TARGET {
                half4 color = tex2D(_BlockTextureAtlas, ...);
                ...
                return color;
            }

            ENDHLSL
        }
    }
}

Any help is greatly appreciated!

#

Things I've tried:

  • Leaving out uniform
  • Separately defining the texture and sampler
uniform Texture2D _BlockTextureAtlas;
uniform sampler2D sampler_BlockTextureAtlas {
    Texture = _BlockTextureAtlas;
}
  • Using Unity's macros (I used these originally for the per-material texture)
TEXTURE2D(_BlockTextureAtlas);
SAMPLER(sampler_BlockTextureAtlas);
half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, ...);
  • Adding it back as a property at the top
  • Scaling the coordinate way up to see if normalization was disabled
  • tex2Dlod, tex2Dbias (the texture does have mip mapping on, so I do suspect one of these is the right choice)
peak ridge
# quaint coyote Ohh… then you need to extract the bits out ?

yeah exactly. but i've tried playing with the depth texture by simply multiplying by large powers of two and doing modulos on them and can't see the pattern shifting as I change stencil values. which it totally should to some noticeable degree. so seems to me that regardless of what you do, the depth texture you have in the end is not identical to the internal depth buffer

#

but would be a lot cooler if it was! imagine all the cool stuff you could do with single pass postprocess effects with those 256 bits 😛

#

actually guess that makes sense, to store 24 bits of depth and 8 bits of stencil you'd have to use the exponent and sign and NaNs and Infs would map to various values, so youd have to do some interpreting to give the user usable depth

torpid sapphire
#

Hey people ! I was wondering if deleting Tangents data from vertices for meshes that won't be using normal maps is okay ? Seems to weight about 30% less.

Is it a good idea or could the Tangents be useful for other operations ? Does Unity get rids of tangents at runtime if it knows it won't be used?
Thank you 🙂

sweet spoke
#

what is this shadder effect called, I want to make it but I don't know how

grizzled bolt
peak ridge
#

light shafts / god rays

sweet spoke
#

thnx alot

dark forge
#

So I'm getting this error "array index out of bounds" and I have no idea why it's giving me this. I looked through my code a few times and I don't see a moment where I'm referencing an out of bounds array. I'm fairly new to shaders so I hope someone more experienced can see what I'm missing lol.

The relevant parts of my code, a bunch of defined functions and when they're called at the bottom:

inline float linearizeSRGB(float inputChannel)
{
    //data from https://www.image-engineering.de/library/technotes/958-how-to-convert-between-srgb-and-ciexyz
                
    float output = 0;
                
    if (inputChannel <= 0.04045)
    {
        output = inputChannel/12.92;
        return output;
    }
    else
    {
        output = pow(((inputChannel + 0.055)/1.055), 2.4);
        return output;
    }
}

inline float1x3 sRGBtoCIEXYZ(fixed4 color)
{
    //data from https://www.image-engineering.de/library/technotes/958-how-to-convert-between-srgb-and-ciexyz
                
    float linearRed = linearizeSRGB(color[0]);
    float linearGreen = linearizeSRGB(color[1]);
    float linearBlue = linearizeSRGB(color[2]);

    //good idea to check your work here
    float3x3 conversionMatrix = {
                0.4124564, 0.3575761, 0.1804375,
                0.2126729, 0.7151522, 0.0721750,
                0.0193339, 0.1191920, 0.9503041
                };

    float1x3 sRGBMatrix = {
                linearRed,
                linearGreen,
                linearBlue
                };

    float1x3 CIEXYZ = conversionMatrix * sRGBMatrix;

    return CIEXYZ;   
}

inline float fXYZ(float XYZ)
{
    //http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html
                
    if(XYZ > 0.008856)
    {
        float convertedXYZ = 116 * pow(XYZ, (1/3)) - 16;
        return convertedXYZ;
    }
    else
    {
        float convertedXYZ = 903.3 * XYZ;
        return convertedXYZ;
    }
                
}

inline float1x3 XYZtoCIELAB(float1x3 XYZ)
{
    //Matrix Values for D65: [0.9504, 1.0000, 1.0888]
    //above taken from: https://www.mathworks.com/help/images/ref/xyz2lab.html

    //http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html

    //float3 D65 = float3(0.9504, 1.0000, 1.0888);

    float XoverXn = XYZ[0][0]/0.9504;
    float YoverYn = XYZ[1][0]/1.0000;
    float ZoverZn = XYZ[2][0]/1.0888;

    float fX = fXYZ(XoverXn);
    float fY = fXYZ(YoverYn);
    float fZ = fXYZ(ZoverZn);

    float L = 116*fY - 16;
    float a = 500*(fX - fY);
    float b = 200*(fY - fZ);

    float1x3 CIELAB = {
            L,
            a,
            b
    };

    return CIELAB;
}

inline float1x3 sRGBtoLab(fixed4 color)
{
    float1x3 linearColor = sRGBtoCIEXYZ(color);
    float1x3 CIELABColor = XYZtoCIELAB(linearColor);

    return CIELABColor;
}
            
inline float CIE76Comparison(fixed4 originCol, fixed4 ComparisionCol)
{
    float1x3 originalLAB = sRGBtoLab(originCol);
    float1x3 compLAB = sRGBtoLab(ComparisionCol);

    float deltaE = sqrt(
        pow((compLAB[0][0] - originalLAB[0][0]), 2) +
        pow((compLAB[1][0] - originalLAB[1][0]), 2) +
        pow((compLAB[2][0] - originalLAB[2][0]), 2)
        );

    return deltaE;             
}

later in fragment shader:

...
colorDistance = redMeanComparison(col, sampledColor);
silk sky
#

I'm trying to make a simple proximity barrier to polish some invisible walls.

How can I change the alpha based on the player (or camera) proximity?

silk sky
#

Current shader, I just need to replace that manual float (0-1) with a value based on camera distance

grizzled bolt
silk sky
grizzled bolt
#

Object position can be changed to geometry position so it works per pixel rather than per object, and makes it identical to the View Vector method

silk sky
#

I tried both approaches but none of them actually altered the alpha so either theyr not working (for some reason) or the actual value get changed so slightly that is not visible

#

I tried also to multiply x10 the result but the result is still the same

grizzled bolt
#

@silk sky It's best to confirm that it's working in the first place by removing other nodes and using it purely as emission, for example

silk sky
#

using an unused "end" like metallic or emission to check the change

grizzled bolt
#

So the distance works, but alpha does not?

silk sky
#

No, i think that distance is not working, I tried to put the "preview" node in emission and the result never got altered at any distance

#

maybe something in the shader setting could be wrong?

#

I just changed the surface type to Transparent

grizzled bolt
silk sky
#

yes

#

I tried to move the camera very far and very near but with no alterations

grizzled bolt
#

Distance can't be altered in preview nodes so it's never a good indicator
Which render pipeline are you using

silk sky
#

I can confirm that the rest work since I was previously used a manual float instead of distance and the result was as expected

#

URP

grizzled bolt
#

Hmm I don't have any more ideas
All three ways work on my end

silk sky
#

mhhh

#

does exist a way to "debug.log" some shadergraph values during Play?

grizzled bolt
silk sky
grizzled bolt
silk sky
#

yes I'll play with the values to get the result

#

thanks for the help tho

#

Updated and working version

#

I have just a last issue: for some reason when I select a Blue-ish color the patter disappears

#

I have no clue on why it happens since the preview is fine

grizzled bolt
silk sky
#

I'll try to split

grizzled bolt
#

why not just

silk sky
#

Fixed now but I get a strange fade effect

#

nvm fixed by switching to unlit

amber saffron
#

Why not simply use a regular float3 ?

ashen lance
#

Hi, I made a texture in Blender. In Blender the rotation of the uv islands are correct, but when I import the texture in Unity, Unity doesn't consider the rotations of the uv map.

So when I use Shader Graph to scroll over the uv map, one of the faces is scrolling the wrong way.

Do you know how to fix it?

#

In Blender, when I scroll down any of those islands, they go up on the model, which is the intended result

#

But the rotations are ignored by Unity

grizzled bolt
#

Or it has multiple UV maps, perhaps

#

Using a temp texture that can visualize directionality might shed light on the issue

ashen lance
#

How do I do that?

grizzled bolt
#

which one?

ashen lance
#

Using a temp texture that can visualize directionality might shed light on the issue

grizzled bolt
#

That means that instead of the "uv grid" in blender you would use the "color grid"

#

It's not a fix per se, but it would help confirm that the UV islands are indeed in correct orientation

#

The color grid has numbers and letters so it's hard to confuse which way it faces

ashen lance
grizzled bolt
#

Yes, do they appear correct in the 3D viewport now?

#

UV editor doesn't actually tell us if the islands are flipped or rotated 180°

#

In blender 3D viewport, I mean

ashen lance
#

Yes

grizzled bolt
#

Every side?

ashen lance
#

All the As are on top all the Hs at the bottom

grizzled bolt
#

So how does this one look in unity

ashen lance
#

one sec

#

One is indeed flipped

#

I imported the model and the texture separately to Unity

#

Couldn't figure out how to import them together

grizzled bolt
#

After ruling out the obvious I have no idea why this would happen

ashen lance
#

How do you usually export a texture, are there specific settings?

grizzled bolt
#

It makes about as much sense to me as unity ignoring changes to the mesh geometry itself
I'd try to duplicate all the faces in the mesh, move them next to the pillar and UV map the new pillar wholly anew and see how they look together in unity

#

Unless the texture itself has flipped parts, that isn't a part of the problem

#

Duplicating the pillar in the mesh would also doubly verify that the mesh is indeed changing in some way

#

Too often I've realised that the changes didn't actually make their way to unity

ashen lance
#

Thanks for your help, I don't really understand what you mean

#

Would you mind checking the model and the uv map directly? I can send you the texture and the model

grizzled bolt
ashen lance
grizzled bolt
# ashen lance

The blend file exports and works fine
The fbx has a flipped face on the UV map and it exports and works fine after de-flipping it

#

I'm guessing you weren't successfully updating/replacing the mesh asset in unity

#

Which is what I meant when suggesting to make changes to the mesh so you can confirm that something happens

ashen lance
#

Ok great thanks, how do I deflip the face?

#

Can you show me a screen shot?

grizzled bolt
#

Since none of the UV islands there are flipped

ashen lance
#

Yeah that's what I meant

#

I did flip it

grizzled bolt
#

I'm guessing it was still the old mesh in your scene

foggy scroll
#

Heyo I wanna learn about shaders for future things,
and currently to make the Toon/Lit have a sort of a small gradient on the edges with a color, so the edges stand out visibly
how hard would this be?
any tips?

ashen lance
grizzled bolt
# ashen lance I still have the same problem

I implore you make some kind of change to the mesh geometry before you export it
Some change you can see in the scene to be sure it's the new mesh file instead of the old one

grizzled bolt
ashen lance
#

Now it works

#

Thanks, I guess I didn't export the fbx again because I thought the problem solely lied with the texture

#

Thanks again man, you saved me a headache

grizzled bolt
vague ginkgo
#

is it possible to apply a shader(like an outline shader) to an entire game object(say one that has multiple particle systems)?

plucky hazel
#

Most of the shaders broke and opaque objects looks invisible in build. Does anybody know how to solve these?

calm rock
#

Hey there,
Does anybody know how to do an early-z prepass in URP and HDRP shadergraph? Specifically with alpha-to-coverage so I can get nice anti-aliasing of a cut-out texture

#

I can see how to do it with a straight shader but in shadergraph (which I'm obliged to use), I can't see how it's done

grizzled bolt
mighty grail
#

Hi, I am following the unity tutorial for shadergraph, in there the tutorial connects position node to position in PBR graph. However, when I try to connect position to position in the URP lit graph, the ball preview in the main preview disappears. Is there any way to fix this? Any help is appreciated! --using view space because the tutorial is using view space

tight phoenix
#

How do I reverse this model's normals so that the lighting of something inside of it doesnt look off?

#

I cant reverse the normals in a separate program, it has to be dynamic

tight phoenix
#

How do I make a shader that looks like this, that cuts away ONLY the intersected space between two meshes?

regal stag
quaint coyote
grand jolt
#

whats the attribute to show changes in editor when code is saved?

tight phoenix
#

again, im a fucking stupid piece of worthless shit, i dont understand any of tha,t im just a fucking worthless idiot who has to be hand fed every single fucking thing because i cannot put a fucking square peg in a square hole without

#

I XANT HANDLE TIHS

#

stop being so fucking condescending

#

dont fuckiung DUDE me

#

i get it, i get it, im a worthless piece of shit

quaint coyote
tight phoenix
#

i am so deep in uncontrolable crisis

quaint coyote
#

You can do it, relax an think.

tight phoenix
#

I dont think i can, literally the reason i am in perpetual crisis is because i cannot do a single fucking thing on my own

quaint coyote
#

Are you in the middle of a deliverable?

tight phoenix
#

im not in the middle of anything im a worthless piece of shit with no friends and no job and no goals and no life, i sit in my fucking room living the exact same fucking day on loop for years at a time, i have stupid idiot dreams of making soemthing great that people will love but i cannot do a single fucking thing

grand jolt
#

how can i update shader in scene view?

tight phoenix
#

because im worthless garbage who is completely untalented, and every single time i try to reach out, do anything, achieve anything, its like screaming into an endless black void

#

post on every single fucking social media piece of shit a hundred times a day, not a single post gets any enguagement because im invisible

#

i cannot handle living in this fucking society as someone who lis terally objhectively worthless garbage

#

if i had any value at all as a human being, people would value me, but they dont, because I dont

grand jolt
#

WTF?

tight phoenix
#

i am on medication, it does fucking nothing
i see therapists, they take my money and tell me to fuck off after an hour

quaint coyote
#

Dude you are already writing shaders that hardly anyone can do. Just relax and calm down

tight phoenix
#

I didnt write any of that

#

those are pictues, from the net

grand jolt
#

yea shaders are pretty hard. I wrote multiplayer game lobby and rooms from scratch. it was a bit easier, tho some iof it was harder

tight phoenix
#

telling people to relax and be calm works LITERALLY NEVER fyi

grand jolt
#

shaders have hard terminology to wrap head around b4 getting good at it

quaint coyote
tight phoenix
grand jolt
tight phoenix
#

trying to help me is pointless, i am in mental health crisis

#

i can clear as fucking day say that, but it in no way allows me to exit being in crisis

grand jolt
quaint coyote
tight phoenix
#

AW GEE YEAH WHY DIDNT I THINK OF THAT JUST TAKE A FUCKING BREAK

#

whn does this hypothetical 'break' end exactly

#

ive been 'on break' since being fired from my last job for about 5 years now

#

how much LONGER do I have to be on break before my fucking life is allowed to start again?

grand jolt
#

I get brain fog if i go coding more than 10 mins. so i need to take a break or I just sit there without being able to finish what im doing

tight phoenix
#

when do i get to feel feelings that are positive again? when do i get to wake up before 2pm? when do i get to have friends, a life, joy, when do i get to be able to control how i feel ?

#

i cannot handle being alive

grand jolt
#

so yea, take a break, come back when you feel a bit more refreshed.

quaint coyote
tight phoenix
#

i dont have a single fucking person or family to rely on, i know this is the shader forum of the unity discord, do you think i have a single other place i could turn if I am posting this here

quaint coyote
#

What you’re trying to do is making a tough shader. Relax and try smaller easier things. That would build your confidence

grand jolt
#

just posting here for everyone that this needs to be checked to update materials

inner zenith
tight phoenix
open quarry
#

Hey guys, if my compute shader works on both dx11 and dx12 is there any reason why it wouldnt on vulkan?

hazy sage
#

Heya ! Sorry for the sudden ping but I had a question about normal maps and triplanar mapping.
You helped me a lot last time and your node library is perfect, however I tried making normal maps and I can't seem to find how to make normal maps work with it

dark forge
#

Thanks for taking a look, appreciate it :)

tight phoenix
#

do you have any tutorials on how to read/write data to a shader, specifically binary data that will change how the effect looks

#

I googled and can find no tutorials, resources, or anything

#

use case example: 3d volumetric fog of war, like a voxel grid of fog, recording where is revealed vs not

#

and then applying shader to the surfaces in the areas that are not revealed

gaunt hemlock
#

Hello, I have a problem with the textures of the particles, the textures are purple

gaunt hemlock
unkempt mica
#

Can I have a light show up only on one camera?

#

And be invisible to another?

analog karma
#

i think you can use layers

unkempt mica
analog karma
#

yeah

#

?

unkempt mica
#

The dynamic real-time spotlight has a layer, and I unchecked that layer on the main camera, yet I still see it

analog karma
#

oh

unkempt mica
# analog karma oh

If I can't use a culling mask to remove a light from the POV of one camera, could I brighten up the view of the camera in which I want to see in the dark?

#

Like via post-processing or something

sour lantern
#

Hey,

Im working on a horror game where its completely dark (appart from lights here and there for important player progression I have a toon shadder (https://www.youtube.com/watch?v=whmPkDp3dqo) that works but doesnt make it completely dark at the end. Ive tried things here and there and the closest ive gotten was to make it basicly only have 2 colours. (idk how to explain it too well without images sorry). idk shader graphs that well so any help would be appreciated.

✔️ Works in 2020.1 ➕ 2020.2 ➕ 2020.3 🩹 Fixes for 2020.2 and .3:
► When you create a shader graph, set the material setting to "Unlit"
► The gear menu on Custom Function nodes is now in the graph inspector
► Editing properties must be done in the graph inspector instead of the blackboard
► In Lighting.hlsl, change the line "if SHADERGRAPH_PREVIEW...

▶ Play video
#

what i have

#

closest ive gotten

grand jolt
#

any math that can be moved from fragment shader to the vertex shader should be done so. Can I have an example on what type of data should be moved from fragment to vertex?

grand jolt
white coyote
#

Guys, there is a question. Unfortunately, I'm not good at English, and I can't find information in my native language.
Matrices M/V/P, MV/VP/... and so on - what space are they in?View, World, Local, Clip?

As I understand it, then
unity_ObjectToWorld - Model space to world space transform.
unity_WorldToObject - Inverse of unity_ObjectToWorld.
UNITY_MATRIX_V - World space to view space transform.
UNITY_MATRIX_P - View space to clip space transform.
UNITY_MATRIX_MV - Model space to view space transform.

Vertex data - world space

charred berry
#

Does anyone know or have reference/documentation on how to do Gouraud shading in unity as apposed to phong, im WAYYY out of my field in this and I really cant find anything on it.

tacit parcel
#

iirc, gouraud is calculating lighting in the vertex stage then interpolate it in the fragment shader

dim sequoia
#

I'm using a Surface Shader with Standard Lighting model for a projector material in the builtin render pipeline, sadly, this results in an unpleasant shadow being cast, here seen in black.

Any ideas on how to bypass this, are there any tags or pragma statements I can use?
"ForceNoShadowCasting"="True" - doesn't work

I also checked the enabled keywords on the surface material that weren't added by me, and I disabled all of them in code, the shadow was still cast.

Does anyone have experience with how to circumvent this issue? Or what other lighting model or configurations I could try?

Here is how it looks, ideally there should be no black parts

#

Or has anyone gotten a surface shader to work on a projector material without it casting such shadows? (or seems like it might be a fragment in the projection itself)

meager pelican
# white coyote Guys, there is a question. Unfortunately, I'm not good at English, and I can't f...

They are "just" matrix data. They convert to a space. So objectToWorld converts from object-space to world-space. WordToObject is the other way around. Etc.

Vertex data comes into the vertex stage in object space. It gets converted to clip-space by the vertex stage. Could be converted to any other space in addition, and stored in the v2f data, as the programmer wants/needs.
The spaces can get confusing.

dim sequoia
#

the descriptions you posted for the matrices tell the spaces they convert from and to already,
when you are in the vertex pass, you will usually get the information in object/local space

#

from the incoming appdata input

white coyote
#

But when in pass, are they already transformed?

#

When I work with vertex pass, do I work with local vertexes?

dim sequoia
#

Input data, like vertices or normals in the builtin pipeline (I guess it should be the same for newer ones) would be default come in object space/local space into your vertex method, then they are usually transformed into clip space and passed to the fragment pass

white coyote
#

I meant it that way)

dim sequoia
#

so in a vertex pass, you already work with local vertices by default. There is an instance where it is annoying though, baked skinned meshes (like if you bake them into a separate mesh), because by default it will take the position and rotation of the skinnedmesh renderer as origin, but will not include the scale the skinnedMeshRenderer transform

dim sequoia
white coyote
#

Last question. As I understand it, to get the camera matrix, reverse view matrix is enough, isn't it?

#

I've just been sitting here all night (I've never written shaders, I haven't worked with matrices). It would be possible to find it on the Internet, but I have a mess in my head by morning) But, in general, I am already close to the truth and, one might say, figured it out) Thank you very much)

dim sequoia
dim sequoia
#

I don't really handle matrixes well either, but as far as I understand it, if you have a matrix that transforms from one to another space,
you can transform the other way around by inversing it,
I think that happens by multiplying a matrix by 1 / it's determinant

#

Maybe we should ask - what do you want to do or what feature do you wanna write with that knowledge?

white coyote
#

No, just experiments with matrices) I want to learn to understand them a little better) With my own head)
Actually I have already received enough information to continue + especially your article is very useful! so compact, everything is needed without bloating
*And Unity has all the necessary tools to quickly visually see the results)

dim sequoia
somber snow
#

[Disclaimer: I am terrible with shaders]
Hey, I've been struggling to make a toon shader. First I tried making the lighting through shader graph in URP with a simple (I think it's called) Lamber model and a custom subgraph (which I stole from a user in this channel) for recieving shadows but they looked awful, I am now trying to code a standard surface shader in the built-in renderer but now that I look at the shadows in built-in, they look even worst.
So, should I try and improve the shadows in built-in/URP? Or should I try on HDRP with coded/graph shaders?

white coyote
dim sequoia
#

the concepts are the same,
surface shaders are usually not well suitable if you want toon shading because they have more realistic, sometimes physically based lighting models by default,
but if you implement your own lighting function, or use a vertex fragment shader, or if you use a shadergraph:

basically you could get the dot product between the normal direction of each pixel of the model and the view direction of the camera. you'll get a value between -1 and 1. Based on this value you can decide on a shadow color you multiply the original color with.
no shadow would be a shadow color of white (1,1,1,1) - so that the input color stays the same.

I don't have a specific tutorial for you, but if you look up more about toon shading/cell shading, I'm sure you'll find plenty of tutorials

#

Ned Makes Games has pretty good tutorials, although I haven't watched this one:
https://www.youtube.com/watch?v=RC91uxRTId8

However, I watched this, and it was super interesting. If you have the basics of shadergraph down, you might be able to implement something like this
https://www.youtube.com/watch?v=mnxs6CR6Zrk

✔️ Works in 2020.1 ➕ 2020.2 ➕ 2020.3 🩹 For 2020.2 and .3:
► When you create a shader graph, set the material setting to "Unlit"
► The gear menu on Custom Function nodes is now in the graph inspector
► Editing properties must be done in the graph inspector instead of the blackboard
► In Lighting.hlsl, change the line "if SHADERGRAPH_PREVIEW" to "...

▶ Play video

Let's figure out how The Legend of Zelda: The Wind Waker was able to pull off cel shading at a time when nobody else was able to.

🐦 https://twitter.com/JasperRLZ
💰 https://patreon.com/JasperRLZ
🤼 https://discord.gg/bkJmKKv
🌎 https://noclip.website

🎵 Jasper - Epoch ( https://www.youtube.com/watch?v=DDmzbYV0d9M )
🎵 Allister Brimble - Fluidity - ...

▶ Play video
somber snow
somber snow
dim sequoia
#

and like Rocco says, it's important to have the normals of your model setup correctly,
usually, artists who purposefully make their models for toon shading play with topology and custom normals so that the model looks well from each lighting direction

#

ah, maybe it would be easier to not use a surface shader and start with a vertex fragment shader (there is less magic going on), or if you disabled receiving shadows

somber snow
dim sequoia
#

on the renderer, should be possible in the shader too but nto sure how

somber snow
#

I've tried to get them working in 3 different ways now

dim sequoia
#

oh 😅

#

I never did those calculations manually,
am currently having shadow issues with my shader too, it's not casting them anymore, but it also doesn't receive any

dim sequoia
amber saffron
amber saffron
civic fern
#

i have a graphic which i want to combine a color and a background color - i have the two bits set up (make the texture green, the background red), but i dont know how to combine them into one graphic. this was my best attempt.

#

i think Add is being weird, right? adding (0,0,0,0) to (0,1,0,0) would equal green for the green pixels ... right? help would be appreciated ^^

regal stag
#

Can use a Saturate node to clamp between 0 and 1

hazy sage
normal solar
#

Hey people!! are there any good resources about translating custom builtin RP shaders (Cg) to URP (HLSL). Unfortunately I am more experienced with GLSL and never really wrote much Cg or HLSL. It seems like it might be an easy task but I am a bit stuck in a rabbit hole of one error solving after the other with no real end in sight.

I am trying to convert this awesome tool to URP: https://github.com/RoyTheunissen/GPU-Spline-Deformation/blob/master/Shaders/Deformation Lookup Shader.shader

GitHub

Baking spline deformation to a texture then applying it to a mesh via a shader. - GPU-Spline-Deformation/Deformation Lookup Shader.shader at master · RoyTheunissen/GPU-Spline-Deformation

regal stag
civic fern
#

that did the trick! ty!

hazy sage
#

The top part is for the texture

amber saffron
livid pond
#

isn't the vertex position that is passed to the vertex shader supposed to be in model space ?

#

col.rgb = normalize(i.vertex) * 0.5f + 0.5f;

#

this should give me the same color despite where the camera is

#

but it acts like its view space

livid pond
#

nvm it was my mistake

dim yoke
# livid pond nvm it was my mistake

what was it? did you use UnityObjectToClipPos in the vertex function ig? also note that interpolator with SV_POSITION semantic will not be the same in fragment shader as you set it in vertex shader (I think unity transfers it automatically from clip space to pixel coordinates or something like that)

quaint coyote
normal solar
#

That's what I did (or at least tried to do...)

#

I'll check the example, thanks a lot @quaint coyote

#

I will try again

quaint coyote
#

What errors are you getting?

normal solar
#

🙂 THat's the problem, I either get no errors and a flat white shader or an error complaining about fixed4 not existing (the code does not include fixed4, I switched it all to float4)

#

But I see from the example code you are sending many things I could try.

quaint coyote
normal solar
#

I am pretty sure I was making a mess with the arguments/return values of the vert and frag functions

quaint coyote
#

Hmm, might be. Good luck though 👍
If you get any errors drop them in here. If there’s anything I could understand from them, I’d help you out. 👍

normal solar
#

Super cool @quaint coyote thanks so much!! I had to skip to the next task cause I am running a bit late but I will get back to it soon and post stuff here. If I manage to convert it properly I will commit it to a fork of the repo and make a PR then you guys can also use it if you need.

fervent flare
#

Does anyone have any idea how I would go about widening a texture gradually?

#

The obvious parameter to tweak is Tiling, but that does not increase the size based on a center point. It extends the texture starting from a corner point.

#

my math kung fu is weak I know

dim yoke
woeful zealot
#

Not sure if this is the right place to ask this, but I am getting a weird issue when Unity compiles my shader. Specifically this function:
float GetHue(float2 pos, float angle) { float rads = radians(angle); // this line seems to be the issue, it complains about swizzle. return pos.x * cos(rads) - pos.y * sin(rads); // If I instead do this I get no compilation error: // return 1.0f; }

Unity gives me this error when it compiles the shader:
GLSL compilation failed: 0(46) : error C1031: swizzle mask element not present in operand "z"

#

when calling this function I am just passing in i.uv and a material defined float angle from the standard frag function

quaint coyote
woeful zealot
woeful zealot
# quaint coyote Replace rads with 0.0 once and try?

after testing more the issue seems to be with using my angle variable. If I change it to:
float rads = radians(0) or float rads = 0.0 * PI / 180.0
it compiles fine, but if I use
float rads = radians(angle) or float rads = angle * PI / 180.0
I get the error

regal stag
#

Its likely to do with how you calculate that angle variable

woeful zealot
#

aha i found the issue, it was weirdly that I had previously setup my _speed variable (another float) as a float2. I am unsure why that was affecting the use of the angle variable, but now that I have made that change, it doesn't complain about using angle anymore

#

thank you!

fervent flare
#

Anyone know how to go about fading only the beginning or end of a line renderer material ?

#

The harsh ends looks so bad and amateurish

#

but I'm using a shadergraph for my material, so I cannot make use of soft particles feature 😦

meager pelican
fervent flare
#

I have! That simply does nothing. Even when I add an excess of points to the line, the color and alpha of the gradient just get ignored entirely

meager pelican
#

That's with ??YOUR graph??, but have you tried it with a standard particle material?

fervent flare
#

standard particle material does use the gradient. But I do need my own shadergraph because I'm doing bullet trails and I need two textures scrolling along the x direction at different speeds for the effect 😦

#

Is there some setting I can add to the shadergraph to make it consider the gradient settings of the line renderer ?

meager pelican
#

IDK off the top of my head, but you can try vertex colors. IIRC particles (and maybe line renderers) use vert colors.

#

So maybe the line renderer is setting the vert colors on the line's vert points.

fervent flare
#

oh yeah I'll look into that!

meager pelican
#

Otherwise I'd have to research, which you can do too now. See how the particle shaders work for your rendering pipeline. There's also code repositories for them, depending on pipeline.

dark forge
#

I'm new to shaders, so forgive the newbie question lol. But as I understand it, when the shader compiles, it checks to see how many iterations a for loop will go through before running the code, right? That's called unrolling if I'm not mistaken.

So, I have a for loop that runs for every pixel in the width of a texture. Assembled like this in the fragment shader:

{
  ...
}```

So, this doesn't need to be unrolled.. because of reasons I don't understand. 

However, when I put this same loop in an if statement:

if (condition)
{
for (int j = 1; j < _Palette_TexelSize.z; j++)
{
...
}
}

Suddenly it returns this warning: 
`gradient instruction used in a loop with varying iteration, attempting to unroll the loop at line 347` 
and this error:
`unable to unroll loop, loop does not appear to terminate in a timely manner (607 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number at line 342`

Why does it have issues with the same for loop in an if statement, but not otherwise? How would I fix it?
low lichen
dark forge
#

Right, that I understand, but then why only return the error in the if statement?

#

the loop works fine normally

#

but when I run it again, (it runs once normally, then again based on a condition defined in the if statement) it gives the error ONLY then

low lichen
#

It's because you're using a "gradient instruction" inside an unrollable loop. A gradient instruction is something like tex2D.