#archived-shaders

1 messages · Page 202 of 1

meager pelican
#

Or something outside of clip-space I guess.

willow pike
#

Interesting. How would I go about doing that?

grand jolt
#

Who are you asking 👀

willow pike
#

Would it be the same approach I'm doing now but using just setting vertex position to NaN where I have blue in my test scene?

grand jolt
#

Idk, I'm late to the grass talk.

meager pelican
#

You're basically asking to check if it is "under" something in your mask map. And IDK if you can go by some origin like object-space vertex 0,0,0. If so, you can check the mask, and then decide on a binary basis if it is clipped or not.

And I haven't decoded his shader. Hate graphs. But.
you could set the output clips space position of each vertex to be something that gets clipped.
Maybe with a conditional and a ternary operator.

stable lake
#

@grand jolt it probably would be easier to just ask: how do you make a shader for leaves?
my idea of simply slapping the texture with a sample 2d array and connecting it to the alpha clip threshold has failed and the result is just a grey blob? anyway, not sure what i can still add or remove, or what im actually doing tbh

grand jolt
#

Ugh, let me load up the sad clone of Amplify.

stable lake
#

really thought it'd be much simpler to get some trees going but damn 😫

#

sure

grand jolt
#

Gonna be URP, I ain't sitting here for 10 minutes opening my old HDRP project 😄

stable lake
#

ik the feeling, if i can translate it to hdrp then idm

#

i guess some things will be differnt

#

i just need the leaves to look like leaves, then figure out how to do a water and waterfall. thankfully i found some tutorials on youtube for those, and got pretty close to a decent result

willow pike
meager pelican
#

I'm unclear on if you have individual blade meshes or you said quads?

willow pike
#

They are built using quads but all of the grass on one "terrain chunk" is combined into one mesh

#

not actual Unity terrain, a mesh representing my terrain

meager pelican
#

Oy. It looks 2D from the pic you posted. So I'm getting confused.
So the "mesh" is a quad, or a bunch of triangles. Ortho mode camera.

#

I'm asking because IDK how you isolate a "blade" in a camera-facing quad with lots of grass on it.

#

Since the verts are the vers of the quad, not the blades.

willow pike
#

Yeah the grass is a series of quads that all face forward in a 3D environment but after they are created they are combined together. Our camera is static so there is no need to rotate them.

#

If you change the material so there are no textures, it looks like a bunch of cards following the surface and facing in one direction

#

It's a toon shader so the lighting gets flattened, but they look like this when the texture is off

meager pelican
#

See the shader you're converting uses individual blade-meshes. So it can figure things out. Yeah.

OK, so maybe you can figure out the worldspace position of the verts along the bottom, but you won't be able to isolate a diagonal piece of grass in the texture on the billboard.

#

Which would be a problem.

grand jolt
#

@stable lake smth like this maybe

stable lake
#

thanks, ill give it a go

willow pike
#

I think it's okay if it roughly follows the shape of the grass using the top of the quad, it doesn't need to be completely along the "point" of the blade in the texture

meager pelican
#

You need the bottom of the quad, mapped to your map. As far as the "top" goes, IDK what to tell you...that's the problem.
You're using an individual-mesh technique on a billboard quad.

#

The best you can do is clip all the Y (vertical) parts from the occluded part on up to the top of the quad.

stable lake
#

@grand jolt finally, that worked. you saved me a lot of headaches man, thanks for taking the time of day to help me out. bless u!!

grand jolt
#

Next step would be writing em by hand with fast fake SSS 😄

stable lake
#

i started learning c# a month ago, my skills aint gonna cut it lmao

#

maybe in a few years

willow pike
#

I think that would be a good enough solution @meager pelican, I think I need to break and come back to it. This is a brutal problem to solve. Thanks for your help.

meager pelican
#

Cool, just remember that if you're clipping PIXELS then you have to pass that to the frag() stage and clip it there. You can't just clip the whole mesh. Then you may get into some (hopefully minor) mobile issues on tile-based systems.

#

@willow pike

willow pike
#

Yes it would definitely need to be clipping pixels rather than the whole mesh. I'll give it another go later and post any progress. Let me know if you have any other ideas, feel like I just fried my brain hahaha. There has to be some simpler solution 🤔

meager pelican
#

I'm remaining optimistic. 🙂

grand jolt
#

The most reasonable solution would be just automatically generating grass detail splatmap that doesn't have the grass there.

willow pike
#

That sounds like a good idea, would it be able to update the grass when we add in new objects to the terrain surface or move existing ones? We want to be able to work in the editor and quickly see the impact of changing scene compositions without having to finesse grass that ends up stabbing through objects and looking bad.

grand jolt
#

Ideally you would have a bake button in your editor tool.

#

Are you using the terrain system?

#

You could also flip the concepts upside down and do what Far Cry V did.

#

Where you paint biomes.

#

And place the buildings.

#

Then press bake and it places everything accordingly.

willow pike
#

It’s a custom system using subdivided planes that we can change the elevation of. (Think Roller Coaster Tycoon or Parkitect) but we want lush toony BotW style grass in most biomes.

#

The important part is that we have a way to quickly change the detailing over areas and move things around and have it look good without getting hung up on correcting the grass each time we add features or move stuff.

#

Seeing grass stabbing through rocks and tree trunks all over is giving me an aneurism lol and cleaning them takes too much time

verbal python
#

how to fix this shaders problem?

#

that purple thing is a plate

#

dont worry about it

stable lake
#

try upgrading your materials to hdrp materials

verbal python
#

hmm okay how tho?

stable lake
#

edit > render pipeline > hdrp > upgrade from builtin pipeline > update materials

verbal python
#

But

#

i have alot of matirials

stable lake
verbal python
#

i cant go 1by1

#

ooj

#

kk

stable lake
#

you can do it 1 by 1 or do as i said, that will automatically update all materials for you

verbal python
#

wait @stable lake

#

in wish tab is that?

stable lake
#

on Edit

#

and render pipeline

verbal python
#

i have that renderpipe thign but i dont have the HD render ... @stable lake

stable lake
#

well what render pipeline are you using

#

i assumed its hdrp

verbal python
#

so?

stable lake
#

well even if its URP should be the same process

verbal python
#

not understanding basic please

#

i just want fix to this

#

please 😄

grand jolt
#

So, I'm new to shader programing

#

Are there any good tutorial series that you guys recommend?

#

(Not new to unity, just shader programing)

willow pike
willow pike
grand jolt
#

Well how do you render the grass?

#

I don't have any links tbh.

willow pike
#

Currently I’m building the world using 128x128 “terrain units”. They’re just pro builder planes with subdivisions that we can change the heights off. But they have a grass spawned script that spawns grass quads at vertices along the surface of the “terrain unit”

grand jolt
#

So you create a mesh renderer per grass blade?

willow pike
#

They have some random offset and randomization in the uvs to create different looking more natura grasses

#

But after they are spawned on the surface of that 128x128 terrain chunk they are combined into a single mesh

#

Helps performance a ton

#

So one 128x128 chunk has a single childed 128x128 game object that contains all of the blades for that section of ground

wintry ridge
#

yes your guess sounds reasonable. I am checking the precision along with making a test build to play with a few variables in the shader.
The RT format doesnt seem to be the issue, its definitely some shader functionality that works different on the mobile architecture

grand jolt
#

@willow pike what I suspect modern terrains do is they dispatch a compute shader that samples the grass splatmap for the current streamed in area and build the vertex buffer with all the grass meshes in it. Then they queue up an indirect render call that uses that vertex buffer to draw it in 1 drawcall.

#

Anyway. If your grass is gameobject based you can put like a grass blocker collider on your houses or something and raycast to check if the grass is blocked. Or use a top down view acceleration structure that has all available areas where grass can go cached.

#

Idk if you place the grass in the editor or not.

#

To be clear I haven't done any of it. I just saw what some indie/AAA did.

willow pike
#

Gotcha! It is Game object based but since a whole field is a single mesh I wouldn’t want to turn off that whole field. The grass is created in editor. Maybe before the meshes are merged I can do a check against a splat or temp camera tied to that section of the terrain.

grand jolt
#

Some ideas: if you go with the grid of raycasts in the editor for removing grass, your tool can cache the last touched terrain piece so you can press bake last instead of bake all.

willow pike
#

Remove those blocked blade pieces and then merge the remaining

#

Yeah I would need something like that so it didn’t take five minutes to build every time I move something

#

I might end up using smaller sections of merged grass quads so only those small piece need to be rebuilt. But having a single quad game object for each grass piece got way too performance heavy in game.

grand jolt
#

You can go a step further and stop using gameobjects for grass completely.

#

Then you would save grass positions into a scriptable and later use it with Graphics.DrawMeshInstanced.

#

It would be less editor fuckery possibly.

willow pike
#

Interesting. Sounds like it would be nifty if I can figure it out!

#

And the grass would still show in the editor too? That’s important for us. I’ve seen a lot of nice grass tools that only spawn in grass at run time but we want to be able to see it as it will appear in game.

onyx jungle
#

Hey guys, say I wanted to shade the interior of a shape completely white, i.e when you enter the shape, the parts of the screen inside the shape should be shaded completely white, how could I acheive this?

grand jolt
#

@willow pike yes. You would need to hook into the renderer.

#

In URP you can do that using the .preRender event on the pipeline or by writing a custom Renderer Feature.

stark canopy
#

Hey, hope everyone's doing well. I had a question relating to CustomRenderTextures. I'm attempting to write a shader for a CustomRenderTexture attached to a RawImage component on a UI GameObject. The only thing I'm trying to do in the shader is render an inputted Texture as-is to the RawImage. But for some reason nothing is being rendered to the RawImage.

I probably wouldn't be trying to use a CustomRenderTexture for this, but the project I'm working on uses one. If anyone has any tips or advice on this, that would be awesome. Thank you!

Shader "Custom/DrawTexture"
{
    Properties {
        _SnapshotTex ("Snapshot Texture", 2D) = "white" {}
    }
 
    SubShader {
 
        Lighting Off
        Blend One Zero
 
        Pass {
 
            CGPROGRAM
 
            #include "UnityCustomRenderTexture.cginc"
            #pragma vertex CustomRenderTextureVertexShader
            #pragma fragment frag
 
            sampler2D _SnapshotTex;
 
            float4 frag (v2f_customrendertexture inputFrag) : COLOR
            {
                return tex2D(_SnapshotTex, inputFrag.globalTexcoord.xy);
            }
 
            ENDCG
        }
    }
}
meager pelican
onyx jungle
meager pelican
#

This can be done with things like light and fog too.

onyx jungle
#

Also hey again, thanks for your help with the sand 🙂

#

Imagine this scenario

#

where the camera is clipping inbetween the object

meager pelican
#

🙂

onyx jungle
#

I essentially want to render the interior white here

#

Also it would need to work for an irregular shape

#

not just a perfect sphere/square

#

any pointers would be great

#

I did try tinkering with screen effect shaders, but they seemed to effect the whole screen, I needed it to be per object

meager pelican
#

Yeah, it's a whole thing. Often/usually done with ray-marching. It's almost a discipline in and of itself. It is for things like medical imaging. You're going to have to bite the bullet in research if you want "pretty" results.
See that link above and start googling first to familiarize yourself with volumetrics.

onyx jungle
#

hmm ok

#

thanks, ill take a look

meager pelican
#

I wish (sincerely wish) it was a 1 hour answer. But it isn't.

#

But maybe you can cheat somehow. Like think minecraft instead and do voxels and small objects.

onyx jungle
#

how do you mean

#

how could voxels help render the interioir of an object white?

#

or were you just thinking of a comparison

meager pelican
#

Well, just like real objects are volumetric and are composed of atoms, your objects could be composed of many small cubes. Fairly small. With little effort and no ray-casting.

#

But it would look blocky like minecraft.

onyx jungle
meager pelican
#

Like procedurally generating it from voxels

#

OK

#

All depends on your needs and what you're after for the effect.

#

Let me ask you what you mean by "white"?

#

In other words, if you used 2 sided geometry, and you had interior triangles mapped to a white texture, but it is hollow inside, does that work?

onyx jungle
#

no not really, because I already have a volumetric effect going on within the object, currently utilizing some scattering

#

so the interior is actually orange by nature

meager pelican
#

OK, so much for the easy off-top-of-head cheats. Have at it, and good luck! 🙂

onyx jungle
#

Thanks 🙂 Ill let you know if I find a nice solution

#

first stop for me is that link you sent

#

thanks again

warped vigil
#

ayy, so im having troubles inverting a transparent cutoff shader

#

basically, when an image is has an alpha above X, make that part transparent

#

the white circle should be transparent and letting me see through to the other side

#

but no matter what alpha i set the pixel to, its not transparent

shadow locust
#

should be able to just do like alpha = 1 - alpha

#

Are you using shader graph?

warped vigil
#

the fancy visual scripting thing?

#

can i use clip() pixels above a certain alpha value?

#

i basically just need to inver the default transparent cutout shader

#

ack!

#

to that end, how do i even know my shader is transparent?

#

maybe its been working, but the background is just white

wheat quail
#

is there an easy way to do this(?) : I want to be able to add my own ambient lighting (NOT the global ambient lighting) to a material using a Lit Shadergraph. Basically I want it to behave like a lit graph sometimes and a unlit when I tell it to.

#

I figured it out. nm

warped vigil
#

ack

#

clip(1 - col.a); doesnt for me

#

drats

warped vigil
#

yeah, why does setting col.a = 0; do nothing?

#

WAIT

#

I THINK I DID IT

#

HAA

#

aaand i immediately fucked up and lost it somehow

#

welp

meager pelican
#

@warped vigil Alpha cutoff is for opaque stuff. It's not usually run in the transparent queue. Maybe you can override that but IDK if you're using SG.

#

Otherwise, use transparent queue, and do the cutoff manually. To do that use the discard or clip nodes.

#

So if you're doing any non-zero levels of transparency.

warped vigil
#

i plan to

#

and im not using shader graph

#

col.a = 1 - col.a;
clip(col.a - _Cutoff);

#

inverts it how i like

#

but only does full transparency of not, and i would like inbetween values as well

meager pelican
#

OK. So if alpha is, say .75 and _Cutoff .5, you want that to be gone? But if alpha is .25 you want it to stay.

#

And for .25 do you want that 25% transparent, or 75%

warped vigil
#

the grey area should be half transparency, but clearly isnt right now

meager pelican
#

Are you rendering in the transparent queue? And what are you putting into alpha?

warped vigil
#

right now, a camera looks at sprites on a specific layer

#

or this

meager pelican
#

There's a pragma in the shader that tells Unity (and you) what queue you're in. I'm asking what queue you use. I don't care what your pics/sprites look like yet.

warped vigil
#

transparent queue

#

at least in the code its tagged as such

meager pelican
#

And you're doing traditional blending?

warped vigil
#

cant say i know quite what that means

meager pelican
#

Surface shader or vert/frag or what?

warped vigil
#

vert frag

meager pelican
#

Is there a blend command in it?

#

(search for "blend"

warped vigil
#

nope

meager pelican
#

You could try adding
Blend SrcAlpha OneMinusSrcAlpha
up in the pass section, but I think that's the default.

#

Probably won't fix it. You'd have to post your shader.

#

Best to use pastebin or something to post it.

warped vigil
#

gotcha

#

mind you, its a pretty awful bootleg of one of my other shaders

#

i struggled for a bit, so i just started trying random shit

meager pelican
#

It's always fun, no judging.

#

Just fun

warped vigil
#

ayy

meager pelican
#

I still don't know what you want the alpha to be though, after clipping. The original or the modified somehow one?

warped vigil
#

i took a look at the editor and the blend SrcAlpha code worked

#

huh, nice

meager pelican
#

Cools. Your render type is still cutout, and IDK if you want that. (in the tags). Will have to look that up.

warped vigil
#

its not quite perfect, but it worked well enough for what i need it to do

#

thank you for the help

loud remnant
#

When I look down the floor material is visible

#

When I look a different direction it looks darker

#

Anyone have this problem,?

#

NVM lighting was turned off

plush oasis
#

hi there, i dont know if this is the right channel for my problem. -> i use a model package from asset store, i replaced shader for all objects, the problem is, after replace the shader, the material is stretched on some surfaces. not alle on the object. maybe sometimes only one side is streched. without my shader everything looks good. any ideas?

latent mirage
#

hello, is it possible to create or use already existing shader to avoid / ignore object's Normals? I have a lot of objects that have inverted normals, and I want to use them unlit therefore i assume that there no need of normals. there is an example of viewport rendering from 3ds max that shows what want in unity. thx

#

I've tried 2 sided standard but half of the objects become transparent.

shadow kraken
#

a 2 sided unlit material should do what you need @latent mirage

latent mirage
shadow kraken
#

No, it means more triangles rendered on screen

latent mirage
latent mirage
shadow kraken
#

Literally the only thing to do is to create a new unlit shader and add Cull Off

#

Try two cases with and without that line and you can compare the performance

tacit parcel
#

I think the best way to fix this is fixing the model's (inverted) normal

latent mirage
meager pelican
latent mirage
#

but here is what normals do

#

upside and down side

meager pelican
#

Well, you can make sure tangents are recalced too (it should default to recalc if normals are recalced, but check). Tangents are used in lighting.

Otherwise, you've got some major modeling problems, and should fix it there like @tacit parcel said. Otherwise you're setting yourself up for a wold of hurt.

#

Just my 2-cents.

latent mirage
#

3d model have problems itself, it is normals, but i supposed that here is in unity some shader like in 3ds max that don't consider normals

twilit geyser
#

Hi guys 🙂 I am currently dissecting an HLSL script from a bought asset. I'm currently learning HLSL and I learned that you can use #includes in your ShaderLab shader and reference other HLSL scripts to use those functions. Now in the script I am currently looking at there is this part:

#define CUSTOM_LIGHTING_INCLUDED

void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out float DistanceAtten, out float ShadowAtten)
{
#ifdef SHADERGRAPH_PREVIEW
    Direction = float3(0.5, 0.5, 0);
    Color = 1;
    DistanceAtten = 1;
    ShadowAtten = 1;
#else
    float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);

    Light mainLight = GetMainLight(shadowCoord);
    Direction = normalize(mainLight.direction);
    Color = mainLight.color;
    DistanceAtten = mainLight.distanceAttenuation;

    #if !defined(_MAIN_LIGHT_SHADOWS) || defined(_RECEIVE_SHADOWS_OFF)
        ShadowAtten = 1.0h;
    #else
        ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
        float shadowStrength = GetMainLightShadowStrength();
        ShadowAtten = SampleShadowmap(shadowCoord, TEXTURE2D_ARGS(_MainLightShadowmapTexture,
        sampler_MainLightShadowmapTexture),
        shadowSamplingData, shadowStrength, false);
    #endif
