Author Topic: Cool shader, but...  (Read 2860 times)

0 Members and 1 Guest are viewing this topic.

Offline Kolgena

  • 211
The new metal shader looks fantastic, and gives the lighting much more depth and detail, but it has a weird visual glitch. There seems to be an error in the way lighting is handled on surfaces facing away from a light source.

Behold: The Iceni with a gloriously lit underside... in the ship lab which only has a light coming from the top.

Is there any way to fix this?

(I suspect, with my nonexistent knowledge about shaders, that it may have something to do with some angle value that is being calculated for both positive and negative, where it should only be calculated for positive. Either that, or ATI is being gay again)

[attachment deleted by a basterd]

 

Offline Kolgena

  • 211
So uh, I hate to double post, but is anyone else getting this issue/looking into it? I'd appreciate some form of feedback about this issue, is all :)

 
Isn't the light coming from the mouse ?
I noticed that when I ship-labbed after the update came out.

 

Offline -Norbert-

  • 211
When I rotate the Iceny to the same angle, I don't have that issue on my end. All the light seems to be coming from the top (or rather the top minus 45°, as if the light was right above my head, shining into the monitor, so to say).

Either way aren't the shaders something that came from the SCP, rather than a BP specific issue?

 

Offline Kolgena

  • 211
@Norbert: The shaders with BP are different. Namely, there's a section under shine that is greatly expanded compared to the ones that come with 3.6.14 RC2 thread. The screenshot was taken with mediavps as the active mod, but with BP's new shaders extracted into the data\effects directory.

@X3no: I might be mistaken, but Valathil's build is the one with the mouse as a light source. RC2 does not have this function IIRC.

Edit: Yep, just checked: RC2 does not make the mouse a light, and RC2 + bp main-f.sdr and main-v.sdr make the undersides of ships brightly lit at some very specific angles.
« Last Edit: December 28, 2011, 12:09:49 pm by Kolgena »

 

Offline -Norbert-

  • 211
So when you use the BP2 shaders outside of BP2, you got that glitch. Do you also have the glitch in BP2 itself?

 

Offline Kolgena

  • 211
Yes.

Edit: Just verified. Keep in mind, that the angles where the glitch appear are fairly specific. It's not immediately obvious that there's a problem unless you tweak around with the position of the ship a bit, but the problem affects every ship I've tried (which is a dozen or so)
« Last Edit: December 28, 2011, 12:34:08 pm by Kolgena »

 

Offline Kolgena

  • 211
Re: Cool shader, but...
*apologetic necrobump*

I might have managed to fix/minimize this issue. Basically what I did is replace the eye vector calculation responsible for anisotropic reflections with a half-vector calculation. This greatly minimizes backlighting/shine at wrong angles, though I don't know why it should.

Code: [Select]
// Specular
  #ifdef FLAG_NORMAL_MAP
mat3 tan_mat = mat3(tbnMatrix[2], tbnMatrix[1], tbnMatrix[0]);
mat3 bin_mat = mat3(tbnMatrix[2], tbnMatrix[0], tbnMatrix[1]);
vec3 tan = normalize(tan_mat * normal);
vec3 bin = normalize(bin_mat * normal);

float _AlphaX = 0.3;
float _AlphaY = 0.1;

float dotHN = clamp(dot(normal, half_vec), 0.0, 1.0);
//float dotVN = clamp(dot(normal, eyeDir), 0.0001, 1.0);
//Above  is  a hack, to get rid of weird backlighting
float dotVN = clamp(dot(normal, half_vec), 0.0, 1.0);
float dotHTAlphaX = dot(half_vec, tan) / _AlphaX;
float dotHBAlphaY = dot(half_vec, bin) / _AlphaY;

lightSpecular += dotVN * exp((-2.0 * ((dotHTAlphaX * dotHTAlphaX) + (dotHBAlphaY * dotHBAlphaY))) / (1.0 + dotVN)) * (gl_FrontLightProduct[i].specular * attenuation) * specularIntensity;
lightSpecular += ((gl_FrontLightProduct[i].specular * pow(dotHN, gl_FrontMaterial.shininess)) * attenuation) * specularIntensity;
  #else
float NdotHV = clamp(dot(normal, half_vec), 0.0, 1.0);
lightSpecular += ((gl_FrontLightProduct[i].specular * pow(NdotHV, gl_FrontMaterial.shininess)) * attenuation) * specularIntensity;
  #endif
}