PIXELART effect in Unity 2022.1 using custom render feature URP

Поделиться
HTML-код
  • Опубликовано: 4 дек 2024

Комментарии • 71

  • @felipezymor9970
    @felipezymor9970 2 года назад +3

    This one, combined with a toon shader, seems to be awesome... Thank you so much

  • @Kyanoxia
    @Kyanoxia 10 месяцев назад +4

    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.

  • @kaizen9451
    @kaizen9451 2 года назад +1

    Literally just saw this on the unity sub Reddit and open up RUclips and the video is there 😄. Timing.

  • @orangesoupd
    @orangesoupd 7 месяцев назад +3

    For anyone who can't use this because of NullException, replace Blit code with this
    commandBUffer.Blit(sourceTexture, tempTexture, material);
    commandBUffer.Blit(tempTexture, sourceTexture);

    • @SunnyValleyStudio
      @SunnyValleyStudio  7 месяцев назад

      Thanks so much for sharing yout solution! 👍

    • @MrElMunto
      @MrElMunto 6 месяцев назад +1

      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.

    • @orangesoupd
      @orangesoupd 6 месяцев назад

      @@MrElMunto that's because this code deprecated and need rewrite, it's not so hard

    • @schmiselchen
      @schmiselchen 6 месяцев назад

      @@orangesoupd can you elaborate please T-T how can I fix this?

    • @orangesoupd
      @orangesoupd 6 месяцев назад

      @@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

  • @iamgnud1092
    @iamgnud1092 2 года назад +10

    settings - render resolution 100% -> 20% - done xD
    joke aside, great job

    • @venesardthethief6704
      @venesardthethief6704 2 года назад +1

      Was going to say the same, unless we need some UI :D

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 года назад +1

      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

    • @venesardthethief6704
      @venesardthethief6704 2 года назад

      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 :)

    • @iamgnud1092
      @iamgnud1092 2 года назад

      @@venesardthethief6704 That's changing the entire resolution of the game. There are games where changing the render resolution only affects the game models

    • @venesardthethief6704
      @venesardthethief6704 2 года назад

      AFAIK changing render resolution in project settings affect everything, but I may be wrong, need to check this :D

  • @felipeticov
    @felipeticov Год назад +8

    *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!

    • @SunnyValleyStudio
      @SunnyValleyStudio  Год назад

      Sorry about that! I will need to look into it (what has changed in the new unity version).

    • @exhaston8780
      @exhaston8780 Год назад +6

      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!

    • @jorge5161
      @jorge5161 Год назад

      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!

    • @jackrj3464
      @jackrj3464 11 месяцев назад

      @@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

    • @exhaston8780
      @exhaston8780 11 месяцев назад +1

      @@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.

  • @mac12hallo
    @mac12hallo 2 года назад +5

    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!

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 года назад

      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

    • @Phoenix-0455
      @Phoenix-0455 Год назад +1

      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

  • @Zicrus
    @Zicrus 2 года назад +5

    I just get a NullReferenceException spammed in the console even in edit mode :( It happens in the second Blit command.

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 года назад

      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!

    • @TheSameTeam
      @TheSameTeam Год назад

      @@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.

    • @SunnyValleyStudio
      @SunnyValleyStudio  Год назад

      @@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 😅

    • @TheSameTeam
      @TheSameTeam Год назад +1

      @@SunnyValleyStudio No problem! I am using 2022.2.1f1

    • @Hietakissa
      @Hietakissa Год назад +1

      @@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.

  • @cordellcarrier3
    @cordellcarrier3 Год назад

    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.

  • @shouptikdey2089
    @shouptikdey2089 2 года назад +3

    I am getting error in "cameraColorTargetHandle" is it got removed?

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 года назад

      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.

  • @ULTRADARKSETH
    @ULTRADARKSETH 2 года назад +1

    Really good. Any chance this can be done to a layermask?

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 года назад +2

      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

  • @s3nju279
    @s3nju279 3 месяца назад +1

    why am I getting null reference exception.

    • @SunnyValleyStudio
      @SunnyValleyStudio  3 месяца назад

      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

  • @justadevlog1667
    @justadevlog1667 2 года назад +2

    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

    • @justadevlog1667
      @justadevlog1667 2 года назад +1

      fixed it , it was problem with URP version i had to upgrade to 13+ to work

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 года назад

      I'm glad that you were able to find a solution 🙂

    • @wizzzle2948
      @wizzzle2948 2 года назад +2

      @@justadevlog1667 can you tell me how to upgrade the URP version? i've got the same problem

    • @wizzzle2948
      @wizzzle2948 2 года назад +3

      Found the solution, you need unity 2022 to be able to get URP version 13.x

  • @wiglord
    @wiglord 2 года назад +1

    I've dropped about $50 or so for pixel effect assets but this one seems to do much better :)

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 года назад +1

      I'm no artist but I hope that others cna use it to create some cool post processing effects for theire games :)

  • @dexartsdesgblendair9526
    @dexartsdesgblendair9526 2 года назад +1

    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?

    • @greendino5868
      @greendino5868 2 года назад +1

      no, its post processing effect, basically you convert the final image rendered using the shader the 3d model it self is untouched.

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 года назад +1

      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.

    • @kepcukhusamettin9400
      @kepcukhusamettin9400 2 года назад

      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)

    • @Phoenix-0455
      @Phoenix-0455 Год назад

      @@greendino5868 that is not what he was saying

  • @Phoenix-0455
    @Phoenix-0455 Год назад +1

    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 :(

    • @SunnyValleyStudio
      @SunnyValleyStudio  Год назад

      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.

    • @NihongoWakannai
      @NihongoWakannai Год назад

      @@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...

  • @CowboyCoder21
    @CowboyCoder21 2 года назад

    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!

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 года назад +1

      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 😅

    • @CowboyCoder21
      @CowboyCoder21 2 года назад

      @@SunnyValleyStudio love to see you jumping into VR development, I'll pick that course up forsure!

  • @AbachiriProduction
    @AbachiriProduction Год назад

    hi great video bro, i have one problem i cant add material to the FullScreenRenderPassFeature

    • @SunnyValleyStudio
      @SunnyValleyStudio  Год назад +1

      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.

  • @Phoenix-0455
    @Phoenix-0455 Год назад

    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?

    • @SunnyValleyStudio
      @SunnyValleyStudio  Год назад +1

      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.

    • @Phoenix-0455
      @Phoenix-0455 Год назад

      @@SunnyValleyStudio no I am using 2022.1

    • @Drymarti
      @Drymarti Год назад

      @@SunnyValleyStudio I have the same, have you found the way to handle this Handle, by any chance? :") Great vid btw, very informative!

  • @monawoka97
    @monawoka97 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?

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 года назад +1

      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 🙂

    • @monawoka97
      @monawoka97 2 года назад

      ​@@SunnyValleyStudio Np! Cool video for exploring post processing effects and how to configure them!