Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[CLOSED] Is it possible to create PS1 vertex snapping shader in Shader Graph?

Discussion in 'Getting Started' started by BroMandarin, May 24, 2019.

  1. BroMandarin

    BroMandarin

    Joined:
    Dec 27, 2016
    Posts:
    5
  2. Renalicious

    Renalicious

    Joined:
    Nov 2, 2019
    Posts:
    1
    Yes it's possible to create a something like that in shader graph. I'm currently working on something like that myself, but now I'm stuck on trying to replicate the affine texture mapping.

    The main graph for vertex snapping.
    PS1_VertexSnapping_MainGraph.PNG

    The sub graph for generating approximate scene depth from vertex positions. Not as accurate as the scene depth node, but it's about the only way to get it done since the scene depth node is only usable on the fragment portion of the shader. At least as of now.
    PS1_VertexSnapping_AproximateSceneDepth.PNG

    Hope it helps!
     
    WizPit and Onigiri like this.
  3. BroMandarin

    BroMandarin

    Joined:
    Dec 27, 2016
    Posts:
    5
    Thanks for your reply!

    As far as I see, this shader replicates vertex snapping by snapping vertices to object space grid. So if camera is moving away, effect becomes invisible, but if camera is too close, effect becomes crazy.

    Original PS1 hardware had snapping in pixel space, so effect is noticeable at any distance.
    To replicate this in shader, we should use vertex clip position. We have two problems with that in shader graph:

    1. We have to manually transform object to clip position using projection matrix.
    2. Shader graph master node takes position in object space, so we have to convert clip space back to object space. As far as I know, this involves inverted projection matrix, but is doesn't work in shader graph (It is present as option in Transformation Matrix node, but it throws error).

    As my original goal was to have ps1 effect in lwrp (and not in shader graph specifically), I decided to rewrite shader manually.
    Keep in mind that this is my first shader actually written in HLSL, so there are a lot of space for improvement.

    https://github.com/BroMandarin/unity_lwrp_psx_shader
     
  4. Jasperle

    Jasperle

    Joined:
    Jul 16, 2015
    Posts:
    4
    Hey BroMandarin,

    isnt there a way of faking this effect via creating a raster via the screen view direction? I want to recreate this effect for so long but every shader i testet looses its effect in the distance like you said. I mean we just need to create a raster or something the vertices can snap to right? Or am i thinking wrong- im a total noob when it comes to shader programming ^^

    -Greetings
     
  5. BroMandarin

    BroMandarin

    Joined:
    Dec 27, 2016
    Posts:
    5
    Hi, Jasperle.
    I don't quite understand your approach, but I can say that shader loses its effect because it "fakes" it and not implements it in "proper" way.
    Vertices should snap to screen pixels or custom sized grid (original PS1 resolution in both shaders I linked).
    This should be done in clip space coordinates. (Which shader graph doesn't support).
    Have you tried shader I linked? (https://github.com/BroMandarin/unity_lwrp_psx_shader) It shouldn't have that problem with distance. It worked before Universal RP (2019.2?), but is probably broken in later versions. For default render pipeline this: https://github.com/dsoft20/psx_retroshader is probably the best one.

    But, if you want it to work correctly in ShaderGraph, I don't think that's possible. It wasn't possible last time I used Unity (2019.2).
     
  6. Jasperle

    Jasperle

    Joined:
    Jul 16, 2015
    Posts:
    4
    Sorry if that offends you but im just thinking of faking this because im not reallly interestet in reproducing it in a way it was done in the past :) Its an extremly interesting aspect of 3D history but mybe there is a way of getting this to work in shader graph... i also testet it witha distance multiplicator but it was to jerky or a dont have enough experience :)

    Im thinking of it like here;

    upload_2020-2-8_23-42-44.png
    Creating a raster which is drawn from the camera to the far plane maybe? and limiting the vertices to snap to the lines which are created via a raster texture in the view directon... but i dont have any understanding in shader developement so this approch may be to expensive
    upload_2020-2-8_23-48-1.png

    to make it clear... i have no idea what im doing, im just playing around ^^
    -> two approachs, one with the raster procedural and one via uvs

    it does not have to be precise just that the effect increases at in the distance right?

    yes back in 2018/19 at least the second one you postet (not the one you createt yet) (and another one but i cant remeber the name of the creator) but i need shader graph to implement features i want for my project, so im bound to it~ :)

    Sad :( bit maybe with custom functions?

    -Greetings
     
  7. BroMandarin

    BroMandarin

    Joined:
    Dec 27, 2016
    Posts:
    5
    Oh, no, not at all :) I wasn't clear here. I didn't mean making it exactly like original hardware.
    I see. The thing is, I'm no more using Unity, so I can't help with ShaderGraph. Sorry.

    I can't really "recommend" anything to you, but if you already know regular programming I would really try to learn shader programming. This may be just a personal thought, but I really think ShaderGraph is the dead end here.

    BUT I totally understand if you don't want to and prefer ShaderGraph as I started this thread exactly in the same situation.

    Best regards.
     
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,954
    Unity's official stance is that you should be using Shader Graph, and everything I've read from other people posting about it has led me to the conclusion that they're correct. Getting custom shader code working with the new rendering pipeline is simply nowhere near as easy as it was with the old pipeline.

    An experienced shader developer most likely won't have any troubles with it, but a beginner will have to invest a lot of time into learning everything and for little to no gain compared to the node-based approach. It's intended that you only write code if you need a new master node or need to implement custom nodes.
     
    Last edited: Feb 9, 2020