#endif
}```

It uses functions like GetMainLight and GetMainLightShadowStrength. I don't see any references to other scripts in there. Looks like there are some globally available functions for every HLSL script I write? Where can I check what kind of methods I have access to globally?
regal stag
twilit geyser
#

Ah!

regal stag
#

I think those sort of includes aren't always available for the previews though, hence the need for #ifdef SHADERGRAPH_PREVIEW to prevent the functions being used for them.

twilit geyser
#

I see.

#

My main goal for today is to find out how I can get information about point lights in the scene within my shader. From what I saw in other scripts there's also a way to get the main light and then there's usually another function called AdditionLights. I understand it like this: the MainLight refers to the directional light in the scene while the AdditonalLights handles all other sources of lights. Is my understanding of this correct?

regal stag
#

Yeah

twilit geyser
#

Okay, cool. Good first step haha

regal stag
twilit geyser
#

Does the function have to be named AddtionalLights or is this just a common naming convention and good habit to call it like this?

twilit geyser
regal stag
#

The functions can be named whatever they want. For shadergraph in particular, the name of the function should also match the one used in the Custom Function node of course. It also needs to end in the _float or _half prefix, which allows you to select the function based on the precision of the node.

#

It's also common for HLSL files for SG to be wrapped in blocks like :

#ifndef CUSTOM_LIGHTING_INCLUDED
#define CUSTOM_LIGHTING_INCLUDED
...
#endif

Which is so, if the file is used for multiple Custom Function nodes within the same graph, it's contents will still only be included once. Otherwise it would cause redefinition errors.

twilit geyser
#

Ah, I remember reading this on your blogpost. Basically the issue would be that you define certain methods and if you run this again Unity would be like "hey, these methods have already been defined, I am not sure what to do now". I have a background in C# so it would be basically similar to checking if something is != null before doing something, right?

regal stag
#

Yea, something similar to that

twilit geyser
#

Okay, I think I understand it. I'll try to get my hands dirty and see how far I will come. Probably back with a question in 5 mins hah

regal stag
#

But #ifndef / #ifdef / #if etc are handled when the shader is compiled, rather than at runtime like just if

twilit geyser
#

If I wanted to have access on functions from another hlsl script I could also just use #include [PATH] after the #ifndef etc blocks?

#

Just like I would do it in a general ShaderLab shader I would write without SG

regal stag
#

Yep (at least I would presume so, I haven't really used other include files like that for SG yet)

twilit geyser
#

Got it

#

The WorldPosition argument in the AdditionalLights_float function - is this the WorldPosition of the fragment the shader is currently processing?

regal stag
twilit geyser
#

Hope you don't mind me asking so many questions, really new to this. TheView Direction what's that about? Is that the angle of the main camera looking at the object with the shader?

regal stag
twilit geyser
#

Cool stuff. Let's see if I can implement things.

#

What's wrong here?

regal stag
# twilit geyser What's wrong here?

The default precision of the node is float, so it's looking for a FogOfWar_float function which hasn't been defined. Either use float, or swap the precision on the node to half (can right click it to do that, or select node and check Node Settings tab).
(Personally I tend to ignore precision and always use float/single, but it's probably useful if you're targeting mobile)

twilit geyser
#

Ah, I thought Inherit meant that it looks what the function offers and just use that

regal stag
#

Ah no, it inherits it based on the precision of the inputs

twilit geyser
#

"the precision of the inputs" -> The V3 in my case?

regal stag
twilit geyser
#

is the type of the value required? It seems to be working without it. I have already declared output to be half4, will it not convert the (1,1,1,1) to half4 precision automatically when I assign that value?

#

Nevermind, it wasn't working, it just didn't throw an error

meager pelican
#

Your output variable is a half, not a half4.

twilit geyser
#

Oh, I had that changed already based on the answer from Cyan

meager pelican
#

OK, but assigning what you're assigning doesn't make sense then.

#

You would use a scalar value (a number).

twilit geyser
#

Well, I was wondering, if it converts automatically. Similar to C# where I can declare a float variable and assign an int to it and it will convert it to a float value automatically.

meager pelican
#

There is type conversion in shader language. And in the case of a constant the compiler will probably substitute the right type inline (compilers are better these days).

#

But in your case you're probably just getting the .r (same as .x) component of whatever you type in for constants.

twilit geyser
#

I see, I guess my case is just not covered by that substitution then. When I had the output declared as half4 and just assigned (0,1,0,1) it didn't throw an error, but it showed up as white instead of green inside shader graph. When I added the half4 type it worked as expected.

meager pelican
#

And to make it more fun, BaseColor is a float3. lol.

#

IDK, but it will all convert. The danger is that you may lose precision (but with colors you really always do in the end).

twilit geyser
#

I thought non-HDR colors use half precision. Read that on some Unity examples

past echo
#

quick question... the usual Renderer.materials, does it still work with URP?

twilit geyser
#

Thanks for the help by the way @regal stag and @meager pelican

regal stag
past echo
#

hmmmm, mind looking at my question from a few minutes ago in #archived-code-general ? Probably should have asked it here instead

meager pelican
regal stag
past echo
#

ahh makes sense, I'll give it a go, thank you

main coral
#

Hello everyone! I still have some pretty ugly artifacts from my cel-shader. Did anyone have similar problems?

#

Or does someone know how to fix it? 😇

twilit geyser
#

What does GetAdditionalLight return exactly? It requires an index and a position in world space. When will it return a light object and when will it return null?

#

Where can I find these information? Googling those functions usually just lead to HLSL scripts using them, but not the ones declaring them or explaining them.

regal stag
#

Might vary slightly depending on version, that's the v10.3.2 one. Can change the branch/tag on the repository to view other versions. I think the master branch has moved it to a separate hlsl file now too.

twilit geyser
#

Does the version in the URL represent the URP version?

regal stag
#

You should also be able to view the source in your Packages folder

twilit geyser
#

I see.

I'm on URP 12.0.0 right now to be able to use Light Layers in URP. Tried using the code that's also in Lighting.hlsl but it always returns true for me at the moment.

#

So, I think what it is currently doing is this:

  1. For every fragment of the mesh, check the world for additional lights
  2. If there is an additional light in the scene that matches the light layer of the mesh then mark the output as green
#

I activated Light Layers in the URP asset, set my Point Light to LightLayer2 and the Cube Mesh I'm using to test on LightLayer1. So this should not return true?

regal stag
#

@twilit geyser Ah, also if you're using it in an Unlit Graph, you might need an _LIGHT_LAYERS boolean keyword (global, multi_compile) defined in the blackboard.

stable lake
#

Quick question, does the HDRP already have depth texture and opaque texture on?

#

If not, where do I find the check boxes?

regal stag
#

I think they're always enabled for HDRP

twilit geyser
#

How do you usually add credit to another author inside HLSL scripts? I copy pasted parts of your custom lighting shader

#

Just as a comment at the very top like in C# scripts?

regal stag
#

I don't think there's any proper / recommended method, but sure a comment somewhere would do.

stable lake
#

Following this tutorial trying to create a water shader, at 17:03 he creates a noise texture and uses that as what would be, wave scale.
I can't follow along since I can't see the noise texture being applied to my plane, not sure why? Can anyone give me any insight maybe why this happens?
https://youtu.be/FbTAbOnhRcI?t=1063

Hello and welcome to, like, the 10 millionth water tutorial I’ve done. In this week’s video we’re looking at some more in-depth Unity Shader Graph features to make water, or an ocean, with shoreline/edge foam, depth, and waves.

Shader is compatible with HDRP., Edit: it used to be compatible with LWRP but Unity changed something. I'll update t...

▶ Play video
stable lake
#

sure let me make it a bit better to see

#

first screenshot is what should make the noise texture appear, it's hooked to emission, like in the video

#

second screen shows the normal maps

#

third screen is just a displacement, no clue what it does, hooked into position vertex.

#

i didn't create that part, but it was there from a previous shader, and im just trying to add some new stuff to it

regal stag
# stable lake

It's a little strange that the noise preview is cyan. I know that colour is used when shaders are compiling but I've personally never seen it used in a preview like that.

stable lake
#

also, idk if its worth nothing

#

but i can see the foam being applied in the material preview

#

yeah thats also weird shouldn't be cyan

#

in the video it's black and red

regal stag
#

Maybe unconnect the other parts of the graph from the master and only have the emission part (with base colour set to black). That might help debug if the noise is working properly. Make sure properties aren't set to 0 (in both shader graph node settings and material inspector).

stable lake
#

Well I tried it out and it's definetly something up with the noise, even with just the noise plugged in, there is still no change what-so-ever to the scene view

#

I've read the comments and other people that had these issues simply: enabled "Depth Texture" and "Opaque Texture",
check ZWrite in generated shader code and if it is "Off" then set to "On".

#

Neither works for me

stable lake
#

@regal stag no worries, i didn't get it to work, but that displacement part in my shader, turns out it does exactly that, creating waves

#

so no need to bother

keen patio
#

Hi, I want to access the lightmap uv2 in shader,
before the lightmap is baked.
yea, there is no lightmap, can I use the uv2 only?

meager pelican
#

The lightmap UV's (in uv2) are usually set by the modeling program or on import. IIRC.

#

what pipleline?

harsh marsh
#

How can I achieve a random tint on the color of a material per every object it's on in a shader graph? This is the effect I want. These objects all (except the metal balls) have the same material in Blender.

#

got it! had to use the Object node and use the position property on that

wraith verge
#

How do I create a heat wave effect with urp?
In unity 2d

meager pelican
#

What pipeline @wraith verge ?

wraith verge
#

Universal render pipeline

meager pelican
#

Yeah, I knew you were going to say that... lol.

#

It's easy in 3D with URP.

wraith verge
#

Welp rn im kinda dying cause of this code lmfao

meager pelican
#

In 2D URP the screen background isn't captures as with the scene node

#

last I knew

wraith verge
#

I could use particles tho for the effect right"

meager pelican
#

I'm searching to see if you can get hold of the back-buffer or something. Otherwise you may need another camera

#

IDK if a render feature will do it either.

#

But in order to distort it, you have to be able to grab it, read it, somehow.

#

3D you can. But 2D was a PITA last I knew. Checking.

wraith verge
#

Like the bread or...

meager pelican
#

Sorry, but I dont' want to explain that one. No, like pain in the ____

wraith verge
#

oh

#

ok

#

LMFAO

meager pelican
#

lol

#

Here, check this while I check it too.

wraith verge
#

ok ty

#

I will later cause today is finals

#

I think I've looked at that before

grand jolt
#

Hello. I hope this makes sense, as I am a beginner in Unity and coding.
I created a 3D project, installed the HDRP Shaders in my Unity Project and created a HDRP Hair shader graph for my characters hair.
How do I go about making it functional? ( Example: http://prntscr.com/138hult )
I will appreciate any form of information. I have searched Google & YouTube and cannot find this specific question anywhere on the internet.. Only about other shaders that I cannot purchase at this time. Thanks in advance.

Lightshot

Captured with Lightshot

#

If anyone needs any more information, I will definitely provide it for you. I appreciate any help I can get. 🙂

lean lotus
#

hey would it be better to implement a real time image denoiser in a compute shader, or is there a better place to do it? also are there any examples/code samples that I can use for denoising images in real time by chance?

meager pelican
misty flame
#

I've been trying to do a refraction effect on water and make it based on how far it is under the surface so the color represents how strong the effect will be.

#

For some reason, there's some white on the bottom of the screen that'll always be horizontal and is based on how close the beach model is to the surface of the water.

#

I disabled the water completely in the second picture (the water you see in the second pic is just part of the model)

#

Here's my setup (it's pretty weird since I've been trying to debug it)

#

I've been trying to fix this for a while and I'm pretty new to this so I don't know what's going on

#

I'm guessing for some reason the scene depth and screen depth of the pixel are getting closer to each other for some reason at that white part.

brittle owl
arctic sierra
#

is vertex displacement not working for visual effect shader graphs in 2020.3?

#

extremely simple graph, it does nothing when applied to an "Output Particle Quad" node in a vfx graph

urban dune
#

Is amplify shader 'standard surface shader'

indigo frost
#

So how heavy is shader effect graph excatly?

#

I did make 1 graph, and it was enough to choke out my gpu with just 1 instance of running it

thick fulcrum
#

sounds like you made the exception, did your graph contain a loop?

indigo frost
#

A loop

#

Hum I'm not sure actually, pretty new to shaders in general

#

Let me send it to you

#

I don't really see a loop in there, but i could be wrong

#

It's the first graph that i made following somewhat of a very helpful tutorial

#

but it is a shame that it uses this much resources

thick fulcrum
#

I'm not about to open a random file, screenshot of graph or in the case of code can be enclosed in quotes or for large files use a suitable code posting site.
But that extension suggests it's Visual Effects Graph as in particles not shader graph.
it maybe a question for #✨┃vfx-and-particles channel

indigo frost
#

i did say visual effect graph

#

is it not considered a shader?

thick fulcrum
#

that does not read as visual effects graph 😉

indigo frost
#

oh

#

i mssed that up

#

i meant visual effect graph

thick fulcrum
#

visual effects graph uses shaders, it's not exactly a shader and there can be many things which affect performance

indigo frost
#

Would you still like an image of the graph?

#

Or should i ask in the vfx like you suggested?

thick fulcrum
indigo frost
#

Okay

#

thank you

thick fulcrum
#

good luck 😉

grand jolt
#

How do u add transparency in shader graph? I am using a blend node and setting it to Base Color in Fragment

#

Am I doing something wrong? Also Color Out is connected to Base Blend

thick fulcrum
grand jolt
thick fulcrum
#

if you don't need full transparency, you can use opaque and enable the alpha clip checkbox to have an opaque cutout shader.

#

then it should be as simple as feeding your alpha into the alpha on frag, either from texture, mask or calculations etc.

#

if your using older version it's still very similar and lit / unlit makes no difference to this option

#

I think on older version was a cog wheel you need to click on corner of the node

grand jolt
#

Really appreciate it 👍

meager pelican
#

@arctic sierra All you've done is translate the verts by 1,1,1. So you've moved the whole thing over, up, and back, but it won't be changed in shape. Its center is in a different place.

bleak stone
#

I'm very confused, I'm using the URP Lit shader, with alpha blending, but my object is not rendering over the skybox. In fact it renders really inconsistently. Sometimes I'll see it rendered only over an object with the skybox drawing over the top (resulting in it looking masked)

#

here's the material

#

I tried changing the priority hoping it would render last, but that doesn't help

#

Ok I fixed most of my issues by changing my skybox shader from Mobile/Skybox to Skybox/6 Sided. there are still some cases where it wont render over an object, which is weird

meager pelican
#

It will still pay attention to the depth buffer and z-test against it. But it won't update the buffer for its pixels. So if it is positioned "behind" something, it won't draw over it.
There's another thing called z-fighting, that happens if the depth is identical to another object in the scene, so they "fight" over who wins or not, leaving weird results. If you think that is the case, you can slightly alter the object's position (by like .001 or something) to help deal with it.

#

And the skybox should be rendering BEFORE the transparent stuff renders. So that's weird.

#

@bleak stone

bleak stone
#

thanks for the reply! here's the issue in action. the game is paused currently

#

the teal rock going a solid color is actually a GIF artifact, sorry to be misleading there. the only thing that looks weird is the little sphere

vocal narwhal
#

If the other objects are using transparent shaders then this will inherently be a problem

bleak stone
#

ahh yeah good call. although the teal-ish rock has an opaque material, and then over the top of that, there's another material. but maybe thats causing trouble

#

heres that

#

heres an object with just one opaque material and its not drawing over the top of it

meager pelican
#

Change the shader to just output "red" in the fragment. Dump everything else other than clipping if any. Set frag color to (1, 0,0,1) and see if it still clipped. If so that would imply that there's a z-issue.

bleak stone
#

Thanks for the tip, yeah that helped me narrow it down, its not a clipping issue

#

I mean z issue

meager pelican
#

Otherwise, if you get a full-red circle, you've got a problem with transparency (alpha).

#

Yeah

bleak stone
#

yeah i'm new to URP

#

this was working fine in built in

meager pelican
#

Try doing some kind of max with the alpha value you're putting into the stack.
Like max(yourValue, .25) and then plug it in.

#

Just as a test.

meager pelican
#

With URP, if you're trying to read the "back buffer" what you get is really a one-time grab-pass that happens between the opaque and the transparent stages. So it won't pick up the other transparent stuff either.
That is if you're using the scene-color node (I think that's what it is called).

bleak stone
#

Gotcha, didn't know that. thanks so much for the help!

smoky bridge
#
There are 102 objects in the Scene with overlapping UV's. Please see the details list below or use the 'UV Overlap' visualisation mode in the Scene View or Lightmaps in Lighting Settings for more information.

- Cube (13): 220 texels
- Cube (1): 191 texels
- Cube (20): 190 texels
.
.
.

I am trying to do some light baking, it was all good but now for some reason some objects aren't lit.

And i get this error?
What am i doing wrong?

meager pelican
#

Where did the models come from? Are they standard unity cubes or no?

#

If you're messing with UV's (or lightmap UV's in the 2nd UV set) that could be it.

harsh marsh
#

I've got a shader that lets me have random slight tints on objects to give them a more realistic feel (based on their world position. Every object with the material has a different tint) .

One problem is that I can't mark them as static without the random part breaking. Is there any way to fix this or is this just something that happens with static objects?

meager pelican
#

What pipeline?

Static objects are often batched. Depends on your settings.
What can happen is that the engine takes a bunch of your static objects, makes a combined-mesh out of them, and sends that one big mesh in one draw call. There's limits, so it may have to do that in several groups.

There are other ways to deal with unique instance variables, but I need to know the pipeline you're working in.

#

@harsh marsh

harsh marsh
#

URP

meager pelican
#

OK, if you're only tinting you might be in luck.

#

URP doesn't support material-property-blocks well last I knew. BUT, IIRC, it supports instances of _baseColor being set.

#

I'd have to test. Also what unity version are you using?

#

The alternative is to make materials for each block, and if you've got 1000 of them it's a pain.

harsh marsh
#

2020.3.7f1

meager pelican
#

One easy thing you can do is make like 30 different tints (with 30 versions of the material) and randomly assign the material to the render.sharedMaterial property.

#

Then you can have 1,000,000 blocks with randomized tints.

#

and only use up 30 material instances.

#

Short of that, you need to research Material Property Blocks and see if it works for SG baseColor still.

#

SRP batches by shader, not material, so you can have several materials, but MPB's might break batching, I'm unsure of the latest.

harsh marsh
#

Alright. I'll try that out thanks @meager pelican

#

Also, is there a way to increase the brightness of a color in shadergraph? Trying to port a blender material over and I can't find a node that's the same as Blender's brightness/contrast (which in Blender is only being used for the brightness part)

hazy bridge
#

Hello, does anyone know how to get OnEnable and OnDisable callbacks on the ShaderGUI editor? I would like to be able to call some funcionality once user opens up material and sees the inspector, as well as when he closes it ..

Would there be any reasonable way to do that?

meager pelican
#

There's also a contrast node but IDK if that's what you want either.

#

Generally, brightness is additive and contrast is scaled, as IIRC.

#

Don't forget you may want to saturate it to clip any over/under values if you're not HDR.

odd dagger
#

I'm confused. I made an Image Effect shader, only change to the code was to put "Blend One One" to make it additive and then made a material that used this new shader. When I attach it to an object, its colours are inverted and it has this weird fluff around it.

I tried changing the blend type and removing the blend altogether but the effect was still there. The effects do actually work in game, it's just my sprite looks like this lol

Any way I can sort this? Or any reason why it's happening in the first place?

arctic sierra
knotty juniper
harsh marsh
#

made a shader which projects a HDRI in a way that makes it have a 'floor'

#

though this messes up reflections.

#

Not sure how to solve this. Is there a way to make it so it only changes the way the skybox looks to the camera so it doesn't affect stuff that's reflecting it?

#

In a Blender shader (of which this is an almost direct port of), I would just do this

#

Is there an equivalent way to do this in shader graph?

mystic trench
#

Hi, I'm afraid I've got some more deferred rendering questions - does Unity's world-space normals GBuffer require a special conversion/sampling to read from?

#

I think the values I'm getting from it are incorrect.

knotty juniper
glass timber
#

I'm making a wave system and, initially, I was manipulating vertices on a plane directly with a script, then using the values from that script to apply sufficient forces to a floating object. Now I've changed to using a shader to make the plane look like it's wavy, how do I apply forces to the floating object so it matches the movement in the shader? I think using a compute buffer might work but I don't know how to use that to do this

hazy bridge
thick pier
#

Hello, I have a bit of shader experience with Blender, and I'm trying to learn Shader Graph now in Unity.
Is there an easy way to generate this "waves" style texture in Shader Graph?
I tried to blur the output of the "Checkerboard" node, but I don't see how to do that

thick pier
#

Oh nevermind. think I figured it out!

meager pelican
# arctic sierra that's what it *should* do, but it doesn't do anything

I re-read your question. Yeah, the position is going to be maintained by VFX graph's routines, not the SG coloring, IIUC.
If you use your simple-translation shader on a normal quad object outside of VFX graph, it would probably translate it all. But VFX graph is making billboard quads and locating them and maintaining a particle system on the GPU.

So without having tried it to verify this, it seems the most plausible answer. Your quad locations are overridden by VFX's needs. Best guess, two cents.

arctic sierra
#

that seems likely, thanks for the response

#

i got it working using the vfx graph, but it was a hassle not having the custom function block

toxic flume
#

I want to add some overlays and decals to weapons. I can implement a simple shader that receives an overlay texture and overlay it on top of base texture
Do we have a better and more efficient way to handle it?

grand jolt
#

@harsh marsh you can write an editor script that bakes the tint into the vertex color.

#

@toxic flume yeah, the most efficient way is hand modeling the mesh decals in a 3d modeling program.

#

A literal plane hovering slightly above the surface, that's what a mesh decal is.

mystic trench
#

Hey, sorry to bother again with this but it'd be helpful to know if the deferred rendering path normals gbuffer requires any special decoding, as I'm getting obviously wrong values.

charred shore
#

can someone tell me, why when I click to open the shader instead of opening the editor it open the visual studio?

grand jolt
#

Opening what editor?

charred shore
#

the shader thinggy

grand jolt
#

If you created a shader file instead of a shader graph, you can't open it in Shader Graph.

mystic trench
#

Shouldn't .shader files normally open in your assigned code editor?

charred shore
grand jolt
#

Nope, you need to create an Unlit Graph.

charred shore
#

sooo how can I create it, I don't have that option

grand jolt
#

Did you actually install HDRP or URP?

charred shore
#

yes

grand jolt
toxic flume
#

because only a small part of arm has a tattoo

grand jolt
#

Even with mesh decals you aren't using the texture of the main object. You use a separate decal atlas.

#

People usually pack many decals into one texture.

toxic flume
#

My main texture is 2048*2048
I should use the same size for makeup or tattoo as well, maybe I can scale it by 2, OK thanks

#

They are not static. The player can change it in runtime and choose between them

grand jolt
#

Hmm, for tattoos, I'd maybe texture swap instead.

#

So basically you'd create a full body texture for each tattoo using the same uv map and then you can mix any amount of tattoo textures on top from the skin shader.

toxic flume
#

Yes, my talk is about that

#

A simple shader with base texture+ normal + overlay

grand jolt
#

Yeah, it's perfect.

mystic trench
#

anybody seen errors like this before?

#

I keep getting them when writing shaders and googling this hasn't turned up anything

meager pelican
#

Now I know you're dealing with the normal buffer. But there's got to be some code out there somewhere

#

That you can see a sample of. (See below for DecodeDepthNormal helper function from UnityCG.cginc.)

mystic trench
#

Okay so weirdly enough subtracting vec4(0.5,0.5,0.5,1.0) from the raw sample gives me a correct result

#

Now I'm getting these darned source component initialisation errors?

meager pelican
#

Normals are kind of "encoded"

#

IDK about that one. Temp r1? Weird

#

It's implying that a z or b component isn't initialized.

mystic trench
#

Worst part is that I can't find anything on google

#

It's very likely some hlsl compiler error

#

some optimisation probably

meager pelican
#

This builds a screen-sized 32 bit (8 bit/channel) texture, where view space normals are encoded into R&G channels, and depth is encoded in B&A channels. Normals are encoded using Stereographic projection, and depth is 16 bit value packed into two 8 bit channels.

UnityCG.cginc include file has a helper function DecodeDepthNormal to decode depth and normal from the encoded pixel
value. Returned depth is in 0..1 range.```
https://docs.unity3d.com/Manual/SL-CameraDepthTexture.html
#

