Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


I'm guessing specular highlights shouldn't curve?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 05 March 2014 - 05:45 AM

Hello everybody!

 

I'm implementing a fresh set of lighting shaders and I'm testing using this scenario:

http://dl.dropboxusercontent.com/u/45638513/cur01.png

 

The bigger cube is in the middle of the scene. To the right is another cube signaling the direction of a directional light that is turned off in this scenario. Ambient and diffuse are also turned off. To the left is another small cube signaling the position of a red point light with blue specular highlights. 

 

If I move back from the point of view of the scene, the specular highlight starts to curve:

http://dl.dropboxusercontent.com/u/45638513/cur02.png

http://dl.dropboxusercontent.com/u/45638513/cur03.png

 

If I rotate the camera a bit to the right, the curving andle changes, eventually getting this:

 

http://dl.dropboxusercontent.com/u/45638513/cur04.png

 

I'm guessing that this is not correct behavior.

 

If I turn on the directional light and ambient and diffuse, I get pretty weird results:

http://dl.dropboxusercontent.com/u/45638513/cur05.png

 



Sponsor:

#2 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 05 March 2014 - 09:08 AM

Hmm, the curving seems to be persistent under all settings.

 

GGX Specular: http://dl.dropboxusercontent.com/u/45638513/cur06.png

Beckmann Specular: http://dl.dropboxusercontent.com/u/45638513/cur07.png

 

Even a hacked non attenuation version has it: http://dl.dropboxusercontent.com/u/45638513/cur08.png

 

It is hilarious that after so much time I can't write a very good physically based BRDF :).



#3 eppo   Crossbones+   -  Reputation: 2609

Like
0Likes
Like

Posted 05 March 2014 - 09:35 AM

What's the vertex resolution of the ground plane? It could be per-vertex calculations have a large error when they're interpolated over a large distance over the face of a primitive.



#4 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 05 March 2014 - 09:48 AM

What's the vertex resolution of the ground plane? It could be per-vertex calculations have a large error when they're interpolated over a large distance over the face of a primitive.

 

Wow, great hint. Thank you! I was so caught up on the shaders that I didn't think about the mesh. The plane was only 4 vertices.

 

I increased the resolution 100 times and the curving is gone at normal angles.

 

But at very steep angles I'm getting a "snaking" pattern:

http://dl.dropboxusercontent.com/u/45638513/cur09.png

http://dl.dropboxusercontent.com/u/45638513/cur10.png

 

Interesting and something to think about why this happens.



#5 Styves   Members   -  Reputation: 1073

Like
0Likes
Like

Posted 05 March 2014 - 10:35 AM

Is this per-vertex lighting?

 

Btw, the curving is probably your view vector being backwards. Try negating it.



#6 kostasan   Members   -  Reputation: 167

Like
1Likes
Like

Posted 05 March 2014 - 04:02 PM

Are you normalizing light/camera vectors in the vertex shader? I came across a similar problem some time ago and it was caused by just that.

http://interplayoflight.wordpress.com/2013/05/17/correctly-interpolating-viewlight-vectors-on-large-triangles/

As a rule of thumb I usually normalize nothing in the vertex shader as by doing that you lose "distance" information and the interpolation gives wrong results.

#7 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 05 March 2014 - 04:42 PM

Yes, I'm using per-pixel, a quite heavy pixel shader even.

 

But I was computing the view vector in the vertex shader.

 

I went from this:

http://dl.dropboxusercontent.com/u/45638513/cur11.png

 

to:

http://dl.dropboxusercontent.com/u/45638513/cur12.png

 

This did help a lot with the snaking.

 

But there was still some curving, particularly at a fixed small range of angles. After further testing I started to suspect anisotropy. The brick texture has a high surface variance and at a few angles the brick texture disperses the specular highlight vertically. This makes the oval highlight almost circular and over long distances curves it.

 

I tried a few smoother normal maps and they seem to have substantially less curving. The smoother it it, the less curving it has and the higher frequency you can use.



#8 Styves   Members   -  Reputation: 1073

Like
0Likes
Like

Posted 05 March 2014 - 08:15 PM

There should be no curving at all, regardless of roughness of the normal map.

 

Are you sure the normals are being calculated properly? If it's shifting to one side then it could be your bump map not being scaled properly (should be signed).



#9 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 06 March 2014 - 09:40 AM

The pattern used in the normal map seems to create distortion pattern with anisotropy at higher levels.

 

Here it is with anisotropy turned off:

http://dl.dropboxusercontent.com/u/45638513/cur13.png

 

