#archived-shaders

1 messages Β· Page 9 of 1

tight phoenix
#

i just hqave no idea how to translate its result into representing thin film iridescense

#

his only makes the bottom while thin film needs the top

#

maybe I can just lerp it with grey???

#

I got abunch of charts of what im 'supposed' to see

#

pretty close tbh

molten jasper
tight phoenix
#

atomic

#

is that from the colors being way too high, or is that bloom post proccessing?

molten jasper
#

it's because I set the film layer index to like 7

tight phoenix
#

oh geez

molten jasper
#

Soap bubbles have very thin walls. The range can be anywhere from 10 nanometers at the top of a thin-walled bubble to over 1000 nanometers

#

It's 00:28 here

molten jasper
#

brit moment

tight phoenix
#

Ah yeah im five hours behind, that lines up with UK on the ol' timezones of the world

molten jasper
tight phoenix
#

oh yeah that's the same page isnt it πŸ€”

tight phoenix
# molten jasper

That result is real good, glad to know this will work in the end πŸ‘€

molten jasper
#
Soap Bubble Wiki

The colors of a soap film provide a precise measurement of the film's thickness. The relationship between the colors of a soap film have been well known for more than a century. In fact, these colors provided important evidence in confirming the molecular theory of matter. The color charts on this page mapping color to thickness were prepared by...

#

soap bubble fandom wiki lmao

#

I think the thing I'm missing here is how to actually use the result of the thin film since I can't just plug that straight into the base colour

#

Ok I sleep, 02:10. Will post the shaders tomorrow

tight phoenix
#

there are neiches everywhere

#

wow this is actually really useful info too

tight phoenix
modest zealot
#

Thanks for the detailed response. I'm on built-in pipeline.

So the reason I'm trying to use this instead of an actual transparency is twofold: first, when used on something like a door. This reversed reflection probe can be used to disguise level loads while making it appear that the scene on the other side has loaded. Second, used in an object, it could be used for liquid/glass effects without any significant addition to draw overhead because it's pulling from the already-implemented reflection probes in the scene. Essentially It is as performant as a normal metallic object.

I will go pry through the standard shader again...

violet bough
#

is there any way to sample coordinates of a pixel in "screen space" or "clip space" with the addition that it accounts for the movement of the camera? (using orthographic projection)

#

meaning that the coordinates remain the same if we translate the camera

#

if it helps, im trying to do some screen space dithering that moves when the camera moves

#

and it moves in such a way, that the same point in space will use the same dither threshold if the camera hasnt rotated

#

what comes to mind is maybe calculating a projection matrix that doesnt account for translation and using that

molten jasper
#

Won't you want world position for that?

violet bough
#

the problem with that is that the dither pattern will be lost

#

it looks like this if you sample clip space

molten jasper
#

cool

violet bough
#

thanks

#

im making a pixel art renderer πŸ˜…

#

copying tessel8r

molten jasper
#

does look familiar lol. Shame he hasn't released his work

violet bough
#

well there are many tutorials online, but he is currently using a custom render pipeline

#

and his work is just way ahead of anyone else

#

im doing it the same way

#

but it's hard

#

i might release some tutorial or the codebase when im done doing the most important work

#

though i get why he hasn't released his

hallow plover
#

is there a way to generate perlin noise in hlsl shaders?

amber saffron
molten jasper
# molten jasper

@tight phoenix lets agree that whoever gets it working shares the result

gray harness
#

how do i read a pixel value from a texture2DArray in hlsl?

karmic hatch
mental bone
molten jasper
karmic hatch
molten jasper
#

additive with what?

karmic hatch
#

It's a blending mode, means it adds onto the background

molten jasper
#

sorry I'm not super familiar with shaders themselves

#

ah, how would I enable that on the urp standard lit shader?

karmic hatch
#

I used shader graph and it's in the graph inspector

molten jasper
#

Is yours a physically based thin film shader?

karmic hatch
#

Not entirely physically based (I don't calculate the phase offset properly using the thin film stuff) but the colors should be the same as you see in irl films and it does have similar properties

molten jasper
#

wondering what refraction indices you use for outside, film, and inside

karmic hatch
#

No refractive indices, just a remapped Fresnel multiplied by some noise

molten jasper
#

ah ok

molten jasper
# molten jasper

you can see my attempt above. I'll need to change the alpha to use dot(view, normal) which is listed as the value of cos0 in the related paper. Then I'll need to update the alpha blending to use additive

karmic hatch
#

Is that entire mesh transparent?

robust drum
#

Hi, does anybody know if there's a way to make a single channel tileable from the Sample Texture 2D node from Shadergraph?

regal stag
robust drum
clever saddle
#

I got an error when upgrading the project material to URP.Some of them succeed but only shader with "Animmal/" directory failed

regal stag
molten jasper
gray harness
#

please anyone knows how to read from Texture2DArray in hlsl? or have link please?

clever saddle
regal stag
quick cape
#

How do I use my Compute Shader as a Material on my 2D urp?

violet bough
# molten jasper Won't you want world position for that?

I did it after quite some time, using this

output.ditherCoords = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_V, output.positionWS)) * 0.5 + 0.5;
output.ditherCoords.xy /= output.ditherCoords.w;
output.ditherCoords.xy /= 2;
output.ditherCoords.x *= _PixelW;
output.ditherCoords.y *= _PixelH;
#

now the dither coordinates stay fixed in place when the camera moves

molten jasper
#

cool

clever saddle
regal stag
# clever saddle I still have no clue.Does it mean if there're already some costum shader in the ...

You cannot use URP and the Built-in pipeline together. They are separate pipelines that change how rendering works.

If you have custom shaders that are written for the Built-in pipeline, they won't work in URP. You would need to find a custom shader that is written for URP instead (e.g. on the Unity asset store, or write your own in shader graph)

If you have lots of custom shaders, it may be easier to stick with the Built-in pipeline.

regal stag
quick cape
#

Oh I was doing this already, I'm just not sure where that goes, following a tutorial

#

Checking your link, thank you!

#

Oh gosh, what's a Kernel..? '^^

gray harness
quick cape
mental bone
#

Or dispatch

regal stag
quick cape
regal stag
#

Ah yeah, your renderTexture in your code

mental bone
quick cape
#

As my material for my Canvas

#

This one's using a.... Um... Shader..? I don't.. Really understand yet!

#

I mean duh, shader

#

...I am not sure what it's using '^^

mental bone
#

Raw image can take in a render texture directly no?

quick cape
#

I don't.. Know!

regal stag
#

They're creating the Render Texture in the script, so would probably need to use something like GetComponent<RawImage>().texture = renderTexture;
Might need using UnityEngine.UI at the top

quick cape
mental bone
#

Ok no need to get upity with me

#

I was just about to suggest that

quick cape
mental bone
#

Then again a mandelbrot seems to be already rendering from the material so not sure what the end goalnis here ?

gray harness
quick cape
#

I want to use a ComputeShader instead

mental bone
#

I feel like you have a normal pixel shader that renders a mandelbrot and a compute shader that does the same

quick cape
#

The Mandelbrot's a .shader

mental bone
#

So remove the material from the raw image

#

And do what cyan said

regal stag
#

I guess they might want to switch because the compute shader could only need to run once.
Could still bake a texture using the vert/frag version if you were to blit with it though

quick cape
#

Sorry I'm not really following, but I realised I didn't give this as context yet

#

I am outputting a texture here, can I just somehow use it on my Canvas texture?

regal stag
quick cape
quick cape
regal stag
#

Would do it in the Start() function you shared earlier

quick cape
#

Ohhhh that'd give me the Canvas to use in the code..? Hmmm

regal stag
#

It would obtain the RawImage component then set it's texture field.
The "Canvas" itself doesn't have a texture.

#

You'd probably want to also remove your current Material assigned there, switch to a regular UI one

mental bone
#

I feel like you should do some beginner coding tutorials before diving into the world of compute shaders.

quick cape
#

