#archived-shaders
1 messages ยท Page 7 of 1
oh i thought it was a hash value
fml I'm done trying to use shader graph in unity, tut is not even a year old and can't follow it either
shader graph is a mess to work with
agreed
can you explain how this line works? every VAT demo I see does not convert to UV coordinates, just straight out casts a uint into a float. shouldn't vertCoords be in the range of 0...1 if i want to use it for texture sampling?
struct appdata
{
uint vertexId : SV_VertexID;
float4 vertex : POSITION;
uint inst : SV_InstanceID;
};
v2f vert (appdata v)
{
float vertCoords = v.vertexId; // THIS
...
}
Would likely depend if the texture is being sampled with Sample methods, or just using Load (which uses pixel coords instead)
i'm using tex2Dlod, i'm assuming that's normalized coordinates?
If you want UV coordinates that's not SV_VertexID that'd be TEXCOORD0 for example
unless I'm just completely misreading what you're tying to do here
i'm trying to bake animations into textures. x axis is the individual vertices of a rig, and y axis is the frame count for the animation
but i think i messed up my texture baking process as well, i fix that first and see if my shader improves
ok I missed that this was a shader animation
ok you may need to do something like take vertex id / vertex count if you need normalized coords (or as Cyan said there's apparently a way to use pixel coordinates to sample textures so maybe that's an option to use the uint more directly)
you probably need to know the width/height of the texture either way to map your 0-1 or 0-vertexcount number to an x/y in the texture, right?
i'm super confused because every example I find on github treats the first argument as uid (vertexId) but the second seem to be a normalized coordinate for texture sampling. am i trippin?
Can you link one of these examples
and also this seems like a nice package
https://github.com/mattatz/ShibuyaSelfieCrowd/tree/master/Assets/Packages/VertexAnimator
i really don't get what happens when they cast uint to float
so here float normalizedVertexId = vertexId * invTextureWidth; it looks like they're dividing the vertex ID by the texture width
which makes sense
so you're going from a vertex id (uint) to a normalized value (0-1) which indicates the x coordinate of the pixel on the texture
I'm assuming the y coordinate will come from the time factor
so each row in the texture is a frame in the animation
so float vertCoords = v.vertexId; is just a typo i guess
first paragraph, without the bilinear filtering
my shader looks like this, so i do divide by tex size
float4 vertex_sample(sampler2D tex, float4 texelSize, uint id)
{
float vertexCoords = id;
float animCoords = _Time.y * _Speed / texelSize.y % texelSize.w;
float4 texCoords = float4(float2(vertexCoords, animCoords) * texelSize.xy, 0, 1);
// @TODO: offset
return tex2Dlod(tex, texCoords);
}
hmmm i see that
I'm wondering if they're somehow doing the texture sampling in "pixel coordinates" instead of "normalized" coordinates somehow in that example
something like what Cyan was mentioning earlier
like what does tex2Dlod(); expect
normalized or pixel coords?
or it's just a typo and they forgot to normalized it ๐
not sure
at least now it's not a big blob but an almost correct set of vertices ๐
i inverse LERPed my vertices on the CPU side and convert back in GPU side
could this be that I have no normals? ๐ฎ
gamma question ๐ค if I highpass filter a texture in photoshop and then use the Overlay blend mode, the middle range greys should not change much/at all.
Bringing that same texture into Shadergraph, I would expect the same behaviour, but instead Overlay severely darkens it
If I multiply by 1/2.2 (gamma removal) it works as expected.
How do I save out my files/work gamma-less in photoshop? I dont want to be constantly gamma correcting within shader itself
is there anything I can do about this on the Unity's side?
my setting is to linear but im still getting gamma problems? because the source file's gamma is wrong? But in photoshop there's no gamma option on save out
same problem again - even though there is a wide range of colors, the lerp doesnt see that because gamma is fucking up its sampling
maybe I should ask in artasset workflow ๐ค
Hmm it looks like unchecking sRGB in the texture import settings is enough to move it back to the linear space even though it was exported from photoshop in 2.2 gamma ๐ค
I guess that also explains why it always seems like the one-minus range has way more lights than darks even though I know both of those ranges are 'linear'
ill keep this in mind in case I ever want to do any falloffs in gamma space? ๐ค
how to project image to a plan object in unity ? can it done in unity?
what's a "plan object"?
its plane im typo/get auto correct. its done thanks
im stil confused in main preview my effect its well and its look like a like. but in my viewport its even no get rendered?
its in hdrp
The image is very blurry to read the node names, but I think you are pluging the swirl into the emission ?
HDRP is using physically based lighting with physically based light intensity value, making the direct and ambiant light VERY high intensity (look at the directional light intensity, it's about 100k).
What you see is correct, it's just that the emission is totally washed out by the scene lighting : raise the emission intensity by multiplying it with a constant, or use the emission node to control it more easilly
how do i send zero length compute buffer to gpu?
its done when im put btm node to base color too
yeah thnks
the switl
Please re-read yourself and correct, it's very hard to understand what you said :/
haha my grammarly is off sometimes in discord.
but thanks
im ask again sorry for to much ask, its hologram animate up and down but i want it to consistent up and down in any angle not like the first picture but like in central angle like in second picture.
Use object or world space position or UV rather than screen space/view space position
alpha is black when URP Sprite Lit shader is used with image. Any possible solutions
I am trying to create a shader in a URP project that displays a grid pattern on the surface of an object, where the grid remains a static size regardless of the scale of the object (no stretching).
Right now I change the parameters of the material via script as the object is resized, however the Z axis does not work correctly and I'm not sure what to do. I considered there must be something I can do with normal information, but I don't know how to use it.
Any ideas are appreciated.
This is me extending a sample I found and not knowing what I'm doing
I feel like this would work fine if it was the actual mesh changing and not the scale of the object.
you need to use a triplanar shader
If the cube is always aligned to all axis, you could use the worldspace Position, to avoid needing to send in scale values. Bit messy, but something like :
Each side is also masked here using normal vector, similar to a triplanar shader as Praetor mentioned
Ok, at least I had the right thought trying to do some sort of normal mask...
I think I understand what is in that flow
If you mean the UI Image component, shader graphs don't really support UI properly. The shader generates multiple passes, and overlay UI tries to render them all.
Switching the Canvas to "Screen Space - Camera", assigning a camera and choosing an appropriate Plane Distance (e.g. at near plane value + 0.01) does work though.
this is how my animation baking looks like. It resembles when Dr Manhattan was reincarnated from thin air more like an actual human
do you guys think adding normals would help this?
because to me it rather looks like the vertex order is messed up big time
i'll ask again: are we 100% sure that SV_VertexID is the vertex ID going from 0 to Nvertices, in order? The same order that UnityEngine.Mesh.vertices goes?
this is when I use the original vertex coordinates (static mesh with MeshRenderer), but output the baked anim texture to the fragment shader color
seems right to me as only the limbs change color
i'm guessing it has to be the shader that's wrong
Ok will try tomorrow
Thanks ๐
can anyone tell me what the type for a property assigned with CommandBuffer::SetComputeVectorArray should be on the gpu side?The docs don't say (that I could find), so I'd assumed it might be Texture1D, but that doesn't work. I've tried a handful of different types I could find in the hlsl docs that might be applicable and haven't found one that doesn't cause an error, so I'm obviously missing something.
nvm, float a[size] seems to not throw an error, thinking too much in C# brain
@grand jolt Yes, the order should be the same.
I would greatly suggest to also add a half pixel offset to the sampling coordinates, to be sure you're not getting the value from the neighbour pixel, or some interpolation
float3 vertex_sample(sampler2D tex, float4 texelSize, uint id)
{
float vertexCoords = id;
float animCoords = _Time.y * _Speed / texelSize.y % texelSize.w;
float4 texCoords = float4(float2(vertexCoords, animCoords) * texelSize.xy + 0.5f, 0, 1);
// @TODO: offset
return tex2Dlod(tex, texCoords).xyz;// * _VATScale + _VATOffset;
}
so like this? i just added the +0.5f
If you do this, you're offseting the sample by half the texture ๐
You want to do +0.5f * texelSize.xy
float4 texCoords = float4((float2(vertexCoords, animCoords) + 0.5f) * texelSize.xy, 0, 1);
OMG IT WORKS
JUST LIKE BLACK MAGIC
yep, should work
yeah and no compression
i even downloaded import settings from others' VAT githubs just to be sure
also I was using renderer.BakeMesh on the renderer's sharedMesh and that didn't seem to modify the mesh. that was the other bug from yesterday
Why would you want to do this ? ๐ค
i'm making a vertex anim texture, to render a bunch of people without heavy CPU calls
now i shall see if calls are actually reduced in a minute
Ah yeah, had to reread and think twice : so applying a skinnedmesh.BakeMesh to a meshrenderer+meshfilter
Can you get a Render Texture from a Overlay Camera?
I want to save explicitly what an Overlay Camera is seeing.
is there an easy way to remove this weird black pixel line that polar coordinates is generating?
its not even happening at the "end" of the texture because the texture gradient starts and stops at black, that yellow/green is the 50% mark
if I add 0.5 to offset it so that the black part overlaps that line... the line becomes yellow ๐
pretty sure it has something to do with texture compression ๐ค but imt not sure why its occuring at the 50% mark instead of at the ends
the gradient starts and stops with black, not yellow
This doesn't look like black on the right to me
its black enough, its not yellow at the very least
hm wait is it because its trying to lerp between the two ends, and 50% of the way between the two ends is the yellow
because its trying to blend across
I don't get your issue...
I seed the gradient texture, I see the preview of the sample node, it seems correct to me
AHHH this !
No, it's not because of lerp
It's texture mips : where the uv.x goes brutally from 0 to 1, the sampler will force a very hight mip value, sampling the highest mip of the texture, that is probably yellow-ish
mips you say ๐ ๐ค
If you don't need mip maps on the texture and anisotropic filering, disable mipmap generation on the texture asset
That's the easy fix
Textures "LODs"
Sweet that worked. I don't think I need mip maps for this ๐ค
its a very small teture
you are right the red doesnt go fully black though ๐ ill fix that
Mips are not only about texture size, but help to reduce rendering artifacts when displaying a texture from far of the camera
Ahh
seems fine
It really depends on the texture.
See the moire effect here : https://en.wikipedia.org/wiki/Mipmap#Overview
In computer graphics, mipmaps (also MIP maps) or pyramids are pre-calculated, optimized sequences of images, each of which is a progressively lower resolution representation of the previous. The height and width of each image, or level, in the mipmap is a factor of two smaller than the previous level. Mipmaps do not have to be square. They are i...
Anyway, problem fixed now ๐
Ahh yeah that checkerboard looks pretty awful without mips
wtf
i get the same batches as if i spawned the same number of objects with SkinnedMeshRenderer
my FPS is much better as it was 37 before
did I screw up something? do I have hidden calls from CPU still? :S
I believe URP does dynamic batching only for particle systems, and static batches only show up in that counter during playmode
All the rest will be handled by SRP batching which you can examine more closer in the frame debugger
do you think assigning the same material with color Material Properties would help?
one way to find out
Hey guys, i'm having trouble with shaders in unity. Trying to make this custom platform for beat saber but everytime I make an asset and put it in it takes or a black-like colour or a white/blueish light colour. I tried making a material and it automaticly takes the other shaders or something... Anyone who knows how I caan fix this?
It also doesn't matter what shader I choose, I always get the same two colours, black or blueish white
If I have N objects, each with the same mesh and M materials (that refer to the same material, with property blocks), then I can expect N x M draw calls?
If I modify my shader to use GPU instancing, that will reduce the N x M significantly, right?
I'm asking because now my shader has no instancing enabled, and I get 10K draw calls with the exact same params, and I'm wondering how I could optimize this
@grand jolt Assuming that you are on URP from what you asked previously, it's worth looking into what SRP batching does and how to work with it
It seems more effective than instancing or dynamic batching in many situations
i opened its documentation and it was Mandarin to me ๐
i'm trying to understand normal instancing first. I see that having M materials per Renderer makes it M calls, but I can live with that if i can get 1000 objects to have 10 calls
Being on URP may make this process a bit more confusing, as URP will default to SRP batching whenever possible and you will have to do some extra steps to disable it for instancing to work
https://docs.unity3d.com/Manual/SRPBatcher.html#intentionally-removing-compatibility
okay then i'll try with SRP batching
You can try all the options, just be mindful of what's happening under the hood
Hard to test instancing if SRP batching disables it, or causes almost exact same performance savings
https://catlikecoding.com/unity/tutorials/custom-srp/draw-calls/ this article is really clearly written, in the context of SRP
but in theory it's possible to eliminate draw calls by having the same N meshes with multiple materials (i assigned the same mat to all materials on mesh)?
Yes
Though it might not be reported by the statistics window
It only seems to display draw calls reduced by static and dynamic batching specifically
the turorial talks about the stats window so i'm assuming it'll reduce ๐
Which tutorial?
Probably the most important note about SRP batching is that it doesn't reduce draw calls, it reduces their cost
i really don't get this, and i do want to reduce draw calls
anyone knows how to check if you're using URP or HDRP, im trying to find the exposure node but i dont see it, even tho I think im on hdrp
You don't have to reduce drawcalls to improve performance, and SRP batching often beats the traditional draw call optimization techniques for much less work
If you do want to practice those techniques I would recommend you use built-in RP for it to keep things simple (especially so if your tutorial uses built-in RP)
i'll first understand how normal GPU instancing works
Shader language translation question - what are the equivalents of "sin_thetaL" "sin_thetaV" in a unity shader's code/language?
or maybe my mistake is something else entirely
okay fixed the = and the truncation, but that first question remains
hmm I didnt fix the truncation
I see why its happening but im not sure what it should be instead
oh wait its not a vec3 it was just a float all along
okay fixed it for real
but still no idea what sin_thetaL and sin_thetaV are or how to replace them with real things
I assume its sine, and theta, of whatever L and V are??
oh wait thats from the next step I didnt read enough
so nevermind everything Im dumb for not reading ahead
(it was the dot product)
im following this tutorial but im not getting the expected result
the result is white and I dont know how to debug whats wrong with it
he defines d = _Distance
but no where does he declare or show what that is
he has a variable for distance in and unrelated earlier step, which he sets to 1600
and using that value here just makes it white
I dont understand why its not working I copied it exactly every single step
going into mental health crisis now because im too fucking stupid to see where i made a mistake in copying someone
cant do a single fucking thing right on my own ,cant even fucking plagarize without fucking it up too
If anyone knows the answer to my question you can still message me, cause i'm still looking for an answer ^^
Does using the absolute thing to sample a rainbow gradient look OK?
How is the depth value in the depth buffer calculated?
Would anyone happen to know why my sprite and shader is making the hair semi-transparent?
Had my wires crossed!
in vertex ?
So, I'm trying to make a portal using the Render Pipeline.
I need to find a way to get the screen space coords to make the portals actually look like portals instead of just a render texture plastered on
Portal is one of the most celebrated videogames ever, and its core mechanic certainly got people talking when it first released. In this video, I go over some of the core concepts you'll need for making your own portals in Unity! This project uses quite a lot of C# scripting and a couple of HLSL shaders, but I try and go over the core bits in de...
Yeah, that's URP not Render Pipeline
Uh, I meant Shader Graph
Sorry, I'm trying to do it with Shader Graph
Sometimes English is hard, my bad
you should be ablte to transfer that shader code to nodes line by line
Hmmm, okay, thanks
I'm still not entirely sure what nodes would do what...
Like, this is what happens. It doesn't seem to do much.
When you're calculating the horizontal lines
yeah its done thanks
i want manipulte the strength 0 - 10 and make animation for it any idea how to do it? im still new using it. i know use time node but dont know how to setup.
I would guess you have to decide what to put in Strength
Perhaps some property multiplied by cosine(frequency*time)
ah yeah but i need the first is 0 then going to 10 not steady at 10.
Cosine goes between -1 and 1 at regular intervals
Yeah, I'm still unable how to convert that Shader into a Shader Graph
I have no experience with Shaders, only Shader Graph so I'm not sure what corresponds to what
Well, go through the code line by line. There's usually a similarly named node for each shader function.
I've tried that. Some of the functions don't have similar nodes
Then ask specific questions. We can't read your mind.
you can make custom nodes and just copy/paste the function
I don't wanna do that. I don't want to use shader code at all.
We can't help you if you don't provide any specifics...
I was talking to Tach.
I can't help you without more details either
Well, I've been messing around with the code and found that for some reason, using Render Textures isn't working when I have URP enabled.
Like, without the Forward Rendering Pipeline, the default Unity one shows the render texture correctly from the cameras point of view
But when I have the FRP on it just shows a section of the skybox
Aaand we went into a different issue entirely... I thought you were trying to convert a shader to shader graph?
Yeah but while I was trying to do that, I realised it wasn't working because the _MainTex was just giving me a sky box chunk
So I changed the material to a regular Unlit Texture one to see if my shader was doing that and nah, it's the render texture just being given a sky box.
Again, it's very difficult for us to reply if you don't share more info, like screenshots or code snippets... Render texture works the same way, wether it's birp, urp, regular shader or shader graph, so the issue must be somewhere else.
If I remove the FRP, the Render Texture works perfectly fine, displaying the camera feed.
If I put it back into the settings, it just shows a sky box section
This is with it on
That's not enough info. We don't even know what you render into that render texture. Share details of your setup. Just rendering to a render texture from a camera doesn't even involve shaders. And certainly rendering path wouldn't affect it.
...
The render texture is rendering the camera feed from a secondary camera. Without the Forward Rendering Pipeline, it shows the feed correctly on the material of the Quad that shows the feed in game.
When I take the FRP out of my graphics settings, the Render Texture no longer displays the camera feed, but rather a section of the skybox.
Red area camera displays onto the Blue area white screen
Blue area camera displays onto the Red area white screen
If I press Delete on this, so it's back to the default Unity settings, the cameras work
If I put it back, it breaks
My end goal is a cutout shader to snip the section of the render texture that I need to display on the canvas to get a Portal effect
- That setting in Graphics determines what RENDER PIPELINE you're using. Removing the URP asset switches to BIRP.
- Birp shaders are incompatible with URP, so your shaders stop working entirely. Everything turning pink is an indicator of that.
- To confirm that the render texture is rendered properly on both render pipelines, look at the actual render texture preview instead of relying on whatever happens to it in the shader.
- I know this
- I know this, the floor textures are URP that's why they turn pink. This isn't about those, this is about the white screen.
- This isn't the issue I'm having
I appreciate your help, but I don't think I can repeat the issue for a 4th time.
Okay, so can you confirm that the render texture renders properly regardless of the render pipeline?
And if it does, then we're back to the conversation half an hour ago: provide the shader code that you have an issue to convert to shader graph as well as what you have in your shader graph currently.
The fact that you were bringing up forward renderer made me think that you didn't know this.
The render texture displays incorrectly when the URP Pipeline is being used
Where there should be a recursive blue archway, there is instead, a section of the skybox.
I bought up the Forward Renderer in case there was a setting involved that means it might not work correctly.
The shader isn't the issue. This is a different issue
I can't progress with the first issue because a new one has come up that has been the entire reason I've struggled to solve the first one.
I was only able to identify this "big boss issue" because I switched back to the BIRP
BIRP shows this
Where is it displayed incorrectly? In the scene view? That doesn't mean that it renders incorrectly(into the render texture itself). Please stop wasting our time and just take a screenshot of the render texture asset both with Birp and URP.
Forward renderer and deferred renderer are render paths that exist both in BIRP and URP, so that's totally irrelevant.
And that's the problem...
How?
Because it has to be rendered through a shader.l to be displayed in the scene view...
There is no Render Texture preview because it's dynamically created with code.
You can still reference it and view it in the inspector.
Okay.
It seems like the objects are not rendered on the birp one. Is it because of layers setup?
Didn't you watch the tutorial? It should be covered.
What tutorial?
Wherever you got that shader from
It's not the shader in this particular case, no. But the whole thing is relevant.
Did you or did you not get it from a tutorial?
I haven't implemented a single shader, because switching over to URP causes the Render Textures to fuck up
No, I haven't done anything from a tutorial
So you created that portal system entirely on your own?
Then how so that you can't answer my simple question?
"Why are the objects not visible on the render texture?"
Which question is it that I supposedly can't answer?
Because I don't use render textures that often either.
It's irrelevant.
Let me simplify: why are the objects not rendered by the camera that renders the render texture
So you didn't create that system..?
I don't work for Unity, so no I did not program the camera system in Unity
I mean the little portal setup that you have ๐
My code doesn't do anything to any of the objects in the game, there is no reason for them to be invisible
Nothing is toggling their mesh, disabling/enabling them or changing their layers
So you don't know how your portals work in BIRP despite you being the one who made them?
I can't tell if you're a troll or just misunderstanding me
I'm asking you simple things: to explain how your system works(when it actually works). And you can't seem to do it.
The code for the portals isn't doing anything that would disable the blue and red objects abilities to be rendered by the cameras onto the render texture.
It doesn't have to be the code. It could be the setup in the scene
The code simply moves around the cameras in relation to the main camera's distance from itself
The setup of the scene is irrelevant when the matrixes are all converted to local space in the calculations.
the cameras all move accordingly and there is no reason for it to not function in URP
The setup is relevant precisely because there are ways to make these objects not render by the camera.
Let's leave out URP for a moment and try to figure out how your portals work in the first place
If they are able to render while set up in BIRP, then their setup is irrelevant in URP.
There could be camera settings that are different in BIRP. Anyways we can't know it unless we know how it works in BIRP.
There are 3 cameras.
Main, R and B
Main moves with WASD
R moves relative to it's own portal based on the offest of Main from B
B moves relative to it's own portal based on the offset of Main from R
In R, the R Screen is invisible and in B, the B Screen is invisible
so each can see the other side of their own portal, which will (eventually, when I get the Cutout Shader Graph figured out) show the other side only of the alternate portal
Okay, so you agree with me, that normally R and B cameras should be rendering the box and the portal frame that appear in their frustum?
If there was a green sphere behind the blue portal, within the shaded blue box under the blue camera, then the main camera (black) would be able to see that green sphere on the red portal's render material.
But at the moment, in BIRP, the cutout doesn't work because I haven't made it because I want to use URP. But in URP, the cutout doesn't work because the only thing being given to the render material is skybox
Previewing the camera feed through the Unity editor shows the correct image
and yet, on the red portal
We don't see that same image reflected.
What we should see
Ugh... Okay. I think I got myself confused somewhere along the way.
So this is the BIRP RT, correct?
And this is the URP one?
Yes
So, the whole "objects are not rendered in BIRP" thing was incorrect. They are actually rendered in BIRP.
They don't render in URP though
Can compare the render textures now that you have materials properly rendering?
The render textures are the same.
The pink was because I didn't switch the red and blue back to BIRP materials.
So the URP one is still like that?
When I had them as BIRP materials, back before switching to URP, they showed up as red and blue on the render texture
The camera can still see the objects, as shown in the camera preview
But it's not rendering them to the texture
Take a screenshot of your camera inspector...
Is that the wrong camera? I don't see render texture setup as the output. Or if it's not at runtime, then play the game and take a screenshot again
Some interesting findings while I was messing around:
If I change the Background Type from Skybox, the camera works properly
As in, if I change it to Solid Colour...
Something wrong with the skybox?
Why is the camera disabled though?
I'm not sure if that bypasses something in the render pipeline(specifically related to render textures)
Let me try turning it on a sec
Nope, the camera being on or off doesn't make a difference
the only thing that does is the Background Type of the environment, so far
Yeah, setting the Background Type to Solid Color or Uninitialised works
Can you share the whole script? We keep on discovering things that you never mentioned, so I wonder if there's more to it...
The script for what?
The only thing the script does is moves the cameras, and then manually calls the Render
Hmmm
Device type & OS version: iOS 15 Host machine & OS version: Mac Issue Environment : On Device Xcode version: 13.2.1 ARDK version: 1.3 Unity version: 2021.3.1f Description of the issue: As soon as URP is enabled in project settings I cannot see camera feed. Camera just renders whatever is selected as Environment Background Type. Render Pi...
Seems like I'm not the only one who has had an issue like this
The skybox doesn't seem to work in my project either...๐ค
So the skybox is making your render textures weird as well?
Ah, nvm. I didn't have skybox material set up.
Hm
Maybe I don't have my skybox material set up correctly either
How do I create a URP Skybox?
Nope. Regardless of that, the render texture was rendering correctly, unless I disable the camera.(in which case it was not updating)
Need to setup a skybox material in lighting settings. The default one works.
Yeah, I did have it set up correctly. Still doesn't work. Weird...
For starters, I'd avoid calling Render manually.
We've already established that it's not causing an issue though.
We don't know that for sure. It might be a combination of factors.
Is there any reason you need to call it anyway?
I'm calling it manually so I can control when the render texture is being updated and controlled so it isn't using too much processing power
I'll switch it back to auto rendering and see what happens
Keep the camera enabled at least until the issue is resolved
Going back to manual rendering doesn't fix it
Only changing from Skybox to Solid Background Color works
Can you check that camera with the frame debugger?
Could it be that skybox is rendering after your object?
It's possible. But the camera still sees the objects in the preview window.
With the background set to a solid colour, sometimes the legs of the frames disappear behind the base. Strange
At least the portal works now lmao
Still, need to figure out that skybox thing...
Check The frame debugger. I feel like it has something to do with depth.
How do I open the frame debugger again?
Might want to look at your game tab in parallel. It displays the render target at the currently selected stage.
Yeah, that's what I've got
Not really sure what I'm looking for
The first one is the skybox in the background
That adds the skybox onto the background
But you can see the second SRP Batch puts the skybox onto the render texture
Ugh.. Wait. That's the wrong camera.
The custom renderer one is the one that we need to look at
So B Camera?
Yes
How do I get to that one?
It keeps taking me back to the Main camera when I click enable
They should both be rendering. I think it's this one
Yeah it's plastering the skybox over everything else
Can you take a screenshot with details visible
First image is before it paints skybox. Second is after.
So how do I fix the depth issue?
hmm
i'd have to change it's RenderQueue position, right?
But that wouldn't fix the strange issues with the portal frame legs :/
did it fix the issue with the skybox?
I haven't figured out how to change the RenderQueue yet
In your render texture settings, can you set the depth buffer to something else?
That fixed the leg issue
but not the skybox overwriting?
What unity/urp version are you using?
How?
Well, after you told me to change the buffer, I looked at what other options could be used when making the render texture
And? What option was it?
I just changed the RenderTextureFormat
And it works now. No idea why.
Maybe my GPU?
I know that some GPUs have issues with certain formats.
What format was it before/is it now?
I don't know what it was before.
Wait, I think I changed the GraphicsFormat not the RenderTextureFormat
R8G8B8A8_UNORM was what it was before. I changed it to R16G16B16A16_UNORM and it works now
I'm not gonna question it. I'm just gonna take the W and continue with my project.
Guess there's a possibility it's hardware issue
Or it could be a bug in your URP/Unity version. I did notice some differences(especially in the frame debugger) when comparing to mine.
It could be. I'm not 100% sure. I haven't updated it in a long long time though.
How to change object colour based on colours of other objects using shader with blend modes?
"Multiplicative" blending
Most render pipelines have an option for it without any custom shaders I think
There is no blending properties in sprite renderer
Oh, sprites don't have that for some reason
I would wager a guess that they were written for BiRP and aimply dont support HDRP
can anyone help me fix a lit billboard shader graph?
the quad on the left is just a normal quad, and the one on the right is using the billboard shader
it does everything I want it to, but the shadows are wrong as well as casting a shadow on itself
Rather than using the "Inverse View" Transformation Matrix node , you could use a Custom Function node with Out = unity_CameraToWorld;. That version of the matrix is still the actual camera when rendering shadow passes.
https://www.alanzucconi.com/2017/07/15/cd-rom-shader-2/
I'm trying to follow this tutorial. To the best of my knowledge I've done everything as written, and I have a result that is similar but not exactly what his produces. Attached is a gif of the effect - from certain angles it gets very very bright and I am unsure is this is the intended expected result or not.
Following these same steps, my result differs:
The above is the expected but mine seems to be the reverse of what is expected? What differs?
Is the tangent vector being calculated correctly?
In his code, there is no concept of the 'space' its in, tangent, world, view, object, etc. so I have no way of knowing if ive set those values to the correct "space"
using WorldTangent (is tangent vector set to world space equivalent?) I get a very blown out result compared to his example of what should be the same result:
I have a custom node that is all the parts of his code that had to be done in node
I think viewDir would be in World space
It might also help if you test with a similar cd / flat circular mesh rather than a cube
are these not world space?
His tutorial says his shape is just a quad with regular 0 to 1 UVs, so a quad or face of a cube should be equivalent right?
I'm referring to the View Direction here
Oh okay, ill make that change
Hm, I guess. I would also test in scene view too rather than the main preview since that might produce different results
there must still be flaws since mine still looks weird
Yeah I recalled the same thing - here it is in scene ^
scene is currently behaving identically to preview
This step I know 100% is not right because his pictured result and mine are not the same colors, thats the only step I know for sure is incorrect, but dont know how to correct
I did all the same mathematical steps to the same input in the same order, but the result is not the same
which is confusing and frustrating
math should be math so why isnt it working
I get furiously frustrated and my mental heal plummits because it feels like im being gaslit by the universe, the same steps should produce the same result, not a different result, this is not how real life functions
UV in, mult 2, subtract 1. Done
Normalize, done.
Make a vector 3 that is the negative of UV.y, zero, and UV.x, done
Transform that to world space (I guess I dont know what space that original set of steps is based in??????????)
normalize, done
Trying every space
none of them produce the correct result
its not possible that it doesnt produce the correct result but its staring me in the @#$@^ing face producing the wrong result which isnt possible and Im sceaming in agony on the inside
I have to go now because im now deeply in mental health crisis because nothing ever fucking works the way its supposed to work when -I- do it because the only common denominator in everything I do is that I'M the one doing it, im the stupid fuck up every time, its never anyone elses fault, the tutorial is never wrong, im always the stupid fucking piece of shit idiot fuck who cant do a single fucking thing right
Sure it's possible, because Surface Shaders do "automatic lighting", and Mr. Zucconi is using a feature called a custom lighting model that is plugged into it (calling their default lighting function, and then doing an ADDITIVE lighting on top of that to get the diffraction grating). And he's got a conditional on that where if cosThetaL and cosThetaV are the same (diff is 0) he returns just the original color from the standard lighting calc.
In shader graph, AFAIK, you can't just call the standard lighting calc, like a built-in node, and get the result and then add to it (additive blending). But @regal stag may know if it is possible, maybe with an unlit graph and adding your own lighting calc sub-graph. He has tuts to that effect. Then you could add your diffraction result on top of that.
Outside of that, you won't duplicate Mr. Zucconi's results.
Im calmed down and cooled off now. Reading this.
Reading this, you're saying the only difference between his and mine is that his is added over top of whatever lighting the mesh is receiving by default, how would that lighting data affect things like how many bands, shape of the bands, those extreme white bands I'm getting be?
I am not seeing how the differences in regard to being added over top of existing lighting would result in the bad results I have
maybe I dont understand the default shading models?
I haven't verified your code....I'm loading unity though, might take me the day to screw with things (doing several things today). But I can try to SG some diffraction and see what I get.
I did notice that you weren't using the tangent node (it wasn't hooked up to anything) in one of your posts.
Your first results looked pretty cool, and they had circular diffraction, so you're on the right general track somehow. ๐
He has that conditional though...
I did notice that in this include file line 34 (containing a saturate) is uncommented which might affect things.
There's also a _Distance property used in the tutorial, though I don't think it ever says which value they are using for this. Maybe try adjusting that.
Could be that linear vs gamma colourspaces change some ranges too.
I commented that because every step I could do outside of code, I moved into nodes.
The default distance used is 1600, its listed as between 0 and 10,000 when he initially sets up the property
the color space thing is a good point, I am returning it to color space from linear space afterwards
so maybe his curve values are no good since they're not based on linear space?
I changed my output tangent vector to resemble his to illiminate that possbility as well
As Carpe mentioned there is also that conditional in the tutorial
if (u == 0)
return pbr;
Could try handling this with a Comparison and Branch node.
"u" being the output of "Calculate Tangent Vector" group.
But rather than return pbr, maybe just use... 0? Whatever the Base Color is? Not sure.
Oh hmm, I did see that but I figured it would be okay if I was using an unlit with black texture to simply skip that step, but I guess it does serve a purpose, if the value is exactly zero is aborts?
Seems like it. I'm not sure how much it will affect the result though
using the above adjusted tangent vector, the result is closer to his, the ultra burn out only occurs on the up/down axis
Ill try adding that back in as a test, I wasnt going to because conditionals in shaders are bad to have (to my awareness)
Conditionals are fine. Branching sometimes isn't, but they are different things.
Branch node uses a ternary (bool ? x : y) behind the scenes which never actually produces a real branch. Both sides are always calculated.
Oh, interesting ๐ค I didnt know that
Will this work in place of returning PBR? Since I have no PBR to return in shade graph, will break make it exit?
I don't think you can break in a function. (It's usually used to exit from a loop)
That, in his code, is the result of a standard lighting calc. If you look at his example pics, you'll see CD-ROMS with environmental reflections on them.
But if you want to bag all that, and just do some flat color, maybe with an N-dot-L calc for lighting, you could return that instead. Or a texture lookup with an N-dot-L.
This might work yeah. Though I'd probably add [flatten] before the if statement to prevent it branching.
The only thing I am studying right now is the anisotropy itself, reflections and base colors and stuff I have no current interest in
So return black.
{
// Calculates the reflection color
float3 color = 0;
[flatten]
if (viewTangent != 0)
{
for (int n = 1; n <= steps; n++)
{
float wavelength = viewTangent * inDistance / n;
color += inline_spectral(wavelength);
}
}
Out = color;
}```
like that?
Yeah
No change in the output at all
so I guess it wasnt neccessary to break, that or im doing something else wrong that is negating the change
The conditional I was talking about was the Cos_TheaL - Cos_TheaV == 0
Yeah that value is "u" in his code
for me I named it "viewTangent" because I didnt know what u was supposed to represent
cyan pointed that out as well, I am also saturating the result
I moved anything that could be done in nodes outside of the code
this is the only point I can difinitively say is definitely 100% wrong
to my understanding its -exactly- his code word for word function by function
but the result is completely different
I "fixed it" but it only looks fixed
it shouldnt need "fixing" if it wasnt fucked
I thought you could "just" use a worldspace tangent node.
so most likely it just looks fixed and is still fucked
but I can't see the left side
doing that will make the right side result
define left side
addendum, doing that is -supposed- to make the right side result, but mine is also fucked
so the mistake must be occuring within or before the custom node
The input into the "fix tangent" for you is UVs, but for him he's using Unity's tangent.
I dont know what that means, could you clarify?
I may not be reading you right. I mean I hate graphs! ๐
there must be a mistake in this above since it produces that gif
Hang on
and it doesnt happen later since you can see it if I open the preview
Never mind, you have a worldspace tangent node plugged in.
Maybe the viewDir is negated in graph vs surface shader?
negating it only slightly moved its center point, mega burn out still happening ๐ค
the 'white' here is assume is extremely high values?
he didnt do anything to this step after the absolute
but maybe I need to do something?
Could try a Saturate to clamp them to 1
does that not say: the absolute of the two dot products, THEN .. multipled by D which im not doing ๐ค
I looked at that dozens of times
now to recall what d even was
oh wait no
im not dumb
that step is inside of the loop
oh hm
that step is inside the loop
I dont think I can precalculate it outside and pass it in maybe?
viewTangent is u, inDistance is d
For that , you can do most of it outside the loop (and should). N is the loop counter though.
yeah that part of the function is within the loop so I guess I was wrong in that I was doing that part correctly and its not the problem
It should be fine to move it out the loop as nothing inside the abs is based on n
in his code, 'steps' was the magic number 8
so I just replaced it with steps and defined steps as 8
Out of curiosity, what happens if you use 8 rather than steps.
ill try switching it
No change in output after replacing steps with 8 hardcoded
Am running out of ideas ๐ฆ
I feel very strongly that the problem is in here somewhere
blink blink
he's counting from 1 to 8 and calcing a new wavelength each time. So it's based on that within the loop. Then calling his special function. The other parts could be passed in though, and calced outside the loop.
in some capacity this does not match that above code
his special function, I didnt change a single thing here though, its copied over directly
maybe GI Light Dir is different than the main light direction?
What version are you in btw?
Try a Normalize node on the View Direction output
It's not normalised by default in versions prior to 2021.2
that seems to have fixed it ๐ ๐ค
In v12+ they've now got View Direction (normalised) and View Vector nodes which makes this clearer
I didnt know how I was wrong, but I knew the problem was going to be some invisible difference between his and mine, and low and behold the invisible difference was view distance was not normalized ๐ค
Yeah. It's just one of those differences between surface shader inputs and shader graph. :\
hokay anisotropy GET
now to learn about thin-film iridescence and every other aspect of anisotropy
Thank you both for all the help and find kind words
made my own subgraph node of it in hopes Ill remember for the future
how do i have like a texture / albedo like in the base materials where i can have a variable than can be color and texture at the same time in shader graph ?
like this :
Can't do it automatically. You'd need to write a Custom Shader GUI, and assign it under the Graph Settings. Kinda complicated though.
https://docs.unity3d.com/ScriptReference/ShaderGUI.html
Specifically, would call materialEditor.TexturePropertySingleLine
https://docs.unity3d.com/ScriptReference/MaterialEditor.TexturePropertySingleLine.html
Render Face : Both in Graph Settings
Or "Two Sided" checkbox for older versions
I put Two Sided on but it still doesn't work. I still see through the "screen cube" if i stand in it
Well, Cull Off and Two Sided are equivalent. It might be that you need to do something else to fix the issue though.
It just isn't drawing on the inside of the cube
Are you saving the graph after changing the settings?
depth buffer problem?
I have it set to 24 on the render texture i think
After updating Unity to the latest version, I am still unable to make it work
When I enter half way into the portal, I see out the other side of the frame instead of the image being rendered still
\
First image is before entering, second image is if the player stops on the boundary of the portal
Isn't that where you're supposed to switch scenes? IDK what you're doing exactly, and there's a number of ways to do a portal, but at that point you've "transitioned" into the next space that you should be in. Right?
If I move 1 more pixel forward, I transition
Near plane clipping of the object?
But I don't get why this one pixel exists, as it makes the portal flicker if i run through it
How do I check/fix this?
I have it set to 0.01
well, try 0.001, or move the transition point to something that works for ya. 2-cents.
I don't think I can go lower than 0.01
If my loop length depends on a property, does it mean that it can't be unrolled? just how much more ineffective would that make it? ๐ค
[unroll]
(int i = 0; i < LayersCount; i++)
hey, iโm just putting this here because i think itโs an issue pertaining to materials or textures, but iโm having issues with a model iโve imported from blender
That's just inverted normals.
You can either use a shader that renders both faces of a polygon in unity or invert the affected face's normals in blender.
Fixing it in blender is a much better solution for most such situations, to clarify.
yโall are absolute blessings, iโm grateful to you
The compiler has to know how many versions of the loop contents to insert at compile time OR wrap it in conditionals. So for constants it can unroll it directly by simulating the loop. But for a variable, it has no way to know how many lines to plan for, UNLESS YOU TELL IT.
So if you know the max iterations, say 16, you can use
[unroll(16)] as an attribute. I haven't tried it, but it is supposed to check if the actual value of the variable exceeds the condition specified in the for-loop on each iteration. That's a lot of ifs.
The plus side is that it can optimize memory access better when the loop is unrolled. It is linear flow strait down the line, no increments or "goto"s in a loop except for the terminating check.
https://en.wikipedia.org/wiki/Loop_unrolling
Loop unrolling, also known as loop unwinding, is a loop transformation technique that attempts to optimize a program's execution speed at the expense of its binary size, which is an approach known as spaceโtime tradeoff. The transformation can be undertaken manually by the programmer or by an optimizing compiler. On modern processors, loop unro...
Yep, I ended up doing that. Thanks for the explanation!
The compiler wouldn't compile otherwise actually.๐ค
Right, because it can't, otherwise. ๐
I mean even without the unroll. Or I'm mixing up things. Hahah.
Yeah, I guess sometimes you must either specific [loop] or give it a count, as it has a hard time guessing what optimization to use, or not.
Weird
I see. That makes sense
anyone know why this is happening? i copied cel shading from daniel ilett
When my model is in blender the hair looks perfectly fine but when I import the model to unity and then add transparency on the hair material some of the hairs don't show but the culling is off , can somebody please help
The usual way is to use Opaque + Alpha Clip rather than Transparent. Assuming the shader supports this.
When I use alpha clip it works perfectly fine but it doesn't have a sudden realistic transparency
On the tip of the hair and I really don't know why it does this when I select transparency
I assume you mean the black parts surrounding the model? Looks like it could be an inverted-hull style outline, though the distance is very high. Typically that also requires the model to have smoothed normals.
Hard to say more without a link to the tutorial/shader
I am using the vrm shader and I'm totally fine I know how to get rid of the black parts I was asking why this part of the hair looks transparent when the culling is off
If u look u can see the grid lines just go through it on only some parts i don't know why it does that I wanted to ask if u knew
Perhaps just an issue with the depth texture?
The black parts was a reply to someone elses question.
This is a common issue with transparency. It doesn't write to the depth buffer (this is why the grid shows through it). Also means it can't easily sort pixels.
I would use alpha clipping rather than transparency
Ok I'll do that but do I still not have a option to go with transparency and still have the whole models hair show up correctlyy??
Is there no option to fixing that โขฬ โฟ ,โขฬ
Perhaps change the rendering order?
Okk
Or is it called sorting order/sorting queue?
It's in the material settings usually at the very bottom
Alr
Getting transparent hair geometry to not render through itself is a whole field of science
You can find many resources about it, but no single fix
(besides forgoing semitransparency with alpha clipping as suggested)
I think they were referring more to the unity grid rendering on top of the hair.
this is in editor
the shader i use
It looks like the outline pass is not using ZWrite On
i really don't understand shaders, i just copy and paste them
oh ok, i changed zwrite off to zwrite on
and it works thanks
hey,
I have few walls that are URP based, they look fine on the editor even in playmode.
However, once I make an android build it and enter the game, those walls just disappears.
what could be the cause of that?
hey guys
In a compute shader, how do I access global variables from another file ? I have textures and samplers in the main shader file and need to sample them in functions defined in separate files
and I can't just sample them in the main and then just pass the values, because some functions need to sample areas around each pixel of the output
can I just pass the reference to the texture along with uvs ?
how to activate those blocks ??
Use them, or change settings.
What?
Like using an #include directive?
Otherwise, set values of variables on the material/shader from c# script.
i'm trying to use them, its just greyed out
Textures can be set across shader invocations. They persist.
why ??
Probably settings.
IDK, shouldn't matter.
But maybe it's like...if you're using tangent space normal, you won't need world space normal.
yep, need to move functions out of the main shader file for readability
@pale pythonAnd the specular color probably only applies to specular workflow.
im only useing tangent space Normal
i dont have that
i have basic stuff and they are greyed out
So what's the problem? You don't need worldspace normal active in the block.
You don't need specular color either.
So no problem.
just put them in an include file so you have one set of source.
make sure to include them at the point where you would type them in, not just at the top of the file.
any thing i add to the default, doesnt work, all greyed out
Is it a lit graph?
oh, so I just use those Texture2D declared in the main as if they were local to the function's file
i dont know , how do I know that ? i know its a shader graph
i'm using the shader graph editor for it
@pale pythonCheck the settings box.
https://docs.unity3d.com/Packages/com.unity.shadergraph@10.3/manual/Graph-Settings-Menu.html
An include is a copy/paste by the compiler.
So you define/declare them in each file, but you have one set of source code to maintain since you used an include
You have to set them on each file/shader/material from c#.
Each shader is independent of the others, there are no "externs" for that type of thing, you must set the references in c# for the invocation, or the engine will do it for you for many things like with materials.
It's an unlit graph, so you don't have those PBR calcs available.
yup that was the reason thxx ๐
@pale python In the future, don't crosspost your questions
sorry i forgot to delete the other one
thank you for clarifying, the single file shader works fine, didn't know how it deals with references to resources in the included files ๐
Performance cost question of lots of noise
https://gfycat.com/understatedunselfishbadger
ignore that its a mess, is this too many noise nodes to get the above look?
You should be able to cut down the cost by using noise textures instead of noise nodes
Noise nodes tend to use a bunch of expensive math from what I know
However, optimization is always relative to performance budget and how much of that shader you need to render
Might not be an issue
Assuming you don't need this to scroll over time or something, you could also bake the current result of the shader to a texture.
That way you could use another shader graph with just a single texture sample to basically produce the same result.
I've made quite a simple 2D sprite URP shader that offsets horizontal, vertical and diagonal copies of the maintex to create a fake blur for my foreground and background layers.
A problem I have is that I can only increase the offset ever so slightly until you can start telling apart the "sampling".
Does anyone know if there's some nice way to blur more accurately and increase the samples, like a gaussian blur or something? I'd rather try and avoid playing around with the render pass stuff as it's a bit complex for me but any suggestion is welcome.
I can't resort to using DOF or anything like that as I can't use that as a post process layer on my foreground (it blurs everything on the screen, not only the foreground)
You could use a low-resolution texture, and see if there's a bicubic interpolation option?
what do you mean exactly? use a low res texture where?
On your sprite you want to be blurry
Low res and then bicubic looks roughly gaussian
though ig at that point you could just use a texture and actually gaussian blur it
yeah the problem is I have a loooooooooot of textures and manually blurring the actual texture would more than quadruple the game size
they're all scattered around on sheets
if they're at different distances there's probably a depth of field post processing option
it would also benefit to have it automatically blur a certain strength just directly in the scene
yep. I tried that before and like I said it doesn't work for the foreground unfortunately. It does work well with the background though. But the foreground is just as important
the problem is the post processing pass applies the dof on the whole screen so it blurs my middle-ground layer too
after having searched around forever I just ended up going back to my older solution which was this shader but trying to improve it and make it a little better, although I get stuck here at the sampling as I can't figure out a way to make it look better
oh right didn't see that
You could use the pixel coordinates as a random seed and then it'd be a sort of dithering?
Use your eyes and the framerate to average it rather than lots of layers
@ocean boughWould Unity's motion blur help you? You could use a separate camera for the background if you don't want that blurred, and composite them.
motion blur doesn't really do what I want. Yeah I've used separate cameras for background before, where I used DoF to get achieved effect. Problem is the foreground
It's a very basic 2D foreground, middleground, background layout. Middle is sharp, everything else blurred (statically blurred)
preferably in a gausian sampling
ori a great example. background further away blurs. More the further away. Foreground is very "close" so appears very blurry
I think the closest I've found was this thread where someone links an uber sprite shader that does the trick but it's unfortunately quite outdated and not made for URP https://forum.unity.com/threads/how-to-blur-specific-layers-only.555520/
OK, so layers or camera stacks, with blur on top of them. Does Unity's blur post process not work for your use-case? Just curious. You CAN of course write your own blur shaders, but it ends up likely being a post processing pass with layers anyway.
Exactly. And here is where I've gotten stuck. It sounds pretty straight forward - but the problem comes when ever the post processing layer is applied on the foreground layer (either as a camera, or just a layer), because the post process pass doesn't produce an "alpha" that can read what part of that layer has content in it - it simply applies the full effect all over the screen, thus blurring everything behind it (even the sharp middle ground).
I'm not so skilled in how render passes/features work, but the ideal gold moment for me here would be if there is someone knowledgeable enough on how to make one custom render feature that can produce post processing dof on the foreground without it being applied "backwards" all over the screen
i've been struggling for a long time with this. It seems like a very very common thing in 2D games but it seems almost impossible to recreate it in URP 2D. Seen lots of threads without any proper solution
Hmmm.
I'm not a 2D expert.
But...
Seems to me you could put a post processing pass on the foreground camera, and then AFTER that, draw the mid-ground. There would be some "extra work" doing that, since it would draw over stuff it didn't otherwise need to draw, but if the blur happens before you draw the sharp layer, problem solved?????
yeah exactly if it was drawn first it would of course not be applied on the next coming layers in the queue. but how would you go about rendering the next layer (in this case, the sharp middle ground) without it overlapping? as if its sorted correctly
How do I extract the scale from a float4x4 in HLSL?
It would still be depth clipped.
Ok, how would you about doing this? A camera with priority numbers?
I don't know how to sort around the render queues in an order like this
It's in here somewhere, IIRC:
https://answers.unity.com/questions/1359718/what-do-the-values-in-the-matrix4x4-for-cameraproj.html?childToView=1359877#answer-1359877
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
thx
I'm talking off the top of my head here, so grain of salt.
But...
You'd assign objects to layers, foreground, middle, background.
Then you'd have a camera, or cameras, to render say the foreground + background layers, but not the middle.
You'd then have a post process of blur or DOF or whatever.
Then you'd have another camera with "don't clear" on it, and render only the middle layers.
I think. But I don't do 2D
I'd make a very simple test-case scene and test stuff out
Hmm, ok. And priority number on the said cameras to decide the render order yeah?
The cameras dont have Don't clear in this pipeline though
I guess, or just the order in the object list. You'll play with that and get it. It's been a long time for me since I've messed with that and it could have changed.
What?
What the hell?
Second. Please stand by.
you mean in URP?
There are Depth Texture settings and stuff in urp
Yeah
I use the 2D stuff in URP though but the camera rendering should be the same (throughout URP).
OK, so you want an overly camera, right?
It gets the depth buffer and the color buffer from the previous camera
per that docs page
Hm ok
Seems interesting, I'll follow what you said tomorrow and see if I can get something out of it. I need to head to bed. I'll keep you posted. Thanks so much
Welcome.
I'm just guessing though, but worth some experimentation.
Anyone know how to get the height of the mesh at a point using a surface shader?
Afaik theres only worldPos and worldNormal nothing for the actual surface
I generate the mesh in code using a float[] heightmap, how could I pass this to my shader if theres no built in way to do it through shader only?
nvm figured it out, unity_WorldToObject and it's inverse
float3 objectPos = mul(unity_WorldToObject, float4(IN.worldPos.xyz, 1)).xyz;
The vertex shader stage receives the original object-space position. You could pass that to your "frag()" in the v2f data. Check the generated code to see what it is doing. But your appdata or whatever you call it gets the original object position.
Using a surface shader, I don't think this would apply
I wouldn't have said "check the generated code" if it wasn't a surface shader.
There's still a vertex stage, you just have to check the code.
Ah ok, im not that great with shaders - I only know enough to be dangerous
Didn't know you can check the output
struct Input {
float3 worldPos;
float2 uv_MainTex;
float2 uv_MainNorm;
float2 uv_SecondTex;
float2 uv_SecondNorm;
float3 worldNormal;
INTERNAL_DATA // Required to set o.normal and read worldNormal
};
I'm just reading straight from this struct
And converting worldPos and worldNormal to object space
appdata_full has a value called "vertex".
See that struct for how to include it in your "Input" values.
They have an example here: https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html
That extrudes the model along the normals and makes a "fat soldier" (towards the bottom of the examples, about 2/3rds down the page)
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert vertex:vert
struct Input {
float2 uv_MainTex;
};
float _Amount;
void vert (inout appdata_full v) {
v.vertex.xyz += v.normal * _Amount;
}
sampler2D _MainTex;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
}
ENDCG
} ```
They use a custom vert function in the surface shader.
The point is that v.vertex is what you want already, you don't have to "uncovert" it.
I see, I guess the only problem then would be if i'm drawing stuff based on the height of the vertice and normal in the surf method, how would I do that using the vert method?
Thats a big help though thanks
This is what I wanted, so that the model can be rotated and translated without changing
I'm low on time, I have to get ready for work.
Uhm, I thought you generated the mesh in C#.
But if you're doing vertex height mapping in the shader, you can expect those values to be interpolated in the v2f data.
Ah gotcha, thanks man. Enjoy work 
ha
So it depends on if you need a custom vert() function or not, I guess. Just make sure you have a v.vertex and an IN.vertex and that you set the IN.Vertex to the value of v.vertex. You'll have to check the code and makes sure that unity doesn't translate that vertex value before you assign it.
You can check the generated mess in the inspector, there's a button for that.
Ohhh yeah that makes sense, I got it now. Thanks a lot!!
๐
Hey guys !
I am a real unity newbie.
I am currently developing a 2D game, and I want to make my enemy projectiles more visible to the player, but adding a shadow/outline behind the sprite (like white shadow on this drawing).
How should I do that ? Is it with Shaders, or another graphic tool ?
This is how I draw a smooth circle in a black background, but how can I draw a rectangle?
How to create rectangle mask?
These functions are distances to a shape, so you can use that distance as a mask if you do some basic remapping (and saturating the result to avoid non 0->1).
Hi! I have a question, maybe someone had same issue like me. On the left - game view, on the right - scene view, for a GOLDEN text shader. I think it's something with Additive mode, because it should work as intended just like on the scene view
try setting the shader to lit
you might also not have post processing enabled on your camera
trying to figure out this ink shader im using, mostly how it uses colour, it has a float4 channelMask
depending on the values it changes colour,
x at 1 = yellow
y at 1 = red
z at 1 = green
w at 1 = blue
it always uses the last value eg x will be ignored if y is 1
removing the channel mask makes it default to blue
Thank you, that was the case โค๏ธ
I found this glass shader online
It seems to have a tiling option on the inspector but changing its value does nothing, how should I change the script to make tiling work?
Should be able to add float4 _MainTex_ST; (around lines 30-34). And change line 60 to output.texCoord = TRANSFORM_TEX(input.texCoord, _MainTex);
(Though that may assume the texCoord in the vertexOutput is a float2 (not float3)... It doesn't seem like the z axis is used so could change it)
Worked like a charm had to add #include "UnityCG.cginc", though but still it's perfect. Thanks!
Are standard URP shaders now used for vertex displacement?
im using cyans blit for a screen effect, though i now have a minimap thats using a second camera, the blit is being applied to that too, is there a way to only do the effect for one specific camera?
You can create multiple Forward/Universal Renderer assets (one with Blit, one without). Assign them both to the list on the URP Asset, then change the Renderer field on the Minimap Camera.
where do i add them both?
To the list here on the URP asset
You must do, it's what tells Unity to use URP ๐
It'll be what is assigned under the Project Settings -> Graphics
oh, on each of my quality settings?
Yeah or there, would probably need to add them on all if you have multiple assets for each quality setting
ah ok ok! i didn't know you could do this!
For the ball above, I got the look with scene color + some fresnel. My goal is to check off the opaque texture, I was wondering if there's a cheap way I can get something that looks like it w/o the scene color? The ball rotates
Why do you need the scene color? Can't you just use Transparent + Additive blending?
Hello, I am new to Unity. Was wondering if someone might be able to offer me some assistance with a texture problem I am having
Is there a formula or method to deform a 2D square UV into a hexagonal UV? (until is still booting up but ill picture my use case here in a sec)
by deform into a hexagon I know the UV will still be square ultimately, but I am trying to correct a bit of distortion that comes from a shortcut I am using
as a cheap alternative to 3D noise, I am projecting my 2D noise textures at my cube from a 45 degree angle to make a texture that is unique on 3 faces and tiles on all sides
The downside with this method is that it produces a degree of stretching that sorta 'points' at the vertex im projecting at
I want to try to correct the stretch, I know there will be some stretch no matter what with this method, but I am thinking that if I can somehow deform the UVs in these three directions away from the center, that it will look slightly less stretched
Hello there, fellow unity enjoyers! I have a minor question to ask - does Render Texture utilize object's UV islands or it just uses whole UV space?
RenderTexture is just a texture
not different from any other texture in terms of how it gets sampled
hoping I can use a triangle (or maybe hex?) sdf to adjust the UVs ๐ค
Damn, now I feel stupid... Is there a way to get UV vertices position, using URP shader graph?
sorta but not quite ๐ค
almost?? ๐ค
hm I think maybe the problem is that I need the triangle to be rotated to point at the lines instead of the faces?
you can see it not working here
almost kinda works ๐
I think the gradient curve just needs to be changed
sorta works except you can kind of see a decreased cell density the closer to that corner
maybe the problem is that I need a hexagon instead of a triangle ๐ค
@dim yoke to answer your question mark reaction (which you would have been better tagging me for). There are some old tutorials on Unity's site that refer to displacing vertices in shaders on hdrp/urp. However the option for PBR shaders (which the tutorials use) in the context menu is missing.
hexagon is proving troubling to use ๐ค
apologies for the newb question but is there a reason why when using a texture with a transparent background as a Base Map produces black as the background color? is there any way to change this?
its easy to make it worse, maybe my problem is that I should be doing this from the opposite corner, or in reverse to what I am doing ๐ค
Lit = PBR
I figured it out, thank you anyway
everything I try just makes it worse, not better
getting frustrated
this shouldnt be this hard to fix, its just geometry
great now that I achknowledged that im frustrated, the feelings are now overwhelming
stupid worthless piece of shit doesnt do what I wnat because im too stupid to make it do what I want because I cant even describe what I want it to do
maybe the problem is that im trying to fix a 2D problem with a 1D sollution????????????????????????
I just want to unfuck the shitty stretching worthless look my own stupid worthless hack is generating
why is it so hard not to hate myself for being a worthless failure at everything i ever try to do or touch
time to go somewhere else
i can NEVER seal the fucking deal, I can only make these shitty worthless half ass attempts, and then im forced to wait for people who are better than me to fix it because im too stupid to fix it myself :/
i hate myself for being so weak and stupid that im forced to rely on others. all the people I idolize arent forced to rely on others, the people with actual skill and talent just -DO- it
im just a fucking worthless parasite
the sollution has to be that i need to write math that will stetch the UVs along the black axis, along the green lines, towards the yellow points
stretching it this will way remove the warped appearance
what vector math will fill these quadrants with negative values, and the others with positive values, ramping away from the lines?
Where do you connect the multiply node?
i tried to brute force it because thats the only thing im capable of doing, but even that doesnt work
the gradient is pointing in the wrong direction
stretches in completely the wrong directions, another worthless failure produced by the worthless failure
I stupidly thought I could redeem myself by at least proving that it can be done
I hate that I know it CAN be done
but only by someone better than I am
i will never be that better person, im just a stupid worthless POS who can do nothing but dream, I cant achieve a single thing with my own two worthless hands
ideas are worthless
when someone better than me solves this problem for me, IF that happens, it will be THEIR achievement
I will have contributed nothing
infact I contribute less than ntohing, I actively TOOK AWAY that better person's time, which could have been spent achieving something even greater than my worthless hack ideas
I tried to do it -manually- by -drawing it- in -photoshop-
but im STILL too fucking stupid to do it right
it still doesnt @#$@%^@^&ing work and I dont know why because im too fucking stupid to do do anything on my own
they all stretch in the wrong @#$@^@ing direction
I wish I wasnt so stupid
a smart person could solve this easily
I wish I felt like I was a smart person, I wish ididnt call myself stupid just like how my parents, my siblings, my teachers, and everyone else ive ever met called me stupid growing up
i give up, im too stupid to do anything useful
i just have to settle for my original shitty hack job
the one that any talented person could easily fix all the flaws in
but I have to compromise, settle for something objectively worthless, objectively worse in every regard
just like every single thing I do and touch, settle for less, settle for worthless, always compromise compromise compromise, never do a single fucking thing or achievement or note, never live up to any expectations, never HAVE any expectations of to be anything but a worthless waste of space to begin with
i wish so goddamn fucking desperately to BE SOMEONE
but im just too fucking worthless, ill never be the people idolize
they're younger than i am, smarter than i am , faster than i am
every trait i have, they have in greater exccess
the ONLY thing I can ever hope to achieve, is to be the big fish in a VERY small fucking pond
because if people have the option for something with real skill, real talent, and myself, they will never, EVER 'compromise' the way I have to fucking compromise and take me over someone with real skill
I have a problem with this shader, on the x sides the material is 90 degrees turned
Code:
Shader "Custom/WorldSpaceShader"
{
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Scale("Texture Scale", Float) = 1.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
fixed4 _Color;
float _Scale;
struct Input {
float3 worldNormal;
float3 worldPos;
};
void surf (Input IN, inout SurfaceOutput o)
{
float2 UV = abs(IN.worldNormal.x) > 0.5 ? IN.worldPos.yz : abs(IN.worldNormal.z) > 0.5 ? IN.worldPos.xy : IN.worldPos.xz;
o.Albedo = tex2D(_MainTex, UV * _Scale).rgb;
}
ENDCG
}
FallBack "Diffuse"
}
How can I rotate this side 90ยฐ
probably worth practicing using vectors in geometry problems, and often you might need to break out the pen and paper if you can't guess at the form of the answer. Then for me at least there's a lot of trial and error with signs and coefficients, and often messing around with some vague idea of the geometry/physical problem you're trying to solve, but more trying to make it look reasonable at the end, will get you something that works.
Do you want them to stretch towards the diagonals?
For something that's positive on one corner and negative on the other, you could do:
float DiagonalSlice(vec3 normal, vec3 position) // Both are in object space
{
vec3 one = vec3(1.) - normal;
vec3 posOnFace = position - normal;
return dot(one, posOnFace);
}
So all faces will be sliced along the vector in the plane of the face, closest to (1, 1, 1)
and then for the scaling, you could have the input be something like:
float AlongDiagonal(vec3 normal, vec3 position) // this gives us the coordinate that DiagonalSlice misses
{
vec3 one = vec3(1.) - normal;
vec3 posOnFace = position - normal; // unnecessary given the next step (all components parallel to normal return zero) but whatever
posOnFace = cross(posOnFace, normal); // normal is always length 1 and points outwards so this gives us a perpendicular vector
return dot(one, posOnFace);
}
float OutputValue(vec3 normal, vec3 position, float stretching) // this function gives the stretched voronoi noise
{
vec2 faceCoordinates = vec2(DiagonalSlice(normal, position), AlongDiagonal(normal, position));
faceCoordinates.r = stretching * faceCoordinates.r / (stretching + abs(faceCoordinates.r)); // this function can really be whatever you want
// but it determines how one coordinate is stretched
// with respect to the other.
return Voronoi(faceCoordinates);
}
@tight phoenix
I believe you have to change the UVs for the cube for that; probably by making your own cube and marking out how the UVs are supposed to go
Hey all I am running into an issue where SRP batcher will not work with multiple shaders ?
How can I make all of my game effects inside fit into one shader? Is that a suggested method for optimization?
Use the frame debugger to see why the draw calls are not batched.
is there a method of creating full screen effects without using any sort of scripting?
I'm attempting to create a custom asset for a game but one of the limitations is user generated scripts do not get included within the asset
only shaders and such
my only idea was to slap a grab pass shader onto a quad or something and then transform the vertices to the screen, somehow
wondering if theres a better way
Right
because of different shaders are used
hey guys its possible to make this effect from shader graph? i can doing the affter effect but idk how to import it to unity
https://www.youtube.com/watch?v=peb7DQtSieQ
How to Create Futuristic Digital Circuit - After Effects Tutorial
โญ Download AE Source File: https://www.patreon.com/posts/59783358
โบ SUPPORT the cause: https://www.patreon.com/moveshapes
Saber: https://www.videocopilot.net/blog/2016/03/new-plug-in-saber-now-available-100-free/
โ https://dribbble.com/peterarumugam
โ Visit: http://www.movesha...
I would create a mask that is a 0->1 gradient from the start to the end of the trail. You can then clamp by time against that mask to make it appear over time. Appending circles to the end of that mask would be much more complex...
The alternative would be to use VFX graph particles (for the circles) and trails, but that reduces platform compatibility and has a higher knowledge barrier.
Plug things in, plug things out.
Never mind it working. i thought it wasn't.
just cleared all my settings when i saved.
i will try second , the alternative i know to bulid trails and the VFX graph (circle) but idk know to animate it? can it be keyframe as a want?
I think the complexity with VFX graph would be not overlapping the lines. If you didn't care about that you could pick some random times when new particles split off, or take a 45deg turn from their starting angle. With my experience it would be hard to tell what would work without a bunch of experimentation
It's a complex effect! Another option that might be easiest might be to use the spline package (https://docs.unity3d.com/Packages/com.unity.splines@latest), they have some examples for extruding meshes along splines, and it also lends itself to placing the circles on the ends too.
Is there a reason of how when you import a 3d file, some shaders are shown on the editor but then some others don't?
ty i will try the splines
I have a pretty specific question, I think.
So I have a shader for a UI image material. And it has a variable I am controlling from a script. However when the image is masked, it does not work anymore.
I've done some research and it's because the mask mucks with the materials. I can get it to work if I use "materialForRendering" instead of material, but the problem is I'm not just getting the material, I'm also setting it so each instance of the material in the scene is its own thing. If I don't, the variable is obviously the same for all instances of the material, which I want to avoid.
So what I am currently doing is: get the material that's on the image, make a new instance of it, and then put that back into image.material. However when the image is masked, this doesn't work, because materialForRendering is read only, obv.
You can set it to be a mask in script by messing with the stencil
so avoid the mask component
Is there another way, because that doesn't seem feasible for whhat I'm trying to do. I want it to use the mask component if needed.
is there any way to access that material?
no, the mask component locks the material
Is there a way to do this before the mask locks the material?
dont think so
like instantiate my version of the material, put it on the image and then when the mask comes in it grabs that one?
maybe if you add the mask component in script?
So just so I understand it: what's the mask doing, specifically?
Like when the mask is turned on (maskable on the image, frex), it grabs the material that's on there and then?
It instantiates that somehow? Because I can't seem to get to it anymore at that point, right?
I think the flag there is the issue
https://github.com/liuqiaosz/Unity/blob/master/UGUIๆบไปฃ็ /UnityEngine.UI/UI/Core/MaterialModifiers/Mask.cs
from the mask.cs script
Ah.
I made my own masking script to avoid it
Yeah, unfortunately that's not an option here. damn
alright, further testing: If I enable masking after the material has been instantiated I can actually access the variables in there.
So: make an instance of the material, assign it to the image, then enable masking (mask makes its own copy) and then use materialForRendering.SetFloat to access that version of the material.
However if masking is on when the material is enabled it probably comes down to order of script execution, and even with mine being early in the script execution thing, I can't do my copy thing before the mask does its copy thing. So something doesn't work
update: sometimes it works, sometimes it doesn't, even with the mask enabled?
Some options
- export to video and import the video in unity
- Using some circuitry mask on top of a growing circular gradient image, but I dont know what to do about those moving dots
- animate using 3d modeler
- animate using unity's animation and linerenderers
Oh, question: is there a quick way from an image component to find out if itโs actually being masked? Maskable is obv not definite
the stencil buffer is different
im end animate empty in blender with follow path and apply effect in it. but i want when the effect past the line there is glow line behind it and not disapper? can i done in vfx graph?