when you say dynamic objects move - i guess what remains to be clarified is; if my entire scene is static, just the only thing moving is - myself i.e. the player / the camera controller moving around the scene, is that what you call a static scene which CAN be reflected from-any-angle to-any-angle with reflection probes on the cheap, and it will look correct even for a moving camera? or if the camera is moving around the scene at all - all bets are off, baked reflection probes is not the way to go. instead we must use the other solutions like spreading out updating reflection probes over multiple frames, or probes are not the way to go altogether just all-out planar reflections
#archived-shaders
1 messages ยท Page 16 of 1
i did in fact make a scene pretty close to what you're describing at that github link - lemme know if you ever get around to giving it a spin, either to see where i went wrong or if you can show a little bit of how to correctly implement what you're describing
and thanks i appreciate the time & advice/explanations ๐ ๐
Could anyone help me with this errors? i cannot figure it out
It works in editor but not on console itself
im struggling, im really really really really struggling to produce this appearance
no matter what combination of noise I use, I cant solve it
the key critical thing that never works is smudging
its easy to make cells that roughly look like the above
but they -always- have soft gradient peaks from edge to top
i need desperately to have the secret to smudge those peaks
nothing ive tried has worked
closest ive managed and its completely shit and wrong
how do I smudge the white peaks closer to the dark valleys?
everything ive tried has failed to achieve this
A Smoothstep might help "flatten" the peaks a bit, not sure if that's exactly what you want though
yeah its not enough to just flatten it, I want to smudge the peaks away from the perfect center of each voronoi cell
but I cant find a way to change the voronoi cell center
like this is pretty good, but its missing that critical step of smuding the peaks
no matter how much I distort the UVs, the peaks are always dead center because thats just how voronoi works
Maybe if you're doing offsetting, sample the new noise, then use that to boost the offset, and sample a final layer of noise using those boosted coordinates
sample the new noise okay
boost the offset? How is this done? Adding the new noise to the UVs that created that noise?
hmm that has sorta worked ๐ค its quite messy but maybe if I tweak the values a bit
Adding, or multiplying by, or something.
Anyone have any examples on how I can use DrawMeshInstancedProcedural to draw thousands of mesh instances in different positions? I can't seem to get it to work
Never used procedural, but have used DrawMeshInstancedIndirect. Would a source on that be helpful to you?
Yes, that would be helpful! Thank you. From what I understand DrawMeshInstancedProcedural is basically a wrapper for DrawMeshInstancedIndirect that you can call from C# scripts if you know the number of instances to draw
I could be wrong though
This article was incredibly helpful for me https://toqoz.fyi/thousands-of-meshes.html
but I'm not sure your characterization of the methods is quite correct.
importing the toon fantasy nature pack and all the materials turn pink with this error
What render pipeline are you using? I think that pack is only compatible with LWRP and URP.
Was there a separate URP package that you need to install? There often is.
oh yeah, found and it worked
Do you know how you might detect a ray intersection with one of the meshes?
I see you can use Bounds.IntersectRay(Ray ray), but you would need to know the bounds for each instance. I'm a bit confused on if DrawMeshInstanceIndirect just draws "one mesh" broken up into mulitple pieces. Or if all of the cubes I'm seeing in scene are in fact separate meshes. I'm a bit new to shaders and draw calls ๐
The mesh in the example is a quad
They are drawing the quad hundreds of thousands of times
the quad is the entire mesh
it's not broken up
you could replace the quad with a mesh of the statue of david
So is there no way then to detect intersection with a specific cube?
and you'd have 100,000 little stars of david
A GameObject cube?
Yeah, but I'm trying to avoid GameObjects due to performance ๐ฆ
You have to realize that DrawMesh, in all its incarnations, is just a way of drawing things
I basically need what GameObject colliders do, but without them ๐
it doesn't create anything in or interact with the hierarchy at all
For improved performance
if you want to get collisions of these meshes with a shape or something, you'd have to write the math to do that in your compute shader
you certainly can't use Unity's Physics engine(s) which are CPU based
the example I shared has a primitive implementation of such a thing though
Yeah, I don't need Physics at all. My use case is I have thousands of cubes that need their positions moved programmatically. Users can not move or manipulate the objects (no physics needed). However, I do need to be able to detect if a user points at a specific cube (and mimic a selection interaction)
If you look at the last animation on the page you can see a manipulation in a similar vein to what you're talking about perhaps
Could I achieve that with a custom compute shader?
maybe? I'm not sure I fully understand the nature of what you're asking
I'd just say look at the last animation on the page and see if it's in the same realm of stuff as you're talking about
Yeah, I'll take a look. Thanks!
@shadow locust To give a better idea of what I'd like to do.... these cubes are all moving and I'd like to detect which specific cube my raycast is intersecting with
I followed the example here to create the scene in the picture
you'd have to do the raycast in the compute shader
what is the formula to mask out a specific range of values, with falloff?
desired end result is putting in a value for time and the falloff range returning just those bits
my attempt here is flawed though, it isnt behaving
better example - here ive manually adjusted all the values to get just the vales between that range
but I need the formula so automatically determine those 4 values from just the two values of range and time
certain formulas work at very specific values
but stop working as soon as those values change
ideal outcome is that as the time value changes, the range value does not need compensating adjustments, the range value falls off from where time is
if it was working, time at 0.5 and range at 0.1 would give me 1/10th of the values from the exact center of the 256 value range a color has
I know I will need a values time +/- range , but then how do I use those it isolate a thin band
maybe 1 - min(1, abs(threshold - input) * falloff)
if thats what you're after
this will have falloff both ways, I'm too sleepy to understand what you're after exactly, hopefully this was it, goodnight ๐ด
one more thing - if you want the smoothness off the falloff do 1 - min(1, pow(abs(threshold - input) * falloff), smoothness)
(couldn't go to sleep with this retained information)
I think im making some kind of pemdas error trying to parse the correct order of operation of
1 - min(1, abs(threshold - input) * falloff)
one subtrating the minmum of 1 and the absolute of the threshold minus input, multiplied by falloff?
oh I was using Range for both threshold and falloff
but after fixing that, its still not working
so im definitely still making a pemdas error
got it working, turned out I did have the right maths, it was my values that were not working
turned it into a custom node though to be sure pedmas was correct
๐
Does anyone have a link to a resource / tutorial that talks about how normals are calculated?
I don't want to fully replace the Lit behaviour, but I do want to add a simple blinn phong (?) specular highlight to a height map
I want to calculate 'normals' from this height, butI still want to use the actual Lit normals
but I am not sure how normals interact with manually calculated view direction spec / fresnel
https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html
reading this is way too code for me to make sense of how normals are used
I guess im trying to google normals for lighting for an unlit shader? Toon shader normal maps? yes im aware there is no light in the unlit shader but I just need to use that data for another purpose
oh looks like it might be covered in here
I know just the basics about shaders. Is there a way to make a shader for a quad that makes the edges of the quad distorted?
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, 48.0);
half4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * atten;
c.a = s.Alpha;
return c;
}```
from here: https://docs.unity3d.com/Manual/SL-SurfaceShaderLightingExamples.html
@tight phoenix
HOW you do it depends on what you want....but....in general just check the UV values and decide if you want to apply your distortion. The uv's will tell you how close to an edge you are in x and y, since they range from 0 to 1.
Assuming the mesh is properly uv-mapped.
Hello! is it possible to give a stencil shader different cutout shape? instead of the mesh shape. For example adding star shaped cutout texture will create a star shaped stencil in whatever it cuts through
That "star shaped cutout texture" could be used as a mask to stencil or not. It would require a specific stenciling pass, you'd discard any pixels that were not in the star. Probably use a Color Mask of 0, and just output the stencil.
and how do i make the stencil pass to consider the given texture as a shape to which to do a cutout?
currently my stencil simply replaces every shader that has:
Ref 1
Comp notequal
Pass keep
}```
This is the entire stencil shader right now:
Shader "Custom/Stencil"
{
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Geometry-1" }
ColorMask 0
ZWrite off
Stencil
{
Ref 1
Comp always
Pass replace
}
Pass
{
Cull Back
ZTest Less
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 pos : SV_POSITION;
};
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}
half4 frag(v2f i) : COLOR
{
return half4(1,1,0,1);
}
ENDCG
}
}
}
You'd use something like clip(shapeTexSample.a - _AlphaClipThreshold) in the fragment shader
something like this?
{
Properties
{
_MainTex("Albedo", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Geometry-1" }
ColorMask 0
ZWrite off
Stencil
{
Ref 1
Comp always
Pass replace
}
Pass
{
Cull Back
ZTest Less
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 pos : SV_POSITION;
};
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}
half4 frag(v2f i) : COLOR
{
return clip(_MainTex.a - _AlphaClipThreshold);
//return half4(1,1,0,1);
}
ENDCG
}
}
}```
forgive me if i make noobish mistakes ๐ im still learning how to handle with shaders..
You need to sample the texture. The clip function also shouldn't be used for the return. It discards the pixel if the parameter passed in is less than 0. You'd still need to return your colour for the other pixels.
half4 frag(v2f i) : COLOR {
float4 mainTexSample = tex2D(_MainTex, uv);
clip(mainTexSample.a - _AlphaClipThreshold);
return half4(1,1,0,1);
}
Also either change _AlphaClipThreshold to a hardcoded value (0.5 maybe), or provide a Float property as an input.
oh so its not something that exists as a parameter in this shader, alright
Would also need float2 uv : TEXCOORD0; in appdata and v2f, and o.uv = TRANSFORM_TEX(v.uv, _MainTex); in the vertex shader to pass the uv through
so um like this?
{
Properties
{
_MainTex("Albedo", 2D) = "white" {}
_AlphaClipThreshold("Alpha Threshold", Range(0, 1)) = 0.5
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Geometry-1" }
ColorMask 0
ZWrite off
Stencil
{
Ref 1
Comp always
Pass replace
}
Pass
{
Cull Back
ZTest Less
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
half4 frag(v2f i) : COLOR
{
float4 mainTexSample = tex2D(_MainTex, uv);
clip(mainTexSample.a - _AlphaClipThreshold);
return half4(1,1,0,1);
}
ENDCG
}
}
}```
i mostly got to play with surface shaders, not with vert/frag shaders ๐
mmm i believe i did everything correct but it throws me this error:
Looks like you're missing an include that defines the TRANSFORM_TEX macro
Like UnityCG.cginc
let me get you the syntax
Hmm, comparing it to the unity docs cyan gave, everything looks correct, how do I add this macro?
Oh yep now I see it
I missed the unityCG
now it throws me this error:
not sure how the clip supposed to work..
here is the updated script:
{
Properties
{
_MainTex("Albedo", 2D) = "white" {}
_AlphaClipThreshold("Alpha Threshold", Range(0, 1)) = 0.5
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Geometry-1" }
ColorMask 0
ZWrite off
Stencil
{
Ref 1
Comp always
Pass replace
}
Pass
{
Cull Back
ZTest Less
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
half4 frag(v2f i) : COLOR
{
float4 mainTexSample = tex2D(_MainTex, i.uv);
clip(mainTexSample.a - _AlphaClipThreshold);
return half4(1,1,0,1);
}
ENDCG
}
}
}```
The param is a float.
If it is < 0, the fragment is discarded. So the math expression is written by you such that it returns a negative value for discarded pixels.
but, no how is it possible?
Change this line to:
_AlphaClipThreshold("Alpha Threshold", Range(0, 1.0)) = 0.5
and see if it helps. Explain later if it works.
nope, still the same error:
i changed the range to Float earlier but that did not help either
You need float _AlphaClipThreshold; somewhere in the hlsl portion, outside the function scope. e.g. after the float4 _MainTex_ST; line
yes now it works! Thank you so much @regal stag and @meager pelican ๐
im having an error on my shader graphs, how can i fix it. note: i upgraded my project from built in to hdrp
Is it possible to make the stencil to work on on what infront of it? by that i mean between the object with the stencil shader on it and the camera, but cut nothing that is after that object
Hello, I made a shader for post-processing effects which most of my sprites use. One of these effects is a brightness effect which can range from -100 to 100, where -100 turns it completely dark and 100 completely white. However, changing the brightness value for one sprite does it for the others. I think I know why this happens, but I'm not sure what it's called, or how it can be prevented. Can anyone help me define this? Thank you very much for your time.
hello, im new to untiy and im wondering how to create a cartoony outline effect like the image i attatched, if anyone could provide any tips or support that would be much appreciated
thanks
I am following a tutorial for a water shader but the water waves basically flash flood the entire map, my first instinct was to change the scale of the noise but that didn't do anything other than change the speed of the waves
It's a single big cube but I need it to be a single big cube for other reasons so is there a way to make the waves smaller
tried to fix with a tiling node
but it's 2D
Why am I getting this weird effect on my alpha? The preview shows it the alpha is completely transparent but the scene view shows something completely different
Looks like it's going negative. Put it through a saturate() node at the end and it should work
Before adding the waves to the position, multiply by a new wave height property.
The usual way is to (in the shader) create a second mesh, which you then extrude outwards along the normal vectors, and then you flip the normals for it so you cull the front face (so it only appears behind your object). I think there might be a built-in shader for it?
ok the thing is the problem isn't exactly that they're too high but they should be applied on a smaller scale, like for example the voronoi for the ripples was too small, and it looked huge on the scene, so I had to make the voronoi scale like 50 for it to look normal
also
I ran your scene. I also tried a reflective plane with the standard shader. Your shader and the standard shader both worked, and the environmental reflections moved, while the player moved/turned. With similar performance between both shaders, since they're using the same lit routines (and using reflection probes).
do you know how to get the built in shader
If the mesh's size is controlled by its transform's scale, you can get that fairly easily in the shader (there's an object node that holds it). If it's procedurally generated or something, so its size isn't primarily controlled by the transform's scale, you can create a property and set that using a script.
the waves are generated from a gradient noise so I guess it is
Looked it up, there's a package for it (at least one): https://docs.unity3d.com/Packages/com.unity.toonshader@0.6/manual/index.html (you can turn off all the features you don't want)
and what am I gonna do with the scale of the mesh if the scale doesn't make the waves smaller
How are you generating your mesh?
Actually just rather than feeding a UV or something into the noise, feed in the position
the mesh itself is just a cube that spans the whole map, and the shader displaces it with this
A cube only has vertices at the corners, so you won't be displacing much
you'll just move the four corners around
so I have to subdivide the cube
Indeed
you want your subdivisions to be the same size as the waves or smaller
ok
still floods
I'ma send the whole shader
anything about it
it gives me a 404 error on hte github page
it doesn't for me, it sends me to https://github.com/Unity-Technologies/com.unity.toonshader
@karmic hatch
For some reason the image is really small so I can't read the text
ok I'ma send different parts of it
In your tiling and offset node, in place of UV0 put in the position
ok
still goes above
these are my settings btw
That fixed it. Thanks! I'm newish to shaders so I'm still learning.
Between the noise and multiplying by the normal vector, multiply by a 'wave height' property.
multiply the noise or the normals
The output from the noise
ok
(Since you're multiplying both together, it's mathematically equivalent, but in one it has to do three multiplications while the noise is just a float so one multiplication. Very minor performance difference but might as well take it)
partially fixed it, the waves aren't like spread out but instead a very very subtle and unnoticeable unless on the shore kind of wave
What happens as you change the wave height property?
they cover up more ground
had to set it to 0.05 to get something noticeable that respects the map
Oh also after the noise (but before the multiplication) subtract 0.5
Then the water shouldn't rise up
ok
aaaand I ran into a problem that I saw coming but chose to ignore
it's a water shader
made for a plane
applied to a cube
so stuff like this happens
the waves are still unnoticeable it just makes stuff drain up
ykw I might as well just leave it with the waves it already have
at least you can see it on the shore
Have you made the wave height property larger?
yes
If you subtract 0.5 from the noise, the waves should grow without the water overall rising
as I said it is still one big wave
and yes, I subdivided it
a lot
Did you swap the UV for the position in the tiling and offset node?
And for the tiling vector2, put in a float property for wave scale
actually this is unnecessary you already have a wave scale property
going into the noise node
what the fuck
just realised, instead of just position, either use a swizzle node or split + vector 2 and take the (x, z) components
I'll use swizzle
whatever that is
Swizzling is just playing with the components of a float1/2/3/4
yes position in, and for the mask do xz
so this
yes
ok
And then just play around with the properties until it is good
better
ok
IT WORKS
TYSM
wo'a
ayy nice :)
wo'a?
wo'a
what does that mean
wo'a
like woah?
wait
. . .
I get it now
water
#archived-shaders message
CC: @amber saffron ^^
Basically, @leaden turret, because you're using a lit shader and a metallic surface, you're using the reflection probe method. The only way around that is to do your own lighting and "manual vert/frag" type of thing if you want to avoid using probes.
Unity is auto-generating the lighting calcs.
I couldn't find this node
the only other one is scene depth
and it doesn't look like this
Seems to be an Unreal engine node
it's on unity tho
maybe there's a package for it or something; or maybe they made a custom node
Ok so they made a sub graph for it ig
ok but then how do I get the node
I think if you subtract length(fragment position <view space>) from (depth <eye>)/(normalize(view direction <view space>).b) it should give the distance between the water surface and the background
so how do I do that
in the nodes
all of those functions are nodes
oh
and how did you know that's what the node did
I'm assuming it's the distance between water surface and background.
If it's not, it's certainly a function of that
it's for foam
so idrk
For foam you just check when that distance is small, then paint the surface white
I didn't understand anything after the word from
but something like this right?
yes
then there's a depth node and you want to divide that by the z component (aka b component) of the normalized view space view direction
(it might actually be a multiply instead of a divide, now i think of it. I just remember the depth itself being biased depending on the view direction)
yes, but swap scene depth from linear 01 to eye
now I just check if the distance is less than 1
and if it is
how do I paint it white actually
Or more generally some property
yeah
Use a comparison node to do the check, and then have a branch node that either outputs the water color or white
(and a similar branch for alpha)
and it's supossed to look like this
At the moment it'll just look like straight lines
Then you can add noise to the distance and then it'll make it look better
what part is the distance
just the result of all of this is what i mean
so after all of those nodes
I add a noise
got i
it
so this
and after the branch a noise texture
I would put the caustics with the blue color before the branch, rather than adding them afterwards
also it seems you're adding the base color to itself?
oh true
in the bottom image, take the output of the addition node on the far left, and then put that into the false on the branch
is the bottom image this
yes
you're adding the simple noise after the branch, so you're just adding on average light grey to all of the water
so I add the noise if it is true
and that would go on the true?
like
in between the true
I put the add
you could put the noise in the bottom part of the comparison
and that would do it?
you want the noise to be affecting the comparison though, not the final color
oh
still white
try negating the b component of normalized view direction
now there's no foam at all
swap the inputs to the subtract node
like, make b be in a and make a be in b
that doesn't change anything
right?
aand everything's white again
yes
can you just put the output of the subtract into emission color, remove everything going into base color and set base to black?
(debug)
ok
green
you are putting a float into the emission output, yes?
the line starts out as blue?
I think
what line
the lines connecting nodes in shadergraph are colored depending on what type of struct it is. Float1 is blue, float2 is green, float3 is yellow, and float4 is pink.
Bool is purple
oh it starts out green
wait
nvm
it starts out blue
so what do I do now
is the water still green?
that is... genuinely baffling. It's a float, it should be greyscale
that subtract then goes into emission right?
and you set base color to black?
yes
can you set alpha to 1
can you set emission to black too?
if it's still green then that's probably something other than the shader being very weird
just assign like base color set it to black
i mean set both emission and base color to black, have nothing going into the fragment node
could even go all the way and set the shader to be unlit
ok
it is still green
very strange
Can you try making the shader unlit and setting the base color to black and alpha to 1
ok
still green
looks like my shader is just cursed
any post processing effects or something?
looks black here tho
only underwater tho
can you turn those off just to check
they only get triggered underwater
when the camera is underwater?
yes
ah
ok i don't know why it's green but let's get back on track and hope it's just adding on or something
can you try putting the output of the divide here into the color node
and move the camera close to shallow water
still dark green?
yes
now it's white
does it turn grey if you get very close to shallow water?
Quick question, do I need to us a URP or HDRP project to use PBR stuff? It's been a hot minute since I've messed with that stuff.
Or is it just something I can import to an existing project?
I think the default lit material already has slots for normal/smoothness/metallic/etc maps in BiRP
wait lemme see
do you mean shallow as if it's like the shore
yes
can you try dividing by 10 or something
dividing what
the result of everything that's going into the color output
yes
when do you get to the part where I get done with the foam so I can finally finish stuff up and prepare the build
don't want to rush things up but
I've been like 1hr on this
alright I'ma check it now
there are certainly tutorials online
does it change as you get nearer or further away?
yes
back to this then, if you just remove the negate node on the bottom, does it go dark near the shore?
lemme see
it becomes black
always black
it's kinda spooky actually
if you negate the output, does it change?
(specifically, does it go back near the shore, and white elsewhere)
lemme check
yes but it turns gray
not black
at the very very edge of the shore does it turn black?
also does it change color as you move the camera or change the direction you're looking in?
still gray
no
ok that's good at least
anyway so then you can just plug that into the comparison node, maybe just branch between 1 and 0 for now and see what that looks like
already there
actually you can just put the bool from the comparison into the color directly
yes
can't plug the comparison to the color
same as branch with 1 and 0 so just do that
any specks of black at the shore?
no
try adding 1 to the noise
if you set the bottom of the comparison to 10, still nothing?
lemme see
yep
still nothing
going to try to whack something together on my end and will send it if/when it works
ykw I'm just not going to add foam at all
it looks good already
and I want to get this done today
been working on it too long atp
good luck
i will dw
something tells me i've been there.. hmm..
that must be because of the map
did you notice
just stay hidden from nintendo ๐
dw this project isn't a game I'm planning to make public
at least not at this stage
of development
mayybe when I have more flexibility over it
anything yet @karmic hatch
ok
so I just have to copy that?
alr
and the bool goes into a branch, which has white on the true port
and the normal water color in the false color
and then I add it to the other color
and that should be it
right?
@karmic hatch
you shouldn't add anything after the branch
nvm
Using unlit sprite graphs for some UI images. Had to update to 2021 LTS for some unrelated reason, now half of the UI shaders render as fully white. Can't seem to pinpoint the issue. Same nodes are reused across both working and non working shaders. Any idea?
The issue occurs on iOS exclusively
@leaden turret CC: @amber saffron
Just for fun, I've played around with driving a single real-time reflection probe via script. It costs about 15 frames/second and that's on a medium desktop card. This might vary, though, due to scene rendering time. Because if the underlying scene isn't efficient, neither is the probe rendering. It's a catch-22, even at low probe resolution. Turning off vegetation helped a lot so there's some optimization that can be done in the test-scene to get closer to real benchmarks.
I've got it set to only refresh the probe if the player moves some set distance from last-known-position.
I'm doubting it is practical for low-end mobile, but I can't really test it unless I build and load it and I'll leave that to you, @leaden turret, if you want to experiment I can post more.
Such a technique makes accurate reflections.
Next thing I'll do, though, is go back to your baked probes and see if I can adjust them to not have the doubling effect and to be every X world-units apart so they don't glitch so much.
doesn't the reflection just make like a mini camera in front of the reflective face(s) and take a screenshot and put it in the face every frame
don't know why that's so performance intensive
Well, there's no such thing as a "mini camera", it's a scene camera (but I take your point that it is low resolution) rendering a cube map. The thing is it has to re-render the entire scene, or whatever layers are applicable. That takes time. Time to re-submit all scene objects, render them....and it does it SIX TIMES, the way I did it is one side of the cube map per frame, and it actually spreads it across 14 frames somehow (on the individual sides per frame setting).
So it tries to reduce the costs, but there are costs. And if your scene is inefficient, so is the reflection probe rendering.
There are other techniques, such as screen-space reflections that can basically use screenshots. But reflection probes are re-rendering. And we're in a discussion about experimenting with different techniques.
by you the scene reflections looked fine and not off / out of place when you traveled across anywhere on the map?? by me it looks like they stay in place....
They were doubled up for some reason, and not precise. But they did move somehow. Still not right though. But I haven't really played with that yet, it's my next step (see post above) after finishing the real-time test (for fun).
ahh right right yes same here, they do seem a bit overlapping/duplicated (maybe that's the blending interpolation between multiple probes at play?) and yes they kinda do slide along a bit... but it's reeeally kinda not close to satisfactory... and from certain angles it's really horribly completely wrong and off
Yeah. Right now you've got them in two columns near the center (for testing of course) but their active-area boxes are all the same and cover the entire water.
What I was going to do next was to make a "grid" of probes, say every 10 meters, low res like you have them....and have their boxes be about 20 meters large so they over lap (or maybe 15). And have them be baked probes. And then try having the player move through them.
The thing about realtime is that there's only one reflection probe at the play position. But it costs to update it. With baked, they're baked, but you chew up memory having them available even if the engine only passes one or two during any given frame.
Such a technique makes accurate reflections.
You mean the technique of to only refresh the probe if the player moves some set distance from last-known-position ? cool! def wanna test that on the low end mobile
Next thing I'll do, though, is go back to your baked probes and see if I can adjust them to not have the doubling effect and to be every X world-units apart so they don't glitch so much. ๐ awesome! thanks! much looking forward & staying tuned for any developments about that
I mean the real-time technique. The "only update when moving" is an optimization, admittedly with only a little payoff.
right, that's another thing i didnt know about; how many probes is too many probes
ah i see ok
Maybe you can mess with them from the description and see if it gets any better. IDK, I haven't really experimented with reflections on low-end mobile, I mostly play with desktop stuff so this is a fun experiment for me and why I'm engaged.
I thought you were looking at doing some form of screen-space reflection, maybe. But if you're using the lit shaders, you'll get reflections from probes automatically as the lit shaders generate/contain that code already.
Incidentally, just as a test, since you have the metallic and smoothness at 1.0, I overrode the render queue to be opaque on the material settings, and it upped the frame rate since it didn't have to draw the ocean bottom area and then blend.
i was considering screen space at some point, but i fear the limitations of frustum angle might really make things quite fugly... it can happen fairly often that a player is looking kinda downward towards the water and not including the distant landmasses, possibly making it really jarring between yes seeing / not seeing those reflections based on how low the camera angle aims towards the water...
so at this point i limited myself to - either finding a workable solution with baked probes, or - no choice, all out planar reflection
(but ๐คทโโ๏ธ i could still be convinced otherwise heh... if it makes sense somehow to still try screen space...)
TBH i'm always messing/playing with those numbers, hardly knowing what i'm doing and not sure i'm fully satisfied with the effect as-is in the demo project. One annoyance i've noticed is; if I turn metallic all the way up, then the reflections are more colorful which is desirable, but the sun specular reflections are totally blue tinted which i find not ideal... if i turn metallic down the sun specular is nice and white as desired, but island reflections are very washed out. i wish i had also bright white specular AND colorful water reflections of islands/landmass
but very cool to know about that optimization if indeed i dont care for deep water visibility... good do know ๐
Here's the script for driving the real-time reflection probe. No warranties, I just threw it together to test. Put it on a game object that is a child of the real time reflection probe. Set the public references properly to the camera object and set a move distance.
๐ ๐ awesome, thanks much!! will take this straight to the lab
Ooops got some message text in there at the top...lol
np
noted
i also do wanna try a bit what you described about grid of probes. Still not sure i fully understood how to do it right (how big should each probe box be / cover? and other questions) so will still be looking out for if you happen to play around with that and get any interesting results, but ye i'll be trying to play with that a bit
Yeah, the editor really screws with your timing, so always time with the stats window showing in maximized mode, so the editor window overhead doesn't mess with your data.
Also the UI scrips seem to be taking quite a bit of CPU side stuff, and the veg stuff I disabled to get it out of the metrics. Still only got about 80 FPS ish on mid-end desktop hardware, and I suspect the terrain system is part of the reason. But could be my system settings too.
aside from that i'm gonna be trying to develop further the test/demo project; a few more vegetation types (trees / grass etc), making a GameObject version of the scene, an ECS SubScenes version of the scene, each version with a 1-piece terrain mesh version of the scene and a 16x16 subdivided terrain mesh version of the scene to see if any occlusion culling makes a significant difference or not (maybe i'll try another version putting each 16x16 chunk with its vegetation in another subscene, a-la MegaCity kind of optimizations...) and a camera "on rails" sequence loop to demo various rendering conditions ex. narrow "corridors" of the map with limited visibility vs. large landscape views with long distances etc. so it can be profiled on mobile for lack of a proper mobile DOTS character controller
I'd try every 10 meters, so you'll have a grid of N x N probes, box sizes about 15 meters each so they overlap...play with that value. You know you can select them all and edit that size all at once so it isn't too bad.
ah cool right ๐
so like this
the false is the normal water texture and the output went into the base color
is this correct
@meager pelican also just to confirm - am I on the right track that it only makes sense to go Box projection? Not regular non-box-projection probes?
@karmic hatch
The proper script, no extra text
or maybe it can make sense to use non-box-projection, if each probe box is like you say a smaller 15x15 area or something...
regedit and carpefunsoftware be writing a paragraph
terrains by default start at 1000x1000, which i decided is ok to play around with for testing this game concept out (need kinda large areas etc) so if we do 10x10 probes so that's like... 100x100 probes total for the whole map?... ๐ค
Mess with it. I mean, I tried it both ways, but when it was not working, you can't really tell what it SHOULD be doing.
My limited understanding is that box-projection is more applicable to indoor type of things than it is large outdoor scenes.
also should the foam be visible in the editor
right thats what i read in docs.. not sure what i was doing which made me think box projection was the way to go...
I think he got offline
@grand jolt Sorry, we should really be using a thread for all this, and much if it isn't about writing shaders, yet, it's about how stock shaders react. I'm about ready to bail out for the day.
dw it's ok
he hasn't come back anyways
(BTW not sure what you mean about timing in regards to the metallic & water specular / reflection color ๐ค )
Well do em every 100 then? I mean, it's a test.
aha ok i'll try, no idea really - maybe 100x100 probes does make sense ๐คทโโ๏ธ truly have no clue and wondering what might be best idea to use here..
Going to bale out for the night. Catch up with you later.
re. terrain system; yes i was made aware that unity terrain is not most performant and especially not a good idea for mobile, which is why in fact i use this asset plugin https://assetstore.unity.com/packages/tools/terrain/terrain-to-mesh-2021-195349 to convert the terrain to mesh with its own splatmap shaders & stuff (which had their own complications about moving variables to CBUFFER if you remember... which still dont work on mobile for some reason..) i've been starting to try messing with making terrain meshes in blender, still working on that (no success yet...)
anyone
this is supossed to do that but it didn't
is this about a water shader?
yes
stylized water shader
I'm trying to get the foam
which one? custom? or from the asset store
custom since I believe it's better to do stuff myself
or at least put some work into them
well it's from a tutorial
but I did it manually
ah cool, which tutorial?
lemme get it
the thing is the node this guy used doesn't exist for some reason so we had to come up with an idea to get around it
i'm kinda looking around for a good water solution for my project too, ideally performant & lightweight but with certain effects
and since it got complicated I decided to just not have foam and he told me he was gonna try to get it to work for himself and then send it
been trying to follow some tutorials myself, totally newb to shaders
so he sent it
I did it and it doesn't work because it wasn't the full thing, so I just guessed some stuff
maybe look at how some other guys do it? ex. https://assetstore.unity.com/packages/vfx/shaders/stylized-water-for-urp-162025
hey our hero is here ๐คฉ
you're remapping the noise to be almost exactly 0.5 at all times, the In Min Max(2) should be 0, 1 since that's the range the noise covers
In this video I showed you how to make a water shader that has foams in it. It is one of my most requested video so far.
In this video you will learn how to make a simple or cartoon water shader and a Dynamic FOAM shader that you can apply to any water shader or can work as a base for adding foams in your water.
I have tried to explain everyt...
oh
and is the foam visible from the editor
Should be
you don't need the clamp
My clamp was on another branch, bc i was using an exponential and didn't want it to get mad
ok
or actually you might use it if you're using it for the color
but you don't need it for the foam
For the gradient noise, use position <world space>.xz
ok
as the uv right?
yes
alr
strange
and this happened
for the FoamNoise&Thickness property, make sure both values are >0
are not zero?
yes
if you make the g value larger than the r value the noise should start doing its thing
what g value
it's a vector2, it has an r and g component (x and y)
if they're different, it doesn't actually matter which is larger
what did you put in for the UV?
yeah you want the x,z components; this currently does xy by default but the y is vertical so it doesn't see any change
yeah but split doesn't give x and z combined
swizzle
(also there is a combine node)
just put the position into the swizzle
oh ok
a float doesn't have a z component, that's why it's mad
yeah currently i think you were setting it to black and then for whatever reason that gets greenified
in the branch, just lead it to a color node with white
or a float node with 1
alright I found it
the final
test
IT WORKSSSSSSSSSS
:)
TYSM @karmic hatch
tyty
trying to make a toon shader with a scribble effect on shadows. right now it uses GetMainLight().shadowAttenuation as a mask for the screen space scribble texture. what I want to do next (and where I'm stumped) is adding some noise to the shadow edge so the jaggies are not so noticeable. I want to avoid upping the shadow resolution itself. any suggestions?
I was wondering how I could hide the backface with this shader?
Suggestions? Just off the top of my head....
Although you're doing screen-space shadows, you could distort the UV with some noise based on world-space xz location or some such. World space so that static objects would have the same distortion value every time. It would change for moving objects of course, but so does screen space.
Then there's just the scale of the textures themselves...might reduce the "jaggies".
Hmmm....
Looks like the material already renders only front faces. Can't really tell well from that image though, but the inspector panel's material settings say front face.
Backfaces are hidden, but if you want to make the faces not render through each other you'll have to change it from transparent to opaque
if attenuation ranges from 0-1, you could multiply attenuation by (1-attenuation), multiply that by some noise, and then add that to your attenuation value (this way it won't de-attenuate to <1 if it's meant to be complete shadow, and it won't go >0 if it's direct light)
Could use * step(0, dot(normalWS, lightDir)) (or maybe with inputs swapped) for masking these shadows too, that would help hide the jaggy parts on the side of that sphere.
Can still add some noise before the step if you don't want it straight (e.g. + 0.01 * noise). And to the shadowCoord used for sampling the shadowmap too.
hey guys, i'm wondering, how would i be able to make an object be rendered directional, that is, no matter where you go the object is still in the same place, pretty much like a skybox
Hey, how would one make something in shadergraph that "stretches" a tunnel
as in the tunnel looks short from the outside but it takes longer to get through it than it seems from the outside
but what about warping a tunnel around you at the same time ๐ค
like here : https://youtu.be/a7TjmtVMmLo?t=6211
https://www.youtube.com/watch?v=kEB11PQ9Eo8 this is a good example
i think you could do that by adding a mesh and making the mesh a camera render of another place and if you walk in the tunnel you get seamlessly teleported to that place
but in shadergraph i don't really know a lot about shaders
can i use Shader.Find() for Shadergraphs somehow?
if i try Shader.Find(MyShadergraph.shadergraph) it returns null
https://docs.unity3d.com/ScriptReference/Shader.Find.html
The string passed in should be the same as it appears in the shaders dropdown on a Material. Will probably will be something like "Shader Graphs/Name"
Though as it mentions in the docs, it may be better to provide an actual reference to the shader (e.g. public Shader shader) or it might not be included in the build.
yeah, i didnt think that i have to add the "Shader Graphs/"
with the Shader Graphs/ infront of the name it works. Thanks for the answer tho!
i added them to the always include shader list in the project settings
Halp, the screen position node output seems to have its y component negated when rendered via an overlay camera. Behaves fine with a base camera. Any workaround to retain the same behaviour across both types of cameras?
this is in 2021 LTS, iirc was fine with 2020 lts
this worked like a charm, thank you!
can you not just use a skybox?
the reason why i wanted to use that was for a moon (i use BiRP) and the way i saw some people do it was just making a sprite move, one downside is you can go behind it, but you may think that you could just make the sprite move with you, but then the moon would render first than say a tree, and you could also say, use a lens flare but lens flares work weirdly, they disappear instantly, but i want them to be able to be seen just a little bit if you're behind a tree or something
you could create another camera that doesn't move around, and then use that as the background
could you explain it a bit more? like how to do it etc.
I haven't done it before myself, here's a tutorial https://www.youtube.com/watch?v=OmCjPctKkjw&ab_channel=Unity
In this video we're going to take a look at Camera Stacking with the Universal Render Pipeline, in short URP, using Unity! Using Camera Stacking you can layer game UI in Unity very quickly, and author high quality user experience.
Download the Cockpit demo, along with other URP example projects here!
https://on.unity.com/3jUFeQm
More info on...
'Error unexpected token 'float3' at line 1'
I am not seeing its problem, can you?
float3 works just fine in other custom node hlsls
ah there was a missing , further down the line
trying to emulate specular and having weird results. The result looks nothing like the output of a Lit shader, its hard to describe how its not right, its just like completely lit, or lit contrary to light direction, its just wrong
the problem cannot be the code so it must be one of the inputs
what space should the world light direction and view direction be in to calculate specular?
I think the normal has to be in world space too?
Yeah, use the Transform node, Tangent to World, Direction mode
๐ That's looking right now
first time using world space normals
hmm interesting
there is a difference between when I built it from nodes vs. when I did it from a single custom node
The custom one must be right since its the original code
but as far as I can tell I didnt make any mistakes in the non-custom one
ah wait I think I found it
Yeah fixed it, the mistake was normal got used twice but I only set it to world space on one of them, not both of them
does anyone have any examples of modifying the normal buffer in AFterOpaqueDepthAndNormal?
whenever i try to do it, it just returns a solid white texture
texture proccessing question:
- Noise looks real nice for making a procedural texture
- The same noise however makes for a normal map full of very hard edges
Is there a way to like, lightly blur it to reduce the intensity of those edges?
๐ yeah I think it is primarily the voronoi thats introducing these edges, Ill google check that out
https://iquilezles.org/articles/smoothvoronoi/ ๐
What is a Hash2f ๐ค I tried googling it but no dice
source: Inigo Quilez's smooth voronoi
google only has 8 results for hash2f and none are shader related
I believe it's a function returning a random vector. Can see IQ's implementation in the shadertoy example : https://www.shadertoy.com/view/ldB3zc
vec2 hash2( vec2 p ) { p = vec2( dot(p,vec2(127.1,311.7)), dot(p,vec2(269.5,183.3)) ); return fract(sin(p)*43758.5453); }
Oooh you're right you're right
that made it click in my brain I have it (renamed) in another custom voronoi based on IQ's work
Yeah that's the method Unity uses in their Voronoi node. Either will likely work
Does anyone know how I would go about a planar projection of a texture onto another object so that it's written into it's render texture? I know it's possible to raycast onto an object and then draw a sprite at the hits UV coordinate, but that means it's dependent on the UV mapping... so it would be different sizes depending how the object has been UV mapped... I'm looking for a way to do the same but within world space to keep the sizing consistent between objects
OK, not sure I understood that. Let me spit it back at you and see if I get it right:
- You're doing some type of (probably triplanar) mapping of a texture onto an object.
- you want to raycast and get a "hit" location, and figure out how that location maps to the uv space of some render texture that you then wish to update?
- but you're concerned about size somehow, and want it based on world space?
Sorry, I'm really struggling to describe it myself.
But yes I think so.
So I'm after what you might get in Blender when you're painting, or Substance Painter
Right now I have a version that raycasts, gives me the UV of the hit, I feed that into a shader
Right! You want to "paint" (or whatever) onto an object.
And I draw a sprite there, but if I try it across two different objects
Then the size changes, so I assume this is where it needs to be in world space, or something like that
Exactly
I want to be able to paint across two objects keeping the size consistent
Please excuse this question, but why would you draw it on two different objects?
If there is one object in the world, you might want to paint on that... then walk around a bit and paint on something else
Or maybe it's a modular level and you want to paint across modular sections
I already spent a couple of years working on a paint system, and I model everything with all it's issues in mind
But I'm basically trying to refine it so it's less dependent on how objects are UV mapped
So I can just use whatever objects I like
Let's say we have one 1-meter cube, two 2-meter spheres and three 3-meter capsules in "our world".
You want to be able to apply your paint decal and not have it change size?
And further
You want to set a modular template for all capsules?
Sort of a decal, I need it written into the render texture that's on the object
But yes not changing size is the aim here
As you can see from the link I sent I already have a pretty robust paint system but if two objects are UV mapped differently it results in different sizes
hmmmm
If you didn't have to "stamp" it onto other objects, the answer is easy, as you know. You have unique render textures for each object.
Nice link/vid BTW ๐
This is really hard to talk about.. I think that's half the problem, thanks
So the easiest way to really describe it is imagine if you had a projector
You load an image into it
So you're thinking you want to translate object1-uv-space to world space, and then world-space to object2-uv-space if it fits at all.
You fire it at an object, or even two... and however the image lands on the object, I want that to be written into the texture
I think so yes
But I'm just struggling to fully comprehend whats involved\
OK.
But can each object have its own unique uv-mapped render texture to write into?
Yup
So in the video I sent there are actually two walls, theyre basically just quads, theyre side by side... and because they have the same UV maps, it works
WIth some trickery
But I'm wondering if there's a way I can do it across objects when the UV mapping isn't identicle
The wall in the video is actually 3 walls wide, with a render texture for each
OK, one more question (at least).
Let's say we're projecting onto a screen-space sphere. What happens to the "backside" of the sphere that isn't visible? So I "splat" a bullet hole at some sphere and it hits at the side relative to the view direction, so only 1/2 the bullet hole actually shows. What should the render texture contain? See? Did the paint "miss" or did it wrap around the undrawn back side? Or is this not an issue?
Like in the video, those are just planes, they don't even have a back face
And you can't get behind the walls
UV's are already size relative.
BUT....you need to know on a pixel by pixel basis, what the UV value is regardless of size.
IDK if I'm making sense, let's see.
If I had a projector and it projected a "star" onto a wall, and another one onto another wall that is beside it but bigger.
That's where I'm at, I think I'm a little too stupid to comprehend whats involved
You don't want to have the same UV coordinates....and you wouldn't if you can somehow take the projection and map that to world-space UV results. Which is what you were asking to start with and now I'm getting it.
Do you by chance use a color index scheme, or are you using all three rgb channels to hold color?
I'm using channels
So they're not set colours (indexed)
Does that make a big difference?
I was trying to cheat.
If you could free up two channels to store the uv values that ended up being used as it was interpolated across each polygon, you could get at them easier. Each pixel would know it's UV value ON READ.
If you project onto a "wall" whatever pixels you had projected onto would "know" their own uv's.
Question, I have this dark spot in my height map, you can see its quite rounded.
I'd like it to be more steeply deep, but I havent been able to figure out how to multiply the values just in that specific range without affecting the steepness of the rest of the overall height map
Nah, there's other ways, just checking if I'd get lucky.
you can see in its hight map its pretty flat
Sorry for being slow, still here, just thinking
NP, me too. I'm thinking about how we do it when we know the geometry because it is stored in a buffer for the shader to access. Let me think for a bit. AFK.
Okay ๐
@tropic sluiceOK, I'm the one that's slow. ๐
So I THINK you're already doing what you need to do. By that I mean:
How are you, now, casing your ray such that you decide on where to paint? I mean, with just one wall?
Somehow, you're projecting a ray onto a wall and calculating where to splat, right? And updating a render texture. Just one wall....
Yes
And if that one wall happens to be a "small wall" it works. And if that one wall happens to be a "big wall" it works.
I just use Physics.Raycast, the RaycastHit gives me a UV coordinate, I then have a custom shader that I use with Graphics.Blit to draw a sprite at that UV coordinate
I feed the UV coordinate of the hit into the material I use to blit
And also the distance of the raycast which I use to scale how big the splat is
But it means very little because it's dependent on the UV map scale at the end of the day
And yes if the walls have difference scaled UV maps, the splat is of an inconsistent size
Ha!
you can go backwards from that.
Because it's drawn in UV space
That's exactly what I'm wondering
I can't work out how to do inverse UV space conversions and such
You want UV-Space to world-space (which is exactly what you asked, I'm just dense).
So Like I said here ^^
Yeah that sounds about right to me
But I think I'm stretching my poor brain a bit too much ๐
This crap is never considered "easy", just "experienced".
It's sounding more and more like a world-space projector to me.
Yes
So if you've seen the projector thing in Unity... I basically want something like that which can actually write what it's projecting into the target objects render texture
Now if I knew off the top of my head the formula, we'd be all set. But I don't. Others might.
The thing is, you basically need to rasterize your bounding box if you can get it in world space, by the UV values, and map that rasterization to world-space interpolation onto another object probably regardless of orientation.
It might just be adjusting 2D height/width ratios. Come to think of it.
If I paint a splat onto a 1x1 wall, and then want to copy it to a 2x2 wall, I've got to cut the uv's in half and then locate an orientation/offset point.
newUV.x = rt1.width/rt2.width * spat.uv.x + spatUVOffset.x;
newUV.y = rt1.height/rt2.height * spat.uv.y + spatUVOffset.y;```
Of course you'd pre-calc with width/height stuff so as to not do it every time.
I guess but the whole uvmap couldnt vary in density
Imagine how you UV map things, some areas take up more of the UV space
So the scaling might even vary across the UV map. nevermind between two different uv maps
That make sense?
Yeah, OK, so you need it to adjust to the new-uv-map however it is mapped.
So we're back to "how do you do it for wall 1"?
Can you "just" ray cast to wall 2 and get UV info? no? I mean, if you spat a circle onto wall 1, you can hit several triangles in one spat, and they could be uv mapped anywhere, right?
Yes the raycasts give you back a UV coordinate
Do you basically ray-cast each pixel?
Yes they could be uv mapped in any crazy way
So most of my objects are actually perfect squares, ie, they match uv space perfectly ๐
No crazy stuff
No I raycast once, feed that into a shader, and then I turn every pixel that's within a certain range of that UV location white
it draws a circle
If raycasting were performant that would definitely be an option
But it's a lot of pixels and a lot of raycasts ๐
But if you cross a triangle boundary, the uv maps COULD be split anywhere in the texture, conceptually, although they'd share at least one point.
BBIAB, AFK for a min
So you paint, it gets drawn onto the uvmap as a perfect circle if you're actually looking at it in uv space, but once it's mapped onto the object it's distorted
I think it's because I need to draw somehow from within world space, and then transform it so that it fits into the UV space
This is for wall 1. Only one wall. Right?
If I could work out how to do it with one, I'd spend time working out how to do it to two later ๐
OK, I thought it was already working on wall 1, and you "just" had a problem with wall 2.
Nope, that game is done.. it works
But it has the limitation that my objects basically have to be square planes
If you think of it like this... I'm casting a ray, it gives me a UV coord, I open up the texture and draw a perfect circle.... But if the uvmapping is all wonky, it wont look like a circle back in the world
I need to be able to project from world space, and convert it into the UV space so its wonky in the wonky uv space
Rather than the other way around
If you go into blender for example, and have your cat do the uv mapping of an object for you...
And then try to paint on it, it'll see look kind of okay
Right, that's what I'm worried about.
But can't you "rig the system"? In other workds, no weird UV mapping allowed?
But OK, let's project it into non-wonky uv space. By that I mean since we have a render texture of known size that we write into, and we know world space locations of ray hits...
It'll look silly in the uv map view though
I mean, you're talking about rectangles, right?
Always rectangles that you paint?
Squares map perfectly to uv space ๐
So do rectangles.
But no matter.
We know the world-space locations of the corners of the quad.
We know the ray-hit location. We know the spalt size.
Yes?
Yes
Non-wonky UV space is "just" the % across the quad in each direction.
So let's say we use UV set 4 for non-wonky uv space.
UV0 can still be whatever it is for texturing base albedo.
So the quad's uv locations range from
x-start-WS at UV.x=0 to x-end-WS at uv=1
And similar for y.
And the splat is somewhere in the middle of all that, conceptually.
So the spat uv for the center is
uv.x = (splat-WS.x - quad-start-WS.x)/quad-width-WS
uv.y = (splat-WS.y - quad-start-WS.y)/quad-height-WS
This basically demonstrates what I'm doing wrong vs what I want to do
And yes the UV map is intentionally very wonky ๐
What I'm currently doing is like when I draw into the UV map
What I want to do is like when I draw onto the 3D object
I see.
OK, the thing is that raycast.rayhit is done on the C# side, right?
Then you pass it into the shader
OK, the C# side knows the whole mesh, and there's a c++ routine backing the function call, that is basically going through all the mesh data, figuring out what polygon the ray hit, and then knowing all 3 verts, it calculates where the UV's for that polygon were hit by the ray.
ok
so you can get the uv coordinates for that polygon?
where those vertices lay in uv space?
Yeah, there are ray-triangle intersection tests....
If you want to wamp through the mesh on the C# side
But oy...
Sounds like it could be slow
yeah.
But IDK why you want to do that. Just use another non-wonky uv set, like uv4
No wonky, no problemy
Assuming you're drawing on flat planes
I think you have a point, maybe it will sink in soon
So it's basically just use another uvmap for paint only
Winner winner chicken dinner!
So let UV0 be the normal texturing, no paint. UV4 be the paint uvs
So I have artists that just do whatever the hell they want
Then I go create a really simple planar uvpmap or something
Yeah
In the other UV slot and use that
๐
That makes a lot of sense
But you'll still have "challenges" if it's not planar objects. But for walls, or flat stuff, no problem.
There's probably other ways, storing decals instead. So you're painting on some invisible quad that gets projected onto the non-planar object, and you'd have to distort the paint to map back to the quad, and IDK how to do that exactly.
But for planes/quads no problem.
Yeah I like the idea that things distort if you're not painting head on
It distorts from the spray cans perspective
Because that's how it would work if you were doing it in real life
But it's not the end of the world
As a trade off for a much simpler soluation
Well, again, I'm confused as to if we're talking about planes-only or not
Because if not...decal system should be thoroughly investigated.
Using projection.
im still trying to work out the requirements
but basically planar projection should suffice
i think your idea of just doing a planar projection uv map is a good one
what blender and substance can do is very cool, and required because people are painting to non-planar objects a lot
most of my objects side of a train, a wall, etc
so some aren't truly planar, but they're near enough it wont matter
@meager pelican thanks for all your help
Yep, or you drive it all from C#, mostly. And then just "paint the result" using a shader.
Glad to help (and I hope I didn't confuse it).
Hello, how can I use more than 16 sampler2D slots in my shader?
Thanks for any help!
Why would you need that many textures?๐ค
Or rather samplers.
Custom shader with different configurations, usually not all of them are active at the same time but the compiler still throw errors I guess when compiling all variants
What are the textures for? Can you not use a texture array instead?
Or an atlas with multiple textures in one.
Has 3 albedo, 3 normal, 2 metallic and 1 occlussion, 1 emission, 1 parallax, 1 height, 1 cutoff, 1 SSS, and some other slots for Special effects like wetness, snow, dissolve, etc
I can't use an atlas because some textures are already 8k textures needed for a high end human skin render
WOuld you help me understand the concept of texture array?
But really, it feels like you're putting too much work on 1 shader.
What exactly do you need help understanding about them? It's an array of textures, I'm not sure how to put it more simple that that.๐
yeah but I know there are limitations from what I am reading because the GPU sees them as a single object
Im concerned they all need to have the exact same attributes
not all albedo are 8k textures
they also need to be able to set independently at runtime, not sure if this is a limitation
Im also concerned a texture array has the same source, meaning if I have x4 8k textures into an array that would be a 16k texture and is not supported I think
Anyhow, because I dont think textureArrays are an option and going back to the original question, forgetting the reason of why I need it, Is there any way I can I use more than 16 sampler2D sots?
They are of the same size, yes. But you could sample only within the bounds of the actual texture size(handle that in the shader).
You can set them at runtime.
And I don't think Tex array size is calculated as a sum of its texture elements.
I guess you could reuse the same sampler for a few textures if you really wanted. Check the docs page on samplers.
https://docs.unity3d.com/Manual/SL-SamplerStates.html
Thanks, I will take a look!
Im having trouble remapping a very shallow range of values into a deep spike of values
the plateau is so samey that using stuff like power exponents isnt working
it keeps turning into a punch out
discord bot wont allow me to post a gif because apparently its explicit
the whole thing gets pushed in instead of gradiently pushed in
Why is my compute shader creating a bunch of memory use with repeated uses when recreating a buffer everytime I use it? I release the buffer and I don't think theres anything referencing it so why it the memory adding up?
How do you know that the memory is adding up? Are you looking at the memory profiler or something?
Task manager
Also this is in the editor
How do you know that it's the compute buffer then?๐
Because I release it as soon as I'm done with it
Oh sry
Just a note, but compute buffer is allocating VRAM. Not RAM.
Because I temporarily disabled it and it worked
What worked?
I constructed the compute buffer only once, but then my mesh wouldn't modify even if I re-set it to the shader.
I also tried using set data to clear it each time but that didn't work either
In your task manager are you looking at RAM or VRAM?
Im looking at the tab that says memory
That's RAM. So it's likely something else in your code that keeps on allocating
Also, you should probably use the profiler instead of task manager
ok
Let me see if I can find any other references to the buffer
It's not the buffer...๐
Oh, ok
Could it be because I'm setting buffers/textures over and over again?
(not creating them, the SetBuffer() function)
No. Although I'm not sure how you're doing it... It's something on the CPU side.
Need to see your code to tell for sure.
Ok, I have two potential culprits, I'll send them really quick.
Also any general pointers for how to optimize this would be nice too cause I don't know how compute shaders work to well, specifically managing the buffers and stuff
Check #854851968446365696 on how to share code
Ok one sec
First one is used at runtime aswell, second one is just editor.
The Bulge function is what causes it over time when I try to raycast it through the editor script
I got double specular working thanks to your code - the mesh itself is using Unity's real Lit, while the heightmap 'resin' has its own simulated specular
Try setting filter shared mesh instead of mesh. Also, have a look at the memory module of the profiler to see what eats the memory.
ok, one sec
Check this for more details on mesh/sharedMesh and why it might be "leaking" memory for you.
It is your responsibility to destroy the automatically instantiated mesh when the game object is being destroyed. Resources.UnloadUnusedAssets also destroys the mesh but it is usually only called when loading a new level.
https://docs.unity3d.com/ScriptReference/MeshFilter-mesh.html
You should be able to see what exactly is occupying how much memory. I think it was supposed to be in the profiler Memory module details. There's also a dedicated memory profiler, although it needs to be installed via the package manager.
I don't see any buildup at all in that graph.๐
Interesting, my task manager still says 84% even now
That could be from before the changes. Did you restart the editor?
I'm in the detailed part of the memory profiler and I'm looking for it now
Then you still have the leaked meshes in memory.๐คทโโ๏ธ
So it's meshes?
Most likely
Did you read my message about mesh/shared mesh?