How I can allow things to get passed on n all

mental bone
#

On n all?

quick cape
#

What is your question?

mental bone
#

What does passing things on N all mean to you ?

quick cape
#

For example this issue I am having now. I have a ComputeShader, I am able to compute the actual shader, but I don't know how to pass that data onto the Canvas.

#

To the RawImage

mental bone
#

Cyan told you

quick cape
#

Yes, Cyan did

#

Though I am still having trouble. Checking more!

mental bone
#

Get the raw image component, set its texture field as the render texture you have created

quick cape
#

Yes I have, it's white still

#

Just blank

mental bone
#

Show the code again

quick cape
#

Okay, managed to get it to be blue!

#

The output appears correctly, but it's still blue

#

That's So interesting that you can just .texture =

quick cape
regal stag
quick cape
#

My Unity's Incredibly way too slow when it comes to maximizing it again, probably some Linux related glitchhhh~

#

I'll try to move the .texture up

#

It may be a I do changes and then get the reference

gray harness
quick cape
#

It just freakin takes forever... My code changes shouldn't take 20+ seconds to update, should they..?

gray harness
#

restart unity if you havent tried, it helps me when script assemblies take way too long

quick cape
#

I've tried! Been the same since 2 days ago unfortunately - it was never fast

#

(Since I started Unity)

regal stag
gray harness
#

oh thanks

#

ill try

regal stag
#

There is also Load which would work with pixel coords (int3)

quick cape
#

The texture just does not appear no matter what...

#

Mandelbrot does

regal stag
# quick cape

Maybe the compute shader is setting the pixels to be transparent (alpha = 0)? Not sure.

quick cape
#

Wouldn't the preview show that also, though?

quick cape
#

So preview defaults to full alpha, noted!!

mental bone
regal stag
quick cape
#

Ohhh I see!! Thank you again!!

#

Is ComputeShader.Dispatch used for Graphics.blit?

#

Or do I need it using this approach still?

#

...Seems I do, still trying to understand how this works...

regal stag
#

Not sure what you are referring to

quick cape
#

First, the renderTexture is created

#

Then, the computeShader is assigned the renderTexture and width and height

#

Then Dispatch does ???

regal stag
#

Dispatch executes the compute shader

quick cape
#

....Oh!

#

That makes more sense, thank you! πŸ’•

#

I noticed some fields start with a capital letter - is this the norm?

#

Feels like it could get confusing

gray harness
#

by field you mean "Result"?

#

if its that its just a name @quick cape

#

you can change it to whatever

quick cape
#

Oh yes I know ^^ I'm just wondering if there's any good reason for it to be like that

#

Or all just preference

gray harness
#

Its just the default name of texture in default compute shader not anything special, atleast i think

restive radish
#

I'm trying to make a see through shader that makes anything inside a mesh become transparent. I have tried with a Depth Mask, but it also makes things behind the mesh invisible (not only inside), and I tried with stencil and it also affects objects in front of the object. Does anyone have a hint on how to do that properly?

tight phoenix
#

I am getting an error: 'unexpcted token float at line 27 (which is the X)

#

What can cause an unexpected token float? I can post more of it if that helps

restive radish
#

chat about the line before?

#

is it missing some ; } ) or something similar?

tight phoenix
#

