#archived-shaders

1 messages Β· Page 13 of 1

zenith heron
#

and since I thought hue would range from 0 to 360, I put a hue/6 in my code

#

which is why at some point I played around with the colors but only got yellow

#

oh i just had a good idea

#

i'll just take the alpha from the Ellipse function, and not use RGB to HSV conversions

gray kelp
#

can any1 tell me why this doesnt works
Shader.SetGlobalVector("PlayerPosition", transform.position);

kind juniper
gray kelp
#

doesnt change in the Mat. I check the value there

kind juniper
mental bone
gray kelp
#

then how to make it global ??

mental bone
#

Define it jusr in the shader and not in the properties

gray kelp
#

how do you do that in shadergraph??

#

nvm found it

mental bone
#

Oh you should have led with that

#

I think if it's not exposed it should work

gray kelp
#

there is a option now

regal stag
gray kelp
#

is there a way to debug the value in shadergraph??

zenith heron
#

like, show the value of an output?

regal stag
gray kelp
#

why doesnt changing alpha doesnt seem to effect shader mat ??

regal stag
# gray kelp why doesnt changing alpha doesnt seem to effect shader mat ??

It depends what you want the Alpha to do.
If you want it to affect transparency, would need to change the Surface Type under the Graph Settings. Would also depend on which Blend mode is being used.
If Alpha Clipping is checked, then it just clips/discards pixels if their Alpha is below the Alpha Clip Threshold (but 0.5 > 0, so nothing is clipped here)

zenith heron
#

Hello, I want to know if there is a way to store pixel data (namely, the kind that you see in the Preview window in ShaderGraph) into some sort of pixel data variable of some sort. That way I can draw one circle on my Pen shader, save that data, and then I can try drawing a second circle without having to worry about the first one disappearing. Finally, the effect I want is the one shown in the video (it's an old attempt at making a Pen component, it's only acting weird because it was before I had implemented a simple fix)

teal breach
#

Is there a way we can use global variables in shadergraph in URP13? I used to make a file which would just define the variable at global level - eg float4 _variable outside any function defs. Then I would include this file in my shadergraph and use a function to return the value. It worked in 2020/2021, but now throws errors in 2022

teal breach
zenith heron
#

oh there is?

#

what is a custom shader feature?

regal stag
teal breach
# zenith heron what is a custom shader feature?

You can write your own code to insert at more or less any point in the rendering process. I think I would roughly do it by creating a custom shader for your brush which implements a custom shader pass, and then render only objects with this pass into a separate render target that you don't clear between frames

zenith heron
#

what is Blit?

regal stag
zenith heron
#

i see now

#

how would I position the circle though? My frame is 480x360

regal stag
zenith heron
#

something like shifting the circle's pixels over

regal stag
teal breach
teal breach
gray kelp
#

i am trying to create a player fade effect. Problem is when player fades inside of char is visible anyway to fix this ??

brittle dirge
#

How can I get the WorldToLocal matrix of a transform at a position offset?
My current solution is to just move the transform to that position, cache the matrix and move it back, but It feels like there is a better solution.

Current solution:

var old = transform.position; transform.position = transform.TransformPoint(Center); var matrix = transform.worldToLocalMatrix; transform.position = old;

teal breach
regal stag
zenith heron
#

by the way, how can I scale my UV (or something along those lines)? My circle, in fact, is a weird oval because my _MainTex is supposed to be 480x360

teal breach
gray kelp
teal breach
regal stag
regal stag
regal stag
zenith heron
#

Thank you very much, Cyan!

teal breach
regal stag
craggy chasm
#

Hi guys I wanted to know how to make Single pass Instance work on shaders that I have made using the Shader graph.

Currently what happens is i can only see it from one eye and not the other. I have checked the gpu instancing on the material that uses these shader.

I tried asking earlier but no one saw this so I am asking, Any kind of help is appreciated.

teal breach
brittle dirge
zenith heron
#

Hello, I have a question involving Shader Properties. Two of my Shader Properties are a Vector3 and a Vector2. However, they show as Vector4 Properties in Inspector. Why is that (and can I prevent it?)

teal breach
#

Did my unity just try and allocate 2TB of keyword memory?

regal stag
# craggy chasm Hi guys I wanted to know how to make Single pass Instance work on shaders that I...

I think shader graph is meant to automatically support Single Pass Instanced. I don't target VR so can't confirm that though.
I know in the past I've tried to use regular GPU instancing and using any properties in the blackboard would break it. Instead I had to use a custom function as a workaround : https://www.cyanilux.com/faq/#sg-gpu-instancing
But I don't know if that really applies to SPI here.

regal stag
zenith heron
#

oh ok

patent plinth
#

@regal stag would you consider to port your water-color shader to custom rendererFeature? I reckon that's very possible, right?..

#

It is nice to have a fullscreen effect of it, rander than per object based effect

regal stag
patent plinth
#

yeah, was just asking πŸ™‚ .. Good to know! πŸ‘

zenith heron
#

What is a pass in the given context?

teal breach
# zenith heron What is a pass in the given context?

