#archived-shaders
1 messages ยท Page 10 of 1
It samples each mipmap level of the texture (lower resolution versions). I don't know how the gpu stores/connects them exactly but it's different from an array which requires each slice to be the same dimensions.
To sample an array you'd use
SAMPLE_TEXTURE2D_ARRAY(texture, sampler, uv2, slice) or
SAMPLE_TEXTURE2D_ARRAY_LOD(texture, sampler, uv2, slice, lod)
Ah, of course. Mip maps.
You're using time and a sine function, so that will return negatives. Try adding a saturate node before plugging it into the color. Just a thought.
I can't sample texture arrays in vertex stage though, can I?
Like Uri said. lol ๐
Should be able to, though you'd need use the LOD version (to specify which mipmap is sampled). The regular one uses ddx/ddy to calculate a mipmap level which is only available in the fragment stage.
SAMPLE_TEXTURE2D_ARRAY_LOD will work in the vert stage
Since the two legends have gathered here, do you mind having a look at the thread that I created yesterday?@regal stag @meager pelican
Good. But what I still don't understand is why it is so different between scene view and game view and the game view is the one that worked.
oh guys btw if you remember my elipsoid vertex clip problem. Turns out position node returns post skinned positions that are in who knows what space so I had to bake the pre-skinned ones into a extra uv channel to get it to work
I saw it yesterday but I have very limited knowledge on compute shaders, so no idea sorry
But it's not like I can set the mip map levels manually, right? And even if I could, they would have to be of different sizes.๐ค
And I'm no legend, and not in Cyan's league, but if you give me a link to the thread I'll look for fun.
You'd typically let unity take care of it. But if you're trying to generate mipmaps on a rendertexture filled from a compute shader I'm not too sure. Maybe you can read that back on the gpu, have it generate mipmaps, then send it back? ๐คท
Thanks. Here's the link.
The idea was to be able to use texture arrays to sample custom data per vertex index, but I guess I'll have to either use structured buffers or several textures.๐
Using a texture array would've been more convenient from several points though.๐ฎโ๐จ
Wait so why can't you use a texture array? ๐ค
Because I need it sampled in the vertex stage and it doesn't seem to work.
I want to interpolate the sampled data
Using custom interpolators.
It should work if you use SAMPLE_TEXTURE2D_ARRAY_LOD(texture, sampler, uv2, slice, lod)
Wow. Is there such a thing?๐ฒ
Of course ๐
I'll give it a try.
yeah thats for sampling in the vert stage
but you have to provide mip level yourself
Wow. A bit out of my league too, but I'll give you some paths to track.
The graphics system includes a FENCE for deciding on when execution of a given routine has been completed for all processors. It's kind of a "Lets all wait here until EVERYONE is done". That exists on the individual core level, but there's also a level in the graphics pipeline itself.
https://docs.unity3d.com/ScriptReference/Rendering.GraphicsFence.html
(more in next post)
I knew about the Texture2D one, but didn't think there's one for an array.
as far as I understand texture arrays they are nothing more that a old school texture atlas laid out sequentially in memory so in a way they are a Texture2D
But in general, when I call Dispatch in C# does it queue the shader to execute after all the previous dispatches? If I have several shaders that depend on each other's work, is it safe to just dispatch them in order?
IDK of any "common workflow" to keep the data serialized from a render texture. I mean, other than read-back and storing in a serialized object.
There's not even any guarantee that the GPU won't discard the whole thing during some massive OS operation and demand the texture gets reloaded again by the engine!
I seem that'd make sense.
I ended up copying the render texture to a texture2d when I want to save it. It seems like render texture doesn't store color data on the CPU.
At any point.
Ouch, not sure. In general they will be dispatched in order, but IDK if you can guarantee that they don't work in parallel. But use fences in that case. e.g. dispatch1, dispatch2 that checks fence1 before proceeding, dispatch3 that checks for fence2...
right, it doesn't. It's basically a buffer on the GPU.
I see. I'll have a look at the fences if I feel like something is being broken. ๐
It seems like Unity might just handle it. The GraphicsFence docs mention
GPUFences do not need to be used to synchronise a GPU task writing to a resource that will be read as an input by another. These resource dependencies are automatically handled by Unity.
I've seen this HDRP docs page the other day, which made me think, that there's an execution order.
https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@6.9/manual/Post-Processing-Execution-Order.html
Nice. Didn't think Unity would handle that for me. But hoped that it does... ๐
Good point. Yeah, but if he's doing two updates in a row...fence.
That's a PP system that enforces its own execution order. So yeah, that thing has it.
But for you calling compute shaders....
I'm mistaken to use the word 'texture', I think it's more clear if I use 'image'.
My goal is to change the image tint a little bit. For example I have an image of some green branches, I want to slightly change to another green tint by the objects position.
Maybe I'm doing it correctly already with the hue node, but I wanted to pick different tint colors with the gradient myself, if that is common to do.
OK, that can be really easy. Interestingly, if you have a grey-scale leaf (basically shades of white, all same values in R, G and B) you can tint it to ANY COLOR by multiplying it by that color! Easy peasy.
So "just" pick your tint color out of the gradient, and multiply your leaf pixels by that tint color. But if the leaf starts out as only green, the result will only have a green channel in it. Whereas if it is grey-scale leaf, it can have nice fall colors with reds and even blues if you want them.
You can do masks and stuff too if you're working with an actual image and not a model.
I understand. Thank you. I will try something. In this case it's a pine tree texture, so I want to make it very slightly ๐
You could just vary the green channel by a random amount....
I will try..
I should mention too that you can do a luminescence calc and then multiply, or just use the green channel value as the luminescence. There's a node for luminescence/grey-scale in SG. So you don't have to really have an original image that is B&W because you can calc the B&W value from it.
Thanks for that. I'm still struggling to get a working shader..
I created something like this. It's working. Does it look alright to you?
I will try your black and white method later today.
If it is working, it is working! Yay.
I would have put the random result into the sampling of your gradient to vary the gradient result by a random value, then multiplied the texture result by that random gradient selection, but IDK if that makes sense to your use case.
You'd have to scale the random result range to match the expected sample gradient input
Hey, so maybe a stupid question, but can I use a RenderTexture as a Texture2DArray?
If I have an RWTexture2DArray<float4> on hlsl side, will a RenderTexture bind to it properly?
You have to create it the right way in script.
Texture array elements may also be used as render targets. Use RenderTexture.dimension to specify in advance whether the render target is to be a 2D texture array.
See the bottom part here: https://docs.unity3d.com/2020.1/Documentation/Manual/class-Texture2DArray.html
I'm getting this error if I try to bind a Texture2DArray. I guess it does not allow writing to it in compute shader?๐ค
Compute shader (TerrainBaseGenerator): Property (Splatmaps) at kernel index (0): Attempting to bind texture as UAV but the texture wasn't created with the UAV usage flag set!
Ah, I guess that answers it.
You have to set the iswritable flag. Since you cannot import 2D arrays with the texture importer, your script will have to do it.
Yeah, but Texture2DArray does not have that property
Render textures have enableRandomWrite which I've been using successfully, but it seems like regular textures are not meant to be written to in compute shaders.
I guess the issue was that I though of an RT as a special version of Texture2D
But it seems like it can be any kind of texture: 2d, 3d, array
It is special, it's writable. lol ๐
Yeah, but the point that I was missing is that it can take many forms.
Yeah. I haven't used that much, but from what I read...yeah. So each element is an RT, of the same size and I think same format.
ugh... But the regular shader still considers it as a Texture2D it seems.๐ค
Error assigning 2D texture to 2DArray texture property '_Splatmaps': Dimensions must match
nvm. I had to explicitly set the dimension property. Thought that it was inferred from the constructor.
There's macros for declaring them too, in case you didn't see this: https://docs.unity3d.com/2020.1/Documentation/Manual/SL-TextureArrays.html
And then there's full blown 3D textures, although IDK if you can write them in a shader. EDIT there's an isreadable flag on them.
Yeah, that part I've figured out some time ago ๐
I'm wondering how I put the random result into the sampling of a gradient?
was busy for a few days, but I tried doing this in an empty scene now, and it doesn't seem like it works.
It renders the fore and background in a camera, it uses a volume with DoF
I add an overlay camera on this other camera, to only render the middleground without DoF.
The overlay camera gets rendered, but it doesn't place itself between the other layers. just goes on top. I'm not sure if I missed some setting or anything, but I can't seem to get it work no matter what i play with in priority/depth/culling
keep in mind i cant select dont clear on the overlay camera, only on the normal camera(that renders the fore and back) - where its called clear depth
ill show you some pics of the settings if you'd like.
it is possible to enable/disable these things btw in the render file. I can play with this in a shader using _CameraDepthTexture (and CameraOpaqueTexture)
The gradient sample takes a value from 0 to 1, with 0 being the left side and 1 being the right side. So picking a random value between 0 and 1 using your position seed (to always get the same value at any given position) should give you a random green (or whatever colors are in the gradient).
an update: i just realized background color places a full color on a stack of cameras, covering stuff in the "back". ALSO- the lights in 2D clears the color to black
IDK if that makes sense.
will keep experimenting
could be a 2D thing, I don't do much of that. Like I said it was a guess as to a maybe-how.
Yep understood, I think you're on a good path to it though, so I'll keep trying
will keep posted
so the output of the "random range" node would plug into the time value on the gradient, and the range would be 0 to 1 on the setting of the random range node.
Is there a way to make the _Time variable in shaders not stutter in the editor while play mode is turned off?
Are there some settings for maybe either pausing it or making it update properly?
Ok, I managed to get some progress. It's funny, I notice that Z position doesn't change the color, only Y and X.
There's a dropdown on the bar at the top of the Scene View window, which has something along the lines of "Always Update"
That's because the Random Range input takes a Vector2.
The Position is Vector3 so it gets truncated (taking XY channels)
How do I get random numbers in my ComputeShader?
I tried Everything
float random = scaleToRange01(hash((uint)23523*time*id.x));
uint hash(uint state)
{
state ^= 2747636419u;
state *= 2654435769u;
state ^= state >> 16;
state *= 2654435769u;
state ^= state >> 16;
state *= 2654435769u;
return state;
}
Debug.Log confirms that the time value on the Shader side is definitely the FixedTime value
So even though my hash() function gets different inputs everytime
I still get the same freakin number out....
Omg I think I figured it out
I am multiplying it by 0 since my first id.x is 0
Yeaaaaahhhhh
Not my brightest debug moment >w<
yeah found it thanks :)
Hello! can someone help me with original code based shaders? i understand nothing about them and all i wish is to add glossiness to a distortion shader
This is the distortion shader:
the goal is to basically reflect light based on the normal map, the shader only distorts whatever is below it
I would really appreciate if someone could help me out
Maybe start with some default environment reflections.
From here:https://docs.unity3d.com/2017.4/Documentation/Manual/SL-VertexFragmentShaderExamples.html
// refection vector calculated in vert() and passed in
// v2f's i.worldRefl member via
// o.worldRefl = reflect(-worldViewDir, worldNormal);
// sample the default reflection cubemap, using the reflection vector
half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
// decode cubemap data into actual color
half3 skyColor = DecodeHDR (skyData, unity_SpecCube0_HDR);
// output it!
fixed4 c = 0;
c.rgb = skyColor;
return c;```
You can't just "paste that in" but it's an example of environment reflections in a vert/frag shader.
You have a world-space normal vector already, and can use that calc in the comment above to pass along a world-reflection vector in the v2f struct. Sample it per pixel in the frag(), decode it, and decide what you want to do with it when applying it to your result.
thank you i really appreciate your help but i seriously have no idea where to even begin ๐ , how do i use the code that you wrote? how do i apply it the distortion shader? and how does it work?
i mainly need only this shader with light reflection/gloss, everything else uses regular standard material
everywhere i search it seems it is impossible to make a transparent shader to be glossy
along with that, why is that in game the distortion looks timid
while in editor it looks much better?
Hmm...IDK, play with the power and refraction settings maybe.
As for your shader, I literally copy/pasted it into notepad and edited in the changes for you. This is a rare thing, as I don't usually code stuff for others in discord questions, that's something you need to learn to do, so I want to be clear...no warranties. I haven't even loaded this into Unity so there could be syntax errors. But here it is, attached as a file.
And that line near the end with the 0.5 hard coded in it should have said:
vDistortColor.rgb = saturate(vDistortColor.rgb + skyColor * _ReflectionPower);
omg thank you so much, ill try it now ๐
btw changing power does not help..
for some reason ingame camera gives different visual effect
hmm yes its not working as you warned ๐ , ill try to go over and search for syntax errors
pink shader yes
let me know the error in the console
ok i did not noticed you also added .rgb, so i added it now, no errors but still pink shader
This error did remain, reapplied the shader:
Yeah, I just tracked that down. I missed a semicolon.
o.vReflectionWS = reflect(-worldViewDir, o.vNormalWs); Needs a semicolon on the end.
It's line 88 in the file.
That's what I get for using notepad. lol
I saved my .fbx object with multiple uv maps. I was wondering if I could change those to my liking in shadergraph?
(blender example)
I must be googling the wrong keyword, because I cannot find anything about switching uv maps.
That's because they're uv settings within the mesh. So a mesh has sets of UVs...like UV0 set, UV1 set, etc.
But IDK how to set that in Shader Graph as something on the blackboard.
You'll have to have the model map those to the UV sets in the mesh somehow, and I'm not blender-ish enough to tell you how.
Uv node has a little dropdown that lets you sellect a uv set
I think they want to do it programmatically/dynamically.
yesss it works! thank you again! though, the result only lifted the brightness of the shader ๐
Yeah, it's just a simple additive blend. But fear not brave coder! Now that we have something to work with, we can mess with what we do.
for a notepad thats quite impressive
I see that this works, but there are only 4 in this node.. Is there a reason why it doesnt shows all of them?
lol
I'm sure there's a reason.........
somewhere
๐
It's a common...observation...
so is there a way to add this shine effect? something like in here
Let's start from the top.
What shape is that mesh that you're applying this shader to?
simple quad
i mean, i do have that preview window for shader that is a sphere
Nah, in scene.
?
OK, that's exactly what I think you asked for, but sounds like it's not what you wanted. ๐
Now it has environmental reflections based on the OBJECTS normals (which is what that shader does).
i meant something like this, using the normal map to make it shine, like in metallic objects
They're not great reflections, but they're reflections. And it is distorting the background.
OK, we can mess with our calcs. Sec, afk.
altough, if ill be able to understand how to make it look ingame as it looks in editor ill be far more then happy
i tried raising refraction and power and it never reaches the same effect
IDK about that one ....yet.
But I was going off your "the goal is to basically reflect light based on the normal map," and I took that to mean environment reflected light. But maybe not. Maybe you're talking about reflecting the main light in self-reflecton.
Like a blinn-phong reflection. https://en.wikipedia.org/wiki/BlinnโPhong_reflection_model
See example pics.
But there's another problem...
it doesnt have to reflect the enviroment, only light sources, i already have underneath a shader that does planar reflection
mm ill try to show you what i mean, one sec
in another game, I have these cobblestone that reflect the orange light above them, it gives off this highlight effect
you can see it also here with the blue light on the wet ground
OK, let's talk about "The other problem".
The shader you started the question with is a shader that takes an object, like that sphere, and distorts the background behind it.
It does that with a grabpass.
ill be back in a moment ๐
OK.
So what it does is take a screen shot and then distorts it. It doesn't know anything about the normal vectors (although there is such a thing as screen-space normals) of what was drawn behind it.
So I assumed you wanted lighting on, say, a sphere or whatever. At first. And that's what stuck in my head. And then you posted screen shots, but I didn't realize that what you actually wanted was a post processing effect or something to distort the WHOLE SCREEN.
So let me get this figured out. You are putting this on a quad the covers the screen? Yes?
Hey guys, I hope you're doing well. Does anyone knows why my preview is pink ? I followed a youtube tutorial but it doesn't seem to be working for me
And here's the tutorial i followed https://www.youtube.com/watch?v=xZNjnyuKuRQ
This is a video on how to create a grid shader using Unity's shader graph. This video uses the Universal Render Pipeline (URP), you can use HDRP or any other render pipeline you prefer.
Chapters
00:00 Introduction
00:12 Creating Grid Shader
02:45 Demo
I can work hard with your support.
https://ko-fi.com/evelyngamedev
Recommended Vide...
- Make sure you've saved it.
- you have to set up your graphics pipeline to support shader graph, and make sure that the graph type matches your pipeline.
Are you in URP?
I don't know where the problem could be coming from (i absolutely suck at shaders ^^'), maybe a missing package ?...
I think I am in URP, where can i check that ?
Graphics settings.
not really, it only appears on the water tiles, it is the lowest tile in terms of height
yup 2D
Crap on a cracker.
i mean, the tile is
the world is 3D in my game
OK
Graphics settings
so its impossible to give the same bumped normal tile effect on a transparent shader?
well....we're talking about..."Who's normals?"
The normals on a quad...are all the same flat normals. You seem to be saying you want the normals of the object drawn BEHIND the quad.
i guess to sum it up, im trying to achieve the pool water shader, its transparent with distortion and it does reflect light
yeah but i can trick the light by using normal maps, this is the one i drew for the water
OK, that's better. We're actually still on the right track, and I'm going to buy a lottery ticket because I'm getting convinced I'm psychic or something. lol ๐
So we DO want normals on your quad
But you want to use a normal map passed in.
glad to hear you are interested on it as much as i do ๐
And you don't care about the normals on the background, but you're distorting based on water surface normals.
the only texture/map the shader will have is the normal map
yes im distorting the image below the shader with the normal map
what do you mean by "And you don't care about the normals on the background"?
You don't care about the normal direction of that block under the water.
It doesn't matter anymore
You care about the water surface normal and how it distorts the background
mm i dont think so.. for the most part, everything below the shader will be flat textures with single normal upwards
And when you put the new shader on it, with environment reflections, all you got was a lighter version.
yes overall slightly brighter
basically i decide the brightness with the reflection power slider
Right on all counts. And that slider is the same for all pixels, which isn't what we want.
But we'll keep it, because it scales the whole effect.
So with your normal map, we have to calc how relfective the angle is...that brings us back to blinn-phong or some such calc
how does it work on regular shader with high metallic, low smoothness and with a normal map?
OK, that's PBR lighing. And it's a bit more complicated.
You probably don't need that for mostly-transparent water, FYI.
so its not something that will work on a transparent shader
so how does anyone make a transparent shader with light reflection by normal map? even without distortion
or does distortion also play huge role on it?
It will work but it's more complex and slower.
Hell, you can probably do it in a surface shader.
I seem to remember someone having a transparent wall of some sort that distorted stuff behind it.
did it reflect light using normal map?
Probably. But PBR is overkill for water, IMO.
if its slower then i better avoid it
AFK for a bit
Well, we have environment reflection information now (just the color of the walls/sky/whatever from the reflection probe).
We don't have the main light direction, nor its intensity/color. Yet.
And we have most of the info we need to calculate specular reflections.
And we already have some type of distorted background, even if it isn't scaled like you want it yet.
Do you want actual waves? Or just the color distortion. In other words...at the edges of the pool...right now they will be flat due to using a flat quad.
well the normal map animation already has this sort of pixelated wave
what do you mean by color distortion?
By that I mean that you don't pick the pixel directly behind, you pick a different one, causing distortion effect based on mormal mapping.
edges of the pool? if by that you mean the edges of each quad then no, itll look blocky... if its somehow when the shader touches a surface, I guess itll look nice
There's multiple quads?
multiple tiles that are quads that contain the exact same shader
tiles of water
OK, but...I guess what I'm asking is...
Are those different pools, or do you have, say, a 10 x 10 grid of tiles in that one pool pic you showed me?
umm, its both, its basically and island and there are water tiles both in and outside the island
this is basically the standard shader with blue color and the normal map that i use on water
so i mainly need it to reflect the pink pixels and everything else remains transparent
We should have started a thread.
i agree ๐
I'm going to recommend that we do one of two things now.
- Start a thread so we don't keep flooding this main thread. But I won't be able to continue following it up alone, others will have to jump in, as I'll be at work.
- check out various tuts for water shaders for BiRP. They have some methods for dealing with all this stuff so we don't have to reinvent the wheel. For example, they make waves by vertex displacement of a plane that has a lot of triangles, they do the waves in the shader, add caustics if you want them, etc.
Unity even ships with some standard water shaders you can try.
the 2nd one ive been doing all day and still am searching, that is why im here ๐
hi, using TextMesh Pro, whenever I switch the shader of a text, it also changes the shader of all texts elements to that new shader, any help? I want all texts use one TMP shader, but one text to use another.
What would you suggest for writing a shader if your looking for low level access?
Are you using a assembly reference?
An assembly reference tells unity that you want to use an assembly outside of your project assembly
I'll find an example
anybody any idea why this could be happening? I had a bug and tracked it down to sampling a render texture that i render my scene to
base.rgb = _PixelTex.Sample(point_clamp_sampler, i.screenUV).rgb;
return base;
I'm an idiot I used the wrong thing sorry, I would still like that explanation on assemby references tho
My project is the Game folder. I need an assembly reference for GooglePlayGames so I can access that assemly...
No worries. You will definitely need assembly references at some point...
I uh need to look those up because I do not know what an assembly is
Kind of overwhelming at this point, I do not know where to start learning this advanced stuff
Definitely google it. You should find it easily. But don't worry, they really aren't too tuff... Don't worry about learning everything fast, just go at your own pace and you'll get it as you need it...
Just learn what you need as you need it...
Yep, that is what I'm doing now thank you
How much difference is there between CG and HLSL?
The text is unreadable...
Does anyone knows how to stop this from happening ?? .. I dont want the texture to get stretched like that, I rather want it to get repeated/tiling across the surface area available.
My current material is made of just 1 texture and it it's connected to the base.
the material is made by Unity shader graph and its ulit type
( the scene is using urp ).
ive sat all day with this now and i never actually came to a solution with your workaround, mainly the problem being that i could never get rid off the automatic clearing of the scene color in rendering. i just think unity 2d simply cannot do this with semi transparent assets. it would've worked if i had more control with opaque techniques
I kept searching around for ways to do it in a shader instead but i just simply couldnt find any way of making a really nice gaussian blur, the problem being sampling it correctly.
Stumbled upon this article, which is an actual goldmine. He explains how they tried several methods of doing EXACTLY what I've been trying to do, and in the end deciding to roll with the method of using separate files with baked blur directly in photoshop, in the end showing up to be a way more performant and actually not at all memory issue. So I'll be rolling with this. Makes it a lot simple to handle everything too 
https://80.lv/articles/depth-of-field-in-unity-for-2d-games-with-semi-transparent-sprites/
I think the biggest issue out of all here is the way to do this with specifically semi transparent sprites, just like these guys, because Unity can't really handle it in a nice way
probably explains why i could search for this forever and never find an answer. simply because i dont think there is one simple answer
makes me wonder though how other games have done it, like ori
See, and I don't do 2D much, so I took a shot.
Glad you found a performant solution ๐
yeah :) still worth to try what you suggested. made me learn a little bit more about how the rendering works.
and yeah, as for this solution, its something that fits with my level of expertise at least so thats good.
mucho gracias!
Hello I'm new here and I've been trying to use the unity shadergraph but it stays the same default pink texture. I've changed my project to URP I'm not sure what the problem is
Is there a way to force writing to the depth buffer on a 2nd pass of a transparent material?
The first pass should be transparent and use the depth buffer, and the 2nd pass should ONLY write to the depth buffer for a later stage with decals.
Did you set the target in the graph inspector?
(Open the graph, open the graph inspector (button in top right), then select URP)
Universal is URP correct ?
universal render pipeline yea
Yes
yes
hey, I want to copy paste the nodes but that doesn't work. Im trying to export my shader graph to another project and it doesn't really work. what can i do?
Well, you can disable color writing to the color buffer (thus making it "transparent") and update depth only.
But please specify what pipeline you're in, first.
Assuming you're in BiRP and you're hand writing the shaders, research "COLOR MASK" and "ZWRITE" in shader lab.
It is in URP. I have tried ColorMask 0 and ZWrite On and ZTest LEqual, is that all I would need to do?
Hey I'm working on a stylized shadow shader that I place on a plane beneath each actor. Then It uses a "shadow caster" camera's depth texture to draw dithered shadows beneath characters. The problem is that when two or more actors get close, you can see their shadow planes overlapping and their shadow dither patterns not lining up. Is it possible for me to somehow check what was blocking the light on a fragment and only draw the owner's shadow on the plane? I can't think of how I would get that information to the fragment shader.
Shader is written in shaderlab/hlsl and running in unity 2021.3.9f1 with urp.
This may be a tough question to try and solve over discord.
Hey guys, What's the best way to show fingerprints under a UV light?
I figured a shader but my experience with shaders is minimal to none.
just dither in screen or world space instead of object space
One of my goals was to make the pattern move with the character, which I think rules out screen and world space as being a good solution.
Hey there, I just imported my texture in a shader graph and it has this weird diamond shape around it
this is the actual texture
i import the same thing into a shader graph and it gives me the light blue diamond around it
assign light attenuation to alpha
I finally found something on this (for anyone else looking for info on this...):
https://docs.unity3d.com/Manual/shader-shaderlab-code-blocks.html
https://docs.unity3d.com/Manual/SL-ShaderPrograms.html
I think @cosmic prairie is correct. It was my first thought as well.
The point being that you align the dithering pattern on the grid formed in either screen space or world space, so the squares line up when two character shadows overlap. Black is black, and squares are squares.
The problem, though, is if it dithers based on any intensity. If you're at a hard-binary shadow or no-shadow, not a problem. But if you have any degree of fade off...where the dither patterns differ, the overlaps won't match up...if that makes sense. Right now your shadows don't look like a traditional dither so much as they look like a checker pattern...always the same pattern. And if so you're in luck...just do what Peter said and use world-space dithering to align the grids.
Shadow existence is still calculated relative to the character positions, so they move with the character. The pattern is relative to world/screen space.
In theory. Did it work? If not, why not...what's not working?
I have water that has a different color depending on the scene depth, and a decal that needs to render on top of the water. The decal is rendering on render queue 5000
The water is rendering on render queue 3000.
However, the depth buffer is not being wrote to so the decals still use the depth from before the water and draws below the water.
The problem would be with the current setup and what is described, is even if you could override one shadow with the other, it will still look weird, the first shadow to render on an overlap would not be visible
So you're saying the 2nd pass didn't work? It didn't update the depth?
If you're drawing the water last except for the decal, you should just be able to draw it while updating the depth buffer. You can draw transparents and update depth. At least I think you can in URP, should be able to. One pass.
The decal is the build in solution, are you still able to draw the depth before drawing it without modifying engine source code?
Are you hand-writing URP shaders?
Or using SG?
At any rate, "just" turn depth-writing on when you draw the water. What happened when you tried that?
When I do that, it draws the depth before accessing for the shader for the water, so it treats the entire mesh for water as 0 depth, and draws it like coast rather than shallow or deep water
And the water is in shader graph, the decals are the build in shader graph solution
Huh. I don't understand that (why). I mean, the depth write happens AFTER the pixel is "sent", not before. Is it a multi-pass shader, excluding your decal-update pass, is there still more than one pass? E.G. with your decal update transparent pass is there three or more passes?
Oh, SG.
I believe it is all as one pass. When I force write depth on, it looks the same as if I render is as a geometry render pass rather than a transparent render pass.
But when it does that, the depth buffer is correct and the decals display on top of the water
Another thing I tried was a hand written URP shader that is on render queue 3001 to render right after the water that has those lines of code in the shader to try to force the depth buffer to the water level
Yeah, might be an SG thing. Not sure what's going on. Maybe post your shader so people can help debug this issue.
In theory, you should be able to have a trasparent shader, and still output depth, it's just not commonly done with transparent things.
The shader itself is quite large, because it does color calculations, and modifies the vertices to create waves. Do you want to see just the depth buffer / color part?
I'd start with showing settings.
I don't care how it looks as long as the depth value is right and it looks OK.
But from the sound of it, it's not right
IDK what SG does differently with transparent things that would impact this. If it writes depth, it writes depth. To me.
This is on URP 10, I have tried on URP 15 as well with Force Depth to on. I am using URP 10 because that is what the other developers were using when I joined the project
So 15 has an option for "force depth = true" or something?
But 10 doesn't? Because if you need to use 10, then, you're screwed.
I found this online from a different person, and this is URP 15. This did write to the depth buffer, but it had the same issue with the depth buffer affecting the water color
The other people aren't opposed to upgrading, just need probable reason to.
https://forum.unity.com/threads/urp-decals-on-transparent-surfaces.1273913/
It was from this article
The two outcomes so far is either:
No depth write, water looks fine but decal underwater
Yes depth write, but water has wrong depth texture and thus wrong color / texture
That last point, I don't understand why it would have the wrong depth texture. Confused here.
I get why they changed the decal to be a later event in that article. Because skybox is drawn before transparents are drawn.
I suppose you could try to see if you can shoe-horn the water into the opaque queue, but do alpha blending or whatever.
No writing to zbuffer gives the first image.
Writing to the zbuffer (forcing, or rendering as opaque, geometry, or alphatest) gives the second result
That shader does calculations based on the depth to determine whether or not to add white spots for foam for coastal water, or with little to no room between the water and the terrain under it, which is why it has that color.
Yeah, but the depth should be the bottom-depth.
That's what I'm not understanding.
Why is it getting it's own depth?
Wait.
I think I know.
Did you put it in the regular opaque queue? Or opaque + something.
You have to draw the bottom first.
Opaques are drawn front to back...closest to farthest.
So you have to draw the bottom (farthest) before you draw the water. So the water has to be in a higher queue number.
The water is essentially over-draw
The terrain under it is render queue 2000
That 2nd image I provided was render queue 2450 (for the water)
That's still an opaque range, yes?
Opaque is in the 1000s, Geometry starts at 2000, and AlphaTest starts at 2450
Transparent starts at 3000
Without +- render queue like you can do (eg 2999 is Transparent-1)
IDK why you want to alpha test, is there a reason?
Draw after terrain (2000) but before transparent (3000)
I want it to be transparent ideally, just writing to zBuffer
If it would help I can send the generated .shader file that the shader graph creates
Yeah, it gets confusing. IDK if URP forces settings on things based on queue number, but "transparent" is just a matter of shader settings, not really queue numbers. Per se. It about sort order though.
I'd try queue 2010 or something, and no alpha clipping unless you need it. You do need depth buffer clipping.
That effect happens with anything except transparent render queues
Damn.
Maybe others, smarter than me, will figure it out. I'm at a loss as to what the hell it is doing. It should render the <=2000's before your water, and your water should get the depth buffer value which should be the "ocean bottom". Then you should be able to blend on top of that. In theory. IDK what is happening in practice. Frame debugger might help you.
I also just tried copying the generated shadergraph code into a test hlsl shader and modifying the ZWrite property and didn't change anything either.
How do I access the frame debugger?
Aha, I have this pulled up. Is there any way to view depth buffer with it?
I can see that the water is indeed drawing after the rest of the geometry but before the decals as expected. This is similar to RenderDoc
Yeah, and yes.
There's a depth buffer view, right where you select the render target (keep reading down the page).
You can also check shader properties to see if depth write is enabled, blending, etc.
lol
Might need remapping
How would I go about doing that?
Also the Frame Debugger says that the water texture is indeed writing to the zbuffer in transparent mode, just the decals are not displaying on top of the water for some reason
Use the levels range
Top of the window
That article talked about a depth buffer transfer pass. Which concerns me, as to when it happens.
That's why I suggested queue 2010
it wont I guess, transparents dont write to zbuffer so your decal will be rendered at the bottom of the sea
Even though in the .shader I put ZWrite to On?
Before and after the water draw call
It might just be something with the decal shader, not necessarily the water depth buffer
Yeah.
Why are there still two draw calls for the water shader?
That is a good question lol. The generated .shader only has a single pass, so I am not sure. It is using gpu instancing too
So you're no longer doing a 2nd pass manually or whatever, that's good.
Just checking
Not two materials on the thing.
OK, so it is updating the depth buffer.
I cannot tell when/if the decal shader uses that same depth buffer or if there's a copy pass somewhere BEFORE the water is drawn.
But if the decal is using that depth buffer, it looks updated AF so why wouldn't the decal use it?
Isnt decal use it's own buffer? dbuffer?
That's what I'm wondering, and where it comes from and WHEN
Is there a way to write to that buffer?
Hang on, Cyan is here. (insert Superman swoosh sound)
The 3 SRP batches that includes the decals I have included here, including their details
I think decals would also use the Depth Texture, so there indeed may be a CopyPass to copy the depth buffer, or a DepthPrepass, if it can't copy.
Yeah but that's why we're trying a queue like 2010 or something in opaque, and it's updating the opaque depth buffer. So I'm at a loss right now.
Even when rendering in the opaque queue, if transparent shader doesn't have the code to sample from the decals buffer, it wont do it
It updated the ZBuffer no matter what, in Opaque or transparent. It should be a transparent so you can see under it, just need some way to update the ZBuffer information onto the decal
The decal render queue is set to 3001 in these images, to draw right after the water (3000)
I haven't looked into how URP does decals, but if it's like HDRP on opaque decals, they are drawn in a custom buffer after the opaque depth pass
Ah wait, that's not decal "projectors"
Correct me if I am wrong, but there is a setting in HDRP that says Affects Transparent, correct?
Also correct, this is not decal projector. This is ShaderGraph/Decal
Speaking of decals. How would you guys to skinned mesh decals? Im not a fan of the render the mesh into uv space and paint on a temp rt aproach, yet I can seem to think of anything else
See doc here, you're supposed to apply the decal shader to a projector : https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@15.0/manual/renderer-feature-decal.html
Either use the projector to project to the depth and underlying geometry, or use a mesh, but it won't project
Where do I find the component for Decal Projector? Is it in a package I need to import?
It should be in URP package.
iirc, new object / rendering / decal projector
What version of URP was the decal projector added? It might be on a version later than what I am on
I think 2021.2, or at least that's the earliest the docs page appears
Also, I was reading through that doc you posted and saw this. This wouldn't apply so long as I am force writing to depth texture, correct?
According to the docs, it appeared at version 12.x (2021.2+)
But this will also break your water rendering, right ?
It is currently force writing to the depth buffer.
And like mentioned, even if the water does depth write, if the transparent shader code doesn't have what is needed to sample from the decal buffers, then it won't do it
Force writing to the depth buffer isn't exactly the same thing as the depth texture though
You could technically be able to do it yourself
I guess it would also depend whether the decal is rendering using the DBuffers or a screen space method
If you're on earlier versions I'd assume it's just screenspace atm?
I am currently on 2020.3.34f1
URP 10
We are probably going to be updating our client to 2022 after the next update in a few weeks, so I can mess around with the other settings for now so I know what to do when we update.
Are you handling the decal yourself then? Or is the decal graph still a thing in v10?
The decal shader exists, but not the decal projector.
Decal shadergraph target ?
Are you sure it's a decal target, and not just a shadergraph named decal?
What appears in the Graph Settings?
I am assuming its using screen position based on this clip-space section
Yep
So, this is "just" a regular transparent shader named "decal", not a "real" decal
It functions perfectly like a decal on opaque geometry, but transparent it does not
But it is not a decal projector
I think it's just an issue of rendering order in that case
In the frame debugger it did the pass for the water, the decal after
I think atm you are writing the water to the depth buffer but those changes aren't appearing in the depth texture because it's already been copied / generated using opaque passes.
You would need to write a custom renderer feature to DrawRenderers() directly into _CameraDepthTexture
Oy.
And your water should not be thought of as "transparent" in your case, it should be thought of as "blended opaque" e.g. see through dirt, and in an opaque queue. Or wait until you upgrade everything.
These 3 images show that the water and decals are being drawn in the same batch ( I believe )
They are all under the same render loop, so could it be that it writes to the depth buffer which is used later, but not in the same render loop?
Looking at the screeshots of the framedebugger higher, everything makes sense to me :
Water is drawn first, wrinting into depth buffer
Decal is drawn after, with ztest, causing it to not display where the water mesh is above
The decals are rendering in their third screenshot, just the ones on the water are a bit lower than the ones on the land/ice
Yes, I saw that, but to me this rendering is expected, and I guess the issue is still about some parts of the decals disappearing
Ah true
If I can give some suggestion @wintry valley :
Based on the current look, you could render your decals as opaque alpha clipped, that would force them to render before water and in depth.
The missing parts would the be rendered in the water with a small blending effect that would maybe even be nice to see
Here's the render order with the frame debugger viewed. Opaque > Water > Decal
Its not so much the blending effect, it just needs to be at the water surface so when you see it from an angle you can tell where it is like on land
Couldn't you place the decals mesh at the water level then ?
The water isn't flat though, it has a compute shader that moves the vertices for waves. In theory, yes
Well, if you really want perfect water height matching decals, you can go the route of writing you own rendererfeature, that:
- renders water in a custom depth buffer
- project decals vertically on this depth buffer, and stores in a screen space decal buffer
- then in the main loop render the water with the water shader, sampling this decal buffer
I'll write that down and give that a shot. I appreciate it a lot. Thanks to @regal stag and @meager pelican as well! Appreciate all 3 of you!
In Unity 2021.3 the smoothness property in shadergraph does not seem to do anything?
can anyone give me a hint as to what changed?
you cannot use PBR properties in shadergraph anymore ?
hello i recreate a simple lambertian in shadergraph iv'e got something like that
to get my direction light i use something like that for my custom nde
Light mainLight = GetMainLight();
direction = -mainLight.direction;
oups i change my normal vector to world
and it seem to be good
but i probably can do that easyli with this half3 LightingLambert(half3 lightColor, half3 lightDir, half3 normal)
in lghting.hlsl
Smoothness should work. What are you seeing/doing that makes you think it's not working ?
I my game, I do this to use custom light edited from lighting.hlsl:
- Copy lighting.hlsl to folder XXXX
- Generate the code for the shader graph and save it into the folder XXXX
- Search for all places with #include ".../lighting.hlsl" and change to #include "lighting.hlsl" (that will link to the copy in your XXX folder).
- Edit the UniversalFragmentPBR function as you wish, and you will see the changes even during play mode (in editor, not in release).
Using this method, you can, for example, change PBR to BliinPhong (very slight gain), or toon lighting, for example.
i see exactly what you mean
is your plan to add bands to the lighting?
no my plan it's to replace shadow by hatches
greaaat
I don't know what part of the code you change that, but feel free to experiment
i find some code who perform that, but i really want to do on my own
I think that way is more powerful than creating a custom function node on shader graph
probably its way more efficient
I still have a lot of shadows, on how to quantify the shadows to replace them by points or stripes
It also took me a while to get proper shadows on a 2d character on a 3d world, because it can get messy when lighting or camera hits from different directions. I messed a bit with shader for that, then gave up and found a way easier way.
especially nice for point lights
an easier way ?? sound interresting ๐
could someone explain to me why the triplanar node uses world position/normals by default?
afaik moving any object using triplanar mapping in world space will result in an undesired effect, so I'm assuming I'm misunderstanding its uses. Would like clarifications on what it is that I am missing, if that makes any sense
Having it in world space allows to have automatic texture transitions from one object to the other, and is not scale dependant
No
Oh yeah that makes sense, thank you
I believe it's the most common implementation, nothing special to it
"depth", not "deep" ๐
But those settings are related to this : https://docs.unity3d.com/2019.1/Documentation/Manual/SL-CullAndDepth.html
You shouldn't have clicked that.
It compiles all the shader variants and then will try to open the humongus code in a single file
Next time for a shadergraph, click "View Generated Shader"
I'm not sure if it's normal for it to be 8 kk lines...๐ค
I think it's only supposed to include your code and whatever dependencies it has. Unless you're using every single node there is and in many different combinations?๐ค
Several thousand lines, sure, but millions?
I think that's the result of "compile and show code" ...
Each multi compile will create a new copy of each variant. It can really add up exponentially.
So you're saying that every shader in the project compiles into 8kk lines of code?
usually unity strips unused variants, but that button compiles all of them
Hmmm
I guess unity only does automatically for shader features, though.
I leave that to people that know more
@kind juniper okay! so, here it goes... will this lag or not? it lags a lot even an editor, its supposed to be smooth. the animation is shader-based, not animator-based.
I know there are many people in this discord, that can read people's thoughts, but sadly I'm no one of them, so I can't see your code.
Or shader graph(if it is)
Interesting.
So I have these sliced sprites. I'm trying to apply emission by applying the second sprite on the first sprite. Problem is, I'm not able to drag them into the shader graph after slicing them. All youtube videos I found told that I needed my spritesheets sliced before animating. How do I make them work with my shader graph?
It's really subjective and case dependent. Can't generalize. I had some issues with it myself, but I think I did not troubleshoot it properly and made too hasty of assumptions.
oh, that, one moment!
Hmmm... It's not extremely heavy. It should definitely not lag in the editor.
Try profiling. Maybe it's not the shader's fault(or rather not just the shader fault)
okie, certainly will! but the question is: should I bother with such a shader at all? I can just animate that flowing energy and it will probably be less heavy, especially that I'm targeting mobile only.
Hard to say. It's not super lightweight, but I think mid -high tier devices should be able to handle it. Best way to tell for sure is test and profile on the device.
Animation would be faster, yeah
okay! then animation is what I will try to choose. One more question in that case though, should I return to built-in pipeline? Or urp has other advantages aside from shader creation?
Again, the target is mobile
Your choice. There's a controversy about whether urp is slower or faster on mobile compared to birp.
It's supposed to be faster
if it's a controversy, than urp is not significantly slower, right? That's ok enough for me.
Especially if you don't employ any optimization techniques on birp.
Thank you!! Okay, then will try to stay with urp ๐
How can I smoothly fade in and out this effect? https://pastebin.com/tVqBZkgW
is it possible to make unlit shaders receive shadow? without custom lighting
https://youtu.be/m6YqTrwjpP0
hey guys im trying to follow this tutorial where it needs me to create a Pipeline Asset, but the Create dropdown is changed and the Rendering section doesnt have the same options, can someone help?
In Unity 2019, we introduced a few changes to the Lightweight Render Pipeline, including a name change! It is now called the Universal Render Pipeline - but what exactly is it? How do you use the URP? Well let's check it out!
The Universal Render Pipeline (URP) is a prebuilt Scriptable Render Pipeline, made by Unity. The technology offers graph...
In scene view, it doesn't by default update shaders every frame, so they often look slow. There's an option to make it update every frame and I imagine the performance would be fine
Certainly doesn't look too expensive at any rate
Hey thanks for the input. I was asleep when you sent this. I'm in a tough spot with this effect. I have tried screen and world space dither on this before and it causes a TON of visual noise. I'm trying to mimic the look of the shadows in total carnage, where they were part of the character sprites. This means it is acceptable for two objects casting shadows to have shadows overlap and look weird when they overlap. The problem is when one object casts a shadow onto another actor's shadow receiver as well as its own.
okay! sad or not, I already have a animator alternative to my shader and will use it. but, will make note from your information for the future possible shaders. thank you!
I'm thinking that maybe if instead of using a camera to create the depth texture, I could have a custom script that records depth in r, and an actor ID in g. Actors and their shadows would get matching IDs. Then I could use that ID channel to only draw shadows when the IDs line up. I'm gonna start by trying to just cast 512x512 rays in a c# script to generate the texture. This sounds like a good way to kill performance so let me know if there is a better way.
hello, im not sure how to word this but is there any way to move uvs in runtime? the effect im trying to achieve has the selected uv vertices move to the right, but i dont know how thatd be changed in runtime in unity
nevermind, found a solution, used 2 uv maps, one with the top line at the start, another a bit further on, then used a lerp mode between both uv maps in shader graph
Anyone have an idea how to get this kind of shader? https://www.youtube.com/watch?v=aj7_66WkVMg
Find the bounds or extents of a scene gameobject in Unity, regardless of the scale. Omarvision game programming tutorials, unity game engine. www.omarvision.com
I need it for rendering bounds. I'm currently using GL.Lines to render the bounding box but this seems like an easier implementation.
hmm maybe I should just stick with GL
Hi how would I change a color's value (hsV) there is a saturate and Hue nodes but no value
I tried this but it does not seem right
IDk what he's doing, I haven't seen his script he put on each object, but it sounds like maybe a custom inspector, or he's making/updating line renderer objects.
What's wrong with GL.Lines? He's definitely showing it in edit mode witch implies he could be using gizmos.
You're multiplying the value by 10. It's probably blowing the color out of range, I suspect.
The code here: https://docs.unity3d.com/Packages/com.unity.shadergraph@14.0/manual/Colorspace-Conversion-Node.html?q=colorspace
for HSV>RGB implies that the z component is indeed the value.
Maybe try setting it to a value between 0 and 1 directly.
Hello, I'm trying to make my first vegetation shader in HDRP but I have this weird behavior were the grass work well as a GameObject but is black and not moving when placed as a detail on the terrain (Vertex Lit). Using 2021.3.7 HDRP
Anyone have an idea of what going on?
I'm not sure if you're updating texturing uv's, or vertex positions on the model...your pic shows what looks like a vertex move to me. If those are UV mappings they're out of bounds.
Doesn't matter, though, there's two ways to update either of them:
- Update the mesh itself using a c# script. It has UV's and verts in the model. Look at unity docs about mesh data.
- Pass offsets to a custom shader, setting the offset values on the material. You may have to flag the verts with a flag to know what one you're updating. You can flag it with vertex colors indicated what vertex number you have so you know how to apply offsets.
For either, that is done in the vertex() function/stage of the shader, although texture UV's can be done in the fragment stage too, it's probably slower unless you have to do it per pixel for some reason.
how can i check if the renderer is using a particular shader pass ?
How can I smoothly fade in and out this effect? https://pastebin.com/tVqBZkgW
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
why i cant chnge the shader?
Hi for shader graph how do I reference the texture as UI's Image source image?
Need to create a new material and assign it. Can't modify the default material.
You probably need to name your texture property reference the right way. You can probably figure it out from looking at the default hi material properties or shader code.
thanks
I'm trying to animate a render texture in HDRP, the material animates just fine, but the render texture is static. Does anyone know what could be causing this?
Shader "CustomRenderTexture/CausticsShader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_Tex("InputTex", 2D) = "white" {}
_TimeX("TimeX", float) = 1
_TimeY("TimeY", float) = 1
_Speed("Speed", float) = 1
}
SubShader
{
Lighting Off
Blend One Zero
Pass
{
Name "Caustic Shader Pass"
CGPROGRAM
#include "UnityCustomRenderTexture.cginc"
#pragma vertex InitCustomRenderTextureVertexShader
#pragma fragment frag
#pragma target 3.0
float4 _Color;
float _TimeX;
float _TimeY;
float _Speed;
sampler2D _Tex;
float4 frag(v2f_init_customrendertexture IN) : COLOR
{
float time = 0;
time = sin(_Time.x * 20) * _Speed;
// Scroll UV coordinates by time
return _Color * tex2D(_Tex, IN.texcoord.xy + time);
}
ENDCG
}
}
}
Where do you actually update/render to the texture?
unless it's a new feature I'm not aware of, a shader/material cant change the content of the (render)texture itself
well.. maybe except a compute shader..
I would assume they are using a Custom Render Texture asset. https://docs.unity3d.com/Manual/class-CustomRenderTexture.html
I'd check the Initialization and Update modes on that. If they aren't set to Realtime it's not going to update automatically.
I made a scan line shader, I was wondering if there was a way to rotate the final result?
I could change the frequency of the Checkerboard UV but it only scrolls UP/Down or Left/Right.
The rotate node (both UV and Rotate About Axis) just change the color of the input and not rotate it.
Is there a way to do this in the shader graph?
Rotating the UVs input of the checker node should work
I completely missed that :x
Yeah, I tried rotating it in a different place (Where Optional Sprite was)
Works now
Thanks :)
Thank you, I found another solution which I said under my original question
How can I smoothly fade in and out this effect? https://pastebin.com/tVqBZkgW
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
so, it is a new feature I was not aware of...
Wait, that feature was available from unity 2017? and I only heard about it today ๐คฆโโ๏ธ
You add parameters to your shader and then tween/lerp them on the material instance ๐
you must have some parameters in your drunk shader, just lerp them from 0 to desired value, it will make the smooth transition
Is there a way to inspect a sub graph from a shader at a particular point?
For instance... That group "Head" can I see the subgraph in there with those inputs?
I'm finding it hard to debug without being able to see in it :/
So I copied the entire subgraph, pasted it into the main shader and just hooked up the inputs into the slots there.
I managed to fix it this way but if anyone knows if it's possible to look into a subgraph at a point so you can see the results with the inputs, I'd much appreciate such information
hey guys,
i have a problem i want to render an mp4 file over a shader called Unlit and then play that video back in a loop as a affect infront of the camera but i always get this error if i try to play
Unexpected timestamp values detected. This can occur in H.264 videos not encoded with the baseline profile. Timestamps will be skewed to correct the playback for
Another toon shader in the wall?
https://youtube.com/shorts/Orl4x0Yymew?feature=share
hello, i'm trying to make a smoke trail effect in shadergraph by sampling 3d perlin noise with the world position, which is working perfectly. However I'm trying to make it move along the object by scrolling it's UVs in a specific axis, but since I'm using the world position to get the perlin noise, I can't really do this. Does anyone know how I can go about making this scrolling smoke trail effect?
mainly, i'm looking for a way to convert world coordinates to uv coordinates and vice versa
my current idea on doing this is to first get the perlin noise, then convert it to uv coordinates and then scroll the uvs
but there doesn't seem to be any way to do that
also if it helps, i'm using the built in trail renderer as my object
Do you want it to follow the object as it moves?
the object is never moving, i'm doing a raycast that creates a trail renderer immediately from the starting point and end point (can also have reflected points off of walls and such), i'm just trying to make the illusion that is is moving
Can you just take world coordinates and discard one axis?
yes and no? i can discard one axis and then reimplement it later, which is what i was messing around with when I was using the tiling and offset node
i think i could just get the noise from the uv coords itself, but then it would warp it because it gets stretched along the line?
oh wait, there's a texture mode that lets me tile it
oh i'm dumb lmao, i can just tile it and it works perfectly fine for what I need
i'm just using the uv now and not thinking about the world position at all
I'm (still) working on my thin film shader and I think I am very close, but am making a mistake somewhere I'm unclear about.
{
float3 L = inLightDir;
float3 V = inViewDir;
float3 N = inWorldNormal; // at least one of these three is not getting the correct input.
float d = inDistance;
float cos_ThetaL = dot(L, N);
float thetaL = acos(cos_ThetaL);
float sin_thetaR = (IOR1 / IOR2) * sin(thetaL);
float thetaR = asin(sin_thetaR);
float u = IOR2 * 2 * d * abs(cos(thetaR));
float3 color = 0;
float shift = 0;
if ((IOR1 < IOR2)!=(IOR2 < IOR3)) shift += 0.5; //this doesn't appear to do anything.
for (int n = 1 + shift; n <= steps; n++)
{
// Constructive interference
float wavelength = u / n;
color += inline_spectral(wavelength);
}
color = saturate(color);
Out = color;
}```
Im pretty sure at least one of my 3 world coordinate references is incorrect because when I rotate around the mesh, the fresnel colors do not change at all, only when I rotate the mesh itself do they change, which is not the expected output
my other hangup is the output and expected output differ slightly
In real life as the thin film distance increases in size it seems it goes from black to white to yellow and then starts to repeat the colors. The Shader seems to start blue, do one rainbow, and then had a dark blue gap before starting to repeat colors. Once it starts to repeat colors it looks 1:1 identical, its only the start that's a little different.
I havent been able to figure out why that is the case or correct it out of the shader
my outpuit vs a calculation of the expected output vs a real like photo of an output
theirs kinda turns greyish while mine goes nuclear white
and mine starts blue while theirs starts black
I noticed in the For loop, the more times it loops, the more blue the starting color becomes
actually the more blue the ENTIRE thing becomes
maybe this in in part causing the problem?
is there a way to keep track of a variable that decreases overtime within shadergraph? or do I need to create a separate monobehavior for that?
like having a thing gradually disappear after 2 seconds or something like that
Is there a way to get Scene Color to work in shader graph for the built-in render pipeline since it's now supported as of unity 2021?
you could set it through a script, you could also use the Time node (though idk if it's time since the start, or time since the shader started running; if the former, you'd still need a script to set the start time property of the material)
the time node does have something for deltatime which i can use, but I don't know how I'd be able to keep track of the variable within shadergraph
is there a way to achieve this same result without using an if statement?
I always assumed deltatime is like Time.deltaTime in scripts; it's just the time between frames? Not sure though now you mention it.
Anyway, you can create a float property for the start time, set it in Start() with a script, and then just use (time - startTime) as your time since start
Will probably compile to the same thing (and i imagine it's not all that terrible) but Out = w < 400 ? float3(0,0,0) : [the second one];
You could do it with a step function but the step function is step = value < 0 ? 0 : 1 so it's the same thing
syntax error, unexpected token '='
hey
I wanna be able to allow players to draw on some texture without changing the original white sheet/background.
how do I add a node texture as an overlay to another node texture ?
Out = w < 400 ? float3(0,0,0) : Out = bump3y(c1 * (x - x1), y1) + bump3y(c2 * (x - x2), y2);
do I need brackets or double == or something?
oh you don't need the second Out =
it's [variable] = [bool] ? [value if true] : [value if false]
anyone with shaders exp ?
that worked great, it no longer floods with blue the more steps I add
thank you for your help btw! i figured out how to do it without a script, i'm going to use the sine time found in the time node
Nice :)
Worth noting that you can also do it manually, with time * frequency -> sine, then you can control how fast it goes
ye, i'm just taking time and then dividing it by the duration i want, then plugging it into a sine function
Also bunp I made this a while back when you and the other guy were working together; it's mostly physically based (using the thin film phase difference); the one thing that's not physically based is I assumed that red, green, and blue were discrete wavelengths (can be changed in the graph) and that the thickness that each wavelength has irl creates a dropoff following a particular ansatz function I chose (should work in the large limit anyway).
nice
awh, damn the time isn't tied to when the object is created
here's the shader on a bubble (for the cube demonstration i made it opaque and unlit)
๐ that looks pretty accurate
The discrete wavelengths mean they do line up again so you get the large-scale waves you can see there but for low thicknesses it seems to work well
compared to what im currently getting, yours looks like those outputs
Oh so like if there are TONS of bands it gradually comes back into focus? that shouldnt be a problem I think
It's probably some minor bug deep inside screwing it up
Indeed
thankfully its not too deep,this is the entire thing
at least on this particular iteration, which is like the 4th completely different method Ive tried to approach this from
Did you post the code that made your result somewhere far up that I can search?
Why does my sprite in game not match the preview from my shader?
It has orange line where the head connect to the body and where the ears connect to the head
I posted images of the shader graph, I'll see if I can post the shader graph file itself?
here we are :)
I'm struggling to debug a compute shader that implements raycasting based on this article (https://www.gamedeveloper.com/programming/gpu-path-tracing-in-unity-part-3). Is there a way to visualize rays in a compute shader? I don't know how to visualize anything in the compute shader aside from putting debug colors on the texture.
Nvm I think I can make an output buffer with the info I want to visualize and draw it from c# since this is a compute shader. I will try that.
Anyone know?
3 hours ago I posted this, I don't think it's too hard but I'm new to shaders in general and especially "Unity graph shader" so that is why I'm struggling with it.
I'd appreciate it if anyone could give me a hint or something on ways to achieve my goal or what to google.
All I'm asking :
Is there is a way to put a Texture2D on top of another Texture2D as an overlay or photoshop layers or is there is any better way to do that?
I'll take a look; the title looks promising , maybe its what I'm looking for, thx in advance โค๏ธ
it was thx!! โค๏ธ .. yes but not for my problem unfortunately, because it relies on URP High-definition , i'm building a mobile project, I can use hd in there. :S
I might be able to help. What is the effect you are going for? I don't know how to spray decals on using a shader, but if you want to put two textures over the top of one another in a urp shader graph powered material I think you can use a blend node set to overlay.
For things like bullet holes or blobby shadows I just instantiate a plane that has an image on it and place it where the hole or shadow should be.
Thank you, I'll give it a try โค๏ธ โค๏ธ
I'm trying to combine a gpu-based culling system with indirect instanced draws. I wonder if I need to modify the data stored in the indirect argument buffers (e.g. change the number of instancing due to culling), how can I navigate this indirect argument buffer in the compute shader?
From the cpu side, I know I have to offer a GraphicBuffer or ComputeBuffer for the indirect argument. But how do I know where it gets bound to? Thanks!
Hello, why do I get this error while coding shaders?
Invalid subscript "vertex "
I get it at the highlighted line
v2f vert(appdata v) {
//v.vertex.y += 0.1f * sin(v.vertex.y + _Time.y);
v.vertex.y += 0.1f;
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex); //THIS LINE. v.vertex causes the error, why?
o.uv = TRANFORM_TEX(v.uv, _MainTex);
return o;
}
this is my struct
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
i'm not sure but can you modify the input arguments without changing it to "inout or out"?
you prolly can't write to appdata v without declaring it as inout
the code didn't give an error at the previous line
so I think I can
I used "v"
before the error
but, let's give it a try
it gives the same error
oops
oh, my bad
does it work?
yeah
oh nice
another question
how do I start the shader?
I modified vertez position but it doesn't seem to work
even if the code does not give errors
I mean, when I am in the editor, does the shader affect the object or do I have to start the enviroment?
like this
did you use any variables related to "_Time"?
it just doesn't do anything
yes
v.vertex.y += 1 * sin(v.vertex.y + _Time.y);
try play the game and check the Game window
if you want it to be effective under Scene View, you want to find an option called "Always Refresh" and have it ticked on
should be on the top right of the Scene View tab
there's not
i'm not on unity rn, but should be folded under one of these items
then prolly problems from elsewhere
gl ^^
You seem to be using the default standard material.
okay so, how can I change that?
If you have a custom shader, you need to use a material that uses the shader.
Create a new material, assign it to the object. Select the right shader for the material.
Sorry, you'll have to research that. That's one of the very basic things when working with unity. You need to create a new material asset in the project.
Hey there I got a problem with my textures
heres what is happening
Please don't ping random people. Just ask your question and someone might answer. I just happened to be online now, but if I weren't, no one would answer you probably(since you pinged me specifically).
Also, be more specific. What exactly is the issue?
Is it with the cube? The terrain?
The textures will apply to unity cube but not my blender model
Did you uv-map your mesh properly? It looks like there's no uv data or it's broken.
Well, then you've gotta do that. That's one of the basics of 3d modeling.
That or use a shader that doesn't rely on uvs. Like one using triplanar mapping.
Do you know where I could a texture that uses triplanar mapping?
It's not a texture. It's a shader. You can create one yourself.
Try googling a bit.
Alr thx
SO
So*
I don't know why but the texture works for the Unity cubes and what so. But not my blender model
Didn't you read what I said? Your model does not have proper uvs. The default cube does. That's it.
in real time, is it more efficient to change a shader or the whole material? For reference, that's for trees, so it would only apply to one or two trees at a time.
I wonder if changing shader would just create new materials for those trees, and then it would be better to use some shared material for those trees instead
Performance-wise it won't make a difference, but it's more easy to swap a material than a shader, because if the new shader doesn't have the same property names as the old one, you will need to reassign everything by script.
Also, in a build, changing the material from one that is referenced by the script assures you that all needed variants are here, but changing the shader won't.
Thanks!
Can someone help me understand why this might be occurring on my image?
I thought maybe my alpha is wrong? So I ceiled it but it still does it?
Okay so it only happens where sprites overlap...
I've downloaded a water shader graph from the asset store out of inability to write shaders, it looks great but I can't figure out how to convert it to work in World Space.
I am aiming to get the edges of neighbouring ocean plane meshes to match seamlessly, however I just can't comprehend how to convert it to work in World Space - if I simply switch from 'object' to 'world' I get weird distortions, and the entire thing shifts around when moving the camera.
I'll pop in a screenshot of the vertex displacement, if anyone has any ideas would be much appreciated :)
- Keep the Position node in object space.
- You want to change the UV input of the "Tiling and Offset" node :
- Create a new "Position" node, and set this one in World space
- Swizzle the output to keep "XZ" coordinates, and connect it to the "UV" input of "Tiling and Offset"
What causes red distorted colours like that? I assume it means something, just don't know what.. It'd help me fix it if I knew what it was
Thanks for the quick response, I'll try that now :)
Tried to use saturate node on alpha ? It has negative values ?
Swizzle Node seems to crash my shader graph weirdly
I will try it, I'm pretty new to this but have noticed that when I put 2 in front of each other it goes translucent
Thank you very much, I just tried it and that fixed it ^^
Hum ... well, you can manually swizzle, but splitting the position, and connection X & Z in a vector2 node
hi can someone help me here
I have followed this instructions but still not working https://www.youtube.com/watch?v=YfolVBo_2-I&t=163s
Enjoy it!
Full Project:
https://github.com/varpon666/Roof-Cleaner
Code and Textures:
https://github.com/varpon666/Cleaning-Game
My game on Google Play :
https://play.google.com/store/apps/developer?id=V.A.R.P.O.N
You need to explain us better what is "not working".
Also, the project source is in the video description, might be good to look at it and compare
sorry sir I'm uploading it now in github ๐
here's the link
if u can't download there here's alternative https://drive.google.com/file/d/1SfL2sS0lf3lYiG_TuJDxpsqZV-dv3jCq/view?usp=sharing
the not working part is it's not cleaning the dirt and I don't know why
Take a screenshot of the shadergraph
Hi, sorry for popping up with a random question but:
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
#if defined(UNITY_SETUP_INSTANCE_ID)
int d2 = unity_InstanceID;
#endif```
why does the code above fail with undeclared identifier 'unity_InstanceID'
what am I missing?
Can't see the node names on that screenshot.
Are IF statements bad?
Are you sure there's such a variable and if there is are you including the file that contains it?
unity_InstanceID is a unity defined variable
I have no clue if I am supposed to have it at that point, I am following the examples
In shaders I mean
To a degree. It was mostly true a few GPU generations ago. Like 10-15 years ago.
Ok so not today
this is the function that unity executes to enable it:
void UnitySetupInstanceID(uint inputInstanceID)
{
#ifdef UNITY_STEREO_INSTANCING_ENABLED
#if !defined(SHADEROPTIONS_XR_MAX_VIEWS) || SHADEROPTIONS_XR_MAX_VIEWS <= 2
#if defined(SHADER_API_GLES3)
// We must calculate the stereo eye index differently for GLES3
// because otherwise, the unity shader compiler will emit a bitfieldInsert function.
// bitfieldInsert requires support for glsl version 400 or later. Therefore the
// generated glsl code will fail to compile on lower end devices. By changing the
// way we calculate the stereo eye index, we can help the shader compiler to avoid
// emitting the bitfieldInsert function and thereby increase the number of devices we
// can run stereo instancing on.
unity_StereoEyeIndex = round(fmod(inputInstanceID, 2.0));
unity_InstanceID = unity_BaseInstanceID + (inputInstanceID >> 1);
#else
// stereo eye index is automatically figured out from the instance ID
unity_StereoEyeIndex = inputInstanceID & 0x01;
unity_InstanceID = unity_BaseInstanceID + (inputInstanceID >> 1);
#endif
#else
unity_StereoEyeIndex = inputInstanceID % _XRViewCount;
unity_InstanceID = unity_BaseInstanceID + (inputInstanceID / _XRViewCount);
#endif
#else
unity_InstanceID = inputInstanceID + unity_BaseInstanceID;
#endif
}
Of course if you want to squeeze every bit of performance, it's still relevant. But sometimes there's just no better alternative.
I guess it was supposed to be a local variable, but you forgot to declare it.
I think it all work through unity macros, but you are right I am not sure where it's declared, although i think it's declared as static
which I guess means global?
#if UNITY_ANY_INSTANCING_ENABLED
// A global instance ID variable that functions can directly access.
static uint unity_InstanceID;
There would be no point in calculating it here, if it was coming from unity.
Aaah, okay
the code I am copy and pasting is all unity stuff
Then I guess the define is not enabled
but it is otherwise the compiler wouldn't fail right?
#if defined(UNITY_SETUP_INSTANCE_ID)
int d2 = unity_InstanceID;
#endif
my code is around the define
Basically what I want is
If uv.y is even, run a performance heavy image effect, if not, don't
Would that be better than running it on every pixel?
Hmmm... Let me get to my PC. It's really hard to read it on mobile.
oh wow thanks for the help
Hard to say. Best way to tell is test and profile.
It definitely wouldn't be slower.
That's all I need
Try using the same define in your code as unity does.
#if UNITY_ANY_INSTANCING_ENABLED
yes you are right, it's not defined
another question: can I do
material.SetBuffer("_TerrainBlendParams", blendBuffer);
Graphics.DrawMeshInstanced(mesh, submeshIndex, material, batch, batch.Length, null,
shadowCastingMode, true, layer, Camera.current);
and expect the buffer to be usable inside the sahder?
unfortunately render doc shows me I am not able to bind the buffer
Did you declare it properly in the shader?
Logically thinking it should be bound.๐ค
yes render doc shows the varialbe in the shader
StructuredBuffer<float4> _TerrainBlendParams;
Try Shader.SetGlobalBuffer instead๐ค
Did it work?
nope
Hmm
I tried that before start the chat
I wonder at this point if it's compatible with Graphics.DrawMeshInstanced
but I would be surprised otehrwise
Just to make sure, you did create the buffer properly, right?
Does it work with regular rendering?
I have seen examples using the same code just with normal gameobject
if it works with that it should work with everything
but I have never seen examples specifically with DrawMeshInstanced
sorry but I dont think I can screenshot it properly
Did you try with normal gameobjects though? You could be looking at the wrong place.
no I always used the same code with DrawMeshInstancedIndirect and I cannot use gameobjects for my case but I trust that example works
I'm sure you can arrange a small test case with regular gameobjects
what would it prove if it works?
If it works, then the issue is indeed with DrawMeshInstanced. Otherwise, it would prove that there's some other issue with the buffer not binding.
Can't you use the snipping tool? win + shift + s?
What's the reference name of the DirtMask parameter?
sorry where can I find dat?
Select the property and look at the graph inspector
And yet in your code you bind it to "DirtTexture"
Btw, you should be getting warning/errors in your console when attempting to bind a texture to a property that does not exist.
so in the settextture i should put "_Dirtmask"
I'm afraid it doesn't show any warning or error
Weird
Yes
Thank u ur a life saver it works now
I guess I have to study shader graph can u recommend references on where to study?
Hmm... It's been a while since I've looked at shader graph tutorials. Just google or search in youtube and pick the one with most views I guess.
Thank you sir I owe you one
Hi! I can't get the Scene Color node on shadergraph to work. I've configured my project as the tutorials suggest. Opaque texture is active on the URP asset and the surface on the shader is set to transparent. All I'm getting is the camera background color as output, not the colors on the render buffer. Any ideas?
How do you usually pack your channels for complex shaders? Is there any standard? I usually use two textures:
- Color + Alpha
- Normal + Ambient Occlusion + Height
Metallic and Smoothness I leave out since they don't match much the pixel art style on the textures of my meshes.
Why images with material assigned overlap other UI elements?
https://i.gyazo.com/441da20bb513c99a11b52989c877ffb4.mp4
https://gfycat.com/nippyassuredgrasshopper
Panzer yours works better than my previous four attempts, and is closer to physically accurate to boot.
carpaint dragon test with it
can somebody help me make a shader? i want to make a shader that would blackout my scene
bump
.
Hi, I've got this basic toon shader
The editor writes that error
What does it mean? I've not written code
Tried to compile, errors multiplied:
What could it be? I've never received an error like that... Also restarted editor, it didn't work
:) glad it works
Something is quite wrong; shader graph should not give errors. Did you try to edit the shader code itself (rather than the graph)? Maybe try reinstalling shader graph?
No, it was a random bug with a gradient property. I removed it, added it again, and it got fixed...
Very strange
is there a way to get the sprite color modifier in the shadergraph?
like when you use a sprite renderer, or particle renderer, you can set the color and opacity of the material, but it's applied on top of everything
is there a way to access that color before it's applied?
the particle system and sprite renderer write the color you set / the particle system sets in the Vertex colors of the mesh
you can use the Vertex Color Node to get that data
oh okay! is there a way to disable the vertex color multiplication at the end of everything?
i'd like to implement my own vertex color thing
use your own material with your own shader
the shader defines the behavior
if you don't want the default sprite shader don't use it
i'm using shadergraph to make my own shader
nvm, i'm just going to use the unlit shader base for shadergraph
works perfectly for what i want
.
haha! it works! an incredible increase in performance
By not using ifs?
Or by using it?๐ค
by using it
so for context, i wrote a raytracing volumetrics script, but as you can imagine it's quite performance heavy. but i'm also using interlacing, which if you know how that works it means i only need to render half the pixels per frame. so what i did is change the volumetrics script to only run on half the pixels, and that worked!
with literally no comprimise
from 15 to 20 fps
I see. interesting to know. I guess the GPU is able to group the threads in such way that fast threads are not delayed by the heavy ones. Reducing the overall processing time.
What you mean by blackout in this context?
What do you suggest to implement water shader and river in voxel games?
Using a big water texture and tile it, then assign each tile to each voxel?
I have seen some voxel games use one tile texture for each voxel but it is
repetitive and not impressive
Use world space coordinates for water texture projection
Hi, i'm having trouble with normal and alpha channel. I need to have a normal with one mask in the alpha channel but if i set the texture type to normal seems like the alpha channel change.
Now i'm trying to reconstruct the normal map directly in the shader (using shader graph) using the R and G channel for the normal and the alpha for the mask i need and keeping the texture type at Default. But the reconstructed normal is not working properly.
Anyone have experienced the same problem?
Import the texture as regular texture, but don't forget to disable sRGB.
In shadergraph, take the RG channel (use the swizzle node), remap from [0;1] to [-1;1] (can also be done with x2 - 1) and pass them to the "normal reconstruct Z" node.
yes, voxel indices
Oh thank you!! You saved me a lot of time. Is there a specific reason to use the swizzle node instead of a vector 2 connected to the texture sampler to the RG channels?
what do you mean
swizzle is just a mask from vector4 to vector2 (in fact, any combination).
How can i make a blackout shader. I have never used shaders before so I need help. Thanks
"Blackout"?
ok, thank you! ๐
To blackout everything around me
It sounds like you have a very specific kind of effect in mind, but that description is not very specific
...Unless you're just looking for advice how to put a black screen in front of the camera
something like this, but i have managed this with lighting but i want to manage something like this without a lighting but with shader
@grizzled bolt
to have sort of like nearvision
Did you look at fog options in environment settings? Might not need shaders at all
that works
Hey guys, I've been getting back into unity, and I was wondering if there's anything crucial that I might've missed when creating a vertex shader
I did some vertex painting on the wings and the movement isn't working on the mesh, though it shows up in the preview
Can you expand the material properties in the inspector?
This
I have global voxel index for each voxel in the world, so I can choose the correct water tile for each
but you don't even need to assign UVs to the water
or are you doing some fancy mesh compression where you only send bytes for vertex coordinates?
Oh got it, it was set 0. Rookie mistake
Although it's super buggy, and plays only if I move the windows, is there a reason for it somewhere in the settings?
It's because of how the time value updates during editing time.
If you press play, it should work properly
Or enable animated materials in the scene view.
Awesome, thanks for the help
Yes, you are right. I do not need any voxel index data. Only world pos
But it is like an island, a voxel shape Island.
I would like to simulate waves towards that island
In my mind, I should send data like the direction towards that island for each voxel
Make sure to enable Always Refresh from Scene view View Options toolbar > Effects: https://docs.unity3d.com/Manual/ViewModes.html
Why masking doesn't work on images with materials assigned?
https://i.gyazo.com/441da20bb513c99a11b52989c877ffb4.mp4
Have you tried the default UI shader? https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/UI/UI-Default.shader i think its the UnityGet2DClipping part that does the clipping. Maybe you could modify that shader to do what you want assuming the clipping is supported there
Well I made custom shader using shadergraph so default UI shader wouldn't make sense. I am not sure how to use Get2DClipping part in shadergraph. Any idea?
Shadergraph doesnt support UI shaders sadly. You most likely have to do that using handwritten shaders
Do they still work in URP/HDRP?
I think cg shaders works on urp atleast, dont know about hdrp
I fixed it by adding this to Pass {}
Stencil
{
Ref 1
Comp Equal
}
Didnt realize the mask would use stencils, makes sense
@karmic hatch https://www.shadertoy.com/view/NttcRr
I am trying to reimplement your SSS cube a second time. The first time I was not satisfied with the results I got, trying to remake it EXACTLY 1:1, not 'close' not 'similiar', EXACTLY identical.
Its the only way I can be sure I am getting the same results as yours is if its exactly exact, anything less than exactly identical is useless and worthless to me.
A few questions:
- What 'space' are surface vector, sun direction, position in? Are any of them normalized?
I am having trouble translating your version's color and normal and position and direction values, yours are all based off of a For Loop checking if a ray hits the cube or not, I have an actual cube so I don't need to do that but I can't figure out how to replicate the values the loop would have given me if I had needed to do that
the old implimentation looks nothing like your original implimentation and its full of mistakes, 'close enoughs' and is just completely worthless fucking trash because its not perfect and I have no idea how to fix it
Also if the absorption color is too bright, I get pink errors, which shouldnt be possible ergo there must be a huge mistake here
{
subsurface = Remap(subsurface, 10., -0.2);
vec3 subColor = 1.2*tanh(exp(-subsurface*ABSORBCOLOR));
return vec4(subColor, 0)/(1.-0.7*dot(direction, SUN))*0.4;
}```
``` MY CODE
float3 subColor = 1.2*tanh(exp(-Subsurface*AbsorptionColor));
Out = float4(subColor, 0)/(1.-0.7*dot(ViewDir, SunDir))*0.4;```
Why would this return broken pink? How can I prevent it from returning broken pink? It returns broken pink if the ABSORBCOLOR is too bright. (I remap externally before passing into my own code)
their color is (0.4, 0.6, 0.9), mine is the same, theirs doesnt return purple error, mine does
ergo there must be a difference im not accounting for but i cant find it
starting to get really agitated
going into mental health crsisi because its not perfect and identical despite being a perfect copy paste
taking a break
Yeah but for some unknown reason this shader works on image component attached to one object but doesn't work on other at same time. Looking what went wrong
replaced SG's remap with Panzer's remap helped, I guess whatever SG remap does is not equivalent to this
im more comfortable with custom nodes now so I am doing more and more in that instead of with nodes, nodes I cant trust the output
Position isn't normalised, I think everything else is. In this case world and object space are the same but I would say object space makes more sense.
The for loop is just for rendering the faces of the cube (finding the nearest face to the camera), you already get the position and normal. AxisA and AxisB can be swapped for the two tangent vectors.
My remap assumes the input goes from -1 to 1 iirc, so it's just SG's remap with the first Vector2 fixed at (-1, 1)
weird that its result was completely different than yours though, like its night and day not the same output
setting everything to object space instead of world space made it ignore the world's light's direction compared to the object
though it did improve the look
I assume you also transformed the light direction from world space to object space
What do you mean by two tangent vectors? Those outputs look nothing like the output of the Tangent node
I didnt, let me try that now
Doing that didnt change anything, spinning the object in scene rotates the point where main light is hitting it
it looks a lot better than the first time I tried to adapt this though so its definitely an improvement
They just need to be perpendicular to the normal and they and the tangent vectors are for a cube
I am not comfortable with making substitutions that I don't understand, its already not identical to yours so the further away it becomes the less I can trust the output to reliably match yours
everything is in object space now but that means if I rotate the mesh, the main light rotates, which is not how it should work
MainLightDirection transforms as a direction not a position
changed, no difference
I swapped it because it wasnt working with direction
view direction is still in world space, does that need to be object as well?
Yes everything in object space
why am i putting everything in object space, couldnt it all be in world space if the end result is the same?
It could, but object space also makes it independent of scaling and whatnot
Good point, I want that ๐ค
putting view in object space seems to have made it 1:1 to your implimentation
Im not fully clear on how it differs from the first time I did this, other than that I used custom nodes instead of rebuilding the math as nodes, gif in 1 sec
the red one is the first attempt
seems to be working a lot better
I'm developing a voxel game and have begun working on a greedy-mesh algorithm to decrease the number of vertices used in each chunk mesh. Since fewer vertices exist, now the UVs are being stretched. Since varying portions of the chunk mesh have different levels of UV-stretching, I can't simply have the tile texture repeat x-amount of times across the board. From what I've read, my only solution to this is to create the shader myself.
Here's essentially what I want the end product to result in:
In addition, the texture map has over 10,000 unique texture tiles on it. In some way, I have to tell the shader to use its given UV coordinates, and then repeat the said texture based on- I imagine world space? Thanks.
Awesome :)
I will play with the values in hopes of getting it looking closer to this, but first shower and lunch time, I might be back if I get stuck again, thank you as always for the help
I've got this rectangle hugging the terrain with raycasts - is there any way I can make sure it gets drawn on top of the ground layer?
increase the frequency of raycasts/vertices. Ideally you want vertices precisely on top of that hill.
Hoping someone can help me. I am using a nice grass shader with my procedurral terrain. It all looked just fine a second ago, i chose to update my networking setup and boom. It's like Unity is not rendering the material properly or something.
Here is a picture of it now, and also for reference how it looked before. I changed nothing regarding the grass...
I am really hoping there is just some known way to get Unity to get its shit together with this? ๐
Once again, i changed NOTHING regarding the grass. Only updated my networking system. So this behaviour seems odd..
I have tried restarting btw. Still no luck.
Ayo, quick question as I'm new to this stuff..
How do I make it so that my sprite won't so stretched up?
it should be looking like this
you might have to set it to transparent here, and then plug in the Alpha
Im running into the same roadblock I ran into the first time I tried to adapt this
the front face is burning white and the backside barely transmits anything, no matter what values are provided
there is no value for 'density' or 'less transmission' that isnt also 'burning wash out the front face'
am I just using it wrong?
is there a step you are doing that im not that somehow changes this?
I cant get the bellow look
something is critically different that is completely altering the appearance
it was like this before and its still like this now and I cant figure out to fix it
getting agitated again
why wont it just @#$@#^@&ing work
why wont it be this, what am I missing
bump for this ^^
I'm writing a shader that is supposed to edit a rendertexture before another rendertexture/material is using for its main texture. Can someone help me troubleshoot why my red pixel at (1,1) will not show up?
The writing shader:
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#pragma target 5.0
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
RWTexture2D<uint2> _ShadowTex : register(u1);
RWTexture2D<uint2> _ShadowTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
_ShadowTex[uint2(1,1)] = float4(1, 0, 0, 1); // red pixel at 1,1 does not appear
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
col = col * _Color;
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
Hey, I'm trying to change that Vector4 in my code, but I get this error, any ideas why?
Here's the code btw:
private IEnumerator OutlineFadeIn()
{
for (; material.GetVector("OutlineRGBA") != new Vector4(1f, 1f, 1f, 1f);)
{
material.SetVector("OutlineRGBA", material.GetVector("OutlineRGBA") + new Vector4(0.1f, 0.1f, 0.1f, 0.1f));
yield return new WaitForSeconds(0.01f);
}
yield return null;
}
oh.
I might know why
What is the formula for the length of a cube of known size's intersecting ray from surface normal out its back?
like if a ray from the viewpoint hits the surface normal, what is the length between it and passing out the back of the cube, represented as a color on that surface
expected output is nearly black at the edges, and oversaturated white at the poles if its rotated 45 degrees, since that would be the longest possible length through a cube corner to bottom opposite corner
this is the distance between the dead center point of the cube to its surface
I need the distance between the opposite face of the cube to its surface ๐ค
am I correct in my assumption that if this was representing the distance between the cube front and cube back, it would NOT be a circle?
can anyone confirm that such a formula even exists?
a cube of known size, what is the length of a ray intersection from any two points on its surface?
am I just wasting my time googling for it?
why is this so hard to find?