@mystic trench

signal flume
#

I'm a beginner with shaders and I've made a few attempts at recreating the grass effect shown in this video:
https://youtu.be/thUXblUXKeU
My last attempt was to calculate random positions on a ground mesh's surface and to then use Graphic.DrawMeshInstancedIndirect() to draw a large amount of sprites in those positions. This worked, but has a lot of issues like grass clipping through objects. Could anyone guide me to how the effect in the video works, and how I could go about creating it in my game?

Date of Recording: 2020-10-04

To avoid popping issues, grass is shaded directly, by transferring the world position and normal of the base terrain in 3D, which does not change frame-to-frame. GPU instancing is used for performance reasons. A random subset of the grass is given a separate sprite and a randomized color, to add visual interest.

▶ Play video
mystic trench
#

Doh, thank you @meager pelican

odd dagger
#

Okay so I figured out why the colour was all weird, but this background colour still persists. I need the sprite to just be the flower. Any way to get rid of the weird edges?

charred shore
normal sable
#

Hey guys! I'm creating a dissolve effect that applies to all materials in a scene that fades when far from the camera, but I don't know how to apply this effect to all materials in URP, without needing to create a shader variant to each material type. Someone knows how to do this?
Also, some materials use hlsl written shaders, so creating a sub-graph won't work in my case.

