#archived-shaders

1 messages · Page 33 of 1

strange basalt
#

though what does it look like when you are doing alpha 0

#

could be your blend mode expects pre multiplied alpha

smoky flume
#

i haven't set the shaderlab blend yet

strange basalt
#

should have a Blend line somewhere in it

#

Blend One OneMinusSrcAlpha would expect color to be pre multiplied by alpha

#

Blend SrcAlpha OneMinusSrcAlpha would work without doing that

steep hill
#

Same thing

smoky flume
#

Blend SrcAlpha OneMinusSrcAlpha did the trick, thank you

strange basalt
#

other thing that would work is using Blend One OneMinusSrcAlpha
but in your shader do color.rgb *= color.a

#

would just see which one looks best for your case

smoky flume
#

ok i'll try it out

narrow pendant
#

Does anyone know why the transparent part of one of the textures in an asset im using?

dense flare
dense flare
#

for the water edge

grizzled bolt
dense flare
#

im using screen space instead of a generated mesh

grizzled bolt
#

Or lerp the surface's alpha based on the resulting gradient instead of drawing a new one

#

Neither of the examples appear to actually use a blur

grizzled bolt
dense flare
grizzled bolt
#

Yes

#

As I understand the generated mesh is pretty important because otherwise there isn't really anything to draw the blurred edge on below where the water surface clips out
But there are different ways to get to the same result I'm sure

dense flare
dense flare
grizzled bolt
dense flare
# grizzled bolt Shaders are pretty similar across engines so an example may help

This is the first of 3 Videos about creating a Waterline in Unreal engine 4.
In this video you will learn how to setup a BASIC waterline with under water split Post Process material.

Download of Project and Files:
https://bit.ly/waterline_mm
Material Post Process blur:
http://bit.ly/wl_pp_blur
Link to all of my shared content:
https://bit.ly/m...

▶ Play video
vague wolf
#

Hi, can someone be kind enough to explain the reasoning why the "Line" function of this Compute Shader calculates if the pixel is between two coordinates in order to color a line? I know what dot, saturate, vector subtraction means, but I'm having a hard time grasping the general logic. Thank you.

float Line( float2 p, float2 a, float2 b )
{
    float2 pa = p-a, ba = b-a;
    float h = saturate( dot(pa,ba)/dot(ba,ba) );
    float2 d = pa - ba * h;
    return dot(d,d);
}

[numthreads(8,8,1)]
void CSMain (uint2 id : SV_DispatchThreadID)
{
    float2 uv = float2 ((float)id.x/1024, (float)id.y/1024);
    float k = Line(uv,float2(0.3,0.1),float2(0.8,0.5));  
    float thickness = 0.00001;
    surface[id.xy] = lerp( float4(1,1,1,1), float4(0,0,0,1), smoothstep(0.0, thickness, k) );
}```
tacit parcel
#

is shadergraph's world to view transform works the same as camera.WorldToViewport?
I'm trying to convert a position inside a shader to viewport point but the result is slightly different, like, in shader, I need to multiply it by certain magic number (0.1) in my case

cosmic prairie
#

looks like it is the Segment - exact sdf equation

#

the return value is a bit different, but same thing overall

#

it basically returns the distance to the line at any given point

#

as to how you come up with an equation like that

#

Maths

#

(go to articles > 2D distance functions) the link wasn't copied properly

vague wolf
uneven frost
#

what sort of noise/node setup should i use to get squares or polygonal shapes?

grizzled bolt
uneven frost
regal stag
regal stag
meager pelican
#

The stencil operation can be tested before calling the fragment shader whereas the discard operation is done within the fragment shader. So it is more efficient to not even call the fragment stage for pixels that fail the stencil test.

This applies to depth buffer tests too. Pixels that fail the so-called "early z test" never even have to have their fragment shaders called.

This is why stencil operations and depth testing operations are set "at the pass level" and not coded into fragment shaders...because the fragment stage may never be called.

sand ginkgo
#

ShaderGraph 2D shaders/URP sprite shaders won't work properly with the depth of field.
From what I gathered, it is because sprite shaders do not write into the ZBuffer. Tried to generate and copy the shader and changed the ZWrite on, but it led nowhere. Any ideas what else could be hindering this?

#

Also I would prefer to not have to generate the shader and fix the ZWrite every time I make a change in the graph. Is there another way for shadergraph users to set these flags?

#

I think I just managed to solve the issue by using a standard lit graph. Probably a hacky solution I guess? If someone could shed some light on a proper way to handle sprite renderers, It would be much appreciated

dense flare
#

or whats wrong?

sand ginkgo
#

the depth of field post process was blurring the sprite renderer, eve though it was in the correct focal distance

#

as you can see on the first screenshot

#

So far it seems I solved that problem, just interested in feedback if my approach is somewhere near correct for the use case

dense flare
#

and its a simple fix

sand ginkgo
#

Just hoping there wont be a problem down the line ☺️

karmic hatch
dense flare
dense flare
karmic hatch
dense flare
# karmic hatch you could put a linerenderer there if you know the positions of the mesh vertice...

or do you know how to move this shader to unity?

https://www.youtube.com/watch?v=rnUEdKPPuhI&t=328s 4:05

This is the first of 3 Videos about creating a Waterline in Unreal engine 4.
In this video you will learn how to setup a BASIC waterline with under water split Post Process material.

Download of Project and Files:
https://bit.ly/waterline_mm
Material Post Process blur:
http://bit.ly/wl_pp_blur
Link to all of my shared content:
https://bit.ly/m...

▶ Play video
frosty linden
#

Hi all, I'm having an issue with my character how wears two layers of semi transparent cloth, like a semi transparent bra and a semi transparent top. Sometimes, depending on camera angle, the bra will be display above the top??? How to fix this issue?

dense flare
frosty linden
#

Meaning, the higher queue should be on the material closer to camera?

frosty linden
#

Got it.

#

I'll give it a shot, thanks a lot!

dense flare
dense flare
frosty linden
#

Yep

dense flare
frosty linden
#

An adult simulation 😅 Not sure I can talk about it here lol

frosty linden
#

😉

dense flare
# frosty linden 😉

Is it like life as an adult or explicit sht cus if so then no talk im not dealing with that😂😂

frosty linden
#

loooool second one 😉

#

🤣

dense flare
dense flare
frosty linden
#

Not at all. There are lots of "adult" games using Unity around. Mine is named "Glassix 2" if you dare search on Google lol

frosty linden
#

Ahah, good night 😁

frosty linden
# dense flare I mean i guess top

And your solution fixed my issue btw. I'm changing renderqueue at runtime depending on the cloth type, so tops are 3002, bottoms are 3001 and underwear are 3000. That fixed issues between clothes but there's a weird behavior now with tops when parts of the back and front are visible at the same time. The front seems to render above the back. If you have any idea if that's fixable.

dense flare
#

Just make sure you keep that bra on at all times

frosty linden
# dense flare Why

Well, it is on by default. I'm not the one removing it, it's the player 🤣

dense flare
#

Why and wht possed you to make this

dense flare
#

But why

#

I still dont believe you btw

frosty linden
#

Money. I tried normal games, but didn't earn back enough to cover the time invested. I tried with an adult one and it covered. And now, that's a huge part of my income so I can hardly stop. But I do wish to switch back to normal game when my financial situation is better.

jade ginkgo
#

In my search to learn shaders I'm struggling to separate information that's outdated vs current. My coding mindset has had me exploring custom shaders, but everything I find on custom written shaders seems more out dated. Are Shader Graphs the new hotness and can do pretty much whatever a custom shader can do? I see that Shader Graph properties can be set dynamically in C# scripts, does that apply to the shader as a whole? Or does it apply to that mesh? (I want to build a shader that blends textures in certain ways, but then each mesh will control the blending and even what textures to use for blending)

frosty linden
#

One mesh can have multiple materials

#

And you can do what you said with shader graph indeed, blending stop with basic properties and have other options to change it based on the mesh

dense flare
grizzled bolt
frosty linden
jade ginkgo
#

Yeah, that's something I'm struggling to wrap my mind around. I'm working with BathRenderGroups and controling the draw calls, but want to make decisions about what gets rendered at ever spot (not pixel, mesh)

grizzled bolt
jade ginkgo
#

I know I've seen legacy custom shaders that do what I want. Blending two terrains where they meet. But dynamically support N number of terrains, just blending any two textures where they meet.

jade ginkgo
grizzled bolt
frosty linden
#

By the way, here is a screen of my weird transparency bug, if anybody would know why it behaves like that and how to fix it, that would help, thanks!

jade ginkgo
grizzled bolt
#

You can probably find more info if you search for how this problem is tackled when rendering transparent hair cards

#

HDRP may have some advanced transparency features, or maybe those are only work in progress

frosty linden
smoky flume
#

How would I go about determining if one shader code is more performant than another (inside the unity editor). The rendering debugger would be good, but im getting too much variance with one instance. Is the best way to just create 1000 instances to reduce measurement variance? (But then I have to worry about Unity batching things for me when I don't want it to optimize)

meager pelican
#

That's a pretty good way, actually. Just make sure to do apples to apples comparisons.
Put 1000 (or 500, or 100) spheres in some temp scene, and have the two materials ready. Assign one material to all of them, and play while watching the stats, and then switch the material to use the other shader. Assuming they have the same inputs. Or assign the other material if they have different inputs.

Don't move the camera, or do other stuff. Try to isolate it to drawing the exact same thing, stationary if at all possible.

#

You can of course check out the profiler, and the profiler api too, and frame debugger.

#

REALLY testing out this stuff requires vendor tools and shader debuggers/profilers.

#

I don't recall what renderDoc has for timing data, but worth a look.

smoky flume
#

I'm actually looking at RenderDoc right now. It has some timing data, but not sure how to use it just yet...

smoky flume
#

Well, this works similarly to Unity's frame debugger. clicking the clock icon reruns the frame and shows each step's duration. but again the variance is pretty wide so 😐

#

Though the tool does have a nice disassembly feature where you can see what the pixel/frag shader really does on the register level

muted pond
#

I'd like to turn off backface culling for one of the segments of a game object. I read that I have to go into "shader settings". I went into "Edit" of the "Standart" Shader. However there is not really anything I can toggle on/off. What am I misunderstanding?

meager pelican
#

If you really really want to dig in that deep.
You can record and play back for debugging too, so you can check the values of variables that way.

sick knot
#

Hi, I have followed a PolyToots tutorial to make a 'rug deform' effect.
This is great except for that the vertices aren't deforming faithfully enough to complex meshes.
Here is what I mean.

https://i.imgur.com/yKPcL7A.png
The FlowerPot mesh is on a layer called 'Deformers' which a RenderTexture camera is looking at.
Then a shadergraph says to deform the Rug mesh based on the RenderTexture output.

This is the shadergraph: https://i.imgur.com/ucwqtOm.png

As you can see, the rug is deforming based on the flowerpot's shape but not in an accurate enough way. Is there a way to make the deformation more accurate?
https://i.imgur.com/hRUOxOX.png

Edit: I experimented with a higher polymesh for plane, and white material for flowerpot, and results are 'improved' but still weird. Spiky and overly indented... https://i.imgur.com/Ba7WTt9.png

jade ginkgo
grizzled bolt
jade ginkgo
smoky vale
#

so uh quick question, i vaguely know what im doing wrong but im not sure if i completely understand it, but i want per-pixel lighting (which i am doing, a bit of the calculation is in the frag shader) but i am unable to do it in a way that makes it visually appealing on lower-vert-count meshes like this cube that the objects are resting on, which makes sense because im using vert normals which i presume are interpolated across the surface to achieve the effect, what should i be doing instead?

v2f vert(appdata IN)//40
{
    v2f OUT;
    OUT.vert = UnityObjectToClipPos(IN.vert);
    OUT.verttwo = IN.vert;
        OUT.worldcalc = normalize( _WorldSpaceLightPos0 - mul(unity_ObjectToWorld,IN.vert));
    OUT.uv = IN.uv;
    OUT.norm = UnityObjectToWorldNormal(IN.norm);
    return OUT;
}
fixed4 frag(v2f IN) : SV_Target
{
    fixed4 pixColor = tex2D(_Albedo, IN.uv);
        float lightFac;
        if (_WorldSpaceLightPos0.x+_WorldSpaceLightPos0.y+_WorldSpaceLightPos0.z > 0)
        {
            lightFac = dot(IN.norm, IN.worldcalc);
        }
        float3 litColor = pixColor * _Color * _LightColor0 * saturate(lightFac);
    return float4(litColor,1);
}
#

btw, verttwo is for calculations ill be doing later

#

mostly irrelevant to this stage of the shader (basic lighting), its for stylization after the lighting is finished

jade ginkgo
#

@grizzled bolt @frosty linden (don't worry, I won't keep dragging you along my journey, I just want to post a follow up). I realize what I wanted was the ability to pass UVs to my shader on a per mesh basis (which is really per vertice) which can be done by interacting with the Mesh in my script and then working with those provided values within the shader. The fact that the UVs are specified on the Mesh (really the vertices within that Mesh) is the part I was trying to figure out. One more dot connected on how to make this all work. (don't worry, I won't be abusing UVs for weird things, at least I hope not. They will essentially be coordinates within a Texture / Texture Atlas, if that's the right terminology, still researching).

swift loom
#

I am looking for some tips if anyone has any experience with using raytracing for rendering in Unity. Rn I am rendering using a compute shader but the performance is not ideal. I know there's something called a raytracing shader but I don't know if it really makes a difference if I try to use that instead or not, or if that's specifically geared towards lighting and such, or if there are other things I can do or disable in Unity to get some extra juice.

queen lance
meager pelican
# smoky vale so uh quick question, i vaguely know what im doing wrong but im not sure if i co...

I'm not sure what I'm looking at in the pics, but my off-the-cuff comments are:

  1. OK, I'm ignoring .verttwo for now.
  2. .worldcalc is the light direction vector (lightDir would be suggested as a name instead).
  3. I noticed that lightFac is unitialized and technically undefined if the if-condition fails.
  4. I don't understand why that if is there, but that's up to you...I see WHAT it does, but not why you want that to happen.
  5. The worldcalc/lightDir vector should be interpolated across the polygon for normal polygons (not using POM or other things that fake out the depth of the fragment) since polygons are "flat". Ditto for the surface normal, unless you're using normal maps. The capsule looks lit correctly to me for what you're doing.

So the only thing I don't understand is the if and why you're limiting calculating lighting only when the light has one world-space position component in the positive quadrant. But it either does or doesn't, so I don't see where that's a bug. It SHOULD be doing an NdotL per pixel like you want.

For debugging purposes, you can always output the surface normal, the light direction, and/or the lightIntensity (lightFac) as color results to see if anything looks amiss. You may want to remap them to a 0-1 range to see the results as a color. Otherwise I don't know what I'm missing or maybe don't know what I'm looking at.

smoky vale
#

also i was focusing more on the cube underneath the objects than the objects themselves

#

ill think about this some more in the morning

timber wharf
#

Hello. I have 2 material. The left one uses Quibli Stylize lit shader and the right one uses URP lit shader. I have a spotlight pointed to the wall, why I only have the light on the left wall?

regal stag
meager pelican
#

If I'm seeing/interpreting the pics correctly, and the bottom pic is a point light, the point light's NdotL looks correct, the entire top surface of the cube is illuminated. What you're not doing is attenuation of the light (yet).

meager pelican
swift loom
#

If I have two kernels in the same compute shader and I want to set a texture/buffer for use in both, do I actually have to do SetBuffer for each kernel? And won't that cause copied data on the GPU?

#

or is it just pointing to data

meager pelican
swift loom
#

Alright thanks 👍

meager pelican
# swift loom Alright thanks 👍

P.S. and the reason is that setbuffer sets the context PER KERNEL, that's why you have to pass the kernel index to it. Some kernels may use that buffer, others may not, in the same compute shader.

swift loom
#

yeah i just wanted a texture to pass from one kernel to another after writing to it in the shader but i kinda settled on just combining them to one kernel instead for now. seemed better

cosmic prairie
#

to have proper deformation you need to render depth

#

you could also try blurring the render texture afterwards, to get a more real cloth look

native arrow
#

are Unity Terrain Trees supported by URP? or deprecated?

vestal surge
#

This shader takes normals that are close to a camera and stretches them downward.
Does anyone know how to make the stretched normals transparent?

smoky vale
smoky vale
#

and should i write my own equation for attenuation? is there any way to get the pointlights range value?

swift loom
#

It wont let me use clip() in a compute shader, but I can't find any information about this not being allowed. I tried doing a pragma target as well but nothing. Is it just not available for compute shaders??

regal stag
swift loom
#

i see thanks

queen lance
karmic hatch
thorn tapir
#

Hey, I need to turn the output of a shader into a sprite

anyone know how to accomplish this?
I have my shader done, I have a material with the shader applied, so far so good....

but now I need to get whats on the material into the Sprite property of a SpriteRenderer, one way or another

#

I know how to turn a RenderTexture into a Texture2D which can then be used in Sprite.Create to create a sprite from it, but my output from the shader is a material, not a render texture

crude sun
#

Any way to fix the mipmaps not taking texture scale into account?

#

They are mipping way too early. Doesn't happen with default URP material

grizzled bolt
#

!collab

echo moatBOT
thorn tapir
meager pelican
#

https://forum.unity.com/threads/how-can-i-access-the-properties-of-point-lights-or-spot-lights-in-a-shader.529344/
It can't be simple, because life.
lol
But if I were you and just playing with lighting, I'd start by hard coding something simple, and then build on that.
I think if you can get the light info at all, it's in the .w component stored as 1/range. But see all the complexities in that post above.

wintry perch
#

hey guys i need some help setting up URP in my game

#

i've imported some assets for water, but those textures dont seem to import and the lightning doesnt seem like it's changed

#

can someone help me out in a voice chat maybe? because im not even sure where to start

warm crag
#

does anyone know how an Unlit shader's Base Color and Emissive Color interact in terms of the shader's Render Pass setting, being Default or After Post Process? After Post-Process seems to result in a final output color of Base Color + Emissive Color , but if the Render Pass setting is set to Default, it seems less clear. Like an emissive color of white with a base color of red gives a light peachy color

#

(just a general answer is fine. I'm teaching a class on tech art and we're covering shaders this week but I'm more used to Unreal Engine's situation, so i'd like to know what Unity is doing here so I can explain it to my students)

#

oh I'm using HDRP, that probably makes a difference here

tacit parcel
warm crag
vestal surge
#

I have another question. I'm trying to use an 'underwater' shader effect that forces vertices downwards if they're close enough to the camera, so as to create the illusion that there is water continuing underneath a water-material plane mesh instead of empty space.
However, I am also using a "waves displacement" node group, and I can't figure out how to get these two node groups working well together.

The effect of each group works fine individually when plugged in to the "Vertex-Position". But I need to find a way to get both effects to apply together into vertex-position.

I have tried Adding, Multiplying, and Lerping these two groups together but each way results in visual problems. Of course, I could have done these attempts incorrectly.
Is there any solution to making them work together or do I have to just do another approach?
Screenshot of node groups...
https://i.imgur.com/nwf6A2f.png

Also, I tried a setup like PositionNode(WorldSpace) -> Waves group -> Transform(ObjectToWorld) -> UW group -> VectorPosition(ObjectSpace) [where the input to UW replaces the UW group's PositionNode] but it resulted in the waves effect being pushed down with the underwater effect, if that makes sense.

thorn tapir
#

Hey I am having a problem of some shader-fu I'm doing not working in webGL

Sprite MaterialToSprite(AfterImageParams e)
    {
        RenderTexture _renderTex = new RenderTexture(e.playerAIRT.width, e.playerAIRT.height, 24);
        _renderTex.filterMode = FilterMode.Point;
        Material _shaderOutput = e.shaderOutput;
        Rect _rect = new Rect(0, 0, _renderTex.width, _renderTex.height);
        Graphics.Blit(null, _renderTex, _shaderOutput);
        Texture2D _texture2D = new Texture2D(_renderTex.width, _renderTex.height, TextureFormat.RGBA32, false);
        _texture2D.filterMode = FilterMode.Point;

        RenderTexture.active = _renderTex;
        _texture2D.ReadPixels(_rect, 0, 0);
        _texture2D.Apply();
        Sprite RT_Sprite = Sprite.Create(_texture2D, _rect, new Vector2(0.5f, 0.5f));
        return RT_Sprite;
    }```
#

I've been googling around a bit and it seems RenderTexture class may be the culprit here? I found some things saying that its not supported by webGL

#

what I'm doing here, in short, is turning the output of a shader into a sprite, through a multistep process

#

is there another way to get a sprite out of a shader ouput that doesn't involve RenderTexture??

or some other way to get this working on webGL?

meager pelican
# warm crag https://www.youtube.com/watch?v=sqE7JVW_NNw one other thing: can anyone explain ...

Well, it's hard to tell (at least for me) from that video, but I'm sure you know that pre-multiplied alpha differs from the "regular" in that the shader code won't be generated to multiply color.rgb * color.a since this operation is already "burned into" the colors (AKA the color values are pre-multiplied by the alpha already).
Therefore the blending result changes because the values are different each way.

candid bane
#

is there a way to display text using shadergraph? for example take a float input number and display it somewhere on the UV?

meager pelican
candid bane
#

thanks, I wanted to make a speedometer, and the only thing left to do was to display the numbers on the large segments

meager pelican
#

Ah.
Well, you have to generate that result somehow. Like TextMeshPro and having quads with text on them. Or doing that and saving the result to a render texture. Or the easy way is to just burn it all into the artwork, like into a texture.

dim yoke
candid bane
#

thank you @dim yoke , i'm sure i'll figure something out. until then, I have a very minimalist wristwatch lol

karmic hatch
#

(make sure the spaces are the same; e.g. if one spits out an object space position and the other wants a world space position, put a transform node to convert them)

dim yoke
# candid bane thank you <@689758471003963472> , i'm sure i'll figure something out. until then...

this is what I managed to do with a shader graph (one plane with shader in it), this ⬇️ texture atlas and C# script that sends the digits to the shader by using 5x1 Texture2D. It's certainly possible to do this in shader graph but I'd still probably use world space UI as it would be easier I think but If you are confortable enough with shaders, that could be solution too

candid bane
#

@dim yoke thank you, i'll be using this

dim yoke
#

this is the 320x32 texture that I used for the numbers, may not be the artstyle you are looking for but here it is anyway

candid bane
#

very nice of you

raw walrus
#

https://youtu.be/IC5JoS0wX0s
Followed this tutorial step by step, it works but this bizzare glitch happens on the scope

✅ Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=IC5JoS0wX0s
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👇
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Games https://unitycodemonkey.com/gamebundle

🔴 RELATED VIDEOS 🔴
3 Ways for a Scope Zoom Effect (Unity Tuto...

▶ Play video
#
public class ZoomShaderScript : MonoBehaviour
{
    public Material material;
    Transform TR;
    public Camera playerCamera;
    private void Awake()
    {
        TR = transform;
        material = GetComponent<MeshRenderer>().material;
    }

    void Update()
    {
        Vector2 screenPixels = playerCamera.WorldToScreenPoint(TR.position);
        screenPixels =  new Vector2(screenPixels.x / Screen.width, screenPixels.y / Screen.height);
        material.SetVector("_ObjectScreenPosition", screenPixels);
    }
}
amber saffron
# raw walrus

I guess that the zoom is sampling out of screen pixels.
Try to add a saturate node between "Tiling And Offset" and "HD Scene Color"

uncut birch
#

Hi. A question: is it possible to achieve the following in URP and shader graph: when (otherwise invisible) object B occludes object A, the occluded part of the object A is rendered differently (the red area marked with C in the image).

This SHOULD be possible, as in many games there are "X-ray" vision kind of features, where enemies etc can be viewed through walls, right?

What I find troubling in this is that this probably requires special 2 shaders, both for object A and B? But how to make the shaders "aware" of each other?

regal stag
# uncut birch Hi. A question: is it possible to achieve the following in URP and shader graph:...

Well for x-ray features you can use ZTest Greater, so that the object only appears if depth values are higher than what is currently drawn (i.e. enemy behind a wall). There's a similar example here using the RenderObjects feature : https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@15.0/manual/renderer-features/how-to-custom-effect-render-objects.html
But that may not really apply here, since B is transparent and in-front of A.

Instead, you'd want to look into Stencil operations. RenderObjects also provides overrides for that too, which may be useful if the shader doesn't use stencils directly.
https://docs.unity3d.com/Manual/SL-Stencil.html
In short, the idea would be render A to the stencil buffer. Then render B testing against the same stencil value. Pixels that fail the stencil are discarded, so only the overlap would be rendered.

floral fox
#

hello. im new to shaders. im trying to send the texture to the shader for post processing but I can't.

#
    private void OnWillRenderObject()
    {
        Camera.current.RemoveAllCommandBuffers();

        keyBuffer = new CommandBuffer();

        keyBuffer.name = "KeyBuffer";

        int tempID = Shader.PropertyToID("_Temp1");

        keyBuffer.GetTemporaryRT(tempID, -1, -1, 24, FilterMode.Bilinear);

        keyBuffer.SetRenderTarget(tempID);

        keyBuffer.ClearRenderTarget(true, true, Color.black);

        foreach (GameObject o in outlineObjs)
        {
            Renderer r = o.GetComponent<Renderer>();

            if (r && keyMaterial)
            {
                keyBuffer.DrawRenderer(r, keyMaterial);
            }
        }

        keyBuffer.SetGlobalTexture("_KeyTex", tempID);

        Camera.current.AddCommandBuffer(CameraEvent.BeforeLighting, keyBuffer);
    }
uncut birch
#

is it possible to set ZTest Greater in shader graph, or do I have to convert my shader to text?

regal stag
uncut birch
eternal python
#

hello every one i have very very simple shader which i want to convert it to Amplify shader editor (PAID JOB) if someone interested in it send me a dm!

btw here is the shader itself

{
  Properties
  {
    _Color ("Main Color", Color) = (1, 1, 1, 1)
    _Intensity ("Color Intensity", range(0, 5)) = 1
    _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" { }
    
    _DistortionTexture ("Distortion Texture", 2D) = "black" { }
    _DistortionIntensity ("Distortion Intensity", range(0, 5)) = 0.5
    _ScrollSpeed ("Scroll Speed", float) = 0.5
  }

  SubShader
  {
    Tags { "RenderType" = "Opaque" "Queue" = "Overlay" "IgnoreProjector" = "True" }
    LOD 200
    Cull Off
    ZWrite Off
    Blend OneMinusDstColor One
    Fog
    {
      Mode Off
    }
    
    CGPROGRAM

    #pragma surface surf SimpleUnlit nofog
    #pragma target 3.0

    sampler2D _MainTex, _DistortionTexture;
    half _ScrollSpeed, _DistortionIntensity;
    half4 _Color;
    half _Intensity;


    half4 LightingSimpleUnlit(SurfaceOutput s, half3 lightDir, half atten)
    {
      half NdotL = dot(s.Normal, lightDir);
      half4 c;
      c.rgb = s.Albedo;
      c.a = s.Alpha;
      return c;
    }

    struct Input
    {
      half2 uv_MainTex;
    };
    

    void surf(Input IN, inout SurfaceOutput o)
    {

      half scrollX = _ScrollSpeed * _Time;
      half2 uv_scrolled = IN.uv_MainTex + half2(scrollX, 0);

      half distortion = tex2D(_DistortionTexture, uv_scrolled);

      half uv_distorted_x = (distortion * _DistortionIntensity * 0.1) - 0.05;

      half2 uv_distorted_xy = IN.uv_MainTex + half2(uv_distorted_x, 0);

      half3 col = tex2D(_MainTex, uv_distorted_xy);
      half3 finalAlbedo = col * _Color * _Intensity;
      o.Albedo = saturate(finalAlbedo);
    }
    
    ENDCG

  }

  FallBack "Diffuse"
} ```
winter basin
#

Hello, how should i do caustics for terrain in unity 3D? I would like it to interact with shadows too. Thanks

tight phoenix
#

What is a texture2D in hlsl if I want to do it in a file instead of a string?

#

I get console errors if I use texture2D

#

I want to move away from using a string here because its hard to work with

#

but I cant figure out what to declare a texture2D, nothing seems to work

#

tex2D function says it takes in a sampler2D and a float for UV, neither of those are a texture

regal stag
tight phoenix
#

That explains why I couldn't find the answer, the net was giving me standard hlsl answers, not unity ones

bitter forge
#

Hello, I want to create a material, with which I am able to see kinda the outer „edge“ of a sphere – so that I only see a circle. And when I am changing my position, I see the outline of the sphere again, but from that position. I googled a lot, but I can’t seem to find a solution. Does anyone know how I can achieve that?

tight phoenix
bitter forge
tight phoenix
bitter forge
tight phoenix
hearty obsidian
#

@bitter forge Is it exclusively a sphere?

bitter forge
hearty obsidian
#

Then you can probably simply use a fresnel effect. If you're familiar with shadergraph, there is a fresnel node

bitter forge
floral fox
hearty obsidian
#

@bitter forge If you're willing to dive in, and your project isn't using built in rendering pipeline, then just create a new graph.

  • Create a color parameter
  • Create an outline color parameter
  • Create a float parameter for the thickness
  • Drag your color/float parameters in the graph, it'll create nodes
  • Right click in the graph to add a node, search for fresnel
  • Right click in the graph to add a node, search for step
  • Right click in the graph to add a node, search for lerp
  • Connect your thickness to the fresnel's power input
  • Connect the fresnel's output to the step's "in" input
  • Set the step's node "edge" value to something like 0.001
  • Connect the output of the step's node to the "t" input of the lerp node
  • Connect your base color to the lerp's a input
  • Connect your outline color to the lerp's b input
  • Connect the output of the lerp node to the graph's color input
bitter forge
hearty obsidian
#

@bitter forge Right click anywhere in the project window. Then Create -> Shader Graph -> Pick your rendering pipeline -> Lit or unlit depending on your needs

timid minnow
#

Trying to think of a good way to handle hexagon floor tiles that span over curved surfaces... probably facing the kinds of problems tile layers face in real life 😛

#

Beginning to think the best way to solve this would be with a shader effect instead of hexagon geo.

#

Normal + displacement height map? Anyone have ideas on the approach that would be suitable?

bitter forge
#

@hearty obsidian I followed your steps now and put the shadergraph onto a material and than that on my sphere. But my sphere is completely filled with the outline material. (Thickness is 0.001 and also the edge value of step's node is 0.001 as you wrote). The only point I am not sure, if I did it correct is the last one - connect the output of lerp to graphs color input. Where is that? I have connected it to the color input of the fragment shader, was that correct?

tight phoenix
#

Im getting undeclared identifier on uvX at line 9 but I don't see why its undeclared

#

What am I missing?

#

I added a second texture to the input which had nothing to do with uvX but now UV x is the part that broke

#

its clearly declared on line 7 in my eyes

hearty obsidian
tight phoenix
#

I hate writing shaders so much because it never behaves consistently ._.

#

this is literally impossible, code that worked before does not simply stop working, thats not how code works

#
void WhiteoutBlend_float(UnityTexture2D BumpMap, float3 worldPos, float3 worldNorm, float3 blend, out float3 Out)
{
// Whiteout blend\\
// Triplanar uvs
float2 uvX = worldPos.zy; // x facing plane
float2 uvY = worldPos.xz; // y facing plane
float2 uvZ = worldPos.xy; // z facing plane
// Tangent space normal maps
half3 tnormalX = UnpackNormal(tex2D(BumpMap, uvX));
half3 tnormalY = UnpackNormal(tex2D(BumpMap, uvY));
half3 tnormalZ = UnpackNormal(tex2D(BumpMap, uvZ));
// Swizzle world normals into tangent space and apply Whiteout blend

tnormalX = half3(
    tnormalX.xy + worldNorm.zy,
    abs(tnormalX.z) * worldNorm.x
    );
    */
tnormalY = half3(
    tnormalY.xy + worldNorm.xz,
    abs(tnormalY.z) * worldNorm.y
    );

tnormalZ = half3(
    tnormalZ.xy + worldNorm.xy,
    abs(tnormalZ.z) * worldNorm.z
    );
    */
// Swizzle tangent normals to match world orientation and triblend

float3 worldNormal = normalize(
    tnormalX.zyx * blend.x +
    tnormalY.xzy * blend.y +
    tnormalZ.xyz * blend.z
    );

Out = worldNormal; 
}
#

Where is my mistake? how is this not working now when it worked before?

#

I literally saved out a copy of the working code before changing it, and upon reverting it, it no longer works

bitter forge
regal stag
tight phoenix
#

okay there were some /*s floating around but even after removing them I still get the same error

tight phoenix
#

I assume its more than just preference

#

The code I was given instructed me to use it so I am hesitant to diverge even further from it when I can't even fix it as written

#
void WhiteoutBlend_float(UnityTexture2D BumpMap, float3 worldPos, float3 worldNorm, float3 blend, out float3 Out)
{
// Whiteout blend
// Triplanar uvs
//float2 uvX = worldPos.zy; // x facing plane
float2 uvY = worldPos.xz; // y facing plane
//float2 uvZ = worldPos.xy; // z facing plane
// Tangent space normal maps
//half3 tnormalX = UnpackNormal(tex2D(BumpMap, uvX));
half3 tnormalY = UnpackNormal(tex2D(BumpMap, uvY));
//half3 tnormalZ = UnpackNormal(tex2D(BumpMap, uvZ));
// Swizzle world normals into tangent space and apply Whiteout blend
/*
tnormalX = half3(
    tnormalX.xy + worldNorm.zy,
    abs(tnormalX.z) * worldNorm.x
    );
    */
tnormalY = half3(
    tnormalY.xy + worldNorm.xz,
    abs(tnormalY.z) * worldNorm.y
    );
    /*
tnormalZ = half3(
    tnormalZ.xy + worldNorm.xy,
    abs(tnormalZ.z) * worldNorm.z
    );
    */
// Swizzle tangent normals to match world orientation and triblend
/*
float3 worldNormal = normalize(
    tnormalX.zyx * blend.x +
    tnormalY.xzy * blend.y +
    tnormalZ.xyz * blend.z
    );
*/
//float3 worldNormal = normalize(tnormalY.xzy * blend.y);

Out = tnormalY.xzy;
}```
#

this version of the code works

#

but I dont understand why it works

#

all I did was comment out some useless parts I didnt need

#

but when un-commenting them because I needed them again, it stopped working

#

which doesnt make sense because all i did was revert it to how it was before, which WAS working

regal stag
# tight phoenix What is the reason to not use tex2D?

There's 2 texture syntaxes in hlsl. sampler2D name type and tex2D(name, uv) is an older syntax. Texture2D name, SamplerState sampler_name and name.Sample(sampler_name, uv) is the newer one. This page goes over this too : https://docs.unity3d.com/Manual/SL-SamplerStates.html
Unity SRPs/SG implements their own structs (i.e. UnityTexture2D) & macros (i.e. SAMPLE_TEXTURE2D) to automatically use whichever syntax is required to support the target platform. Again see : https://www.cyanilux.com/faq/#sg-custom-function-textures

lean lotus
#

So I needed to get the albedo from the gbuffer of textures that are on objects
I was doing this by adding together the diffuse albedo and specular albedo, but in some palces this messes up with specular being a white, when the texture is red for some shaders
is there a way to get just the albedo of the texture of the mesh on the screen?

#

basically I need this(but this is wrong because here the specular is a white that gets added on top, making it washed out)

waxen grove
#

I want to make a shader that had a couple sounds (an array) in its data, references to them, is there a possibility to add to the shader code if it is on collision or not?

This would be used for collision sounds

meager pelican
lean lotus
#

those are what I am accessing

meager pelican
#

Hmm....and specular is mixed in? I thought that was a separate buffer, but I admit I haven't looked it up lately.

lean lotus
#

it is a seperate buffer but you have diffuse albedo and specular albedo

#

if I only use the diffuse then metallic objects ar black

#

if I combine diffuse and specular then specular is always non zero

slow rain
#

I have an issue where a shader isn't appearing inside of a vr build. Adding the shader to included shaders isn't working. Also this issue happened after a merge from source control. Any ideas?

meager pelican
lean lotus
#

you good, it threw me too

meager pelican
#

Also check the build logs.

waxen grove
#

Can someone help me with this?

I want to make a shader that had a couple sounds (an array) in its data, references to them, is there a possibility to add to the shader code if it is on collision or not? The end result should be that I am able to have a audioclip array in the material inspector, for impact sounds

This would be used for collision sounds

gusty rune
# waxen grove Can someone help me with this? I want to make a shader that had a couple sounds...

I don't think that it is possible to reference audio clips from a material (or shader), beacuse the graphics hardware doesn't care about sounds.
Also, this might not work once you consider that the visuals of an object aren't necessarily using the same geometry, or maybe only one of them is present on the same object.

Instead, you might want to use a script to store the references to the audio clips, and select the right one to play.

waxen grove
#

I was thinking thag

#

Can a shader store a String?

#

I already have an audio library that could work if I can reference strings

gusty rune
# waxen grove Can a shader store a ``String``?

I'm still not so certain why you want to attach this kind of data to your shaders/materials. Shaders and materials are used to render your objects, but not to hold any kind of data that might be necessary for other systems the objects might interact with (e. g. playing a sound). In order to retrieve the data, you would need access to the MeshRenderer to get the Material, but instead you could use GetComponent to retrieve the component that actually stored the data for the sounds and retrieve the data from there.

waxen grove
#

I'm trying to copy what Source does with its Materials and Audio

gusty rune
# waxen grove The reason I want to do this is for ease of access, one, and two because each ma...

You could create a "SoundDatabase" that contains a dictionary mapping sounds to materials, and use the material of the object to look up which sound to play. This falls apart however as soon as you have MeshRenderer with multiple materials, or once you can't distinguish which material should be used, or maybe also with a Terrain and its blended textures.
Yes, it would simplify things for the editing if only a single material needs to be assigned in order to adjust multiple properties at once, but there are also drawbacks to this. I guess the problem here might be that the Source engine has a different concept about what a Material is compared to Unity.

waxen grove
#

Fair yeah

#

I was thinking "what am I gonna do with multiple materials?"

#

I mean, at that point, just make a script, which I kinda already have

waxen grove
#

Thanks for your help

lone bone
#

im trying to make an effect that results in the object being completely transparent, but even when alpha = 0, theres still a wierd lighting reflection

#

ive been playing around with the settings, but nothing completly removes the effect

#

(shown on the left capsule)

serene creek
#

Hello, Any idea why I am getting z-fighting on Built In when the camera is far from objects? Increasing Clipping Planes on the camera has no effect on this issue. The object with this problem is using a semi transparent Shader. I appreciate any help!

gusty rune
meager pelican
#

Or possibly reduce your visible world size so you don't run into the floating point precision problem.

meager pelican
# lone bone ive been playing around with the settings, but nothing completly removes the eff...

Like @gusty rune said, that's specular/environmental lighting.
The only way I can think of doing it is to either use a shader that takes alpha into account with the specular/environmental lighting (like multiplying those things by the alpha value) or swapping the shader out when alpha is near-zero...perhaps even better if you could just disable the drawing entirely. I mean why draw what you want to not be drawn? There's an old saying in CG...the fastest polygons are the ones you DON'T draw...so don't draw it if you don't want/need to see it.

lone bone
meager pelican
#

Firstly, do you have to draw it at all?

lone bone
#

not if its fully invisible, no

oak maple
#

So this might be a bit hard to explain, but I used a normal map to make it so this grid only appears when a light is put on it. I want it to look like the second image from all angles, but half the time it looks like the first. Is there something else I can do, should I not use normal maps? I previously put this in lighting but I don't actually know if it should go there or here. Sorry if I'm intruding on conversation

meager pelican
# lone bone not if its fully invisible, no

Then don't!
What render pipeline?

But for the nearly-invisible, you'd have to show the shader. I assume you're using a lit shader, and that's why you're having a problem, but maybe show it so we can discuss. Maybe change the spcularity somehow as alpha approaches zero. Depends on HDRP vs URP, but the master stack has some inputs that impact that.

oak maple
#

nevermind, I figured something out

lone bone
meager pelican
oak maple
#

Oh, alright, thanks

#

I'm not new to discord but I'm pretty new to public discord so

serene creek
tacit parcel
meager pelican
serene creek
#

However changing any of them didnt had effect

#

I might need to resolve it using a LOD mechanism then

meager pelican
#

Hmm.
1000 isn't all that bad. Not sure why you're getting this.

#

If you'd had 100,000 for far plane...well yeah.

#

Does upping the near-plane help any?

tight phoenix
#

I have a complicated shader that gives the appearance of 3D print lines.
An earlier version of it used World-space coordinates, world normals, world position
I want to switch it to use Object space everything, which I did by changing everything to object, but now I am having a problem.
I want to set up a vector 3 to rotate it's object position, but I can't seem to figure out exactly what I want to rotate to make it act the same as if it had been rotated in world space coordinates

#

How/what do I do to simulate rotating an object in world space to object space?

#

this alone wasnt enough, it doesnt behave the same as if it were world space rotations, so I assume rotating in world space is doing more than just this and I need to account for those other unknown changes

lunar valley
tight phoenix
#

but I want to be able to 'rotate' the mesh in-shader and mimic what would occur if I had rotated in world space

#

without actually rotating it

#

at no point is actual rotation occuring to the mesh or object

floral fox
grizzled bolt
#

@serene creek @meager pelican It can also be a rendering error, particularly if it happens specifically at long distances
The suggestion to bring near and far planes closer should work in that case
The closer the near plane is, the more likely geometry will get squashed together close to the far plane and z-fight

dense flare
#

is there away of fading alpha of shader based on cameraposition to the planes vertices?

meager pelican
# serene creek However changing any of them didnt had effect

@grizzled bolt Yeah, good point, but they mentioned changing "any" of them didn't help, so I'm assuming it was tried.
However, it's a settings issue, not likely a bug in the renderer. I'm surprised that it showed up with a max range of 1000, so the only thing I could think of was that .001 near plane

dense flare
#

nvmi got it working

grizzled bolt
#

Road decal geometry for example can be visible far but easily too close to ground

floral fox
#

Is there a way to get multiple render textures, each rendered with a different material?

floral fox
#

how

amber saffron
#

Just do like you said : multiple render textures, multiple materials, multiple blits (or use custom render texture for the easy use)

raw walrus
#

wait no it started happening again

#

wth

raw walrus
#

okay so it works properly only on maximized mode

#

something about resolution messes it up as you said

tight phoenix
#

How can I make the green edge a hard line straight across instead of arced?

#

I have tried pulling out the green at earlier stages but I cant seem to get the line I want

#

hm maybe I am getting somewhere with this

grizzled bolt
#

It's a sphere, so I assume it'd have to depend on view direction to be completely linear

tight phoenix
#

I want to use this on meshes other than sphere

#

making progress but now I can't figure out how to prevent division by 0 here

lunar valley
tight phoenix
lunar valley
karmic hatch
#

i think if you do step(abs(g), threshold) it'll make straight lines

#

but to get all three to line up you'd need to find the right value of the threshold

tight phoenix
karmic hatch
#

yeah smoothstep would work

tight phoenix
#

I dont want anything red or blue in the green at all

#

this but all green

karmic hatch
#

i think 1/sqrt2 = 0.7071... is the right threshold value?

amber saffron
amber saffron
karmic hatch
#

bc the contact points form squares

tight phoenix
amber saffron
tight phoenix
#

This sorta works but doesnt meet my use case, I need to adjust where green is, and red and blue don't extend all the way to the top behind it

karmic hatch
tight phoenix
#

Yeah thats a problem ^

#

if I remove the third channel I get divide by 0 problems

#

but if the third channel is there, red an blue dont extend all the way to the top

#

this doesnt work either, more divide by zero

amber saffron
karmic hatch
#

Is minimum cheaper than multiply?

lunar valley
tight phoenix
#

Use of step is confusing me, I dont want super hard edges

#

this is for tri-planar so I need smooth-ish edges, I need to control the smoothness with a value

amber saffron
tight phoenix
#

replacing step with smoothstep has different values

karmic hatch
amber saffron
#

Replace steps with smoothsteps

tight phoenix
#

step takes in two, smoothstep takes in three,

#

Ill just try to figure it out myself

amber saffron
#

I'm trying to help, but please do some effort

tight phoenix
#

I'm sorry that I am much less experienced than you on top of being extremely stupid

lunar valley
tight phoenix
#

i am going to step away for a bit because the barrage of put down critisism is getting me agitated. Thank you for assisting me get this far

amber saffron
amber saffron
lunar valley
#

Tbh. I do not know what he was doing but it probably doesn't really matter

tight phoenix
raw walrus
raw walrus
#

Here's the zoom shader that works, all I need is to add a texture2D on top of it

#

and I have no idea on how to do that

lunar valley
#

ah so that was a question lol

lunar valley
raw walrus
#

a png texture

lunar valley
raw walrus
lunar valley
#

oh is it some scoped rifle or something

raw walrus
lunar valley
raw walrus
raw walrus
raw walrus
lunar valley
lunar valley
misty crown
#

Hi how do you set a smoothness map on a material?

uneven jungle
#

Hello this might not be related to shaders, but thats the closest channel to this issue that i can find.

So i made this in blender as just an example item for later ones, but i am having an issue where i can't find a way to transfer over the checker board pattern that was created by blender over to unity.

Blender:

#

heres how it looked right after importing

#

Heres how it looks right now, i just removed the glow and set its colors. Tho the checker board patter didnt transfer over

#

Under blender it is not a texture, but it is generated as shader i beleave by blender it self.

#

Help?

#

How do i transfer that patern over to unity

brave osprey
#

How do I add a second texture overlay in a custom sprite lit shader?

cosmic prairie
#

paintDotNet is your friend

uneven jungle
#

1 * 8 pixel?

#

and then in unity i will be able to scale it up?

cosmic prairie
#

unwrap the UV of the checker top to be the default square aize

#

then 1 pixel per

#

import the texture into Unity with Point / None filter mode

uneven jungle
#

Ok ill try tomorrow

#

Quick question about player UI's in vr. Can i add any image as a button?

cosmic prairie
jade ginkgo
#

Is there a reason there's so few examples of shaders with HLSLPROGRAM? I understand that CGPROGRAM is older and therefore has a legacy of tutorials and examples, but hasn't HLSL been the go to syntax for a while? Is there a reason Unity 2022 is still defaulting to CGPROGRAM when you create a new unlit shader? Do folks still generally write with the CG syntax and just let Unity compile it into HLSL for them?

brave osprey
#

How do I blend two textures, and make the black layer transparent? Ive tried multiple methods and can only get one textures 50% transparent by lerping by 0.5f. How do I remove the black layer to show the texture underneath

#

for context, here is both layers

regal stag
# brave osprey How do I blend two textures, and make the black layer transparent? Ive tried mul...

Typically you wouldn't have black pixels in the texture you want to overlay, they'd instead have an alpha channel and be transparent. That way you could just use the A output in the T of the Lerp.

But otherwise you could also use some math to test if the pixels in the texture are black. Either with a Color Mask node, or since black is a value of 0, Add all the channels together and use a Step node (or Comparison + Branch). Again use that result in the T of the Lerp.

tight phoenix
#

Is it possible to change which shader this material is using but inhereit that color field into the new shader?
I need to change a looot of materials and I was hoping if I just name it something it will just work instead of a ton of manual data entry

brave osprey
tight phoenix
regal stag
# jade ginkgo Is there a reason there's so few examples of shaders with HLSLPROGRAM? I unders...

For the built-in RP there's not really a reason to switch to HLSLPROGRAM, especially given the amount of resources/tutorials as you mention. Either way it's still hlsl - CGPROGRAM just includes a few built-in shader includes, (HLSLSupport.cginc and UnityShaderVariables.cginc, iirc). That way you automatically have access to some macros and variables (like _Time, unity_ObjectToWorld, etc).

But yeah, when writing shaders for post processing v2 stack/package and other render pipelines, their ShaderLibraries replace those built-in include files, so we must use HLSLPROGRAM there or it causes conflicts.

I imagine there's less examples of shader code for URP/HDRP since it's easier to just use Shader Graph, especially due to the lack of surface shader support. But you can always look at the shaders those pipelines have in the package files / Graphics github (https://github.com/Unity-Technologies/Graphics)
For URP I've also got https://github.com/Cyanilux/URP_ShaderCodeTemplates (though it was written for v10 which is a little outdated now)

fervent flare
#

I've been desperately searching for a solution for this problem for days now and am starting to lose hope 😦

rare charm
#

Idk if this is specifically a shader thing, but this seems like the best place to post this. I'm making a toon-ish game where everything has the same material with uvs mapped to colors in a texture which is basically just a color palette. This works well and it makes things pretty fast for me.

But I have a few models that I want to have different colors. Pretty simple, like a cube that is blue, a cube that is red, etc. Not exactly that, but just as simple.

Is there a way to basically remap the UVs in unity so I don't have to export several meshes with different uv maps? I suppose I could have different materials with different versions of the palette texture, but that sounds less easy than having multiple meshes.

sick pulsar
#

is there a way to get the edges of a mesh

lunar valley
sick pulsar
#

sort of

lunar valley
#

I can't help you with the information: sort of

sick pulsar
#

*currently trying to figure out how to phrase it

#

like synthwave but instend of cubes its whatever shape the sides of the mesh are

lunar valley
sick pulsar
#

yes

#

im going for a similar look to get to the orange door

lunar valley
sick pulsar
lunar valley
#

all I can say now is lots of bloom, the black object in the background seam to have a subtle outline, and then we have these streaks on the ground which are also just emissiv materials

sick pulsar
#

the edges glowing

#

*ones the bottom islands?

lunar valley
sick pulsar
#

ye

lunar valley
sick pulsar
#

both

lunar valley
sick pulsar
#

ight

#

and im assuming the glow is an outline

lunar valley
sick pulsar
#

oh

#

thx for the help

lunar valley
lunar valley
rare charm
# lunar valley I do not really know if you can change uv maps in unity but using different mode...

Idk if anyone cares about this but me, but I wanted to share just for posterity's sake.

In Blender I made several UV maps for my model, one for each color I want in the texture. The order of these matters.

Then in Unity I made an enum with the names of each UV map in order. Then they can be switched on the mesh filter like this:

var uvs = new List<Vector2>();
meshFilter.mesh.GetUVs((int)uvMapNames, uvs);
meshFilter.mesh.SetUVs(0, uvs);

And that's it. My use case is a little more complex because there is an object with several meshes in it and only some of them have multiple uv maps. So I just iterate through and if GetUVs() returns an empty list I ignore it.

#

I put the UV swap in the Awake() of that gameobject and when I press play the colors immediately change to whatever I want them to be. No preview in the editor, but I'm ok with that.

lunar valley
#

thats pretty cool

dire ravine
#

How would I use one sprite from a sprite sheet for a texture?

#

currently its using the whole sprite sheet

floral fox
#

why is my commandbuffer completely black?

#

outlinekey isnt just a black material btw

meager pelican
# rare charm Idk if this is specifically a shader thing, but this seems like the best place t...

"Is there a way to remap the UV's in unity"....well, the UV's are an attribute of the mesh object. Although, as you note, you can make several copies of a mesh and put unique UVs on each copy. I suppose if you have to special case a mesh, you could, instead use some kind of override...perhaps a texture or a data array...and pass a switch to have the shader use that instead of the UV embedded in the mesh data. If it's as simple as "red cube" vs "blue cube" just pass a switch and a color, and use an IF to check it in the shader.
AKA you'd have

float4 overrideColor;``` declared in the shader and set that value on the material instance for that mesh. 
If it's a solid color you could pass that on from the vertex stage to the fragment stage, so you'd do the IF in the vertex stage.
regal nacelle
uneven jungle
#

size is good its just that the pixels dont show as pixels but more just blured out

#

also the little second image is the 8x8 pixel image

amber saffron
uneven jungle
#

i did it but nowthing changed

keen scaffold
#

Make sure to hit apply!

safe ravine
#

How to debug a HoloLens application using RenderDoc? The editor switches to mono rendering during initialization, but I need to capture a separate eye.

keen scaffold
#

Am I right in thinking that it's completely impossible to make a first-person shooter using deferred rendering in URP? You can't use camera stacking to render the guns in front of everything else. Also, using custom renderer features draws the meshes on top of the level, but then the meshes within the gun on the top layer don't write depth. Is it literally impossible? (I HAVE to use deferred rendering)

uneven jungle
#

if i want one side to be checkers and other faces of the mesh to be black or white what do i do

amber saffron
uneven jungle
#

How do i make it so it dosnt glow/emit light, as no matter how dark i make the light around it it still can be seen like before

amber saffron
sterile knot
winter basin
#

hi hello can someone help me with this water shader the bands are suppesed to come out of the meshes but instead it is moving with the camera.

uneven jungle
uneven jungle
#

it becomes this when setting it to sprite texture

amber saffron
karmic hatch
# winter basin hi hello can someone help me with this water shader the bands are suppesed to co...

What are you using to create the bands? If it's depth, they'll only appear where the water is in front of the capsules (which i think is what you can see if you look carefully around each capsule). That method for creating foam works well if you've got large objects, usually with fairly shallow gradients going into the water. It doesn't work well if you have very small objects or sharp jumps in depth.

uneven jungle
noble wedge
#

google results say you can get Unity to render both sides of faces (backfaces), but it seems like no one really knows how to get it to work anymore. i tried a bunch of different methods, but no luck. do you guys know if figuring this out in Unity is even worth it, or should I just create the geometry on my 3D model?

snow forge
#

Soooo, I have a plane that my character walks on (fps) and I want to have it so it gets transparent the further away from the character (ie, have the character walking around on an opaque 'disk' with a fade off into the distance.

I know I need to have position and camera nodes going into a distance node and then an 'amount' float node to control the distance of the opaqueness, but I'm drawing a huge blank about where to go from there.

Could anyone help out a little please?

#

HDRP Shader Graph btw.

meager pelican
# keen scaffold Am I right in thinking that it's completely impossible to make a first-person sh...

I'm surprised that you cannot force it to write depth, but you may need to set the proper depth buffer on the camera.
Also see here for some funky stuff: https://forum.unity.com/threads/urp-deferred-camera-stack-not-possible.1204534/

meager pelican
#

For example a playing card...I'd use a double sided model for that.

noble wedge
honest bison
#

What are the best resources for learning compute shaders?

meager pelican
# noble wedge Thanks! That's really helpful to know I'm not creating extra geometry for no rea...

Sure, it all depends on how you define "when needed". I mean, if you have a very complex mesh, it might be nice to just handle it in the shader, it's not all that bad. But then again, GPU's process polygons in the millions, so for a playing card, meh. And you can use all the same uv sets because they're all front facing polygons. So UV0 is UV0. Otherwise you tie yourself into knots doing "is backface, use UV1 otherwise use UV0" or whatever. Why bother for only a few polygons extra?

YMMV. It is possible to show the backfaces and invert the normals. And deal with the UV mapping.

noble wedge
#

Thank you

misty torrent
#

I'm just gonna post the question I posted in Youtube Answers to not repeat myself.
https://answers.unity.com/questions/1938514/lit-cutout-shader-in-universal-render-pipeline-urp.html
I'm on a tight schedule so I can't afford to start learning shaders from scratch, can anyone help me out or point me to where I can learn how to do what I'm asking about?

meager pelican
misty torrent
misty torrent
shy fiber
#

Is it possible to use triplanar + parallax occlusion mapping?

shy fiber
#

woth shader graph

#

with

wintry valley
#

Hello! I am trying to make a border shader for hexagons that use decals. I am using URP and the issue is the decals are rendering below water which is in a transparent render queue. I have tried forcing the water shader to use depth write, but the decal still does not respect it. I want the decal to project ontop of a transparent material. Any ideas on how to get the decal to do that?

uncut birch
#

hey, is it not possible to make a wireframe shader with shader graph?

grizzled bolt
meager pelican
#

I'm assuming your decal process is after opaques.
I suppose the best option would be to change the queue of the decal writer to be after the water shader that writes depth.

raw walrus
floral fox
#

how do i get objects position in shader

amber saffron
amber saffron
floral fox
amber saffron
floral fox
#

green objects are exactly same color

amber saffron
#

What would you expect position value (25, 8, 0) to display ?

dense flare
#

?

ember scaffold
#

Is there a simple tutorial on how to make procedural 2d grass textures?

#

Aiming for something like this but 2d

frigid compass
#

I made portals so when the player collide with the 1st he transport to the 2nd
I made dissolve shader starts when the player collides

when I put the player besides the portal then start the game.. press D to move and collide with the portal .. the dissolve does not happen

But when I put the player above the portal and start the game he falls by gravity on portal and the dissolve is running ok

can anyone tell me why this is happening?
( I’m using a new input system)

raw walrus
#

tried this

regal stag
# raw walrus tried this

You'd likely want to connect the A output from the texture to the Opacity port, and use Overwrite mode.

raw walrus
regal stag
frigid compass
regal stag
regal stag
ember scaffold
winter basin
#

why is my water shader graph shader thingy doing this when high or far from the water it has blue thingies and whithe thingies when you go too far

#

blue from this angle

muted pond
#

I'd like to build a damage shader. It should work in a way that if a player attacks a wall then there should be a damage map that looks similar to a heat map. Ranging from undamaged to destroyed. For each color spectrum another Albedo map should be used for that "revealed" section.

Was something like this done before? Would be interested in how it has been achieved

native ruin
#

Hey there!
Someone could help me please?
I added a rotate node, but when i set a value, like 90º, the texture doesn't seem to rotate properly, looks like 45, i need to put a very specific value to keep it like I want, as I show in the second image.
I put a rotate just before my images textures, idk if it's the correct way, i'm newbie at this shader stuff, thank you!

regal stag
native ruin
grizzled bolt
muted pond
grizzled bolt
muted pond
#

I see - well ok I think I need to experiment a bit then. I guess when creating a new Shader I also can extend the existing Standard Shaders, eh?

lunar valley
shy fiber
grizzled bolt
shy fiber
#

because i don`t even know where to start

#

POM needs UV and triplanar output only color

wintry valley
shy fiber
#

Is it possible to write a triplanar shader to output UV instead of color?

regal stag
#

I imagine triplanar + POM is possible but isn't very practical as triplanar triples the amount of texture samples. POM is probably already expensive enough without having to do that.

shy fiber
#

can i use it with triplanar?

#

i`m creating a tile engine, it needs triplanar to look good but without POM it does not look as good

#

they are square for now

regal stag
#

I'd look into proper UV unwrapping of the meshes rather than relying on triplanar. Can still sample both grass + stone textures with those mesh uvs and blend based on Y axis of vertex normals though.

shy fiber
#

but then it will be repetitive

#

if i repeat the same tile it will look bad

#

and very hard to do it seamless

#

i`m doing it like dota 2 tile editor

#

they use triplanar too but not POM

shy fiber
snow forge
#

Hi all,

I hope someone can help cause this is driving me insane. lol. I'm trying to build a shader graph whereby only the area of the 'ground' close to the player (relatively close anyway) is visible and fades out at a distance (ie, min/max distance) etc. (See image for an illustration as to what I mean. Red is player, dark grey is ground, light grey is ground visible area).

I know that at the beginning of the graph I need camera position and 'world' position into a distance node, it's what comes after that where I'm stuggling. I've seen a couple of videos on the subject but I can't seem to get those methods to work. 😕

Anyone have any ideas please?

regal stag
snow forge
#

@regal stag Thank you, will give those a go 🙂

#

Hmm......okay, not sure what I'm doing wrong here. 😕

There's the graph.......

#

That's the result. 😕 So very confused.

regal stag
snow forge
#

Oh yeah. lol. Thanks.

Okay, well something is happening, but not really what I expected.

The 'ring' is getting alpha clipped but the distance is way off (I have min/max set to 10/20) the ring has a diameter of 240km so I think I'm misunderstanding something about how the min/max distances are being read/applied.

#

And changing the min/max numbers doesn't seem to do anything at all. 😕

native ruin
#

Guys, i'm still learning a bit about shaders.
In unity we have this first one, but the divisions among textures are so soft, and I need something with more "contrast" if i can say this way.

I made this new one (second image) based in some videos I saw, but to painting work properly I would need a very subdivised mesh, and that's not an option for the project we're working now, anyone could show me a way?

It's a mobile project

snow forge
#

How are you blending the textures?

native ruin
snow forge
#

Okay, try adjusting your 'blend amount' Lower values may harden up the edges. Failing that, I think your height map might need to be a higher resolution.

native ruin
snow forge
#

Hmm. Not sure tbh (still kinda learning this stuff myself. 😕

native ruin
#

But thanks for trying anyway xD

snow forge
#

Okay I'm seriously about to lose my ** about this. I seriously don't understand why, after trying every method I've found/been told about I can't get this damned thing to fade off.

#

InverseLerp, SmoothStep, no fading at all and SphereMask just makes the whole thing transparent.

subtle glacier
#

Is the following shader using any bumpmapping or displacement?

snow forge
#

I believe so yes. My limited understanding of shader code suggests that this section

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

        struct v2f
        {
            float4 vertex : SV_POSITION;    
            float2 noiseUV : TEXCOORD0;
            float2 distortUV : TEXCOORD1;
            float4 screenPosition : TEXCOORD2;
            float3 viewNormal : NORMAL;`

Is dealing with moving vertices on the mesh to displace it.

subtle glacier
#

isn't it just editing the noise and distorting coordinates to "fake" displacement?

snow forge
#

I'm honestly not sure, but it's referencing the vertices of the sea mesh.

regal stag
snow forge
#

My bad. lol.

regal stag
snow forge
#

@regal stag Okay, yeah it is set to transparency, will disable the clipping (the clipping before BTW that I mentioned was because of my camera far plane. lol.

regal stag
snow forge
#

Really becoming frustrated now.

Player is 100m above the object I want fading. Min distance is set to 0, max distance is set to 200, but the bloody thing is still solid. I so don't get this at all.

#

Camera is attached to player.

#

What it looks like

#

What I want it to look like......

(with the transparent bit 'following' the player.

subtle glacier
#

Cyan is there ANY chance I can get you to explain every line of code?

regal stag
snow forge
#

@regal stag Yes it is.

regal stag
#

Then you shouldn't need the Camera node, as HDRP's "world" space is already camera-relative. Use distance to (0,0,0) or Length node.

#

Sorry, didn't realise it was HDRP at first

snow forge
#

ok. 1 sec (thank you a lot btw for taking the time to help out)

#

Still the same result. 😦

And game view (running)

regal stag
regal stag
snow forge
#

And the width of the ring is 20km.

regal stag
snow forge
#

Okay. Just thought I'd check. lol.

regal stag
#

These values would basically be the distance at which the fade begins and ends, to clarify.

snow forge
#

I thought that, but as I have the player/camera 100m away from the surface, in my head at at least a min/max of 100/200 should show some fade.

#

Oh, wait. Something is happening. lol.

#

Okay, it's sort of working. (at least the fadey part is now.)

But, something else weird is going on. I'm still getting a specular hit on the transparent part. 😕

snow forge
#

UV's are a 'map' of sorts of the Vertices of a model but 'flattened' out. They allow for accurate texturing etc.

subtle glacier
#

so what does this line do exactly?:
o.distortUV = TRANSFORM_TEX(v.uv, _SurfaceDistortion);
o.noiseUV = TRANSFORM_TEX(v.uv, _SurfaceNoise);

snow forge
#

It looks like it distorts the UV Map, thereby giving the texture assigned to the object some distortion.

regal stag
# subtle glacier so what does this line do exactly?: o.distortUV = TRANSFORM_TEX(v.uv, _SurfaceDi...

TRANSFORM_TEX is a macro unity defines, it applies the Tiling and Offset fields of the textures (from the material inspector) to the uv coordinates.
Also again, the tutorial literally explains this, please read it. https://roystan.net/articles/toon-water/

snow forge
#

Ah fixed my spec issue. lol.

regal stag
snow forge
#

There's a setting in the material settings 'Preserve Specular something' that was turned on.

regal stag
snow forge
#

But it's now doing what I want it to do 😄

@regal stag seriously dude, thank you. 🙂

snow forge
#

RTX stuff mainly. lol.

spiral tendon
#

Has anyone here made a shader for TextMeshPro Text?

stray wraith
#

Anyone have any insight on how to create a shader in shadergraph that when two outlines over lap one another it hides the overlap part?

#

Like the image above

dire ravine
#

Im trying to make a 2D shader and it turns out really weird

#

im not sure whats happening

floral oyster
#

is _MainTex not a thing for 3d shader graph?

dim yoke
meager pelican
floral oyster
#

yea, i started to think that I need to create a separate material for every model, and then select thhe texture and add it into the material manually.

I thought it was like in 2d, where _MainTex would just grab me the texture from the spriteRenderer, and then i can just edit stuff.

meager pelican
# stray wraith

That gets a bit complicated. Each shader only knows about its own mesh. In order to do what you're asking, you need the outline to happen "after the fact" of them ALL being drawn. That information can be passed in the stencil buffer. However, last I knew SG doesn't support stencil operations. And the process for doing this requires another pass, as I said. So unless stencils are added to SG, you'll have to either generate a shader with SG and then edit it from there, or just hand-write one the "normal way". URP shaders support stencils, just SG doesn't.
Maybe you can find a way to use a separate set of passes and a render texture instead of the stencil buffer, but I don't know of a solution like that. Maybe someone else does.
More about outlines in general: https://alexanderameye.github.io/notes/rendering-outlines/

wide quartz
#

i want a number to go from 0 to 1 and repeat from 0 to 1 (not go back and forth, just go 1 the max value and repeat) .... what node does that

grizzled bolt
wide quartz
#

thank you, I will try both

devout imp
#

hey hey, quick question

#

is there any way to expose and hide input fields dynamically based on a toggle in shader graph?

wide quartz
wide quartz
#

ok so... I am working in a sprite shader, I want to repeat a texture in a mask of that sprite... I am thinking i should use a tiling and offset node to move the wanted texture.... but how do I repeat it (the tiling and offset only makes the picture smaller or bigger)

wide quartz
#

if anyone can help please do, I am unable to do this

#

i did this but i didn't get the same result

#

ok done.. the problem was the import settings of the texture.

winter basin
#

why does my tessellation in the shader graph gett better and at around 5m it gets worse?

winter basin
#

more tessellated is better worse is worse

#

when it gets closer at around 5m it worsens

amber saffron
#

Like, when you get closer the triangles get bigger again, or just they don't continue to tessellate ?
Maybe you jost got to the tesselation limit.

winter basin
#

closer = bigger triangles

gloomy tendon
#

Can you set a float2x2 in a shader from C#?

cosmic prairie
#

try SetVector maybe

#

usually works if it's the same size

#

or SetFloats

gloomy tendon
#

yeah I did SetVector but assumed it would not set a 2x2 matrix but will check

#

well something is not quite right doing that - best I got now is SetVector to a float4 and then fill out the 2x2 from that!

amber saffron
amber saffron
gloomy tendon
amber saffron
# gloomy tendon there is only 4x4

Like SetVector takes only a Vector4 as input, but works on float2/3/4, I suspect that the matrix version works on different hlsl matrices size.

gloomy gust
#

hey, i downloaded a shader file which makes sprites hide behind shadows. how can i make it so the hidden part is completely 0, ad not just like slightly hidden? the only way it would go completely hidden is that if i turned shadows all the way to 1, but that makes the shadows completely black and defeats the purpose of it.
https://stackoverflow.com/questions/65696260/is-there-a-way-to-hide-a-player-who-is-in-the-shadow-in-unity-2d-light-system/67780057#67780057

#

this is the shader file i used

#

also, im having an issue where it says this, but the file is in the same folder?

scarlet crater
#

Hello! I'm attempting to create a CRTV shader, and I'm running into the inevitable issue of the "subpixel" pattern causing moire patterns / artifacts at distance, making the text on the screen unreadable

#

I had seen mentions of using screen space derivative functions to determine when to draw the subpixel mask, essentially removing it when the subpixel pattern doesn't fit inside a certain clump of pixels or whatever

#

At a very surface level, I understand what that means, but not nearly enough to begin implementing it

#

If someone is more knowledgeable on this topic, I'd love to know more

wind tundra
#

guys need help in making a simple 2d dropdown shadow

#

i have this working right now

#

but it doesnt work with particles

wind tundra
#

my circle not showing correctly help

#

2d

#

basic circle

#

help'

prime shale
#

<@&502884371011731486>

tame topaz
#

!ban 782321334139092994 bot

echo moatBOT
#

dynoSuccess wilkasse#0290 was banned

wind tundra
#

help

modern delta
# wind tundra

Is the problem the light blue edge? I think you have negative values in your "drop shadow". Add a Saturate node between the multiply and add nodes

wind tundra
modern delta
#

Oh, well I think that is just the texture you're using

wind tundra
#

for some reason its not showing properly

modern delta
#

My guess is that the default texture in shader graph is still set to a non-circular texture. Setting a texture or value in a material will not propagate to the shader graph defaults

#

Can you click on "MainTex" in shader graph and check what the default texture is?

wind tundra
regal stag
#

You haven't connected the alpha channel (A output of sample) to the Alpha port on the master stack

wind tundra
#

but then the redish brownish outline thingy diappears

regal stag
#

Combine the alpha channels of both texture samples with a Maximum node

wind tundra
#

the entire point of making shader is to have that dropshadow

wind tundra
#

ok it kinda works now

#

but now how do i remove this blue thing?

#

got rid of the blue thing too

#

but the brown color is also gone

modern delta
#

Pretty sure the blue is from negative values from your subtract node. Add a saturate node after to keep the values between 0 and 1

wind tundra
#

anyhelp

wind tundra
#

the brown should be there

#

is that because of the alpha im using

modern delta
#

can you show the graph again?

wind tundra
modern delta
#

I don't see any saturate node. And you said the red is gone

#

wait, why did you switch everything to use the alpha channel of the textures?

wind tundra
wind tundra
#

man im soo stuck

modern delta
#

Sorry, gotta go. But I quickly remade the shader. Hopefully this does what you want.

#

I'm not used to working with sprite textures, but that seems to be why shader graph is showing the weird shape instead of the circle in all the previews. But by multiplying the color by the alpha first, you get nice circles everywhere in the graph. This makes it easier to preview what you're doing. So you take your normal and offset circles, subtract to get the shadow, saturate it to normalize the values, multiply it by the color and then add it back. And for the alpha, I just took the max of the normal and shifted texture alphas like @regal stag suggested. This ensures that the circle and shadow are visible.

wind tundra
#

AND THANK YOU @regal stag TOOO

#

just one thing tho

#

why the drop shadow not showing in game view?

#

nwm it works now

pale python
#

hi ,
I have a dissolve shader that maks the object seem as if its broken
my question is , is it possible to make the shader also TRANSPARENT?
I have never seen a Transparent dissolve shader before but I wonder if its possible

modern delta
#

Btw, if you just want fully transparent for some parts and fully opaque for others, I would change your clip threshold to something like 0.5. Any alpha value below the clip threshold will be fully transparent, even in an opaque shader.

pale python
# modern delta Btw, if you just want fully transparent for some parts and fully opaque for othe...

the alpha value controls the dissolve function , let me show u
noise feeds the "step" and the other input is "position" which feeds the direction of the noise
the noise has a float value , 1 means no noise at all ( all white , apha = 1 ) , 0 means its full of noise ( all black = alpha = 0 ) , 0.5 gives a an image like the one u sees in this snap shot ( half the circle visable and the other is not )

#

so I dont know if there is a way to make the white part of the alpha a bit more "Grey" to make it transparent

frigid galleon
#

Job: Shader Artist

Requirements: Looking for a artist to create a shader that will visually show how airflow is affected by an object and its pose. The current pipeline is URP however it can be changed if needed. This is a constant flow of air with a body in different poses. This cannot be animated as the body is falling at different rates/angles. It does not have to be 1:1 realism but does need to show semi realistic airflow. Examples of the visual effect we are going for would be similar a wind tunnel, aerodynamic testing etc

From a programming perspective we have Vector3 points the 'air' starts from and then Vector3 'hit' points where it hits the bodies collider if these are useful. The particle system in unity combined with a shader may be an idea. The key point is it shows a visualisation of how air is moved as an object is free falling through it.

modern delta
#

But you need to make sure that your alpha clip threshold is lower than the alpha of the partially transparent stuff.

#

Or just turn off alpha clip

pale python
cosmic prairie
#

Easiest part is faking the direction the air flies off in, hardest part would probably be the vortices

quartz crypt
#

So Im controlling a Skybox with a shader and long story short (cuz this is confusing) I have a condition where it's controlled by a variable where if its greater than or less than, the shader switches Cubemaps by using SetTexture but I'm having a hard time actually DECLARING the thing in the code....

I've tried Material, Float, Texture, GameObject, none of it works

#

It always comes up Null or just not found

tame topaz
#

@frigid galleon Job posts go on the forums
!collab

echo moatBOT
meager pelican
quartz crypt
#

I'm just having a problem with labeling the variable, I don't even think that code makes sense

meager pelican
#

It's proper working shader code.

#

That's how you declare it in the shader.

quartz crypt
meager pelican
#

You mean the C# code, not the HLSL code?

quartz crypt
#

Yes

meager pelican
#

lol

#

OK

quartz crypt
modern cradle
#

hello do you know how to fix this

#

i use probuilder

lunar valley
modern cradle
#

sorry i didn't know where to ask

peak ridge
#

im trying to use a command buffer with draw renderer to write into a UAV in a pixel shader, but it writes nothing no matter what i do. would anyone know how to accomplish this or why it isnt working?
ive read all the forum threads on this subject and cannot get a single thing to work.

// the creation of the rendertexture in the c# script
paintBuffer = new RenderTexture(1024, 1024, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear)
{
  name = "Paint Buffer",
  enableRandomWrite = true
};
paintBuffer.Create();

// relevant part of the painting method which gets called
cBuff.ClearRandomWriteTargets();
cBuff.SetRandomWriteTarget(1, paintBuffer);
cBuff.DrawRenderer(rend, paintMat);
Graphics.ExecuteCommandBuffer(cBuff);
// How the RW texture is defined in the shader (using SM 5.0 and only dx11)
RWTexture2D<float4> _PaintBuffer : register(u1);

// All I'm trying to do for now. The texture res is 32x32 so this should be fine!
_PaintBuffer[int2(1,1)] = 1;```
meager pelican
#

THOUGHTS:
Is "rend" a full screen quad, or something the dims of the RT, or what? Does it cover the whole texture? You might want blit.
Do you write to multiple targets at once? If not, you can just "return" the value from the pixel shader to the render target if the rendering has that texture set as the active target.
I think you also need to call RenderTexture.active = paintBuffer somehow/somewhere.
Also maybe material.setpass(0).
Just some stuff to try off the top of my head, without actually doing it this way myself.

#

@peak ridge

#

You may also want a compute shader instead of vert/frag. It all depends on what you're doing.

peak ridge
#

hi! rend is a meshrenderer and the goal is to use its UVs for painting, so I can't use a compute shader for this.
and yes, i can use return with the shader targeting the rendertexture, but using that method i've been unable to sample the existing rendertexture inside of the shader and write back to it. the read into the shader comes up empty, which may be a symptom of the same problem. im not sure

#

ive never used RWTextures inside pixel shaders

#

regardless i did see some things online about being able to set the data of a RWTexture like this in the same manner you would do in a compute shader

meager pelican
peak ridge
#

im not sure what active render target has to do with it?

#

im trying to avoid adding another texture. i already have a method which pingpongs between two but it's clunky.

floral fox
#

hi. im new to shaders.
is it possible to find the closest pixel to the current pixel among the pixels with the light source?

peak ridge
#

youll need to create a distance field. jump flood would be the best approach

peak ridge
#

hopefully i understood your issue correctly anyway. if so, jump flooding is a bit complicated. id recommend reading this:

floral fox
#

thanks!

peak ridge
#

basically you're finding the shortest distances to the source uv coords by doing 8 samples in each direction, halving each time. this isnt a trivial shader, but best of luck!

meager pelican
# peak ridge im trying to avoid adding another texture. i already have a method which pingpon...

https://stackoverflow.com/questions/11410292/opengl-read-and-write-to-the-same-texture
You can't read and write to a FBO texture at the same time.
MAYBE you can in a compute shader, but not in a vert/frag....unless I misunderstand this or things have changed since 2012. Although there seems to be an exception by using special extensions, see post in that link, and here: https://registry.khronos.org/OpenGL/extensions/NV/NV_texture_barrier.txt

north karma
#

Is it possible to access Structured Compute Buffer in Shader Graph? Or I need to save the output in a texture?

meager pelican
# north karma Is it possible to access Structured Compute Buffer in Shader Graph? Or I need to...

"Save the output" means you'd render the result to a render texture. So that you can do.
Accessing a StructuredBuffer in a shader is certainly possible. In SG though, if it works at all it needs a custom function node. There's been some historical issues about getting so-called "compute buffers" bound to the shader's context. But that might be fixed now, IDK.
I'd google around for "StructuredBuffer" and "shader graph custom node"....be warned I've gotten mixed results on the google search, so you'll have to play around with it and see if it works for whatever version you're using.

#

Cyan or others may know if recent versions of SG bind the compute buffers correctly now. So basically you can write it with custom nodes, but it may or may not work depending on if the engine binds the resource. And I don't have that answer but the easiest way is to try it with a recent version.

peak ridge
#

im not writing to a framebuffer though?

#

and ive found a few forum posts of people saying theyve been able to do it but no code i can successfully duplicate.

meager pelican
meager pelican
peak ridge
#

you can read and write to the same texture, thats what an rwtexture is. it works fine in compute shaders. but thats not so much the issue so much as not being able to write into the texture at all via _PaintBuffer[index] = 1 in a frag shader
in the end i will be accumulating the previous results with the new results, yes.

#

in fact if i did _PaintBuffer[index] += 0.001 that should act as a basic accumulate as all threads write to the same location, but that doesn't work either

#

it seems to instead treat the texture as a local variable, even if specifying it as a uniform and doing the rest of the setup as directed by others

meager pelican
# peak ridge you can read and write to the same texture, thats what an rwtexture is. it works...

OK, I'll bow out and see if anyone else is more enlightened than me.
From what I understand, doing a same-texture read-update operation in a vert-frag shader is undefined.
This is because the GPU is massively parallel processing the pixels, and it cannot tell (at least not easily for a vert/frag type of operation) if some other core has updated the pixel before the read is done for "this" core. Since it can be written randomly, and it's not smart enough to know that the code logic is limited to its own pixel. So they'd clobber each other without sophisticated caching logic. And that's still a problem even in compute shaders so there's atomic operations do deal with contention issues.

So you can read the the texture, sure. You can write the texture, sure. But you will have problems both reading and writing the texture in the same operation. As I understand it.
Note that the open GL link mentions extensions that allow such. So it's probably theoretically possible.

But if all you need is the previous frames data, double buffering that stuff is (IMHO) the way to go. So you'd bind the last frame's result as a read texture, and the current frame's texture be output from that. May require a blit pass to copy the whole texture before you call the shader to do the mesh render update.

peak ridge
#

as far as how the approach works in compute shaders, if a thread reads from an index, does something, then writes back to the same index there is no problem since it only gets acted on once. i do this for a number of things across projects and its really useful.
you can read and write to the same index across threads but like you mention it has pretty undefined behavior. in the _PaintBuffer[index] += 0.001 i would expect to blow out to white very quickly, but instead when done in a pixel shader i get nothing at all. just a black texture no matter what and that doesnt make sense.

here's a link mentioning the correct way to bind an rwtexture to the pixel shader stage, which does not work for me.
https://forum.unity.com/threads/how-to-write-to-an-unordered-access-compute-buffer-from-a-pixel-shader.403783/#post-2941291

meager pelican
# peak ridge as far as how the approach works in compute shaders, if a thread reads from an i...

It looks like they're binding a RWStructuredBuffer, not a render texture. BUT maybe that should work, IDK.
In the case of indexing into the output, with a bound render texture, as I mentioned before, you'd return the result (the pixel index is already set in the rasterization stage, so you only have to "return the result for the pixel"). But that's if you're using vert/frag in the traditional way, and double buffering.

So others may know more than I or have done this, and I hope you get your answer. 🙂

peak ridge
#

thanks! hopefully ill solve it soon, usually just takes a bit of noodling and finding some right ordering of things. the way ive been trying to write things currently is by having a void frag shader so there's no return, just a direct write into the rt's index. i did try using a return but couldnt get reads to work.

winter basin
#

why is this happening with my tessellation? it gets more tessellated when i get closer but at around 10 metres it gets less?

peak ridge
#

its hard to tell just by looking at this but something about this doesnt seem like its being uniformly scattered

floral fox
#

yeah

#
 CGPROGRAM
            #pragma vertex vert_img
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float2 uv : TEXCOORD0;
            };

            sampler2D _MainTex;
            half4 _MainTex_ST;
            float4 _MainTex_TexelSize;
            int _StepWidth;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }

            fixed4 frag(v2f i) : SV_Target
            {
                int2 ipos = int2(i.uv.x * _MainTex_TexelSize.z, i.uv.y * _MainTex_TexelSize.w);

                float bestDist = 1.#INF;
                float2 bestCoord;

                UNITY_UNROLL
                for (int u = -1; u <= 1; u++) 
                {
                    UNITY_UNROLL
                    for (int v = -1; v <= 1; v++) 
                    {
                        int2 offsetUV = ipos + int2(u, v) * _StepWidth;

                        offsetUV = clamp(offsetUV, int2(0, 0), (int2)_MainTex_TexelSize.zw - 1);

                        float2 offsetPos = tex2D(_MainTex, float2(offsetUV.x * _MainTex_TexelSize.x, offsetUV.y * _MainTex_TexelSize.y)).rg;

                        float2 disp = i.uv - offsetPos;

                        float dist = dot(disp, disp);

                        if (offsetPos.y != FLOOD_NULL_POS && dist < bestDist)
                        {
                            bestDist = dist;
                            bestCoord = offsetPos;
                        }
                    }
                }

                return isinf(bestDist) ? float4(FLOOD_NULL_POS_F2.xy, 0, 1) : float4(bestCoord.xy, 0, 1);
            }
            ENDCG
#

this is the code

#

am i doing something wrong?

peak ridge
#

cant look super closely rn but are you running multiple passes of this?

floral fox
#

yes

#

i think i solved the problem

wild marlin
#

Why is my preview and the material different

deft quail
#

Did you save the asset ?

wild marlin
#

Thank u

#

im blind and

#

yeah

#

sorry

deft quail
#

don't worry

#

it happens to me often to lmao

stray wraith
#

Is there an easy way in shadergraph to blend the center of the 2 materials together, so its one color when they overlap?

lunar valley
stray wraith
#

How can I either mask the overlap or something else so it doesn't look like and just one solid color

stray wraith
lunar valley
meager pelican
stray wraith
stray wraith
lunar valley
stray wraith
pale python
#

hi, I made a cube and applied a whitish shader on it but for some reason some of it's sides are invisable
i mean when I look at the cube from above, i can see its inside with no top side at all , is this because im on the editor or is there is something wrong with it ??

#

in blender when this happens we just flip the norms , is this is what I need to do in unity ? I dont even know if we can do the same in unity

stray wraith
grizzled bolt
# pale python

Transparent and two-sided are probably the reason you can see the faces through itself
You'd see the same in Blender with backface culling disabled and alpha blended transparency enabled

meager pelican
grizzled bolt
#

We don't know what the goal is though

ocean bough
#

thinking its probably best I ask here instead
Im trying to make a toon shader and theres hundreds of instances explained doing it custom by code functions.

But in the URP documentation theres a node called Get Main Light Direction, popping up at URP 13.1.9. Nobody is mentioning this node but it sounds like exactly just that. Is it? cant find changelogs even mentioning it got added by unity either...
has anyone used it? trying to find what version of unity i can reach it but seems URP 13.1.9 isnt in any LTS yet

meager pelican
#

There's been custom function nodes doing that for years.
Is there a problem using it as described?

#

The odd thing is I don't see main light color

ocean bough
#

I keep hitting errors triyng to follow the examples and am not sure what im doing wrong, so started looking at this instead out of curiousity

#

yeah exactly and its not really including the attenuations either

pale python
#

but thanks for the help 😄

meager pelican
#

Yeah, but directional lights have an intensity (which could be factored into the color values) but no range, so no attenuation.

#

However I agree with your general observation.

pale python
regal stag
ocean bough
wary field
#

I have a background of a render texture. I am using Graphics.Blit(null, renderTexture, material) to render an electric-looking shader to the background. It appears to work at first, but it seems the "time" on the shader isn't getting updated. It shows the initial graphic, but never updates with time.

This is a simple shadergraph shader.

lunar valley
#

Hello I wanted to make some light reflections from the surface of my water and what I did was to simply make a specular highlight and then scroll a normal map on top of it. But it did not give me the results I was expecting..

icy oxide
#

How do people generally solve this issue in Unity? I made a shader w/ shader graph that gives a simple outline but it requires drawing outside of the sprite mesh. I can't use "Extrude Edges" in the texture because the sprites are part of an atlas.

lunar valley
icy oxide
lunar valley
lunar valley
dense flare
#

is there a way to use a gradient texture as a gradient for water depth in shadergraph?

dawn laurel
#

i'll try to summarize this better but basically I want to make a custom shader that makes a radial wipe so this circle (from sprite renderer) shows up like a loading bar, and so far the shaders i've found online have just not worked at all with what i'm trying to do

#

also i'm really not getting how to use shaders since i started out recently but this is basically pointing me towards the easiest solution

meager pelican
meager pelican
# dawn laurel i'll try to summarize this better but basically I want to make a custom shader t...

What pipeline are you using, are you using shader graph or hand writing shaders?
Try messing with conditionals based on the polar coordinates of UV. The Y value is the "amount around".
This video may be interesting to you:
https://youtu.be/rj129Wc1vyo?t=653
https://youtu.be/rj129Wc1vyo?t=1400

Being able to draw different shapes in a shader can be really useful to avoid having to use a lot of textures, make images that can scale in resolution without being pixelating like a texture would or make shapes that can be modified on the fly.
This tutorial shows the principles that can be used in any shader, but focuses on using ShaderGraph, ...

▶ Play video

Being able to draw different shapes in a shader can be really useful to avoid having to use a lot of textures, make images that can scale in resolution without being pixelating like a texture would or make shapes that can be modified on the fly.
This tutorial shows the principles that can be used in any shader, but focuses on using ShaderGraph, ...

▶ Play video
dawn laurel
#

like i said i just started and have literally zero clue what any of that means

#

i'll look at it anyways

#

okay i have no idea how to open the procedural shapes tab in the first place

meager pelican
dawn laurel
#

is all of this really the best solution for a radial wipe

#

at this rate i think a spritesheet would do better

grizzled bolt
meager pelican
karmic hatch
vague wolf
#

HI. If in fragment shader I want to calculate distance of pixel from a list of points, is there a better and more efficient way than saving an array of Vector2 as shader variable, populate and loop this array to calculate the distance of each pixel from these points? Thank you

meager pelican
# vague wolf HI. If in fragment shader I want to calculate distance of pixel from a list of p...

Well, it depends on the list and the pixel...and if they change per frame.
Otherwise you can cache the results, and only recalc when things change. This is basically a distance field you'd store in a texture or an array if you're only concerned about ONE location's distance to the various points.

I mean, you can make a per-item-per-light list in an append structured buffer or something.

It all depends on the DETAILS. How many? How often? Per item or per pixel? All pixels or just some?

#

Consider Forward+ 's ability to render many lights by building a "heat map" per pixel. Basically an acceleration structure built per pixel. This guy has a million small-range point lights:
https://www.3dgep.com/forward-plus/
Note that that's not Unity's implementation, it's C++, DirectX and HLSL, in 3D. But you get the point.

Comparing Forward, Deferred, and Forward+ rendering algorithms using DirectX 11.

vague wolf
meager pelican
#

Yeah, so sounds like you're dynamically looping through the point list, per pixel, per frame.

#

IDK what else to do. Maybe you can cache it if the camera doesn't move and points don't move. Other than that I can't think of an optimization off hand.

#

Acceleration structures MIGHT help you (calcing the range of the points and culling some that are out of range), but unless you have 50K points I wouldn't bother.

#

(not a literal number, but you get the idea)

meager pelican
#

But that would require atomics to increment pixel counts, so they don't clobber each other.

vague wolf
meager pelican
#

Not a particular fan of WebGL so, IDK. Haven't had much use for it at present.

vague wolf
stray rune
#

hi guys
may i make a 3d game with low graphics with dx11?
i guess i could use shader

#

i want to make a game with low graphics for low end pc

lunar valley
lunar valley
deft quail
#

Hey, I have a little question,
I have this shader with two property a float and a gradient. However in the inspector only the float parameter appears and not the Gradient

#

Is there anyway to make the gradient appear ?

lunar valley
deft quail
#

Oh

#

ok thanks !

stray rune
lunar valley
dense flare
# deft quail ok thanks !

You could use a thing i found on youtube tho i cant remember what the video was but it had a solution but the sub graph itself would take alot of space

stray rune
#

thats mean i can do that?

#

i thought its not supported

lunar valley
stray rune
#

i thought i cant do that with dx11

lunar valley
stray rune
#

because i dont know how to make shader xd

#

gonna learn to make shader

grizzled bolt
#

Graphics API is not something you have to worry about most of the time
If you're using dx11 exclusive features, then those won't be available on platforms or devices that don't support dx11

hasty depot
#

Heyyyy does anyone here have big brain for amplify shader editor

lunar valley
hasty depot
#

Alright alright

karmic hatch
hasty depot
#

well what i want to do is calculate a directional vector based on the brightness of the nearest light probes
then feed that into the lighting calculations instead of the realtime light direction

to get baked speculars

#

I have files of such a process yet I really need it for amplify for custom lighting

#

For built in

#

Standard pipeline

viral elm
#

hey folks )

I use unity 2020.3.7 urp and faced a problem of an inverted and messed up normal map when the prefab's scale value is negative, with static batching on

I see people complaining about it in the forums, but couldn't find a better solution rather than disabling the static batching

was this issue ever fixed in the further releases or is there another workaround?

dim yoke
# viral elm hey folks ) I use unity 2020.3.7 urp and faced a problem of an inverted and mes...

Thats quite expected because negative scaling will flip the winding order and therefore what was earlier front is now backface. Unity does some black magic (likely flips the culling side when the count of negatively scaled axes is odd) to make negatively scaled objects render correctly but its not going to work when static batching combines everything into single mesh and tries to render everything within single draw call (well, of course the triangle array could be changed to correct the winding for those negatively scaled objects but I dont think it is worth the trouble so unity didnt do that). Negatively scaled objects tends to cause all sorts of problems like physics going crazy and stuff so its noy recommended doing that anyway. Is there any way to achieve the same effect without scaling objects negative?

grizzled bolt
ember scaffold
#

Is there a way to make the unity toon shader register multiple lights?

viral elm
#

@dim yoke@grizzled boltthank you, guys, for the detailed explanation 🔥

as for
Is there any way to achieve the same effect without scaling objects negative?
perhaps mirroring the model with its collision and lods in dcc and importing to unity as a new mesh will do the trick

floral fox
#

hi. im new to shaders. i want to outline all but a few in the game. depending on whether the w value of color is 1 or not, whether or not the outline is covered is determined. however, i wonder why the particle is sometimes covered with an outline or not.

tacit parcel
fierce aspen
#

Is there a reason why _MainTex isn't working here?

deft quail
#

Did you give a texture to your MainTex (because in your screen it is set to None)

fierce aspen
deft quail
#

Ah yes indeed

#

It’s wierd

fierce aspen
#

resetting unity fixed it

#

lets go

toxic ore
#

Using Shader Graph. I have a white plane and want to place a red rectangle on top of it.

  1. How can I place the rectangle so that I can control its size and position on the plane?
  2. I couldn't find a straightforward way to just "place a rectangle on a plane" so I had to subtract from the white plane the rectangle with inverted colour. However, if I change the color of the plane, the color of the rectangle will change as well, as I am using Subtract . Any way to avoid using subtract and just render the rectangle on top of the plane?
grizzled bolt
oak aspen
#

is it at all possible to create a shader to add a blurred drop shadow (similar to the one in photoshop) to a sprite?

grizzled bolt
oak aspen
#

Also for clarity, i already have a border around the sprite using shader (using the copy top/left/bottom/right technique). So i figured if i copied that and somehow blur the border, it would be somewhat similar. But i'm not sure how the blurring bit would be achieved

lunar valley
lunar valley
warm crag
#

If I make a procedural mesh and define my UVs as Vector4s, what are Z and W components used for in the HDRP default Lit shader? It seems to be some sort of transparency situation, but I'm not really sure, and I can't find much by reading the shader code itself

lunar valley
#

uvs have two coordinates usually...

warm crag
#

indeed, but Unity allows you to specify Vec3 and Vec4 for them as well

#

I don't actually intend on doing this, btw. I'm teaching a lecture today on procedural mesh generation, and I want to go over why you might want to use this extra UV data, and I want to be able to tell my students what the default behavior is with the default HDRP lit shader.

#

(with the caveat that you should use vertex color for this first, as 4D uv coordinates isn't something you encounter in any other engine or 3D modeler that I know of)

cobalt totem
#

I'm not sure if this is a shader thing or a particle system thing, but when I have a mist particle system, the outline of my tornado goes completely white:

#

(Without the particles)

#

Ah nvm, there was a tint setting in the shader I didn't see

floral fox
gloomy gust
#

Hey guys, i downloaded this shader online that hides 2D sprites based off the amount of light incident to it. as you can see in the image, it does its job, but is there a way for me to make this completely transparent? it gets more transparent as it gets darker, and is completely transparent when its black, but that kind of defeats the purpose of the shader. anyone know how i can make it go transparent at this level?

#

this is the shader i downloaded, if it helps 😄

tight phoenix
#

What are possible reasons the scene prefab and preview prefab are lit so completely differently?

#

What can I do to make them one and the same? This discontinuity is making it exceedingly difficult to calibrate its appearance

tight phoenix
lunar valley
tight phoenix
tight phoenix
#

but in scene they are blindingly bright

#

and 'just do all your work in scene view' is not acceptable

#

doesnt play nice with instanced prefabs or viewing elements together and all sorts of other stuff

grizzled bolt
#

The thread seems to be only about the background color

reef osprey
#

Not really familiar with shaders so not sure if this is possible but is there a way to have a shader only execute when I want it to, rather then every frame? I got a blur effect shader but apparently it's super taxing, I only actually need to change the blur intensity every so often rather then every frame. The object that the material is assigned to never actually moves or anything. Is this possible? UnityChanThink

lunar valley