

Attachment: granite.PNG (253k)

But still, I can't guess what tha black material should be .


I hereby license the file granite.png under the CC-BY license
I hereby license the file granite_NRM.png under the CC-BY license
I hereby license the file smooth_normals.png under the CC-BY license
I hereby license the file smooth_rock.png under the CC-BY license
Attachment: granite.png (193k)
Attachment: granite_NRM.png (402k)
Attachment: smooth_normals.png (1042k)
Attachment: smooth_rock.png (286k)

Clonk is using weird coordinate systems sometimes.


> Seems like when there is ambient light, the materials are per default light on top and dark at the bottom
Yeah, that's the ambient shader.
Yes - the presence of ambient light directly overrides the effect of light sources. This makes a certain amount of sense: The sun is basically assumed to be so bright that it drowns out everything else. Like in real life: Put a candle outside, and it has basically no effect. Do the same in a cave, and lights change radically. The weighting basically "compresses" the brightness range on top of that, in order to emulate our eyes adjusting to different lighting conditions.
I was a bit skeptical at first when I read the code, too, but I think it works rather well.
I was a bit skeptical at first when I read the code, too, but I think it works rather well.
Just some small issues:
The brickback material was used for an alternative tunnel style, you are currently using it as a second brick type which is odd. This should be fixed. Also sometimes you name a normal map _NRM and sometimes _nrm, this could also be made consistent.
The brickback material was used for an alternative tunnel style, you are currently using it as a second brick type which is odd. This should be fixed. Also sometimes you name a normal map _NRM and sometimes _nrm, this could also be made consistent.

Sand and earth, given their rough nature, could benefit from a more dull shading instead.
> I think custom shaders for materials could add a lot of sugar to this.
It would probably be a major effort to allow this. It would require the landscape to be drawn in multiple passes, with one pass for each shader. Would also have implications for landscape rendering performance...
Which is often exactly as expensive as having a numerical material property for whatever you're interested in (shinyness? transluency?). I would prefer that route.
Which, btw, shouldn't keep anybody from experimenting with it. If somebody wants to test landscape shader effects, just put a suitable
if
-branch checking materialIx
into LandscapeShader.c
(predicting the material index might or might not be a bit guesswork though). I'm a bit skeptical whether there's really a lot we can gain from this, but would love to be proven wrong.

A pull request would be suboptimal if we don't do quality checks on the milestone repos.


Edit: Oh, Sven was faster. :)


So I guess you have a different normal response in mind? Right now, we have essentially (ignoring culling, which doesn't matter for the landscape):
What you have in mind is probably simply:
If you want "sharper" spotlights you could even use something like:
Actual reflection would involve different maths: "Incoming angle = outgoing angle" would suggest that the light source being right in front of the material should *not* cause reflection. So maybe something like
Could cause interesting light effects. All untested, mind you :)
float light = 2.0 * lightBright * max(dot(normal, lightDir), 0.0);
What you have in mind is probably simply:
float light = 2.0 * lightBright * max(dot(normal, lightDir), 0.5);
If you want "sharper" spotlights you could even use something like:
float light = 2.0 * lightBright * pow(max(dot(normal, lightDir)), 0.7), 2.0);
Actual reflection would involve different maths: "Incoming angle = outgoing angle" would suggest that the light source being right in front of the material should *not* cause reflection. So maybe something like
float reflect = max(1.0 - abs(0.8 - dot(normal, lightDir)), 0.7);
float light = 2.0 * lightBright * pow(reflect, 2.0);
Could cause interesting light effects. All untested, mind you :)


Disclaimer: I have absolutely zero idea what I am doing. My shader code is a huge mess and my normal map is not "correct" as I just eyeballed some normal-map-like colors in photoshop. I do not even know if the shader would look ok if the normalmap was acutally correct. Best is to take this as a proof of concept.

slice(light) {
if (f2i(landscapePx.r) == 189) {
float reflect = max(1.0 - abs(0.8 - dot(normal, lightDir)), 0.6);
light = 3.0 * lightBright * pow(reflect, 2.0);
}
}
slice(color) {
if (f2i(landscapePx.r) == 189) {
float reflect = max(1.0 - abs(0.8 - dot(normal, lightDir)), 0.7);
float light = 2.0 * lightBright * pow(reflect, 2.0);
float r = pow(light, 3.0);
float g = 0.5 + light/2 + pow(light, 2.0)*0.8 + color.rgb.g;
float b = 0.5 - light + pow(light, 4.0)*0.6 + color.rgb.b;
color.rgb = vec3(r, g/2, b);
}
}
Edit: important: I disabled the material light for amethyst
I hereby license the file amethyst_NRM.jpg under the CC-BY license
Attachment: amethyst_NRM.jpg - People who knew what they were doing with normal maps would cry if they saw this (56k)

slice(light+2) {
if (f2i(landscapePx.r) == 189) {
float reflect = max(1.0 - abs(0.8 - dot(normal, lightDir)), 0.6);
light = 3.0 * lightBright * pow(reflect, 2.0);
}
}
slice(color+1) {
if (f2i(landscapePx.r) == 189) {
float reflect = max(1.0 - abs(0.8 - dot(normal, lightDir)), 0.7);
float light = 2.0 * lightBright * pow(reflect, 2.0);
float r = pow(light, 3.0);
float g = 0.5 + light/2 + pow(light, 2.0)*0.8 + color.rgb.g;
float b = 0.5 - light + pow(light, 4.0)*0.6 + color.rgb.b;
color.rgb = vec3(r, g/2, b);
}
}

Nice! Instead of the hardcoded 189, we could have the engine generate
#define MATERIAL_XXX
constants for all materials when generating the landscape shader. Or, like Peter suggested, introduce a set of material properties that allow to achieve this effect and which are then applied to all materials.
I would definitely suggest a material property - highly likely we want this kind of thing in different strengths for a good number of materials. Things we could parameterise here:
1.
2. Point of highest reflection
3. Luminosity?
Here's what I get trying to refactor Matthi's code:
Now I'm going to assume for the moment (any objections?) that we don't want the material to shine through the FoW. Setting
I approximated the
At which point we have broken the whole thing down to just a few numbers that we could easily set per material. However, a few troubling things: Normally "tex" is what we get from the texture, not the luminosity (?) part. In this case, we especially completely ignore the red part of the colour. Personally, I would prefer if we could break it down into something like:
That's roughly what I would suggest. All factors previously on "
1.
pow
exponent2. Point of highest reflection
3. Luminosity?
Here's what I get trying to refactor Matthi's code:
float reflect = max(1.0 - abs(0.8 - dot(normal, lightDir)), 0.7);
color.r = 8.0 * pow(lightBright, 3.0) * pow(reflect, 6.0);
color.g = 0.25 + 0.5 * lightBright * pow(reflect, 2.0) + 1.6 * pow(lightBright, 2.0) * pow(reflect, 4.0) + 0.5*color.g;
color.b = 0.5 - 2.0 * lightBright * pow(reflect, 2.0) + 9.6 * pow(lightBright, 4.0) * pow(reflect, 8.0) + color.b;
Now I'm going to assume for the moment (any objections?) that we don't want the material to shine through the FoW. Setting
lightBright = 1
(hm, maybe 0.8?) and re-introducing it as a linear factor doesn't change the lights in the FoV, and gives us: float reflect = max(1.0 - abs(0.8 - dot(normal, lightDir)), 0.7);
color.r = 8.0 * pow(reflect, 6.0);
color.g = 0.25 + 0.5 * pow(reflect, 2.0) + 1.6 * pow(reflect, 4.0) + 0.5*color.g;
color.b = 0.5 - 2.0 * pow(reflect, 2.0) + 9.6 * pow(reflect, 8.0) + color.b;
color = lightBright * color;
I approximated the
pow
sum curves to get just a single pow
, which allows us to write the whole thing as: float reflect = max(1.0 - abs(0.8 - dot(normal, lightDir)), 0.7);
vec3 tex = vec3(8.0, 2.1, 6.5);
vec3 lum = vec3(0.0, 0.25, 0.5) + color * vec3(0.0, 0.5, 1.0);
vec3 pw = vec3(6.0, 4.0, 8.0);
color = lightBright * (tex * pow(reflect, pw) + lum);
At which point we have broken the whole thing down to just a few numbers that we could easily set per material. However, a few troubling things: Normally "tex" is what we get from the texture, not the luminosity (?) part. In this case, we especially completely ignore the red part of the colour. Personally, I would prefer if we could break it down into something like:
float reflect = max(1.0 - abs(0.8 - dot(normal, lightDir)), 0.7);
vec3 lum = vec3(0.0, 0.5, 1.0);
vec3 pw = vec3(6.0, 4.0, 8.0);
color = lightBright * color * (pow(reflect, pw) + lum);
That's roughly what I would suggest. All factors previously on "
tex
" should be baked into the material texture in this scenario.
Looks nice indeed, there is a bunch of pixels in the granite that behave strangely, is this a bit of amethyst material?
Nice, proven wrong right away. Btw - does the shader apply to the Clonk's face too? What is going on there? o_O

Also, Diamondium for the name would be great *shaking fist of anger* .
[Edit]
Maybe you can do some unicorn-code-magic on the gold, too!
Added now? Just wanted to drop in to say: Looks good. If this is the new style, we might want to raise
Also this might have been lost a bit - but alongside the shader reorganisation every material now has three new properties that determine how it reacts to light. So far, I only changed it for Gold:
normalMapStrength
to 0.3 or 0.4.Also this might have been lost a bit - but alongside the shader reorganisation every material now has three new properties that determine how it reacts to light. So far, I only changed it for Gold:
LightEmit=0,215,255
LightSpot=64,64,64
LightAngle=220
LightEmit
makes the material "emitting", which is basically normal-independent lighting ("glow"?). The higher LightSpot
is, the sharper the light response in a particular color channel. Finally, LightAngle
changes the angle at which the material reflects the light the most - 255 is normal, lower values mean that the light will reflect most when the light source is a bit away.

What would be necessary to have that same effect Matthi showed in here for crystal?
It's not quite immediately comparable. According to my calculations above, it should be something like
Because for
LightEmit=0,127,255
LightSpot=96,64,128
LightAngle=204
Because for
LightSpot
, 16 is 1.0 and for LightAngle
, 255 is 1.0.

It feels like everything except ore disregards the clonk light source completely.
Yes, noticed that too. My working hypothesis is that the border normals and the texture normals mix differently depending on how much the material normals vary. Therefore the borders look huge on flat materials, but disappear on very structured textures. Maybe "mix" isn't the right approach here after all.
This is probably not causing this problem, but if you mix two (normalized) normal vectors, they are not guaranteed to be normalized afterwards. But the shader doesn't seem to renormalize them.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill