In the shader graph, you can compute the screen width/height by using the "Screen" node. This will fix stretched pixels on different resolutions. Assuming we have the float "VStep" (Vertical Steps) which will be our desired height, and we need to get "HStep" (Horizontal Steps) which will be our desired width to make 1:1 square pixels. We can do the following math: Multiply Screen Width by VStep = X Divide X by Screen Height = HStep Make a Vector4 where X is HStep and Y, Z, W, are all VStep. Then you can plug those in to the posterize node and you have perfect 1:1 pixels which will scale with resolution.
For anyone who can't use this because of NullException, replace Blit code with this commandBUffer.Blit(sourceTexture, tempTexture, material); commandBUffer.Blit(tempTexture, sourceTexture);
This worked for me just corrected BUffer to Buffer. I get an Assertion failed error - Assertion failed UnityEngine.Rendering.RTHandle:op_Implicit (UnityEngine.Rendering.RTHandle) - . This happens every frame but its not game braking.
@@schmiselchen obviously you doesn't need shader for pixelart at all, you can just set render scale in URP settings and change aliasing method to point
I guess :) I'm still learning myself shaders / vfx but it seemed like a cool effect to apply using a custom render feature aka custom post processing in URP
Yeah, it's still better than what we typed here, because your solution allows to add exceptions for UI - where changing render scale affect everything :) By the way, using posterize is way simpler than what I am used to create :)
@@venesardthethief6704 That's changing the entire resolution of the game. There are games where changing the render resolution only affects the game models
*I just upgraded to 2022.2.1f1 and the custom scriptable render pass is not working anymore.* This worked for me on Unity 2022.1.23f. The script prints a NullReferenceException to the console on the second Blit call. For what I could understand so far, the Blit method tries to access the source's (RTHandle) render texture ("rt" read-only field) but it is null. I guess they've changed something with the CommandBuffer.GetTemporaryRT or the rt field default value. I'm hoping someone or the video creator can help me with this setback, thanks for reading!
I think I found a solution in Unity URP 2022.2 +. Use Full Screen Shader Graph to create the shader, and simply put the material into the new Full Screen Pass (Renderer Feature) from Unity. Instead of using a texture in the graph, plug it into the UV channel of an URP Sample Buffer instead. Check out the documentation on Full Screen Pass to make sure your material gets drawn correctly. This new feature from Unity let's us skip the code part completely as well!
To add to @@exhaston8780's comment, and just in case someone has the same problems I had in URP: For this solution to work, the URP Sample Buffer attribute "Source Buffer" needs to be set to "BlitSource". Then you plug the output into the Base Color attribute of your Full Screen Shader Graph and it should work just fine once you plug it in as material on your Full Screen Pass!
@@exhaston8780 hey man can you help me? i did what you say but i still confuse because my game now is Green, blue and red (the colors of URP Sample Buffer). i try put the texture again but it bring the error back so what you think i need do? thankss
@@jackrj3464 I installed Unity to give it a whirl after a while, and the fullscreen shader graph Shader should have UV->Posterize->SceneColor/SampleBuffer(Remember to put this to BlitSource)->BaseColor(Output). In the renderer data asset, apply fullscreen pass renderer feature, and assign a material you created from the shader. Set requirements to everything. It should work as this, let me know if it works or not.
Really great video. I was experimenting with this, and found that the "pixels" become stretched with the aspect ratio of the game window. Any ideas on how to work around this? Would it be something with how the material is applied? EDIT: I figured it out. I think it is an improvement to your method. To get the pixels to become square and not stretched rectangles, I split the UV into x and y, and have each of them posterized seperately. I use the same Pixel Rate, but multiply the x posterization with the decired aspect ratio. Hope this helps if anybody was wondering about the same thing!
Hey! Sorry about not takling it into account. Great to hear that you have found a way to fix it! 👍 Jettelly has a grate video about this that includes a solution for it but I wasn't sure how to transfer it to the shader graph (still learning myself 😅 ) ruclips.net/video/S8beHPDqE50/видео.html
Hey, I'm having the same issue but when I implemented the solution you suggested, it just changes the resolution of the image not the individual pixels. Do you think you could provide the node setup that you used? Thanks
Hey! I think I explain around 13:24 that we need to change the RenderPassEvent - when we want to apply our Blit command. Using the wrong one (trying to pixelate our screen too early in the Render pipeline) will cause this. We set it to BeforePostProcessing. Let me know if it helped!
@@SunnyValleyStudio I'm having the same problem, I have render pass event set to BeforeRenderingPostProcessing but the game screen renders black and my console is full of NullReferenceExceptions coming from the Blit command.
@@TheSameTeam Thanks for letting me know! What version of unity are you using? It sounds like the URP package or Unity version issue. I did follow the documentation for this but maybe it something on my end so i will check 😅
You can just go to the Quality settings of the URP asset and set the scale to a value lower than 1. I'm using version 2022.3.9f1 LTS currently. Haven't checked others.
Are you sure that you have set the effect to run Before Post Processing? I explain it i think at the end of the script - since if you don't set it you will get an error.
Hey. You can use a separate camera to render the specific objects and combine 2 images together 1 pixelated and the other one not through the custom render feature. PS. I have seen it but never done it's just an idea
i got this error thing is i checked unity doc about ScriptableRender and it contain it i dont understand error Assets\Shader\FullScreenRenderFeature.cs(20,63): error CS1061: 'ScriptableRenderer' does not contain a definition for 'cameraColorTargetHandle' and no accessible extension method 'cameraColorTargetHandle' accepting a first argument of type 'ScriptableRenderer' could be found (are you missing a using directive or an assembly reference?) help plz
Stupid Question, but can you also "simulate" a Pixelart game with such a shader? So you basically make 3D Models and then you "convert" them to Pixelart?
You can render ex your player onto a render texture using a second camera and apply the pixelated effect to it - so just to a single object (just like the censure effect works in The Sims I think) and you can combine the output of both textures using a custom render feature. At least that is how I would try to create it.
i'm trynna do this. i get 3d models and render them as pixel art without lighting and then light them with 2D lights using 2D normal maps && diffuse maps (without lighting). It should be possible to simulate a pixel art game, but i'm not sure if thats the correct way (i'm checkin' rn)
I followed the tutorial but in the end URP turned off my post processing and all the objects in my scene were one flat color without shading. The only way to see the edges of objects was if they had a different material. I don't know what I did wrong :(
Hey! I'm really not sure. I will have to redo this tutorial anyways since Unity 2022.2 changed how this all work. I will make sure to take a look at this issue. Still since it is Post Processing all the shadows should already be rendered since we are using the Frame Buffer image so what the camera produces at the end of processing all the other objects.
@@SunnyValleyStudio they changed everything again? Man... why can't Unity just make features that work, are consistent and documented instead of constantly treating their engine like an experiment...
Hey man great stuff! Any news on a new udemy course in the future? I would love to see you teach how to create an xcom like 3d turn based game. You're literally the best teacher on Unity coding, don't ever stop!
For some reason when I switched to Unity 2022.1 it is now giving me a null reference exception error for the cameraColorTargetHandle. Anyone know how to fix?
Well as far as I can tell this method stops working when you use 2022.2 since some changes were made to URP pipeline. It should work correctly in 2022.1. Still I will have to make a new video using Unity 2022.2.
I think this is cool as an instructional tool but it feels extremely wasteful to render at a high resolution then bin down the pixels like this. Why not just change the render resolution and reap huge performance gains as a result?
That is a good point. I am not sure really as I am still learning about the rendering process. I was exploring a bit more the way to use the custom render feature to create some additional effects and thought this to be a nice way to present it 🙂
This one, combined with a toon shader, seems to be awesome... Thank you so much
In the shader graph, you can compute the screen width/height by using the "Screen" node.
This will fix stretched pixels on different resolutions.
Assuming we have the float "VStep" (Vertical Steps) which will be our desired height, and we need to get "HStep" (Horizontal Steps) which will be our desired width to make 1:1 square pixels. We can do the following math:
Multiply Screen Width by VStep = X
Divide X by Screen Height = HStep
Make a Vector4 where X is HStep and Y, Z, W, are all VStep. Then you can plug those in to the posterize node and you have perfect 1:1 pixels which will scale with resolution.
Thanks for letting me know!
Literally just saw this on the unity sub Reddit and open up RUclips and the video is there 😄. Timing.
For anyone who can't use this because of NullException, replace Blit code with this
commandBUffer.Blit(sourceTexture, tempTexture, material);
commandBUffer.Blit(tempTexture, sourceTexture);
Thanks so much for sharing yout solution! 👍
This worked for me just corrected BUffer to Buffer. I get an Assertion failed error - Assertion failed
UnityEngine.Rendering.RTHandle:op_Implicit (UnityEngine.Rendering.RTHandle) - . This happens every frame but its not game braking.
@@MrElMunto that's because this code deprecated and need rewrite, it's not so hard
@@orangesoupd can you elaborate please T-T how can I fix this?
@@schmiselchen obviously you doesn't need shader for pixelart at all, you can just set render scale in URP settings and change aliasing method to point
settings - render resolution 100% -> 20% - done xD
joke aside, great job
Was going to say the same, unless we need some UI :D
I guess :) I'm still learning myself shaders / vfx but it seemed like a cool effect to apply using a custom render feature aka custom post processing in URP
Yeah, it's still better than what we typed here, because your solution allows to add exceptions for UI - where changing render scale affect everything :) By the way, using posterize is way simpler than what I am used to create :)
@@venesardthethief6704 That's changing the entire resolution of the game. There are games where changing the render resolution only affects the game models
AFAIK changing render resolution in project settings affect everything, but I may be wrong, need to check this :D
*I just upgraded to 2022.2.1f1 and the custom scriptable render pass is not working anymore.*
This worked for me on Unity 2022.1.23f.
The script prints a NullReferenceException to the console on the second Blit call. For what I could understand so far, the Blit method tries to access the source's (RTHandle) render texture ("rt" read-only field) but it is null. I guess they've changed something with the CommandBuffer.GetTemporaryRT or the rt field default value.
I'm hoping someone or the video creator can help me with this setback, thanks for reading!
Sorry about that! I will need to look into it (what has changed in the new unity version).
I think I found a solution in Unity URP 2022.2 +. Use Full Screen Shader Graph to create the shader, and simply put the material into the new Full Screen Pass (Renderer Feature) from Unity. Instead of using a texture in the graph, plug it into the UV channel of an URP Sample Buffer instead. Check out the documentation on Full Screen Pass to make sure your material gets drawn correctly. This new feature from Unity let's us skip the code part completely as well!
To add to @@exhaston8780's comment, and just in case someone has the same problems I had in URP: For this solution to work, the URP Sample Buffer attribute "Source Buffer" needs to be set to "BlitSource". Then you plug the output into the Base Color attribute of your Full Screen Shader Graph and it should work just fine once you plug it in as material on your Full Screen Pass!
@@exhaston8780 hey man can you help me? i did what you say but i still confuse because my game now is Green, blue and red (the colors of URP Sample Buffer). i try put the texture again but it bring the error back so what you think i need do? thankss
@@jackrj3464 I installed Unity to give it a whirl after a while, and the fullscreen shader graph Shader should have UV->Posterize->SceneColor/SampleBuffer(Remember to put this to BlitSource)->BaseColor(Output). In the renderer data asset, apply fullscreen pass renderer feature, and assign a material you created from the shader. Set requirements to everything. It should work as this, let me know if it works or not.
Really great video. I was experimenting with this, and found that the "pixels" become stretched with the aspect ratio of the game window. Any ideas on how to work around this? Would it be something with how the material is applied?
EDIT: I figured it out. I think it is an improvement to your method. To get the pixels to become square and not stretched rectangles, I split the UV into x and y, and have each of them posterized seperately. I use the same Pixel Rate, but multiply the x posterization with the decired aspect ratio. Hope this helps if anybody was wondering about the same thing!
Hey! Sorry about not takling it into account.
Great to hear that you have found a way to fix it! 👍
Jettelly has a grate video about this that includes a solution for it but I wasn't sure how to transfer it to the shader graph (still learning myself 😅 ) ruclips.net/video/S8beHPDqE50/видео.html
Hey, I'm having the same issue but when I implemented the solution you suggested, it just changes the resolution of the image not the individual pixels. Do you think you could provide the node setup that you used? Thanks
I just get a NullReferenceException spammed in the console even in edit mode :( It happens in the second Blit command.
Hey!
I think I explain around 13:24 that we need to change the RenderPassEvent - when we want to apply our Blit command. Using the wrong one (trying to pixelate our screen too early in the Render pipeline) will cause this. We set it to BeforePostProcessing.
Let me know if it helped!
@@SunnyValleyStudio I'm having the same problem, I have render pass event set to BeforeRenderingPostProcessing but the game screen renders black and my console is full of NullReferenceExceptions coming from the Blit command.
@@TheSameTeam Thanks for letting me know! What version of unity are you using? It sounds like the URP package or Unity version issue. I did follow the documentation for this but maybe it something on my end so i will check 😅
@@SunnyValleyStudio No problem! I am using 2022.2.1f1
@@SunnyValleyStudio I'm also having the same issue as Sock here, also using 2022.2.1f1, have double checked that all the code is correct.
You can just go to the Quality settings of the URP asset and set the scale to a value lower than 1. I'm using version 2022.3.9f1 LTS currently. Haven't checked others.
Thanks!
I am getting error in "cameraColorTargetHandle" is it got removed?
Are you sure that you have set the effect to run Before Post Processing? I explain it i think at the end of the script - since if you don't set it you will get an error.
Really good. Any chance this can be done to a layermask?
Hey. You can use a separate camera to render the specific objects and combine 2 images together 1 pixelated and the other one not through the custom render feature.
PS. I have seen it but never done it's just an idea
why am I getting null reference exception.
Unless you forgot to assign the Render Texture to the camera I am not really sure that can cause it docs.unity3d.com/Manual/class-RenderTexture.html
i got this error thing is i checked unity doc about ScriptableRender and it contain it i dont understand
error
Assets\Shader\FullScreenRenderFeature.cs(20,63): error CS1061: 'ScriptableRenderer' does not contain a definition for 'cameraColorTargetHandle' and no accessible extension method 'cameraColorTargetHandle' accepting a first argument of type 'ScriptableRenderer' could be found (are you missing a using directive or an assembly reference?)
help plz
fixed it , it was problem with URP version i had to upgrade to 13+ to work
I'm glad that you were able to find a solution 🙂
@@justadevlog1667 can you tell me how to upgrade the URP version? i've got the same problem
Found the solution, you need unity 2022 to be able to get URP version 13.x
I've dropped about $50 or so for pixel effect assets but this one seems to do much better :)
I'm no artist but I hope that others cna use it to create some cool post processing effects for theire games :)
Stupid Question, but can you also "simulate" a Pixelart game with such a shader? So you basically make 3D Models and then you "convert" them to Pixelart?
no, its post processing effect, basically you convert the final image rendered using the shader the 3d model it self is untouched.
You can render ex your player onto a render texture using a second camera and apply the pixelated effect to it - so just to a single object (just like the censure effect works in The Sims I think) and you can combine the output of both textures using a custom render feature. At least that is how I would try to create it.
i'm trynna do this. i get 3d models and render them as pixel art without lighting and then light them with 2D lights using 2D normal maps && diffuse maps (without lighting). It should be possible to simulate a pixel art game, but i'm not sure if thats the correct way (i'm checkin' rn)
@@greendino5868 that is not what he was saying
I followed the tutorial but in the end URP turned off my post processing and all the objects in my scene were one flat color without shading. The only way to see the edges of objects was if they had a different material. I don't know what I did wrong :(
Hey! I'm really not sure. I will have to redo this tutorial anyways since Unity 2022.2 changed how this all work. I will make sure to take a look at this issue. Still since it is Post Processing all the shadows should already be rendered since we are using the Frame Buffer image so what the camera produces at the end of processing all the other objects.
@@SunnyValleyStudio they changed everything again? Man... why can't Unity just make features that work, are consistent and documented instead of constantly treating their engine like an experiment...
Hey man great stuff! Any news on a new udemy course in the future? I would love to see you teach how to create an xcom like 3d turn based game.
You're literally the best teacher on Unity coding, don't ever stop!
Thanks! Currently I am one step from releasing a VR coruse (more news soon). Next will be a Farm game course in 2D. Sorry for all the delays 😅
@@SunnyValleyStudio love to see you jumping into VR development, I'll pick that course up forsure!
hi great video bro, i have one problem i cant add material to the FullScreenRenderPassFeature
Hey! Sorry to hear that. I think that they have modified how it works from 2022.2 so I will have to have a look at this again.
For some reason when I switched to Unity 2022.1 it is now giving me a null reference exception error for the cameraColorTargetHandle. Anyone know how to fix?
Well as far as I can tell this method stops working when you use 2022.2 since some changes were made to URP pipeline. It should work correctly in 2022.1. Still I will have to make a new video using Unity 2022.2.
@@SunnyValleyStudio no I am using 2022.1
@@SunnyValleyStudio I have the same, have you found the way to handle this Handle, by any chance? :") Great vid btw, very informative!
I think this is cool as an instructional tool but it feels extremely wasteful to render at a high resolution then bin down the pixels like this. Why not just change the render resolution and reap huge performance gains as a result?
That is a good point. I am not sure really as I am still learning about the rendering process. I was exploring a bit more the way to use the custom render feature to create some additional effects and thought this to be a nice way to present it 🙂
@@SunnyValleyStudio Np! Cool video for exploring post processing effects and how to configure them!