Physically Based Rendering - Page 2

Physically Based Rendering

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

I've run a bunch of tests and indeed the bitangent value received from the engine:

Code: Select all

vec3 modelBitangent = gl_MultiTexCoord6.xyz;
vec3 worldBitangent = normalize(vec3(modelMatrix * vec4(modelBitangent, 0.0)));
and bitangent calculated as

Code: Select all

vec3 worldBitangent = normalize( cross(worldNormalN, worldTangent) );
have exactly the opposite sign.

The cross(N, T) produces correct normal mapping for me. At least on dae models.
I'm not sure what conclusions to draw from this result: does engine have them wrong?
MaDDoX
Posts: 77
Joined: 08 Jan 2006, 17:45

Re: Physically Based Rendering

Post by MaDDoX »

I can confirm the result of the commit I got is the exact same visual appearance as what I get in Substance or Sketchfab. Truly amazing, Unity for instance has some hard time getting the proper final look in a PBR-textured model. Animated gif from the final effect:

https://media.giphy.com/media/5bb7C2Dk7 ... /giphy.gif

For a more detailed look into the normals we should probably use some more neutral/plain object, maybe a checkerboard covered sphere or something like that.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

I talked to @Floris the other day. Between the lines he raised his concerns on how "difficult" it is to set PBR and how many params are in the file.
I'd like to reassure everyone that most (90%) of the params are not really necessary most of the time and have sane implicit defaults.

What one really needs to define are maps (which texture unit represents which map), texture filenames and whether or not flip UV (depends on texture file type). This is more or less it. The rest is fine tuning. Moreover if all models have same texture mapping, some form of common template can easily be introduced to reduce amount per-file lines. All-in-all don't get scared away by https://github.com/lhog/Zero-K/blob/pbr ... fy.dae.lua Think of it as a "wiki" example.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

Hi again!

A small update: I've added softer on-model shadows to the PBR shader.

Image

Not only they work on the solid geometry, but also on the parallax mapped surfaces:
Image
Image

Note these parallax soft-shadows are extremely cheap, but they are merely a rough estimation, so sometimes fragments, that should be shadowed, won't receive any shadow. Still looks quite nice.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Physically Based Rendering

Post by FLOZi »

Utterly stunning work.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

Since PBR framework for unit models is completed, I have decided to distill it into separate Github repo.
Here is the new home:

Don't hesitate to find me on Github, here or in Discord if you have implementation questions or suggestions.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

Huge props to TurBoss, who tried to integrate my PBR unit shader into his game, found a bunch of glitches, that happened when I did the rip off from ZK repo and stayed patient until each and every bug was shut down.

Looking forward to see this guys on spring soilImage

P.S. Now I'm quite a bit more confident that current code can be easily integrated into 3rd party games.

P.P.S. Make sure to grab latest (maintenance, not develop!!!) engine for PBR, as the ugly cubemap seams were defeated by almighty Kloot. https://springrts.com/mantis/view.php?id=6099

P.P.P.S Screenshot from Jauria ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
Attachments
screen00089.jpg
(314.57 KiB) Not downloaded yet
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Physically Based Rendering

Post by Anarchid »

I know i've seen that parallax before, but that parallax is awesome. I hear rumors of a map shader; a working parallax would be great there (as opposed to the current lsd trip that vanilla spring has)
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

Anarchid wrote: 18 Dec 2018, 15:26 I know i've seen that parallax before, but that parallax is awesome. I hear rumors of a map shader; a working parallax would be great there (as opposed to the current lsd trip that vanilla spring has)
Vanilla spring parallax mapping is simple and fast, however it's less accurate than Parallax Occlusion Mapping, that I use in my shaders.

I indeed work on PBR map shader, however it's much more complicated with maps:
  • With models PBR, I had a sample model, a bunch of PBR textures and a picture of result image that I was supposed to get in the end.
  • I got lots of great advises from MaDDoX, who knew the best practices. This way we could prototype and test ideas quickly
  • Existing custom shaders were simple and didn't do much, so I just rewrote everything from scratch
None of the above is the case with maps: I don't have a map, PBR textures nor someone who can author them quickly enough. Not to mention that I haven't found someone who would know how things are supposed to work from artist/technical artist point of view. Also the existing standard map shader covers a lot of rendering, so existing code cannot be just easily reworked in the way I like.

With lack of better ideas my current approach is just to augment three detail levels (map-wide, details, splats) with PBR textures and base rendering on the existing standard diffuse textures (per detail level) and these additional PBR textures. Whether it makes any sense remains to be seen.

That said, I welcome any contribution from the community side: map, PBR textures, ideas, advices, etc.

P.S. My parallax will certainly make it into the shader :lol:
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

Playing around with terrain types: https://shaderfrog.com/app/view/2818
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: Physically Based Rendering

Post by PicassoCT »

Unlimited detail..

yes, its spectacular. I plan to do something with it over the xmas holidays.

Wish it could produce some fugly aproximation with default textures.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

WIP. Map PBR shader:
Image
screen00115.png
(3.41 MiB) Not downloaded yet
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: Physically Based Rendering

Post by PicassoCT »

Holy Moly
User avatar
azaremoth
Cursed Developer
Posts: 549
Joined: 17 Feb 2005, 22:05

Re: Physically Based Rendering

Post by azaremoth »

Wow - that looks impressive!
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

Added Ambient Occlusion, NdotL shadows and Shadow Mapping.
Also enabled materials' normal mapping just to showcase how they look.

Image

Wanted to point out that the current branch of Map PBR code lives here:
https://github.com/lhog/spring-map-pbr/tree/PBRv2

Also I'm looking for a brave soul who would put together a map using the Map PBR as an artist.

If anything this would help greatly to offload artist work from me and clean out the bugs (which must be there in abundance).

P.S. Small in game video (note the surface here is configured to be very glossy because I was troubleshooting reflections). https://drive.google.com/file/d/1yGK6Os ... ZXr_t/view
Attachments
screen00120.png
(3.89 MiB) Not downloaded yet
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

At this moment I'm working on materials blending.

The industry standard for this is more or less what's called height based blending. It's the blending mode, where two or more materials are mixed not only according to their distribution weight (which alone would give a very flat featureless picture), but with respect to the height/displacement provided along with texture materials as well. Here's the good explanation of what is materials blending and what each blending mode looks like (I'm aiming to replicate the look of the last picture):
http://www.gamasutra.com/blogs/AndreyMi ... atting.php

As always couple of pictures of what's been achieved so far:

Here you can see the gravel and ice material are mixed together linearly from left to right. The most interesting part is what happens in the middle, where both weight (changing from left to right) and height (which is the property of each material) play nicely together.
Image

And here's the zoomed in fragment, it's placed around the middle of the map, as described above. On the left side the gravel is almost "pure" with very little perceived amount of inclusion. In the middle, we can see ice patches occupy cracks between individual gravel stones. On the right side, ice has almost replaced the gravel patches as the latter are barely visible.
Image

What pictures above lack is the sense of volume, which in case of spring can be only emulated by use of the parallax occlusion mapping (POM).

Unfortunately with such diverse set of materials and the way they are currently described in Lua, the implementation of POM looks rather complicated, so it remains my stretch target. Practically this means, that I only do it in case there is some real interest/demand from the artists (see my previous post).

In the mean time you can entertain yourself by looking how materials blending might work with POM here: https://shaderfrog.com/app/view/2818
Attachments
screen00139.png
(4.25 MiB) Not downloaded yet
screen00138.png
(3.59 MiB) Not downloaded yet
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Physically Based Rendering

Post by ivand »

Time to bump topic a bit since I'm still (unsuccessfully) looking for a volunteer artist to test terrain PBR in action.

To illustrate "why PBR?" and ignite some interest, I'm attaching the next screenshots, where height based materials blending is more evident than on screenshots I attached before.

The materials I mix together can be seen/downloaded here:
"Rock"
"Some soil"


0.1 metalness (reflectivity) on both materials:
Image

1.0 metalness on the rocks.
Image

1.0 metalness on the soil.
Image
Attachments
screen00234.png
(3.94 MiB) Not downloaded yet
screen00233.png
(3.79 MiB) Not downloaded yet
screen00232.png
(3.52 MiB) Not downloaded yet
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: Physically Based Rendering

Post by PicassoCT »

Moose and Yak he is looking at you.
User avatar
The Yak
Posts: 351
Joined: 20 May 2012, 05:36

Re: Physically Based Rendering

Post by The Yak »

I'll be travelling for a while yet, and no computer with me this time. Perhaps after winter season I'll have some time to play with this.
MaDDoX
Posts: 77
Joined: 08 Jan 2006, 17:45

Re: Physically Based Rendering

Post by MaDDoX »

Beautiful, height/vertex blend is amazing. It's worth mentioning that in Ivand's PBR terrain implementation you're not limited to 4 materials as in the standard splats technique, you're only limited to the amount of max textures at once - 24, if memory doesn't fail me. So you can have, for instance, 2 splat textures with 4 +1 materials (RGBA + default) defined by one splat map and 4 materials (RGBA) in another.

That's an incredible breakthrough! I probably won't be the first to get a map done in this system, but I'll try hard to be among the first few ;)
Post Reply

Return to “Engine”