a pass is like a program on the shader that generates some outputs to write to the buffer/screen. You're probably most familiar with the forward rendering pass, because that's what you literally see when your shader runs (it determines screen color), but there are other passes like 'shadowcaster' (which is used to generate the data required for this object to cast a shadow

zenith heron
#

ooh interesting

regal stag
# zenith heron

That list is a good example of the different passes but note that the numbers next to them won't necessarily be the same as the pass parameter here.
The pass param is the index of the Pass{} within the SubShader{} in the shader. For a graph you'd have to view the generated code to see what each pass is used for (via the LightMode tag). Typically pass 0 wil be the main forward one though.

zenith heron
#

omg my camera rendered to a render texture

#

this is so beautiful

#

the data is saved

kind juniper
#

Heyyo! Any clue if it's possible to make the compiler resolve a constant expression like that at compile time?

normalize(float2(1, 1));
#

Or does it already do it?

regal stag
kind juniper
zenith heron
regal stag
zenith heron
#

should I convert it into a Texture2D?

kind juniper
zenith heron
#

oh do I create a material that uses Render Texture? I read something similar just now

regal stag
zenith heron
#

ohh ok

regal stag
#

You'd only need to convert it to a Texture2D if you need to actually serialize the data (e.g. save it as a PNG file)

zenith heron
#

ohh

#

So the idea is to keep one object with the brush, and one other for my canvas

#

pass isn't at all involved in the other overloads right

#

looks more like Material needs to be a parameter for that to happen but wanted to make sure

regal stag
#

Probably because if you don't specify your own material, it automatically uses a shader with only one pass, that would just output _MainTex.

kind juniper
#

Another question. Does the float3 version of lerp need a float3 t param?
would that interpolate only the x components?

float t = someValue;
float3 vectorA = someVectorA;
float3 vectorB = someVectorB;
value = lerp(vectorA, vectorB, t);
regal stag
kind juniper
#

Oh, does it fill all the components with the same value? I thought it would only fill the first one.

regal stag
kind juniper
kind juniper
regal stag
#

You have float4 scale, when it should be float scale

tall flicker
#

sry im blind πŸ’©

#

gosh i missed my intellisense

#

thx

brittle dirge
#

Speaking of intellisense; what IDE do you all use for shaders? I'm using Visual Studio with the "HLSL Tools for Visual Studio" extensions, it's a good extension, helps quite a bit but I still somehow think that it could be better

ancient arrow
#

dude im so dead, how do i make smth like this

meager pelican
ancient arrow
#

the outline shader

#

so if 2 and more objects with that shader intersects

meager pelican
#

I was pulling your leg.... πŸ˜‰

ancient arrow
#

their outline combines

ancient arrow
meager pelican
#

You do that with stencils.

#

The objects write to a stencil buffer, and then you'd use some kind of render to texture followed by a jump/flood-fill method to outline the mask(s) in the render texture. Then combine it back.

#

It's not simple

ancient arrow
#

is it possible with shader graph or i need to code it myself?

meager pelican
#

SG doesn't support stencils yet, AFAIK

#

But maybe others will know a way. The jump-flood methods require loops too.

ancient arrow
#

oh k, more things to learn about shaders

meager pelican
ancient arrow
#

btw, any good resources for learning the shaders?

#

the code wise

meager pelican
#

Well, see the stick-pin on the top header of this page for starters.

ancient arrow
#

oh k ty

#

and

#

how long it takes to learn it?

#

month? year?

meager pelican
#

It's a constantly evolving black-art...there's always things to learn. But to get up to speed with the basics...month(s).

mental bone
ancient arrow
kind juniper
#

If I'm using Global buffers, do I need to declare them in each shader file?

#

Or would that be considered a local buffer?πŸ€”

meager pelican
#

You always have to declare them, the global is the SETTING of the values/references onto the shader where you declare it.

The engine "just knows" to set them on the material/shader because they are global...but it has to have something to set.

kind juniper
#

I see. What about shader graph? I see that you can set some properties declaration as global, but there's no such parameter for textures?πŸ€”

#

Ah

#

There's no such parameter for Texture arrays apparently

#

there is for Texture2D

#

Or was it because it's a Sample nodeπŸ€”

regal stag
kind juniper
regal stag
#

Yeah

kind juniper
#

Weird stuff but okay

#

I guess I don't entirely understand how gpu resources are bound to shaders...

regal stag
#

It's a bit different for Matrix properties, as they cannot be exposed and it is assumed that they are set locally. If you need a global matrix, that's when you'd need to use the override property declaration. But for anything else, don't touch it basically.

regal stag
kind juniper
#

I don't need matrices. I think it was some other person that had a question on matrices πŸ˜„

regal stag
#

Exposed basically puts it in the Properties section at the top of the shader, and in the UnityPerMaterial cbuffer inside the HLSL portion - which is used to support SRP batching.

not-Exposed only defines it in the HLSL portion, outside that cbuffer.

wanton grove
#

Is there any way to blend 2 textures together into one without having to use a shader or manually combine each pixel through code? I have a shader that all my objects already use so I don't want to add this modification to all of those shaders just for this one object.

zenith heron
#

does Material.mainTexture return a RenderTexture type if that material has a render texture inside? The return type is Texture but that may be like saying GetComponent returns Component. Thank you very much for your time.

brittle dirge
#

What's the difference between Shader.SetGlobalBuffer vs Shader.SetGlobalConstantBuffer ? what does the constant entail here really ?

regal stag
# brittle dirge What's the difference between Shader.SetGlobalBuffer vs Shader.SetGlobalConstant...

It depends how it was defined in the shader. "cbuffer" (or related macros) would be a constant buffer, while a regular buffer is usually StructuredBuffer<T> / RWStructuredBuffer<T>.

On the C# side the ComputeBuffer constructor has a ComputeBufferType parameter. (clicking each of them shows what it maps to in HLSL : https://docs.unity3d.com/ScriptReference/ComputeBufferType.html)

But I'm not too sure what actually happens if you try to use SetGlobalBuffer with that type set to Constant, or vice versa. Maybe it errors.

zenith heron
#

Is there a way to take a Render Texture, and make all its pixels be RGBA(0, 0, 0, 0)?

#

basically, transparent

#

or maybe use a Texture2D as reference and directly set the render texture as that texture2D

#

Whenever I tile this sprite, it makes things come out of its corners. Why is that?

regal stag
#

Or I guess use a Graphics.Blit, with null source and with a material/shader that outputs (0,0,0,0) maybe

zenith heron
regal stag
zenith heron
#

oh

calm elm
#

Hi guys, so I'm making a level editor for my 2D platformer, and I want to have a grid showing in game (that you can toggle its visibility). I've been looking around the Internet on how I could do that, but nothing seemed to fit what I wanted. Since this grid shows on the entire screen indefinitely, I thought I would need to make a shader for that. Any ideas on how I would achieve that ?

junior sky
#

I'm trying to create materials at runtime and apply them to clones. The below portion of code seems to be working

            renderer.material = new Material(Shader.Find("MK/Glow/Selective/Legacy/Normal/Diffuse"));
            renderer.material.SetFloat("_MKGlowTexStrength", 0f);```

except the objects are spawning with what looks like no skin? 

Ive tried fiddling with the shader in the inspector in runtime and I cant find a way to make his skin show back up. Did my creation of a new material lose this info somehow?
zenith heron
#

oh my god it worked Cyan 😩 thank you so much

brittle dirge
# regal stag It depends how it was defined in the shader. "cbuffer" (or related macros) would...

Thanks for the insight, when I googled this I only found like 12 results and none of them actually relevant.
Looking into the Unity URP shader code; it seems that Unity implements both cbuffers and structured buffers for passing around light data. yet they fallback to cbuffers all the time.
Is structured buffer support that bad? I'm using them for this volumetric ambient light effect and they run very well for me, even ran on my Android Poco F3 phone.
Should I be using cbuffers instead of structured buffers?
Sorry for the random questions ... yet thank you for any input

worldly karma
#

OMG I GOT IT WORKING THANKS GUYS HOLYCANNNOLLLI WOOO WHHHOAHA FSIFHBSIHFBSIFHBIFBISBDF RTYHTBHS 78.2 (:

wet pagoda
#

hi
need help any one online
shader related help needed

#

hello

karmic hatch
#

@wet pagoda

wet pagoda
#

😒

#

please add any wind or wave effect in this shader please help me

knotty bough
#

What would be the best approach as far as smoothing out the edges of the texture node on the right? I'd like to achieve as simialr effect to "feathering" in photoshop if that makes sense.

karmic hatch
knotty bough
#

Aight, I think I can do that, thanks!

karmic hatch
#

I might have gotten the edges the wrong way around or something similar, just ask if something is going wrong

knotty bough
#

Seems pretty good. Need to fiddle around with the values. I also imagine I would want to do some sort of normalization on the final node to make sure that it goes from 100% white to 100% black (since I intend to use this for alpha channel anyways).

karmic hatch
#

if you set blur -> 0 (smoothstep probably includes a divide so don't do exactly zero) it should be sharp and go to 1 and 0

knotty bough
#

Ah

#

Aigh I see how this works

#

Thanks

echo lily
#

Hey guys. When passing a custom View Projection to a shader, and multiplying it by a world point, I'm getting strange values in the projected .z and .w components:

_reflectionProbesViewProjectionMatrices[(probeIndex * SidesPerProbe) + sideIndex] =  _cubemapCaptureCamera.projectionMatrix * _cubemapCaptureCamera.worldToCameraMatrix;
float4x4 viewProjectionMatrix = _ReflectionProbesViewProjectionMatrices[(probeIndex * SidesPerProbe) + sideIndex];
float4 clipPos = mul(viewProjectionMatrix, float4(pos, 1.0));

clipPos z and w components are negative and I can't understand the values tbh

zenith heron
#

Hello, I have a question involving the usage of Shaders on Materials. I have a Shader which uses a texture (say, a picture of an apple). Scaling that texture, I find that the render space limit won't let me make the texture 5 times bigger, although I would like something of that sort. I am looking for a way to specifically make my Texture2D render through either a specific amount of pixels or a specific amount of units. Also, some of my textures get squished down in size, and I can't seem to get around that. Thank you very much for your time.

kind juniper
# zenith heron Hello, I have a question involving the usage of Shaders on Materials. I have a S...

A mesh that you render, whether it's a 3d mesh or a simple quad, defines the dimensions of the rendered object. You can't render outside it's geometry(you can expand the geometry in the vertex shader though). So If you want whatever you're rendering to expand up to the full screen, your best bet is a full screen quad.

As for the w being squished I think it's due to the mismatch between the texture resolution and the mesh you're rendering it on.

knotty bough
#

So I've got this nice pulse effect going in shader graph. I was wondering if there was a way to normalize the value that's going into the alpha channel such that the size of pulse is consistent and doesn't scale with respect to the size of the mesh.

steel notch
#

I have pixel art and want to create a sort of "shimmer" effect with gradient noise. How do I get the gradient noise to match the pattern of the pixel art itself? Aka how do I make the noise look pixelated at the same scale as the pixel art?

#

I know I can do this to pixelate the noise.

#

But I want the scale to match the pixel art dynamically.

#

If possible.

civic lantern
#

Hey, I'd like to have my shader know if a position under the sky, so I can have environmental effects like snow, raindrops and puddles. How would I go about doing this? I think I need to render some sort of depth texture from above? Any good techniques, ideas, resources? I'm using HDRP Shader Graph. Maps are procedural but a short baking delay is OK if needed.

zenith heron
#

how do I make it so that my shader uses a full screen quad? Also, what exactly is a quad?

kind juniper
#

Hey, so I'm generating some textures for my procedural terrain generation and passing them between different shaders(compute and rendering): heightmap and splatmaps. And I was wondering if there's any advantages/disadvantages of these textures not having a power of 2 resolution. I know that it's important for stuff like compression and mipmaps, but I'm not using either of these for these textures, so is there still any downside of them not being a power of 2?

kind juniper
teal breach
#

is it just me or does 2022 crash constantly?

#

usually whenever saving a shadergraph

regal stag
steel notch
#

Yep did exactly that πŸ˜›

#

Alright I feel like this is a basic thing I'm goofing. I obviously just want to tint pixels towards a certain color while giving them a bit of bloom, but often these regions just end up completely white. What am I doing wrong?

#

It can't just be as simple as doing a multiply instead of add.

regal stag
#

Yeah you'd usually Multiply for tinting. Can make the colour HDR to control the strength better.

steel notch
#

I guess I'll give a bit of context. I'm trying to replicate this effect here.

#

Basically this sorta randomized color tinting on a pixel by pixel basis off of what I assume is some scrolling noise.

#

While I got the noise to appear and move inline with the sprite's pixels, coloring isn't going as well.

regal stag
#

Could try a Blend node, there's various modes there to try out too

steel notch
#

bro I wasn't even aware there was a blend node I was just going off pure math

#

Any suggestions though on how to replicate what I posted above?

regal stag
steel notch
#

Ya definitely. I'll get to the distortion once I have the coloring down.

regal stag
#

Yeah not too sure on the colouring part

#

Perhaps rather than greyscale noise they are using textures that have the colours baked into it

steel notch
#

It does seem like the base color of the original sprite is used a bit in how those random colors are chosen? For example on the skirt of the rightmost one the pixels are nearly all blue.

regal stag
#

Yeah I noticed that. That might be due to the Blend mode being used though

steel notch
#

Also possible. Currently what I'm doing to get random colors is taking 3 simple noise textures at different scales and combining them back together in RGB.

#

produces this as an end result

meager pelican
# calm elm Hi guys, so I'm making a level editor for my 2D platformer, and I want to have a...

IDK what type of grid you want... on the terrain only....or over the entire screen. The latter is more of a post-processing effect (see Cyan's post a bit above yours talking about a "Blit" too).

For the terrain-only version, it would be computed in the custom terrain shader. You'd have to decide (world space is probably easiest) if the pixel falls on a grid boundary or not based on coordinates and probably a remainder (think modulus operator returns near-zero).

calm elm
#

Yeah I want it on the entire screen. I'll look at that

#

Oh yeah using post proc would probably work, the thing is I have no idea where to start with that

naive canyon
#

I am trying to make looping (repeating) gradient shader in Shader graph. Could someone please give me a hand ? :/

clever saddle
#

Whaat's the blue and yellow line of shader graph while connecting nodes?Why texture 3d cannot connect to vertex position

dim yoke
regal stag
#

Light blue connections would be a Float (single value). Yellow would be Vector3 (3 values, xyz/rgb)

clever saddle
dim yoke
#

You need to sample the texture at certain position to get single vector3/4 out of texture

dim yoke
#

Ah you probably need sample texture 2d lod node

clever saddle
#

I actually didnt understand

clever saddle
dim yoke
#

I meant you have to use Sample Texture 2D (/LOD) node, you cant connect the texture straight to the position block

regal stag
#

That's also assuming you are using a Texture2D. You mentioned Texture3D in your question but unsure if that's what you meant or a typo. If you really are using a 3D texture you'd likely need a custom function using Out = SAMPLE_TEXTURE3D_LOD(texture, sampler, uvw, lod);

dim yoke
#

Oh, missed the 3d part

regal stag
naive canyon
regal stag
naive canyon
#

To be more specific, I need looping world-position based gradient. I was close to make gradient world positioned but it "overflow" resulting in different colors like it would keep going beyond the gradient

#

This is the nonlooping gradient. I can not add Fraction node there

#

Lerp out (4) and Fraction IN and OUT (1)

regal stag
#

You'd put the Fraction before the lerp, not after it

naive canyon
#

Ok no gifs πŸ˜…

#

So between the Split and Multiply node ??

regal stag
#

Probably yeah

naive canyon
#

Ok ok, kinda works 🌟

#

I just need to make it loop (the color) as you mentioned before πŸ™‚

#

I am having hard time doing so... Any ideas ?? It needs to start and end with same color, while integrating the second color in the middle.
So (C = color)
[ C1 C2 C1 ] - color order

Is there any node for such color that can have colors exposed?

#

OR
should I do it via the Lerp nodes ?

regal stag
naive canyon
#

Aha

regal stag
#

For Sine it would also expect a different input range if you want it to repeat each unit. Would probably need to Multiply by 2*PI (aka Tau, Constant node can give that) or something like that.

naive canyon
#

How do you do that ?

#

Just multiply the Sine input ?

regal stag
#

Yeah, Multiply just before Sine

naive canyon
#

It overflows

#

Ou, my bad

#

Ok done ! Thanks A LOT for your help πŸ‘ You are great!

civic lantern
#

TLDR: need a global mask that stores data on if a position is outdoors or indoors

echo lily
#

Anyone here could explain what are the values in the z and w components of a position multiplied by a custom projection*view matrix? The values I'm getting are wildly different from the ones I get using the builtin Unity MVP matrix

grizzled bolt
civic lantern
grizzled bolt
civic lantern
#

Yes that's what I was planning, thanks for validation. Guess i'll start experimenting :)

meager pelican
# echo lily Anyone here could explain what are the values in the `z` and `w` components of a...

The MVP value includes the model's transformation. Then it moves to view space and projection space (basically making it end up in clip-space before perspective updates). "The values you're getting" I'm assuming are AFTER the multiplication, so the Z is the depth and the W is the value to be used for the perspective divide that happens during rasterization, between vertex and frag.

So If you're in the vertex shader stage, you haven't divided your results by W yet, but by the time you get to the frag stage, it gets divided out if it has the SV_POSITION semantic and X and Y are going to be NDC space....I think. Z is still the depth but might be encoded differently depending on API (not sure if that's fixed up or not at this point) and W is the value that was the divisor.

echo lily
# meager pelican The MVP value includes the model's transformation. Then it moves to view space ...

DX11 on Windows. But when using the following code on a surface shader:

o.Alpha = Linear01Depth(IN.screenPos.z / IN.screenPos.w);

Where screenPos is the builtin value passed in the Input structure:

struct Input
{
  float2 uv_MainTex; 
  float4 screenPos;
};

I get a totally different value in another surface shader where I pass my VP matrix manually:

_reflectionProbesViewProjectionMatrices[(probeIndex * SidesPerProbe) + sideIndex] =  _cubemapCaptureCamera.projectionMatrix * _cubemapCaptureCamera.worldToCameraMatrix;
...
var ratio = (reflectionProbe.farClipPlane / reflectionProbe.nearClipPlane);
_reflectionProbesZBufferParams[probeIndex] = new Vector4();
_reflectionProbesZBufferParams[probeIndex].x = 1f - ratio;
_reflectionProbesZBufferParams[probeIndex].y = ratio;
_reflectionProbesZBufferParams[probeIndex].z = _reflectionProbesZBufferParams[probeIndex].x / reflectionProbe.farClipPlane;
_reflectionProbesZBufferParams[probeIndex].w = _reflectionProbesZBufferParams[probeIndex].y / reflectionProbe.farClipPlane;

Shader:

float4x4 viewProjectionMatrix = _ReflectionProbesViewProjectionMatrices[(probeIndex * SidesPerProbe) + sideIndex];
float4 clipPos = mul(viewProjectionMatrix, float4(pos, 1.0));
float4 screenPos = clipPos * 0.5f;
screenPos.xy = float2(screenPos.x, screenPos.y) + screenPos.w;
screenPos.zw = clipPos.zw;
return screenPos;
...
float ProbeLinear01Depth(uint probeIndex, float z)
{
  float4 zBufferParams = _ReflectionProbesProjectionZBufferParams[probeIndex];
  return  1.0 / (zBufferParams.x * z + zBufferParams.y);
}
...
float screenDepth = ProbeLinear01Depth(probeIndex, screenPos.z / screenPos.w);

The cameras used in both cases have the same configuration (fov, near and far clip planes), but the z and w values are very different in each case

#

The values I'm getting with the custom VP are like 1.6x bigger than using the builtin screenPos in the surface shader input structure

meager pelican
#

Your Pos variable is a world position? Or what?

echo lily
#

World pos, yes

#

There is the trick I use in some screenspace effects that I'm honestly not sure what it does, but I'm not applying it here: (Makes no difference here anyway)

gpuProjectionMatrix = GL.GetGPUProjectionMatrix(context.camera.projectionMatrix, false);
var projMat = gpuProjectionMatrix;
projMat[15] = projMat[14] = projMat[11] = 0;
++projMat[15];
meager pelican
#

IDK why they don't just set projMat[15] to 1.
I'm not sure either, but the last component of the matrix ends up being 1, and the previous one a 0, and the another w component ends up 0...the one before the last one.
The meaning of the values in the projection matrix are:
https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/opengl-perspective-projection-matrix
If you want to digest and decode that, but I don't do that off the top of my head. πŸ˜‰

meager pelican
#

@echo lily Keep in mind that Unity uses an Open GL standard for matrix multiplies, IIUC. However, this video was helpful in explaining how to build a perspective projection matrix. Thought you'd be interested:
https://www.youtube.com/watch?v=EqNcqBdrNyI

In this video you'll learn what a projection matrix is, and how we can use a matrix to represent perspective projection in 3D game programming.

You'll understand the derivation of a perspective projection matrix in 3D computer graphics. The matrix I'll derive is as used by left-handed coordinate systems like DirectX (OpenGL uses a right-handed ...

β–Ά Play video
echo lily
meager pelican
#

:/ so maybe not the best example.

Also don't forget about aspect ratio when you're building your matrix.

#

That 1.6 you mentioned is pretty close to 1.7777 of a 16:9 aspect ratio.

echo lily
zenith heron
#

Hello, I have a question regarding Materials. I have a material which is currently using a RenderTexture as its _MainTex, and that won't change, and I want to access that RenderTexture in my C# script. The RenderTexture is an asset in my Assets folder as well (in case the RenderTexture in Assets is changed as it is in the Material). So, is there a way to access that RenderTexture from C# (Material.mainTexture returns a Texture, but that isn't enough to convince the compiler that it's a RenderTexture). Thank you very much for your time.

regal stag
zenith heron
#

oh yeah i used casting

#

i thought it wouldn't work well though

#

can the product of casting still be a reference

#

Does my source Texture for Graphics.Blit need to be showing in the game or can I disable SpriteRender the whole time? Also, if I use the Texture source, RenderTexture dest overload, does pass not get set to 0? If so, I would have to use an overload that uses the pass=-1 parameter, in which case I would need to specify the Material mat parameter. Which one would that be, the RenderTexture's mat, or the source's Mat? I was thinking the RenderTexture's mat. Thank you very much for your time.

grand jolt
#

hey i made a simple shader with shadergraph

#

how do i make it so i can change a material property without affecting another object with the same material?

#

at runtime*

regal stag
regal stag
zenith heron
#

These are the objects involved with my Graphics.Blit operation currently. The operation assumes that there is a Material with the source texture in it as _MainTex, a Material containing a RenderTextureAsset, and that the parameters used are source texture, dest rendertexture, rendertexture's material, and pass=0. The operation uses these to draw the source texture onto the dest rendertexture. Are all of these the requirements, or am I missing something? I am asking this because when using the operation during runtime, there is no sign of change for the RenderTexture when viewed in the Projects tab as an asset. This change can be viewed when clicking on the asset (which I had tested by drawing using the Camera). I figured showing everything currently in use might be more efficient such that others may see any errors I had not known about or noticed. Thank you very much for your time.

#

Does Graphics.Blit require some sort of Camera to have its RenderTexture output set to that of the RenderTexture used as an argument in Graphics.Blit?

#

Or can I do it without using a Camera at all?

wet pagoda
#

how to animated wind effect shader only this portion of vertices not bottom

regal stag
zenith heron
#

oh

#

i was asking about camera since it has this option

#

that's how I got my camera to draw on the asset

regal stag
# zenith heron These are the objects involved with my Graphics.Blit operation currently. The op...

Your DrawCircle function is currently using SetFloatArray, but these properties aren't float arrays. You would want to use SetColor for the Color, and SetVector for the Position.
You're probably also using the incorrrect property names here. You need to use the "Reference" of the property in shader graph, not it's actual name. Can find it under the Node Settings tab with each property selected.

They will probably be _Position, _Color, _Size and _Alpha at a guess. But if you're on older versions it might be an auto-generated string of random numbers, but you can change it to those to be more readable.

regal stag
regal stag
#

I'm also not too sure what Ut.Admin().rtpref is exactly but the source and destination here is probably the same "Pen" render texture, right?

zenith heron
#

yeah

#

Ut.Admin() returns my Administrator mono class, which contains the RenderTexture rtpref asset

regal stag
#

You would ideally want to avoid having the same source/destination. So either should set up two Render Textures and kinda switch between them each frame, or have unity set up a temporary one via RenderTexture.GetTemporary : https://docs.unity3d.com/ScriptReference/RenderTexture.GetTemporary.html
and use two blits (also RenderTexture.ReleaseTemporary after that)

zenith heron
#

does my _Color property have to be a float4?

#

oh

#

is having two RenderTextures better than a temporary one?

#

since the temporary one seems to deal with memory allocation

regal stag
#

In both cases there is memory allocated. Using a temporary one is usually easier but need 2 blits rather than one which is a bit more expensive

zenith heron
#

ohh unity keeps the temporaries in a pool

#

i asked that without that in mind

regal stag
#

Yeah, it would use the same temporary each frame (provided you release it properly, and don't change the size or something)

#

If you find it easier you can also create RenderTexture from C# rather than using assets

zenith heron
#

so if I used two pre-existing Canvases, I would use a bool to do B is A was done last frame? What happens when one is used rather than two?

#

If I had two pens running at the same time, in which case they go to the same Canvas, would I need more canvases?

regal stag
#

You could probably do something like

RenderTexture A, B;
// Start()
  A = new RenderTexture(width, height);
  B = new RenderTexture(width, height);
  A.Create(); B.Create();
// DrawCircle()
  Graphics.Blit(A, B);
  // swap A and B
  RenderTexture a = A; 
  A = B; 
  B = a;
// also in OnDestroy() would probably want to release. Maybe Destroy() too, idk?
  A.Release(); B.Release();
zenith heron
#

o:

#

is OnDestroy when the application like closes

#

or the object is destroyed

regal stag
#

It's when the gameobject is destroyed, but it should also be called when the application closes afaik

#

And in the case of the temporary RT version, would be something like

RenderTexture temp = RenderTexture.GetTemporary(width, height);
Graphics.Blit(yourRenderTexture, temp); // copy to temp
Graphics.Blit(temp, yourRenderTexture, drawCircleMat); // another blit, using material to draw circle
RenderTexture.ReleaseTemporary(temp);
zenith heron
#

if i wanted to render my RenderTexture, would I do so by using some sort of Canvas material which takes this texture?

#

like so

regal stag
#

Can do that yeah. Or if you want to draw it fullscreen could likely do another blit, with null as destination. That should use the camera then.

leaden turret
zenith heron
# zenith heron

as shown in the picture, it's okay if there's no sprite right?

leaden turret
#

A Hybrid Renderer V2 batch is using a pass from the shader "Amazing Assets/Terrain To Mesh/Splatmap", which is not SRP batcher compatible. Only SRP batcher compatible passes are supported with the Hybrid Renderer.

regal stag
# wet pagoda how to animated wind effect shader only this portion of vertices not bottom

Haven't looked at the shader file you shared, but the usual way is to multiply the vertex displacement by the Y axis of the UV coords. Since Y=0 is the bottom of the texture and multiplying will result in 0 displacement there.

Can do some additional remapping of the values if necessary. e.g. By using add/subtract, multiply, and max(x, 0) to clamp any negative values.

regal stag
zenith heron
leaden turret
#

@regal stag it is a .shadergraph file yes, so why is it causing this warning and showing incompatible with SRP batcher?

regal stag
regal stag
zenith heron
#

ohh

#

so that's why

#

and pass=-1 is better off left alone?

regal stag
#

Depends what material you use, but pass:0 is probably safe. -1 would render all passes (like shadowcaster, depthonly, etc) which may cause some strange rendering in this case

zenith heron
#

this can be used with my "_Color" property right?

regal stag
leaden turret
#

not sure myself... lemme try to look around...

regal stag
leaden turret
regal stag
#

Hmm okay... that's quite different from what you posted before. It seems like it has a lot of properties that aren't included in the cbuffer so that explains why it doesn't support SRP batching

#

If those properties were setup in the shadergraph blackboard it would have added them to the cbuffer, so I'm guessing this asset copied the generated shader code then edited it

leaden turret
#

ah

#

so would it be simple or take some work to rectify this situation?

coarse spruce
#

is there any way to edit or change grayed out materials via code?

#

actually nvm

regal stag
#

Can keep the textures defined outside that, but all float/vectors/etc that are in the Properties block at the top should be there

leaden turret
#

sounds "simple" in the sense of it sounds like just a copy pasting job. if i may pester you over the next few minutes for specifics to make sure i'm doing it right - i'd love to give it a try

#

or - can i buy you a beer to do it for me?... πŸ˜›

#

oh snap 6600 lines of shader code... 213 instances of "#include"...

#

179 of which are #include "Packages/com.unity. ... "

zenith heron
#

oh my god

#

πŸ›

meager pelican
leaden turret
#

@meager pelican heh... good point - i have no clue really, i'm trying different things, cutting up the map into a grid 4x4 (= 16 parts), 8x8, 16x16 etc trying to find if any is more/less performant than another with dots's hybrid rendering optimizations & batching etc

meager pelican
#

Interesting. Might save you some due to culling, but OTOH, it might cost you too compared to just submitting en mass. I'm curious as to your results so far, particularly since you're using DOTS.

leaden turret
#

well so far this Splatmap shader is not rendering at all for not being compatible with SRP batching...

zenith heron
#

Is it costly to turn a RenderTexture into a Texture2D, or copy a RenderTexture's values onto a Texture2D during runtime like, every frame? Or rather, what's the best way to render a RenderTexture?

thorn snow
#

has somebody ever had it that shadergraph cannot open .shadergraph files anymore? somehow the icon also changed to what a normal shader looks like.

amber saffron
zenith heron
#

yeah i just want it to show during the game

#

so Graphics.CopyTexture can help me do that?

amber saffron
zenith heron
#

yessssss

#

thank you so much

#

i was about to use a questionable method

tall flicker
#

following is hlsl shader code, not C#

    {
        _MainTex ("Texture", 2D) = "white" {}
        _ScaleFactor("Scale Factor" , Range(0,1)) = 0
        _ReferenceDistance("Reference Distance", Float) = 10
    }```
*in subshader section*
```    SubShader
    {
        Tags { "RenderType" = "Transparent" "Queue" = "Transparent+500"}
        LOD 100

        Pass
        {
            ZTest Off
            Blend SrcAlpha OneMinusSrcAlpha
            Cull Off```
#
            float _ReferenceDistance;

            v2f vert (appdata v)
            {
                v2f o;

                float4 world_origin = mul(UNITY_MATRIX_M, float4(0, 0, 0, 1));
                float4 view_origin = float4(UnityObjectToViewPos(float3(0,0,0)),1);

                float scale = (_ScaleFactor * (length(view_origin) / _ReferenceDistance)) + (1 - _ScaleFactor);

                float4 world_pos = mul(UNITY_MATRIX_M, float4(scale, scale, scale, 1) * v.vertex);
                float4 flipped_world_pos = float4(-1, 1, -1, 1) * (world_pos - world_origin) + world_origin;
                float4 view_pos = flipped_world_pos - world_origin + view_origin;

                float4 clip_pos = mul(UNITY_MATRIX_P, view_pos);

                o.vertex = clip_pos;

                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }```
lament karma
#

Making a game with lots of realtime lights using forward rendering is... not good to say the least.
I want the lights to have very simple features - kind of like cel-shading. Is there a way to create a "fake" light that acts like a realtime light and lights up on materials close by without needing all the processing of a normal Unity light?

#

The light just adding a certain colour to the area on the objects it emits on, just like cel shading I suppose.

lament karma
#

I might want to change to deferred rendering and see how far I can come there...

neat lichen
#

Hi, I've made a shader for an aurora borealis, but the vertex displacement I use for my aurora plane does not work in play mode - only in the editor. What did I mess up?

grizzled bolt
molten crown
#

Hello

#

Why is the preview empty?

candid mortar
#

Is it possible to send positions through a buffer as half rather than float?

#

i tried many things and it seemed to glitch on rendering (drawn at 0,0,0)

#

i think its something c# side. MathF.Float2Half outputs ushort, and math.f32tof16 outputs uint

#

should probably debug the output, maybe next time. as they have to go in as x4, it still saves space using x4 half, compared to x3 float. no idea what the output would be like but wanted to experiment!

haughty moat
#

General question. Using a computeShader and CS.SetTexture(KernelID,PropId,Texture), I don't understand what the KernelID does(it does seem that you need to set the texture in every kernel you are going to access it in though). If I have several kernels, what does setting the texture in one kernel rather than the other do ?

storm cloud
#

Objects with shaders near both the editor view and camera view have this weird circle at the bottom of the view where things render incorrectly, anyone know what to do about this?

grizzled bolt
regal stag
storm cloud
#

was lazy and put the toon shader on the cube just to have something there

#

thanks!

dense bane
#

what's the current way to add random meshes on a large mesh using only the GPU?

steel notch
#

Is there a way to warp the UVs of a scrolling texture where it appears to sort of "crawl" along the contours of a sprite? Looking to replicate this effect.

#

And it seeems like it's more than just 2+ scrolling water textures?

grizzled bolt
steel notch
#

So a texture producing the actual mask, and another distorting that mask?

#

Any idea on how they're producing the nice rainbow colors btw?

grizzled bolt
#

Hard to tell from the gif what's happening

tight phoenix
#

I'm trying to debug something, can you see a difference between this code and this graph? I've looked it over half a dozen times but I can't find my error, but they don't produce the same result

#

more labels

#

expected output vs the output I get - it DOES work, but for some reason it only works from for a narrow 1/4 slice, which I assume is coming from distB

#

hmm I output min and max, and there is a distinct difference at that step

#

min looks right but max does not

#

ah

#

T0 was plugged into both slots of max

#

it wasnt the nodes the problem, it was the connections

#

solved

hearty obsidian
#

Quick Q, the moment I set the alpha clip threshold to > 0 in shadergraph, backfaces on a 2 sided shader are culled

#

What am I not getting?

patent plinth
#

how to make vertex displaced scene objects work with PP outlines?

#

if that doesn't make sense lemme know cos my english is like from another realm πŸ˜†

regal stag
# patent plinth how to make vertex displaced scene objects work with PP outlines?

It's typically due to the method used to capture the depth & normals of objects. For example, Using an overrideMaterial in a URP renderer feature is the common method, but that means the new shader doesn't have the same vertex displacement code that the regular shader had. Same problem occurs with alpha clipping too.

Newer versions of URP can create it's own Depth & Normals textures (by using ConfigureInput(ScriptableRenderPassInput.Normal);). That uses a DepthNormals pass in the shader rather than an overrideMaterial - so it works with vertex displacement as long as that pass is set up with it.

That works with Lit Graph as they generate that pass. But sadly Unlit Graphs don't generate that pass... (Probably because the normals texture in URP was designed to work with the SSAO feature, and I guess you typically wouldn't have ambient occlusion around something that isn't lit?). You could copy the generated code and add it in, but probably a bit annoying to setup.

violet urchin
#

and there is not an option to choose

patent plinth
regal stag
patent plinth
#

also that UnityChanTOonShader has issues with DepthPrimming...

violet urchin
violet urchin
patent plinth
#

you don't normally use that mode... so feel free to ignore it

violet urchin
#

So far im pretty happy. Only outline does bug if an object edge is aligned 0Β° to the view/camera

lean lotus
#

Hey is there a way to write to the gbuffer from a compute shader? I need to modify the depth texture for cases where I hit the skybox

modest zealot
#

Hey, I know this is a really old post, but I once again really wanted to thank you for your detailed response. It took a few weeks of doing some serious wizardry but I finally got it to work! The 'invisible' cubes here are using the reflection probes from the scene, which with a little extra shader tweaking can be used as frosted glass, to hide things like level loads, or create essentially vista impostors.

#

And frosted glass (without a grab pass or alpha transparency!)

grizzled bolt
#

Tech Art tip ✨
Want a transparent refractive opaque material ? πŸ€”
Just use a reflection probe and sample it like this in your shader. Using #unity3d URP.
Bonus : caustics made with an emissive decal.
#gamedev #VFX #shader

β–Ά Play video
#

I only got as far as sampling the cubemap, didn't figure out the correct math to get it to bend light correctly

modest zealot
#

Ah, but that does take URP. I'm in built-in render

grizzled bolt
timid minnow
#

Anyone with more generalized experience know if rendering water incurs more of a CPU or GPU cost?

#

My intuition would say that if there's no wave geometry deformation, it'd be basically entirely GPU right?

grizzled bolt
timid minnow
# grizzled bolt Depends on what "water" is in this context

Ain't that just it... seems like there's so many ways to do it... I guess just a shader would be like I'm saying, probably entire GPU... if water is something you have to interact with, you'd want to use VFX particles and such, and then if you're doing any geo deformation I'm not sure if that is CPU or GPU

#

Basically, I ask because I would desire to have an ocean in my game, but I do not really have CPU budget left so it'd have to be the most lightweight-possible on the CPU

grizzled bolt
timid minnow
#

I guess I'd like to learn more about pros and cons... what do I miss out on with trying to eschew CPU processing?

grizzled bolt
timid minnow
grizzled bolt
timid minnow
#

Yeah that should be fine

subtle dagger
#

moving my questions to here bc i was told shaders might be the solution, is there any way to make the thermal cam im trying to create see certain objects as transparent, while the normal cam sees them opaque, at the same time?

leaden turret
grizzled bolt
subtle dagger
#

kk ill stay in pp

meager pelican
leaden turret
# meager pelican 1) What's the exact error message you're getting? 2) is it a pink-error-shader r...

@meager pelican

  1. A Hybrid Renderer V2 batch is using a pass from the shader "Amazing Assets/Terrain To Mesh/Splatmap", which is not SRP batcher compatible. Only SRP batcher compatible passes are supported with the Hybrid Renderer. (also see image attached)

  2. no pink, just not showing at all, so maybe it is rendering - just not showing all the values/texturing expected since they are not part of the shadergraph SRP-batcher-compatible variables or whatever

  3. using URP in this case not HDRP, pretty much left everything as-is havent touched anything rendering pipeline related at all.

To be clear - the shader does work in regular scene. But now i'm working it in SubScenes and ECS/DOTS/Hybrid renderer, which is apparently specific about SRP Batching compatibility for its optimization benefits

leaden turret
#

wondering whether to post a job for it...

tight phoenix
#

Whats mathematically different between length, add, and maximum in this circumstance?

cosmic prairie
#

the key is that you overlap the colors here, if it were all just one color or separated colors then they would return the same

#

if that's what you're referring to

meager pelican
# leaden turret <@573586703202254878> 1) `A Hybrid Renderer V2 batch is using a pass from the ...

To be clear - the shader does work in regular scene. But now i'm working it in SubScenes and ECS/DOTS/Hybrid renderer, which is apparently specific about SRP Batching compatibility for its optimization benefits
OK, sorry, that makes more sense. Also there was a bug in some Unity versions related to HDRP installs, configs, and batching/rendering so I was asking.

But now, that makes sense. It DOES render in a regular scene. It's using passes that aren't compatible with ECS/Dots-Hybrid-Renderer. A pickle for sure, no easy answer as you're aware. You not only have to fix the CBUFFER issues, but the passes as well if they don't correspond, or maybe it's just that the pass would work if the CBUFFER was fixed up.

potent jetty
#

Hey, is there a way to get the second splatalpha in shader graph? I am using "_Control" to get the first RGBA values, but how can I get the other ones?

karmic hatch
honest bison
#

how do I sample skybox in URP shadergraph

#
    half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
    // decode cubemap data into actual color
    half3 skyColor = DecodeHDR (skyData, unity_SpecCube0_HDR);
#

I want to get this into my URP shader graph

#

have made this hlsl ```//this include provides unity_SpecCube0_HDR
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityInput.hlsl"

void SpecCube_float(out float4 Out, in float3 Normal, in float3 ViewDirection) {
float3 reflectionDir = reflect(-ViewDirection, Normal);
float4 envSample = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, reflectionDir);
indirectLight.specular = DecodeHDR(envSample, unity_SpecCube0_HDR);
Out = indirectLight.specular;
}```

#

UNITY_SAMPLE_TEXCUBE is not defined

#

honestly, I guess I dont need this. If I set spec and metal to 1

#

my real question is that my custom skybox will not render into the reflection probe

regal stag
# leaden turret <@357936113983291393> since right now this is kinda blocking my whole project pr...

As I mentioned before, to support SRP batching all Properties in the shader, other than textures, need to be defined in the Cbuffer. e.g.

CBUFFER_START(UnityPerMaterial)
float _T2M_Layer_Count;

float4 _T2M_Layer_0_ColorTint;
float _T2M_Layer_0_NormalScale;
float4 _T2M_Layer_0_uvScaleOffset;
float4 _T2M_Layer_0_MapsUsage;
float4 _T2M_Layer_0_MetallicOcclusionSmoothness;
float _T2M_Layer_0_SmoothnessFromDiffuseAlpha;
float4 _T2M_Layer_0_MaskMapRemapMin;
float4 _T2M_Layer_0_MaskMapRemapMax;

// etc
CBUFFER_END

But doing this should cause redefinition errors as I'm assuming they'll already be defined elsewhere in the shader include files, so you'd need to search through for those lines and remove them.

Whether this is the only fix you'll need to make the shader compatible with the Hybrid Renderer V2 though, IDK.

honest bison
#

do skybox need to be cubemap to render into the reflection probe?

regal stag
honest bison
#

My goal is to have reflections match a changing skybox

regal stag
#

I'm not too familiar with reflection probes. Didn't think there was anything special to get the skybox rendering there

honest bison
#

dang... I had fog on... lol

#

well, mystery solved

#

The shader graph still doesn't work as you need to add custom tags to the shader

#

any way to add tags to a shader graph shader?

regal stag
# potent jetty Hey, is there a way to get the second splatalpha in shader graph? I am using "_C...

Afaik no, the usual way to handle this in Terrain shaders is by using multiple passes (well, technically also separate shaders connected by the ShaderLab "Dependency" syntax)
e.g. Assuming URP : https://github.com/Unity-Technologies/Graphics/tree/2021.2.16f1.4502/com.unity.render-pipelines.universal/Shaders/Terrain
So in TerrainLit.shader you have :

Dependency "AddPassShader" = "Hidden/Universal Render Pipeline/Terrain/Lit (Add Pass)"
Dependency "BaseMapShader" = "Hidden/Universal Render Pipeline/Terrain/Lit (Base Pass)"
Dependency "BaseMapGenShader" = "Hidden/Universal Render Pipeline/Terrain/Lit (Basemap Gen)"

AddPassShader would be responsible for sampling the next SplatAlpha and 4 layers. I think the BaseMap passes are used when the camera is very far away.
Other pipelines should be basically the same.

But it's not possible to add these Dependencies in ShaderGraph currently. Perhaps you can find a way to pass the SplatAlpha textures in yourself, but not sure. Could also generate shader code from the graph and add those dependencies. Would still need to write separate shaders for those though. Or rewrite in shader code entirely, maybe using the provided terrain shaders for your pipeline as a base.

honest bison
#

I don't really feel like converting this shader graph to CG

regal stag
sacred patio
#

Hi guys, I am having trouble understanding how to connect the custom data in the particle system to the shader..
I am trying to dissolve the alpha over time, does anybody have any tips how can I improve this for it to work?

regal stag
#

The custom data is being sent into TEXCOORD0.zw, this corresponds with the UV node set to UV0, but should use the B and A outputs to obtain them. (XYZW=RGBA)

#

The shader also doesn't use the Vertex Color node yet, which I believe is causing that "COLOR streams do not match" error

steel notch
#

Anyone have a good place to get nice, tiling textures?

#

Looking for something like this.

potent jetty
sacred patio
leaden turret
sacred patio
elder mesa
elder mesa
#

in the gif I adjust a mask to remove noise from the center

#

ill tidy up the graph and send 1 sec

steel notch
#

Damn thanks.

#

What I was trying right now was to use a simple water texture with some UV distortion as the mask.

#

This was the result, but I was struggling to get the mask to follow the pixels of the sprite.

#

Before I could just use the texture size, multiply with UV, floor and then divide by texture size again to get the pixel look.

#

But with this UV distortion, those pixels are getting distorted too.

#

Wasn't sure how to separate it.

elder mesa
#

ohh you wanted to pixelate it in the shader, Ive got an upscaled render texture setup for certain layers to get pixelation on anything easily

steel notch
#

Like you can sorta see squares in there, but it's getting distorted.

steel notch
elder mesa
#

well heres the graph anyway

steel notch
#

woah what are these?

elder mesa
#

redirects, purely for organisation

#

right click a line

#

(at least in 2020.3.14f1)

steel notch
#

ah, I never used this

#

good to know

#

so you get the colors it to pixelate through methods outside the shader?

elder mesa
#

yea, correct

steel notch
#

Darn, looking to do it within the shader itself.

#

Thanks for the help regardless.

#

Your effect looks very good.

regal stag
steel notch
#

Ya sure.

elder mesa
#

toward the end of the gif i fade out the mask

#

(pixelation done in the shader)

#

just did what you mentioned at each noise UV

steel notch
#

here is what I am doing currently to produce what I posted above, no Pixelation yet.

steel notch
# elder mesa

Might want to floor it instead of rounding? Those colors don't look like they're exactly matching the pixels all the time.

elder mesa
#

they dont, im not sure how youd do that

#

easiest way for pixel perfect like that is to either use the PixelPerfect component or have an upscaled render texture setup

#

otherwise its likely gunna be a lot of work to get exact pixel snapping (i think)

regal stag
#

Shouldn't be that much work. Can use the Texel Size node on the main sprite texture to get it's resolution

steel notch
#

And it looks like the pixels always match.

#

I just wanted to try a different mapping for the colors.

#

It was the attempt at adding distortion that's mucking it up.

paper loom
#

hi can I ask the default value for getpixels?

#

I declare Color[] pixels = _templateDirtMask.GetPixels();

#

but getting NullReferenceException: Object reference not set to an instance of an object

#

I already tried GetPixels(0, 0, 0, 0);

steel notch
#

Preferably I'd like it to be like there's a "filter" over the mask, always forcing its color pattern to match the pixels of the sprite.

regal stag
# steel notch

Rather than using a Lerp here, to handle the distortion I would Multiply the noise output by a small value (like 0.01, I guess can use the Distortion Intensity property for this) then Add it onto the other Multiply you already have

#

I think you'd need to handle the pixellation before applying that distortion though

steel notch
#

ya I just realized that

regal stag
regal stag
steel notch
#

@regal stag

paper loom
#

*values

primal basin
#

Hey, how do I sample from texture array while using ddx and ddy derivatives in URP?

e.g.:
`float2 dx = ddx(UV);
float2 dy = ddy(UV);

float4 sample = SAMPLE_TEXTURE2D_ARRAY(array, sampler, UV, index, dx, dy);`

The usual function SAMPLE_TEXTURE2D_ARRAY doesn't have the dx, dy parameters. :/ Does any other function exist?

regal stag
primal basin
#

all I was missing was the simple _GRAD

#

cheers!

regal stag
honest bison
#

How do I find "RotateAboutAxis" for CG shader?

steel notch
#

When you're making a subgraph, how do you make it so your Vector1-4 adapt based on the input?

#

Like the multiply/add/subtract nodes?

regal stag
regal stag
honest bison
honest bison
#

I'm recreating the world space View Direction in CG but getting a different result.

#

nm, I got it now.

cursive swift
#

Im trying to write up some code for blending two or more normal maps together.

I already have the section of code planned out for blending the normal maps, so that part is not an issue.
The part im a bit stuck with is how to implement it.

#

cause I could have it all run on CPU and go through each pixel of a baseMap normal map and a detailMap normal map, but this is pretty CPU bound.

or i could have it implemented on the GPU, but in not sure how then i could retrieve the normal map after it has been calculated and keep it referenced in code.

#

Cause if i had it implemented as a material, it would have to perform that normal map combination each rendered frame right?

kind juniper
#

You could blend them in a compute shader and output as a new render texture@cursive swift

cursive swift
kind juniper
#

No. Blit is for rendering to the render target with a normal shader. While you could do it too, compute shader way is way more straightforward.

cursive swift
#

ah okay

#

Ill read up on compute shaders then

#

Thank you @kind juniper !

cursive swift
#

what are some good resources for compute shaders?

#

im scratching my head a bit at how to get started with it

kind juniper
gentle river
#

I want to render healthbars for units in an RTS-like game, above the units heads, with a "pixel aligned" healthbar. Ideally, the healthbars are always the same scale and have a perfect 1 pixel border around them. Am I correct to believe a fullscreen shader writing using screen space could achieve this effect? Or would it be better to use the common quad with healthbar shader approach, yet somehow achieve pixel perfect alignment?

If it's possible in a shader, would it also be possible in Shader Graph? Following some advice on the forums I was able to create a Texture2D with the positions of the units and their health values encoded into the image. However, I am unsure how to take that data and turn it into meaningful healthbars.

If anyone can help shed some clarify on the subject and recommend an approach I would be super grateful! Would honestly love to hear solutions to both approaches if anyone has any ideas. Thanks.

orchid tusk
#

Im running 2022.1.16f1 HDRP. Is the tessellation feature not working when creating a new shader, or am I missing a setting aside from checking the Tessellation box under Surface Options?

sharp ginkgo
#

anyone know why there's an oversized black version of my asset surrounding the asset when applying a material/shader?

#

both of these are the same asset but the one on the right was exported from blender and the same material doesn't work on both

cursive swift
#

what are the export settings in blender?

#

also does tex2D work on mac os in metal?

patent plinth
#

that's the outline effect, it's just oversized....

cursive swift
#

im getting this bug when I added a tex2D in my compute shader:
cannot map expression to cs_5_0 instruction set at kernel

kind juniper
#

Doesn't sound like hlsl

cursive swift
#

did i mix up hlsl and glsl?

#

heck

kind juniper
#

Probably.

#

Compute shaders are written in hlsl just like SRP shader code.

cursive swift
#

its been a bit since a last wrote a shader

#

for HLSL, I need to use samplelevel to then get the colour from the texture

#

though im not sure what samplerstate is

kind juniper
#

No, you don't need that In a compute shader. You access texture pixels as a 2d array.@cursive swift

#

You should be using the thread id for that.

#
Texture[id.xy]
cursive swift
#

omg that is so much more simple

scenic cobalt
#

hello, is there a template for a material shader that includes Diffuse map / specular / glossiness and normal map?

kind juniper
scenic cobalt
kind juniper
#

Glossiness is the other name for specular, is it not?

#

Or rather a different workflow to specular but fulfilling the same function.

scenic cobalt
#

glossiness is inverted roughness

#

in my case

#

specular is reflections

kind juniper
#

Inverted roughness is reflections though.

#

You're talking about the same thing.

scenic cobalt
#

I need this to preview my meshes before I import them in bundles

#

escape from tarkov uses this maps for their meshes

#

they have a glossiness map a diffuse map and a normal map

#

and the difusse map has glossiness in its alpha channel

kind juniper
#

Glossiness is just the alpha channel of specular. It defines surfaces that reflect light.

scenic cobalt
#

they output different results tho

#

okay so I use diffuse and specular and normal map in unity

#

it looks nothing like in the game

kind juniper
#

Then you're using them wrong.

#

Gloss map is probably just 0-1 in all the channels. In unity it needs to be packed into the specular map alpha channel(every other channel in it needs to be 0 I think).

scenic cobalt
#

so I still have to use glossiness map?

#

In the game they use diffuse map and in the diffuse map the alpha channel is the specular

#

and normal and glossiness are its own textures

kind juniper
#

Then they you'll have to rearrange the channels.

#

Alpha in diffuse is usually used for transparency in unity.

#

And specular is responsible for reflective surfaces.

#

Point is: you need to understand what they use how in their shaders. then you'll be able to map it to the standard shader or your own custom shader.

kind juniper
scenic cobalt
#

Thing is

#

I need this shader to preview my mesh before importing

#

So using a certain workflow with alpha channels for unity

#

Then making another set of textures that use different alpha channels

kind juniper
#

Then write your own.

scenic cobalt
#

Would defeat the purpose

#

So Its possible to make a shader that take those maps separately?

#

As their own textures

#

Not as alphas

#

So a shader that would take specular diffuse glossiness and normal all separately in a different map

#

Because that's how substance painter outputs them

kind juniper
scenic cobalt
#

So I guess the standard shaders already split the textures

#

But from alphas

#

So I should configure it that it would take separate images as the glossiness

clever saddle
#

What's wrong with my code(see 2nd picture)? I have a square and I want the all the vertex inside the sphere(less than radius) extrude out(see 1st picture).But effect looks wierd(see 3rd picture).The _Offset is obj's pivot(2nd picture)

kind juniper
clever saddle
#

I actually wanna make a trampoline with hollow and raised.I was trying to test it in x axis

kind juniper
#

Do you have enough vertices there?@clever saddle

#

It doesn't seem like you have any vertices in the center, so only vertices at the top are affected.

clever saddle
#

Yes,I have.I think maybe I mix up the v.vertex.Does v.vertex represen object position which center is object's pivot?

kind juniper
#

Depends on the shader. Based on the name it should be vertex position in local space.

#

What's your offset is equal to?

clever saddle
#

0,0,0,1

#

Btw.How do u guys debug to check values in unity shader?

kind juniper
kind juniper
grizzled bolt
mental bone
clever saddle
clever saddle
kind juniper
kind juniper
#

That's why you should probably share more code for us to understand the context.

#

That being said, I'm not sure if that's the issue, since even if it's 0, it would be 0 for all the vertices.πŸ€”

kind juniper
#

Judging by the screenshot.

clever saddle
kind juniper
#

Are you sure you're not trying to fool us or something?😬

clever saddle
#

Wait

#

I dont

#

Im a beginner.I know my code is confusing...

#

I made a mistake.Uncommented a unnecessary line

kind juniper
#

Honestly, all this math looks questionable to me...πŸ€”

float total_Dist = distance(worldSpacePosition, GLOBAL_ObjWorldPos); //Dist only used for specify which shader is currently working
            if (total_Dist < 3 && GLOBAL_Attachment == 1) {
                float4 new_Dir = float4(1, 1, 1, 1) - abs(GLOBAL_Direction);
                float4 difference = worldSpacePosition - GLOBAL_ObjWorldPos;
                float4 limitedAxisDifference = mul(new_Dir, difference);
                float vertex_Dist = length(limitedAxisDifference.xyz);

                if (vertex_Dist <= _Radius) {
                    v.vertex += (1 - (vertex_Dist / _Radius)) * -GLOBAL_Direction;
                }
                float vertex_Dist = length(v.vertex);
                vertex_Dist = distance(v.vertex, _Offset);
                if (vertex_Dist <= _Radius) {
                    v.vertex += -GLOBAL_Direction * (1 - saturate(vertex_Dist / _Radius)) * GLOBAL_ObjDistance;
                }
            }
            v.vertex.x += (1 - saturate(distance(v.vertex, _Offset) / _Radius));
clever saddle
#

If w is 1,It's the 1st picture

#

If w set to 0,and I increase the radius value.It's like this

kind juniper
#

It does look like your pivot is at the top of the mesh, so all your math is calculated around it.πŸ˜…

kind juniper
#

Open your mesh in blender, recenter the pivot point. And it should work.

#

Somewhat

#

Probably

clever saddle
regal stag
#

If you're doing distance calculations you'd usually truncate down to 2D/3D rather than handling them on 4 components. Can use .xy or .xyz on the parameters to do that.

round patrol
#

When extracting materials from an FBX why does it default to 0.5 smoothness? It's so tedious going through them all and setting the smoothness to zero every time. It's so unnecessary.

leaden turret
# regal stag As I mentioned before, to support SRP batching all Properties in the shader, oth...

@regal stag currently I see these variables defined in Splatmap.shader on lines like this

Properties
    {
[HideInInspector] [TerrainToMeshLayerCounter] _T2M_Layer_Count ("Layer Count", float) = 0        

[Space]
[HideInInspector] _T2M_Layer_0_ColorTint ("Color Tint", Color) = (1, 1, 1, 1)
[HideInInspector] _T2M_Layer_0_NormalScale("Strength", float) = 1
[HideInInspector] _T2M_Layer_0_uvScaleOffset("UV Scale", Vector) = (1, 1, 0, 0)
[HideInInspector] _T2M_Layer_0_MapsUsage("Maps Usage", Vector) = (0, 0, 0, 0)
[HideInInspector] _T2M_Layer_0_MetallicOcclusionSmoothness("Metallic (R), Occlusion (G), Smoothness(A)", Vector) = (0, 1, 0, 0)
[HideInInspector] _T2M_Layer_0_SmoothnessFromDiffuseAlpha("", float) = 0
[HideInInspector] _T2M_Layer_0_MaskMapRemapMin("Maskmap Remap Min", Vector) = (0, 0, 0, 0)
[HideInInspector] _T2M_Layer_0_MaskMapRemapMax("Maskmap Remap Max", Vector) = (1, 1, 1, 1)

Do i need to remove them from this Properties{} section and move them into the CGBUFFER part? or leave the Properties{} and just add them to CBUFFER ?

regal stag
#

But I imagine the shader is also declaring them already somewhere in the HLSL portion / include files which you'd need to remove or there will be redefintion errors

leaden turret
#

ah

#

not sure how to tell / how to identify "the HLSL portion" πŸ€”

regal stag
#

Between the HLSLPROGRAM and ENDHLSL tags

leaden turret
#

got it thanks

leaden turret
kind juniper
#

There's probably gonna be no difference. I think many GPUs don't work with int, so they simulate them with floats. Or so I heard.

leaden turret
#

i thought it was something like that... so int might end up being float anyway sorta thing

kind juniper
#

From my understanding yes

regal stag
#

If they define it as int, probably safer to keep it at that. I couldn't see where they are defined so just made it up based on the property types.

leaden turret
#

i'm gonna try posting the whole thing on github so the full picture can be clearer

regal stag
#

Unless the asset you are editing is free, I wouldn't share it's code

leaden turret
#

ah

#

well just the shader codes?...

#

temporarily... just to troubleshoot & help fix up this requirement... then delete the repo when we're done...

leaden turret
#

@regal stag these 2DArrays i can leave same as all the 2Ds?

//Texture 2D Array
[HideInInspector] [NoScaleOffset] _T2M_SplatMaps2DArray("SplatMaps 2D Array", 2DArray) = "black" {}
[HideInInspector] [NoScaleOffset] _T2M_DiffuseMaps2DArray("DiffuseMaps 2D Array", 2DArray) = "white" {}
[HideInInspector] [NoScaleOffset] _T2M_NormalMaps2DArray("NormalMaps 2D Array", 2DArray) = "bump" {}
[HideInInspector] [NoScaleOffset] _T2M_MaskMaps2DArray("MaskMaps 2D Array", 2DArray) = "white" {}     ```
regal stag
leaden turret
#

ok

sharp ginkgo
patent plinth
#

most probably you're not using the standard 1 scaling for all objects... the 1 there is just an example, it can be any number that you'd consider as standard or default value in your project

#

like, each one of them has a different scaling when importing

#

also make sure to apply the transform when exporting from the 3d software you're using, for example Blender hit ctr+a then select all transform everytime you change the transform value there

#

the when exporting, toggle on the Apply transform in Blender export settings

sharp ginkgo
#

ok i'll take a look at that, thanks you for your help!

sharp ginkgo
patent plinth
#

goodluck

leaden turret
#

@regal stag initial success 🀩 testing now, let's see if this works...

#

aaand yes it works πŸ™Œ

#

please share link where I can send you some beer πŸ˜„πŸ™

leaden turret
#

hm now after attempting a build i see an error...

#

maybe i didnt do this part right...

#

how do i properly remove these definitions from a .cginc so that i can define them in CGBUFFER ?


#if defined(_T2M_TEXTURE_SAMPLE_TYPE_ARRAY)
    
    #define T2M_DECLARE_LAYER(l)                float4 _T2M_Layer_##l##_MapsUsage; float4 _T2M_Layer_##l##_uvScaleOffset;   float4 _T2M_Layer_##l##_ColorTint; float4 _T2M_Layer_##l##_MetallicOcclusionSmoothness; int _T2M_Layer_##l##_SmoothnessFromDiffuseAlpha; 
    #define T2M_DECALRE_NORMAL(l)               float _T2M_Layer_##l##_NormalScale;
    #define T2M_DECALRE_MASK(l)                 float4 _T2M_Layer_##l##_MaskMapRemapMin; float4 _T2M_Layer_##l##_MaskMapRemapMax;

#else

    #define T2M_DECLARE_LAYER(l)                TEXTURE2D(_T2M_Layer_##l##_Diffuse);   float4 _T2M_Layer_##l##_uvScaleOffset;   float4 _T2M_Layer_##l##_ColorTint; float4 _T2M_Layer_##l##_MetallicOcclusionSmoothness; int _T2M_Layer_##l##_SmoothnessFromDiffuseAlpha;
    #define T2M_DECALRE_NORMAL(l)               TEXTURE2D(_T2M_Layer_##l##_NormalMap); float _T2M_Layer_##l##_NormalScale;
    #define T2M_DECALRE_MASK(l)                 TEXTURE2D(_T2M_Layer_##l##_Mask);      float4 _T2M_Layer_##l##_MaskMapRemapMin; float4 _T2M_Layer_##l##_MaskMapRemapMax;

#endif
#

do i move this entire block as-is into the CGBUFFER ?

oblique cloud
#

posible to get the root bone transform?

grizzled bolt
leaden turret
#

@regal stag in Variables.cginc there are calls to this "T2M_DECLARE_LAYER(x)" passing in a number i think 0 to 15, how can i get Variables.cginc to use a #define from the CGBUFFER ?

oblique cloud
grizzled bolt
# oblique cloud yes, is it possible or no?

Not generally within the shader
Amplify can access object scale, and Shader Graph can access object scale and position, but I don't know if those have equivalents in manually written shaders
You can use scripts to get any transform values and pass them to the shader using properties though

west cobalt
#

Hello folks. I am kinda new to shader coding. I figured that with urp we port cg to hlsl. Most of the materials i find online and also a lesson that i took utilise cg. Should i stick to cg or learn hlsl although i can't find the proper functions of it. If so, how can i find documents about hlsl functions or variables ? Thanks in advance.

wary horizon
west cobalt
#

Ah sorry

sudden bough
#

Hi everyone ! I'm new to shader and I need to modify a shader to single pass instanced. I can't figure out witch part is broken in my code. I should have these bloody stains:

#

But I only have this red weird looking :

#

This is the old code and the new code with my changes :

faint estuary
#

Why does rendering a terrain with an Unlit shader make it not render at all?

lean lotus
#

hey so im doing this to read from a raw index buffer in a compute shader, but this only works if the index buffer is 32 bit
How do I make it work with 16 bit?
uint3 vidx = uint3(bufIndexes.Load(idx * 12), bufIndexes.Load(idx * 12 + 8), bufIndexes.Load(idx * 12 + 4)) * 10;

tight phoenix
#

having a problem with this - Length stays anchored at the correct position, but add/add as I rotate the mesh, the effect gets brighter/darker

#

I think its because when its rotated the positions are sometimes +/+ or +/- or -/-

#

but I have no idea how to fix that

#

what I want from it is the effect to not be circular

#

hrm now its behaving completely differently and I dont know why

#

im back at a place where I have no idea how to do anything and no idea why anything is behaving the way it does and all I can do is delete all of it and start over, im too lost to solve this

#

huge fucking mess that does nothing of what I wnat it to do and I have noi dea what im doing because im fuckiung stupid

#

I want square, I have circle

#

its incredibly painful and difficult to obtain square

#

I cant even remember what I was trying to solve with this stupid piece of shit to begin with

cursive swift
#

what could i do to create a system where i can merge together several layers of textures into one texture?

kind juniper
cursive swift
#

oh it worked well

#

just thinking of other sections I need to work on now

#

and also thinking of how to detect when the compute shader is complete

#

I know compute shaders arent really set up for that, but it would be good to be able to get something to happen once the rendertexture has been updated

kind juniper
cursive swift
#

I guess i could work around that

#

I could use the render texture as is for the normal map

#

I still need to though create a compute shader for combining multiple textures into one texture

#

I should explain that im making something where i can add a lot of normal map details to an object.

#

the part i started yesterday was overlaying a detail normal map over a base normal map

#

but today i need to get multiple base maps put together to make one base map

kind juniper
winter timber
#

ive wondered, what is the difference between a shader graph shader and those .shader files, is one faster than the other, can one do more things, or are they just different ways of doing the same thing?

kind juniper
winter timber
#

ok fascinating! Thanks a ton!

tight phoenix
#

How can I remove the line running through the center of my cross product?

#

I would like it to be softer πŸ€”

#

im trying to get a mask that runs different from the direction of the light

#

specially like all of this is XY

#

I want to emphasize the face from this angle and this angle alone

#

its fine from other angles but it vanishes from directly on the side

#

I cant figure out how to emphasize it from the side, I though getting some kind of mask that runs like 90 degrees different from the light direction would work?? but I dont know how to get that

#

I tried to use just SOME of the cross product channels, but since the light and the object can rotate, I can't reliably select just the ones I want, from certain rotations that changes

#

same cross product, completely different chanels because the cube itself is rotated

#

this has what I need, but only when rotated a certain way, how do I only get this no matter what rotation it has?

cursive swift
kind juniper
cursive swift
#

okay, ill keep looking into things for it

#

Thank you for all the help!

#

I can probably figure out the matrix transform with enough time

tight phoenix
#

none of this is working, I can't solve this without help

#

how do I emphasize the backfaces that are barely visible? I cant figure out how to make some kind of mask that ONLY highlights just that portion

#

I need a dot product that is 90 degrees rotated from this

#

but that also works no matter what rotation the light or object are

#

no matter what I pipe into rotate, it never rotates

#

not to the way I want, not to anything

#

I wish I wasnt so stupid that i can't solve a single thing without help :/

#

im just going to keep posting my failures until I manage to solve it since I can do literally nothing else

#

this works in this ONE single rotation

#

but I can't figure out how to make it account for the rotation of the object and the light

#

its only working because they happen to align in this exact moment

#

but in practice I dont have that kind of control

#

do I need to get the rotation of the object somehow???

#

I guess the third vector is the camera view direction?
some combination of the light direction, the view direction, and the box direction will give me a 90 degree rotation of the light's direction?????

#

this didnt work

winter timber
#

how do i have a default colour input for things to interact with, like how base map automatically takes the colour from the particle system?

kind juniper
winter timber
kind juniper
winter timber
#

how do i set it to be the base?

tight phoenix
#

through blindly plugging things together I think i might have actually got what I wanted πŸ€” sorta, its kinda messy still

kind juniper
kind juniper
winter timber
#

yes i know

#

i dont know how to set it, cause usually with default shaders they set themselves, how can i set my shader to act like that

kind juniper
tight phoenix
#

How do I get rid of this roundness? it doesnt exist in the UVs

winter timber
kind juniper
winter timber
#

ok ill try that, thanks!

kind juniper
winter timber
#

ok thanks

#

ok giving the same name didnt work, guess whatever magic the default shaders use is not possible on regular shaders, guess ill have to try set the materials manully using dots in some way to save performance

tight phoenix
#

moving away from getting itworking again

#

I'm guessing ive been shadow banned or something since it seems like not a single person has seen a single one of my posts?

kind juniper
winter timber
kind juniper
winter timber
#

how do i get vertex colours?

kind juniper
#

Is it a shader graph?

winter timber
#

yes

kind juniper
#

Then I think there's a vertex color node

winter timber
#

thanks so much!

tame topaz
kind juniper
hollow wolf
#

hey, so i already create shader which make obj disappear on certain direction, and i want to assign it to my textmeshPro,but there's problem, the text now is broken, did anyone know how to fix it? thanks

vocal narwhal
#

Don't change the text material. It should be using Text Mesh Pro materials, or else it will not function.

#

Just change the Debug Settings of the actual text material. The Cull Mode can be set to Back

vocal narwhal
#

yes

hollow wolf
#

yes, that's what i did, but it's still broken

vocal narwhal
#

Don't change it's shader. Don't change the material to anything else. Just change the Debug Settings on the original material.

hollow wolf
#

ahhh, ok thanks for the info

fervent flare
#

Anyone know if there's a way to organise shadergraphs in their own category, outside of the general 'shadergraphs' category in the drop down list ?

eager folio
#

Is there any documentation on the SpriteMask node? Or, alternatively, anyone able to explain how to use it?

regal stag
fervent flare
#

Amazing!!

karmic hatch
# tight phoenix How can I remove the line running through the center of my cross product?

what are you doing the cross product between?
It looks like at some point, one of the components of the product becomes zero and since you're doing an absolute, that leads to a discontinuity in the derivative of that component. Maybe try putting the abs() value to some power to smooth it out, or do something like (v^p + d^p)^(1/p) where v is the output of the absolute node, p is some power, and d is the width over which it's damped

haughty moat
#

Workflow question. I can create render textures for use in a compute shader through code but I'd like to use a serialized one so I can have it referenced in the scene by a UI component. Only the serialized texture isn't randomwrite enabled (I get Attempting to bind texture as UAV but the texture wasn't created with the UAV usage flag set!) and I can't change it without making a new one. Is there a trick to get both the serialization and a correctly setup texture. Or is there a "non-random write" way I can write to this texture that would comply with whatever settings the serialized textures are created with (I assume these texture can be written to by the renderer somehow)?

kind juniper
haughty moat
pallid prism
tight phoenix
#

I havent been able to mock up a descent example of what im trying to mean

#

This is what I mean

#

but the above was made by brute force copy pasting and offseting the same set of UVs, and only works for those 3 faces, I'd have to copy it 6x times to cover all rotations

hot lagoon
#

why is this happening?

#

i'm not using URP or HDRP

tight phoenix
tight phoenix
hot lagoon
#

it's shadergraph but not URP

hot lagoon
#

appears trough other faces too

blissful marlin
#

does anyone know how I could approach having backfaces culled, while still obscuring the geometry behind them?

tight phoenix
shadow locust
#

(note i have no idea how to actually do that)

grizzled bolt
karmic hatch
# tight phoenix Panzer, would it be non-trivial to reflect the interior cubic UVs so that you es...

Probably the easiest way would be to calculate the cube normal (so if the position is (x,y,z), get the component with the largest absolute value, and for the cube normal set that component to sign(component), and set all the others to zero), subtract the cube normal times either one or two (depending on how everything else is doing the geometry, whether it's assuming a 1x1x1 or 2x2x2 cube) and then redo the calculation to find the next face along the ray

karmic hatch
tight phoenix
karmic hatch
#

Sign, not sine

#

Sign(x) is -1 for x<0, 0 for x=0, and 1 for x>0

#

The repeat comes in by subtracting the cube normal, which basically brings you back from the bottom of the cube to the top, so you can go through it again

leaden turret
#

i was just going to ask about how to make a water shader

#

but i think i want something slightly less intensive / slightly less realistic / as optimized & "barebones" as possible

#

basically trying to mimic this good ol' classic

#

while i'm hoping to achieve as close as possible effect, i am trying to target mobile so ideally keeping things as dumbed down and performant as possible

#

unfortunately i don't know the faintest thing about shaders... maybe i'll try working on this in phases, first maybe trying to figure out how to do the nice reflections, then maybe how to do the rather mild water movements, then maybe the shoreline waves effect

#

any ideas / guidance how to get started would be greatly appreciated πŸ™

karmic hatch
#

btw one very important thing I've found, if you have water that uses the background color to some extent, don't just lerp between background color and some water color with the depth (or exp(-depth) if you're being fancy); if you do that, it looks like paint. You have to multiply the background color by exp(-absorption color * water depth) (or similar). One mimics scattering off colored particles (paint), the other mimics absorption (as in real water).

leaden turret
# karmic hatch https://github.com/Unity-Technologies/BoatAttack maybe try looking at the water ...

i was actually looking at that, also the video tutorial about it https://www.youtube.com/watch?v=gRq-IdShxpU

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
leaden turret
# leaden turret basically trying to mimic this good ol' classic

but it still seemed kinda.... advanced-ish? i didnt know if i would reach the desired effect as in this clip πŸ‘† by starting from this tutorial and then trying to subtracting/remove effects & parts that i dont want or need, OR if maybe it would be more direct to build bottom up, effect by effect, until i have just what i need

#

2 example concerns;

  1. does the tutorial have reflection of landmasses as in my clip above? i dont know if it does..
  2. does the tutorial have fancy/realistic water waves? i think i need much simpler ones to achieve the effect as in my clip above
karmic hatch
#

I would suggest 1) calculating the depth through the water, 2) multiply the scene color by some base value (corresponding to the light reflecting around inside the water plus the sun intensity), multiplied by exp(-absorption * depth through water), 3) sample some normal maps to create waves and move them around over time, 4) use a reflection probe to get reflections off the surroundings, 5) make a mesh with the shorelines painted with UVs (in the vertex colors perhaps) so you can easily paint some waves on top.

leaden turret
#

ok i am copy-pasting these instructions into a notepad for further studying and learning

leaden turret
#

now my mission is to start having the faintest clue about what is being explained πŸ˜„

karmic hatch
#

btw the absorption color would be reddish orange, rather than blue, because you want red to drop off quickly with depth, and blue to remain.

leaden turret
#

(just taking some very wild guesses here, really have no clue what i'm talking about...)
is #2 absolutely necessary? maybe just working with blue is good enough? does it look like the clip i posted must be using "scene color corresponding to light reflecting around the water plus sun intensity" ? or maybe they just used some static value without calculating it from the scene

karmic hatch
#

(just a light bluish, probably HDR with intensity a little bit >1)

leaden turret
#

either way my main concern about that is performance/overhead. if these calculations are unbelievably trivial even for mobile then i guess i dont mind doing those additional calculations. but if it has even a little bit of significant/noticeable performance boost, i need less realism and more performance

#

ah its not very expensive ok

#

@karmic hatch you seem to know about all this, i'm getting the impression that with your help i might even be able to achieve this. any chance you up for some consultation / DM? sometimes it's a bit frustrating to work on something a bit but then the expert is no longer available in chat for unknown time / time zone / weekend etc..

#

for pay of course

karmic hatch
#

I'm not much of an expert, I just like messing around. Feel free to DM me whenever

leaden turret
#

πŸ™ very kind of you, thanks!

karmic hatch
#

In the boatattack one it looks to me like they sample from a texture to do the absorption and scattering rather than calculating it

#

which makes sense

leaden turret
#

aha

#

as always perfromance-concerned me wants to know; is any one of those less intensive than the other?

karmic hatch
#

Tbh I'm not sure

#

Found this slide mentioned in a unity forum post

#

(presentation is titled 'Bringing AAA graphics to mobile platforms')

#

On mobile, texture sample probably takes as much as "several to several dozen simple math operations".
On PC, the ratio is higher, for one texture sample you can afford dozens to hundreds of math operations.
another guy under the same forum post

#

someone on another forum claimed exp2() costs around 4-8 addition/multiplication operations (exp would cost one more and any difference could be absorbed into the absorb color)

leaden turret
#

not sure what these amounts "4-8 addition/multiplication operations" mean, on one hand they sound incredibly trivial, whats a few multiplication ops to a processor/GPU? but on the other hand if that happens each frame each vertex or something... i guess now it could get exponentially expensive

karmic hatch
#

it seems you mainly just want to keep it relatively compact, and avoid stuff like loops

leaden turret
karmic hatch
#

true, though I don't think they would be

scarlet crater
#

I was trying to implement a fresnel effect in a geometry shader, and it works as expected. EXCEPT for when the object is rotated

#

I have a feeling that this is something super simple that im just glossing over but i've been staring at this for about an hour and nothing is clicking

karmic hatch
cursive swift
#

is there a way to multiply a normal map by a quaternion to apply a rotation to the normal map?

#

cause a normal map is just an image of tangents isnt it?

#

so a quaterntion multiplication should be able to rotate those tangents around to their correct position

scarlet crater
#

I think i know how to fix this though

#

but, thanks for the help anyways lol

lyric copper
#

Anyone know of anywhere I can find an outline shader that draws the edges of a cube and not just the silhouette?

#

Wireframe doesnt work because it draw the tris

scarlet crater
#

or both, i believe some shaders combine the two but im not sure

lyric copper
#

Oddly enough I cant find an asset for it either. Seems like a pretty common ask

scarlet crater
# lyric copper Oddly enough I cant find an asset for it either. Seems like a pretty common ask

if you are keen on trying to do it yourself, heres what looks to be a pretty good guide on how to put one together.
https://roystan.net/articles/outline-shader.html

#

its got a github source repo linked towards the bottom, as well

keen patio
#

if I have 1 material/shader, and many objects with same 3D mesh,
but they have independent material data, how to render it with 1 drawcall?

#

there's only 1 texture, but material params are different. (the roughness, metal)

cursive swift
#

What do i have wrong with this code here?

`// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain
#pragma kernal MultiQuat
#pragma kernel RotateVector

// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
RWTexture2D<float4> Result;

// The normal map that will be rotated
Texture2D BaseMap;

// The amount it will be rotated by
float4 Rotation;

[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
Result[id.xy] = RotateVector(Rotation, (BaseMap[id.xy] - 0.5) * 2);
}

// Quaternion functions

// Summary:
// This function multiplies a quaternion by another quaternion.
// Parameter q1: Quaternion 1
// Parameter q2: Quaternion 2
float4 MultiQuat(float4 q1, float4 q2){
return float4(
q1.w * q2.x + q1.x * q2.w + q1.z * q2.y - q1.y * q2.z,
q1.w * q2.y + q1.y * q2.w + q1.x * q2.z - q1.z * q2.x,
q1.w * q2.z + q1.z * q2.w + q1.y * q2.x - q1.x * q2.y,
q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z
);
}

// Quaternion functions

// Summary:
// This function multiplies a quaternion by another quaternion.
// Parameter q1: Quaternion 1
// Parameter q2: Quaternion 2
float3 RotateVector(float4 quat, float vec){
float4 qv = multQuat(quat, float4(vec, 0.0));
return MultiQuat(qv, float4(-quat.x, -quat.y, -quat.z, quat.w)).xyz;
}`

#

cause im trying to run this compute shader to test out the shader, but im getting errors with the kernels

#

i know the comment for the last function is wrong, i just copied the last functions comment format.

#

wait i know

#

sorry

#

the functions have to be put in order of usage

cursive swift
#

got it working

#

!!!

#

just need to get a render texture to work right with it

#

the script works well with a new one, but doesnt work well with a pre made one

tiny quarry
#

im doing research for a face customisation system in unity URP, with the option to mix and match eyeshadow, eyebrows, lipstick, face paint. What is the best way to go about allowing a player to mix and match all these? is it better to use a single shader with lerps for the head, or just have planes floating on the face and use different materials with alpha blend for each face part?

cursive swift
#

what does this mean?

Compute shader (NormalRotationShader): Property (Result) at kernel index (0): Attempting to bind texture as UAV but the texture wasn't created with the UAV usage flag set!

merry rose
cursive swift
#

trying to pass a render texture

#

but I cant set the read write on it

#

I cant see where to do that in editor

#

and I cant do it in code

long moat
#

Hello! Is it possible to create a shader in built-in renderer that displays something that is not there, for example a forrest outside the windows

#

the closest thing i could find is the spider-mans fake interior shader, but it displays a limited space

merry rose
merry rose
long moat
dim yoke
long moat
#

ill try to draw it to explain better πŸ˜…

long moat
#

it needs to sort of fake extension of the current um.. biome?, once the player passes this wall, they see that it was fake

karmic hatch
long moat
#

one way i see how i can achieve this is by masking what to show through this wall, but im not sure how to instruct the camera to render specific objects through this shader

#

if there is a more performance friendly approach, i would love to hear it

strange roost
#

https://www.youtube.com/c/t3ssel8r, https://assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/propixelizer-177877 Would this kinda style work with a perspective camera instead of an isometric one? My main concern is pixel creep, the object changing when you move around it, etc. Is there a workaround to make it work?

Add depth to your project with ProPixelizer asset from ElliotB256. Find this & more VFX options on the Unity Asset Store.

hot lagoon