#archived-shaders

1 messages ยท Page 98 of 1

warm pulsar
#

The Render Pipeline Converter can only upgrade materials using built-in shaders (it needs to know what to replace them with)

#

A shader is a program that computes what a surface should look like. A material uses a shader and lets you configure things like color and smoothness.

round coyote
#

what shader do i use?

warm pulsar
#

Unity has multiple "render pipelines". The built-in render pipeline (BiRP) was the only one for a long time; now we have the universal render pipeline (URP), which is what you're using

warm pulsar
#

click on it in the project window and then screenshot the inspector

round coyote
warm pulsar
#

hm, so the ones named "TMP" are for TextMeshPro

#

which lets you render text

#

Look at the one used by the mirrors

round coyote
warm pulsar
#

You can find it by clicking on the mirror. You should see a "MeshRenderer" component in the inspector

#

that one's okay

#

but it looks like it's using another material

round coyote
warm pulsar
#

Can you stick it on a cube?

#

That's odd. It looks like it's mostly working right

#

you can see reflections on it

#

Oh, is your skybox also an error shader right now?

round coyote
warm pulsar
#

nah, that's fine

round coyote
#

its good on cube

warm pulsar
#

what if you put the cube in the room?

#

I wonder if there is a bad reflection probe in there

round coyote
#

turns pink

warm pulsar
#

This is a reflection probe. If you click on it and deactivate its object, does the color go away?

round coyote
#

yup

warm pulsar
#

hm, that's pretty weird -- a reflection probe just displays an image

round coyote
warm pulsar
#

Ah, there's the issue

#

It is a realtime probe. That means it's constantly capturing the scene.

But they're turned off right now, so they break

round coyote
warm pulsar
#

I'd consider using a baked reflection probe here. That won't capture the scene in real-time, of course

#

switch it to Baked and then click the bake button

round coyote
#

ok done

#

works, thank you ๐Ÿ˜„

stray orbit
#

What is the best method to clip a ray to the frustum? I have a start position and an end position for a ray. the direction needs to be preserved but if the end position is outside the frustum i would like to adjust it to the edge of the frustum. I also convert these values to clip space. maybe it's easier there?

                float3 originVS = posVS;
                float3 endVS = posVS + R_view * 500;
astral turret
#

Experimenting. been slowly working on displaying large amounts of sprites. With transparencies.

I'm wondering. Is there a way I can manually depth test... Against solid?

Aka draw all the solids first. Then mix the existing pixel with the transparency if and only if the transparency is closer than the solid depth

#

Seems complicated but if done right would tackle a lot of treatment of transparency

warm pulsar
#

Yeah, you can read depth and then discard the pixel if your fragment position is too far away

#

i was just doing that last night, actually, to add a "depth fudge" to a shader

#

so that it appears through walls, but only a bit

#

That's not the hard part of drawing transparent stuff, though

#

The hard part is when you have overlapping transparent objects

astral turret
#

So it's the color mixing... Can that be done on something like a buffer and then applied?

#

I figured that might be the hardest part, heh

warm pulsar
#

Transparent rendering normally happens from back to front, and if you don't have overlapping renderers (as in, they intersect one another), that results in proper blending

astral turret
#

But when they do intersect...

orchid sparrow
#

Hi !

I'm currently trying to create an unlit shader (using shader graph) that can receive shadows, so it needs main light and additional lights.
I'm going with main light first, everything works as for a normal material but one thing : I don't receive shadows.
I think the problem is about the lightmap UV, but idk how to do...

Here are some pics :

#
#ifndef CUSTOM_LIGHTING_INCLUDED
    
    #define CUSTOM_LIGHTING_INCLUDED

    void CalculateMainLight_float(float3 WorldPos, float2 LightmapUV,
        out float3 Direction, out float3 Color, out float Attenuation)
    {

        float4 shadowCoord = 0;

        #ifdef SHADERGRAPH_PREVIEW

            // Out
            Direction = normalize(half3(1.0f, 1.0f, 0.0f));
            Color = 1.0f;
            Attenuation = 1.0f;

        #else

            // Variables
            float2 lightmapUV;
            OUTPUT_LIGHTMAP_UV(LightmapUV, unity_LightmapST, lightmapUV);
            float4 shadowMask = SAMPLE_SHADOWMASK(lightmapUV);

            // Shadows
            float4 positionCS = TransformWorldToHClip(WorldPos);
            #if SHADOWS_SCREEN

                shadowCoord = ComputeScreenPos(positionCS);

            #else

                shadowCoord = TransformWorldToShadowCoord(WorldPos);

            #endif

            // Out
            Light mainLight = GetMainLight(shadowCoord, WorldPos, shadowMask);
            Direction = mainLight.direction;
            Color = mainLight.color;
            Attenuation = mainLight.distanceAttenuation;

        #endif

    }
#
    void CalculateMainLight_half(half3 WorldPos, half2 LightmapUV,
        out half3 Direction, out half3 Color, out half Attenuation)
    {

        half4 shadowCoord = 0;

        #ifdef SHADERGRAPH_PREVIEW

            // Out
            Direction = normalize(half3(1.0f, 1.0f, 0.0f));
            Color = 1.0f;
            Attenuation = 1.0f;

        #else

            // Variables
            half2 lightmapUV;
            OUTPUT_LIGHTMAP_UV(LightmapUV, unity_LightmapST, lightmapUV);
            half4 shadowMask = SAMPLE_SHADOWMASK(lightmapUV);

            // Shadows
            half4 positionCS = TransformWorldToHClip(WorldPos);
            #if SHADOWS_SCREEN

                shadowCoord = ComputeScreenPos(positionCS);

            #else

                shadowCoord = TransformWorldToShadowCoord(WorldPos);

            #endif

            // Out
            Light mainLight = GetMainLight(shadowCoord, WorldPos, shadowMask);
            Direction = mainLight.direction;
            Color = mainLight.color;
            Attenuation = mainLight.distanceAttenuation;

        #endif

    }

#endif
regal stag
# orchid sparrow Hi ! I'm currently trying to create an unlit shader (using shader graph) that ...

Assuming URP, there's some keywords needed to receive shadows which you can define in the Blackboard (or I think as #pragma multi_compile ... in the code)

  • Enum Keyword, Global Multi-Compile "_MAIN_LIGHT", with entries :
    • "SHADOWS"
    • "SHADOWS_CASCADE"
    • "SHADOWS_SCREEN"
  • Boolean Keyword, Global Multi-Compile "_SHADOWS_SOFT"
    A workaround is also needed to undefine something that causes errors in unlit graphs : #undef REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR
    See "Main Light Shadows" section here for example : https://github.com/Cyanilux/URP_ShaderGraphCustomLighting/blob/main/CustomLighting.hlsl
    (Alternatively just install that package and use its subgraphs, which already contain the keywords too)
cobalt mist
#

Hello!

Working on a custom skybox shader rn. I was wondering if there was any way to tile sprites / textures within my skybox shader to draw stars like above? Been searching online but could find no information on this.

foggy bison
rotund tundra
#

(urp) i have a bush (spiral mesh), but for some reason it renders from the inside out?
i dont really know enough shadergraph to resolve this

marsh mirage
#

Hi Everyone!, i am looking for a way to pre load/compile shaders async with a loading screen, but using a shader variant group and using it to warm up progressively doesn't make much change it still lags in the game.

grizzled bolt
tacit parcel
marsh mirage
tacit parcel
#

are you sure its the shader preload that causing the lags? iirc, shaders are precompiled into binary during build, not on runtime. Maybe it was caused by texture loading into gpu.

marsh mirage
tacit parcel
#

shader compile should only happen in editor, not on runtime, iirc. Have you profile the game and check what causing the lag?

marsh mirage
tacit parcel
#

well, if it's unreal and the devs are too lazy to cook the shaders/material, then it might be true...

marsh mirage
#

let me try the quad trick

tacit parcel
marsh mirage
tacit parcel
warm pulsar
tight phoenix
#

How do I set up a stencil to not write to the depth buffer if its occluded by another object?
Seen here the dragon (behind) is writing to the stencil and im using that stencil to omit the full screen shader (blue tint) but I don't want to be able to see that ommission if something is overlapping it

#

easier to see the problem here, the stencil is completely occluded but still being written

#

Is the problem maybe something in here?

#

Setting the Queue to Geometry+1 instead of -1 seemed to have fixed it UnityChanThink

worldly kiln
#

Hey, I have a fullscreen shader and i need it to render on my canvas, except it wont, any way i can make the shader apply to the canvas?

lean phoenix
#

Hey guys

#

How do you put it together in unity on urp?

lethal patrol
#

hey did Unity change shader code recently TMP is giving me an issue when i try to build but not when i play in the editor ?
Shader error in 'TexteMeshPro/SRP/TMP_SDF-HDRP LIT': no matching function for call to 'GetSurfaceNormal_float' at LIT.shadergraph(12716) (on d3d11)

rare wren
rare wren
ebon basin
#
{
    //UNITY_SETUP_INSTANCE_ID(IN);
    //UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);

    // Setup SurfaceData
    SurfaceData surfaceData;
    InitalizeSurfaceData(IN, surfaceData);

    // Setup InputData
    InputData inputData;
    InitializeInputData(IN, surfaceData.normalTS, inputData);

    Light mainLight = GetMainLight(inputData.shadowCoord);
    half shadowAttenuation = mainLight.shadowAttenuation;

    // Simple Lighting (Lambert & BlinnPhong)
    half4 color = UniversalFragmentPBR(inputData, surfaceData);(inputData, surfaceData); // v12 only

    color.rgb *= (shadowAttenuation * _ShadowFactor);
    color.rgb = MixFog(color.rgb, inputData.fogCoord);
    color.a = 1.0;
    //color.a = OutputAlpha(color.a, _Surface);

    return color;
}
ENDHLSL```
Little rusty on this stuff, but where do I go about modifying the lighting projected onto these objects by other objects? Modifying the shadowAttenuation does squat and seems to only change the overall (ambient) brightness of the object.
#

Everything is kinda solid black there

#

Swear I've solved this before but think I've cleaned up the code by mistake

#

Ohh, scene lighting itself actually does fix the issue

#

I guess that's being applied after

#

Surprisingly my issue on self-shadowing from the last time dealing with this shader disappeared

ebon basin
#

https://i.imgur.com/2HWoGff.png
im not understanding why my water ripples are stretching with distortion like that. Only seems to occur when it's near the edges of the viewport, but if I'm right on top of it it's fine.

#

not really doing anything special with the UVs besides some gradient noise

regal stag
warm pulsar
#

It can't possibly get blocked by anything later in the queue

#

You could also just use Geometry, although that could cause some anomalies with overlapping renderers

#

Even if another object winds up covering its pixels up, the stencil buffer has already been changed

#

It's a lot like how transparent rendering causes weird sorting issues

tight phoenix
#

in the same way transparent renderers can fail to sort right

#

I didnt see any obvious wrong layering when setting to geo+1 though

ebon basin
#

Maybe unity's plane is just terrible

ebon basin
#

inverse fresnel kinda fixes the issue by just not distorting on the edges I guess

tight phoenix
#

Question: I'm trying to port a Kuwahara filter to a shadergraph Fullscreen render pass.

The original shader wants inputs of Texture2D and SamplerState, but what I have is the blit source.

Is this port not possible because I haven't got the blit as a texture2D? Or can it be converted to pass in the blit as a float4?

#

Part of me thinks this port is impossible because the shader is running per fragment and it doesn't have the kuwahara pixel quadrants to work from?

#

or am I wrong and the blit contains the full pass?

#

Kuawahara needs to be able to sample neighbours so how do these other implementations work if the shadercode is only running on a single fragment, where do they get their neighbours from and how can I reproduce that in a custom code node for a fullscreen render pass?

#

https://www.danlivings.co.uk/blog/oil-painting-effect-shader-unity/
this person does have a functional implementation of kuawahara as a URP render feature, but the reason I am not using it and am trying to port those other versions is because this verson doesnt use the stencil buffer and I need to stencil out some things from the effect to not be filtered

#

and I dont know how to edit their code to add that, I am too inexperienced with writing actual code shaders vs. building them in shadergraph

#

this is what I am trying to do because I dont know any other way to get both a full screen pass of kuawahara and stencil buffer out part of it

regal stag
tight phoenix
#

Yeah thats exactly what I was trying to do

#

but the problem was all the implementations want to compare pixel regions, but I dont have pixel regions to pass into the custom node, all I have is the float4 from the BlitSource

#

im not aware of any way to sample the Texture2D directly in shadergraph

#

this is where/how im getting the blit source

regal stag
#

If you right-click the URP Sample Buffer node you should be able to look at the generated code it uses and copy that

tight phoenix
#

Oh I didnt know about that, let me look now

regal stag
#

Something like = SAMPLE_TEXTURE2D(_BlitTexture, sampler_PointClamp, uv) maybe

warm pulsar
tight phoenix
#

That actually is no longer true, stencil support is in

#

I was surprised as well

warm pulsar
#

sweet

regal stag
#

Fullscreen graph does have stencils now yeah

tight phoenix
#

full screen pass using stencils to not write to some of them

regal stag
#

But not other types ๐Ÿ™ƒ

warm pulsar
#

Ah, okay

vernal kraken
#

Hey guys! Sorry to interrupt. I am wondering if anyone can help me here with something that should be simple? I want to do a swaying effect on the masked area of my model (the black and white image) but it doesn't seem to work. I'd really appreciate any help

warm pulsar
#

lol lmao

#

just give me stencils ๐Ÿ˜ญ

warm pulsar
tight phoenix
warm pulsar
#

Did you mean to multiply?

vernal kraken
vernal kraken
tight phoenix
#

I assume this wont work for me to call for _MainTex as an input in order to get ahold of it

warm pulsar
tight phoenix
#

maybe I CAN just get ahold of it?
Nope that didnt work

regal stag
#

If you're only going to be sampling in the custom function you don't even need to define it in the blackboard. I would just define it in the hlsl file used by the custom function.
TEXTURE2D_X(_BlitTexture) & sample with the LOAD_TEXTURE_X_LOD like it does

vernal kraken
warm pulsar
#

also, what does "not working" mean?

#

and where are you using this?

tight phoenix
#

The problem I am facing is I don't know how to access it, I only comprehend inputs and outputs here, how do I make the HLSL file summon it from the same place this exposed code is using?

vernal kraken
tight phoenix
#

If I just write this in my HLSL custom node file:
"TEXTURE2D_X(_BlitTexture);"
somewhere, will it 'just work' to get that file from the inputs?

#

not sure why its an _X either

regal stag
#

It doesn't need to be in inputs. Like the function defined here it's not a parameter. The texture is defined before so it's acessible from any code after it.

tight phoenix
#

I assume I cannot just write it and have it just work, but I am not versed in written shader code specifics enough.

I can change stuff from vectors to floats and change returns to Outs but my ability to port is not much beyond that ๐Ÿค”

#

Right but that's the URP sample buffer code

warm pulsar
tight phoenix
#

Or are you saying I should copy paste the sample buffer code, and edit it, instead of trying to write a custom node?

#

I am not experienced enough to know what parts to remove or not when trying to slim down the huge generated code file for the URP Sampler Buffer

#

or like, where to inject my new code

#

I know I don't know enough, but the only way to do is by trying UnityChanThink

vernal kraken
warm pulsar
#

look at the actual material

regal stag
tight phoenix
#

Right but how do I pass it in?

#

I think the problem is im not understanding where its coming from or how its getting it

#

Ill just do what you say and copy paste it completely directly

warm pulsar
#

The custom function code gets compiled along with all of the other ~stuff~ in the shader

vernal kraken
tight phoenix
#

copying the whole thing didnt work which I assumed it wouldnt

warm pulsar
#

You can declare all kinds of stuff in there, like compute buffers

warm pulsar
tight phoenix
warm pulsar
#

and then TEXTURE2D expands into a variable declaration

#

You'll definitely need to include something here

#

I actually don't know what, though! I've mostly done handwritten BiRP shaders

#

the bits of custom functions I've done in the HDRP haven't touched textures yet

tight phoenix
#

It says undeclared identifier _blit texture, which I assumed since you cannot just make it summoned by writing that one line alone

warm pulsar
#

The issue is that it doesn't understand the macro

tight phoenix
#

Ill look in the decompile code?

vernal kraken
tight phoenix
#

generated code rather*

warm pulsar
#

Look at each material. Do they have a mask texture assigned?

warm pulsar
warm pulsar
#

Assign a mask texture.

tight phoenix
warm pulsar
#

You get a white texture if nothing is assigned (by default, at least)

tight phoenix
#

Here is the code from the node

regal stag
tight phoenix
#

I am not understanding how the custom node is 'getting' the blit texture2D, like nothing in the code is giving it, it cant come from nowhere

#

which is why I am so stuck on the idea of 'where is it passed in from'?

vernal kraken
tight phoenix
#

Because to my knowledge, it has to come from somewhere and be defined somehow to recieve

tight phoenix
warm pulsar
warm pulsar
warm pulsar
#

I'm not sure how much is available to the custom function code as-is

vernal kraken
#

Thanks

#

Appreciate the help

regal stag
tight phoenix
#

trying to include all the same includes didnt work, though this DOES change the error

vernal kraken
#

Tbh not sure why this works?

tight phoenix
#

To my understanding I cannot just write 'TEXTURE2D_X(_BlitTexture)' and have it self populate, like thats not how shader code works

#

but I also dont know what Im doing really

#

So I shouldnt run my mouth about how things do or dont work to people who DO know how they work much better than I do

#

the error changed after I added then removed the includes

warm pulsar
#

mildly interesting that you didn't get that one the first time

#

TEXTURE2D_X is from Core.hlsl

tight phoenix
#

hm Core.hlsl wasnt included in the original file

regal stag
#

Probably need to surround some stuff in #ifndef SHADERGRAPH_PREVIEW. Bit annoying

warm pulsar
#

why would you need to exclude that?

#

good to know about that, though, since I was having issues with things that use structured buffers

#

the preview doesn't bind the buffers (duh) and thus it broke

tight phoenix
#

Like this?

#

that does change the errror

warm pulsar
#

You would do this

#
#ifndef SHADERGRAPH_PREVIEW
...
#endif
#

The SHADERGRAPH_PREVIEW constant is defined if the shader is being compiled for display in the shadergraph preview window

tight phoenix
#

oooh

warm pulsar
#

#ifndef will exclude everything until the next #endif if that constant is defined

tight phoenix
#

That actually worked, now the error is my method

warm pulsar
#

Well, now your method doesn't exist at all when previewing the shader graph

regal stag
#

I would put the ifndef around the TEXTURE2D_X(_BlitTexture)
Then again in the function body, but have texture = 0 at the beginning just so it's always set to something

tight phoenix
warm pulsar
tight phoenix
#

hmm no matching 2 parameter function it says now ๐Ÿค”

#

the names are right

#

maybe I shouldnt use the name 'texture'

#

changed it to ouytput

#

That changed the error

#

so naming it texture was definitely a problem

regal stag
tight phoenix
#

the new error is it cant find that method we contained in the If

regal stag
tight phoenix
#

no error ๐Ÿ‘€

#

It worked, we have monkeys

warm pulsar
#

yeah, so this will, in the shader graph preview, just set the output to zero

#

and then outside, it'll do everything normally

warm pulsar
tight phoenix
#

okay now I DO have the Texture2D UnityChanThink and I can pass in the sampler state

#

I shooould in theory be able to now continue trying to implement the kuawahara

#

Thanks for all the help, I wouldnt have figured that out on my own

foggy bison
#

anyone know why a shader might look different in the scene and game view?

#

this was just a bug but it was a pretty cool effect, i want to try recreating it in the game view

regal stag
#

Game view target probably has some clamping. Maybe because it's not a HDR target or affected by post processing

foggy bison
#

oh right, i think i might know what caused it in that case. lemme try something real quick

foggy bison
foggy bison
ebon basin
warm pulsar
#

The scene view renders "differently" in ways I don't fully understand

#

notably, the skybox is drawn...differently

#

i don't know how!

#

if you don't write to depth but still render something, that pixel does not get overwritten by the skybox in the scene view

#

but it does in the game view

#

(this is for the BiRP in particular)

foggy bison
#

im using URP, seems like most of the same stuff still happens though

ebon basin
#

https://i.imgur.com/u2iabGh.png
What's the idea around getting that lava lamp effect with textures? Currently throwing noise on it does create the shape, but throwing time on the strength doesnt give it that animated effect of a laval lamp.

#

Ah, maybe it's voronoi I need to stick in somewhere

ebon basin
#

https://i.imgur.com/88lsQRu.jpeg
Found some neat idea using pure noise, but this tutorial leaves off with the mask (voronoi) being part of the color map, creating these areas of darkness/transparency that I'd like to fill in with another layer of color. I assume I'd want to try to inverse the mask at some point, but I'm not sure of the tools I should be using for that.

ebon basin
#

have to use particle systems to kinda give it information though cause I can't use compute shader with webgl

foggy bison
snow depot
#

I've been using a texture which is supposed to work the same across all the pipelines, and it's documentation says nothing about this, but when I switched over to URP shadows just stopped working with point lights. They still work with directional lights. Previously I was using it for every texture in the game so it's the shader for every texture in the first 2 screenshots.
1st picture is built in render pipeline which is what I've been using where the shadows work with point lights. 2nd picture is the same for everything but in URP. 3rd image is URP after I changed the floor texture to a standard URP one. Does anyone have any idea what could have gone wrong or how to fix it?

#

And just to prove its not dark lighting, the red floor here is URP simple lit and the yellow is toon shader

violet crater
#

So I just finished setting up my very first ever shadergraph, and I was wondering if there is a way to make this screen a bit more compact by shrinking the preview shown of the textures to a much smaller size, similar to how unity's standard shader looks

ebon basin
violet crater
#

Can you direct me to a guide on how to do that?

#

That looks nice and clean

ebon basin
#

Inside of the properties there's a 'group' you can select

#

assuming you've one of the latest versions

violet crater
#

I apologize profusely because I am quite stupid, im currently running on unity 2022 for VRchat world creation, is that option available in that version of unity? this is how my setup looks currently, this is my first time using shadergraph so im still not fully familiar with all of the settings

ebon basin
#

Sorry it's called category

#

may not be in 2022

violet crater
#

ahhh

#

would it just show up as an option on that section there?

ebon basin
#

unless shader graph isn't editor specific i'm not sure

violet crater
#

apparently typing "hrmmm" is against the rules... so ill use an emoji instead

#

ah wait

#

im dumb

#

i found it

#

I thought that "category" was like.. the category of options i was in and not clickable

#

Like I said, I am quite stupid

#

thank you

ebon basin
#

oh noice

#

actually they been in for quite a while, I've always just used older versions I guess haha

violet crater
#

one weird thing though.. it doesnt seem that I can adjust the position of my category Vixithink

#

its just stuck at the very bottom

#

I can move different categories between one another though

#

intteresting

#

well its not quite perfect but this definitely did help me make my shader look a fair bit cleaner so thank you

unborn wren
#

I have a general workflow question - I'm an experienced C# programmer. I started learning shaders by using ShaderGraph but I found the visual-scripting workflow of shadergraph very annoying (the fact that Add node can add only two numbers but not three broke me as a person). Now I want to switch to just writing shaders by hand which is much simpler and intuitive for me. We're using URP and I've heard that Unity recommends using ShaderGraph instead of custom shaders for full compatibiltiy and best performance (is that true?).

I'm wondering what would the optimal workflow be - use ShaderGraph as a shell for custom shaders (custom nodes) to avoid visual scripting workflow, or ditch ShaderGraph entirely and use only custom shaders? Is it a viable approach to never touch ShaderGraph? What would I lose by that approach?

kind juniper
# unborn wren I have a general workflow question - I'm an experienced C# programmer. I started...

You could create custom function nodes in the shader graph.

The main issue with urp and hdrp shaders is that the unity side API is not very well documented, so you'll need to do a lot of "reverse engineering"(or rather just reading the standard shaders and their includes).
Also, there's basically no idea support for unity includes.

Honestly, I'd just recommend to overcome yourself and use shader graph, unless it's something that is not implementable in shader graph.

unborn wren
kind juniper
astral turret
#

I'm learning shaders and transparency, and I'm kind of curious what's going on in this example - the 10 (in the very back) is being cut out by the "3". I think this has to do with the order entities are being drawn in, but I don't know much about this (or whether there is a reasonable solution).

I have some theories on what I could try, but I figured I should ask first. What's the name/cause of that clipping effect from transparencies? is there anything anyone recommends for that?

astral turret
#

honestly the harder part is that I kind of want to ZTest the translucent pixels... but only against the solid pixels

warm pulsar
harsh marsh
#

Trying to implement grass painting for my custom terrain system and I'm having trouble with making a 3D billboard shader in URP. I cannot use shader graph due to the fact that it doesn't properly support instancing (https://discussions.unity.com/t/urp-shader-graphs-with-instanced-indirect-instanceid-node-seems-to-give-0/249813) with the only fix to write shader via code or use custom functions that break compatibility with basically all graphics APIs apart from DX11.

My billboard code currently is extremely simple:

Varyings vert (Attributes IN, uint instanceID : SV_InstanceID)
{
    Varyings OUT;
                
    float3 grassWS = _TerrainDetail[instanceID].TRS._m03_m13_m23;
    OUT.positionHCS = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(grassWS, 1.0)) + float4(IN.positionOS.x, IN.positionOS.y, 0.0, 0.0));
    OUT.uv_MainTex = IN.uv_MainTex;

    return OUT;
}

However, it doesn't support scale. I have a TRS matrix which has the scale information but I have no real idea how to apply it.

warm pulsar
warm pulsar
harsh marsh
#

The problem I'm having isn't with position though

warm pulsar
#

you're then multiplying that "world space position" with UNITY_MATRIX_MV, which is model * view, so that's a bit odd

#

the model matrix takes you from object space to world space

warm pulsar
#

although, I suppose that transforming [0,0,0] would just give you the translation anyway

#

What does that matrix represent, exactly?

harsh marsh
#

it's a TRS matrix

warm pulsar
#

right, but what coordinate space is it supposed to take you from (and to?)

harsh marsh
#

it's in world space

warm pulsar
#

you're treating grassWS as an object-space position here, given how you're multiplying it with UNITY_MATRIX_MV

#

which could be reasonable: each terrain detail could have a matrix that tells you how to go from the detail's object space to the entire terrain's object space

astral turret
warm pulsar
#

If a transparent material has ZWrite turned on, then anything behind it that renders later will get incorrectly blocked

#

Transparent rendering kind of sucks

#

I've fought with this a lot when making VRChat avatars with really complicated gimmicks

#

in my latest project, I decided I'm just not doing any transparent rendering

#

problem solved โœจ

warm pulsar
#

OUT.positionHCS = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(grassWS, 1.0)) + float4(IN.positionOS.x, IN.positionOS.y, 0.0, 0.0));

I presume IN.positionOS is the object-space position of the billboard's vertex

#

So you're performing the following sequence of operations:

  • Get the world-space position of the terrain detail
  • Multiply that with UNITY_MATRIX_MVP (in two steps, I guess?), which would go from object-space to world-space to view-space to clip-space
  • Add the object-space position of the billboard vertex
astral turret
warm pulsar
#

you have your coordinate spaces jumbled up

#

You should be doing something like this:

#
float4x4 detailToWorld = _TerrainDetail[instanceID].TRS;
float4 worldPos = mul(detailToWorld, IN.positionOS);
float4 clipPos = mul(UNITY_MATRIX_VP, worldPos);

OUT.positionHCS = clipPos;
warm pulsar
#

since sprite meshes usually have some extra bits that aren't rendered

#

(but transparent rendering with ZWrite on would be roughly equivalent to that)

warm pulsar
warm pulsar
# astral turret ah, I didn't know

nominally, they could get mixed in with everything else in the Geometry queue, but discarding pixels (which is how you do alpha-clipping) prevents the GPU from taking some shortcuts

#

it can no longer assume that every pixel under a triangle gets drawn to, basically

#

so they live at 2450

warm pulsar
#

That doesn't tell you anything about the meaning of the matrix

#

i.e. what coordinate spaces it moves you between

harsh marsh
warm pulsar
#

How did you construct that matrix?

harsh marsh
#
Matrix4x4 trs = Matrix4x4.TRS(detailPos, Quaternion.identity, Vector3.one * size);
DetailObject detailObject = new DetailObject()
{
    trs = trs,
    normalOffset = normalOffset//Unused in shader
};

detailPos is the world position (obtained from a raycast from mouse to world)

warm pulsar
#

okay, that seems reasonable

#

What is the type of IN.positionOS?

#

If it's float3, you'll need to construct float4(IN.positionOS, 1)

astral turret
#

lol well my idea definitely did not work as intended

warm pulsar
#

in very loose terms: float4 is used for homogeneous coordinates. If the W component is 0, it represents a vector. If the W component is 1, it respresents a position

#

Translating a vector doesn't do anything

#

note how the translation in a transform matrix is expressed entirely in the last column

#

and those values get multiplied by the W component of the coordinate!

astral turret
#

so I'm drawing the transparencies later, but they aren't being 'covered' by solids

warm pulsar
#

The solid objects must have ZWrite On

astral turret
#

they do

#

ZWrite Off
ZTest Always
is the transparencies
ZWrite On is the solids

warm pulsar
#

ZTest Always means that the depth test always succeeds

#

you need ZTest LEqual

astral turret
#

lol

#

oops

warm pulsar
#

that fails the depth test if they're deeper than the value in the depth buffer

astral turret
#

understood

#

I'm glad that this is much more doable than... sorting my sprites

#

that was it!

it ain't pretty but I can work on it.

last issue is just the flickering when the position moves. basically overlapping solids are fighting to be in 'front'

warm pulsar
#

yep, that's Z-fighting

#

I'm not sure what Unity normally does about that with sprite renderers. It can decide which one wins based on the sorting order.

#

I guess that sprites that face towards an orthographic camera don't really have problems with z-fighting, since the entire sprite is at one exact depth

#

(maybe, not sure..)

harsh marsh
warm pulsar
#

hm, that should be a valid position, then

astral turret
# warm pulsar (maybe, not sure..)

I'll do some experimenting to find out. one of the things I made sure to include in my rendering was room for 'offset' on everything, even z

warm pulsar
astral turret
#

so I may go as far as to inject a tiny offset based on the entity id

#

thanks for your help!

tight phoenix
#

Hm does anyone have a repo of the 'language' that shadergraph's custom nodes expect?
For example my specific issue right now is I am trying to port a shader to custom nodes.
The shader uses 'tex2D' and I know I have to change that to something equivalent

I am more interested in learning how to find this answer myself not be hand fed each specific instance of 'change this to that'

warm pulsar
#

That's a question I'm figuring out myself, haha

tight phoenix
#

Im pretty sure tex2D needs to become something like 'SampleTexture2D'

#

I think I used to know or had a resource that had equivalences written in it

#

maybe something cyan wrote one time

#

it was like a 2 column table of shader methods and their shadergraph custom equivalents UnityChanThink

warm pulsar
#

When you use tex2D, you're using one very specific way to sample a texture

#

it's an HLSL function

#

SAMPLE_TEXTURE2D can expand into the appropriate function for your target platform

#

I've used the various methods somewhat randomly while working on VRChat avatars

#

So, if you're writing a custom function node for a scriptable render pipeline shader, you should try to use the core RP macros

#

"when in Rome..."

tight phoenix
#

yeah I want to be using the correct macros

warm pulsar
#

I am still unclear on how you're supposed to figure this out from the documentation alone, though

warm pulsar
#

you'll often see an entire chain of macros

#

TEXTURE2D_X(foo) -> TEXTURE2D(foo) -> sampler2D foo

#

The first step is in the Core.hlsl include

#

The second step is in platform-specific includes

tight phoenix
#

Looking in core now sometimes I am uncertain what something is asking for, like SAMPLE_TEXTURE2D wants 'textureName, samplerName, coord2'
I am guessing those are a Texture2D, SamplerState, and a float2 for uv?
Whwere would I learn that info however, since it isnt written to say 'samplerstate'

tight phoenix
#

Oh that second link defines Sampler2D yeah

#

Ah yeah these has definitions

warm pulsar
#

SAMPLE_TEXTURE2D_X(textureName, samplerName, coord2)

Core.hlsl turns this into

SAMPLE_TEXTURE2D(textureName, samplerName, coord2)

D3D11.hlsl turns this into

PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2)

and then into

textureName.Sample(samplerName, coord2)

#

You can also just write the last bit directly, but that means your code only works on DX11

harsh marsh
# warm pulsar can you show me the current shader?
Shader "Instanced/Grass" {
    Properties {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Diffuse ("Diffuse", Color) = (1,1,1,1)
    }
    SubShader {
        Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
        Pass {
            HLSLPROGRAM

            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
            #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
            #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
            #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
            #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
            #pragma multi_compile _ _SHADOWS_SOFT
            #pragma target 4.5


            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"            


            struct DetailBuffer {
                float4x4 TRS;
                float normalOffset; //Unused  
            };

            CBUFFER_START(UnityPerMaterial)
                StructuredBuffer<DetailBuffer> _TerrainDetail;

                sampler2D _MainTex;

                float4 _MainTex_ST;
                float4 _MainTex_TexelSize;

                float4 _Diffuse;
            CBUFFER_END

            struct Attributes
            {
                float4 positionOS   : POSITION;          
                float2 uv_MainTex   : TEXCOORD0;
            };

            struct Varyings
            {
                float4 positionHCS  : SV_POSITION;
                float2 uv_MainTex   : TEXCOORD0;
            };            

            Varyings vert (Attributes IN, uint instanceID : SV_InstanceID)
            {
                Varyings OUT;
                
                float3 grassWS = _TerrainDetail[instanceID].TRS._m03_m13_m23;
                OUT.positionHCS = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(grassWS, 1.0)) + float4(IN.positionOS.x, IN.positionOS.y, 0.0, 0.0));
                OUT.uv_MainTex = IN.uv_MainTex;
                return OUT;
            }

            float4 frag(Varyings IN) : SV_Target
            {
                return tex2D(_MainTex, IN.uv_MainTex) * _Diffuse;
            }

            ENDHLSL
        }
    }
}
tight phoenix
warm pulsar
#

I'm kind of surprised this worked at all, because you're adding the object-space vertex position to the clip-space position. Those coordinate spaces have nothing to do with each other

harsh marsh
warm pulsar
#

you'd also need to set the uv coordinates

harsh marsh
#

doesn't change anything

warm pulsar
#

that could cause the shader to not compile (i'm not sure why it only sometimes does that when you don't completely initialize the output struct)

#

show me the resulting vertex stage

harsh marsh
#
Varyings vert (Attributes IN, uint instanceID : SV_InstanceID)
{
    Varyings OUT;
                
    float4x4 detailToWorld = _TerrainDetail[instanceID].TRS;
    float4 worldPos = mul(detailToWorld, IN.positionOS);
    float4 clipPos = mul(UNITY_MATRIX_VP, worldPos);

    OUT.positionHCS = clipPos;
    OUT.uv_MainTex = IN.uv_MainTex;
    return OUT;
}
warm pulsar
#

If you replace detailToWorld with unity_ObjectToWorld, do you wind up seeing all of the billboards overlapping at the origin of the terrain renderer?

#

bit of a sanity check

tight phoenix
#

Cannot Convert from Const Struct UnitySamplerState to SamplerState UnityChanThink

#

I'm guessing I should use UnitySamplerState instead

#

or maybe not

#

ill try it anyways since VS code doesnt always know

#

no errors in shadergraph but errors in the console

#

Not sure what it means by SampleBias, something to do with samplers?

#

this is the line it seems unhappy with

#

ill look for other methods than SAMPLE_TEXTURE_2D

warm pulsar
#

i haven't had to sample textures yet from a custom function, so i've never really dug into this

tight phoenix
#

check it out ๐Ÿ‘€ screen-space Kuwahara through shadergraph and a fullscreen renderer feature pass, filtered to only specific things via stencil buffer

warm pulsar
#

nice!

#

What wound up working?

tight phoenix
#

That's the standard regular Kuwahara, now that I have it working Ill take a look at the generalized and Anisotropic versions UnityChanThink

tight phoenix
#

the graph being just 'pass in the stuff and return result'

warm pulsar
# harsh marsh nope

but you did see billboards appearing at the correct positions (just without the scale) with your original code?

harsh marsh
#

yes

#

original code vs yours

warm pulsar
#

D'oh. Your code makes a lot more sense now: you're billboarding, so you just use the vertex positions to offset the view-space position

#

Now I see why you're doing that.

#

It's a bit weird because your TRS matrix needs to be used for two different things:

  • the position of the billboard (in the world)
  • the size of the billboard (in view-space)
#

You can extract a scale from a transform matrix

#

It might make more sense to just pass in a float3 for the position and a float for the scale

warm pulsar
#

But it's definitely not right -- mine would be appropriate if you wanted to draw a non-billboarded mesh

astral turret
#

they are flat-scaling (a float), wheras I've been changing it to float2

astral turret
#

I could attempt to calculate new scale based on sin and cos but I wasn't sure that was needed?

grand jolt
#

Do i need a shader to make it seamless? These are mesh gameobjects, not terrain

undone perch
grand jolt
#

The meshes are multidirectional. Even if the floor UVs merge with some walls they will not merge with others (seamlessly)

#

I think

undone perch
grand jolt
ebon basin
#

https://i.imgur.com/bpGemVB.jpeg
https://i.imgur.com/LSMoslf.png
Trying to make an intersection shader to create soft edges, but I'm having trouble figuring out what needs to be changed here to work with orthographic projection. It currently works just fine with perspective and from what I've read this should also work fine for ortho or maybe I'm missing something.
Edit: Think I fixed but no idea why :D

#

It actually kinda works above the character, but below them does the depth not seem to be calculated correctly.

ebon basin
#

Have you tried just playing around with the scene lighting environmental settings?

#

Does unlit not allow shadows? That's actually odd, but I would expect you can add them in with your own custom unlit shader.

pseudo ravine
#

Not sure, gonna fiddle around more i guess

harsh marsh
#

BIllboarding doesn't really work anymore now.

Updated code:

struct Attributes
{
    // The positionOS variable contains the vertex positions in object
    // space.
    float4 positionOS   : POSITION;          
    float2 uv_MainTex   : TEXCOORD0;
};

struct Varyings
{
    // The positions in this struct must have the SV_POSITION semantic.
    float4 positionHCS  : SV_POSITION;
    float2 uv_MainTex   : TEXCOORD0;
};            

Varyings vert (Attributes IN, uint instanceID : SV_InstanceID)
{
    Varyings OUT;
             

    float4x4 detailToWorld = _TerrainDetail[instanceID].TRS;
    float3 worldPos = mul(detailToWorld, IN.positionOS);
    float3 viewPos = TransformWorldToView(worldPos) + IN.positionOS;
    float4 clipPos = TransformWViewToHClip(viewPos);

               

    OUT.positionHCS = clipPos;
    OUT.uv_MainTex = IN.uv_MainTex;
            
    return OUT;
}
ebon basin
#

Oh hey I think I've taken that code from that repo before

#

I was actually looking into a similar idea, but I just went ahead and used Unity's terrain and detailed meshes

#

Also, do note that if you use spriterender that billboarding like this won't work unless you remove dynamic batching, even if it's instanced I noticed it was creating problems.

harsh marsh
#

I'm not using unity's terrain

#

this is a custom system with custom instancing code

ebon basin
harsh marsh
#

it is instanced geometry

ebon basin
#

right, but this is done by values, you still need to represent that on the editor somehow

#

so is this like an array you feed these positions into?

#

I was thinking like making a custom brush that populated gameobjects, and then feed those transform values into shader. After, strip those gameobjects at runtime.

#

Either that or splatmapping randgen

harsh marsh
#

keep in mind the only issue here is the vertex shader not working correctly.

#

nothing else is relevant

ebon basin
#

oh yeah that looks pretty good

ebon basin
# harsh marsh BIllboarding doesn't really work anymore now. Updated code: ```glsl struct At...
float BillboardVerticalZDepthVert(Attributes IN, inout Varyings OUT)
{
    // billboard mesh towards camera
    float3 vpos = mul((float3x3)unity_ObjectToWorld, IN.positionOS.xyz);
    float4 worldCoord = float4(unity_ObjectToWorld._m03, unity_ObjectToWorld._m13, unity_ObjectToWorld._m23, 1);
    float4 viewPos = mul(UNITY_MATRIX_V, worldCoord) + float4(vpos, 0);

    // view to clip space
    OUT.positionCS = mul(UNITY_MATRIX_P, viewPos);

    // calculate distance to vertical billboard plane seen at this vertex's screen position
    float3 planeNormal = normalize(float3(UNITY_MATRIX_V._m20, 0.0, UNITY_MATRIX_V._m22));
    float3 planePoint = unity_ObjectToWorld._m03_m13_m23;
    float3 rayStart = _WorldSpaceCameraPos.xyz;
    float3 rayDir = -normalize(mul(UNITY_MATRIX_I_V, float4(viewPos.xyz, 1.0)).xyz - rayStart); // convert view to world, minus camera pos
    float dist = rayPlaneIntersection(rayDir, rayStart, planeNormal, planePoint);

    // calculate the clip space z for vertical plane
    float4 planeOutPos = mul(UNITY_MATRIX_VP, float4(rayStart + rayDir * dist, 1.0));
    float newPosZ = planeOutPos.z / planeOutPos.w * OUT.positionCS.w;

    // use the closest clip space z
    #if defined(UNITY_REVERSED_Z)
    newPosZ = max(OUT.positionCS.z, newPosZ);
    #else
    newPosZ = min(OUT.positionCS.z, newPosZ);
    #endif

    return newPosZ;
}```
This is what I use for my grass/foliage and it's based off of one of bgolus' shaders. It prevents the billboards from clipping into 3D geometry behind them at larger angles with a perspective projection.
#

It's also based on that repo code but changed somewhat.

#

I think Unity's grass shader has some similar behaviour, but I do notice that it does clip at very large angles Actually, I'm thinking of another shader that Unity provides

#

Ah, actually the repo code there billboards around the y, so yeah there's somewhat of a difference in behaviour

#

rather, it does not preserve the y rotation

ebon moss
#

do you guys know if theres a way to write directly to the final fragment color in a lit shader graph

kind juniper
ebon moss
kind juniper
#

emission would only work if the color you output into it is brighter than the lit color that unity calculates

ebon moss
#

unlit (left) lit (right)

kind juniper
ebon moss
#

look at the shaded section on the left of the face, I dont like how the lit shader auto adds that lighting

ebon moss
kind juniper
#

Maybe it's due to the specular component of the lighting? Did you try setting specular/metallic to 0 and unchecking specular reflections in the material?

kind juniper
#

Why not use an unlit shader though, if it produces an image that you expect?

ebon moss
kind juniper
#

But it looks like you have some shadows in the unlit shader as well? Some kind of cell shading

ebon moss
#

btw you fixed it, I changed from metallic to specular and set specular to 0 and its good now, so thanks!

ebon moss
#

and textures

violet crater
#

I am attempting to use shadergraph to make it possible to rotate a texture on an object by a specified amount, not to have it fully animated allthe time and i thought i set it up right, but whever i rotate the texture just gets very deformed

#

this is my setup currently

#

however when i adjust the rotation it rotates... but also zooms in a ton, i can sort of fix it by reducing the tiling but id like to avoid that

#

am i just using the wrong math node to combine these?

ebon moss
#

wheb you say rotate the texture do you mean just rotating the 2d texture in the uv map either clockwise or counter clockwise?

violet crater
#

yes

#

so like say i havea countertop

#

and i want the wood planks to go a certain direction on it

#

instead of opening up the model and editing the uvs, id like to be able to just use the material to rotate it instead

ebon moss
#

ofc, let me take a look

violet crater
#

thanks! I can show my entire shadergraph if oyu want

#

its likely a bit.. messy. This is my first time ever using shadergraph lmfao, but im attempting to recreate a shader that has the full functionality of the old alloy shaders since those are some of my favorite ever lol, and then adding a bit more functionality on top of it

ebon moss
#

The first issue I see is that you are using time and offset wrong

#

time will start at 0 and go to infinity, so you are adding too much offset and its causing this distortion

violet crater
#

time?

#

oh

#

thats just for texture scrolling

#

not related to rotation and tiling and stuff

#

i set that up to allow me to created animated scrolling textures if i want to

ebon moss
#

well ok so whenever you have multiple transformations with uvs, its usually better to chain them together using the uv inputs, you just have to be careful of the order

violet crater
#

unless theres a better way to implement that ๐Ÿ˜…

#

I see

ebon moss
#

unless I'm misunderstanding what your using the tiling and offset node for

violet crater
#

tiling and offset nodes are just for exactly what they sound like, being able to adjust the tiling and offset of the texture whenever i want to

#

the scrolling is just an optional animated version of the offset

#

i can set to 0 if i dont want to use

ebon moss
#

so If you just want a basic rotation texture effect, what you would do is take your sample texture 2d node, and plug the rotate uv node into the uv of the sample texture 2d node

violet crater
#

is there a way to do that while ive already got the tiling and offset and scrolling options already plugged in there as well?

#

my goal is just to have all of these as optional things i can do at any time

ebon moss
#

you can plug the tiling and offset into the uv of the rotate node and that should work

violet crater
#

okay so i have the rotate node in the wront place...

#

one sec

#

wait i thinki get it

#

so i dont even need a math node for this?

#

AHA

#

THANK YOU

#

i was overcomplicating it with the math node

ebon moss
#

the add node? No not really, but its useful to know that a lot of the uv nodes are actually just math nodes, like tiling and offset is just addition and multiplication

#

np

violet crater
#

now if only i could figure out what number on the float node equates to a 90 degree angle

#

seems to be about 3.14

ebon moss
#

im pretty sure it uses radians, so 3.14/2 should be 90 degrees

#

you can use the degrees to radians math node to convert

violet crater
#

just plug my rotation float into this?

ebon moss
#

no it should be degrees to radians

violet crater
#

sorry for all the questions i am brand new to shader graph and dont have a clue what most nodes do yet

#

gotcha

#

so plug my rotation float node into that?

ebon moss
#

yeah that will convert your 90 degrees rotation into radian units, which is what many of the nodes use by default

violet crater
#

I could smooch you

#

you are awesome

#

thank you so much

ebon moss
#

np, gl

violet crater
#

Up until now ive only worked wth unity 5.3.5 making mods for a specific game that requires that version

#

so i am very much enjoying this shader graph stuff

#

It gives me the degree of control i like over my materials that blender has while still having a quick and easy setup once your material is made like unity

ebon moss
#

Yeah shader graph is super fun, and its useful even if you know how to write shaders

violet crater
#

my goal here is to recreate the functionality of this since its deprecated now and does not seem to work in modern unity

#

which is a massive shame because its genuinely one of the best shader frameworks ive ever had the pleasure of using

#

when i try to load it into newer unity though the custom ui is completely busted and most of the functionality doesnt work right FeelsBadMan

#

I wish someone would update it for newer unity, its open source, you can even get all the code on github

#

now if only i could find a way to make the actual ui of my shader itself more pretty to look at xD Being able to create the collapsable categories was nice but id love to be able to adjust the size of the imagte previews as well to not take up so much space

#

the potential for things you can do with this shader graph stuff is awesome i love it

#

the nodes dont feel quite as straightforward as the ones in blender, but this still feels easier for me to understand than unreal's shader graph stuff

winter dawn
#

hello, is it possible to make a cutout shader where the object is cut by objects intersecting it?

foggy bison
#

now that i think about it, im not actually sure how you'd do it guh

turbid heart
#

I'm trying to create an effect where i have a hexagon split into 4 triangles that need to be colored in different colors. Very new to shaders or graphics in general. I have created the following mesh through code, and tried just coloring the vertices to the colors that i wanted but expectedly that causes a gradient or blending due to the topleft vertex being shared across all triangles.

What's the proper way of giving these individual colors, or possibly even textures. Should i just instead create 4 vertices at the topleft spot and then treat it as 4 separate meshes, or is there a smarter way

civic lantern
turbid heart
#

would i create unique vertices at that same topleft corner to achieve that (9 vertices instead of 6)? i still want this sort of shape in this case

civic lantern
#

You got 4 triangles so that would be 12 different vertices

turbid heart
#

oh right whoops, forgot the others are shared between two triangles too

civic lantern
#

Then you can use vertex colors without blending/gradient

turbid heart
#

and if i wanted to use different materials or textures, would i opt for submeshes instead?

civic lantern
#

Yeah, materials are per-submesh

turbid heart
#

Thank you!

stoic nova
#

Black screen on launch, Unity 6000.38 URP GPU Resident Drawer + APV enabled.

#

Probable link to a shader bug, linked to APVs

haughty glen
#

I am trying to make field of system like darkwood, is this possible with shaders only? my idea was to create something that just gives back saturation when something inside it. if shaders enough I would be grateful if someone gave me resources to learn from.

warm pulsar
warm pulsar
#

you'll definitely use a shader to adjust the saturation, but it's not going to be able to figure out which areas you can and can't see by itself

#

if you're using the 2D URP renderer, that has a 2D light system

haughty glen
#

what you think I should learn to accomplish this?

warm pulsar
#

You can get a texture that tells you how brightly lit an area is

#

Instead of multiplying that with sprite color, you'd use it to adjust the saturation

#

I don't remember many details, though. Been a hot minute!

haughty glen
#

well, it sounds like cheap way of making it, like I have to put material to every new sprite and get limited to single material. is it possible to write whole renderer for it?

#

or is it too ambitious?

#

afterall it sounds simple you just desature whole render and then don't desatured masked area

warm pulsar
#

I feel like you should be able to do this as a post-processing effect...

haughty glen
#

alright I will check it out thx

dapper arrow
#

Hey people, can someone tell me if alpha blended transparency would perform better than a simple opaque shader with clip() on mobile

warm pulsar
#

I'm pretty sure I've read a bgolus post or two talking about this

hushed silo
#

I want to make fog apply less to self illuminated parts of the texture, how should I do this? (this isn't working great). I don't really understand what the density value of the fog node actually is

regal stag
cunning thicket
#

is it possible to make a light projection shader in shadergraph? I dont want to use unity lights, just want to make a textured mesh project its emissive onto any surface it intersects

cunning thicket
#

im trying to use the built-in VRC target

hushed silo
drowsy shuttle
drowsy shuttle
cunning thicket
drowsy shuttle
cunning thicket
#

light cookies in unity lights? I cant use these lights in this scenario...

drowsy shuttle
#

then you would need to use Decals

dapper arrow
#

I tried this on a pretty old mobile phone. Redmi note 7, snapdragon 660. As per the results, dithered transparency should be more performant too. This may or may not be true for even older mobile devices

tight phoenix
#

How do I get Scene Depth from within a custom function node? As in sample in the code not passed in.
For scene blit I was able to 'Show Generated Code' to see how the URP sample buffer gets the Color texture, but you can't do that on Scene Depth to see how depth is gotten in the same way

#

As in like, what do I put here:

#

This works in Shadergraph but not in the actual scene UnityChanThink

cunning thicket
tight phoenix
#

bgolus on the net says "Just use the built in Scene Depth node"
so XY problem what I am REALLY trying to do is make an outline shader that doesn't suck, roberts cross sucks, but to do more advanced ones I need to run the outline code in a Custom Function node, and to do that I need to be able to sample and offset the scene depth inside the custom function, it cannot be passed in from the Scene Depth node (as far as I know) ๐Ÿค”

regal stag
# tight phoenix How do I get Scene Depth from within a custom function node? As in sample in the...

Should be able to use

float RawDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(ScreenPosition)).r;

No need to define the texture and sampler as the Fullscreen Graph generated code does it automatically.
But like before, needs to be inside an #ifndef SHADERGRAPH_PREVIEW block.
For converting to Linear/Eye modes can use

LinearDepth = Linear01Depth(RawDepth, _ZBufferParams);
EyeDepth = LinearEyeDepth(RawDepth, _ZBufferParams);
regal stag
cunning thicket
#

I did this and it.. doesnt work? is there more to the setup?

tight phoenix
#

How would I have known to call those specifically named methods? Like besides just being experienced enough to know to call them, is there a repo somewhere with this info?

#

Also, shown here, I fear Roberts Cross isnt my real issue, the part about it that I don't like is how the lines aren't aliased, and they cease to exist abruptly as you zoom out in weird ways ๐Ÿค”
Will researching implementations like the Sobel filter fix this to not occur? Or am I barking up the wrong tree?

regal stag
# tight phoenix How would I have known to call those specifically named methods? Like besides ju...

Mostly need to know the ShaderLibrary and check generated code. In this case, you could check the generated code for the Scene Depth node and find it uses a long macro (SHADERGRAPH_SAMPLE_SCENE_DEPTH). Searching the ShaderLibrary you can find that is defined in ShaderGraphFunctions.hlsl in each render pipeline's ShaderLibrary. In URP that uses a function from DeclareDepthTexture.hlsl

iirc the Fullscreen Graph automatically includes that, but for other graph types you'd need to include it manually (in the custom hlsl file, before function, likely inside #ifndef)

ebon basin
warm pulsar
#

I've read this blog like 5 times now

#

i should actually implement it

tight phoenix
#

Yeah its a good article

ebon basin
#
warm pulsar
#

the problem is that I can't really use it in VRChat

#

since I can't bounce back and forth between two RTs

#

I can only do something truly fucking awful: repeatedly GrabPass

ebon basin
#

stencil silhouette seems to work for most of my cases. I find trying to do those toonshader outlines (rim outlining?) to be a pain in the ass

regal stag
#

I know sobel is more samples, so is probably more accurate than Roberts Cross

tight phoenix
#

I will re-read that article but I am not looking to outline a single thing, I was looking to get edge pop out on terrain geo in like a '2D terrain has a black outline' style look

#

Which roberts cross does okay at the outline part, but as you zoom out it acts funny which is not ideal

ebon basin
#

Yeah, I can't seem to really get those fullscreen outline passes to work that well either

tight phoenix
#

but will a different edge detection method fix this specific issue? Or is the issue related to using scene depth? ๐Ÿค”

#

I have other effects I want to pratice so this I think its good enough for now UnityChanThink
I would like stuff like antialiasing on the line, but doing that will require a different method than roberts cross

glass apex
#

a real quick quesion for the shader graph, can someone tell me where to find all the properties that I can read like "_MainTex" or "_NormalMap"?
I keep finding them randomly online but I can't figure out what all of them are

#

idk if this is relevant but its for URP 2d sprite unlit

#

I see various people saying "name it _MainTex and reference it to _MainTex" and then it just magically has the main texture property. I dont really care that it works in this mysterious manner, I just really want to know where these are coming from

regal stag
# glass apex I see various people saying "name it _MainTex and reference it to \_MainTex" and...

The SpriteRenderer component passes the sprite texture into _MainTex. And any other textures if they are set up as "secondary textures" on the sprite. https://docs.unity3d.com/6000.0/Documentation/Manual/sprite/sprite-editor/secondary-texture/add-secondary-texture.html
Those can be named anything, but _NormalMap and _MaskMap are common ones - and are used by the provided URP shaders (i.e. Sprite-Lit-Default) so using those keeps it compatible with multiple shaders

glass apex
#

I mean where can I find all of the things like "_MainTex" or "_MaskMap"

#

I know there is more

#

is it just these?

regal stag
#

Properties can be named anything, it depends on the shader

glass apex
#

that would explain why I cant find a defined list anywhere, if its per shader

#

cool

regal stag
#

Other than _MainTex of course. And a few stencil ones that UI shaders expect.

glass apex
#

well I have a different question also about shaders

#

so why does setting a UI element to use the Sprite-lit-default material, or any custom material, cause it to stop being maskable?

regal stag
#

Probably because those shaders don't have the stencil properties & block, as masking relies on those

glass apex
#

they seem to be referencable properties (except the write/read mask ones)
except multiplying the alpha or setting the sprite mask with those properties doesn't seem to fix the issue

#

colors used to highlight issue

#

those properties seem to be fully 0 no matter if the UI is being masked or not

#

the following shows fully black no matter where the UI is

#

same for stencil and stencilop as well

#

MaskTex seems also to not do anything, although I rather suspect its a different kind of masking rather than UI masking

regal stag
glass apex
#

yeah im in unity lts 2021

#

def should update it to unity 6 but crazy to know that it just isnt supported

glass apex
regal stag
#

I believe so

glass apex
#

doesn't appear to be working

#

do I have to do something special with these properties or something?

#

I am just plugging them into the base color atm to check their values

#

they are just one solid color every time

regal stag
#

If you're in Unity 6 you don't need to add the properties. But change the graph type under the graph settings to Canvas

glass apex
#

oh yeah, that fixed it

#

thanks!

#

iv been trying to figure that one out for a while

fading totem
#

I feel like a big dummy, but I'm trying to make a PBR Shader Graph. Do I need to enable something for that setting to come up, or was there an update I missed/

fading totem
#

Oh. Okay, that makes sense.

tight phoenix
#

What are possible reasons why the distance from the camera to the surface causes an Edge Detection shader to say -everything- is an edge? awkwardsweat
The effect is also worse in Game scene than it is in Scene view

#

This problem occurs in both a Roberts Cross and a Sobel implementation of edge detection so I think the problem has something to do with the unity Depth buffer causing this? Rather than being from the implementation because both have the same issue

#

works great in scene but in game it picks up a huge angle of values hmm

#

possibly the reason for the problem is because im using raw depth?

#

googling I found this, maybe near/far clip plane differences are the issue

#

difference in clipping plane between scene and game does appear to be responsible ๐Ÿ‘€

snow depot
fading totem
#

Did Albedo get removed from the Lit Shader Graph or something.

#

Also, is Render Face: Both the same as the former Two-Sided checkbox that used to be around?

cunning thicket
#

this.. isnt going well

kind juniper
kind juniper
fading totem
kind juniper
warm pulsar
#

Every power of two that separates them halves depth precision

#

so 1..4 is twice as inaccurate as 1..2

#

this means that as you start pulling the near clip in really close, you can dramatically reduce precision

#

0.01 vs 0.1 seems tiny, but that's just over three powers of two

cunning thicket
#

I have looked around and other peoples code just... work.. mine doesnt even have any errors in the log

kind juniper
cunning thicket
kind juniper
cunning thicket
kind juniper
#

Does changing the active target to something else fix it?

dapper arrow
#

I have noticed how any sort of transparency or overdraw completely kills performance on mobile. Would that mean having saturation and contrast control functions within our shaders is better than using any fullscreen effect?

#

Just a question outta curiosity

cunning thicket
#

however when its 'fixed', it just.. doesnt work, theres the texture on the ends of the cylinder, but it doesnt get projected to any of the meshes it intersects with

kind juniper
#

"Projected"? Is that a full screen shader or something?

cunning thicket
harsh marsh
#

Still having issues with my billboard shader.

struct Attributes
{
    // The positionOS variable contains the vertex positions in object
    // space.
    float4 positionOS   : POSITION;          
    float2 uv_MainTex   : TEXCOORD0;
};

struct Varyings
{
    // The positions in this struct must have the SV_POSITION semantic.
    float4 positionHCS  : SV_POSITION;
    float2 uv_MainTex   : TEXCOORD0;
};            

Varyings vert (Attributes IN, uint instanceID : SV_InstanceID)
{
    Varyings OUT;
                
    float4x4 detailToWorld = _TerrainDetail[instanceID].TRS;
    float4 worldPos = mul(detailToWorld, IN.positionOS);
    float3 viewPos = TransformWorldToView(worldPos) + IN.positionOS.xyz;
    float4 clipPos = TransformWViewToHClip(viewPos);

    OUT.positionHCS = clipPos;
    OUT.uv_MainTex = IN.uv_MainTex;
            
    return OUT;
}

The billboards don't correctly point to the camera. I think it has something to do with the scale part of the TRS matrix (which is in world space) since the smaller the scale, the more it points towards the camera (but somewhat stretches)

#

I have no idea what to do. Every example I find on billboard shaders is either for non-instanced geometry and ends up confusing me when attempting to adapt it for use with instanced geometry or it's with shader graph which I'm not using (and will not use)

cunning thicket
#

hm.. could my idea be done via stencil too?

warm pulsar
#

the first half is from my (incorrect) shader code

cunning thicket
#

is stencil buffer available in shadergraph or do I need to do it in C#?

warm pulsar
#

If you get rid of the + IN.positionOS.xyz; bit, you should see a bunch of normal planes sticking out of the gorund

harsh marsh
#

ya

warm pulsar
warm pulsar
#

note that directly adding the object-space position to the view-space position will mean that the planes have the same on-screen size at any range

#

which may not be what you want

cunning thicket
warm pulsar
#

correct

#

I believe you can use stencil operations in full-screen pass URP shader graphs

#

but you can't use it in other kinds of shader graphs

harsh marsh
# warm pulsar To get the position alone, you'd transform `float4(0,0,0,1)` to world space

Ah that makes sense. Got it to work by doing this

float3 scale = float3(length(detailToWorld[0].xyz), length(detailToWorld[1].xyz), length(detailToWorld[2].xyz));

float4 worldPos = mul(detailToWorld, float4(0.0,0.0,0.0,1.0));
float3 viewPos = TransformWorldToView(worldPos) + IN.positionOS.xyz * float3(scale.x,scale.y,1.0);
float4 clipPos = TransformWViewToHClip(viewPos);
warm pulsar
#

ah yeah, and that lets you extract a scale from a transform matrix

violet crater
#

Is there a tool that can take an existing shader and convert it into a shadergraph shader?

foggy bison
#

dont think so. a lot of shader code cant be directly converted into shadergraph nodes, as far as i know

#

closest thing i can think of is chatGPT. although that has a few obvious limitations

neat orchid
#

Does making a shader which changes the prop texture based on location (either via noise texture or some other position based logic) have performance merit?

#

the idea being instead of having multiple materials for, a rock, say, you have a blend of textures and they are automatically applied based on location, all with the same shader and material?

amber saffron
neat orchid
amber saffron
# neat orchid So, let's say, as an example, it would then be better to make a simple script wh...

I think so yes. You could always try both and profile to be sure.
But in theory, the 1rst option will have multiple materials using the same shader but different textures batched together.
The second, even if the texture swap is determined by the object position for example, the shader is a bit more complex. The additional randomization needs a bit more logic, even if it ends up being uniform over the whole object so only one texture is sampled.

neat orchid
#

ok thank you

#

I want to make lots of shaders for practice, but if it's not very useful, I will skip those particular ones

orchid sparrow
#

Hi again !

I've been working on an unlit shader graph to get every light source (so recreating a lit shader, kinda). It will be used later for another shader, and I needed every light node to be different (if I ever want to disable one light or smth).

Currently, I have SSAO, main light with shadows, additional lights, but I can't manage to get shadows from them.
I know that there's something named MainLightShadow for the main light shadows, but I can't find something similar for the additional lights.

How can I do ?

#
void AllAdditionalLights_float(float3 WorldPos, float3 WorldNormal, float4 Shadowmask,
        out float3 MixedColors)
    {

        #ifdef SHADERGRAPH_PREVIEW

            MixedColors = 1.0f;

        #else

            int lightCount = GetAdditionalLightsCount();

            for(int i = 0; i < lightCount; ++i)
            {
                Light light = GetAdditionalLight(i, WorldPos, Shadowmask);

                float3 attenuation = light.distanceAttenuation;
                #if defined(_ADDITIONAL_LIGHT_SHADOWS_SCREEN) && !defined(_SURFACE_TYPE_TRANSPARENT)

                    float4 shadowCoord = ComputeScreenPos(TransformWorldToHClip(WorldPos));

                #else

                    float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);

                #endif
                float3 shadowAttenuation = MainLightShadow(shadowCoord, WorldPos, Shadowmask, _MainLightOcclusionProbes);

                float3 mixedAttenuations = (attenuation * shadowAttenuation) * light.color;
                float ndotl = saturate(dot(light.direction, WorldNormal));

                MixedColors += mixedAttenuations * ndotl;
            }

        #endif

    }
#

Here's what I have rn for additional lights

regal stag
lyric hill
#

Whats the difference between clip space and screen space

cunning thicket
warm pulsar
#

ShaderLab is the language for hand-written shaders

cunning thicket
#

ah

warm pulsar
#

You insert chunks of HLSL code into it

cunning thicket
#

hm.. ok.. looking around at it..

hardy nimbus
# cunning thicket how do I use ShaderLab? is that a different program from Unity? plugin?

ShaderLab is just a syntax that Unity wraps around both the old shader code and also the new shader code using HLSL.

Think of it as a wrapper syntax that adds the ability to read data from Unity inspectors, render pipeline details and also helps with different macros in Shader code.

If you see a Unity asset with the file extention .shader, that is a shaderlab file.
But you can use CGNIC and HLSL stuff in it.

Cyan above actually made a really good blog before.
Will grab the link for it.

Edit: Thank you to Cyan for making a lot of these resources. Credit to them for helping out by writing a really in detailed blog for new and older shader code.

cunning thicket
#

ah... hmm..
I see.. yea I need a bit of help with the shader I want to make, but I have a feeling I should make a simple shader to start with

hardy nimbus
hardy nimbus
# cunning thicket ah... hmm.. I see.. yea I need a bit of help with the shader I want to make, but...

Sorry for double post. Warning if you use URP and you plan to write in HLSL a lot of the tutorials are written using the older shader includes for CGNIC, which are helper utility functions you can import to make your life a lot easier made by Unity.
If you want to use the newer HLSL stuff, which works a lot better in most of the use cases I have done thanks to more built in include files, you will need the new names for the functions.

Cyan made this page that has a list of the new names for the functions, so if you run into a an error following older tutorials look at this list at the bottom here and see if some of the names for the functions have changed and the name of the include file.

Honestly this was the biggest hurdle for me when first starting out. Figuring out what new functions replaced the old ones.

https://www.cyanilux.com/tutorials/urp-shader-code/

Explains how shader code (ShaderLab & HLSL) is written to support the Universal RP

#

One example people starting out learning shader in Unity today is running into old code using the UnityObjectToClipPos(positionOS) function.

This was the old Built-In RenderPipeline for getting the object space and turning them to clip space.

It is replaced by TransformObjectToHClip(positionOS).

Due note you can also use GetVertexPositionInputs().positionCS.
GetVertexPositionInputs is a bloody nice helper function with built in one word conversion from any types of space to another.
Object to world, world to clip, and so forth.

cunning thicket
hardy nimbus
cunning thicket
orchid sparrow
hardy nimbus
#

Just for reference, not sure how much expierence you have working with Unity's rendering so sorry if I might state something you already know, Unity has a few render pipelines that you can choose from.

The old render pipeline is called BIRP (Built-In Render Pipeline) when users only had one option.

Now you have a few options. Due note all the new options work with HLSL, so write HLSl shader once and it can mostly copy to other render pipelines.

You have a render pipeline for 2D games because back than Unity didn't have on, so 2D lighting/shadows was not a thing.

Univerisal Render Pipeline used supporting the most platforms as possible hence it's name. If you need a lot of platforms that have a range of hardware specs like desktop and mobile devices, this one is your friend for 3D games.

High Definition Render Pipeline (HDRP) for higher end games needing better graphics like ocean rendering, dynamic sky lighting, water tools, and a lot more.

Due note all pipelines have the possibility for ocean, water, and dyanmic rendering. HDRP just has a built in tool already made for you.

cunning thicket
lyric hill
#

fellas I dont understand the difference between screen space and clip space. Clip space is after the projection matrix right? When its converted to the frustrum, what exactly is screen space

#

what happens in between screen to clip space

regal stag
lyric hill
#

What exactly does that mean

#

what are they trying to do from clip space to screen space physically

regal stag
# lyric hill What exactly does that mean

Due to the way the projection matrix is set up, it outputs homogeneous coords. Meaning it has an extra fourth component (usually labelled w), which is equivalent to the eye-space depth to the fragment for a perspective projection, and just 1 for orthographic.
In between clip space and screen, it divides the xyz components by the w. That applies the perspective effect, making distance objects smaller on the screen.
Can probably google around for more info & explanations with images which might help clarify further

lyric hill
#

ok, I guess Ive misunderstood clip space then. I assumed clip space was the one that normalized the co-ordinates, instead of the one operation that ensures it lies between (-w to w)

#

If the screen space is what results after it goes through normalization I understand what it is now

regal stag
#

To be specific as well, functions like ComputeScreenPos is typically handled in the vertex shader and does the remapping part of the clip->screen conversion (into a 0 to w range). The output isn't exactly in "screen space" until doing the pos.xy/pos.w, usually in the fragment shader

lyric hill
#

Also one more thing

#

Is there a place where I can look up available HLSL functions for unity

regal stag
#

For URP/HDRP you mostly need to look under the ShaderLibrary folder in the package

lyric hill
#

alright gotcha

storm garnet
#

I have a fullscreen shader applied via RendererFeature, it's working fine but I can't get it to interact properly with transparent materials.
Write Depth is ON, the injection point is set to "before transparent", but I can't find what's wrong. Transparent stuff write fully over it no matter the actual distance, even when setting the depth value in Shadergraph manually to 0 or 1 (using Linear01).

regal stag
storm garnet
#

Shouldn't they be able to read the Depth Write from it?

devout kayak
#

float depth = SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV + sobelSamplePoints[i] * Thickness);
I am new to shader coding , not sure how to filter out some objects off the passed depth in this hlsl function used in shader graph (urp)
also tutorial links would be appreciated

stray gulch
#

does anyone know any good per-object outline packages or any documentation on how to make one?

#

biggest issue im trying to solve rn is having the outline not be in front of objects that are in front of it

#

literally every outline system i've tried on github falls short on that one thing

devout quarry
#

Resulting in something like this

#

So kind of depends on how your outline works, but if it's a 'render silhouette -> dilate silhouette -> composite outline' type of outline, then just add the appropriate ZTest.

case Occlusion.Always:
silhouette.SetFloat(CommonShaderPropertyId.ZTest, (float) CompareFunction.Always);
break;
case Occlusion.WhenOccluded:
silhouette.SetFloat(CommonShaderPropertyId.ZTest, (float) CompareFunction.Greater);
break;
case Occlusion.WhenNotOccluded:
silhouette.SetFloat(CommonShaderPropertyId.ZTest, (float) CompareFunction.LessEqual);
break;
tight phoenix
#

https://youtu.be/jusWW2pPnA0?t=497
I am trying to replicate the fluffy trees from tiny glade.
There are LOTS of fluffy tree tutorials out there, but I looked at all of them and they skimp on the critical details that make it look and feel good. UnityChanThink

Glade trees have a random rotation given to each quad face, how would you achieve that?

#

You can see the random rotation taking effect as the mesh swells up

stray gulch
#

mianly bc i need it to be 1px pixel perfect

#

so there's a bunch of stuff with stencil and all that, just trying to figure out the best way to do the masking there

solid scaffold
#

does anyone have a clue as to why my wall shader is being stupid. using URP unlit transparent shader

#

ill send more pictures if need be

#

but i dont want to spam this channel unless someone can help

#

basically i can see through the wall to the other side of the wall and i can see my player through the wall.

#

I have a good shader which should act perfectly in terms of making my wall fade out where the camera is closer

hardy juniper
#

cutout is also known as alpha clip

solid scaffold
hardy juniper
#

there is a node for dither too which is often good to use with such an effect

warm pulsar
#

Transparent shaders do not (by default) write to the depth buffer

#

Transparent materials do get drawn from back to front, so this is not an issue for non-overlapping renderers

#

in this case, though, the renderers overlap

#

this means that some pixels will have been written to by something that is clearly closer to the camera than what's currently being rendered

#

but the engine has no clue about that

#

In this case, you definitely just want to switch to alpha clipping

#

you've already got a neat dithering effect

#

alpha clipping allows for an otherwise opaque shader to completely skip drawing to some pixels

solid scaffold
#

switched to alpha clipping but still not working

grizzled bolt
solid scaffold
#

thanks

#

it worked

#

switched some things around got it working

#

thank you everyone who helped

molten niche
#

Hey everyone! I'm trying to make an attack indicator system where it highlights the part of the ground that's inside a mesh, any tips on how to implement this?

warm pulsar
#

i've implemented this several times now in various ways

#

i'm not sure i've ever done it "properly", ha

#

most recently, I did it by writing a shader that uses stencils

#

first, in a Cull Front pass, it marks all pixels that are behind the depth buffer. then, in a Cull Back pass, it clears all pixels that are behind the depth buffer

any pixels that remain marked get highlighted

#

i first did it with a shader graph in an HDRP game. that was a lot more mysterious

#

i went back and read it again and had no clue why it worked

warm pulsar
#

the second step gets rid of those that the shape isn't in front

tacit parcel
warm pulsar
#
float3x3 AngleAxis3x3(float angle, float3 axis)
{
    float c, s;
    sincos(angle, s, c);

    float t = 1 - c;
    float x = axis.x;
    float y = axis.y;
    float z = axis.z;

    return float3x3(
        t * x * x + c,      t * x * y - s * z,  t * x * z + s * y,
        t * x * y + s * z,  t * y * y + c,      t * y * z - s * x,
        t * x * z - s * y,  t * y * z + s * x,  t * z * z + c
    );
}
#

it computes a 3x3 matrix that performs a rotation

#

i forget where i nabbed this from

tacit parcel
warm pulsar
#

i love these functions; i use them everywhere

#

you'd use the center of the quad as the input to the hash function, then use the result to rotate the quad

#

(or you'd give each quad an ID, or something like that)

tight phoenix
#

Hmm yeah thats the part that was throwing me off was how do I mark or ID each individual quad

#

I would like to keep doing the shader approach because it is more flexible for working dynamically on any mesh

#

rather than using particles or a baked mesh, I know cyan has a tutorial for flufty trees as well

snow depot
#

Like every outline I can find has these big gaps if you try to make it wider, is there any way to make outlines that avoids that?

warm pulsar
#

That'll happen with inverted hull outlines

warm pulsar
#

they're just...floats

#

a very common thing I do is to bake an identifier into a UV channel

#

so if I have 500 little objects, I bake a unique ID for each object into UV1.x

#

and then shove the center of the object into UV1.yzw

#

(you can put up to four floats into each UV stream -- but you can only move X and Y from Blender to Unity, so using Z and W requires extra work)

#

i've gotta polish up my blender add-on and unity package for doing that

tacit parcel
steel notch
#

What is this "Instanced" property in vertex streams?

#

It's not TexCoord

kind juniper
steel notch
#

I'm trying to access these values from shader graph, so I want to know where they're being pumped into.

kind juniper
#

Assuming it's part of the vertex input struct, you could probably access it via a custom function node

steel notch
#

I can't seem to make it go to TexCoord?

#

Very odd.

kind juniper
#

Not entirely sure what you're doing or trying to do

steel notch
#

Since the base color control doesn't allow that.

#

Yes I know I can just make a regular emissive material, but idk. I thought it'd be useful to control that on a per particle system basis.

kind juniper
#

Might be easier with a separate buffer imho

steel notch
#

What do you mean by a separate buffer?

#

Like a whole render texture?

kind juniper
#

No. A buffer that contains this color for every particle. Then just sample in a custom node function

#

Though, I'm not sure how easy it is to bind it to the right draw call,

steel notch
#

In terms of where the data is being stored on the mesh.

kind juniper
#

I think you can access it in a custom node function by the name. vertexInput.Custom1.

#

Ah, but the function is not gonna have access to the struct.

kind juniper
#

Is it even there?

steel notch
#

Before it was using a URP Particle Unlit mat.

#

How odd.

kind juniper
#

I mean, yeah. If the material was not using your shader, then obviously that wouldn't work.

warm pulsar
#

I'm unclear if you could access any of this in the shader graph

#

I've recently written several ShaderLab shaders for instanced mesh particle systems

#

Unity provides a few functions you normally call in the vertex stage to set up the per-instance data

#

they modify things like unity_ObjectToWorld

#

They grab that data from a buffer

warm pulsar
#

see the example on that page

#

The main thing I'm unclear about is whether you could include that #pragma instancing_options procedural:vertInstancingSetup directive

steel notch
steel notch
warm pulsar
#

1000 matrices, 1000 colors, 1000 speeds, etc.

#

That requires some extra legwork

#

If you aren't doing instanced rendering, then that data will just go into extra texture coordinate streams

#

the particle system creates a large mesh every frame and sends that entire thing to the GPU

warm pulsar
steel notch
warm pulsar
devout quarry
cedar escarp
#

need help on a shader, happy to pay someone to finish - see thread for details

soft solstice
#

Hi all. I am creating a dissolve type of shader using the usual alpha cutoff techniques. However I want to avoid dissolve across the mesh and instead dissolve based on a growing circle. This I have done through some simple radius controls.

But when I add noise to make the cutout less like a uniform circle I end up cutting out pixels further away from circle edge. Has anyone got any advice on how to only add noise to the edge of radius cutout instead of the entire material?

amber saffron
foggy bison
digital gust
#

Has anyone ever made a soft occluder shader?

#

Like fading out object A with anothers object shader while hiding object b entirely?

hearty obsidian
#

How's this accomplished? The grass at the intersection

amber saffron
amber saffron
amber saffron
rigid halo
#

How can i get a masked material reference to be able to modify properties? im doing this on a UI Image.
in code that is

digital gust
# amber saffron Do you have a particular fading method in mind ? Simple alpha fade or something ...

So the whole usecase is to mask out objects on specific spots in 3d space. For now I tested with spheremasks or similar. The purpose is to have some kind of soft occlusion on vision pro like the people awareness but the other way around, so real world objects (predefined positions) should be shown inside the digital world. But as the distances are quite large, we cant rely on the visionos build in occlusion resolution.

#

In the end I plan to create some kind of "cloud volume" as array that feeds that matrix mask into the shader and cuts out those parts, but thats like the top notch and result

warm pulsar
#

if so, it's easy enough to clip out pixels that are too close to a world position

digital gust
# warm pulsar Can you change the shader that object A is using?

Yeh, there are two approaches I am researching. Everything is transparent shaders (not the best experience in z fights on AVP) and we can just clip with a mask/texture or having something like the standard occlusion material of Unity (which converst into realitykit materials), but instead of hard cut, have a soft fade

warm pulsar
#

So I've been working on a pretty wacky shader for a VRChat avatar that does something in this ballpark

digital gust
#

As the second option would need camera access (only for enterprise purposes available), I guess I have to stick to option one

digital gust
warm pulsar
#

It cuts out chunks of the world and renders my own stuff in those spaces. I rewrite the depth buffer with the SV_Depth semantic.

#

you hate to get sent to the Optimized Box

#

(yes, this is Cyberpunk 2077-themed)

digital gust
#

haha, nice effect

warm pulsar
#

It figures out which parts to chop out by recovering a world-space position from the depth buffer

digital gust
#

it it some kind of array or one position you check for?

warm pulsar
#

It's one position

#

I'm working in VRChat so I have like

#

two tin cans and a string here

#

if you want to input additional positions into a shader, you have to add black non-important lights with a specific alpha value and then see if your light array contains it

#

it's great

warm pulsar
digital gust
#

hm, wonder if I can use that on AVP.

warm pulsar
#

If you badly need to punch a hole in the world to display something else, it might just be the way to go

warm pulsar
#

I feel like you can do way, way more if you can actually write..you know, renderer features

#

and run scripts

#

๐Ÿ˜ญ

digital gust
#

post process or camera access would be all i need, but no ๐Ÿ˜„

warm pulsar
#
fixed4 frag(v2f i, inout float depthOut : SV_Depth) : SV_Target
{
    float3 worldPos = ClipToWorldPos(i.clipPos);
    
    i.clipPos /= i.clipPos.w;
    
    float4 grabPos = ComputeGrabScreenPos(i.clipPos);
    bool keep = CalculateCoverage(worldPos, grabPos);

    grabPos.xy /= grabPos.w;

    float raw_depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, grabPos.xy);
    
    depthOut = raw_depth;
    
    if (!keep)
        discard;

    depthOut = LinearEyeDepthToOutDepth(10000);

    return 0;
}

that's the gist

#

CalculateCoverage decides if a pixel needs to be affected

#

oh yeah, and

#
inline float LinearEyeDepthToOutDepth(float z)
{
    return (1 - _ZBufferParams.w * z) / (_ZBufferParams.z * z);
}
#

copy-pasted from a bgolus post as god intended

#

something that I genuinely do not understand is why I need to pass the clip position as a TEXCOORD semantic to make this work right

#

the SV_POSITION input produces crazy results if you try to use it to calculate a grab pos

digital gust
#

Thanks a lot for sharing that information! I def. need to dig more into custom shaders. The issue is, that unity to AVP is a hassle as unity will ocnvert everything to realitykit materials. So I gotta hope, the shaders stuff is working on the converted part too

warm pulsar
#

oh yeah, that's a whole can of worms I know nothing about

digital gust
#

Yeh, its cool they make it easy to build, but all those features you are waiting for unity to adapt are sometimes show stopping.

#

I had not once hack myself into the build xcode project to get features, that are in xcode but not in unity yet ๐Ÿ˜„

digital gust
warm pulsar
#

At the end, I read the camera depth texture and restore the depth buffer with it

#

(or just clobber it completely, so that transparent renderers don't show up)

#

i was seeing everyone's eye lens materials through the illusion, haha

digital gust
#

haha, camera depth texture, yeh, nothing you get from apple rtight now unless you are enterprise which leads to 100+ employees and a lot of other stuff to fulfill

warm pulsar
#

oh, I mean the depth texture of the Unity camera

#

not the real world

digital gust
snow forge
#

Hi all,

Soooo, I'm trying to build up a shader that fades with distance to camera.

It's all working, except for one thing, it looks like it's inverting my normals and I'm a bit baffled as to why (nothing to do with the mesh, it worked fine until I added this new section of the graph to the Alpha channel

Here is the graph, and the result at what supposed to be 100% opacity.

Could anyone point me in the right direction as to what I'm doing wrong please?

frigid jay
snow forge
#

Umm.....Okay, why does this happen when I change the surface type to Transparent? ๐Ÿ˜•

Texture has no alpha channel etc.

warm pulsar
#

A Transparent material does not write to the depth buffer.

#

It doesn't matter that it's got an alpha of 1 (meaning that it completely replaces the contents of each pixel)

cedar escarp
echo moatBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
โ€ข Collaboration & Jobs

lavish spindle
#

no matter what i try i cant get shaders to work on my 2d game

eager folio
lavish spindle
#

Urp shaders

grizzled bolt
#

You have to be more specific about how you encounter the problem

snow depot
#

Is there a way to change the Bayer pattern values to have less +s snd Xs and look more like the second image?

soft solstice
high hamlet
#

Hey, absolute noob at shaders here, I'd like to create some sort of "corruption" effect that would be some sort of noise that slowly moves over the object providing pulsing dark spots and such, any idea what guides / tuts / references I could look up to do this? Other than "I might need noise and some way to move it" I'm pretty lost ๐Ÿ˜