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
 
Ruud, I've just realised something that may be an issue with using that tree shader.

I'm using a large texture atlas so all my broad leaf trees go on one 2048x2048 texture. I can then also mix and match textures for each face of the X, to add variety and avoid that issue of trees that look a bit too symmetrical or samey.
I can get about 16 512x512 textures on that atlas, and as such I can have 16 x 16 tree variations, so in theory, 256 unique trees (although it'll be more like 4 x ash, 4 x sycamore, 2 x beech, 2 x oak, etc etc... :D )

Either way, this streamlines texture loads, and shader loads. I can have one shader and one texture for ALL my broad leaf trees at the road side.

I've been reading often about optimisation and it seems this is the way to go for speed. The trees are numerous and many different types, so it seemed prudent to atlas the textures and unify the shaders into one for all the similar types of tree.


However, the UVW method of calculating for normals doesn't work well with an atlas type lookup.

Is there any other way to detect the tree and shade across it? Perhaps via vertex info?


The effect generally worked nicely here with the full texture size used.

However, I wasn't keen on the viewer position influencing the lighting. If you moved the camera upwards, the tree got lighter (as if you were seeing more of the top of the tree and thus more of the lit part?), since when you drove almost under the tree it became fairly dark, becoming pitch black if you tipped the camera down and looked up at the tree from metres below it.
Then when you moved at a steep angle relative to the planes that stick out towards you, they would get shaded at the extremes and appear darker, and so once again ruining the immersion of the tree by not having an even appearance.

Definitely the right path though, the effect is convincing to add volume to the tree, and nice even lighting, it just needs tinkering with until it reacts nicely :D


Dave
 
1 1 1 1 is probably too bright, but it should be ok at 0.75 rgb values for a light car with a fairly strong metallic (ie, BMW titanium silver for example)

Just make sure your environment is set up nicely too I guess. Carlswood generally feels dark even at midday. Not sure why, probably too little ambient and too high sun intensity value, which then means exposure drops off and the ambient is lost.

I feel it's a bad place to set up materials because of that... not really looked at it properly as to why, but it just seems to be that way. I've not been happy with it for many years (seemed much brighter and lighter 4 or 5 years ago, but it's always so dark, moody and contrasty these days, even at midday it feels like twilight sunset kinda lighting :D )

Dave

Do you know how can I add shadows to this shader ? I don't know why , but when I add the things Mitch told me the shader doesn't work.
 
Is that the metallic flake shader?

Personally I'd pick up the dyn_standard_reflect shader as a starting point, and try instead add the specular 'noise' map into that shader.

However, generally, the effect we see in those screenshots can be had just using dyn_standard_reflect out of the box, just the metallic dots won't be visible in very close screenshots...

If that is important or not for you is another thing :D

For me it wouldn't be a high priority right now. Fancy paint shaders are probably best done, longer term, with BDRF shaders and the like.

Dave
 
Ruud, I've just realised something that may be an issue with using that tree shader.

I'm using a large texture atlas so all my broad leaf trees go on one 2048x2048 texture. I can then also mix and match textures for each face of the X, to add variety and avoid that issue of trees that look a bit too symmetrical or samey.
I can get about 16 512x512 textures on that atlas, and as such I can have 16 x 16 tree variations, so in theory, 256 unique trees (although it'll be more like 4 x ash, 4 x sycamore, 2 x beech, 2 x oak, etc etc... :D )


Ruud, just thinking about this more.

In theory, if there is no workable method using verts etc, would it be possible to pass a variable from the shader to say how chopped up the atlas is, and thus divide down the UVW's appropriately.

Ie, take 0 > 0.25 as 0 > 1 for lighting, 0.25 > 0.5 as 0 > 1 for lighting, etc etc...

Passing either 2, 4 or 8 perhaps, to the shader, so we can have 2x2, 4x4, or 8x8 atlases for trees?

I plan on using 4x4 and 8x8 atlases for the main 3 tree textures...


Thanks

Dave
 
Could possibly be bumpmapped as well for lighting - when I was trying to improve the look of billboarded smoke I just gave the texture a general "sphere" type bumpmap where the top pointed up, left pointed left, etc.

The main problem with that kind of thing is the no-cull reverses the coordinates, so instead of pointing "out" one axis will point "in" and it'll be concave instead of convex. Need to somehow detect that it's rendering the back of polygons and reverse the appropriate (green?) texture normalmap.

I've finally got an opportunity to copy my old Racer folders to my new desktop, so I should be able to resume work on some of this stuff that got lost:tongue: If I can find it I'll post some examples up.
 
I tried the normal mapping technique.

It works ok, even with culling, iirc, the other side worked as expected...

Generally I really really liked it. However, it didn't work so well with the X type tree as the interfering object was lit via the normal map on the perpendicular, so it's shading just clashed with the facing polygon.

I guess it's also costly with video memory having normal maps.

If you could 'theoretically' apply a generic 'sphere' normal map to the tree from the view direction, that lit all fragments on that object according to just that spheres normals, then that would work... not sure how you'd even do that though :D

Either way, it does need to be fast, and Ruud's method does seem fast and effective, it just needs polishing for now I think :D

Dave
 
I haven't really fooled with tracks so I don't know what object coordinates are available. Can trees' coordinates be set with the base of the trunk at (0,0,0) or do they use world coordinates?

If you could put the "cross" of the X along an axis, you could interpolate between the "pointing at the camera" vector (opposite of the camera's, which is definitely available to shaders) and the normal vector, so the branches far out are closer to using the normal map, and the trunk is facing the player.


Or just set up the normal map so the trunk is all "up", which isn't ideal either. Hmm.
 
lots_going_on_01.jpg


I posted this in the pictures thread, but thought it was nice to put here too.

All shaders are out of the box here.

Just interesting how solid everything is now.

No weird issues with shadows or transparencies or ordering etc, good mix of bumps, specs, reflections, shadow casters etc etc...

Everything is just working these days. It's really nice to just author stuff and know it's going to "work"


Nice work Ruud, we are finally getting to a place where we just need to get our heads down and make things, rather than fight with a moving target :D

Dave
 
Tibs Jaguar, I had problems with it long ago so from the comments I got it out and hacked the shaders to get the following images. I'll work over the shaders a bit more and if it's ok to post an abandoned work, I will.

tibs_jag1.jpgtibs_jag.jpg

Camsinny,
Could you post the shader code as .txt files, sure would make it easier to use!
 
In a situation like that you're probably better off simulating leather with just soft specular rather than going with a bump map. It's far too low rez for the application.
Steering wheel looks good but the rest is a bit over the top...exterior looks good though the fresnel might need tweaking. A good start though :)
 
I don't get what is wrong with the default fresnel values for car paints.

My M3 above is using them and generally looks ok. I admit I want to work at them, but not until I'm happy that my environment is faithful enough to then judge the materials from (ie, reflections appearance is based on your scene, as much as the fresnel coefficients!)

Tweaks should only be fairly small. The default values used are probably 90% of the way there for car paint.


As for that leather, yeah, I agree with Cam. Normal maps are great where there really are big topology changes that would case significant real shading, ie, tyre tread patterns, but for the most part they should be avoided for materials that are as good as smooth to the touch that you never get significantly close to.
Also see them as useful for surface details, rather than surface texture. Panel lines, locks, creases, then normal maps are good...

That Jaguar is really nice. I think all it needs is to use the generic out of the box shaders. The specular flake shader *looks* nice up-close, but in most screenshots or videos it just looked like a normal specular blob any way.

:D

Dave
 
lots_going_on_01.jpg


I posted this in the pictures thread, but thought it was nice to put here too.

All shaders are out of the box here.

Just interesting how solid everything is now.

No weird issues with shadows or transparencies or ordering etc, good mix of bumps, specs, reflections, shadow casters etc etc...

Everything is just working these days. It's really nice to just author stuff and know it's going to "work"


Nice work Ruud, we are finally getting to a place where we just need to get our heads down and make things, rather than fight with a moving target :D

Dave

Dave, that looks fantastic! I can't get the standard shaders to make metallic looking paint like that. Could you post the paint shader (car.shd) and settings you are using?

Alex Forbin
 
vf_reflect
{
vertex_shader
{
file=dyn_standard_reflect_v.cg
}
fragment_shader
{
file=dyn_standard_reflect_f.cg
}
}


shader_m3gloss~vf_reflect
{
ambient=1 1 1 1
diffuse=1 1 1 1
compression=0
reflect=1
specular=0.05 0.3 0.5 1
shininess=32

layer0
{
map=m3_01.tga
}
layer1
{
map=$trackenvmap
}
}


The screenie there is with the Mystic Blue Metallic skin, not sure if you can get a hold of that, or have it etc.

The rgb value of the diffuse base between the side glass and the door handle, is 27, 45, 75, to get an idea of the darkness.
I set ambient to the same as diffuse, but as you noted in the past, that might want to be different as not all materials have equal diffuse/ambient response :D
You could tint that a purple for example... but of course with some older car updates one shader covers lots of materials, so you might get a purple tinted numberplate :D


The specular as you can see is a bluer tint of blue than the base colour, which gives it some punch and makes it stand out where the sun is managing to hit the car and generate a specular response.

Then the sharp reflection of the sun in the envmap is giving the sharp specular dot on the rear wheel arch...

That is why ideally, reflection=1 is set, since lacquer is a mirror at glancing angles, and then use fresnel (defaults here), to get the right response of reflection.


As said though, fresnel perhaps isn't perfect, and is probably different from paint to paint. BUT, environment is everything... having trees and shade and a mix of things to reflect gives the object reflecting those things more depth.

The garage track is a nice place to check fresnel too I think, because it avoids bringing too many variables into the mix.

That said, the emission values of the garage lights may be questionable etc etc, but I think it's a good place to gauge things a bit more. Perhaps a touch less reflective strength straight on, but generally that is probably the only tweak it needs for paint?!


I know things still are not perfect, but Ruud has given us a great palette to work from, and I think good results are really possible now, we just need to re-discover the right or ideal settings :D


That said, using my shader values above on a flat material (no baked lighting or a reflection strength control map), does take a huge amount away from the quality look... imo, we really need to be unwrapping and baking AO still, and controlling reflections in panel gaps etc with those maps :D

Dave
 
I haven't really fooled with tracks so I don't know what object coordinates are available. Can trees' coordinates be set with the base of the trunk at (0,0,0) or do they use world coordinates?

As you want loads of X-trees painted in a single DOF batch draw, you can't just get a center position from each tree. That's why I use the UV coords. So now I trace a ray from camera to vertex position, use that to make a basis for the tree (up=(0,1,0), forward=eye_to_vertex, left=cross(up,fwd) ) and rotate the generated normal (for each pixel) into the tree orientation. That orientation then is a billboard really, and I transform the normal according to that billboard (=tree matrix).

The normal generation is easy, a diamond shape really: U=0..1 makes n.x=-1..1, V=0..1 makes n.y=-1..1. Could do spherical with acos() perhaps but you probably won't notice the difference (and it might be faster to avoid using acos()). Those normals can be scaled somewhat, since, as Dave found out, they are a bit unsubtle and quicky leave nothing to be seen. It would be like adding some lighting falling through the trees (sort of ambient light).

On texture atlases; 2 ways perhaps to do this. 1st is to send 'scale=...' to the shader (which is already being passed if you define it with 'uniform float scale') which would indicate the amount of atlas (for example, a 4x4 atlas would use scale=4 or scale=0.25).
2nd is to just use ddx() on the texcoords to determine the direction. I have yet to try such a thing.
 
BTW a 3rd method; use vertex colors to pass 'virtual texcoords', so (0,0,x) at the upperleft, (1,1,x) at the lowerright for example. That would also make the right direction possible. However, I'm not sure how easy this is in Max...
 
The way that you are doing the paint is interesting, it seems like the high ambient values would make the car glow at night though. I think that having a proper metallic shader would be a better way to go in the long run since it mimics reality. The fresnel settings are quite helpful though. This is a good illustration of how flexible the shader system actually is.
I haven't been able to replicate the look you have on your BMW using the settings you posted, but I did get my metallic shaders working properly with shadows. :)

Alex Forbin
 
I get a crash with the shader.
Wed Dec 29 19:10:24 (WARN): [racer/208] DGPUShader::LoadAndCreateFromFile[data/cars/lancia_kappa_2.0_20vt/cg\speckle_v.cg]: The compile returned an error.
Wed Dec 29 19:10:24 (WARN): [racer/208] data/cars/lancia_kappa_2.0_20vt/cg\speckle_v.cg(53) : error C1008: undefined variable "CalculateAtmosphere"
data/cars/lancia_kappa_2.0_20vt/cg\speckle_v.cg(61) : error C1008: undefined variable "CalculateAtmosphereExtinction"
Wed Dec 29 19:10:29 (FATAL): [racer/208] DGPUShaderManager:MakeObject(data/cars/lancia_kappa_2.0_20vt/cg\speckle_v.cg): can't create CG vertex shader program
The compile returned an error.
data/cars/lancia_kappa_2.0_20vt/cg\speckle_v.cg(53) : error C1008: undefined variable "CalculateAtmosphere"
data/cars/lancia_kappa_2.0_20vt/cg\speckle_v.cg(61) : error C1008: undefined variable "CalculateAtmosphereExtinction"
Wed Dec 29 19:10:30 (FATAL): [racer/208] Exception 0xC0000005, flags 0, Address 0x004F9C32
(this dialog text is stored in QLOG.txt)
 

Latest News

How are you going to watch 24 hours of Le Mans

  • On national tv

    Votes: 247 34.2%
  • Eurosport app/website

    Votes: 196 27.1%
  • WEC app/website

    Votes: 137 19.0%
  • Watch party

    Votes: 59 8.2%
  • At a friends house

    Votes: 18 2.5%
  • At Le Mans

    Votes: 65 9.0%
Back
Top