GLSL reflective floor shader

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Vir
Posts: 14
Joined: Thu Feb 21, 2013 10:00 pm

GLSL reflective floor shader

Post by Vir »

I'm going to have a shiny, stainless steel floor at the y=0 plane, in world coordinates. Anyway, I was thinking that with a GLSL shader, it wouldn't be too hard to have a multi-layered floor with the following layers:
  • A reflective layer, which would reflect any objects in the scene that are above the y=0 plane. Reflections would be distorted somewhat due to a tangent-space normal map on the floor.
  • A diffuse layer, which would be the nonreflective component of the floor. It'd be a steel-gray color, with a slight variation. It'd be nice to generate this map on the fly with an equation, so that the repetition of the floor pattern wasn't visible from far away.
  • An ambient shadow layer, which would be blurry and baked on, and fairly subtle. This would have to be a saved texture.
My main issue is that I want it to look really good up close, and also really good from far away. Plus, the floor is going to be pretty huge, to the point where even a 4096*4096 texture wouldn't be detailed enough. I get that this is what the terrain scene node is designed to be used for, but I'm not sure how well that would work as a source of data for a GLSL shader. Also, the floor will be a geometric plane, so maybe something like a modified water shader with a static normal map might be more what I'd need? Any thoughts?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: GLSL reflective floor shader

Post by hendu »

Details up close - try simplex noise in the fragment shader. (google for webglnoise for one port)
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: GLSL reflective floor shader

Post by Mel »

Try a detail mapping approach. Detail maps were used on Unreal Engine 2 so it never became too blurry when you moved near an object, i.e. when the fragment is close to the camera, make the detail map more evident, when it is far, make it less noticeable.

http://rastertek.com/tertut13.html

take a look, well, it is a DX11 tutorial, but the basics for detail mapping are there, and passing them to GLSL is trivial
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Vir
Posts: 14
Joined: Thu Feb 21, 2013 10:00 pm

Re: GLSL reflective floor shader

Post by Vir »

Thanks. I've been looking into noise algorithms, and so far that seems to be the best way to go, as long as I can get the normal map to match the detail map. Or maybe I'll just compute them separately, at different detail levels, that seems a lot easier, and probably would look okay. I mean, it's just a floor after all.

Now I'm trying to figure out if it'd be trivial to calculate the reflection based on distortions from the floor's normal map. It seems trivial, but I guess I just haven't fit all the pieces together yet.
Post Reply