mystic trench
#

@meager pelican Welp, still getting this compiler error with that uninitialised value stuff

grand jolt
#

@charred shore then look up how to set up your pipeline cause it looks like you just installed the package without doing thr necessary steps afterwards.

mystic trench
#

Okay, I don't want to tag the unity admins in case that's verboten, but is there somewhere I can register this shader compilation bug?

#

I can't find any answers on it online or on the existing unity bug tracker.

harsh marsh
#

Even if I set metallic to 0, I still get a hint of the reflection still in the sphere

charred shore
sterile flare
#

Hi! I have a little problem with shader in Unity. This is portal shader and when I try to use him on my mesh I see very strange result.
I understand that the problem is UV, but i have any idea, how I can fixed it.

meager pelican
mystic trench
#

Yeah and the worst thing is that I can't find anything online about it

#

and the unity bug tracker doesn't seem to have anything?

misty flame
#

Hey I've been trying to follow this guy's tutorial https://youtu.be/kgXeo2SRDd4?t=401 but I've gotten to a part where I get a problem that he doesn't get. In the depth mask part of the video, he shows the depth of an opaque object below the water using color with white being close and black being far. I tried using my own method to do this a few times and it worked except for the problem shown in my video. That white part of the bottom of the screen was always there no matter which method I used. I even tried his own method exactly but I still got the same problem. If anyone knows anything about this please lemme know (I also show some URP settings in the vid)

In this one we us a texture based displacement map coupled with a normal map, both made in Blender (not shown) using the ocean modifier. Really simply stuff, but amazing results. We're also using refraction but not in the same way that everyone else is using it, so that's either good or bad.

● Support Links:
♥ Subscribe to learn more!: https://...

▶ Play video
grand jolt
#

Is it possible to make an outline shader for pro builder objects? I'm looking for an effect similar to this:

#

I want the outlines to be as they are when I select a pro builder object

#

Any ideas?

harsh marsh
#

I'm trying to create a shader for the skybox that reprojects an HDRI/Cubemap in such a way that it creates a floor.

Might current implementation is fine but has quite a lot of distortion around the edges of the skybox.

I looked around and found this https://twitter.com/Cuboxel/status/1291900082653102080

My current implementation is a port of a blender shader so I tried porting this one over using the screenshot provided by Cuboxel. Problem is, all of the important nodes are collapsed and some even have hard coded values which can't be seen when the node is collapsed, making it impossible to recreate.

Because @cgonfire and @LucaRood shared their ground projection shaders, here is my version with no distortion and a border sphere #b3d https://t.co/0mqQwlMbrX

Likes

332

brittle owl
#

aagh this is annoying
how do i fix this z fighting? (is this z fighting?)

#

its just a transparent shader

lean lotus
#

so if I have a compute shader that does a bunch of stuff, but another compute shader that does denoising of the output of the first compute shader, what would be the fastest way to get things like a normal map, distance map, etc. from the first shader to the second shader?(first shader is a raytracer, second shader I want to denoise the first shaders output but idk what would be the fastest way to send the needed data from shader 1 to shader 2)

grand jolt
#

Does anyone have a shader that can use a collider and then hide part of a specific object? like for example if you had a black image and a 2d circle collider and you put that collider in front of the black image its like a transparent circle?

#

Black is the image, green is the collider and yellow is everything behind the black image

arctic sierra
#

so it's not possible now, but maybe a year from now

grand jolt
#

So in my shader graph I am using a gradient node on to sample gradient . Now the gradient node is half transparent but in sample gradient ( Time setting is connected to split from UV ) it doesn't show itself as half transparent ;-; . Any way to fix it?

grand jolt
#

Basically I mean .. in gradient node.. u can change transparency but when u connect it to sample gradient..all the transparency changes to black

wooden vortex
#

anyone got an example on how to create neon light of polygon sprites like this:

wooden vortex
#

how do I make it not affect the white line itself? Using URP and 2d light (very new to this part of unity)

grand jolt
#

bloom.

wooden vortex
# nimble drum bloom?

should I make like a diffuse emission part or just use the same texture(the pentagon). Does feel like it blooms over the white part as well. Also, any way to easily get more aliased lines?

nimble drum
sterile plaza
#

Hey! I'm getting this weird border around my sprite, and cant figure out why it is happening. Do any of you have a clue?:)

#

Should have looked like this

wide violet
#

How would i go about making alpha stay the same and not blend when it overlaps?

grand jolt
#

I think i am searching for a similar shader as you carnate

wraith forge
#

Not completely familiar on how this affects alpha, but you could try using different blend modes in your shader. Ideally you'd want a "max" blend mode or something similar

lean lotus
#

if im using a compute shader to write to multiple textures at once, is using a bunch of rendertextures the only real way? I want to pass it to a shader that does denoising, but I still need to figure that out at alll

#

also are there any online examples of using a shader in unity for denoising I can look at the code of?

nimble kraken
#

Hi All, just learning shadergraph currently, and wonder if there's a way to use the base lit material as, well an input to a graph? I've seen some talk of custom masternodes, but honestly, it's a bit over my head.

elfin prawn
lean lotus
#

are there any good examples I can look at for image denoisers or such in a unity shader? trying to learn things like temporal reprojection and denoising for this but im quite lost

grand jolt
#

If I am getting 2 errors of "floating point division by zero" but my graph works then do I have to worry?

grand jolt
#

Like Ik the meaning of error but Idk why it's happening after looking at shader graph

#

Leaving the image here (plus I also added a split node ('A' output is connected to Alpha input from the sample gradient node) so I can get output for Alpha)

onyx jungle
#

Hey does anyone know where I could download/create some 3D noise textures? Many thanks 🙂

lean lotus
#

would it be better to store each vertex and UV in one structured buffer, and a list of indices in another structured buffer(both being very long) for frequent reads in a compute shader, or would it better to, instead of both of those, have one big long structured buffer that stores every triangles 3 verticies and 3 UV's in one entry?

spark crystal
#

can I add a property to a shader that changes how it reacts to directional light color? for instance I have a yellow tint directional light but I want characters to not be affected by the directional light yellow tint

lean lotus
#

or would it be worse for performance if I pack a structured buffer of indices into a structured buffer 1/3 the length, but holds 3 indices per entry?
so i guess essentially, why does having a structured buffer made out of a struct of 3 int slower to read from than a structured buffer made of ints thats 3 times as long

wide violet
#

@grand jolt did you ever find a solution?

grand jolt
#

No

alpine blaze
#

Having an issue where when I replace a constant with a parameter (so that i can treat it as a user-exposed fine-tunable constant) it does... odd things, and the modifying the parameter does not affect the result.

defining the property: _SourceRadius("Source Radius", Range(0.0, 2.0)) = 1
declaring the variable in HLSL: float _SourceRadius;
using the variable: Out.sourcePos.xyz = Out.sourcePos.xyz + normalize(cross(cross(sourceNormal.xyz, -h.xyz), sourceNormal.xyz)) * _SourceRadius;

using _SourceRadius, it seemingly acts like it's either 0 or 0.1 depending on unknown factors. If I replace it with a constant, it behaves just fine.

alpine blaze
#

... side-note, don't know if it's related, but i have a division by zero that i can't seem to get rid of?

if (sourcePlaneVecLength > 0.1) {
    float3 tmp1 = sourcePlaneVec / sourcePlaneVecLength; // division by 0
    // snip...
}
#

oh that's probably just optimizer turning conditional code into branchless code

#

.... nvm, still divides by 0 if i replace the conditional with making the length = min(length, 0.1). somehow.

meager pelican
#

Maybe some cosmological constant changed, and all denominators are now magically zero. Giant Meteor 2021 comes next....
Seriously, IDK.

Note that NaN's might slip through. But I don't see where NaN is applicable to either of the 2 questions. @grand jolt @alpine blaze

grand jolt
#

I myself don't know where I am dividing by 0 ;-;

meager pelican
#

Zero is a valid index/offset for sampling a gradient anyway! The others are a uv output and a split and a gradient source. So it could be on their side. IDK. Where does the error message appear? At run time? In the graph? On the console?

grand jolt
#

It appears in inspector in the shader object

#

With yellow warning triangle ( not red one)

grand jolt
meager pelican
#

lol. IDK man. That's the output of the shader compiler showing up as an warning/error in the inspector.
I'd make sure packages are up to date an in sync, but other than that....

Maybe try another simple shader where you just output a color from the blackboard. No gradients and whatnot. See if the error is still there. If it is, it's probably in their compile/libs and not your specific graph.

grand jolt
#

I didn't use any split or UV or geadient node in it

meager pelican
#

IDK

grand jolt
#

Btw unity is asking me to update ( I didn't update yet)

#

But I don't think 2020 verison will have any problem

grand jolt
meager pelican
#

Just check package manager even for your current version. Other than that, yeah, upgrade MIGHT change it. I haven't seen this.

grand jolt
#

Ok Imma try that

grand jolt
meager pelican
#

@lean lotusAll you can do is test. This is similar to a DOTS thing, but on GPU. lol
I was wondering the same thing today. Was ray-tracing and I added in normals to the data structure. Was wondering if I should have a separate buffer for them, similar to verts, or make a vertexData struc that had both vertex and normal in it.
I went with the latter option. Figuring that when I wanted the vert data, I also wanted the normal-data, and thus I'd have been local cache consistency with having them together since I was reading through sequentially.

alpine blaze
grand jolt
#

So it's probably just a bug?

meager pelican
#

¯_(ツ)_/¯

You guys should check unity answers or whatever, bugzilla thing.

alpine blaze
#

idk. updating unity (2018.4.20f1) is not an option for me since it's content creation for an existing game (vrchat). i don't actually care about the division by 0 itself (the shader is more or less behaving itself), just thought maybe it could have something to do with the weirdness i'm seeing with the parameter stuff.

grand jolt
#

Oh

meager pelican
#

@alpine blazeOne thing to check is your graphics drivers...updating if you can. The GPU-side shader compiler might have a fix in it. Long shot.

#

Otherwise break that expression up and see if you can side-step any optimizer problem if that's it.
I'm at a loss.

alpine blaze
#
float3 sourcePlaneVec = cross(cross(sourceNormal.xyz, -h.xyz), sourceNormal.xyz);
float sourcePlaneVecLength = min(length(sourcePlaneVec), 1.0);

if (length(sourcePlaneVec) != 0) {
    float3 tmp1 = sourcePlaneVec.xyz / sourcePlaneVecLength; // division by 0
    float3 tmp2 = tmp1 * _SourceRadius; // this multiplication seems to either be a fixed 0.1 or 0, regardless of actual _SourceRadius value.
    Out.sourcePos.xyz = Out.sourcePos.xyz + tmp2;
}

right i forgot to post my changes based on trying to dodge the divide by 0 to see if that would fix it.

grand jolt
alpine blaze
#

still has the divide by zero warning, the parameter still doesn't behave.

grand jolt
#

Hmm

#

Welp ;-;

alpine blaze
#

Shader warning in '<snip>': floating point division by zero at line 189 (on d3d11)

meager pelican
#

Try
sqrt(dot(v,v))
instead of length()

alpine blaze
#

no change

meager pelican
#

Same line number?

alpine blaze
#

yes.

meager pelican
#

lol

#

Laughing WITH you

#

Not at

alpine blaze
#

yeah, i know. i'm just laughing at how much i hate shaders rn. >_>

grand jolt
#

I checked google and read somewhere to update shaders or might be a GPU issue

#

And my GPU is really old

meager pelican
#

Yeah. Drivers and/or whatever on the hardware side could do it.

alpine blaze
#

thing is that google will have some site that always says something like that regardless of the issue.

meager pelican
#

yeah

alpine blaze
#

so forgive me if i don't put much stock in that

grand jolt
meager pelican
#

After a while GPU makers just quit supporting them.

grand jolt
#

Hmm

meager pelican
#

I saw an ad today for helping upgrade Windows7...
lol. I mean.... oy

grand jolt
#

Lol I also have windows 7

#

My pc is really old lmao

meager pelican
#

IDK what to tell you. That sucks man. Feeling for you. But there's so many layers of old stuff....that you cannot upgrade.

#

without changing Win7

grand jolt
#

Hmm ;-; welp

alpine blaze
#

side-note, changing the parameter into a static const float fixes my issue with the parameter, but maybe that's because the compiler is just inlining the const then. (also, well, it's no longer a parameter, so not a real fix)

grand jolt
#

Oh ok

alpine blaze
#

(that's separate from the divide by zero, which i'm suspecting is just unrelated)

meager pelican
alpine blaze
#

still works with a static float, probably same thing.

grand jolt
#

I like how divide by 0 is the meaning of my name

#

"NotDefined"

meager pelican
#

Make sure you don't have a typo such that the variable name is different and uninitialized. But if that were true you'd either get a 'variable undefined' error or you'd have to have two of them in there.

meager pelican
grand jolt
#

XD

alpine blaze
#

so, fun thing, i don't get any warnings (and the same behaviour, except i don't have a user visible property) if i comment out the property definition and leave the hlsl declaration.

#

ctrl-f with match case on tells me that the 3 instances i brought up and posted when i first talked about it here are the only instances, and that they do seem to match.

#

dafaq. hold on, give me a sec.

grand jolt
#

??

alpine blaze
#

That's a hisenbug if i've ever seen one.

#

so I decided to try and debug by muliplying the color output by my shader parameter

grand jolt
#

Oh

alpine blaze
#

and not only does darken/lighten the color, it starts working properly.

meager pelican
#

lololololol

#

Maybe an optimizer bug? Now it has two references to it.

#

So it deals with it differently

#

IDK

alpine blaze
#

i. ugh.

#

maybe it doesn't like that the only reference is in the constant hull shader or something.

#

so when i added a reference in the fragment shader it went "oh! i can deal with this!"

meager pelican
#

It's in a HULL SHADER?

#

Huh. Good to know. Yeah.

alpine blaze
#

the constant hull shader, yes, since i'm using tessellation. nevermind that i could just replace the tessellation with a mesh with equivilant geometry, since it's literally just acting as a detail slider for the shader, and no input geometry is actually used.

#

this is a weird shader

#

but i also kinda highly doubt that's the actual issue?

#

nope, that can't be the case, since my _Iterations parameter (determining the number of iterations of newton's method to run) is also only used on the constant hull shader.

meager pelican
#

I've had a weird thing before where Unity's shader compiler (the one that outputs the IL code for the target hardware to finish compiling) would skip a variable because it thought it wasn't used. That variable was in a conditional compilation stage that had some weird configuration. Turns out you can check for some kind of analysis step too in the if().
But that doesn't sound like your case (that you have conditional compilation).

alpine blaze
#

not anywhere in the constant hull shader, no.

meager pelican
#

Yeah, but it kind of sounds like what you did. Because when you referenced it in the frag, it "sees" it.

alpine blaze
#

yeah

meager pelican
#

Lemme see if I can find the info. Sec.

grand jolt
#

So the issue got resolved?

meager pelican
#

You might be able to "trick" it by adding your color multiply thing, but only for the analysis stage.
like

      do your thing
#endif
#

IDK if you're doing a surface shader though.

#

Maybe there's a similar thing for vert/frag or whatever.

grand jolt
#

Damn shader codes look so much tougher than shader graphs

meager pelican
alpine blaze
#

that doesn't work.

#
#if defined(SHADER_TARGET_SURFACE_ANALYSIS)
return i.color * _SourceRadius;
#else
return i.color;
#endif

gets me back to the parameter not affecting anything

meager pelican
#

Is it a surface shader though?

#

Like I said that's only for surface shaders

alpine blaze
#

oh.

meager pelican
#

But maybe there's a similar thing for other types.

grand jolt
#

Btw I tried updating the packages and still the issue is there oof

#

So I should give up for now?

meager pelican
#

Cheat

alpine blaze
#

yeah btw none of this is talking about division by zero stuffs anymore

grand jolt
alpine blaze
#

this is referring to my other issue which is apparently completely unrelated

grand jolt
#

Oh

meager pelican
#

You have a solution that works. You don't care about it in the frag, but you need to reference it.
Do you have a vert() shader

#

@alpine blazeit MIGHT be related.

#

Anyway cheat.

alpine blaze
#

i do have a vertex shader, it does nearly nothing

meager pelican
#

In the frag, or in the vert, reference that variable.. Try vert first, since it has a lower invocation count. Then try frag.
But you can just set it to zero then do an add with it or something. Or increment it. Something that looks low cost and harmless.

alpine blaze
#

setting it to some constant means that it then just turns into using that constant and it stops working.

#

i'll figure something out.

meager pelican
#

If it is an optimizer thing you have to USE it on something that sticks.

#

If you just set it to foo, then never pass it out anywhere or use it anywhere, it gets optimized out as a useless variable.

#

That's what I'm thinking happened. But when you used it in the frag and actually multiplied the color by it,

#

it was seen as a "really used" variable.

alpine blaze
#

i was referencing the set it to 0 part of it -- i did the multiply trick but set it to 1 beforehand.

#

yeah that's what i figured

#

bot doesn't like that i guess, huh

meager pelican
#

What's your v2f look like? Maybe you can pad something out to a float4 from a float3, and then stuff the <variableName>.x component into the thing.w.

alpine blaze
#

i think i can figure it out from here, i was trying to post one of the things i did that worked but bot kept deleting the message.

#

it boils down to 1 + _SourceRadius * <small number>

#

i can't post said small number because bot keeps deleting it

grand jolt
#

How to fix this when trying to import a shader graph?

#

?

grand jolt
#

@meager pelican sorry to ping u again.. I think this error is happening for every sample gradient node assigned to Base Color.. can you check just to confirm my suspicion XD?

