mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 17:50:42 +02:00
Merge branch 'master' of https://github.com/samcake/hifi
This commit is contained in:
commit
6594f963d1
12 changed files with 42 additions and 27 deletions
|
@ -27,11 +27,11 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular,
|
|||
gl_FragData[2] = vec4(specular, shininess / 128.0);
|
||||
}
|
||||
|
||||
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) {
|
||||
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec4 lightmap) {
|
||||
gl_FragData[0] = vec4(diffuse.rgb, alpha);
|
||||
//gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);
|
||||
gl_FragData[2] = vec4(emissive, shininess / 128.0);
|
||||
//gl_FragData[2] = vec4(emissive, shininess / 128.0);
|
||||
gl_FragData[2] = lightmap;
|
||||
}
|
||||
|
||||
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) {
|
||||
|
|
|
@ -92,26 +92,35 @@ vec3 evalAmbienSphereGlobalColor(float shadowAttenuation, vec3 position, vec3 no
|
|||
return color;
|
||||
}
|
||||
|
||||
vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) {
|
||||
vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec4 lightmap) {
|
||||
|
||||
Light light = getLight();
|
||||
float diffuseDot = dot(normal, getLightDirection(light));
|
||||
float diffuseDot = dot(normal, gl_LightSource[0].position.xyz);
|
||||
|
||||
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
||||
// it should be just 0, but we have innacurracy so we need to overshoot
|
||||
const float PERPENDICULAR_THRESHOLD = -0.005;
|
||||
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot);
|
||||
|
||||
|
||||
//float normalMapContrib = (lightmap.w != 0.0 ? diffuseDot * abs(2*lightmap.w - 1.0) : 1.0);
|
||||
// float normalMapContrib = (lightmap.w != 0.0 ? diffuseDot * abs(2*lightmap.w - 1.0) : 1.0);
|
||||
float normalMapContrib = 2.0 * (lightmap.w - 0.5);
|
||||
|
||||
// evaluate the shadow test but only relevant for light facing fragments
|
||||
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
|
||||
|
||||
// lightAttenuation *= (abs(normalMapContrib) * max(0, diffuseDot) + (1.0 - abs(normalMapContrib)));
|
||||
lightAttenuation *= (abs(normalMapContrib) * max(0, diffuseDot));
|
||||
|
||||
// diffuse light is the lightmap dimmed by shadow
|
||||
vec3 diffuseLight = lightAttenuation * lightmap;
|
||||
vec3 diffuseLight = lightAttenuation * lightmap.rgb;
|
||||
|
||||
// ambient is a tiny percentage of the lightmap and only when in the shadow
|
||||
vec3 ambientLight = (1 - lightAttenuation) * 0.5 * lightmap;
|
||||
vec3 ambientLight = (1 - lightAttenuation) * 0.5 * lightmap.rgb;
|
||||
|
||||
return diffuse * (ambientLight + diffuseLight);
|
||||
|
||||
// return normal;
|
||||
return diffuse * (ambientLight + diffuseLight);
|
||||
// return lightmap.rgb;
|
||||
}
|
||||
|
||||
<@endif@>
|
||||
|
|
|
@ -23,13 +23,12 @@ void main(void) {
|
|||
|
||||
// Light mapped or not ?
|
||||
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
|
||||
vec3 color = evalLightmappedColor(
|
||||
1.0,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz);
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
gl_FragColor = vec4(evalLightmappedColor(
|
||||
1.0,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbienSphereGlobalColor(1.0,
|
||||
frag.position.xyz,
|
||||
|
|
|
@ -33,7 +33,7 @@ void main(void) {
|
|||
shadowAttenuation,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
frag.specularVal),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbienSphereGlobalColor(shadowAttenuation,
|
||||
|
|
|
@ -34,7 +34,7 @@ void main(void) {
|
|||
shadowAttenuation,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
frag.specularVal),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbienSphereGlobalColor(shadowAttenuation,
|
||||
|
|
|
@ -26,7 +26,7 @@ void main(void) {
|
|||
1.0,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
frag.specularVal),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbienGlobalColor(1.0,
|
||||
|
|
|
@ -33,7 +33,7 @@ void main(void) {
|
|||
shadowAttenuation,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
frag.specularVal),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbienGlobalColor(shadowAttenuation,
|
||||
|
|
|
@ -34,7 +34,7 @@ void main(void) {
|
|||
shadowAttenuation,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
frag.specularVal),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbienGlobalColor(shadowAttenuation,
|
||||
|
|
|
@ -42,5 +42,5 @@ void main(void) {
|
|||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, 0.0));
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ void main(void) {
|
|||
vec3 normalizedNormal = normalize(vec3(interpolatedNormal));
|
||||
vec3 normalizedTangent = normalize(vec3(interpolatedTangent));
|
||||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||
vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5);
|
||||
vec3 localNormal = normalize(vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5));
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
|
||||
|
@ -47,6 +47,13 @@ void main(void) {
|
|||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st);
|
||||
|
||||
// WE have lightmap AND normal map so we are going to alter the lighting intensity
|
||||
// from the lightmap with the dot product between the surface normal and the normal map
|
||||
// Why will you ask? because we want to see something out of the normal map and since
|
||||
// the lighting from the lightmap doesnt't give a light direction, we just hack one...
|
||||
vec4 lightIntensity = vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb,
|
||||
0.5 * dot(localNormal, vec3(0.0, 1.0, 0.0)) + 0.5 );
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragmentLightmap(
|
||||
|
@ -55,5 +62,5 @@ void main(void) {
|
|||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
lightIntensity);
|
||||
}
|
||||
|
|
|
@ -59,5 +59,5 @@ void main(void) {
|
|||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
specular, // no use of getMaterialSpecular(mat)
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, 0.0));
|
||||
}
|
||||
|
|
|
@ -45,5 +45,5 @@ void main(void) {
|
|||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
specular, // no use of getMaterialSpecular(mat)
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, 0.0));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue