• Home of the RD Le Mans Series by Vesaro
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Directional Shaders; like cheap occlusion

Discussion in 'Racer Physics and Technical' started by Stereo, Apr 15, 2013.

  1. Just playing with some ways to make things work a little more naturally in the reflections+specular department.

    In this case, a model that's mostly occluded in a fairly simple fashion. And is, from what I remember, textured in a way that would make doing this via a control map a pain in the butt, not to mention less accurate, since the reflection depends on where the camera is too.

    Left-new, right-old.
    In the first pic you mostly notice it on the inner part of the wheel which is much less blue due to not reflecting the sky, in the second pic it's mostly the sides of spokes which are also reflecting blue.

    The shader is based on a simple principle - the wheel has one outward-facing direction, from which all valid reflections + specular hilights (which are just soft reflections) appear - basically the halfspace outward from the side of the car. If a part of the wheel model is at an angle to this direction, then, quite frequently, it'll be reflecting something 'through' the wheel or the car - so it should prefer not to do any reflecting at all.

    The shader can't deduce, on its own, which way is 'outward' - so I passed in, through the emission variable, a normal vector for the object. The vertex shader compares this with the current polygon's normals, and if it's reflecting 'behind' the plane then it scales reflections and specular down to 0. This means there's no extra texture reference but each different direction needs its own shader (left + right wheels are separate)

    This is pretty much the equivalent of rendering a reflection map that's black on the half 'behind' the wheel, and normal on the other side. Due to the way it's calculated, it also ramps down to duller reflections at steeper angles instead of having a sharp cutoff.

    With the way the two half-spaces of the model and the current poly intersect, it might also be appropriate to scale ambient light based on this factor - but I think baked AO is a more familiar way to handle that issue. Direct diffuse light, of course, has the shadow map to cull it from inappropriate surfaces.

    With reflections turned up to 1.0 it looks like this. (new left, again)
    • Like Like x 4
  2. Hi,
    i guess i'll be of topic, but i don't know where to post.
    I wanted to make my Racer more realistic, because there was no real impact of normals, i mean the whole scene looks too flat ingame
    I've edited the lighting.cg file and i've uncommented this :
    I'm pretty sure ruud used it ! I remember a version wich had nicer shadows
    I've also decreased normalInfluence impact for the ambient part (make it darker), and added it to diffuse term
    Look (after is bottom)
    [​IMG] [​IMG]
    [​IMG] [​IMG]
    • Like Like x 4
  3. KS95

    RACER Moderator

    Wow, that does look much nicer.
  4. The normal influence is just a fudge factor really, but it's effective. Ideally you want to bake AO maps for everything for ambient, and use the subtle normal influence.

    Normal influence on diffuse is just not right, since diffuse by definition is from a known point, not dispersed all around.

    It looks good, but for every situation where it looks good it might look bad in others and be caught out. It appears that the ambient light on that track is too high generally any way... in strong sunlight the shadow vs lit area should be much starker I think. Hmmmm....

    Really we should be properly unwrapping interiors and doing a proper bake job for AO and diffuse shading etc... :D

    Still, this shader is really nice Stereo. I guess using another shader for wheels is ok as they are separate batches any way being separate models.

    Useful for anything reflective that isn't generally a blob shape (ie, the main car body)
    Ie, exhaust pipes and stuff will look more realistic when they don't reflect the sky when really it's occluded!


  5. Hmm, would it be at all possible to render this kind of information onto a normal map? (direction of incoming lighting, basically, in world coordinates) It would be easy to do a version of this that takes it from a texture instead, the problem is just that I don't know how to compose the texture except manually (look at the model, pick a direction, figure out the colour it corresponds to) so the extra complexity is a bit pointless since it's mostly a minor change.

    If it was for something that doesn't have its own UV map, like the chrome on the Aronde, I could just lay out a grid of the major directions (front/left/back/right, plus 45 degree increments, each with a little tile in a texture), and map each bit of chrome to the right section. For chrome in particular it might be a good idea to use a colour other than black for the 'obscured' reflections since they're nearly entirely illuminated by reflection. Maybe Ka times the lighting of the normal vector.

    In terms of what I know how to do in Blender, it's easier to just render out a cube map from the POV of each object I want to have special reflections, except that cubemaps only load rgb. It's also a higher texture load, this is sort of a compromise of less detail where it's less important. (and where the complexity of the object means a single cubemap's not gonna look right anyway)
  6. It's a tough one to balance properly I guess.

    I think the system you have right now with the wheels is a perfect example of how this works to add visual quality and realism. OK it's not realistic to reflect nothing, but on balance it's better to reflect nothing, than reflect as if the car didn't exist!

    So on balance it's still wrong, but a lot less wrong, and the end result is positive.

    It is also fairly rapid I assume, so no heavy cost associated in the processing of the shader.

    My only thoughts are how wheel blur shaders/models may interface with the technique. I assume this shader acts upon the normals of the model post normal map because the reflection map itself is influenced by the normal map?

    Ie, on the Gallardo I recently updated, it should work elegantly as the blur models appear and not appear broken as it goes from one model with 3d spokes to the normal mapped spokes?


  7. It compares the reflection vector output by the normal shader, so as long as the bumpmap is working correctly, and I use the right R vector, then it should behave right, yeah. I haven't tried it with a bumpmap shader yet though.

    Did this partly to avoid blur models for the RX7; I'm still thinking about how to make them look right, cause the usual 'plane with a radial blur texture' looks... thin? So this was an exercise in making the 'stationary' model look more correct and get some idea of what the blur shader needs to accomplish.

    The big thing with this shader is that I can turn reflections way up without harming the illusion... before, stray reflections were just making it look unreal, now it can have quite bright reflections (which is true to the gunmetal painted material) without reflecting strange stuff.
  8. Well technically reflect = 1 is required if you are using lacquered alloys, as it's the only way to achieve the mirror properties at a glancing angle.

    I generally use a gradient map on the inside of the wheel to tone down the reflection strength, from dark ish grey to black quite quickly. You can also do that on the spoke edges a bit to tone down the reflection strength... in theory you will rarely get at an angle where you can see bright sky in the edges of spokes in real life (ie, glancing angles)...

    So you could already minimise the impact of the problem with a control map I suppose...

    Since you generally only see a wheel from a certain angle then that technique works ok.

    However for your shader you could be looking under the car from the other side and see the sky reflect in the drum of the wheel, which is then more realistic hehe...

    Swings and roundabouts really, but I like this shader idea!

    Not sure I would ever agree with using reflect < 1 for a lacquered glossy surface though... surely you'd have been better authoring a control map to reduce it under 1 where there were unwanted reflections!?