cosmic prairie
# brittle owl aagh this is annoying how do i fix this z fighting? (is this z fighting?)

if it was not answered yet, that is caused by the sorting of 2 transparent things, if you have them at maximum alpha, they are still considered transparent, and they will get sorted by the distance to the camera. you could try to have them as opaque cutout objects, if the floor is not visible through the goo. if they need to be transparent, try to play with blending modes, and ztesting maybe that would solve it

#

or render them yourself and you have control over the order I guess

tame meadow
#

Hi, I need your help again with a graphic problem. A transparent model, made by a graphist, render like this :

#

as you can see, a face of the pillar is hidden by the face behind

#

i don't understand if it comes from the model or the shader (standard specular setup)

#

this should look like this (but with transparency)

#

i'm lost since 2 days, so thanks for the help if someone has an idea

#

a last image with standard shader (transparent), this is Unity 2021.1.7

#

the tower should be in front, but it's hidden, don't know why

cursive surge
#

Might be the wrong channel, but how would I go about getting the depth buffer of a camera as a texture?

dense violet
#

Hello! Im new to shaders and Im trying to find a shader which is a gradient with transparency. I found one that works but it does not handle textures. Is there a shader where one can create a transparent gradient for textures? The purpose is fade in a tower in AR to smooth over the occlusion edges

thick fulcrum
# tame meadow a last image with standard shader (transparent), this is Unity 2021.1.7

this is typical z-fighting, there are a few options each with their own issues. I usually suggest transparent dithering which is an opaque cutout shader with dithered alpha giving you the benefit of proper depth sorting. Here is a good explanation of the technique and why it is used https://danielilett.com/2020-04-19-tut5-5-urp-dither-transparency/

Daniel Ilett: Games | Shaders | Tutorials

Drawing objects with dithering patterns

tame meadow
#

Thank you, i'm reading it !

meager pelican
#

The most common way to deal with actual z-fighting is an offset, from what I've seen.

#

@cursive surgeYou can make such a gradient in the unity editor. Use their editor tool to define a gradient. Then, you'll have to write a script to create a texture from it. Say a 1x1024 texture. Sample the gradient along intervals 0 to 1023 and use setpixel to set the value in the texture. Make sure the texture format supports alpha.

Then just pass it to a shader (sharedMaterial.setTexture) or whatever you want to do.

In the shader you can do whatever you're wanting to do. Like multiply by the gradient alpha. Whether you want a full color or just an alpha value, IDK, I'm not sure what you're doing.

#

@grand joltI'll check in a bit, but we might be on different versions.

grand jolt
#

how to scale the final texture?

meager pelican
#

@grand joltI hate deciphering graphs.
Have you tried the tiling and offset node to scale the UV's?

grand jolt
#

yeah

meager pelican
#

@grand joltRefresh my memory, was it lit or unlit? (what type of graph)

pseudo pilot
#

I wanted to make an area light, but it doesnt work. The whole area is set to static. I tried it to bake it manually too, but still doesnt work. Even with itensity and range up to 5k

#

I also tried to set the light to static

grand jolt
#

Btw it's working in neither xD

meager pelican
#

Second, going back to look at your pick. We all talk too much 😉 :p

grand jolt
#

Np xD

meager pelican
#

Creating Graph, please stand by. One moment please. Your regular programming will resume shortly.

grand jolt
#

Lol btw I think I deleted the shader graph earlier..shall I resend it?

grand jolt
meager pelican
#

It's a simple graph. I've recreated it, just trying it now

grand jolt
#

Okay

#

I hope it works for u so atleast I will know there is a solution

meager pelican
#

I didn't see an error. Where do you see it? Console?

grand jolt
#

No no

#

Click the shader and see the inspector tab

#

Does the graph look similar to this?

meager pelican
grand jolt
#

Yep works for me as well but the error still shows in inspector tab

grand jolt
meager pelican
grand jolt
#

Yep I am doing the same thing with red gradient

cursive surge
meager pelican
#

No error in inspector for graph, for material, and no error on console

grand jolt
#

Oh But my package is also updated and the unity version as well hmm

#

And we did the same thing

meager pelican
#

@dense violetSee above.
@cursive surgeSorry. My bad.

grand jolt
#

Thanks a lot for testing out the graph

#

Really appreciate it :D

cursive surge
#

(No worries)

grand jolt
#

So the issue might be in gpu? Or windows related?

#

I have no other clue lol

meager pelican
#

Or unity software versions. Or or or.
I hate this type of thing.

#

Maybe make a clean project, new, and just do one graph+material. Separate directory. Maybe your install is f-ed up.

#

Or maybe your project.

#

Or like you say, OS, or drivers.

#

Oy

grand jolt
#

;-;

#

Welp badluck ig

#

Btw what's ur current unity version? Cuz I don't think unlit master node is there in 2020.3.9f1

meager pelican
#

That's from an older test rig/sandbox.
That one was 2019.4.23.f1

but I have others installed too, but they aren't URP right now, and I didn't want to wait forever for a new project to be created (slow for some reason)

grand jolt
#

Hmm

#

Well since the gradient works..shall I go with it and don't worry about the error?

#

Or use a different approach like gradient inside an image used as texture?

meager pelican
#

IDK man, I worry about everything. I'm a worrier!

grand jolt
#

XD

#

I am gonna install an older version like urs to check if the error shows in it .. Imma tell u the results xD

meager pelican
#

I'd use another approach. Including math. If you just want a red gradient, that's just he amount of red. Maybe invert the y. Stuff it into color.r.

#

By invert I mean 1-y

grand jolt
#

Ohh

meager pelican
#

In your case looks like you're doing alpha too on the gradient. So you'll want to figure out the values at different points and then figure out what math to do to get what you want.
The SG docs have a calc for gradient, IIRC. You can do it with math.

#

It's basically a lerp anyway, but maybe skewed t

#

Or sampled values lerpted in a loop

grand jolt
#

Hmm Imma check the docs soon

meager pelican
#

The cool thing about doing it in a texture from the editor is that you can use their gradient tool in the editor. Then just stuff it into a texture, and let GPUs do what GPUs do, and sample it at "t". So you pass in the texture and t.
Then the sampler takes care of the rest, smearing the colors in-between to any t. That's what GPUs do for a living anyway. 😉

grand jolt
#

XD

meager pelican
#

The drawback is that you have to write a script and make another texture, and you might just be able to do it all with math (which is faster usually).

grand jolt
#

I like how there can be so many different approaches

#

But that was the simplest one ;-;

meager pelican
#

I was AFK.
Second, have to restart unity. Have an idea.

grand jolt
meager pelican
#

Prolly not. :p
This is what I get:

grand jolt
#

Oooof

#

Now this error is even worse than before. Because before I thought it's from shader but now I don't even know from where it's coming ughh

grand jolt
#

U specially turned on unity for me 😭

meager pelican
#

OH!!!!!

I GOT IT TO SHOW UP!

#

I clicked on "compile and show code" button. THEN it showed up.

#

If I go back into shader graph, save the file again, it is fine.

#

So it might be a spurious error from the "compile and show code" thing in the editor.

#

@grand jolt

grand jolt
#

So the error showed on clicking the button?

#

how to fix my shader? looks correctly on 1, distorted on 2, and completly broken on 3

meager pelican
# grand jolt I am confused

Yeah, I guess. It starts off clean, like in the pic I posted above.
Then I click "compile and show code", and I got the error somehow.

#

Then went back into SG and saved again, and the error went away.

#

It was weird

grand jolt
#

But for me even after I save asset

#

Error is still there

#

:c

meager pelican
#

But maybe it is just shader variant. Are you writing for DX11 or for Open GL or what?

#

What is your target?

#

Like if you do a build.

grand jolt
#

I- didn't make any plans for that ...

meager pelican
#

OK

#

So defaults

grand jolt
#

Also what's the default

meager pelican
#

Variants are activated with different keywords. Like has shadows or not. Things like that. So you end up with multiple shaders output with different options active. Allows for smaller shaders. Then on build, unused variants get stripped.

grand jolt
#

Ohh

meager pelican
#