Then, as I raise it at certain thresholds away from the camera distortion patterns occur:

http://dl.dropboxusercontent.com/u/45638513/cur14.png

http://dl.dropboxusercontent.com/u/45638513/cur15.png

http://dl.dropboxusercontent.com/u/45638513/cur16.png

 

The same thresholds seem to influence the curving, which sometimes curves, sometimes disperses the specular highlight.

 

For now my fix is to not use such large highlights, i.e. add specular highlight only for a few select smaller objects.



#10 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 06 March 2014 - 05:12 PM

Are you normalizing light/camera vectors in the vertex shader? I came across a similar problem some time ago and it was caused by just that.

http://interplayoflight.wordpress.com/2013/05/17/correctly-interpolating-viewlight-vectors-on-large-triangles/

As a rule of thumb I usually normalize nothing in the vertex shader as by doing that you lose "distance" information and the interpolation gives wrong results.

 

I now have a core set of shaders that I'm ready to make physically sound, so I read: http://interplayoflight.wordpress.com/2013/12/23/an-educational-normalised-blinn-phong-shader/

 

I'll play around with that project, might as well start and use FX Composer.



#11 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 07 March 2014 - 07:09 AM

One strange thing I noticed that those samples do:

float3 nor = tex2D(NormalSampler, texCoord).xyz;
nor = nor * 2.0 - 1.0;
nor.y = -nor.y;

What could be the possible reason for inverting the up component of the normal?



#12 kostasan   Members   -  Reputation: 167

Like
0Likes
Like

Posted 07 March 2014 - 08:53 AM

The normal is still in tangent space so Y is not the "Up" direction, Z is.

 

You wouldn't do this normally no but sometimes due to the way the normalmap is baked out, you might need to flip the X or Y component to get correct lighting.



#13 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 10 March 2014 - 02:01 AM

The normal is still in tangent space so Y is not the "Up" direction, Z is.

 

You wouldn't do this normally no but sometimes due to the way the normalmap is baked out, you might need to flip the X or Y component to get correct lighting.

 

Thanks, it makes sense. After further investigation I did notice that the "Green" part of the normal map is flipped. I guess I need to add an option to the content creator to fix such maps so that I don't have to maintain multiple versions of the same shaders.

 

Anyway, after months of study and work this is my result:

 

http://dl.dropboxusercontent.com/u/45638513/rs02.png

 

How does that look? This is the best visual result I ever got and the shaders support (non optimally) any number of light on a forward path. I used the higher resolution textures found in that blog post, but the albedo texture is disabled. It is just a normal map and an optional AO map, which is turned on in that screenshot. This is how an untextured object will look in the engine.

 

I read in one of the physically based rendering papers that an object should look good with only lighting, and I think truer words have never been spoken (in the domain of rendering).

 

The curving artifacts are still there, but depend on texture. This high resolution one has 0 curving or artifacts. High contrast normal maps under 512x512 will curve the shit out.

 

There are two more things I need to master and I'm done.

 

1. Toksvig AA, precomputed or not. I discovered Tokvig a while ago, but I'm always having a problem with it. In all the reference applications, Tokvig does stabilize the specular shimmering and gives some AA, but it also changes the perceived roughness of the surface a bit and spreads out the marginal highlights, basically altering the shape. So the choices are normal shimmering specular of different shaped non-shimmering ones. But whenever I "implement" Toksvig, and I put implement in quotes because it is just basically and extra multiplication with a simple expression based on normal length, I do not get that shape change. I'm comparing it right now with the results in FX Composer and things are slightly different. You do need a magnification glass to see the difference often, but it is there.

 

2. AA. That screenshot has some nasty shader surface aliasing. And from some angles it can be a lot worse. I'm guessing that the high contrast normal texture is partially to blame for increasing the surface aliasing:

 

http://dl.dropboxusercontent.com/u/45638513/rs04.png

 

That surface aliasing is pretty bad. The best SMAA is not good enough to fix this. Maybe with temporal reprojection it would help a bit.

 

What can be done about it?

 

One thing that I'll try it supersampling. I know of a technique used only for specular highlight supersampling. I never tried it on the entire lighting process, so there is no telling what results it will give. It is a constant backbufffer supersampling solution, meaning that 4x does not increase the resolution 4 times nor does it drop the performance by 75%. But there is still a steep performance drop.

 

On the other hand, more and more modern games do come with a SSAA solution out of the box. My GTX 660 TI is not strong enough for that, but I guess top end cards are so strong today that you can run some games with SSAA?

 

Anyway, I'll post my SSAA result here in a few days.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS