The shader thread?

I'm messing with shaders a bit right now.

Right now I am looking specifically at adding control for specular to the existing reflect shader... on Deyan's Murcielago the unified wheel/tyre texturing poses some problems.

I have to control reflection strength with an alpha map, so use the old trick of adding a syntax in the reflection shader so if we define reflection = -1, the baseCol.a is used to control reflection strength.

ambientColor=FresnelMix(ambientColor,envColor.rgb,(Kr>0?Kr:-Kr*baseCol.a),fresnel);


The problem now is that I have no spare texture slot for specular/shininess control.

So I have added this little fragment of code (from the bump speca shader)

Ks=baseCol*Ks;

This now allows the colouring of the outside of the tyre in the diffuse (rgb) channels, to do some work.



However, because the tyre is still dark in the diffuse texture (near black as it is a tyre), it doesn't have much effect on it's own.

I need to somehow increase the brightness of the texture so Racer pumps up the specular we see.

So I added a *5 multiplier to the Ks as you can see in the image attached.

shader_01.gif




Now what I don't understand is why the two images look different.

First case:
Ks in car.shd is 8, while Ks = baseCol * Ks * 5 essentially gives us Ks = baseCol * 40

Second case:
Ks in car.shd is 40, while Ks = baseCol * Ks essentially gives us Ks = baseCol * 40


Now, I don't get why they look different. Ks is meant to control the size of the specular too, but in either case they both calculate out to a peak shininess of 40, because the baseCol lookup isn't changing.
The specular settings remain the same.

It appears that multiplying by 5 in the shader means the specular level is pumped up 5x, while the shininess (size of the specular) is retained at 8 in the car.shd...

That is the effect I wanted to achieve, pumping up the actual output of the specular blob, while keeping it soft at a value of 8, but it seems un-intuitive/wrong because the value that really needs bumping up is the specular value, not shininess? (though the specular being multiplied by 5x (2.5 2.5 2.5) looked awful)

Am I missing something obvious here?




Ideally I'd like to control reflection amount, specular AND shininess using one shader here...

Probably using rgb.a for diffuse.reflection strength, and then another 3 channel texture for spec/shine and leaving another slot free for something else (perhaps transparrency?)

Specular/shininess maps add so much to these kinds of materials, so it is a shame that they haven't really been considered in the default shaders very much. I think they should almost be defaults in all materials that err away from being generally reflective (ie, using the envmap)


Bodging in the code I have for the Lambo works quite nicely in this case, but it's obviously not ideal to use the diffuse channel to control specular in this way.



Hmmmm

Dave
 
FYI thats on a AMD PhenomX6 1055t 8GB ram, GF 460 1GB @1280x1024 (gotto get me a decent widescreen monitor one of these days).

If the blur doesn't hurt your FPS, I'd guess you have a fairly high-end modern GPU or two, where the memory bus isn't a bottleneck compared to lowlier older cards? As you said shadowmapping is lots of large texture movements, so the more lower spec & older the GPU the more pronounced the blurring hit would be.

there must be a better way of blurring the shadow edges, not that I understand how it's done now.
Could you not just downsample then upsample the shadow texturemap? If i take a greyscale 1024x1024 image in photoshop, change the image to 102x102, then to 1024x1024 again, it is blurred fairly well. I'm guessing that as mipmapping uses similar techniques and it is done in hardware fast almost free, something similar could be used to do the blur?
 
FYI thats on a AMD PhenomX6 1055t 8GB ram, GF 460 1GB @1280x1024 (gotto get me a decent widescreen monitor one of these days).

If the blur doesn't hurt your FPS, I'd guess you have a fairly high-end modern GPU or two, where the memory bus isn't a bottleneck compared to lowlier older cards? As you said shadowmapping is lots of large texture movements, so the more lower spec & older the GPU the more pronounced the blurring hit would be.

there must be a better way of blurring the shadow edges, not that I understand how it's done now.
Could you not just downsample then upsample the shadow texturemap? If i take a greyscale 1024x1024 image in photoshop, change the image to 102x102, then to 1024x1024 again, it is blurred fairly well. I'm guessing that as mipmapping uses similar techniques and it is done in hardware fast almost free, something similar could be used to do the blur?


You can't blur shadowmap as normal texture map since they contains depth infor for depth comparison. Simply downscale and upscale them will produce incorrect shadow result. So far what you can do is doing multi-sampling for blurring which is slower but there is not much you can do about it.
 
Personally, I don't even think the blurring of the shadow map adds that much visual quality.

Yes, it looks nice sometimes, wow, lovely... softer edged shadows (perfect for a hazy day)... not so good when it's a sharp sunny day and shadows look all blurry when in real life they should be pin sharp.

Then on a more overcast day, they are not blurry enough.

The current blur profile is almost set up for a hazy sunny day. So it looks ok sometimes, but most of the time it looks worse than it could with either more blur (smaller shadow map size to start with), or no blur and a higher res map (really sunny, not hazy day)



I play without blur now, simply because away from 'photomode' use of Racer, hammering around a track, I honestly don't care about some jaggies here and there. In a replay, crank up the settings by all means, FPS there can be 25fps perhaps, with more effects.

But for realtime use give me fps!


And after all that, if we can get the shadows better with little FPS cost, great... but from my viewpoint Racer looks generally only average mainly because there is no rich content out there... it's nice to have all these super shadows and shaders, but most tracks have very little detail.
Perhaps only Swiss Stroll comes close in adding 'detail everywhere', to the point you start to feel immersed in the environment more than most tracks.

I'd rather pay for more track details and quality, than get better shadows and still have bare barren tracks ala Carlswood.

Dave
 
Personally, I don't even think the blurring of the shadow map adds that much visual quality.

Yes, it looks nice sometimes, wow, lovely... softer edged shadows (perfect for a hazy day)... not so good when it's a sharp sunny day and shadows look all blurry when in real life they should be pin sharp.

Then on a more overcast day, they are not blurry enough.

The current blur profile is almost set up for a hazy sunny day. So it looks ok sometimes, but most of the time it looks worse than it could with either more blur (smaller shadow map size to start with), or no blur and a higher res map (really sunny, not hazy day)



I play without blur now, simply because away from 'photomode' use of Racer, hammering around a track, I honestly don't care about some jaggies here and there. In a replay, crank up the settings by all means, FPS there can be 25fps perhaps, with more effects.

But for realtime use give me fps!


but from my viewpoint Racer looks generally only average mainly because there is no rich content out there..

Agreed. On Carlswood, you can get quite good FPS with high quality blurred shadows (blurring with high quality parameters) but on other tracks that have more detail there is quite a big performance hit.

I don't know, how Ruud tests Racer performance, but I sure hope he uses something other than this dirt-old Carlswood.
And also, I think that live environment mapping should be standard way to go with modern PC setups.

Currently, I think the biggest FPS eaters are the live mapping and shadow mapping, so these should be optimised as much as possible...
 
Live mapping here, running at 1 side per frame (so 6 frames for a full cube update), seems fine during play. You can tell if you look for it, but again, when racing or driving around, it just looks totally seamless and fine.

I think Ruud will be using some good quality tracks. Carlswood is just the benchmark for us because it's the default track for many I guess. We need a new default track perhaps :D

Dave
 
Definitely, Carlswood as-is is looking rather old, maybe that explains the lighting in it, it's in it's twilight years LOL. I never really like Carlswood to drive anyway, too poky, more like a gokart track. My opinion.

Yes, we need a new default but when ARE you going to finish it?
 
Yep, I don't like carlswood much either. The next default track should definitely have a drag strip (preferably longer to test top speed), possibly some sort of cone licence test area, maybe a skid pad too. It needs to be good for testing all sorts and still be fun for online play imo.
 
Yep, I don't like carlswood much either. The next default track should definitely have a drag strip (preferably longer to test top speed), possibly some sort of cone licence test area, maybe a skid pad too. It needs to be good for testing all sorts and still be fun for online play imo.

:D

One of my new tracks is pretty much that. I just need to finish it!

Dave
 
I'd rather pay for more track details and quality, than get better shadows and still have bare barren tracks ala Carlswood.

Hm, not really imo, lights & proper shadows are what makes a scene 'real'. Maybe shadows should be computed in software mode, just to get more GPU power for other things. After that, we would need some shaders like F1/Dirt2/Shift1,2 etc...

We can't wait for others peops here to get their hardware updated & still get 5 years old shaders which are far too much too basic for our crazy ideas, like real clouds, water, flags & all the stuff !

And also, I think that live environment mapping should be standard way to go with modern PC setups.

Currently, I think the biggest FPS eaters are the live mapping and shadow mapping, so these should be optimised as much as possible...

+1, env live mapping with animated objects is the way to go by default.

Shadow mapping needs to go in software mode, as we normally do when rendering a scene in 3DS Max, Maya, Blender or SoftImage with lights...

Forget about the hardware mode, it's bad for our fps...theoretically we shall get twice more FPS with proper shadows.

Here's an interesting link about shadow mapping techniques :

http://www.gamedev.net/page/resources/_//feature/fprogramming/shadow-map-aliasing-r2376
 
Shadow mapping needs to go in software mode, as we normally do when rendering a scene in 3DS Max, Maya, Blender or SoftImage with lights...

Forget about the hardware mode, it's bad for our fps...theoretically we shall get twice more FPS with proper shadows.

What? :D

Since we have dynamic time of day with dynamic shadows, there's just no way the shadows can be calculated on CPU per frame.
The FPS would be even worse.

After all, the GPU is really good at these kinds of things.

Optimizations are what we need! Luckily with shaders, we can also collaborate and opimize the shaders, provided that we have the knowledge.
 
You can't blur shadowmap as normal texture map since they contains depth infor for depth comparison. Simply downscale and upscale them will produce incorrect shadow result. So far what you can do is doing multi-sampling for blurring which is slower but there is not much you can do about it.

You can't use them for depth comparison but you could use them for blurring...
Grab depth info from full scale shadow map -> most accurate
Grab soft info from downscaled map -> softer transitions
uUIYI.png

d -> depth, s -> soft. If you calculate s/d, you get something like the lower plot.

When depth==soft (or soft is closer to the light source, as marked 'ignore'), you use 100% shadow opacity. If depth!= soft, use the difference to fade shadow opacity. (as with 'fade')
The exact formula, I'm not sure of... maybe bicubic on the smooth one? But I think it could be tweaked to take care of edges more efficiently, without multisampling on every screen-space pixel (downscaling texture should only need to multisample on each of the downsized texture's pixels I guess?).

When you do it like this, to get softer shadows you just have to tweak the mipmap level used for soft map, I guess? Bicubic sampling from the original would give sharpest shadows, while a very low-res one would give softest shadows.
 
What is 'depth' in this case? Is it the distance from the pixel casting the shadow to the shadow pixel being cast; or is it the distance from the light source to the shadow pixel?

One shadowing issue at present is along fence objects, treelines and such, where the shadow gets blurred along the points where the shadow meets the object, and you have a bright line of unshadowed area that looks wrong, makes objects appear to be floating until you get close to them.
the amount shadow blurring needs to be a function of the distance between the pixel casting the shadow & the pixel cast as the shadow.

Imagine a sundial, at the base of the sundial's gnomon the shadow is very sharp, the sharpness decreasing with distance from the gnomon along the sundial's face.
 
What is 'depth' in this case? Is it the distance from the pixel casting the shadow to the shadow pixel being cast; or is it the distance from the light source to the shadow pixel?

One shadowing issue at present is along fence objects, treelines and such, where the shadow gets blurred along the points where the shadow meets the object, and you have a bright line of unshadowed area that looks wrong, makes objects appear to be floating until you get close to them.

Yeah, the problem there is thin objects. The shadows are offset a bit so they never break through the sunlit side of objects due to rounding (between pixels on an angled object - it causes the ripple patterns). If something's just a flat polygon, it doesn't have any depth and it leaves a bit of a gap.
 
If the shadow blur amount were a function of distance as above, it wouldn't need to be offset. My point is the current blurring is more a fudge, which then requires another fudge to fix the first fudge. I found if I put a treeline modified to about 1/4 height close behind the real treeline it's shadow overlaps with the real treeline one, and the problem disappears mostly. Not totally, there can be parallax issues due to the distance between the treelines causing weirdness at the ends of objects, and it increases poly count, creates extra objects that need shadowing, that chew clock cycles themselves etc.
Fudge should be eaten not played with.
 
I thought the whole benefit of this new fancy shadow system (away from the initial implements of CSM), was that we got the blurring of shadows as distance increased from the caster?

I think this other issue David, is the one Stereo mentions, which is just that the shadow will always leave a tiny gap under certain conditions. It even does it in high-end renderers with shadow mapping sometimes... just a nature of the algorithm and method I guess...

Dave
 
I had a look at the shadows cast on Broken Springs, the last version I played with I put some trees around it, along with the barriers & carpark itself, there's a few varied shadows to analyse. You are correct, the shadows blur does seem to relate to distance from object. They still don't look quite right though. I don't care much they look good enough, EXCEPT for the shadow/object edge issue. I'll fight for that to be resolved, it really is a glaring bug. pun intended
 
With 3DS Max shadow map issues in this regard, the solution is often to model differently.

You can usually overcome these issues with a different approach. I've noticed them less for example, the more 'noisy' my scenes are. That includes bits of random grass, lumps and bumps, trees, textures on the offending areas etc.
Some1's test scene will show up all the problems right away, but get on a track with lots of fuzzy details (ie, realistic, lots going on everywhere you look), and spotting these accuracy issues becomes much harder, and also what issues there are kind of blend in with the patina of 'realism' you get :D

Dave
 
I try to make a cg shader for a dacia 1300,but:
Xp8AW.png

What's the problem?I'm using dacia 1300 from tracciontrasera.
Windows shader:
Code:
vf_glass
{
  ; Just reflection
  vertex_shader
  {
    file=dyn_standard_reflect_window_v.cg
  }
  fragment_shader
  {
    file=dyn_standard_reflect_window_f.cg
  }
}
Body shader:
Code:
vf_reflect_bump
{
  ; Just reflection
  vertex_shader
  {
    file=dyn_standard_reflect_v.cg
  }
  fragment_shader
  {
    file=dyn_standard_reflect_f.cg
  }
}
 
That's only half the shader - the other half goes with each material, and is something like
Code:
shader_paint[b]~vf_bumpreflect[/b]
{
  compression=0
  reflect=0.6
  specular=.05 .05 .05
  shininess=6
  tangents=1
  layer0
  {
    map=body.tga
  }
  layer1
  {
    map=body_normal.tga
    mode=linear
  }
  layer2
  {
    map=$trackenvmap
  }
}
The bolded part tells it to link to the part you mentioned, and to figure out what's wrong I'd need to see the whole thing.
 

Latest News

Are you buying car setups?

  • Yes

  • No


Results are only viewable after voting.
Back
Top