Three.js Pixel Shader Update - Seamless Outlines

  Рет қаралды 19,617

Kody King

Kody King

Күн бұрын

I fixed gaps in normal-edges around vertices and moved my code into a PR for Three.js.
Inspired by t3ssel8r's work: / @t3ssel8r
Thanks to Omar Shehata for his tutorial on writing an outline pass: / how-to-render-outlines...
Source: github.com/Kod...
github.com/Kod...
PR: github.com/mrd...
Demo: raw.githack.co...

Пікірлер: 76
@monkeysfromvenus
@monkeysfromvenus 2 жыл бұрын
Looks beautiful, I'd love to see it on some more natural geometry with variations in edge "sharpness" like rocks or something. How is the brightness of the normal edges chosen? Is it just a flat increase? It might be cool to brighten the normal edges based on averaging the normals of the two connected faces or something.
@krish-ut9de
@krish-ut9de Жыл бұрын
I watch this video every single day XD, it's so beautiful
@HEOlASSASSIN
@HEOlASSASSIN 2 жыл бұрын
i don't know what sort of shader sorcery this is, but i love it
@gianluska.4255
@gianluska.4255 2 жыл бұрын
That is awesone! Great work
@halo3kings88
@halo3kings88 2 жыл бұрын
This is amazing! Great work!
@elliotb_256
@elliotb_256 2 жыл бұрын
It looks really great! Are you doing interior edge lines by using the normals to detect them, then lightening those pixels? I've also been keen to try an alternative method, which would be to sample the 'average' surrounding screen-space normal and then use that in a lighting calculation. This would allow someone to distinguish between interior/exterior edges, wondered if you had plans to try something similar?
@jamesking2439
@jamesking2439 2 жыл бұрын
Thank you! Yeah, that's how I'm getting the interior edges. It took some hacks to get that method to only detect on one side of an edge though. I was actually planning on trying a more direct method where I render interior/exterior edges in a separate pass and then combine everything in a final step. I haven't gotten around to trying that yet.
@elliotb_256
@elliotb_256 2 жыл бұрын
@@jamesking2439 I also found rendering object Ids to a separate buffer works really well for silhouette outlines, and if you do that stage before rendering the objects you can then sample it and do per-object color grading of the outlines (it would be more performant to be able to do it in the gbuffers but im on unity stuck with forward rendering)
@jamesking2439
@jamesking2439 2 жыл бұрын
​@@elliotb_256 That's clever. Not having per-object artistic control was the biggest problem I had with this effect. Thank you.
@rocifier
@rocifier 2 жыл бұрын
@@elliotb_256 you know you can change unity to use deferred rendering instead of forward right?
@elliotb_256
@elliotb_256 2 жыл бұрын
@@rocifier yes, but in doing so it becomes a lot more 'fixed pipeline', particularly around lighting calcs. And then you can only apply modifications after the lighting calcs to the entire screen, which prohibits things like per-object color grading and dither patterns
@AndersonMancini
@AndersonMancini 2 жыл бұрын
Great work. Looks awesome.
@hyl
@hyl 2 жыл бұрын
Is your camera using isometric or perspective projection? The shape of the plane looks strange at different angles.
@jamesking2439
@jamesking2439 2 жыл бұрын
It's isometric.
@krish-ut9de
@krish-ut9de Жыл бұрын
happy new year bro!
@jpthedio
@jpthedio 2 жыл бұрын
Awesome work! 🙌
@printfhelloworld9806
@printfhelloworld9806 2 жыл бұрын
It‘s annoying to get single pixel edges, I read the code and in the line 173 there is “// Only the shallower pixel should detect the normal edge.”. I want to know is it the key to get single pixel edge? sorry for my bad English.
@jamesking2439
@jamesking2439 2 жыл бұрын
That's the key for the outer edges. The internal edges break the tie by determining which pixel's normal is more towards a fixed "bias direction" in screen space.
@printfhelloworld9806
@printfhelloworld9806 2 жыл бұрын
@@jamesking2439 It works!Thank you so much,I've wasted a lot of time on the convolution kernel trying to get a single pixel edge and I would never think out such a clever trick.
@HiphopBurny
@HiphopBurny 2 жыл бұрын
@@jamesking2439 This conversation helped me so much!!!!! Thanks. I am using Unreal Engine, please can you tell me what do you mean by fixed "bias direction" in screen space?
@jamesking2439
@jamesking2439 2 жыл бұрын
​@@HiphopBurny So when I do edge detection on the normal texture, I look for pixels whose normals are more towards the upper right of the screen than their neighbors. That "upper right" direction is the "bias direction" I'm talking about. You can see the relevant code here: github.com/KodyJKing/hello-threejs/blob/main/src/RenderPixelatedPass.ts#L99
@bunyaponchaiongkarn8258
@bunyaponchaiongkarn8258 Ай бұрын
Great work!
@dontfrickhoes5904
@dontfrickhoes5904 2 жыл бұрын
i bet this took you months to finish and i love you sharing your source code i really wanted to try out t3ssel8rs shaders for my game. do i do this in urp or hrp?
@jamesking2439
@jamesking2439 2 жыл бұрын
This is built for Three.js. If you want something like this in Unity, checkout ProPixelizer.
@dontfrickhoes5904
@dontfrickhoes5904 2 жыл бұрын
@@jamesking2439 oh damn but propixeler is paid i dont have money. is it possible for me to like mimic the shader like make my own in unity?
@jamesking2439
@jamesking2439 2 жыл бұрын
​@@dontfrickhoes5904 I don't know much about Unity, but if you can create a post-processing effect with access to your camera's depth and viewspace normal textures, I think you could translate my edge detection shader to Unity fairly easily. I don't know how hard it is to do post-processing effects in Unity. I do know Unity has a way to get depth and normal textures from your camera: docs.unity3d.com/Manual/SL-CameraDepthTexture.html
@daveb7596
@daveb7596 2 жыл бұрын
omg please post more of this type of stuff.
@joey475
@joey475 Жыл бұрын
Very impressive! How does your technique compare to using an operator like Sobel or Roberts Cross?
@777-h1n
@777-h1n Жыл бұрын
bro could you please do a tutorial? new to three.js and I really would love to understand how to do it on my own and how it works. And great job, it looks great 🙏
@jamesking2439
@jamesking2439 Жыл бұрын
I don't have time to make a tutorial right now, but you can check out this tutorial which helped me: omar-shehata.medium.com/how-to-render-outlines-in-webgl-8253c14724f9 And you can check out my shader code: github.com/KodyJKing/three.js/blob/outlined-pixel-example/examples/jsm/postprocessing/RenderPixelatedPass.js The tutorial doesn't cover how to do pixel perfect outlines, but it gets you most of the way there. I'm doing a some extra tricks to get 1 pixel thick outlines (on lines 167 and 172).
@777-h1n
@777-h1n Жыл бұрын
@@jamesking2439 I understand bro, thanks a lot for the ressources 🙏 I'm going to try it out ! Thank you very much ! Have a nice day 🙌
@XxkevinGUYxX
@XxkevinGUYxX 2 жыл бұрын
Any way to add this to react three fiber?
@jamesking2439
@jamesking2439 2 жыл бұрын
Maybe with this: github.com/pmndrs/react-postprocessing I'm not sure how easy it is to add custom effect components with this, but it's worth taking a look.
@diligencehumility6971
@diligencehumility6971 2 жыл бұрын
How to get pixel perfect out lines from 3D? 🤔🤔🤔🤔🤔
@ropenrommuelle5241
@ropenrommuelle5241 Жыл бұрын
Thanks bro I've been searching for something like this. Do you think you can create a tutorial for the shader grass and leaves? just like t3ssel8r's shaders
@krish-ut9de
@krish-ut9de Жыл бұрын
hi man, i am also looking for that. Can you please tell me if you found anything?
@illumi1749
@illumi1749 Жыл бұрын
can you make a tutorial on how to implement and use this?
@itsafish4600
@itsafish4600 4 ай бұрын
cool
@kombosabinho
@kombosabinho Жыл бұрын
Hey was this done in Godot or Unity? Thank you so much for posting, very beautiful effect indeed :)
@jamesking2439
@jamesking2439 Жыл бұрын
This was done for the web with Three.js. I have another demo I built for Godot: github.com/KodyJKing/PixelShader For Unity, there's an asset you can buy called "ProPixelizer".
@Equilix_Doom
@Equilix_Doom 10 ай бұрын
@@jamesking2439Does the Godot demo have the ability to recreate this scene or is it more limited?
@jamesking2439
@jamesking2439 10 ай бұрын
@@Equilix_Doom IIRC, it was more limited. The edge detection was implemented directly in each materials shader rather than a frame post processing step, so it was more of a pain to customize objects. It probably could still reproduce this scene though.
@Equilix_Doom
@Equilix_Doom 10 ай бұрын
@@jamesking2439 Thanks for the quick response! Another question does three.js use GLSL and if so couldn't the code from the website be reverse engineered to use in Godot?
@cholasimmons
@cholasimmons 2 ай бұрын
Looking at this just reminds me of my father, we used to take turns on Prince of Persia, 💓 Oh Dad
@__BBRAGA__
@__BBRAGA__ 2 жыл бұрын
Amazing would you mind to share a tutorial about this?
@WTZ.
@WTZ. 2 жыл бұрын
:O
@raulcantu9784
@raulcantu9784 2 жыл бұрын
Hello bro, I loved what you did, did you do it in unity? I would love to learn how to do the same, could you make a video explaining how you did it?, Please.
@jamesking2439
@jamesking2439 2 жыл бұрын
I didn't make this in Unity. I made this with a JS library called Three.js. If you want this effect in Unity, you could use ProPixelizer from the asset store. kzbin.info/www/bejne/nnbKlWmOfryKZ6c
@raulcantu9784
@raulcantu9784 2 жыл бұрын
@@jamesking2439thank you very much bro
@woodsy4458
@woodsy4458 2 жыл бұрын
Can this work in unity, would love to try it as a shader for a game project im going to work on
@jamesking2439
@jamesking2439 2 жыл бұрын
My shader wasn't written for Unity, but you could get ProPixelizer from the asset store. It's $25 though.
@Alex-is-Procrastinating
@Alex-is-Procrastinating 2 жыл бұрын
how can i use it? Can you make a tutorial?
@jordanlately
@jordanlately 2 жыл бұрын
this is so gorgeous. would love to understand how I can use this. would you be open to sharing any tips on how to use this shader on 3d compositions I've made?
@krish-ut9de
@krish-ut9de Жыл бұрын
how did you make this????
@osmodivs
@osmodivs Ай бұрын
Ok, how do I use this in Blender?
@jamesking2439
@jamesking2439 Ай бұрын
This is a post processing effect that samples from depth and normal textures to find edges in the image and highlight them. Blender's compositing system doesn't look powerful enough to do this. You'd probably have to render your scene in multiple passes and use an external program to do the edge detection.
@jamesking2439
@jamesking2439 Ай бұрын
You *could* use another scene and feed the rendered passes back into a shader to do the edge detection. Then render a full screen plane with that material.
@sugimanjuara8195
@sugimanjuara8195 2 жыл бұрын
it is possible to be apply for Godot Engine ?
@jamesking2439
@jamesking2439 2 жыл бұрын
Definitely. The shader in this video is for Three.JS, but I did implement a demo of this in Godot a while ago. Feel free to use this however you want. github.com/KodyJKing/PixelShader
@sugimanjuara8195
@sugimanjuara8195 2 жыл бұрын
@@jamesking2439 OMG Thank you so much !!
@babbyboned
@babbyboned 2 жыл бұрын
@@jamesking2439 I'm an aspiring godot game dev looking to make something like this. I took a look at your scene and I am trying to figure out what your buffer node/script does. I can't seem to tell a difference with/without it. Thanks!
@jamesking2439
@jamesking2439 2 жыл бұрын
@@babbyboned That script/node is unused in the main branch. There is another branch where I use that to be able to have an arbitrary number of buffers. In the main branch, I use multiple pass materials. I render normals in the first pass and then in the second pass I render the final image, reading normals out of SCREEN_TEXTURE and depth information out of DEPTH_TEXTURE. BTW, I am a total Godot rookie, so my approach could be very hackish/bad practice.
@corvus7535
@corvus7535 2 жыл бұрын
is there such a thing for Maya?
@jamesking2439
@jamesking2439 2 жыл бұрын
Not that I know of, but I don't know anything about Maya.
@zion6570
@zion6570 2 жыл бұрын
wow how did you do this?
@jamesking2439
@jamesking2439 2 жыл бұрын
Omar Shehata's article in the description explains how to use depth and normal buffers to find edges. I had to modify the technique a bit to get single pixel edges. For depth edges, I check to make sure that a fragment is shallower than its neighbors. For normal edges, I make sure that a fragment's normal is more in the direction of a fixed bias direction than its neighbors.
@jerrygreenest
@jerrygreenest 2 жыл бұрын
Please add a link to PR
@jamesking2439
@jamesking2439 2 жыл бұрын
github.com/mrdoob/three.js/pull/22322
@ibramkadyrov9734
@ibramkadyrov9734 2 жыл бұрын
What app you use?
@jamesking2439
@jamesking2439 2 жыл бұрын
This was made with Three.js, a 3D graphics library for JavaScript.
@krish-ut9de
@krish-ut9de Жыл бұрын
how did you make this???? OMG ITS OPEN SOURCED
@jamesking2439
@jamesking2439 Жыл бұрын
The shader does edge detection on depth and normal buffers to get the outlines and seams between faces. To get single pixel seams, each pixel compares its normal to its neighbors' normals and to a constant "bias normal". The pixel that is more in the bias direction is rendered as an edge.
@krish-ut9de
@krish-ut9de Жыл бұрын
@@jamesking2439 Thank you so much for your detailed reply, i really love your work. Its a piece of art, in fact i bave multiple screen shots of this video just to use as inspiration for aspiring future 3d pixel art projects. I really want to learn how it was done but all of the things that you said are foreign to me. Could you please recommend some starting points for a total beginner such as myself for learning the things that you do
@krish-ut9de
@krish-ut9de Жыл бұрын
@@jamesking2439 thank you again good sir
@jamesking2439
@jamesking2439 Жыл бұрын
​@@krish-ut9de My computer graphics knowledge is fairly limited, so I might not be the best advisor, but I can tell you what's been helpful to me. I learned how to write shaders by watching Inigo Quilez and The Art of Code, following along with their projects on Shadertoy. (Shadertoy is a great way to learn about fragment shaders, but it won't teach you how to about vertex shaders.) If you're already familiar with shaders, this article might be helpful. It's how I learned to use depth and normal buffers for edge detection in ThreeJS: omar-shehata.medium.com/how-to-render-outlines-in-webgl-8253c14724f9
@krish-ut9de
@krish-ut9de Жыл бұрын
@@jamesking2439 THANK YOUU SO MUCH🙏🙏🙏🙏
Bedrock. Why?!
22:37
FundyLIVE
Рет қаралды 315 М.
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,5 МЛН
Шок. Никокадо Авокадо похудел на 110 кг
00:44
Inside Out 2: BABY JOY VS SHIN SONIC 3
00:19
AnythingAlexia
Рет қаралды 6 МЛН
МАИНКРАФТ В РЕАЛЬНОЙ ЖИЗНИ!🌍 @Mikecrab
00:31
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 42 МЛН
How I Made Palette Pixel Shader From Scratch in Godot
9:58
DeveloperEzra
Рет қаралды 8 М.
Pixel Art With MAGNETIC Minecraft Blocks...
8:27
The Plop
Рет қаралды 494 М.
3 Hours vs. 3 Years of Blender
17:44
Isto Inc.
Рет қаралды 4,9 МЛН
I Built the World's Comfiest Mouse (ft. Bambu Lab A1)
6:22
Play Conveyor
Рет қаралды 2,1 МЛН
I Made The Ultimate Cheating Device
9:39
ChromaLock
Рет қаралды 967 М.
Crafting a Better Shader for Pixel Art Upscaling
12:39
t3ssel8r
Рет қаралды 152 М.
Introduction to shaders: Learn the basics!
34:50
Barney Codes
Рет қаралды 335 М.
How I Got Hired as a Character Artist For Games
20:52
J Hill
Рет қаралды 498 М.
MarioKart.js Blew My Mind (Open Source + React + ThreeJS)
11:37
Theo - t3․gg
Рет қаралды 211 М.
An introduction to Shader Art Coding
22:40
kishimisu
Рет қаралды 977 М.
Шок. Никокадо Авокадо похудел на 110 кг
00:44