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
 
Firstly, It blurs the shadow in texture space rather than in screen space so there is no flickering or light bleeding when you rotate the camera, and it won't need an extra FBO for shadow so we may get some performance boost if Ruud is kindly enough to change the code a little bit and disable the shadow FBO.(Current deferred shadow technique can not generate accurate bloom effect as shadow FBO is not taken into account during the bright pass)

It can also produce some nice fake penumbra and if you have a decent GPU you can even use PCSS(a little bit advanced than PCF, generates real penumbra, so shadow blurs less near shadow caster, though not yet implemented)

Hope that helped

Nice stuff. :) What did you mean exactly with 'change the code a little bit and disable the shadow FBO'? Where could we drop a shadow FBO? I currently need to split diffuse & ambient lighting into 2 MRT buffers to do proper shadowed lighting in the postprocess filter (fs_filter1).
 
Hmmm, that's what I meaned. Using PCF so only one MRT is needed. :) (not dropping any FBO,sorry for my misunderstood, ambient and diffuse are attached to the same FBO right?) Split ambient and diffuse caused some problem for the HDR as only ambient color is passed to the bright filter~
 
Hmmm, that's what I meaned. Using PCF so only one MRT is needed. :) (not dropping any FBO,sorry for my misunderstood, ambient and diffuse are attached to the same FBO right?) Split ambient and diffuse caused some problem for the HDR as only ambient color is passed to the bright filter~

It's 2 textures, not really sure if it's 1 FBO or not actually. Anyway, the layout:
MRT1: shadowed RGB, shadowFactor in A (RGB=ambient/reflection)
MRT2: lit RGB, A unused (RGB=diffuse, specular)

So I can't really scrap 1 FBO, unless you take the bad approach of shadowing through darkening colors, but that would bring specular/diffuse back, only darker. I like it better this way, and the forward seems 4 MRT's anyway (storing normals perhaps for SSAO in the future, and more like pixel velocity or such).

Currently looking into the DrawBuffers2 OpenGL extension, which seems to provide separate blending options for each MRT. Still, it seems you need to blend both, so where to store shadowFactor then... (MRT3?).
 
It's 2 textures, not really sure if it's 1 FBO or not actually. Anyway, the layout:
MRT1: shadowed RGB, shadowFactor in A (RGB=ambient/reflection)
MRT2: lit RGB, A unused (RGB=diffuse, specular)

So I can't really scrap 1 FBO, unless you take the bad approach of shadowing through darkening colors, but that would bring specular/diffuse back, only darker. I like it better this way, and the forward seems 4 MRT's anyway (storing normals perhaps for SSAO in the future, and more like pixel velocity or such).

Currently looking into the DrawBuffers2 OpenGL extension, which seems to provide separate blending options for each MRT. Still, it seems you need to blend both, so where to store shadowFactor then... (MRT3?).

I looked into the video memory with gDebugger, both MRT1 and MRT2 are attached to the same FBO so yes, no scraping any FBO.

Then the bright pass filter for HDR should sample both the MRT1 and MRT2 in order to get the proper result, instead of just sample the MRT1 as what it does now. But this means one extra texture sampling for the fragment shader, and both MRT1 and MRT2 are 16-bit texture, probably wasting some bandwidth and fillrate here? Currently, the bright pass works good when CSM is disabled(which means 1 MRT, both shadowed RGB and lit RGB are taken into account)

Take a look at the flow charts below:
1. current HDR pipeline (deferred shadowing)
1.jpg


2. optimal HDR pipeline (forward rendering)
2.jpg



SSAO is still to be considered expensive and it will also cause shadow bleeding around thin objects(like Burnout paradise PC version)
 
P.S. I tried tex2D(sampler2D tex , float3 sz ) in the shadow shader to get Hardware shadow map, but not working. Maybe should set the right glTexParameteri for the shadow texture(link) . If it can be implemented, hardward shadow with bilinear filter enabled can give a free 2x2 PCF filter in one shadow map sampling.
 
Not sure whether a single RT with PCF blur would look better than postprocessed shadow blur. Also, this means you need to blur while drawing objects, which means overdraw is bad for performance. Doing it in post might be faster.

I tried adding:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);

to the depthmap texture but this only messed up the shadow function currently. Should something change in the shaders then as well? (shadow2Dproj instead of tex2Dproj?).

Mitch will be back on Monday so perhaps he can work it out. I am using your shadow shaders but although the smoothing is better, the transition between the shadowmap splits is quite noticable. I think I'll leave it up to Mitch to make a mix or something.
 
Oh, I forgot to mention that, the shader should use tex2D(shadowTex, shadowCoord), the shadowCoord should be a float3 instead of float2, where x,y component are the orignal texure coordinate, and the z component should be the compare value with Bias adjusted. So if sets up like that, the tex2D should return a float (based on the depth test result, 0 or 1 if use GL_NEARST, 0~1 if use GL_LINEAR) instead of a float4.

link

And there is smoe issue with LOD handling of the shadowmap renderer. The LOD should based on object's view distance to the screen camera rather than to the light camera.
 
Hm that is better indeed, but I get severe aliasing next to the regular shadowmapping. If you want to have a look, I've uploaded a 0.8.13 preview (without cars/track) at http://www.racer.nl/download/racer0813a.zip (there in a couple of minutes).

I changed the tex2D() in shadowmapping.cg btw:

//float fDepth = tex2D(shadowTex, vSamplePoint).x+smCor[index];
float fDepth = tex2D(shadowTex, float3(vSamplePoint,z)).x+smCor[index]*2.0; // 2.0 just for testing

(might be a data/script/oncar.rex in that download, just remove it; some rain and 'reset car 200')
 
I looked into the shader, there is some slight issue with the mapsize in constans.cg , the hardware comparison works fine. Ruud, did you use:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

when setting up depth texture?
Only with GL_LINEAR can the hardware perform a 2x2 filter in one fetch

And in 0813a there seems only one split of shadow visible instead of 3, was it disabled on purpose? And it always throws out lots of ERR.

Fri Jul 23 01:25:27 (ERR ): [racer/2804] QObjectManager:Release(ref 0) out of range
Fri Jul 23 01:25:27 (ERR ): [racer/2804] QObjectManager:Release(ref 0) out of range




P.S. Ruud, the 0813a's texture flare still has some problem, where the flare's aspect ratio still changes when rotating the camera, which should stay the same. And btw, could you add some other variable to the cg shader like camera FOV and such. I've developed a lens distortion shader which looks great with wide-angle camera, it would be even better if linking with the FOV variable as long-shot lenses d.

I'm even thinking in the future, more post-process effects can add in, like DOF, motion blur , to create a physically based camera system.
 
The texture uses linear filtering yes. I had to change this in shadowmapping.cg:

float fDepth = tex2D(shadowTex, float3(vSamplePoint,z-smCor[index])).x; //+smCor[index];

I still get aliasing artifacts, but due to the -fRadius..+fRadius sampling. I've attached a screenshot. Think I'll release a v0813b nevertheless so you might be able to check. Should be in the sampling; if you just take the first sample and return it's fine (x=-fRadius, y=-fRadius).

Hmmm.

Nice work on the distorting shader. We use pixelmapping for projectors (licensed stuff though). I think GT5 did this. Also, there is some interest in fisheye rendering, hm. :)
 

Attachments

  • screenshot072 copy.jpg
    screenshot072 copy.jpg
    53.4 KB · Views: 266
Hi Ruud,

So the 0813a do have linear filter enabled? Strange it didn't produce filtered shadow...

Anyway, here is the shadow shaders, should be working:cool:

Set shadowMap size in constants.cg to mach your current shadow map size, and
iSqrtSamples controls blur amount now.(use even number equal or greater than 2, 4 should give a fairly good result, too high will slowdown the pipeline)
 

Attachments

  • shadow0813.rar
    3.2 KB · Views: 131
Strange; when I use GL_LINEAR I get just bad filtering, see attachment.

hmmm, could you sent me a racer.exe with GL_LINEAR? I will take a look at it and tweak the shader a bit.

Current shader is trying to emulate the Hardware filtering, which is a bit slower I think, if you want to test if GL_LINEAR is working or not, try comment out these lines:

if (x == -fRadius)
xWeight = 1 - frac(shadowCoord.x * g_vShadowMapSize.x);
else if (x == fRadius)
xWeight = frac(shadowCoord.x * g_vShadowMapSize.x);

if (y == -fRadius)
yWeight = 1 - frac(shadowCoord.y * g_vShadowMapSize.y);
else if (y == fRadius)
yWeight = frac(shadowCoord.y * g_vShadowMapSize.y);


in shadowmap.cg

and try add a glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
to see if it work

reference link




The Z aliasing is caused by setting CSM splitdist0 too large

Try splitdist0=10 to get rid of the artifacts
 
P.S. Ruud, the 0813a's texture flare still has some problem, where the flare's aspect ratio still changes when rotating the camera, which should stay the same. And btw, could you add some other variable to the cg shader like camera FOV and such. I've developed a lens distortion shader which looks great with wide-angle camera, it would be even better if linking with the FOV variable as long-shot lenses d.

I'm even thinking in the future, more post-process effects can add in, like DOF, motion blur , to create a physically based camera system.

I like the idea of improving the FOV and perhaps DOF from that, linking to effects like flares. The current system of flares is still not great, they scale oddly and stuff in different FOV's which makes them just look naff except in stills where they don't change size etc...

Post effects and lens effects are nice, but I'd ONLY want them in replay cameras where specified (an entry for fs_filters in the per-camera definitions in car.ini and track special.ini perhaps? (replay and driving ones defined?! hmmm))... there is nothing worse than over-done effects when driving around with 'eyes' and not 'cameras' :D

Dave
 

Latest News

Are you buying car setups?

  • Yes

  • No


Results are only viewable after voting.
Back
Top