Trying to fix the forwaard rendering

This commit is contained in:
samcake 2018-02-07 18:46:47 -08:00
parent fd007e845d
commit caacd3e5cf
7 changed files with 28 additions and 77 deletions

View file

@ -11,17 +11,8 @@
<@if not FORWARD_BUFFER_WRITE_SLH@>
<@def FORWARD_BUFFER_WRITE_SLH@>
<@include ForwardBuffer.slh@>
layout(location = 0) out vec4 _fragColor0;
// the alpha threshold
const float alphaThreshold = 0.5;
float evalOpaqueFinalAlpha(float alpha, float mapAlpha) {
return mix(alpha, 1.0 - alpha, step(mapAlpha, alphaThreshold));
}
const float DEFAULT_ROUGHNESS = 0.9;
const float DEFAULT_SHININESS = 10.0;
const float DEFAULT_METALLIC = 0.0;
@ -31,33 +22,4 @@ const float DEFAULT_OCCLUSION = 1.0;
const float DEFAULT_SCATTERING = 0.0;
const vec3 DEFAULT_FRESNEL = DEFAULT_EMISSIVE;
void packForwardFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion, float scattering) {
if (alpha != 1.0) {
discard;
}
_fragColor0 = vec4(albedo, ((scattering > 0.0) ? packScatteringMetallic(metallic) : packShadedMetallic(metallic)));
}
void packForwardFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 lightmap) {
if (alpha != 1.0) {
discard;
}
_fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));
}
void packForwardFragmentUnlit(vec3 normal, float alpha, vec3 color) {
if (alpha != 1.0) {
discard;
}
_fragColor0 = vec4(color, packUnlit());
}
void packForwardFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) {
if (alpha <= 0.0) {
discard;
}
_fragColor0 = vec4(albedo.rgb, alpha);
}
<@endif@>

View file

@ -135,11 +135,12 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu
color += directionalSpecular;
// Attenuate the light if haze effect selected
if ((hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) {
color = computeHazeColorKeyLightAttenuation(color, lightDirection, position);
}
// if ((hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) {
// color = computeHazeColorKeyLightAttenuation(color, lightDirection, position);
// }
return color;
return normal;
// return color;
}
<@endfunc@>

View file

@ -155,6 +155,7 @@ vec3 fetchLightmapMap(vec2 uv) {
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
vec3 localNormal = <$fetchedNormal$>;
<$normal$> = vec3(normalizedTangent * localNormal.x + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z);
<$normal$> = normalizedNormal;
}
<@endfunc@>

View file

@ -66,9 +66,8 @@ void main(void) {
TransformCamera cam = getTransformCamera();
vec3 fragNormal;
<$transformEyeToWorldDir(cam, _normal, fragNormal)$>
fragNormal = normalize(fragNormal);
fragNormal = normalize(_normal);
vec4 color = vec4(evalSkyboxGlobalColor(
cam._viewInverse,
1.0,

View file

@ -63,8 +63,8 @@ void main(void) {
vec3 emissive = getMaterialEmissive(mat);
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
vec3 viewNormal;
<$tangentToViewSpace(normalTex, _normal, _tangent, viewNormal)$>
vec3 fragNormal;
<$tangentToViewSpace(normalTex, _normal, _tangent, fragNormal)$>
float scattering = getMaterialScattering(mat);
<$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>;
@ -78,7 +78,7 @@ void main(void) {
1.0,
1.0,
fragPosition,
viewNormal,
fragNormal,
albedo,
fresnel,
metallic,

View file

@ -63,36 +63,24 @@ void main(void) {
else {
fresnel = albedo;
metallic = 1.0;
}/*
float scattering = getMaterialScattering(mat);
packForwardFragment(
normalize(_normal),
opacity,
albedo,
roughness,
metallic,
emissive,
occlusionTex,
scattering);
*/
}
vec3 fragPosition = _position.xyz;
TransformCamera cam = getTransformCamera();
vec3 fragNormal;
<$transformEyeToWorldDir(cam, _normal, fragNormal)$>
fragNormal = normalize(_normal);
vec4 color = vec4(evalSkyboxGlobalColor(
cam._viewInverse,
1.0,
1.0,
fragPosition,
fragNormal,
albedo,
fresnel,
metallic,
roughness),
opacity);
vec4 color = vec4(evalSkyboxGlobalColor(
cam._viewInverse,
1.0,
1.0,
fragPosition,
fragNormal,
albedo,
fresnel,
metallic,
roughness),
opacity);
color.rgb += emissive * isEmissiveEnabled();
// _fragColor = vec4(albedo, opacity);

View file

@ -38,8 +38,8 @@ void main(void) {
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
albedo *= _color;
packForwardFragmentUnlit(
normalize(_normal),
opacity,
albedo * isUnlitEnabled());
if (opacity != 1.0) {
discard;
}
_fragColor0 = vec4(albedo * isUnlitEnabled(), 1.0);
}