Default my vary depending on platform you're working on. IDK. Seems like I always end up with DX11 and Windows. But I really haven't worked in other environments with the editor (such as Linux or apple's stuff).

grand jolt
#

So u said error showed up for u as well

#

But now it disappeared

#

U know the reason behind it? ;-;

meager pelican
#

Compiling Fragment program
Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR

The full error that showed up was this. See all those active keywords?

#

IDK. But might be spurious.

#

I cannot tell.

grand jolt
#

Like error was false?

meager pelican
#

More like not applicable for the variants you really want. But IDK for sure, not 100% sure how to tell in this case and I'm having a hard time reproducing it again.

#

OTOH, you get it all the time.

grand jolt
#

OTOH means xD?

meager pelican
#

Sorry. On The Other Hand.

grand jolt
#

Aye don't say sorry

meager pelican
#

😉

grand jolt
#

My direct x version is 11

#

So I don't think any issue there

meager pelican
#

Maybe make a bug report and let the experts deal with it, eh?
I mean, you can make a project, isolate it, and reproduce it.
But give them your hardware info and versions in the report....windows ver, graphics card, driver versions....
See if they can tell you anything.
Worst thing would be you getting a "not reproducible" answer back, or an "upgrade it to fix it" thing.

grand jolt
#

Hmm I think that's the last resort

meager pelican
grand jolt
#

Okey dokey

meager pelican
#

@grand joltOne thing that might be worth checking is:

#

that you have it set for the current graphics device.

grand jolt
#

For me it's 459

meager pelican
#

I'd ask unity, send them a repro (small mini project that reproduces it on your system) and system specs. Other than that, I'm not sure but we're going to fill up discord here and not get any further.

#

Try to check the database first to see if there's a report already there.

ionic zealot
#

I really need help using this asset with animations and stuff

#

gun mechanics

#

ammo

meager pelican
#

Animations ^^

lean lotus
#

why does compacting a structured buffer to 1/3 the length but having each element now have 3 ints instead of 1 half my performance of a compute shader?

#

was trying to compact a list of mesh indices

meager pelican
#

What does that mean?
"compact"?

#

You mean split up?

#

Reduce number of elements?

meager pelican
#

The other thing with GPUs, IIUC, is that they love things that are aligned on float4 boundaries. That works for int4 too. 32 bit int or 32 bit float. So 128 bit boundaries.
It's not uncommon to "pack" structures into various4 variables, and also to pad things out to float4 boundaries. But don't go nuts.

#

And if you spit the one buffer into 3 buffers, you end up with memory cache locality issues since you have to jump around and read from separate buffer memory areas to get your data assembled.

#

@lean lotus

lean lotus
#

I had a long structured buffer of single ints
I turned that structured buffer to use a struct of 3 ints(plus. a fourth for material info)
that lowered the length of it by a factor of 3
but now my performance is half

#

this structured buffer is very frequently accessed

meager pelican
#

Are you updating it? (RWStructuredBuffer) or just reading it (StructuredBuffer)?
If the first/former, I'd guess you're "locking" greater strides. That may or may not be a problem depending on what you're doing. If each thread has its own area to update, might not be bad.

The other thing you can check is your wavefront. You'll need analysis tools for that from your GPU vendor. Like Nvidia or AMD. They have tools that can tell you how many cores are running at once in the kernel dispatch. There's limits to threads dispatched based on things like available vector registers, and that's all relative to the code that gets generated. So maybe the code needed to access those changes is larger, and results in fewer cores dispatched.

This is all off the top of my head an a bit of guess work. But there's no easy way for us to answer your questions with such a simple description. You're going to have to dig in using your system and the right tools, IMHO.

lean lotus
#

just reading it

#

and im on mac rn

meager pelican
#

Well, then there's Macs....lol
So IDK. What do you mean "right now"?
You're comparing apples to apples,, of course. Right? So changes on same system are twice as slow.

lean lotus
#

yes

meager pelican
#

IDK why just having a structure would slow it all that much, but who knows?
What were you doing before, just offsets?

#

Like buff[index] and buff[index+1]?

lean lotus
#

its an indice list for raytracing, so its read many times, but thats all im doin

#

yis

#

thats how it is now

#

if I compact it, that means I just read index buffer 3 times, but with a different element each time(indice 1, indice 2, indice 3)

#

but by doing that I go from 50 fps to 20

meager pelican
#

But each was an int before. And now it is a struct?

lean lotus
#

yes

#

before it was just ints, now its a struct of 3 ints

meager pelican
#

I thought you said 4

#

But OK.

lean lotus
#

yes 4 but thats unneeded rn(its material information for each triangle, which is why im doing this at all)

meager pelican
#

Show me the struct/buffer definition

#

I just did this with three-eyed game's tutorial on ray tracing. But the impact was the scene objects, not the buffers.

lean lotus
#

after:

#

before: its just StructuredBuffer<int> _Indices

meager pelican
#

IDK. That's interesting to find out. Wish I had an answer other than the guesses so far.

lean lotus
#

mhm

#

its really annoying

#

but I may have to bite the bullet and just take the drastically lower framerate
unless I wanna send in yet ANOTHER structured buffer(im up to like 5 or 6 rn)

#

its all so I can have triangle specific materials

low lichen
#

What about making it an StructuredBuffer<int4> in the shader, but keep the struct on the C# side? It should translate the bits properly.

meager pelican
#

Yeah, good idea MS

lean lotus
#

int4... I can do that?

low lichen
#

Yeah, any scalar type HLSL supports can be made a vector that way

meager pelican
#

yes, GPUs live for that

lean lotus
#

huh ok
but i still just define it as a struct on the C# side?

low lichen
#

Yeah, you shouldn't need to make any changes on the C# side

lean lotus
#

ok lemme try it

meager pelican
#

The tut I followed just did buffer of [int] and then accessed with [index], [index +1], [index+2] and they calced the index value from the triangle's offset and the mesh object offset. But reading them all might work. Since they're index values into the actual vert buffer.

lean lotus
#

mhm ik
i started with the tutorial form threeeyedgames but its results were much too slow for complex scenes
so here I am now

meager pelican
#

Yeah, that's the one I just did (again). He just did ints.
But it isn't optimized for access. That was going to be his part4 or 5, but not written (yet?).
There are various methods of having "acceleration structures" that allow you to not have to read everything in the scene for every pixel.

lean lotus
#

mhm I have accelleration structures
that 50 fps was for a 143k triangle mesh on mac with primary ray only

#

hmmm still going from about 40 fps to 25-30 fps with this, ugh structured buffers are so confusing/mysterious in their performance to me

low lichen
#

You said this buffer is accessed very frequently. Do you mean it's accessed in many different shaders or it's accessed multiple times in one shader?

lean lotus
#

many times in one shader

meager pelican
#

Usually many times per pixel (many rays for each pixel) and x width x height

#

But if he has acceleration structures, he can reduce the total # of accesses.

lean lotus
#

mhm

#

its the indice buffer for the meshes

meager pelican
#

Right......

#

But see what Trace() calls, and then it will call IntersectMesh for each mesh you have. And that romps through the triangle forest and does an intersectTriangle test.

#

At least for those that pass your acceleration structure test.

#

And he scatters several rays per pixel and accumulates them from a hemisphere pattern

lean lotus
#

trace calls the top level BVH
the top level BVH then transfers to the many bottom level BVH's
then the bottom level BVH's access the triangle index list, the triangle verticies, and the textures

#

ok uhhhhhh i just decided to add ANOTHER structured buffer of ints that stores the triangle material for every triangle
and performance is now improved because I replaced a bunch of things that stored material index with searches into this new structured buffer

meager pelican
#

OK, so accelerated. But still, major romping. Each pixel has many rays accumulated over several frames and added in.

lean lotus
#

how the hell do structured buffers work for performance... this is so confusing...

#

but ive gone from 40 fps to 50-60

#

by now having it look at a much longer list, but each element only contains a single int, vs having it look at a really short list but each list entry has like 5 or 6 different data values in it

meager pelican
#

It all depends on what you were doing.

lean lotus
#

it seems that eliminating any extra data stored together seems to speed it up? idk compute shaders and structured buffers are such a mystery to me in terms of performance

meager pelican
#

If you accessed the 3 ints, then you read the 4th material, and then you went and looked at a material buffer, then tried to go back to the index buffer to get the next triangle, you were jumping around in memory. So when you do that you invalidate the memory cache, and get more "misses". Guessing.

lean lotus
#

idk anymore

#

we need like a comprehensive review and look at the performance effects of different ways and constructions of structured buffers

#

my only guess is that when I have 4 ints in one entry of a structured buffer, every time I need to access one element of an entry of it, it needs to load the other 3 entries? idk

meager pelican
#

Then there's added that 4th byte increased the data throughput needs by 25%
Sure, that makes sense if you have it defined that way.

#

Like with int4 or with a struct.

#

But the idea is that you need all of them anyway, so you know you're going to access it like that anyway.

lean lotus
#

yeah

meager pelican
#

143K triangle mesh? once you go beyond your 1 ray, kiss it all goodbye anyway. I hope the BVH helps you a lot.
What BVH implementation did you use?

lean lotus
#

it do help a lot
I started with octree, moved to bottom up BVH, now im on the Top Down one by MadMann, they have helped a LOT

meager pelican
#

I added materials and normals.
But mats sure weren't per-triangle. 😉

#

Then again, normals are. Was a separate buffer.

#

With barycentrics on the normals (optional flat).

lean lotus
#

mhm
Im working on getting textures to play nice if I decide I want to make a single BVH from more than 1 mesh or submesh
Cant think of how I want to have this structured or defined for grouping

meager pelican
#

Well, now you need at least a float2 on each triangle vert for UVs. So you may run into the same things again.
And then there's a texture atlas array that has to be all in memory at once.

#

lol

#

Starts to make your head spin.

odd dagger
#

Still need an answer to this issue

lean lotus
#

I have that already
and the texture atlas is done

#

textures work fine rn
but I wanna group together things that heavily overlap

odd dagger
#

I imagine what's going on is transparency is not being taken into account for the sprite. I can share the code for the shader if need be

meager pelican
#

First check the import settings on the texture and make sure it is importing alpha. Then you can show the shader code.
What pipeline?
Do you care about mobile or not?

odd dagger
#

Is this what you needed for the first question?

meager pelican
#

Yep. You sure it's got an alpha channel in the graphics editing tool? (the texture has 0's where it should be empty)?

#

That looks good, you're importing alpha.

#

What graphics pipeline? URP, standard, ?

odd dagger
#

Shader code

#

It's pretty much the image effect shader with a couple minor changes

#

Pipeline is URP

meager pelican
#

And you want to clip 0 alpha?

#

You're not even doing anything with alpha right now.

odd dagger
#

Yeah I'm not sure how to make it accept alpha, I haven't tried anything yet but I looked into it and didn't find anything I really understood

meager pelican
#

What you have right now is

               fixed4 col = tex2D(_MainTex, i.uv);
                // just invert the colors
                col.rgb = col.rgb;
                return col;```

and what you probably want is 
```CS
               fixed4 col = tex2D(_MainTex, i.uv);
                // just invert the colors
                col.rgb *= _Color.rgb;
                clip(col.a - .001); // maybe want that, maybe don't.  That's alpha clipping.
                return col;```

And you may want "Blend SrcAlpha OneMinusSrcAlpha" at the top instead of "Blend One One".  But I don't do these sprites much, so that's off top of head.
odd dagger
#

Well I wanted to use shaders to allow objects to be additively or subtractively blended

#

The old sprite used to look like this but adding a material that uses this shader makes it look like the other image I posted

meager pelican
#

One One is additive blending. If that's what you want.

odd dagger
#

Yeah

#

What is it for subtractive btw?

meager pelican
#

You can set the blendop to subtract (sub). By default is is add.

odd dagger
#

I see

elfin prawn
odd dagger
#

Btw I tried the code you suggested and it said that '_Color' is an undeclared identifier

elfin prawn
#

It seems on your code the _Color property doesn't exist, you can either add it or use the _MainTex color

odd dagger
#

Now it gives this

meager pelican
#

IDK what line that was, but try clip(col.a - .001);

odd dagger
#

Oh no it was the line above

#

"col.rgb *= _MainTex.rgb;"

meager pelican
#

And like Alan just said, make sure you define _Color if you want to tint. Sorry about that.

#

You had "color.rgb = color.rgb" which doesn't do anything. I assumed you were trying to do something with it.

#

Otherwise you don't need that line at all.

#

And fix the clip because I edited

odd dagger
#

Uhh what are you actually supposed to put in the parameters for _Color? 😅

meager pelican
#

That's fine, you set that in the unity inspector anyway.

odd dagger
#

I can't seem to find anywhere that explains these individual tags and properties and stuff anywhere

#

..it still says undeclared identifier

meager pelican
#

But you need to also define _Color as a float4 in the code.
float4 _Color;

odd dagger
#

Ohhh