oh you are right there was an opening { missing

tight phoenix
cerulean agate
#

Does anyone know why RealTime reflection is like this in URP? I have a reflection probe with realtime mode. Then the floor is set to a material with Metalic 1 and smoothness 1. It does show a reflect, but not as expected

molten jasper
#

@tight phoenix mornin. Did you see Panzer's implementation of a non-physically based thin film shader?

#

There's no surface film refraction though.

tight phoenix
molten jasper
#

Cool cool, I'll be home in a few

tight phoenix
#

I hit a snag on my end - this guy references a lookup table but doesnt explain what that is or where to get it
Googling it it looks like there are images to sample? but I'm unclear on how to substitute this

#

this is apparently a look up table, but his code doesnt say or show what HIS table looks like so I have no garuntees

molten jasper
#

Yeah I noticed that

tight phoenix
#

going to try to just google 'lookup table for XYZ color coordinates' and see if I can find one Iguess???

#

The CIE 1931 color spaces are the first defined quantitative links between distributions of wavelengths in the electromagnetic visible spectrum, and physiologically perceived colors in human color vision. The mathematical relationships that define these color spaces are essential tools for color management, important when dealing with color inks...

tight phoenix
#

trying to figure out what i should replace lookup[i] with, maybe knowing what comp is will tell me?

#

is an array which is confusing

#

"Since we are calculating from physically based equations, color values are not expressed as RGB, as CG rendering requires, but rather as an intensity at a given wavelength. The calculateIntensity() function above takes a parameter of wavelength Ξ» and returns intensity Ir. In order to generate color values, we will sample Ir for various values of Ξ» at each ΞΈ0. We will apply the resulting values of Ir to a lookup table for XYZ color coordinates, and find the average color, which will be returned."

#

I guess this is like, its returning a value of 510, and we are supposed to know that means green?

#

like in that other tutorial

#

oh wait

#

" // identity of CIE x + y + z = 1, therefore xOut = x / (x + y + z)"

tight phoenix
#

he links this at the bottom

#

and people talking about CIE here, maybe ill find it here

molten jasper
#

Ah yeah I read this post

#

From 2006

tight phoenix
#

I did not find the lookup table there

#

but at least I know thats what I need to find

#

is it going to be a file? a picture? something else entirely like a formula?

#

in here maybe πŸ‘€

#

oh here we go maybe

#

okay it might just be a matrix(3x3)

#

πŸ€” now I gotta find out what 'comp' is

#

comparison maybe? compute maybe?

molten jasper
#

I assume that's just the same as lookup[i+n]?

#

oh btw I think I fucked up the last custom function definition when I was looking at it this morning

#

The corrected should be in the shadergraph asset I provided earlier

tight phoenix
#

I am not skilled enough to make assumptions, I want to do exactly what he has because I know definitively it works

#

when i have it working then ill go back through to look at alternatives

#

damn he doesnt say what 'comp' is anywhere

#

its gotta be a common hlsl thing like 'dot' maybe?

molten jasper
#

got a link?

tight phoenix
#

if this is what you are refering to

#

comp is near the bottom

molten jasper
#

oh yeah this site

#

looked at this one too, love how it tries to download a file

tight phoenix
#

??

#

mine doesnt try to download any files

#

at the top he calls this a 'Maya Texture Animation'

#

so maybe comp is a maya function?

molten jasper
#

I'm not sure, I think it might be an index offset

#

since all three provide the same lookup and then each one takes a different index

#

especially since it's a colour table

tight phoenix
#

Well until I find out what comp is

#

im stuck

#

I dont even know if lookup IS a mateix3x3

#

im just assuming it is because it was the closetst thing I found on his linked pages

molten jasper
#

I know it's an assumption but try

float comp(vec3 colour, int i) {
  if (i == 0) {
    return colour.x;
  } else if (i == 1) {
    return colour.y;
  } else if (i == 2) {
    return colour.z;
  }
}```
#

Or whatever it is

tight phoenix
#

im pretty sure this is it

#

it says compute, its for computing XYZ to RGB, which is what he says he's doing

#

so all that hot garbage on the left must be the comp function??

#

ill google for a code implimentation of that

#

maybe somewhere in here?

#

specifically this

#

ill try to write comp to be this

molten jasper
#

that's an interesting colour space

tight phoenix
#

type mismatch on line 13 πŸ€”

#

what does 100 dot multiply mean?

#

dot product of itself and that multiply or something?

molten jasper
#

100.0f * (tmp * mat)

#

things before and after the decimal point are optional so you can do .1 to do 0.1f or 1. to do 1.0f

tight phoenix
#

nope still type mismatch on that line

molten jasper
#

check the return type

tight phoenix
#

return type is a float

molten jasper
#

float3

#

in that image

tight phoenix
#

oh okay

#

type is STILL mismatch

#

im returning float3 but its type mismatch

#
    vec3 tmp=vec3(
        (c.r>.04045)?pow((c.r+.055)/1.055,2.4):c.r/12.92,
        (c.g>.04045)?pow((c.g+.055)/1.055,2.4):c.g/12.92,
        (c.b>.04045)?pow((c.b+.055)/1.055,2.4):c.b/12.92
    );
    mat3 mat=mat3(
        .4124,.3576,.1805,
        .2126,.7152,.0722,
        .0193,.1192,.9505
    );
    return 100.*(tmp*mat);
}```
#

the original code

#
{
    float3 tmp = float3(
        (c.r>.04045)?pow((c.r+.055)/1.055,2.4):c.r/12.92,
        (c.g>.04045)?pow((c.g+.055)/1.055,2.4):c.g/12.92,
        (c.b>.04045)?pow((c.b+.055)/1.055,2.4):c.b/12.92
    );
    float3x3 mat = float3x3(
        .4124,.3576,.1805,
        .2126,.7152,.0722,
        .0193,.1192,.9505
    );
    return 100.00*(tmp*mat);    
}```
#

my version adapted to hlsl

#

hm i should change c.r g b to c. x y z

#

but iunno if thats the problem

molten jasper
#

I think those are identical accessors. I wonder if the float3x3 has some sort of different operation with mul

tight phoenix
#

maybe something here?

#

looks like they're doing roughly the same thing here

#

ill try copying this one?

molten jasper
#

oh try swap mat and tmp?

#

I don't think matrix multiplications with vectors are commutative

tight phoenix
#

still type mismatch on line 13

#

which is that line

molten jasper
#

is this glsl or hlsl?

tight phoenix
#

no answers online

tight phoenix
#

net says its HLSL

molten jasper
#

try changing the return type to float4?

tight phoenix
tight phoenix
#

no change, still type mismatch

molten jasper
#

hmm

#

try the mul function that person uses?

tight phoenix
#

" mul(x,y) as opposed to using the asterisk operator" will do

#

heyy that worked no type mismatch

molten jasper
#

yay

tight phoenix
#

now the NEXT problem

molten jasper
#

are you able to check the Unity.cginc to see how mul is defined?

tight phoenix
#

his comp uses two inputs, this one doesnt

molten jasper
#

dwai, I'll check later

#

to sate my curiosity

tight phoenix
#

no idea what 0, 1, 2 are doing

#

since we dont have his comp function

molten jasper
#

how are xyz used?

tight phoenix
#

im a parrot, not a human being, I have no comprehension at all what I am doing, I am just trying to copy it directly

#

used like this I guess???

molten jasper
#

colour values

#

So the lookup[i] I think is returning the colour, and then 0, 1, 2 refer to either x, y, or z

#

idk if it does something else internally since we can't check that

tight phoenix
#

:C

#

maybe I can find this guy on twitter and just ask him directly

#

not enough info to find him, too many people with the same name

#

i guess i have to cut my losses and stop again

molten jasper
tight phoenix
#

since it cannot be completed without comp

molten jasper
#

check the headers for the comp def

#

I'll brb 30m, driving home

tight phoenix
tight phoenix
#

composite maybe??

#

rip not this

#

boom found it

#

reading this now

#

well it says what comp is, but doesnt give the underlying code either

#

i cant find an answer on google of what the definition of renderman's 'comp' function is

#

feels like another dead end

#

messaged the renderman twitter πŸ€·β€β™‚οΈ for now ill go look at yours and panzer's implimentations now

#

how far I got before comp stopped me

molten jasper
#

Seems it's just an index accessor

#

So you can replace that with lookup[I].X for example

molten jasper
#

Yup

tight phoenix
#

now it has no idea what 'color' is

#

I know colors can be vector3s

#

but I dont understand the syntax beyond the =

#

why is a name in quotes there?

#

oh great going to have to find out wtf adjustHSV does next too

#

oh huh it knows what adjustHSV is

#

it doesnt know what hueShift and saturation are though, ill just pass in some values for that

#

nope it doesnt know what adjustHSV was

#

it just wanted to complain about saturation and hueshift first

#

highly doubt its the correct function though

#

screw it lets pretend its just HSV adjustments and ignore that all together

molten jasper
#

Won't lie to you, this syntax is bizarre

tight phoenix
#

yeah

#

right now im just outing the color

molten jasper
#

from what I understand tho "color" there is just a float3

tight phoenix
#

and trying to fix the red errors

#

problems on 56 and 51 letssse here

#

its not happy about this being a float???

#

that function returns a float though

#

unexpected token float

#

oh lambda is missing a ;

#

it thinks this is an infinite loop πŸ€”

#

why is this an infinite loop?

#

it should clearly stop after i becomes greater than 81

#

(dont ask me why 81)

#

I also tried this but it still said infinite loop

#

apparently the loop was not infinite

#

it was just too big

#

81 was too big

#

2 is not too big

#

but now gotta debug that

#

well, it makes -a- color

#

its not what I was hoping for, but its something

#

hmm

#

I think NN is wrong

#

because eta0 and 1 never get used

#

and in the code, nn turns into eta0 stuff like
float costheta0 = Ll.Nn;

#

ll nn???

#

iunno what nn is supposed to be

#

I dont like he's passing these out but never uses them

#

that makes me fear there is code that I dont even have access to that is critical

#

nn, normalized normal?

#

nothing changes no matter what I send into Nn

#

nothing changes any time I change n0 1 2

#

I think this entire attempt is another bust

#

dead end does nothing

#

not happy

#

I want thin film intereference

#

but im not skilled enough

#

getting agitated, going to go have lunch

hallow plover
#

does anyone have any guides, tips etc for moving from shader graph to shader code? I tried shader code a few days ago but it seems a lot more primitive and guides are scarce. A lot of nice things you can do in shader graph (such as generating perlin noise or getting view direction uv's) seem to be lacking or really confusing to do in shader code. I am specifically trying to learn hlsl but cg guides also work since they seem simular enough.

tight phoenix
#

oh shit it might just be a values thing πŸ‘€ maybe getting somewhere

tight phoenix
hallow plover
tight phoenix
#

ive learned more about HLSL by doing shadergraph than I ever did from trying to learn HLSL, iunno if that helps you though

#

shadergraph has the 'Custom Expression' node that accepts HLSL

#

so you can learn it as you need it, instead of needing to learn the entire thing all at once

#

hmm it shows it working on the preview, but wont appear on the mesh

#

πŸ€”

#

hmm replacing main light direction with a random vector

#

makes it do a thing πŸ€” but not the right thing

hallow plover
#

I found a usefull video on how to make noise for shaders. Its for gdot and some things may be slightly different sntax wise but its really usefull
(forgot to add the vid) https://youtu.be/ybbJz6C9YYA

tight phoenix
#

progress πŸ‘€

#

its actually doing the thing!!

tight phoenix
hallow plover
tight phoenix
amber saffron
tight phoenix
hallow plover
tight phoenix
#

he's got perlin there, as well as 3d perlin

#

actually on the note of Perlin, I have my own perlin node that can do non-circular distances, lemme find that, posted it here before

#

whoops I meant Voronoi

#

different type of noise

amber saffron
tight phoenix
#

voronoi that can be non circular, and the second one maps UV coordinates into each cell πŸ€”

obtuse zodiac
#

how can i render 2 diffrent things with diffrent colors in 1 camera like layer 1 white layer 2 black

tight phoenix
obtuse zodiac
#

ye

clever saddle
#

Im following the tutorial.This is what I write in surface shader.But the video did in the URP is like.Anyone who knows why?

tight phoenix
molten jasper
#

Is that using the thing we wrote?

tight phoenix
tight phoenix
obtuse zodiac
clever saddle
tight phoenix
clever saddle
tight phoenix
clever saddle
tight phoenix
#

oh you can just right click on it

tight phoenix
#

dragon not included, you have your own dragon 🐲

#

Ive seen that dragon model around before but I couldnt find its source/download, like Suzanne or the default teapot easy to find, dragon not so
Taking lunch now for real now that I have the thin film working

naive mural
#

Hello, what is generally preferrable from performance view? More draw calls or combining multiple shaders into a single one and diverging shader logic based on a branch?

grand jolt
#

How can I make a shader like this in HLSL?

#

You see the shadow reflects itself upon the beams

#

And it looks like you can actually look down and it looks like a bottomless pit

#

Please ping me here if someone can give me an answer. Thanks πŸ˜„

quick cape
#

Omgomgomgomg I got my fiiiirst eeeeverrr ComputeShader drawing what I want it to draw!!!!! Even using a ComputeBuffer!!

#

So excited 😍

molten jasper
#

Feel the power flow through you

#

Now ride my childe and compute!

obtuse zodiac
#

ride my child?

quick cape
#

:3 um

#

I have a small issue~~

#

Can I update my ComputeBuffered in structs inside of my ComputeShader?

#

They don't seem to update

#

I'm trying to modify them like this

#

Any idea why the .pos is back to original on the next render?

shadow locust
#

agents[id.x] = agent;

quick cape
#

Oooooh, thank you!!

#

Omg the example I was using as guidance did that and I thought I was optimizing it!!! :3

#

It's still not working, hmmm

#

Omg

#

Well of course it doesn't work, I am multiplying by an unitialized value, which I assume is 0!!

#

Omg omg omg IT WORKSSSS

#

😍

meager pelican
# modest zealot Thanks for the detailed response. I'm on built-in pipeline. So the reason I'm t...

Well it depends.
I mean, I got to thinking that there could be two ways to interpret your "Works EXACTLY like the standard shader [except]" requirement.

If you want, you can still make custom shaders using Surface Shaders...but they won't have all the bells and whistles of the standard shader...they're customized to the material's needs, no fancy inspectors and such.

So if you want a clone of the standard shader, you'd have to do what we're saying and clone that source and customize it for a general-case uber shader using your new reflection method.

BUT
If you just want "standard lighting, with non-standard reflections" you can use custom surface shaders AND CHECK THEIR SOURCE. Surface shaders are basically code generators that generate vert/frag shaders. So you can inspect the source and then find out where reflections are applied and customize that. It won't look like a standard shader it will look like a custom shader using "standard lighting" if that makes sense.

flint adder
#

anyone knows why my sprites are not showing correctly with a shader

tight phoenix
# tight phoenix

Got time to come back to this now, looking it over its sorta working but there are peculiarities πŸ€”
comparing it to physically based diagrams, the 'thickness' variable seems to be somehow opposite?
using N values eqivalent to IOR of Air, Oil, Water does not produce a gradient that resembles what the math says that should produce πŸ€”

#

the thicker thickness is in the shader, the more bands it adds, and the more vivid it becomes, but according to diagrams that should be the opposite

molten jasper
tight phoenix
#

the value called thickness, as it increases, it does the opposite of that graph of what should happen when thickness increases

#

when thickness is 0, it doesnt look like the top, it looks like the bottom

molten jasper
#

Which implementation are you looking at where it's wrong?

tight phoenix
tight phoenix
molten jasper
#

ah ok

tight phoenix
#

maybe I am misunderstanding how its suppsed to work?

#

the colors are also obviously not right

#

but im not sure how to fix that, I think it must be the lookup table values are wrong

#

it keep having this bland-ish grey tone to it

molten jasper
tight phoenix
#

besides the fact that obviously it doesnt work the way it should

#

all uses of thickness, directly from his code

molten jasper
#

Normally it should be in the hundreds to start showing any difference. It's measured in nanometres afterall

tight phoenix
#

something like this is the expected output?

#

whatever he's doing it works for him

#

some values exposed in his thing

#

I will try these values and then see if I can get his result

#

yeah its just a washed out grey-tan

molten jasper
#

stahp for the lov of gawd

tight phoenix
#

?

#

is that that file you said his kept downloading?

#

I dont get that πŸ€·β€β™‚οΈ

molten jasper
#

weird

#

btw how are you doing alpha?

tight phoenix
#

I'm not

molten jasper
#

ah ok

tight phoenix
#

throwing in a rando cube map still its way washed out

#

so I dont think its transparency is the problem

#

I can just arbitrarily crank the saturation

#

but that isnt physically realistic at all

#

I shouldnt have to post proccess it if its working right

molten jasper
#

right

tight phoenix
#

I dont know what NN is still

#

this is the only thing I have no idea what it is, and thus its possible im giving it the wrong thing here

#

and these dont even get used at all even though he outputs them

#

its definitely not the vector normal normalized

#

that looks completely wrong

molten jasper
#

lol wait what, why 81

tight phoenix
#

fuck if I know, it doent work higher than 4 for me

#

im starting to get agitated that it SHOULD be working perfectly, and it isnt

molten jasper
tight phoenix
molten jasper
#

so it's normal and view direction

tight phoenix
#

thats not what he's doing at all

#

his is the normalized LIGHT direction, and the normal of the surface

#

view direction is not anywhere involved at all

#

no where in his code does the concept of view direction come up

#

replacing light with view direction does do the fresnel again, but this means light is not calculated in this, and it is in his, so no matter what this can NEVER be right

#

because his is right and his doesnt do this, so this cannot be right

#

also thickness is still fucked

#

maybe we should start over AGAIN back on the first one, but this time do it all in code instead of trying to convert to nodes

tight phoenix
#

I have that link

#

but its just mathematics I dont understand

#

theres no code in there so it may as well be hieroglyphics

#

its terribly frustrating and agitating knowing that the answer is right there, in a language I cannot read

molten jasper
tight phoenix
#

oh dear god so much code

#

this just looks like color table lookup stuff

#

none of this screams 'thin film intereference' at me

#

so I dont know what im supposed to take away from it

#

hm nanometers are mentioned in SPECTRUM_TO_XYZ

molten jasper
#

yeah it's referring to the width of the wavelength

tight phoenix
#

its too difficult, im too stupid to solve it

karmic hatch
tight phoenix
#

I just keep running into dead end after dead end

molten jasper
molten jasper
tight phoenix
#

and the dead end is that I don't know enough, its always me πŸ”₯

karmic hatch
molten jasper
#

render face both?

karmic hatch
#

in shader graph it's in the inspector iirc

#

just make sure to flip the normal when it's a back face

tight phoenix
# molten jasper look how far you've come

I honestly dont feel like ive come anywhere at all.
I have nothing to show for all my hard work, I have a glorified color gradient (a wrong one that has nothing to do with real life) mapped over a fresnel. I could have done that with two nodes

molten jasper
#

darn someone remind me how that's done

tight phoenix
#

im now in mental health crisis again because I stupidly had expectation, hopes, dreams, a desire for success that has once again failed because I am a fucking stupid failure

karmic hatch
#

also can i just say that while motivating things from physical principles is nice, you don't need everything to be analytic or accurately represent the physical system you're modelling, it just needs to look similar enough

tight phoenix
#

heading out now

molten jasper
#

I'm going for physically based

karmic hatch
#

fair

tight phoenix
#

my head is clear but im not going back to shaders today, my work hours are over, its the only way to maintain my sanity

molten jasper
#

that's fair. I'll keep at it, I think I'm almost there

karmic hatch
#

From http://labman.phys.utk.edu/phys136core/modules/m9/Thin films.html

2 n_oil t cosΞΈt = (m+Β½)Ξ», m = 0,1,2,...,
for constructive interference. (t is the thickness, ΞΈt the transmitted angle (from Snell's law), n_oil the refractive index in the thin film, and Ξ» the wavelength)

so then,

m = (2 n_oil t cosΞΈt)/Ξ» - Β½
and so we can return a function where when m is close to or equal to an integer, that color is bright, and otherwise, it's dark.

Now what function do we choose? I would suggest something like lerp(0.5, cos(pi m)^2, 1/sqrt(1 + m^2)); the cosine gives us the oscillations we want, while as the thickness goes to infinity, the oscillations should get averaged out because while 500nm might see a peak, 501nm might see no light, and so integrating over the entire region of the spectrum that corresponds to green, we should see no variation. (This isn't the only choice for this function but it should work fine and should approximate the real falloff at large thicknesses)

The result:

#

first half of the graph

#

second half

unreal portal
#

Not sure if HLSL stuff is ok to post here, but can anyone help me with this day night shader? trying to take the blend value and multiply it by time till it reaches the end(@1 but at time of 24hrs) then loop back.

meager pelican
# unreal portal Not sure if HLSL stuff is ok to post here, but can anyone help me with this day ...

You probably want a procedural skybox, not a fixed-function shader.
https://en.wikibooks.org/wiki/Cg_Programming/Unity/Skyboxes
That's one environment cube. But you could do two and blend them in the vert/frag functions.
It is also worth looking into Unity's procedural skybox code from their "default" procedural shader here:
https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/Skybox-Procedural.shader (that's a bit dated, but...)

GitHub

Unity Built in Shaders. Contribute to TwoTailsGames/Unity-Built-in-Shaders development by creating an account on GitHub.

unreal portal
#

ty, appreciate the tools

vocal narwhal
white pivot
#

have some recommendations to bulid waterfall

#

?

violet bough
# white pivot have some recommendations to bulid waterfall

Unity Shader Graph - Waterfall and Ripples Tutorial

In this Shader Graph tutorial we are going to see the steps I took to create this very stylized Waterfall with Ripples. It's one shader for the waterfall and another for the ripples. And we also need some meshes and a simple texture for the ripples.

I MADE A NEW WATERFALL BUT IT'S TOXIC: htt...

β–Ά Play video

A breakdown of the various elements that make up this effect I've created for Waycaster in Unity.

Follow me and the game's development:

https://twitter.com/NickDCarver
https://twitter.com/WaycasterGame

Useful Links:

Stylized VFX in Rime: https://simonschreibt.de/gat/stylized-vfx-in-rime/
Zelda Water Shader: https://polycount.com/discussion/...

β–Ά Play video
#

Anybody know where I can ask questions relating to CustomRP ? πŸ˜…

rough cairn
#

is it possible to have worldspace in compute shader?

pastel oracle
#

Hello, is there any possibility to create Stencil Buffer in Shader graph? Thank you πŸ™‚

quick cape
#

What is going on with my shader math!?

#

Context: I spawned a bunch of "agents" from the middle of the screen

#

Anytime they leave the bounds of the screen, they teleport to width/2.0, height/2.0

#

Aka back to middle

#

But SOME of them screw up and teleport to random locations on the axis

#

They listen to 1 of the axis, but the other is... Random..?

#

It's never both of them being wrong, only one

#
[numthreads(8,8,1)]
void Update(uint3 id : SV_DispatchThreadID)
{
    Agent agent = agents[id.x];

    float2 direction = getDir(agent.angle);
    float2 newPos = agent.pos + direction * agent.speed * deltaTime;
    // float random = hash(time * direction.x * newPos.y * height);

    if(newPos.x < 0 || newPos.x >= width || newPos.y < 0 || newPos.y >= height)
    {
        // agent.angle = scaleToRange01(random) * 2 * 3.1415;
        // direction = getDir(agent.angle);
        // newPos = agent.pos + direction * agent.speed * deltaTime;
        newPos = float2(width/2.0, height/2.0);
    }
    
    agent.pos = newPos;
    Result[int2(agent.pos.x, agent.pos.y)] = 1;
    
    // float x = id.x / width;
    // float y = id.y / height;
    // Result[id.xy] = float4(sin(x), cos(x), tan(x + y), 1);
    
    agents[id.x] = agent;
}
#

But ya, my math is incosistent :c

#

I don't understand, it seems random

kind juniper
regal stag
# pastel oracle Hello, is there any possibility to create **Stencil Buffer** in Shader graph? Th...

Shadergraph does not expose Stencil operations currently.

If you're in URP, the RenderObjects feature can be used to override stencil values when rendering a whole Layer of objects.

But for a few specific objects (especially if they need different stencil values), it's better to use shader code. Or convert the graph to code (via "View Generated Code" button in inspector on shadergraph asset), copy and save in assets and edit the Stencil block into it.

meager pelican
# quick cape ```c [numthreads(8,8,1)] void Update(uint3 id : SV_DispatchThreadID) { Agent...

Weird.
IDK maybe some optimization thing.
BUT, when in doubt, change something. I observe that you can pre-compute width/2.0 and height/2.0 and not have to do the division for each agent each time. So maybe try that. You could basically pass in uniform ints for it, and just set newPos = int2(centerX, CenterY).
Or maybe try doing something like Agent[id.x].pos = blah rather than having the interim variable "agent", and let the optimizer deal with the code.

#

You could also move the if after the first setting of agent.pos (yes, set it possibly twice).

kind juniper
#

If you access something that's not initialized it could potentially be random numbersπŸ€”

meager pelican
#

The center values, though, should still be the same. Assuming height and width are initialized (and per the pic they appear to be). So why would one component be off-center randomly?

kind juniper
#

It could also be that the compute buffer and structured buffer don't align one to one

#

Then the data would get mixed up. You think you read the correct property of one element but you're actually reading another property of a different element.

#

Seeing how they have 8 8 1 threads and only use one axis(id.x) kinda seems sus.

meager pelican
#

That's a good point, there should be a check to see if id.x is out of range if the buffer size isn't a direct multiple of 8 x 8.

kind juniper
#

I have a question on shader execution order. Let's say I dispatch a compute shader to render something into a render texture. I know that it doesn't execute immediately, but is there a guaranteed time it will get executed? Is it gonna be somewhere before the next frame starts? Is there some way to know if the compute shader finished it's processing without getting the data back on the GPU?

And another question is what's the common workflow with rendering to a texture and keeping the data serialized? I remember trying a regular Texture2D asset, but I think there were some problems with writing to it..?πŸ€”
On the other hand RenderTexture keeps on resetting the data at different times(mainly on assembly reload). Can I serialize a RenderTexture without it resetting?

quick cape
#

Any idea how to solve this error? :C

kind juniper
# quick cape

Probably read/write permissions on the cpu side do not correspond to those in the shader.πŸ€”

quick cape
#

That's really odd because I was using them the same way previously..

#

Could there be a name conflict between the two kernels?

#

They're using the same field, but I'm setting it the same for both kernels

kind juniper
#

Maybe? you're accessing kernel 1(the second kernel).

#

Can't say anything without seeing the code. Both the shader and the C# one

grand jolt
#

Hey, I have problem.
I am new and i don`t know where is Mask Map in Material.

kind juniper
#

Some questions on shader execution order

kind juniper
grand jolt
#

In tutorial look like this and this category.

kind juniper
#

a material is just an interface for the parameters of the shader

grand jolt
#

how i can change to this because I don`t see it in the list.

kind juniper
#

For starters you'll need to switch to HDRP, since it's an HDRP shader

#

The shader will be added automatically as it's part of the package

grand jolt
#

how to switch

#

?

kind juniper
grand jolt
#

thx

rotund tundra
#

anyone know how i can get a int3 from my compute shader to my script?

#

the docs dont make a lot of sense

kind juniper
#

There's an example with a texture there

rotund tundra
#

ok so im trying to count the number of pixels that are each of 3 colors
are you saying it would be faster to convert the Rendertexture to a Texture2d and cpu evaluate each pixel?

kind juniper
#

No.

#

I'm saying that you should use a compute buffer to get that data

#

You probably want to use something like an append buffer

#

Add something(doesn't really matter what) to an append buffer each time you hit a pixel of the desired color. Then on the C# side copy the buffer count and get the data(the count).

rotund tundra
#
    public void CheckScores(){
        splatBuffer = new ComputeBuffer(3, sizeof(int));
        splatCompute.SetBuffer(1, "TeamScores", splatBuffer);
        splatCompute.SetInts("TeamScores", new int[3] { 0, 0, 0 });
        splatCompute.Dispatch(1, size / 8, size / 8,1); 
        int[] scores = new int[3];
        
        splatBuffer.GetData(scores);
        Debug.Log("Alpha: " + scores[0] + " Beta: " + scores[1] + " Neutral: " + scores[2]);
        splatBuffer.Release();
    }

ok so i got this but it returns 0,0,0 every time
do i have to wait for the splatCompute.Dispatch to complete?

shadow locust
rotund tundra
#

i set a 10 second wait just for testing and still got nothing, so either my shadercode or the splatbuffer code it wrong

#
[numthreads(8,8,1)]
void GetScores (uint3 id : SV_DispatchThreadID)
{   
    float4 color = InkTexture[int2(id.x, id.y)];
    if (all(color == AlphaColor)) {
        TeamScores[0] += 1;
    }
    else if (all(color == BetaColor)) {
        TeamScores[1] += 1;
    }
    else {
        TeamScores[2] += 1;
    } 
}

i though this seemed hella wrong by anything else ive tried gives an error

shadow locust
#

so much unecessary repetition πŸ˜΅β€πŸ’«

#
float4 color = InkTexture[int2(id.x, id.y)];
if (all(color == AlphaColor)) {
  TeamScores[0] += 1;
}
else if (all(color == BetaColor)) {
  TeamScores[1] += 1;
}
else {
  TeamScores[2] += 1;
}```
rotund tundra
#

tried that, i get this error?

shadow locust
#

``if(all(color == AlphaColor))` apparently? @rotund tundra

kind juniper
shadow locust
kind juniper
#

Yeah, it freezes the main thread until the data is ready. There's also an async version where you can wait for the results.

rotund tundra
kind juniper
#

different threads can't write into the same buffer index

#

You'll need to use an append buffer.

#

As I mentioned previously

rotund tundra
shadow locust
#

yeah this isnn't going to work well

#

the += is actually three operations:

  • read current value
  • increment it
  • write it back
#

If two different threads read the value simultaneously (and they will) and both increment by one and write it back, you won't get +2, you'll only get +1

rotund tundra
#

oh

shadow locust
#

I imagine this is a splatoon scoring thing?

rotund tundra
#

yes

kind juniper
#

The only way this can work is by adding to an append buffer. You have an option to either have 3 buffers for each append buffer. Then get their count on the C# side. Or have 1 buffer and fill it with different ints per channel. In this case you'll need to loop the resulting array on the cpu and check each element in the array.

#

I think the 3 buffers version should be faster, despite the additional read overhead. But you should probably test if performance there is critical

rotund tundra
#

i only need to call it once, so even if it takes like 3 seconds thats fine

kind juniper
#

In this case, why not use the cpu?

#

I'm sure it will be able to handle quite a lot over 3 sec time

rotund tundra
#

wait, so converting to the Texture2d and looping would be fine here?

kind juniper
#

Sure. If you can spare 3 sec of time, why not.

#

You'll need to make it async of course, but other than that, it's fine

rotund tundra
#

hmm

#

now to figure out how to convert a renderTexture to Texture2D

kind juniper
#

Why do you even need to convert it?

#

you should be able to get the pixels regardless

rotund tundra
#

how do i read colours from a renderTexture?
theres no endpoints for pixel data

kind juniper
#

Hmmm maybe not

rotund tundra
#

uhh, am i missing somthing?

kind juniper
rotund tundra
#

code
Texture2D test2 = Texture2D.CreateExternalTexture(size, size, TextureFormat.RGBAFloat, false, false, splatMapRenderTexture.GetNativeTexturePtr());
error

kind juniper
#

What throws the error?

rotund tundra
#

no clue? thats it

kind juniper
#

Also, you need to get the pointer to the color buffer, not the whole render texture

kind juniper
rotund tundra
#

its not cropped, thats it

kind juniper
#

And in the error details?

#

It is cropped though.πŸ˜…

rotund tundra
kind juniper
#

Okay

#

Try with the color buffer and see if it works

rotund tundra
#

same error

kind juniper
#

What's your render texture format?

rotund tundra
#

ARGBFloat

kind juniper
rotund tundra
#
Texture2D test2 = Texture2D.CreateExternalTexture(size, size, TextureFormat.RGBAFloat, false, false, splatMapRenderTexture.colorBuffer.GetNativeRenderBufferPtr());
kind juniper
rotund tundra
#

they dont share peramaters

kind juniper
#

wdym?

rotund tundra
#

TextureFormat and RenderTextureFormat dont have the same options

kind juniper
#

There's a similar format for texture2D though.
TextureFormat.ARGB32

#

Hmm. Maybe not.

rotund tundra
#

unity didnt like that

#

ive never seen the unity crash handler before

kind juniper
#

There is ARGB32 in both

#

Basically, use the same format for both

rotund tundra
kind juniper
#

Hmm

#

Apparently there's a simpler way

#

Hmmm... That might come handy when I need to serialize the render texture...

rotund tundra
#

hmm

#

this renders the camera view to the render texture?

#

interesting results

kind juniper
#

Lol, Yeah. You Should probably unbind it right away

rotund tundra
#

?

#
    Texture2D toTexture2D(RenderTexture rTex)
    {
        Texture2D tex = new Texture2D(size, size, TextureFormat.ARGB32, false);
        Camera.main.targetTexture = rTex;
        RenderTexture.active = rTex;
        Camera.main.Render();
        
        tex.ReadPixels(new Rect(0,0,1920,1080), 0, 0);
        
        Camera.main.targetTexture = null;
        RenderTexture.active = null;
        return tex;
    }

heres the code

kind juniper
#

I don't think you need to call Camera.main.Render

#

nor assign the camera target texture

#

Basically, remove all the lines related to Camera

rotund tundra
#

returns a blank texture

kind juniper
#

Hmm

#

Share the updated code

rotund tundra
#
    Texture2D toTexture2D(RenderTexture rTex)
    {
        Texture2D tex = new Texture2D(size, size, TextureFormat.ARGB32, false);
        //Camera.main.targetTexture = rTex;
        RenderTexture.active = rTex;
        //Camera.main.Render();
        tex.ReadPixels(new Rect(0,0,1920,1080), 0, 0);
        //Camera.main.targetTexture = null;
        RenderTexture.active = null;
        return tex;
    }
kind juniper
#

hmm

fervent garnet
#

Hii, maybe someone can help me, I have a mask texture that I want to flip (reflect) each individual "object" in it on it's own axis, that is, not flip the entire mask, but each masked area by it's own axis, anyone ever done something like this ?

quick cape
#

I'm having trouble generating random numbers in my computeshader!!

#

I'm trying to use a hash function and input it things that shouldn't repeat

#

Like Time.fixedTime

#

But lots of numbers end up being identical

kind juniper
#

Maybe share your code and explain what exactly is identical.

quick cape
#

Thank you, yes, I really should~

#

For example this Very obvious pattern

#

I'm using my hash function to determine the randomness

#

It actually seems fine if I just render the random pixels

#

But patterns do form

native otter
#

I've managed to change the color of my texture slightly using a hue node, but I rather do it with a gradient node.
But I'm stuck how to connect this in combination with the texture.

#

How do I do this the correct way?

meager pelican
quick cape
#

ComputeShader

#

Wait, oh, that issue

#

That issue was caused by not doing renderTexture.enableRandomWrite = true;

meager pelican
# native otter I've managed to change the color of my texture slightly using a hue node, but I ...

If you're sampling a texture that is a gradient, you don't use the gradient node. That node is for a mathematical gradient, not a texture-based gradient.

To sample a texture that is a gradient, you "just" use the regular texture sampler, with the x value of the UV set to a value from 0 to 1 representing the % of the way through the gradient. Set the Y value to something inside the height, not the very edge. Like maybe 0.5

If you want to use the gradient node, the value is from 0 to 1 for the gradient lookup and -180 to 180 in degrees and is -Pi to Pi in radians for the hue adjustment into the hue node.
But IDK what you mean by "change the color of my texture (with a gradient)". Change it how? Try a multiply. Or if you need to see the hue calc, check here: https://docs.unity3d.com/Packages/com.unity.shadergraph@14.0/manual/Hue-Node.html

kind juniper
#

Oh, solved already

timber isle
meager pelican
# timber isle Has anyone seen this issue with Shader Graph? The cube discolors as the brightne...

What's weird, is that since you assigned a float1 to a float3 you should get the same value in ALL components. Yet you didn't in scene view. But you did in game view.

@quick cape had an issue where vector components weren't set properly, but IDK what the deal was, and if it was fixed or not. And it wasn't for a color, it was for a location. But still, weird-component settings.

Can't tell if this is related or not.

quick cape
#

I believe my issue you're referring to was the lack of Alpha in preview - it showed as full opacity, but in game it had 0 alpha!

meager pelican
rotund tundra
kind juniper
rotund tundra
#
Texture2D test2 = new Texture2D(size, size, TextureFormat.ARGB32, false);
        Graphics.CopyTexture(splatMapRenderTexture, test2 );
kind juniper
#

Okay, how do you test it out?

rotund tundra
#

uhh, i ran the code after messing with the rendertexture?

kind juniper
#

I mean, how do you know that it's blank?

rotund tundra
#

hmm

#

maybe the colour checker is inaccurate

kind juniper
#

Also, make sure that both the textures have the same config, like the format and mipmaps count and what not.

#

Make sure there are no errors thrown.

#

Or warnings

#

Actually, I didn't check if the texture data is available on the CPU right away, but the new textures renders properly.πŸ€”

rotund tundra
#

wtf, i put a debug.log and it crashed unity

kind juniper
#

Lol. Make sure that the texture formats match.

rotund tundra
#

they do

kind juniper
#

Here's my code

public void GenerateDefault()
{
    CachedRT = Generate(defaultParams);
    defaultTexture = new Texture2D(defaultParams.Resolution, defaultParams.Resolution);
    defaultTexture.wrapMode = TextureWrapMode.Clamp;
    defaultTexture.name = CachedRT.name;
    Graphics.CopyTexture(CachedRT, 0, 0, DefaultTexture, 0, 0);
}
#

CachedRT is the render texture

#

I create it like that:

sourceTex = new RenderTexture(heightmapParams.Resolution, heightmapParams.Resolution, 0);
sourceTex.enableRandomWrite = true;
sourceTex.name = $"noise_{heightmapParams.Resolution}x{heightmapParams.Resolution}";

#

Try serializing both the render texture and the Texture2D and checking them in the inspector after running the code.

rotund tundra
#

hmm, ok its reading, but the color data is getting changed somewhere

kind juniper
#

Just tried printing some pixels right after copying and it seems to output the correct data

rotund tundra
#
        for(int i = 0; i < colors.Length; i++){
            if(colors[i] == gameManager.AlphaTeam){
                alphaScore++;
            }
            else if(colors[i] == gameManager.BetaTeam){
                betaScore++;
            }
            else{
                noScore++;
            }

for whatever reason the color in the array dont match the source colors that im comparing them to

kind juniper
#

Where do you get the source colors from?

rotund tundra
#

gameManager.BetaTeam and gameManager.AlphaTeam are sent to the compute shader as float4s

#

they are the source colors

kind juniper
#

Hmmm...

#

Actually...

#

It seems like I'm getting the same value for all the pixels lol

#

Hmm

kind juniper
#

It seems like the CPU side data is not updated. Hmm

rotund tundra
#

would adding a delay on the check work?

kind juniper
#

I tried. Doesn't seem to work.

#

It just does not update the data on the cpu side

rotund tundra
#

wait

#

oh dang

#

i just realised i didnt .Apply() the texture

#

but it still didnt work

kind juniper
#

Apply is supposed to upload the cpu data to the gpu, so yeah

#

Oh shoot

rotund tundra
#

ah

kind juniper
#

I tried the yesterday method again and it worked😲

#
        public async void GenerateDefault()
        {
            CachedRT = await GenerateAsync(defaultParams);
            RenderTexture.active = CachedRT;
            defaultTexture = new Texture2D(defaultParams.Resolution, defaultParams.Resolution, TextureFormat.ARGB32, false);
            defaultTexture.wrapMode = TextureWrapMode.Clamp;
            defaultTexture.name = CachedRT.name;
            defaultTexture.ReadPixels(new Rect(0, 0, defaultParams.Resolution, defaultParams.Resolution), 0, 0, false);
            defaultTexture.Apply();
            var colors = DefaultTexture.GetPixels(0, 0, 50, 50, 0);
            for (int y = 0; y < 20; y++)
            {
                for (int x = 0; x < 20; x++)
                {
                    Debug.Log($"pixel ({x}, {y}): {colors[y * 50 + x]}");
                }
            }
            RenderTexture.active = null;
        }
#

Weird shit.

#

Aaah. That makes sense.

#

I only tested the GPU side yesterday and I didn't Apply the texture, so on the gpu side it was not updating. I tested the cpu side and the cpu side seems to copy properly even without Apply

#

So that's it I guess. That's how you get a render texture data back from GPU to CPU.

#

Basically these 3 lines:

RenderTexture.active = CachedRT;
defaultTexture.ReadPixels(new Rect(0, 0, defaultParams.Resolution, defaultParams.Resolution), 0, 0, false);
var colors = DefaultTexture.GetPixels(0, 0, 50, 50, 0);
rotund tundra
#

what is defaultParams?

kind juniper
#

It's just some custom class with parameters. You can ignore it.

#

I only get the resolution to use for width and height.

Rect(x, y, width, height);
rotund tundra
#

πŸ’€

#

still nothing

kind juniper
#

Share your code

rotund tundra
#
    public void CheckScores(){
        int alphaScore = 0; int betaScore = 0; int noScore = 0;
        scoresReadTexture = new Texture2D(size, size, TextureFormat.ARGB32, false);
        //Graphics.CopyTexture(splatMapRenderTexture, 0,0, scoresReadTexture, 0,0 );
        RenderTexture.active = splatMapRenderTexture;
        scoresReadTexture.ReadPixels(new Rect(0, 0, size, size), 0, 0, false);
        Color[] colors = scoresReadTexture.GetPixels(0, 0, size, size, 0);
        for(int i = 0; i < colors.Length; i++){
            if(colors[i] == gameManager.AlphaTeam){ alphaScore++; }
            else if(colors[i] == gameManager.BetaTeam){ betaScore++; }
            else{ noScore++; }
        }
    
        //convert to percentages
        float alphaPercent = (float)alphaScore / (float)colors.Length;
        float betaPercent = (float)betaScore / (float)colors.Length;
        float noPercent = (float)noScore / (float)colors.Length;
        Debug.Log($"Alpha: {alphaPercent * 100}% Beta: {betaPercent * 100}% No: {noPercent * 100}%");
    }
kind juniper
#

I don't think direct comparison would work

#

Try printing some of the pixels to make sure that you actually get some values that makes sense

rotund tundra
#

now its just white

kind juniper
#

Is that from printing?

rotund tundra
#

?

kind juniper
#

How do you know that it's white?

rotund tundra
#

i put it in inspector

kind juniper
#

Oh, you actually need to Apply if you want the gpu side to update.

#

Add the Apply for the time of testing I guess.

#

Before GetPixels

rotund tundra
#

ok its got the image now

kind juniper
#

Okay, so it is working

rotund tundra
#

the Graphics.CopyTexture also did this

kind juniper
#

Yeah, I know. But it didn't update the cpu side.

#

The current method does.

rotund tundra
#

ok

kind juniper
#

If you print the values in the console, you'll see that

rotund tundra
#

no shot unity crashes again

#

it did

#

well

#

its frozen

kind juniper
#

I feel like that's not the current code fault.

#

Or at least not only.

rotund tundra
#

but before i added the Debug.Log it took less than a second

kind juniper
rotund tundra
#

2048x2048

kind juniper
#

Are you looping through the whole texture?

rotund tundra
#

yes

kind juniper
#

lol

rotund tundra
#

thats why i was using computeshaders

kind juniper
#

4,194,304 iterations on the cpu is not a joke

rotund tundra
#

its only at 5% util

kind juniper
rotund tundra
#
int alphaScore = 0; int betaScore = 0; int noScore = 0;
        scoresReadTexture = new Texture2D(size, size, TextureFormat.ARGB32, false);
        RenderTexture.active = splatMapRenderTexture;
        scoresReadTexture.ReadPixels(new Rect(0, 0, size, size), 0, 0, false);
        scoresReadTexture.Apply();
        Color[] colors = scoresReadTexture.GetPixels(0, 0, size, size, 0);
        for(int i = 0; i < colors.Length; i++){
            Debug.Log(colors[i]);
            if(colors[i] == gameManager.AlphaTeam){ alphaScore++; }
            else if(colors[i] == gameManager.BetaTeam){ betaScore++; }
            else{ noScore++; }
        }
    
        //convert to percentages
        float alphaPercent = (float)alphaScore / (float)colors.Length;
        float betaPercent = (float)betaScore / (float)colors.Length;
        float noPercent = (float)noScore / (float)colors.Length;
        Debug.Log($"Alpha: {alphaPercent * 100}% Beta: {betaPercent * 100}% No: {noPercent * 100}%");
    }
kind juniper
#

It's not a joke, but even the cpu will get through it in 3 sec.

#

For starters, just print one line, not the whole thing.

#

We should confirm that the cpu side data is indeed what we expect

rotund tundra
#

wdym one line?

kind juniper
#

one line of the texture.

for(int i = 0; i < size; i++)
#

It should be the bottom of the texture, right?πŸ€”

rotund tundra
#

OHHHH

#

ohno

#

floating point errors ohnodisappear

#

the colour is 0.555

kind juniper
#

Yes, that's what I was implying

#

It's not just floating error, but most likely converting to and back into different formats and passing to/from gpu

rotund tundra
#

yea

kind juniper
#

Honestly the approach you took is not great, but if you want to avoid major reworks, You'll have to introduce some kind of threshold.

#

if the difference is within that threshold, you consider it as the same color.

#

something like .01 is probably safe, and shouldn't make much difference visually

#

Though you'll have to take it into account when the teams pick their color. If they're too close to each other your scoring will break

rotund tundra
#

the colours should always be on opposite sides of the colour wheel

kind juniper
#

Then there's no problem I guess.

#

The only thing left is to check the colors asynchronously so as to not freeze the main thread

rotund tundra
#

great, now it thinks the entire map is on alphateam

kind juniper
#

Probably too big of a threshold πŸ˜„

rotund tundra
#

0.01

kind juniper
#

Hmm...

#

Share the updated code I guess..?

rotund tundra
#
    bool IsColorEqual(Color a, Color b, float tolerance = 0.01f){
        if(a.a - b.a > tolerance){ return false; }
        if(a.r - b.r > tolerance){ return false; }
        if(a.g - b.g > tolerance){ return false; }
        if(a.b - b.b > tolerance){ return false; }
        return true;
    }

color comparison code

for(int i = 0; i < colors.Length; i++){
            //Debug.Log(colors[i]);
            if(IsColorEqual(colors[i], gameManager.AlphaTeam , 0.01f)){ alphaScore++; }
            else if(IsColorEqual(colors[i], gameManager.BetaTeam , 0.01f)){ betaScore++; }   
            else{ noScore++; }
        }

loop its called in

#

wait

#

oh

#

0a - 1a is less than tolerence

#

the alpha is broken

kind juniper
#

But you should probably use the absolute value of the difference

#

Mathf.Abs()

rotund tundra
#

yes

#

thats what was wrong

#

tho i realised theres probably no way to account for empty uvs

#

empty uv space counts as no team

kind juniper
#

It's not like there's no way

#

You just need to check the pixel position

#

That should give you the position in UV space(I think)

y = index / size;
x = index % size;
normalizedPos = (x,y) / size;
#

Now you just need to somehow define the legal areas.πŸ€”

#

Could probably reconstruct them from mesh uv data, but that sounds like a lot of work

#

Maybe find a way to import the isles from blender in a format that's easy to check.

rotund tundra
#

just gotta make uv perfect maps πŸ’€

rotund tundra
#

Oh

#

Smarter solution

#

Cover the visable map

#

Count the still empty pixels

#

Subtract them in future

kind juniper
#

Yeah, I guess that's one way to hack it.

timber isle
timber isle
#

Nothing changes even when I put a Vector4 in the mix...
It looks hardware level...

#

Can anyone repo this?

kind juniper
#

Try disabling any post effects to only see the work of the shader

timber isle
#

I don't think so, I don't have any post proccing

kind juniper
#

It does feel like bloom or something is in effect

#

What's that global volume object doing?

mental bone
#

Sine goes from -1 to 1 you cant exactly have negative colors so saturate the output of the sine

dim yoke
timber isle
dim yoke
#

What you mean by that?

timber isle
timber isle
kind juniper
#

From PP

dim yoke
timber isle
timber isle
kind juniper
timber isle
#

@kind juniper and @dim yoke, yes that was it; it was tone mapping. Thanks guys.
But the question still remains: why doesn't it show in Game view?

dim yoke
timber isle
kind juniper
dim yoke
mental bone
#

I will reiterate, such a thing as a negative color does not exist. When a sine wave that goes from -1 to 1 is used for any color operation it must be clamped(saturated) to fit the 0 1 range

#

Or use a remap node

#

One of the two

timber isle
#

Thanks guys! I'm new to URP and Shader Graph so I didn't realize that the post processing was automatically added πŸ™‚

dim yoke
#

With hdr, you may want to clamp only the low boundary, depends on the case

kind juniper
timber isle
#

@kind juniper and @dim yoke, you guys are Awesome, Thanks!

kind juniper
#

Saturate is the correct solution. Or (value+1) / 2

timber isle
#

Except that oddly I had to divide by 4 to avoid bloom???

#

Maybe not...
Divide by 2 did work.

#

As expected...

#

Didn't notice till now how before the +1, the color drops to black for an extend period of time due to clipping...

proper ermine
#

Guys I am creating Custom sprites by allowing the player to select several parts that use RGB images to allow custom colours

Issue is after I piece them all together I want to add an outline to the final image and it seems impossible to do it?

I can create a UV offset to allow me to move the image left for example and them subtract it from the original to get the difference to create the outline but I have no where to input the actual UV offset?

#

Here is the example of where I end up, an add node with an output of RGBA... Is there a way to create a Texture2D from this? Or a way to offset it? I can't find an answer anywhere

#

Oh this is a main preview... probably better to see that

proper ermine
#

Is there no way to shift a float 4 left? 😦

kind juniper
grizzled bolt
proper ermine
#

I add several textures together to create this final product and I need to then add the outline... Otherwise I'd just draw the outline on myself

#

SampleTexture2D has a UV(2) offset input, but I can't do anything with my end product of a float4... If I could create a new texture with this final output then that'd be great

grizzled bolt
proper ermine
#

This is a Colour / float 4

violet bough
#

hello, i want to render the linear depth of water to a render texture, i already have the correct calculations but i dont know what kind of render texture i need (currently i have RFloat)

#

when i try to render this to a render texture, nothing shows up in the frame debugger

kind juniper
#

Anyone has any insight on Sample Texture 2D LOD node or the corresponding SAMPLE_TEXTURE2D_LOD(Texture, Sampler, UV, LOD); function?
Does it act as a texture2d array? I each lod leveel a separate texture? Can I use a texture 2d array in this function?

#

Doesn't seem like I can connect the Texture2DArray node into it