1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice
Like RaceDepartment on Facebook.

Better Wheel Blur through Bumpmapping

Discussion in 'Racer' started by Stereo, Jan 11, 2010.

  1. Stereo

    Stereo
    Premium Member

    I was fiddling around with editing the normals on a model to help the light play off a spinning wheel. It picks up the specular fine, but it's a pain to work with and apparently can't be done in Blender.

    So I looked through how bumpmaps work, and made one that's physically impossible as a flat surface, to produce the effect I wanted.

    This texture, used as a bumpmap, represents a 45 degree slope at every point on the plane.
    [​IMG]

    Interestingly, the way this texture is rotated changes the direction of the slope. The way it is now, or a 180 degree rotation, are clockwise/counterclockwise slopes around the centre. Rotating it 90 degrees in either direction produces inward/outward slopes. Other angles end up somewhere in between.

    [​IMG]
    This, for example, is the counterclockwise slope. Since it's angled toward the light at the top right, it's brighter, and it's dimmer on the bottom left since it's facing away from the light. The object it's mapped to is flat - the "point" at the centre is entirely a result of the texture.

    This is useful, because on a blurred wheel, you effectively have the angled parts of the spokes spreading out into a flat surface, that reflects as if it were at an angle. (I note that brushed metal can also have reflections like this, so maybe this has other applications).

    In order to use the effect ingame, I split the wheel into a few layers. The first is plain and simple - flat surfaces. The tire and outer rim of the wheel, as well as the face of the spokes, are flat.
    [​IMG]
    A radial blur in the GIMP produces the texture.

    Slightly behind that (at roughly the average depth of the sides of the spokes) is the interesting layer. It's mapped to another circular flat surface.
    [​IMG]
    (this one might be hard to see on the forum, since it's light gray and mostly transparent)
    This is a picture of the clockwise-facing polygons of the wheel, flattened out to face the viewer more directly (mostly a matter of making them wider), and blurred similarly to the previous image. This layer gets the bumpmapping from earlier applied - there are actually a pair of these, one clockwise and one counterclockwise, representing the corresponding sides of the spokes. When they catch the light, as in the earlier image of the composite wheel, they light up at an angle from the surface's normals, so you get the proper lighting on the spokes even though they're mapped to a flat object.

    Behind these would be the brakes, axle, etc.. - which I didn't model.

    The shaders are pretty easy - standard_f/v for the regular surfaces, bump_f/v for the angled ones. I haven't tried with reflections but I expect they would work.

    I hope this makes sense, and is useful to someone.

    (and then there was more)
    To produce the radial gradient, there are 4 compass colours - +red, +green, -red, -green.
    Since the bumpmap is expected to be normalized, step 1 is to decide the angle you want (eg. 45 degrees). Take sin/cosine of that angle -> .707/.707. Assuming 0 degrees to be normal (and 90 at a right angle to that), blue is cos and red/green are sin.
    rgb triplets for the 4 points are:
    +red: (128+128*sin(a), 128, 128+128*cos(a)) = (219, 128, 219)
    +green: (128, 128+128*sin(a), 128+128*cos(a)) = (128, 219, 219)
    -red: (128-128*sin(a), 128, 128+128*cos(a)) = (36, 128, 219)
    -green: (128, 128-128*sin(a), 128+128*cos(a)) = (128, 36, 219)
    Once you have these you can just make a gradient with them in that order, counterclockwise. For example, in the image above, I have +red pointing down, then +green pointing right, -red pointing up, -green pointing left.
    If you switch them (clockwise) you end up with conflicting directions, and ingame the specular will rotate twice as fast as the wheel, instead of staying still. Easy to fix though, just mirror the texture (if your object is mapped mirrored, you'd need to do this in reverse to compensate, horizontal mirror works fine).
    The direction of +red determines what angle to the surface the normals take (I think it's down - clockwise, right - inward, up - counterclockwise, left - outward but I'm not sure).


    It's probably possible to combine the transparency of the various spoke parts with the "flat" bumpmap colour (128, 128, 255) to produce a composite bumpmap that handles more than one surface (and would give a single reflection at any point on the wheel instead of blending them ingame) but I don't know whether that's a good idea.


    I also had a question. What are the blur models (and corresponding speed to switch) called in car.ini? I couldn't find any reference to it on racer.nl.
     
  2. That's a nice idea, I tried a similar thing a while ago but without the bumpmap (the first set of low speed blur rims using the regular models but with the blur textures). Blurred wheels are a huge problem, I tried a lot of ideas without anything really looking good. I still think maybe a radial blur shader of some kind might be the way to go, would save a lot of work making blur models.

    Also, you're right, that would do brushed metal nicely I think. I tried a few ideas for diamond cut rims without much luck, was thinking a few weeks back that bumpmapping might work for them (my idea was a ribbed bump texture tiled over them, scaled so the ribs were small). Your idea will probably be better once you take mipmapping and aliasing into account :).

    Also, not to go OT but you gave me an idea, I just tried a bumpmap on my 3d grass (just a 32x32px texture filled with RGB 128, 0, 128 - I think that's right to get normals pointing straight upward?), seems to work great with diffuse lighting so far, matches the ground well - I owe you the credit for that idea. Sure, there's probably a more efficient way to rotate the normals to point upwards in a vert shader (run the normals through a matrix?), but I'm really not good at the maths stuff.

    Yep, use this code (for some reason I used to need to put the X offset in, I'm not sure if it's still needed - bug?):

    Code:
      model
      {
        file=wheel_rr.dof
        offset
        {
        x=0
        }
      }
       model2
       {
          file=wheel_rr_blur01.dof
          velocity=16
    }
     model3
       {
          file=wheel_rr_blur02.dof
          velocity=36
      }
    }
     
  3. Stereo

    Stereo
    Premium Member

    128, 0, 128 would indeed be either straight up or down on a vertical model with the texture facing "upright" (I'm not entirely familiar with the coordinates used by Racer, maybe that's why I had to rotate the image a few times to get it working right).

    Thanks for the blur code, I didn't need the x-offset. Now I just need to tweak the 2 models so they match up a lot more closely :p

    If Ruud is watching, can we get some more parameters available in shaders? Swapping from low-blur to high-blur textures on a single model could be done a lot more smoothly (interpolate between the 2 textures based on speed instead of cutting to a new model at 30km/h), but I don't think there's a way to get wheel speed into a shader.
     
  4. I just tried the bump map idea on a set of rims, problem is the actual bump lighting is rotating with the rim, hence it looks fine when the car spawns but looks a mess as soon as the wheels start turning?

    Is this a bug at my end or am I doing something wrong? Definitely got tangents=1 in the shader, dried both the standard and dyn_standard bump shaders too, same result, shading seems static and rotates with the wheel? :flat:
     
  5. Stereo

    Stereo
    Premium Member

    I'm not certain, but my shader is about like this:
    Code:
    vf_bump
    {
      vertex_shader
      {
        file=dyn_standard_bump_v.cg
      }
      fragment_shader
      {
        file=dyn_standard_bump_f.cg
      }
      ambient=0.8 0.8 0.8
    }
    
    shader_180sxstockwhlblurb~vf_bump
    {
      reflect=0.2
      tangents=1
      layer0
      {
        shininess=20
        specular=.6 .6 .6
        map=blurb20.tga
        blendfunc=src_alpha one_minus_src_alpha
        alphafunc=gequal 10
      }
      layer1
      {
        map=wheelgradient2.tga
      }
    }
    reflect= and blendfunc/alphafunc= shouldn't be necessary for the bump aspect to work right though.

    I think the standard_ shaders aren't meant for moving objects and the dyn_standard_ are, just a matter of allowing for object rotation or not.

    And like I said, worth a try mirroring the bump texture, if it's mapped the wrong way the horizontal and vertical components don't agree on direction and it ends up rotating.
     
  6. Stereo: That's weird, looks like it's working after I mirrored the image. Remembering now though, doesn't Zmod tend to apply the UV maps mirrored? That could be the reason, my wheel was probably mapped in a mirror image to yours.

    I'll have another try later and see how it looks, just trying to get a similar gradient to yours (but reversed) in Gimp :)
     
  7. Too bad you're gone Tiberius !
    Great work Stereo, you doing good ! Thx :)

    So, it's true it's really tough to make it look right, in Shift it's the same story.
    I've tried yesterday my first blurred wheel, quickly done & it's looking better than having none of them, so I'm happy right now !

    Generally talking, it's worth to implement them, they really enhance the car realism a lot, so I'll do the 2nd blur wheel just with a plane/ cylinder cap closed mesh & align it to the rim border. The first blur wheel I've created is a mix of both...

    Also, been trying to bumpmap the whole, but I still need some time for shader/material tweaking...
     
  8. Welcome back Bruce, I knew you couldn't stay away. ;)
    I completely agree about the radial-blur shader there's no reason we shouldn't be able to find one somewhere.
    Make sure you have your Racer shader set this way, we have a new parameter since you were here....

    Code:
    ;---------------------------------
    shader_tireb3~vf_tire
    {
        layer0
        {
            map=wheelb3.tga
            shininess=8
            ambient=.3 .3 .3
            diffuse=.2 .2 .2
            specular=.3 .3 .3
        }
        layer1
        {
            map=wheelb3n.tga
            mode=linear                <---------------------- NEW!
        }
    }
    Alex Forbin
     
  9. KS95

    KS95
    RACER Moderator

    Eh Alex, sorry to disappoint you but he posted that over a year ago... :(
     
  10. Hehe, doh...

    I also thought he was back :)
     
  11. What's the matter with Quadcore? Does he just search for old topics to bump and talk to people that aren't there?
    Hmm, time to call the nice men in white coats.

    Alex Forbin
     
  12. LoL guys !

    Bump it...

    Was wondering, is someone blurring the wheel tread as well ? idk really...seems logic to me !
    Apart from that, I'm happy with my first results, got the 2 blurred wheel for each side.

    I'll definitely bring some normal map to them, just to add more contrast as other new games do as well, my first test didn't look good with it, something wrong somewhere in my alpha textures.
     
  13. I don't usually bother with the tread since it's difficult to see well anyway. If it's an open wheel car however it would be worth doing.

    Alex Forbin
     
  14. Assuming we get proper scene blur back, like we did pre CSM betas (then there is no real need for blurred wheel textures full stop.

    I'm not sure if we will see a return to it or not. Imo, it was really nice to have as it added a great deal of realism. Even if it only made a return for replays then it would be plenty since it's rare you see the wheels when driving in realtime anyway.

    Hmmm

    Dave
     
  15. Didn't know Dave...was also thinking the blur effect could be hard-coded by Ruud/Mitch, so it's listening to the wheel rotation velocity & then adds an overall after-effect somehow, but that doesn't seem to be the 'standard' in game development.

    Anyways, they look amazing, I'll post later some pictures...:)

    I'll place on the 2nd blur wheel, 2 alpha textured 3D pieces (only the spokes + an added cylinder aligning perfectly the curvature of the spokes) & for sure the original wheel. For the 1st blur wheel, I've only used 1 alpha piece (the aligned cylinder) + the original wheel (default).

    Also, I've blurred the brake disk in 2 levels (radial blur in PS), one blurred at 10 & the 2nd one at 40; I'll go also for a blurred tread just to make things perfect. I mean, if you have a car front wheel camera, you'll see the details, so yeah I got 2 wheel cams, 1 in the front & one in the back.

    Talking about the blur wheel, when braking, the glowing brakes should project the emitted light they produce, so I hope to see somehow a fix from Ruud/Mitch.

    idk maybe we could decide the color & alpha in the car projected lights section (lights {}) in a new slot/layer. I bet they could be easily fixed in a custom script where you listen the car velocity & trigger a dof (a alpha plane) related to the car position, hm not ideal because it's independent from the terrain curvature, so overlapping 3D will occur, that's why I thought we need all debug + all ini files + logical functions that handle as input those variables in a freshly new script editor with auto-detection !?
     
  16. As promised, here's some picture :

    [​IMG]

    [​IMG]

    [​IMG]

    Note, I haven't integrate the idea described before...
    Everything works like expected, 3 wheels models, less than 10 textures + lots of struggle !! :D
     
  17. wow looks nice! and that track too, when it will be available? :D
     
  18. Thanks BVSX, I'll put some more work & release the update for my track soon !
    The car needs some physical tweaks, so I need more time to be happy enough to release it...Don't want to release anything which isn't complete & fully featured.
     
  19. yeah thats the spirit! Racer needs only proper cars and tracks :)
     
  20. Good point, but ultimately the author needs to use discretion.

    I'd rather that be done using scene motion blur like we had pre-csm, perhaps only in replays at 25fps, and then save myself fps and memory for things I'll likely see more of the time from the main cameras (behind, in-cockpit, and bonnet views), say terrains, trees, road etc...

    It's all up to the author really, thats the great thing. I'd prefer to spend my time/gpu power on richness in the environment, than extra details in the tyres that you can see in real-time (great for driving around looking at your tyre in real-time (about all Racer is good for sometimes right now hehe), but a bit of a waste in reality once we actually start driving and racing etc :D )


    Hmmm

    Dave