#archived-shaders

1 messages ยท Page 32 of 1

dense flare
#

Yeah no crap been trying to figure this oit for the past week

#

But tbh i actually might make one considering the lack/no tutorials about the topic

silk sky
#

I've made a simple lit shader to render pixel art on planes with alpha but I'm having some issues with light on back faces even if I specified to render both sides

grizzled bolt
#

So the backface just repeats the lighting on the front

silk sky
#

Do I have a way to fix that?

grizzled bolt
#

I think you can flip the vertex or fragment normal based on the Is Front Face node

silk sky
#

Is that possible using the shadergraph?

dense flare
regal stag
silk sky
#

Thanks everyone for the suggestions, I'm using Cyan's guide w/o normal map since its just albedo but I still got that effect ๐Ÿค”

#

the nodes seems greyed out (?)

grizzled bolt
# silk sky

Normal (Tangent space) is not being used since you set it to use world space, which you can see appeared at the bottom of the stack

regal stag
# silk sky

To be clear, there's two examples on that page. Depends if you're using a normal map or not. Here you likely want to connect it to the Normal (World Space) block and delete (or ignore) the Tangent one.

#

You'd need to change your current "horizontal wave plane" to also be vertical (or at least have a copy of it). Can have the bottom vertices of that match the viewport and not move, while the top ones do move.

That way you have pixels "below" that wave, that you can use to write to the stencil buffer. For that you can read through these :
https://docs.unity3d.com/Manual/SL-Stencil.html
https://www.ronja-tutorials.com/post/022-stencil-buffers/
If you're using Shader Graph, it doesn't support stencils. But you can use the RenderObjects feature in URP to override stencil values. I've got a tutorial here which kinda goes through it. The use-case is a bit different but should still be useful? https://www.cyanilux.com/tutorials/sprite-stencil-overlay-breakdown/
If you are using Shader Graph but in Built-in RP, then you may need to convert the graph to code and edit it (button in inspector on graph asset). Or completely move to shader code.

clear vector
#

Hi guys! If I have shader property's ID and this property is StructuredBuffer then how can I retrieve property name from shader? Is it possible?

silk sky
#

Thanks, fixed by changing Vector Normal space and Fragment Normal space to Tanget (got bit confused at the start cause in the image the node was set to world)

regal stag
#

I think I used stencil operations (also see my answer to ao above). It allows pixels to only appear where the values in the stencil buffer match the comparison.
I was rendering the water surface front faces and back faces with separate materials, so it was something like :

  • Write the waterline subdivided plane into stencil buffer (Ref 1, Comp Always, Pass Replace)
  • Render water surface (top), Cull Back & Stencil Ref 1, NotEqual
  • Render water surface (underwater), Cull Front & Stencil Ref 1, Equal
#

But rendering that waterline plane into a separate buffer is another option. By buffer I mean a Render Texture. (Can do this with another camera, URP renderer feature, or via ComputeBuffer / Graphics apis in C#. Kinda depends on render pipeline)
You can then sample that render texture in your water shader and alpha clip / discard pixels based on that. Also render an image effect (fullscreen quad) for underwater effects, again masked by that render texture.

silk sky
#

Have another issue, this time with the alpha, it seems that sometimes you can see through other objects (with same shader but different material)

regal stag
regal stag
clear vector
dense flare
regal stag
dense flare
regal stag
dense flare
#

I might do more research

dense flare
clear vector
# regal stag No, the IDs aren't used in the shader, just the property names. Unity assigns ID...

Maybe I wasn't clear enough, excuse me for my eng. I have no troubles with passing data to buffers. Also I name buffers with _. No problem with that at all.
I just trying implement EditorWindow where I want to display buffers names which I use in my rendering system. But I have only IDs not names so I searching for a way to retrieve StructuredBuffer name having it's id and shader to display name in the editor window. That is all. And it seems there is no way to do it.

regal stag
# dense flare Also wait does this also mean i can have a caustic texture thats moving and set ...

Yeah. It works a bit differently in blit shaders (likely as it replaces the view/projection matrices to ensure the quad stays on the screen), but it's still possible to reconstruct the world position from the depth. Something like : https://www.cyanilux.com/tutorials/depth/#blit-perspective

Otherwise if you manually place a quad on the camera plane, or just use this subdivided quad & stencils, then you can likely use this simpler method :
https://www.cyanilux.com/tutorials/depth/#mesh-perspective

dense flare
regal stag
clear vector
# regal stag Okay I *kinda* get it now... I don't think there's a way to get the name from th...

Yes, but in my system same buffer may be registered multiple times so I have method overload for passing both name or id, and user can store buffer names/id however he wants so I can't predict name. Though it isn't very important thing in performance terms so I can just remove possibility to pass ID and let just pass strings only to be able to save them only in editor and show in window. Still sounds like extra data for view layer which not great for me

subtle thicket
#

Hi, I'm trying to add a 'moving noise' type of effect to my outline. Sort of make the outline more interesting. Doesn't seem to be working at all though. Anyone know what's wrong?

low lichen
subtle thicket
#

(as it stands, if 'outlineNoiseMovement is above 0 it colors the sprite itself, otherwise it does nothing)

amber saffron
subtle thicket
amber saffron
#

Try multiplying the noise with the outline color.
Or add safeguards (like saturate) to some of the nodes, as I suspect that you have negative values inside the sprite shape.

subtle thicket
#

you mean multiply rather than add?

low lichen
# clear vector yes

Then you can do a brute force search for the right property by using Shader.GetPropertyCount and Shader.GetPropertyName/Shader.GetPropertyNameId.

amber saffron
clear vector
sick knot
# regal stag You'd need to change your current "horizontal wave plane" to also be vertical (o...

while the top ones do move.
Thank you, but what in what way do you mean that the top ones would move? If I place the Waves script onto a plane that I then orient vertically, then its motion doesn't match the intended waterline motion
edit: If you mean to change the waves script to affect the top of a plane that is oriented vertically, I currently don't really know how to target the top of a plane's vertices in that way, but also I think my water system requires a horizontal plane to work properly with swimming logic.

subtle thicket
#

So it seems to work except for the fact it's also affecting the inner sprite (not just the outline)

#

K I got it. Had to subtract the inside area again

#

Nvm same problem. Omg I hate shaders

regal stag
#

Also no idea why a horizontal mesh would be required for swimming logic but this could be a separate plane just used for visuals.

toxic marsh
#

Hey guys, i got this part of the shader for displacing vertices. It looks like a ocean, tho the normals seem to just point upwards on the plane. How do i recalculate the normals based on this?

#

Every bit of help appreciated

#

Better Image

#

Tried this and another method from a video with gerstner waves, but cant get it to work:

https://www.youtube.com/watch?v=arCHjoQHgEU&t=661s

Fix up normals in your Shader Graphs after manipulating vertices!

In Shader Graph, you can move your vertices around, causing your model to take on a new shape. This will often cause the normal vectors to be incorrect, which will ruin your lighting. In this video I'll cover how to fix your normals all within shader graph.

The math is a bit co...

โ–ถ Play video
regal stag
# toxic marsh Hey guys, i got this part of the shader for displacing vertices. It looks like a...

There's a Normal From Height node which is a quick (and likely cheaper) way to calculate normals. (It uses screenspace derivatives (ddx/ddy) which is possible as fragment shader runs in 2x2 pixel blocks, but this means the resulting normal is a bit pixellated too)

Otherwise you'd need to simulate some neighbouring points, offset those and cross product with the differences. Looks similar to this video though I feel they're overcomplicating things a bit. The method I'm more familiar with is :

float4 modifiedPos = Position;
modifiedPos.y += displacement(modifiedPos);
            
float3 posPlusTangent = Position + Tangent_Vector * 0.01;
posPlusTangent.y += displacement(posPlusTangent)

float3 posPlusBitangent = Position + Bitangent_Vector * 0.01;
posPlusBitangent.y += displacement(posPlusBitangent);

float3 modifiedTangent = posPlusTangent - modifiedPos;
float3 modifiedBitangent = posPlusBitangent - modifiedPos;
float3 modifiedNormal = normalize(cross(modifiedTangent, modifiedBitangent));

(based on https://www.ronja-tutorials.com/post/015-wobble-displacement/)

toxic marsh
#

Thx for the mega detailed answer, i think ill try the normal from height. Tho i am confused with its inputs, i am probably not able to just plug my height in there since it takes an int?

regal stag
toxic marsh
#

Oh yeah i see

#

Whoops
aight now i just need to figure out how to use it

#

The out definately does not connect to vertex normal

regal stag
toxic marsh
#

Hmm
So to change the vertex normal id need to use the code you provided?
Sorry if i talk nonsense and dont get all of it, im basically using tape and nails to hammer my project together...

regal stag
toxic marsh
#

Rip, code to node is my worst enemy

#

Thanks for the help tho, ill try all of it to get to the result i am looking for

#

Would i be able to paste the code you provided into the generated shader?

#

Ah nah forget about that it has 8000 rows

regal stag
# toxic marsh Rip, code to node is my worst enemy

I converted an example to nodes,
I think one thing I didn't make clear is the displacement needs to be based off the modifiedPos/posPlusTangent/posPlusBitangent (labelled as Vertex Pos, Neighbour T, Neighbour B in graph)
In your case your noise is sampled using the Position for example. You'd need to copy that "displacement sample" section an extra 2 times and swap that Position out for these Neighbours. If Absolute World space is required, can use Transform nodes first to convert between spaces.

#

May be a good idea to move the displacement calculation to a SubGraph since it needs to be handled 3 times.

toxic marsh
#

so just plug the things i am calculating into what you did at vertex pos?

toxic marsh
#

ahh so basically my stuff needs to be inbetween where displacement is?

#

i want it to be world based so i can make my ocean move with the player easily for performance reasons

regal stag
toxic marsh
#

And the displacement would basically be the heightmap scrolling?

regal stag
#

Yea

toxic marsh
#

I shouldve stayed in school instead of becoming solo indie dev

#

Aight ill try my best

toxic marsh
#

Ok i was too lazy to put it in a subgraph because i wanted to see it work, but now my plane just goes invisible and i also think the normal should not just be pink

regal stag
#

Like you still want the Vertex Pos, Neighbour T and Neighbour B in the A ports on those 3 Add nodes on the right. But the B input would be your displacement.

toxic marsh
#

aight its all stretched out, but at least its not invisible anymore

#

Also seems to deform only on one axis

regal stag
toxic marsh
#

It works now, just jittering very bad

subtle thicket
#

Is there any difference between saturate and clamp?

toxic marsh
#

saturate will always be between 0 and 1, clamp will do between your own set values so they cant exeed if i am correct

subtle thicket
#

I don't really understand why putting or removing a saturate node from specific places can have such a dramatic effect

#

Right now my saturate nodes are preventing the HDR colors from glowing, but if I remove them then the shader gets borked

toxic marsh
#

Maybe use Emission?

subtle thicket
#

emission is something different?

toxic marsh
#

Nvm then, am shader noob anyways

subtle thicket
#

as far as I can tell, you need to use saturate anytime two operations are used back to back, like add + subtract, or multiply + add, or multiply + multiply

toxic marsh
#

Ahh probably need a higher resolution displacement map maybe

#

Nah that wasnt it

heady horizon
#

Does anyone know why my plane is purple? I've been trying to figure this out for 30 minutes

#

Here's the shader that's being used, I'm guessing the issue is something else though

#

Actually, I've just tried offsetting the vertices and that hasn't made any noticeable changes, so it seems like it is my shader code

regal stag
# heady horizon

Magenta typically means there's an error when compiling the shader, or the current render pipeline does not support the shader. (Or the platform doesn't support the shader, though that's more in builds)

#

Usually the console or inspector when shader asset is selected will show error messages

#

If there's none it's probably the render pipeline. Is this URP/HDRP? As that doesn't support surface shaders. Only vert/frag, or shader graphs.

heady horizon
#

It wasn't when I first witnessed this issue, then I tried switching to URP and it didn't help

#

I've switched it back to none now, but the issue persist

#

I'm going to try creating a new project where I make sure I select the normal RP and see if that helps

barren quiver
#

You can convert the material from built-in to URP, if that doesn't work the issue must be in the HLSL script

heady horizon
#

Side tangent here, but aren't surface shaders written in unity shader code?

#

Or do I have that wrong

regal stag
#

The converter only works with built-in shaders. It won't work for custom ones.

regal stag
heady horizon
#

Right, that makes sense

regal stag
heady horizon
#

Ahhhhhh I got it to work

#

Yeah, something weird was going on with the other projects RP config, I just made a new project ensuring that I selected the normal render pipeline

regal stag
heady horizon
#

Thanks for the help Cyan, Alda

#

For future reference, am I able to write surface shaders in URP or HDRP under any circumstance? If not, are there alternatives?

regal stag
heady horizon
#

Okay, cool

#

Thanks for the info!

dense flare
# toxic marsh

I had the same problem but i dont think i could help since my ocean waves are in hlsl or a custom node and all the other effects are in shader graph

#

But u could try adding a negate node to one of the noise textures

tacit parcel
tacit parcel
subtle thicket
grand jolt
#

yo im extremely new to unity but I have a question. so recently, I bought a shader pack from the asset store, "Skybox Extended Shader" By BOXOPHOBIC. I've been searching for a few hours on how to apply shaders but can't find out how. Do you have to make it a script and apply it to the camera?

chilly lava
#

Hello! I'm new to shader graph, i'm trying to make this water shader's foam move in same direction on all tiles (3d), how can i do that?

white cypress
rare wren
dense flare
#

im fairly new to rendererfeatures and i need hel! why does this give me an error?

dense flare
#

oh thank you

amber saffron
#

cmd.Blit( source, dest, mat)

dense flare
#

i just want to get the scene color

#

but only see a layer i set it to

dense flare
amber saffron
#

Do you need a renderer feature for this ?
Shadergraph has a scene color node

dense flare
dense flare
dense flare
amber saffron
#

I don't have the full context of what you are trying to achieve and what technique you want to use, there is probably multiple solutions for doing a waterline effect

amber saffron
#

Like I said, Cyan is listing multiple techniques here

#

I think you are trying to render a waterline mask in a dedicated texture, right ?

dense flare
amber saffron
#

I have nothing on top of my head else than the official doc

#

But seems like the workflow would be :

  • Create a temporary mask RT
  • Assign it as active RT
  • Render the waterline mesh in the mask
  • Set active RT to null (so, screen)
  • Render a fullscreen quad with the mask RT as input
dense flare
# amber saffron But seems like the workflow would be : - Create a temporary mask RT - Assign it...

oh ok! thanks! also i found this! https://www.youtube.com/watch?v=R9MoyEOdmeA im gonna try your idea with this too! thanks my man

In this video we will create a Pixelart effect in Unity by apply it as a post-processing (custom shader graph) to the camera image using a custom render feature in URP

Learn C# for Unity by making games - My Unity video courses:
https://courses.sunnyvalleystudio.com/

Github Scripts
https://github.com/SunnyValleyStudio/unity-URP-Pixel-Effect-Po...

โ–ถ Play video
dense flare
#

why do i get this error?

#

@amber saffron

amber saffron
#

Well, one of the arguments to the method is null when it should not, or the object calling the method itself is null.

dense flare
# amber saffron Well, one of the arguments to the method is null when it should not, or the obje...

public Material material;
public RenderPassEvent passEvent;

class WaterLineRenderPass : ScriptableRenderPass
{
    Material Wmaterial;

    RTHandle tempTexture, source;

    public WaterLineRenderPass(Material mat) : base() 
    {
        Wmaterial = mat;
    }

    public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    {
        source = renderingData.cameraData.renderer.cameraColorTargetHandle;
        tempTexture = RTHandles.Alloc(new RenderTargetIdentifier("_TempTexture"), name: "_TempTexture");
    }

    public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    {
        CommandBuffer cmd = CommandBufferPool.Get("WaterLine Buffer");

        RenderTextureDescriptor textureDescriptor = renderingData.cameraData.cameraTargetDescriptor;
        textureDescriptor.depthBufferBits= 0;
        cmd.GetTemporaryRT(Shader.PropertyToID(tempTexture.name), textureDescriptor);

        Blit(cmd, source, tempTexture, Wmaterial);
        Blit(cmd, tempTexture, source);

        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }

    public override void OnCameraCleanup(CommandBuffer cmd)
    {
        tempTexture.Release();
    }
}

WaterLineRenderPass m_ScriptablePass;

public override void Create()
{
    m_ScriptablePass = new WaterLineRenderPass(this.material);

    m_ScriptablePass.renderPassEvent = passEvent;
}

public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
    renderer.EnqueuePass(m_ScriptablePass);
}
amber saffron
#

I recommand to using VS debuging to debug the error line and identify what is null

#

But all this is slowly getting out of subject for this channel

dense flare
#

how can i stop warping for world space from depth?

amber saffron
karmic hatch
#

^

regal stag
#

I always use this,
But if you're in newer versions of SG you'll want to use the View Vector node instead, as View Direction is already normalised now in URP

dense flare
supple pendant
#

Hi, I have a problem with my enum setup. Basically, when I change enums manually through the inspector the shader changes accordingly but when I try to change it through code and through UI although I see the enum actively changing in the inspector the shader doesn't react as it should. Is that a bug or I am doing something wrong?

amber saffron
#

How are you changing that Enum ?

regal stag
#

Would need to use material.DisableKeyword & material.EnableKeyword

supple pendant
#

It's set up like this in the code basically

if (dropdownValue == 0)
{
m.sharedMaterial.SetFloat("_COLORBLINDNESS_MODE2", 0);
}

supple pendant
regal stag
# supple pendant Do I enable the keyword on value change?

Yeah, you need to disable the other keywords and enable the one you need. I don't know what strings your enum is using but it could be something along the lines of :

Material material = m.sharedMaterial;

// disable all
material.DisableKeyword("MYENUM_OPTION1")
material.DisableKeyword("MYENUM_OPTION2")
material.DisableKeyword("MYENUM_OPTION3")

// enable specific
if (dropdownValue == 0){
  material.EnableKeyword("MYENUM_OPTION1")
}else if (dropdownValue == 1){
  material.EnableKeyword("MYENUM_OPTION2")
}else if ...

Probably should continue updating the float too, so the inspector changes along with the keywords.

supple pendant
#

I will try that now, thank you

regal stag
#

The keywords will be {REFERENCE}_{REFERENCESUFFIX} so in the case of the example above, the Enum Keyword reference would be MYENUM and suffix of each entry OPTION(n)

supple pendant
#

It worked, thank you so much my dissertation is saved I was literally trying to figure it out for two days lmao

sacred stratus
#
public void Test()
    {
        collectBuffers = new List<Vector3d[]>(reps);
        for(int i = 0; i < reps; i++)
        {
            collectBuffers.Add(new Vector3d[bufferSizeSqrt*bufferSizeSqrt]);
        }

        computeBuffers = new List<ComputeBuffer>(reps);
        for(int i = 0; i < reps; i++)
        {
            
            int kernel = i;
            computeBuffers.Add(new ComputeBuffer(bufferSizeSqrt * bufferSizeSqrt, sizeof(double) * 3));
            shader.SetBuffer(kernel, "Result", computeBuffers[kernel]);
            
        }
        for(int i=0;i<reps; i++)
        {
            int kernel = i;
            shader.Dispatch(kernel, 64, 1, 1);
        }
        for(int i = 0; i < reps; i++)
        {
            int kernel = i;
            computeBuffers[kernel].GetData(collectBuffers[kernel]);
            computeBuffers[kernel].Release();
            Debug.Log(collectBuffers[kernel][5].ToFloat);
        }
        




    }

I wrote this code that is supposed to dispatch a computeShader at multiple kernels, but it only works with the first kernel and the other ones crash
I get following errors "Kernel index (1) out of range" and "TestShader.compute: Kernel index (1) out of range"
It would be amazing if someone could help me understand why my code is giving me an error

digital gust
sacred stratus
#

I thought there where infinite kernels as long as my Gpu doesn t run out of threads, I thought kernels are like different instances of the compute shader
Am I wrong?

sacred stratus
#

Can you explain to me what a kernel is?

digital gust
#

A kernel is basically a function/operation that is handling the operations

sacred stratus
#

okay so it s not like an instance of the compute shader?

digital gust
#

the compute shader holds the kernels

sacred stratus
#

yes so if I dispatch kernel 0 the function gets dispatched at kernel[0]?

digital gust
sacred stratus
#

thanks tho

digital gust
#

If I remember anything, I let you know, but for now I rather stick to official docs to not talk nonsense here ๐Ÿ˜„

echo ruin
#

I'm having what I think is some beginner problems using 2d urp shadergraph ๐Ÿ˜…

#

I've got an area of text that I want to pass noise over in a particular direction, but I really just can't figure out how to make it move in any direction other than top right to bottom left - But I want it to move straight up

regal stag
echo ruin
#

That's not quite creating the desired effect, but I wasn't even using tiling and offset ๐Ÿ˜…

#

I'm a complete noob so I'm probably just misusing a node

#

This is my whole graph

#

It's all pretty small idk if you can see any of that

#

And ty for responding by the way ๐Ÿ˜“ ๐Ÿ™

#

I've been stuck trying to achieve this one effect for days now

#

AHA I got it!

#

New graph ๐Ÿ˜Ž

#

Thank you @regal stag !

#

You lead me to explore the UV nodes

#

I'm gonna cut down on some of this logic that I see is extraneous and get back to work. I appreciate it :)

chilly lava
grave meteor
#

Hi all. I have two squares made with compute shaders. One looks good, the other looks derp. For one, I used a standard rectangle collision formula. For the other one, I tried to do something fancy like "if the distance from the center is shorter than the distance to the edge, color the point blue, else black". I don't really know how to debug the values on the compute shaders, does anyone have any idea from the code why the second one might be derp, all other things equal?

float inSquare( float2 pt, float4 rect )
{
    float horz = step(rect.x, pt.x) - step(rect.x + rect.z, pt.x);
    float vert = step(rect.y, pt.y) - step(rect.y + rect.w, pt.y);
    return horz * vert;
}

[numthreads(8,8,1)]
void GoodSquare (uint3 id : SV_DispatchThreadID)
{
    float res = inSquare(id.xy, Rect);
    Result[id.xy] = float4(0.0, 0.0, res, 1.0);
}

[numthreads(8,8,1)]
void DerpSquare (uint3 id: SV_DispatchThreadID)
{    
     const int halfRes = texResolution >> 1;
     const int sideLength = halfRes >> 1;
     const float x2 = (float)id.x;
     const float y2 = (float)id.y;
     const float x1 = (float)halfRes;
     const float y1 = (float)halfRes;
     const float alpha = atan((float)(y2 - y1) / (float)(x2 - x1));
     const float possibleX = abs(sideLength / abs(cos(alpha)));
     const float possibleY = abs(sideLength / abs(sin(alpha)));
     const float rMax = min(possibleX, possibleY);
     const float h = length(id.xy-float2(halfRes, halfRes));
     Result[id.xy] = float4(0.0, 0.0, step(h, rMax), 1.0);
}
pure fulcrum
#

I'm trying to store the previous frame as a texture2d for a post processing effect (birp), is there any way to write to a pixel on a texture? or do I need to set it thru a c# script

rare wren
#

@chilly lava just set a vector 3 direction?

amber saffron
dense flare
#

still does the same .-,

amber saffron
#

Erm, yes, was wrong : View Vector in View space (to have Z aligned with the camera), and after the division, transform to world space

amber saffron
#

I'm a bit lost in my maths now, else you can try Cyan method that probably works ๐Ÿ˜…

leaden zinc
#

anybody knows how to shadergraph this?

#

its blender

digital gust
leaden zinc
digital gust
leaden zinc
#

that part is supposed to be a basic toon shade

#

the rest of it are gradients and stuf

digital gust
#

Oh, you should google for toon shader on youtube, thats like full of tutorials about a toon shader and outline shader

leaden zinc
digital gust
leaden zinc
amber saffron
#

You can't do this in shadergraph with 3 nodes

#

Basically, the "Diffuse BSDF" is already the result of the shader, and you want to apply modifications to the final shaded color (shader to rgb > color ramp).

To do the same in shadergraph, you have to do your own custom lighting

leaden zinc
#

yeah understood

dense flare
#

how can i stop this from happening?

#

it goes althe way to the skybox

digital gust
dense flare
#

default*

digital gust
dense flare
digital gust
dense flare
digital gust
dense flare
#

im using world pos from depth

regal stag
digital gust
#

you might have to clamp it at some point, like cyan says to a value you can get like the far plane

dense flare
dense flare
regal stag
dense flare
dense flare
regal stag
#

I'd look at WaterLineBuffer.cs:34 as that's mentioned in the error stack

dense flare
dense flare
#

sorry im new to renderer features ๐Ÿ˜ฆ

#

ok what is going on now its not givving me an error

dense flare
teal ravine
#

does anyone know how i can edit a shader to work on both eyes on singlepass (vr)

sly steeple
#

Compute Shaders - Only two workgroups seem to be activ

Hello I am working with compute shaders for the first time experienting weird behaviors I dont understand:
The Kernel above has 8x8x8 Workgroups so after excecution of the shader I am expecting to find 8x8x8 = 512 distinct values inside the buffer; instead the buffer is filled with 8x8 = 64 distinct values while the other 448 values are 0.

I am in at almost two hours researching why this is behaving as it does and I am totaly clueless at this point. Is there something I simply missed or am I understanding sth fundamently wrong?

shadow locust
sly steeple
#

pointsPower3 is 8ยณ

#

the results above are the numbers I find in the NoiseValue Array

#

all those other variables are not having an effect at the moment, as I am not using them since I am trying to track down the problem

#

*I mean the shader properties

low lichen
sly steeple
sly steeple
#

so i am assuming only one of the three workgroups is working ?

low lichen
#

Is there any difference if you change all the ints in the shader to uint?

sly steeple
#

putting 64, 1, 1 in dispatch for example gives me 512 distinct values

sly steeple
sly steeple
low lichen
sly steeple
#

Nvidia GeForce GTX 960

jade ginkgo
#

An asset from the store is running with Rendering Thread Time of 1.3 ms in a URP project and 0.3 ms in a Core project. The shader is clearly not URP (it's using CG). Would converting the shader to using the URP/HLSL likely improve the rendering time? The shader ... runs, but it's not functioning entirely as it's supposed to. (apologies, I'm a shader noob, just trying to understand if I'm on the right track)

grave meteor
#

My brain is not awake enough to divide out the permutations to see if 512 would resolve to 64 unique indexes or not

sly steeple
#

for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
for (int z = 0; z < 8; z++)
{
Debug.Log(x+8*(y+8*z));
}
}
}
This how you get all permutations

tranquil vale
#

I use unity 2022.2.2f1 and I don't understand where can I create shader graphs? This is the only what I have in create->shader

amber saffron
tranquil vale
amber saffron
amber saffron
#

Shadergraph is now (somewhat) compatible with the build in pipeline, but you might want to install the universal render pipeline instead (no need to have both SG et URP, only URP is enough as SG is a dependency)

tranquil vale
#

I just thought it's like built in feature to use without installing something

sacred hull
#

I want to make something like this from Bowser's Fury. The object is invisible until the player gets close. Only the parts of the object that are close to the player are visible. How would I accomplish something like this (preferably with shader graph)?

#

P. S. There is also backface culling

sly steeple
grave meteor
sly steeple
#

I spend most of my day on this now and I am getting super frustraded cant find any usefull information anywhere

sacred hull
#

So the far away parts are invisible

amber saffron
sly steeple
sacred hull
amber saffron
#

I don't have any handy, search for some terms and you might find some : distance mask, alpha clip, distance dissolve ...

sly steeple
#

@sacred hull One other option I could think about is never to render the object and instead render a simple mesh in front of the object whenever the player get close enough. That mesh could have that hex texture and move with the player

sly steeple
low lichen
sly steeple
sly steeple
grave meteor
sly steeple
grave meteor
#

I've been struggling to debug

#

doing all the math by hand

sly steeple
#

you can write the thread indicies directly into the buffer

grave meteor
#

what is the value of pointsPower3 in your code?

sly steeple
#

8 to the power of 3

grave meteor
#

ok well one thing that strikes me is you might have too many indexes

#

so you are dispatching with 8,8,8 and num threads is 8,8,8

#

so that means you're going to have 8^6

#

I think, either that or 2*8^3, let me look it up

sly steeple
low lichen
sly steeple
#

it does not matter what i am putting into dispatch except for the first number (that screenshot is a bit misleading)

grave meteor
#

also maybe dumb question but I'm used to seeing this:

_generateFractalNoiseHandle = shader.FindKernel("GenerateFractalNoise");

you are pretty sure that's 0?

sly steeple
grave meteor
sly steeple
sly steeple
low lichen
sly steeple
#

they seem to be up to date but I am updating windows now we will see

#

@grave meteor @low lichen Thanks for all your help I did a windows Update and now it works, there goes a whole day of my life. Some days I really hate programming grrr

grand jolt
white cypress
grand jolt
grave meteor
#

It's like it's going in groups of 10 for some reason and I'm not really sure why

#

oh wait, I'm an idiot

#

there's some nuance there

sly steeple
#

so looks good ?

grave meteor
#

yeah everything good I was just trying to replicate your code to try and help with the issue, but I'm new to ComputeBuffers and HLSL

#

Learned a lot today!

sacred hull
sly steeple
tight phoenix
#

I am using world/object positions to wrap textures on meshes and I ultimately want to use this to make this kind of 'stepped' appearance in the normal map
How do I correct the normal texture values so that they are always going the correct direction?

#

better example

#

the normal looks right at the start, but when I rotate it, the normal doesnt rotate so it becomes wrong, ideally I want it to rotate with the mesh's surface angle

#

I know the sollution will involve something to do with the object surface normal and a dot product of the world normal vector probably

#

but I don't know how to reach that sollution

#

like if this were to be a circle instead of a line, I can't just rotate the red channel

#

something like this is what I am trying to achieve, where it has normal mapped edges based on height, that light correctly

#

i've tried texture based and procedural based and neither has given me the desired output

#

because I am too inexperienced, not because the techniques dont work or are impossible

#

getting stepps is easy but I can't generate a normal map from them that doesnt look like un-antialiased dogshit

#

How do I combine these two outputs into a UV channel that will wrap that normal map around the contour lines?

sacred hull
#

How can I set a value of the shader from a script? The following didn't work:

floorMaterial.SetVector("Player Pos", new Vector4(transform.position.x, transform.position.y, transform.position.z));```
tight phoenix
#

which is probably something like _Player_Pos

tight phoenix
#

I dont know regular shaders but shader graph has the reference as pictured there ^

tight phoenix
#

closer-ish but its still rendering wrongly at weird angles

#

and for some reason doesnt work at all on a cube

#

this is totally different math but same result

#

im orbiting around getting it perfectly right

#

but I dont know what I am doing wrong to correct it to get it rigght

#

can you help? I won't be abkle to get this on my own

#

better but not better

#

what do I do in order to wrap the normal around the mesh?

#

giving up for now here, I cannot solve this without help and no one seems to be around

sullen fox
#

I am making waves, depending on the height of the waves it should change color so i give it a better overall apperence, So what i am trying to do is blend the colors with a lerp. Like this

#

but the result i get is

#

The green is the second color and should only be on the top of the wave instead it comes in a pattern of stripes

sacred hull
#

Is it possible to make loops in shader graph?

#

Like a for loop

#

So I have this shader that uses a vector3 position to do a "reverse dissolve" effect. Right now this only works with one object's position. How could I expand it to work with infinite objects? fx. bullets, multiple players, etc.

grizzled bolt
sacred hull
sacred hull
grave meteor
north karma
#

Compute Shaders vs Custom Render Textures.

What are the differences between these two approaches? Because I can see only one, CRT works on all mobiles, but ComputeShaders only work on compute-capable mobiles.

#

If I want to create for example a plexus effects, it is possible with both approaches. So I don't see benefits of using compute shader instead of storing and processing all the data in a texture.

As far as I know you can't use Dictionaries there, so for hashing you need to implement your own system. And they for mobiles looks like the CRT is better.

Am I wrong, or missing something important?

tiny lynx
#

this might be a simple or really complex question but I just dont know, how would I loop through every face on a mesh, and then check the texture ( in this case, a render texture ), and if the triangle contains a specific color, run code that inverts the normal of that face ( which effectively 'hides' the face )

tiny lynx
#

im very new to shaders in general so ive got no idea what im doing

tacit parcel
tiny lynx
tacit parcel
#

I might be wrong, but I don't think it's achievable on fragment or surface shader since they work in fragment level
It might be easier to do that by script(c#) instead

tiny lynx
#

when i asked how to do that by script i was told to do that by shader

#

bc its not possible to 'hide' a specific face on a mesh without shaders in an efficient way

tacit parcel
#

'hide' a specific face on a mesh without shaders in an efficient way
Yes, this could be done by shader
but
loop through every face on a mesh, and then check the texture ( in this case, a render texture ), and if the triangle contains a specific color, run code that inverts the normal of that face ( which effectively 'hides' the face )
this could be far easier if done by script

tiny lynx
#

how tho

tight phoenix
# tight phoenix

Im still trying to make this work but Im just circling the drain on my own, making no progress.
Still trying to contour a mesh with stepped normal mapped ridge lines

#

it works in object space sorta but I need it to work in world space, and it just cant make the transisition without completely fucking up

#

its a struggle to debug ANY part of it

jade ginkgo
#

Are there any tutorials or resources for how to use a shader to dynamically transition from one texture to another? For a 2d grid with blended transitions from grass to dirt (or sand, or water, etc.).

tight phoenix
#

except it doesnt work in object space either really

#

its just completely nonfunctional and hours of my day have been wasted trying to get it working when I know anyone competent with the free time could solve it in 10minutes :/

white pine
#

I am using URP. I cannot figure out why no matter what I do the preview and view in actual game is pink, even when it is just the default shader graph

tight phoenix
#

why isnt this effect centered?

#

its clearly centered on the left but when it gets used, its offset by like 50% downwards

#

how do I orient this texture away from the pole

#

I want it oriented from the slope angle

#

working fine in one direction

#

but as soon as you rotate it, it stops working

#

expected behaviour: slope remains stable fall down

#

I need it to not do that

#

its doing that because im projecting the texture against its side on a single axis

#

because I dont know how to wrap the texture around it uniformly from all directions

#

how do I uniformly project a texture around a mesh from all directions in order to get stepped height contour lines?

#

I NEED this solved but I can't do it myself and I can't seem to find any help

#

ill try back later i guess, all I can do is repeat the same thing over and over and over until someone helps me

twin sun
#

I'm having trouble with a pixel perfect shader, anyone willing to take a look?

#

the problem is that when I round the UVs to pixels, it works fine

#

however, if I want to offset the UVs by a sub-pixel amount afterwards it doesnt seem to work

vague wolf
#

Hello everybody. If I set two world space coordinates to a shader, in the fragment how can I calculate the line of pixels connecting the two coordinates? Thank you.

lunar valley
#

or fix your uv maps

lunar valley
twin sun
twin sun
#

the part where I want to offset the UVs is where the add is

#

its set to 0 in the image

#

but the idea is that if i offset the UVs by a small amount, the entire screen should shift a small amount

#

but its only able to shift in large pixel increments

#

large pixel being the pixelized resolution, which is 4x smaller than the actual resolution of the screen

#

so each large pixel is 4x larger

#

or made of 2x2 actual pixels

lunar valley
twin sun
#

to downscale the entire screen for a pixel perfect effect

lunar valley
twin sun
#

yeah

#

so in the second image if i get rid of the floor node

#

it works fine, and can offset by small amounts

lunar valley
twin sun
#

then this rounds each UV to the nearest "pixel"

lunar valley
twin sun
#

doesn't that do the same thing?

#

The texture i'm sampling is the screen color texture, which is 1920x1080

dense flare
#

can someone tell me whats wrong? it shows the the skybox is blue but not he geometry? it will only show it blue if the camera y value is < 0

amber saffron
#

@tight phoenix
Am I wrong to say that you want a shader that makes "height steps", on any give geometry ?
This will probably be very hard to do with regular UV texturing.

However, you could so some trickery with shadergraph provided nodes to manipulate the object normal.

Take the object Y world position as input, and make it a sawtooth wave to have looping black/white gradients.
Use this to scale the Y value of the world normal.
Apply this back to the object normal, and you should have something that looks like what you want.

dense flare
amber saffron
#

??? erm, my message was for an other question, not your water effect ๐Ÿ˜…

dense flare
#

features*

amber saffron
#

iirc, yes

dense flare
#

?

amber saffron
tacit parcel
amber saffron
#

@tight phoenix Here's a simple graph I made based on what I said :

sand ginkgo
#

Hi, whenever I connect Texture Size node to my custom function in order to obtain texel size, console complains about
invalid subscript 'texCoord2' somewhere deep within shader pipeline (not within the custom function)

Can someone tell me whats wrong?

#

This is a minimal test setup I managed to reproduce it with. Apparently Unity doesn't like when I sample the texture myself within the function. What could be causing this? Is this an intended behaviour?

regal stag
# sand ginkgo This is a minimal test setup I managed to reproduce it with. Apparently Unity do...

Not too sure, but usually in shader graph you'd sample using macros like, Out = SAMPLE_TEXTURE2D(tex, tex.samplerstate, uv + offset).rgb;
More info/macros listed here : https://www.cyanilux.com/faq/#sg-custom-function-textures

Otherwise, could try using regular Sample Texture 2D node and pass the calculated uv out (or replicate the code in nodes), to see if that also errors. (If it does, I'd try a newer unity version and/or report it as a bug)

sacred hull
#

How do I create a sub-graph?

amber saffron
sacred hull
sand ginkgo
amber saffron
#

Does it work if you just force a vec2 value in the texelSize input ?

sand ginkgo
#

the moment I unplug it it compiles fine

amber saffron
#

(btw, in the code you could just do offset = texelSize * uv )

regal stag
#

Also try using tex.texelSize instead of passing the value in

jade ginkgo
#

Is this possible, and if so can someone give me the industry terms/concepts I should look into?
I want a quad to render a grass texture bleeding into a dirt texture. Via code (scripts or shaders).
Can this be done within a single mesh using shaders or something? Or do I need to use multiple meshes and have the one in front fade out to expose the one behind?

amber saffron
sand ginkgo
#

might get that working eventually

sacred hull
#

What does the "Preview" node do? Nvm, I'll look it up

jade ginkgo
# amber saffron The term is "layering". Done using shaders.

Thanks! Looks like you can assign multiple materials to a mesh, I didn't realize that.
Is SplatMap a related concept to what you were referring to? Is the idea to use RGBA as 4 channels to control the weight of a texture at a given point? Would this process be limited to 4 texture layering?

amber saffron
jade ginkgo
grizzled bolt
amber saffron
#

I said that because since ... years, nothing prevents you to add as many materials to a mesh renderer as you want, exceeding the number of submeshes.
With the build-in renderer, this resulted in the materials stacking up, making it an easy way to do multi-pass rendering.
But with render pipeline, this is an unsupported behaviour that I greatly recommand to avoid

jade ginkgo
#

Okay, so am I understanding correctly that multiple materials/textures on a single mesh is discouraged? Is that where a TextureAtlas comes into play?

#

Discouraged even if using sub meshes?

#

(Googling Submesh)

amber saffron
#

Sub meshes won't allow you to blend, as it's 1 material = 1 group of polygons

grizzled bolt
#

If you want to layer textures, you only need a shader that loads those textures and lerps or otherwise blends them

jade ginkgo
#

Thank you both, I'll stop here and process this. You helped me grasp a stronger understanding of concepts I was already seeing. I know now that I'm on the right track and should probably take a step back and run through basic shader tutorials.

amber saffron
amber saffron
#

Ah, erm, no, 3D terrain ๐Ÿ˜…

jade ginkgo
# amber saffron Ah, erm, no, 3D terrain ๐Ÿ˜…

Hahaha, yeah ... The 3D crowd gets all the good stuff. I was using 2D Tilemaps but they are two specific. No blending control and no ability to use large textures. The tiling nature of the textures isn't what I want.
I would love a 2D terrain feature built in, but I can't even find something good on the Asset Store.

#

I'm honestly considering playing with 3d instead just because of the support for it (and also because entities 1.0 simply doesn't work in 2D)

sacred hull
#

I have a value called "foamScale" that changes the size of the foam. The size changes with the scale of the plane. Is there an easy way to make it uniform no matter the scale of the object?

amber saffron
sacred hull
amber saffron
#

Yes

sacred hull
amber saffron
#

Position node ; mode = absolute world ; use XZ

#

Plug into the UV input connection

sacred hull
tight phoenix
tight phoenix
tight phoenix
tight phoenix
#

fix was to make sure the surface normal is at least 1

amber saffron
tight phoenix
#

better view here, making sure the normal is at least 1 fixes the underside ridges

amber saffron
tight phoenix
#

oh yeah?

#

if you pass in a zero value, it completely futzs up, and that's what your triangle wave bands are doing right?

amber saffron
#

I might be wrong, but iirc, normal strength node will force z value to positive.

I overlooked the issue, but a fix would be to take the z value before strength, passe through a "sign" node, and multiply the out z by it

tight phoenix
#

because its a float with no z value almost immediately

amber saffron
tight phoenix
#

oh you mean this z value

amber saffron
#

Yes, the normal value

#

In your screenshot : the G output of the split node (that gets to Z value of the normal strength)

tight phoenix
#

this looks wrong

#

z constantly switches with y so I dont know when/where to use it

chilly lava
#

I use tilemap

tight phoenix
#

can you tell me what is wrong with these normals if my sollution is wrong?

rare charm
#
        meshRenderers = GetComponentsInChildren<MeshRenderer>();

        materials = new List<Material>();
        foreach (var mr in meshRenderers)
        {
            materials.AddRange(mr.materials);
        }

        for (int i = 0; i < materials.Count; i++)
        {
            Debug.Log(materials[i].name);
            materials[i].SetColor("_EmissionColor", Color.red * 64);
        }

This doesn't affect the emission of my material at all. What am I missing here?

#

The code is a bit sloppy bc I'm just trying to make it work.

amber saffron
#

It's just that the normal strength calculation take as granted that z is always positive

#

But if this solutions fits you, just go for it

tight phoenix
tight phoenix
#

or at the very least an understanding of the why\

amber saffron
#

Like I said : depends if you want to flattend between the steps or not.

elfin lily
#

First time using shader graph, why is the main preview empty?

tight phoenix
amber saffron
tight phoenix
#

How can one "flatten between steps" what does that mean visually, and what is the other doing if its NOT flattening between steps?

elfin lily
#

it worked for a bit but suddenly stopped showing

amber saffron
tight phoenix
tight phoenix
#

are you trying to say that between each slope here that the surface normal is completely flat while oriented upward?

#

whereas here the surface normal is whatever the original mesh's normal was?

amber saffron
tight phoenix
#

okay I think I sorta understand the issue

#

I will try to impliment the fix for the black underside that you commented on before

#

I wasnt able to solve it myself

clear fossil
#

I am doing some work with shader stripping. Is there a way at runtime to see exactly what shader keywords a particular draw is using? I am pretty sure I have identified the shader/keyword set and made sure to not strip that variant but the build is still using the wrong variant

#

Open to any way to debug this problem really.

tight phoenix
tight phoenix
#

is the bottom supposed to look like that? Or am I misunderstanding how it should appear?
the fact that it looks wrong to me makes me feel/think that it doesnt matter if this is accurate to how it should look, that people wont like it because it doesnt look like how they'd expect

#

I think I understand it now though, the normals think the surface is either completely flat oriented upward, or completely flat oriented downward, and the slopes are completely flat as well
So whever the light is coming from, the bottom is acting like light hitting that side is coming from directly bellow, which in this case is very dark since there's no light source under it

#

while the rise of each slope ridge catches the light as if light was coming from the side directly which is why it forms dark bands on top and light bands on the bottom UnityChanThink

sullen fox
#

Whenever I take the botton right alpha node into the alpha block it retunrs in the whole plane turning inviseble. I cant figure out why it happends

lunar valley
# sullen fox

I might be stoopid and wrong but maybe alpha Cliping works, if not your alpha which you are pluging in is probably 0

amber saffron
#

@tight phoenix I've modified the graph to make my own normal strength calculation (and take into account the y sign) + add a slider for flattening between steps :

#

Artistic controls could be way better if you wanted to, but I'm to lazy to do it right now.

elfin lily
#

I've never used shaders in unity before, just made my first one that moves an arrow through time, does the animation just keep playing forever in the scene view? is this normal? Is there a way to make it play only while running the game?

alpine hare
#

Can someone help me translate a GLSL shader into HLSL or is there a way how i can feed / convert a GLSL into a HLSL in Unity ?

merry rose
#

Hi is there way to round a pixel in a shader graph? I would like it to be more or less a circle, so that I could make clean territorial edges.

rare charm
merry rose
# rare charm SphereMask node

I am using texture as a mask, I cannot use UV map to produce the circle, as I wanna smooth it between two pixels aswell

#

I got pretty close now by using a blur filtering to get it closer

rare charm
merry rose
#

I cannot, this is what I have, a mask texture which I would like to smooth out. using sphere mask alone does not produce. In the last image its not perfect but the closest I got with blurring the texture in shader and then running through sphere mask.

rare charm
#

Oh ok yeah now I get it... Hmmm. This is an interesting use case.

swift loom
#

Can anyone tell me how HLSL handles decimals when you cast from float to int? Like if you have a float3 test and you do int3(test), will that variable be floored or truncated?? I'm having trouble hunting down some rounding errors...

shadow locust
swift loom
#

i see, thanks

shadow locust
sick knot
#

hi, i'm trying to follow a whirlpool shader tutorial from 2019 into a unity 2022 version. i'm on a step where you're supposed to connect the Power Out to a Lerp T but it's preventing the connection... is it apparent what i am doing wrong?

smoky vale
#

so im working on getting unity lighting working in my shader, and i wrote what i thought was a simple chunk of code

but it produces SEVERAL incorrect outcomes

fixed4 pixColor = tex2D(_Albedo, IN.uv);
        float4 worldPos = mul(unity_ObjectToWorld,IN.vert);
        float4 worldCalc = normalize(worldPos - _WorldSpaceLightPos0);
    float lightDir = dot(UnityObjectToWorldNormal(IN.norm), worldCalc);
        float3 litColor = pixColor * _Color * _LightColor0 * saturate(lightDir);
    return float4(litColor,1);

firstly, ill say what i meant this code to do, i meant it to take the world position of the vertex, then subtract that by the world space position of the pointlight in my scene, then get the dot product of that vector and the object normal in world space, then multiply the albedo by the tint color by the light color by the saturated light dot factor

what it DOES do however, is very different, i want to say before anything that this chunk of code is almost definitely the issue, ive gotten it to work with directional lights and im trying to get it to work with pointlights, and its this chunk of code that im having issues with, not anything else outside of it

what the code gives me is this, firstly youll notice that the light seems to always be coming from one unchanging direction despite the actual position of the pointlight, and secondly youll notice theres a blinding streak of light on the left of the camera regardless of where the camera is

i dont understand what i calculated wrong to get this outcome, ive managed to get everything else outside of this chunk of code working fine, ive made my shader work with the forward rendering pipeline, set up my code in a cginc file so i can use it for the forwardbase and forwardadd pass, made sure the blend mode is ideal, ect ect, i just need help on this code right here

reef owl
#

is there a way to create a computeBuffer whose element count depends on the contents of a shader value/buffer? Something like indirect args but for compute buffers.

#

I'm doing some compute mesh generation and don't want to over-allocate memory for vertices and indices

midnight mortar
#

Anyone please:

#

Whats this error: InvalidOperationException: Failed to add object of type ShaderGraphMetadata. Check that the definition is in a file of the same name and that it compiles properly.

#

My Shadergraph will not load. This was just working until I updated to latest Unity ugh! There is always something...

#

And actually you can open the Shader Graph and see it all, it just wont show up normally so it can't be used, its not even saving...

vestal surge
snow forge
#

@vestal surge I would imagine (I'm still learning, so not 100% sure), that you could sample the objects height somehow and apply that to the vertex positions of your surface object? Or create a new camera (orthographic I think) put it directly above your surface object and use it to create a depth texture that you could then feed into your graph and use the depth texture to drive the vertex displacement? (just guessing).

There's a section in this that deals with using the camera to generate depth.....

https://www.youtube.com/watch?v=gRq-IdShxpU&t=1s

In this video, we'll take a look at how we can use the Shader Graph feature in Universal Render Pipeline, or URP for short, with Unity to create a water shader! The water shader can be simple or complex, and include the features you desire. Let your imagination get wild in this tutorial, or simply follow step-by-step to get about the same result...

โ–ถ Play video
#

I Think you'd probably need to have your surface object and 'deformation' objects on seperate layers and adjust the cameras occlusion layers to suit (would probably need a second plane object to use as a 'background' for the depth map creation)

vestal surge
snow forge
#

No probs. Neither could work. lol. Like I said I'm still learning the graph stuff myself.

#

Soooo.......I have something I've been playing around with working, but I'm just wondering if there's a more elegant way of doing this? Basically creating a height based mask 'subgraph' with min/max height values with blending.

This is what I have, just seems a little overly complicated to me. lol.

midnight mortar
snow forge
#

@midnight mortar I noticed that on 2022.2 URP is all kindsa messed up. Errors all over the place and refused to create a build, after which URP was completely broken.

#

ie. after restarting Package Manager says URP is 'missing'

meager pelican
lunar valley
#

How would I go about implementing the fast fourier transform myself for combining sinusoids, and is it required to use complex numbers like with quaternions to make a efficient and good fft

#

I read the tessendorfer paper about ocean waves but I need some explanation and help

devout onyx
#

do you guys have experience with amplify shader editor? is it possible to convert unity built-in shader graph assets to amplify graphs?

amber saffron
devout onyx
#

my end goal is converting hdrp shaders to urp and the only reason i considered this was if amplify has some sort of graph converter to generate somewhat compatible URP shader from HDRP shader

amber saffron
#

You "just" have to add URP as shader target in the graph settings

devout onyx
#

since which unity version?

amber saffron
#

2021.3 iirc

devout onyx
#

๐Ÿ˜„ project is on 2020.3

#

im scared to convert

elfin lily
#

Is there a way to pause an animated shader in the scene view?

amber saffron
elfin lily
#

Which icon is it in? i tried looking for it but couldnt see it

amber saffron
#

"Always Refresh" here

elfin lily
#

It is turned off by default, but the animation still plays and jitters a lot

#

i guess its playing on editor Update() cause if i hold rmb it plays smoothly

#

wondering if there is a way to completely disable the animation in the scene view

amber saffron
#

If your shader is using time, it will alway refresh during an update

elfin lily
#

i see

#

Another general question, shader graph seems like a lot of fun and id love to get into learning it, but from the (very little) testing ive done so far, it seems extremely buggy, random error messages when connecting nodes, main preview window bugging out, etc.

Is this to be expected? Im not on the latest version of unity so that could be it, but im wondering if thats just the state of shadergraph and everyone just deals with it or if my editor is just bugged

amber saffron
#

IDK what version you are using, but it should be fairly stable

elfin lily
#

Uhh, the preview still shows but the shader turned white randomly

amber saffron
elfin lily
#

The last thing i did was rename this, and it stopped working after that i think, the name has no effect on what happens right? Im not using any code

elfin lily
amber saffron
amber saffron
elfin lily
#

Ah yeah thats what happened, thanks

#

This got reset

elfin lily
lunar valley
amber saffron
elfin patio
#

Hi guys, I want to see front and back faces through the model but this is kinda messy... I want only the "faces" from the back and not a "back renderer"? Any idea?

latent frigate
#

Hey,

How to make a billboard renderer?
With this it seems like the mesh rotated away from the camera.
Also it's affecting z and x I only want y to be affected.

The code is in the thread

#

Billboard Renderer

alpine hare
#

Guys im new with shaders, can someone help me on this issue: I have written some simple animated noise shader code that returns the "fragColor". When applied to an image sprite it displays the black and white cloud noise. However what i wanted to do is to use it as an alpha mask, and i am currently struggeling to do that. I tried to use my final noise variable "fragColor" red channel as an alpha mask for the main_color which is my _MainTex:

                         float4 main_color = tex2D(_MainTex, i.uv);
                        main_color.a = fragColor.r;
                        return(main_color);

But this doesnt work.

steel sphinx
#

does anyone have a shader that hides objects behind shadows in 2d?

#

ive been researching it for a while but everything ive tried is either outdated or just doesnt work

#

kinda like among us

grand jolt
#

Someone know why it is pink?

alpine hare
#

@grand jolt do you have an ENDCG ?

grand jolt
#

I downloaded the shader from github

alpine hare
#

You need a CGPROGRAM ENDCG tag around your shader code, just create a new shader in Unity Create-> Asset -> Shader and see in their template

#

looks like one is missing to me

#

Shader "Alpha Mask/Bumped Specular" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_SpecCol ("Specular Color", Color) = (1,1,1,1)
_Spec ("Specularity", Range (0,1)) = 0.8
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_BumpMap ("Normal Map", 2D) = "bump" {}
_Mask ("Mask (A)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200

    CGPROGRAM
    #pragma surface surf Spec fullforwardshadows addshadow alpha

    // Use shader model 3.0 target, to get nicer looking lighting
    #pragma target 3.0

    sampler2D _MainTex;
    sampler2D _BumpMap;
    sampler2D _Mask;

    struct Input {
        float2 uv_MainTex;
        float2 uv_BumpMap;
        float2 uv_Mask;
    };

    half _Spec;
    fixed4 _SpecCol;
    fixed4 _Color;

    half4 LightingSpec (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
        s.Normal = normalize (s.Normal);

        half3 h = normalize (lightDir + viewDir);

        half diff = max (0, dot (s.Normal, lightDir));

        float nh = max (0, dot (s.Normal, h));
        float spec = pow (nh, 4096.0 * pow (s.Specular, 2)) * s.Specular * 2;

        half4 c;
        c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec * _SpecCol) * atten;
        c.a = s.Alpha;
        return c;
    }

    void surf (Input IN, inout SurfaceOutput o) {
        // Albedo comes from a texture tinted by color
        fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
        o.Albedo = c.rgb;
        o.Specular = _Spec;
        o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
        o.Alpha = tex2D (_Mask, IN.uv_Mask).a;
    }
    ENDCG
}
FallBack "Diffuse"

As you can see here

tight phoenix
#

What are possible causes of this seam in a tri-planar projection shader?
The sphere is a default unity sphere, is it the mesh itself? the texture?

tight phoenix
#

I checked the normals, UV seams, everything I could think of, none of them show any kind of seam at that position

#

yet a seam exists

amber saffron
#

@tight phoenix Dumb question maybe, but : why don't you use the triplanar node ?

tight phoenix
amber saffron
#

Also, you've mixed the axes when blending.
The easy way to blend triplanar is :
Output =
Sample of position XY * normal blend Z +
Sample of position ZY * normal blend X +
Sample of position XZ * normal blend Y

amber saffron
amber saffron
tight phoenix
tight phoenix
amber saffron
tight phoenix
amber saffron
#

Sorry, wasn't clear : normal blend in my words was the weigth for the blending of each planar projection

tight phoenix
#

I inverted ZY because it looked completely wrong

#

and that fixed it from looking completely wrong

#

the texture was rotated 90 degrees

amber saffron
tight phoenix
# amber saffron

I have no idea what you're trying to show me here, you just want me to change the order in which I combine the normals?

#

I don't see why it matters if I add X or Y or Z first or second

#

why do they all go in B instead of A?

#

Switching tops to bottoms doesnt appear to make any difference at all at the final output

amber saffron
#

Just look at the first lerp node : you are lerping from the normal value to 0, bases on the weight.
Only 1/3 of the faces should be affected but you have 2/3 : the lerp is done in the wrong order

tight phoenix
#

in the end all 3 axis get the correct textures in the correct positions, I am not understanding why its wrong, how can it be wrong if the result is correct?

amber saffron
#

Ok, well, if it's correct, don't change it

tight phoenix
#

I mean it works both ways

#

you arent wrong either

#

switching A and B in all of these makes no difference to the end output

#

hm actually it might, let me check that closer

amber saffron
gleaming trout
#

hello, so i'd like to know how can i change the properties inside of a script? so that i can then connect two values, 1 from script, 1 from the shader graph

tight phoenix
tight phoenix
#

currently trying to fix this weird normal inverison thing happening

amber saffron
gleaming trout
#

am i doing something wrong here?

tight phoenix
#

more pronounced on the bottom side

amber saffron
gleaming trout
#

well idk the values don't change for some reason

amber saffron
gleaming trout
#

these are the names

amber saffron
#

And it's set properly on the script component ?

gleaming trout
#

should be good i think

amber saffron
#

Yep, looks good

#

Shader not saved ? Sure that the function is properly called ?

gleaming trout
#

i think so, i put the script inside fixedupdate

amber saffron
#

Everything seems correct to me and should work then, so maybe a bit of information is missing if you're 100% sure that it doesn't

gleaming trout
#

i accidentally seemed to forget to put on the shader onto the material, i did now but it still doesn't work weirdly

#

btw how do i know if the value has changed?

#

this?

amber saffron
#

Inspect the material that is affected by the script

gleaming trout
#

oh i'm stupid, it does change

#

just looked at the inspector

#

but for some reason this doesn't change

#

it just stays the same color and it's supposed to be different

amber saffron
#

This is connected to an output of the shader, right ?

gleaming trout
#

yes

#

now it is

#

but the thing is

#

wait nevermind i thought i had an idea

#

i thought that the material changed itself

#

but it's probably because i changed the value in the inspector

#

but the thing in the shader graph still no work

#

but when i change the default value it does something

amber saffron
gleaming trout
#

the gradient noise, it's supposed to change

#

you know what perlin noise is?

amber saffron
gleaming trout
#

but isn't the propery value and default property the same?

#

property

#

i thought so

#

so what is this

amber saffron
#

Default property value is what you set in shadergraph, and what value the material will have when created

gleaming trout
#

so how do i change the default property?

#

in code

amber saffron
#

The default value visible in shadergraph ? You don't

#

Why would you want to change this ?

gleaming trout
#

so that it actually changes the gradient noise

amber saffron
#

You change the value on the material

gleaming trout
#

so it affects the material that has the shader?

amber saffron
#

Figure the material as a "variant" of the shadergraph, having the exact same behaviour, bur using it's own input values

gleaming trout
#

and doesn't affect the shader itself?

#

make it a variant you say

amber saffron
#

BUT, as the noise scale value is controlled by your exposed property, and you change the property value on the material through script, the noise scale of this material will change

gleaming trout
#

wait so can i just set the default value in the shadergraph?

#

and it will just be that?

amber saffron
#
  • You can not set the default value in shadergraph through script (or at least not in a trivial way)
  • The default value is applied on a material when it is created. If you try to change the default value afterwards, the material will keep it's previous state as it has saved the value for that property
tight phoenix
#

still trying to solve this weirndess, I cannot find the source of the problem to fix it

#

the normals appear to be inverting their direction

#

I dont understand how this could hapen

#

it cant be the mesh or the UVs of the mesh because neither is being used

#

I dont understand where this little wtf is coming from

#

its even more pronounced on the cylinder

#

how can this physically occur, it cant because I'm not using its UV, im projecting onto that surface

#

where is the wtf coming from?

#

very clearly wrongness

vale estuary
#

Does anyone know how to include the Gizmo.hlsl file in a URP shader? I am trying to write one that only is rendered when gizmos are turned on, and have the allowing line currently.

#include "UnityPipeline/ShaderLibrary/Gizmo.hlsl"

but don't see that file in there, and can't find any references to how to do it online.

#

Shader error in 'Custom/Edge Highlight URP': Couldn't open include file 'UnityPipeline/ShaderLibrary/Gizmo.hlsl'. at line 21

regal stag
# tight phoenix where is the wtf coming from?

At a guess I'd say from the tangent->world transformation (that shadergraph is doing behind the scenes). That uses the Tangent and Normal Vectors from the mesh. And afaik the tangent vector is aligned to the UV.x. So the UVs could still be the cause for this weirdness.

tight phoenix
#

can it even BE fixed?

#

is the problem the mesh? Will i have this problem in other meshes unexpectedly?

regal stag
#

I guess check the uvs, but idk

tight phoenix
#

I cant exactly export it

tight phoenix
#

the problem appears to be related to the 0 position maybe?

#

its trying to align the normal direction but is shitting itself in some way?

#

there is a very clear fuzzy line where the UV direction is getting inverted

#

on one side to the other side you can clearly see what appears to bump IN is now bumping OUT

#

and I dont know why or how to fix it

#

the normals are clearly invertign

#

and I cant solve it

#

i cant figure out why

#

or how to fix

#

one side is completely backwards to the other

#

how do I fix this?

#

I am googlign and googling and Im not getting any results at all

#

every time I have a problem its like I am the only person to have this problem ever in all of history, which cannot be true, and yet I can find no results

#

getting burnt out again

#

I HAVE to solve this because as long as it goes unsolved, I cannot trust any normal map on any mesh anywhere ever to be rendering correctly

#

there is a very clear line where the normal inverts

amber saffron
#

This line looks like it could just be the "edge" of the lighting.
Where the normal is perpendicular to the light direction

tight phoenix
#

better example, I don't see how that's the case, its clearly inverting

#

the 'up' ridges become 'down' ridges

merry rose
tight phoenix
#

it cant be a lighting direction problem because the light is hitting the same side

#

a non-unity sphere has the same problem

#

they're all inverting and I cant solve it and I need to solve it and I dont know why its happening so I cant solve it but I cant stop trying to solve it because I cannot do anything else beyond this step until it solved

#

another example of CLEAR inversion occuring

merry rose
#

when exporting your mesh make sure you are exporting tangent data, and when importing in unity make sure to set it to use Import undet Tangets data

tight phoenix
#

its not the mesh, it cant be the mesh because EVERY mesh is doing it

tight phoenix
#

here is that mesh, what should I change?

merry rose
#

under Tangents choose Import

tight phoenix
#

that does look better, I am not sure if its correct but it looks better at least

#

it still very much looks like its inverting

#

are triplanar normal maps maybe just impossible?

#

because its really feeling like right now its simply not possible to do normal mapping in a tri planar set up because it never works and no one can tell me how to make it work

merry rose
merry rose
tight phoenix
#

I dont want to map one single texture on all directions

#

useless without multiple texture support

#

looks even WORSE

merry rose
tight phoenix
#

also very clearly still inverting

#

so theirs doesnt fix this either

#

this guy shows the normals inverting

#

and solve it in his

#

but I cant figure out how to use his sollution because its all HLSL CG code

#

calling functions I dont have access to

#

How am i the only person in the history of 3D to have this problem

#

surely someone else somewhere has used normal maps before and encountered this problem

#

why is the sollution impossible to find

#

I cannot be the first person, its not physically possible

#

the normal blend doesnt appear to be the problem

#

because a single normal map with no blend at all is having these same issues

#

why isnt this guy's mesh having the same inversion problem that all meshes i try have

merry rose
#

UDN and Whiteout methods works fine in ShaderGraph

gleaming trout
#

why do i not see the preview of the shader?

#

also i get this
pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them
Compiling Subshader: 0, Pass: Universal Forward, Fragment program with <no keywords>
Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: DEBUG_DISPLAY DIRLIGHTMAP_COMBINED DOTS_INSTANCING_ON DYNAMICLIGHTMAP_ON FOG_EXP FOG_EXP2 FOG_LINEAR INSTANCING_ON LIGHTMAP_ON LIGHTMAP_SHADOW_MIXING SHADER_API_GLES30 SHADOWS_SHADOWMASK UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING _ADDITIONAL_LIGHTS _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHT_SHADOWS _CLUSTERED_RENDERING _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 _LIGHT_COOKIES _LIGHT_LAYERS _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN _REFLECTION_PROBE_BLENDING _REFLECTION_PROBE_BOX_PROJECTION _SCREEN_SPACE_OCCLUSION _SHADOWS_SOFT

brazen prism
#

hi im working with low-res pixel images (the one in this sample is 64x64), how can i make the preview in Shader Graph not appear blurry?

merry rose
tight phoenix
tight phoenix
merry rose
#

No, it does not, as its not using mesh normal/tangents data.

tight phoenix
tight phoenix
merry rose
merry rose
tight phoenix
#

oh yours is plugged into the normal node

tight phoenix
merry rose
#

nope, unity is now using HLSL so all the functions works as expected, you just have to supply your own inputs, as there is "i" but here you do not the that data so you have to put it there yourself through custom function fields

tight phoenix
#

I know that unity custom nodes require it to be like
thing_float(variables, out results)
{
// code
results = //code
}

#

are you saying you just copy and pasted the code wholesale? Without re-writing the entire thing?

merry rose
#

im using in shader editor not file

merry rose
tight phoenix
tight phoenix
#

I've never gotten that to work before, it always errors

#

Give me a moment to write the variables up

#
// Triplanar uvs
float2 uvX = i.worldPos.zy; // x facing plane
float2 uvY = i.worldPos.xz; // y facing plane
float2 uvZ = i.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 + i.worldNormal.zy,
    abs(tnormalX.z) * i.worldNormal.x
    );
tnormalY = half3(
    tnormalY.xy + i.worldNormal.xz,
    abs(tnormalY.z) * i.worldNormal.y
    );
tnormalZ = half3(
    tnormalZ.xy + i.worldNormal.xy,
    abs(tnormalZ.z) * i.worldNormal.z
    );
// Swizzle tangent normals to match world orientation and triblend
half3 worldNormal = normalize(
    tnormalX.zyx * blend.x +
    tnormalY.xzy * blend.y +
    tnormalZ.xyz * blend.z
    );

Out = worldNormal;```
#

I have to identify which variables are his and which you replaced them with

merry rose
#

its tricky, mainly with texture2D as when you create a texture field in shader graph with the name "_BumpMap" it will throw error as it uses different variable then tex2D needs so you gotta put it there through custom function input.

merry rose
tight phoenix
#

Ahh I see, this will be quick to change

merry rose
#

yes, also I renamed base worldNormal to worldNorm as it would then be recreated at the bottom again

tight phoenix
#

Yeah I saw that'd cause a conflict

#

Undeclaried identifer worldNormal

#

but its declared as a half3

merry rose
tight phoenix
#

is it b ecause its a half3?

#

ill try float3

#

stil says its undeclared

#

I dont understand how they can normalize it but cant declare it

quiet silo
#

for computeshaders you have a function called SetMatrixArray but in hlsl code all arrays are implicit? so what type do you need set a matrix array

tight phoenix
#
// 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;```
merry rose
tight phoenix
#

What is that if not its declaration?

merry rose
#

yes but rename the ones above to the one you set in custom function

tight phoenix
#

I thought I did

#

oh there is two each time

tight phoenix
#

its still doing it, there is still the distortion

tight phoenix
#

I do not understand

merry rose
tight phoenix
#

I dont have that

#

oh here

merry rose
merry rose
#

nice

tight phoenix
#

the problem appears to be gone

tight phoenix
# merry rose nice

This is already much further than anywhere I got, thank you Kristiรกn

#

I will read up on what it means to have the fragment be in world space and how that affects the rest of the shader behaviour and the like

gleaming trout
#

hi, for some weird reason i don't see the skybox and when i look around, the sky that isn't actually a sky, gets very blurry and it gets worse the more i look around, and when i try to replace the skybox it just doesn't work

#

also the sky getting blurry just happens during play mode

#

and i didn't know what place to put this in so i put it here

#

since i'm currently working with shaders and maybe something messed up

merry rose
gleaming trout
#

unless the whole project is broken or something

merry rose
gleaming trout
#

hm, when i set the skybox material to none, it works but when i set it to any material it just goes back to being broken

merry rose
#

what shader does the material use?

gleaming trout
#

cubemap

#

skybox/cubemap it says

#

just some random skybox texture i downloaded

#

i'm guessing skyboxes work with universal render pipeline?

merry rose
#

Yes they do or atleast should hmm

#

Does the procedural one work?

gleaming trout
#

procedural?

#

i'm sorry i don't think i understand what procedural is, all i'm familiar with is procedural generation, which is what i'm doing in this project

merry rose
#

change the shader to Skybox/Procedural

gleaming trout
#

still no skybox

#

and it still blurs out

merry rose
#

I might be out of ideas now, never seen this happen elsewhere :/

gleaming trout
#

it's fine, it was just a little project for me and my friends but i can always restart and do something else

rare charm
merry rose
steep hill
#

hey guys how do i make a object always be rendered

#

i have a problem with the guns clipping through objects using a camera but is not being affected by the lights and shadows

meager pelican
smoky vale
#

its for blending multiple lights, because im using forward rendering

meager pelican
# smoky vale its for blending multiple lights, because im using forward rendering

Yeah, OK, so you'll be getting 0-1 values. but if your results are wrong, at least you'll be able to see what the values of "lightDir" look like for debugging purposes. As you know it should be the light intensity (not direction) as a float, so you should end up with a greyscale N dot L result, either saturated or not.
If you don't, the calc is messed up somewhere, otherwise if it looks right, the problem is elsewhere.

smoky vale
#

it looks the exact same, just without the albedo or color, so its safe to assume that lightdir is the issue

#

however, i will try to unsaturate it

#

for debugging purposes

#

also the exact same.. hmm..

meager pelican
smoky vale
#

yeah

#

so i should do that all in the vert function and just pass it?

meager pelican
#

Those two lines, I think so.

#

What you don't want to do is the ObjectToWorld twice either. IDK if you are.

#

Since I can't see the vert() function.

smoky vale
#

i didnt do objecttoworld for anything in the vert function

#

the vert variable is just unityobjectotclippos im pretty sure

meager pelican
#

OK, tricky stuff.
UnityObjectToClipPos is a "compound" thing.
It converts objectToWorld, then that result to view space, then to clip space. ๐Ÿ˜‰
All in "one" sneaky matrix multiply.

#

It's actually a function that operates differently based on needs, but yeah....

smoky vale
#

hm, neat

#

so i really shouldnt be using objectotclippos, because it is already doing objecttoworld with more things added on, that i could probably do based off of the converted vert pos

meager pelican
#

Well, ObjectToClipPos is needed to output the result tagged with SV_Vertex/POSITION from the vertex shader.
In fact the vertex stage is required to output a variable in clip position. So something will have to use it.
Between the vert() and the frag() the GPU automatically does a perspective divide, dividing the result by the .w component of the clip pos giving perspective distance to the result (squishing things more toward the center of the screen the farther away they are). That all happens during rasterization.

smoky vale
#

alright

meager pelican
#

If you want to track worldPos, interpolated across the polygon, put it in a variable in the v2f and let the interpolator do the work. The frag() can just use that to calc the vector between it and the light, giving you per-pixel values if you want.

#

You could interpolate that vector too, in fact.

smoky vale
#

actually im not sure if i could replicate it

meager pelican
#

Yeah, the vert() has to output it.

rare charm
# steep hill i have a problem with the guns clipping through objects using a camera but is no...

There are several ways to handle this. This is the easiest way: https://www.youtube.com/watch?v=OMVYyW54QlE

#JIMMYVEGAS In this Mini Unity Tutorial, we show you how to stop your weapon clipping into objects, whether it's a gun or sword or anything.
โœฆ Subscribe: https://goo.gl/gidCM5
โœฆ Patreon: http://patreon.com/jimmyvegas/
โœฆ FREE Assets: http://jvunity.com/
โœฆ Facebook: https://www.facebook.com/jimmyvegas3d/
โœฆ Twitter: https://twitter.com/jimmyvegas17...

โ–ถ Play video
smoky vale
#

lights are sorta working, but i think theres something a little wrong with my calculations, that i can probably figure out

smoky flume
#

What would be the use case of discard vs writing to a Stencil Buffer in a pass and then comparing in order to not write pixels? (Other than the obvious that discard is easier to implement

strange basalt
#

well way stencil buffer discards is the same

#

but discard can be used for anything, you could discard a fragement based on a condition

smoky flume
#

I guess using the stencil buffer is useful for complex comparisons

strange basalt
#

with stencil its just based on a comparison with the stencil buffer

smoky flume
#

yea

strange basalt
#

i find i rarely use discard on its own

#

generally just something that is being done based on my stencil comparison

smoky flume
#

I have two textures on a material, one is the main texture and the other is an alpha mask (for reasons). I don't know if I should be discard ing the base texture pixel based on the alpha mask or just output an alpha value of 0. But If I output the alpha (even at 0) I get garbage

#

It seems like alpha 0 is correct, but discard is working for me ๐Ÿคทโ€โ™‚๏ธ

strange basalt
#

what platform?

smoky flume
#

windows

strange basalt
#

will be fine then

smoky flume
#

Oh, is this just an Editor thing?

strange basalt
#

no, more or less its just more expensive to discard on tiled renderers and mobile

smoky flume
#

i c