Trying to unify the shaders with/without scattering eve more but found a scribe bug. REnder emissive and lightmap during forward pass

This commit is contained in:
samcake 2016-07-08 09:04:10 -07:00
parent fff2a9a5a2
commit 37f7596183
21 changed files with 291 additions and 355 deletions

View file

@ -11,6 +11,7 @@
#include <GPUIdent.h>
#include <NumericalConstants.h>
#include <fstream>
Q_LOGGING_CATEGORY(gpugllogging, "hifi.gpu.gl")
@ -671,14 +672,14 @@ bool compileShader(GLenum shaderDomain, const std::string& shaderSource, const s
// if compilation fails
if (!compiled) {
// save the source code to a temp file so we can debug easily
/* std::ofstream filestream;
std::ofstream filestream;
filestream.open("debugshader.glsl");
if (filestream.is_open()) {
filestream << shaderSource->source;
filestream << srcstr[0];
filestream << srcstr[1];
filestream.close();
}
*/
GLint infoLength = 0;
glGetShaderiv(glshader, GL_INFO_LOG_LENGTH, &infoLength);

View file

@ -33,9 +33,6 @@ uniform sampler2D lightingMap;
struct DeferredFragment {
vec4 normalVal;
vec4 diffuseVal;
vec4 specularVal;
vec4 position;
vec3 normal;
float metallic;
@ -43,44 +40,47 @@ struct DeferredFragment {
float obscurance;
vec3 specular;
float roughness;
vec3 emissive;
// vec3 emissive;
int mode;
float scattering;
float depthVal;
};
DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) {
vec4 normalVal;
vec4 diffuseVal;
vec4 specularVal;
DeferredFragment frag;
frag.depthVal = -1;
frag.normalVal = texture(normalMap, texcoord);
frag.diffuseVal = texture(albedoMap, texcoord);
frag.specularVal = texture(specularMap, texcoord);
normalVal = texture(normalMap, texcoord);
diffuseVal = texture(albedoMap, texcoord);
specularVal = texture(specularMap, texcoord);
frag.obscurance = texture(obscuranceMap, texcoord).x;
// Unpack the normal from the map
frag.normal = unpackNormal(frag.normalVal.xyz);
frag.roughness = frag.normalVal.a;
frag.normal = unpackNormal(normalVal.xyz);
frag.roughness = normalVal.a;
// Diffuse color and unpack the mode and the metallicness
frag.diffuse = frag.diffuseVal.xyz;
frag.diffuse = diffuseVal.xyz;
frag.scattering = 0.0;
unpackModeMetallic(frag.diffuseVal.w, frag.mode, frag.metallic);
unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic);
frag.emissive = frag.specularVal.xyz;
frag.obscurance = min(frag.specularVal.w, frag.obscurance);
//frag.emissive = specularVal.xyz;
frag.obscurance = min(specularVal.w, frag.obscurance);
if (frag.mode == FRAG_MODE_SCATTERING) {
frag.scattering = frag.emissive.x;
frag.emissive = vec3(0.0);
frag.scattering = specularVal.x;
//frag.emissive = vec3(0.0);
}
if (frag.metallic <= 0.5) {
frag.metallic = 0.0;
frag.specular = vec3(0.03); // Default Di-electric fresnel value
} else {
frag.specular = vec3(frag.diffuseVal.xyz);
frag.specular = vec3(diffuseVal.xyz);
frag.metallic = 1.0;
}
@ -135,9 +135,9 @@ vec4 fetchDiffusedCurvature(vec2 texcoord) {
return texture(diffusedCurvatureMap, texcoord);
}
void unpackMidLowNormalCurvature(vec2 texcoord, out vec4 midNormalCurvature, out vec4 vec4 lowNormalCurvature) {
midNormalCurvature = fetchCurvature(_texCoord0);
lowNormalCurvature = fetchDiffusedCurvature(_texCoord0);
void unpackMidLowNormalCurvature(vec2 texcoord, out vec4 midNormalCurvature, out vec4 lowNormalCurvature) {
midNormalCurvature = fetchCurvature(texcoord);
lowNormalCurvature = fetchDiffusedCurvature(texcoord);
midNormalCurvature.xyz = normalize((midNormalCurvature.xyz - 0.5f) * 2.0f);
lowNormalCurvature.xyz = normalize((lowNormalCurvature.xyz - 0.5f) * 2.0f);
midNormalCurvature.w = (midNormalCurvature.w * 2 - 1);

View file

@ -17,6 +17,7 @@ layout(location = 0) out vec4 _fragColor0;
layout(location = 1) out vec4 _fragColor1;
layout(location = 2) out vec4 _fragColor2;
layout(location = 3) out vec4 _fragColor3;
// the alpha threshold
const float alphaThreshold = 0.5;
@ -40,16 +41,20 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness
_fragColor0 = vec4(albedo, ((scattering > 0.0) ? packScatteringMetallic(metallic) : packShadedMetallic(metallic)));
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
_fragColor2 = vec4(((scattering > 0.0) ? vec3(scattering) : emissive), occlusion);
_fragColor3 = vec4(emissive, 1.0);
}
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 emissive) {
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 lightmap) {
if (alpha != 1.0) {
discard;
}
_fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
_fragColor2 = vec4(emissive, 1.0);
_fragColor2 = vec4(lightmap, 1.0);
_fragColor3 = vec4(albedo * lightmap, 1.0);
}
void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {
@ -59,6 +64,8 @@ void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {
_fragColor0 = vec4(color, packUnlit());
_fragColor1 = vec4(packNormal(normal), 1.0);
//_fragColor2 = vec4(vec3(0.0), 1.0); // If unlit, do not worry about the emissive color target
_fragColor3 = vec4(color, 1.0);
}
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) {

View file

@ -12,7 +12,6 @@
<@def DEFERRED_GLOBAL_LIGHT_SLH@>
<@include model/Light.slh@>
<!<@include DeferredLighting.slh@>!>
<@include LightingModel.slh@>
<$declareLightingModel()$>
@ -35,9 +34,9 @@
<@if isScattering@>
<@else@>
color += emissive * isEmissiveEnabled();
// color += emissive * isEmissiveEnabled();
<@endif@>
//color += emissive * isEmissiveEnabled();
vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value
if (metallic > 0.5) {
fresnel = albedo;
@ -48,7 +47,7 @@
<@func declareEvalAmbientGlobalColor()@>
vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) {
vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, float roughness) {
<$prepareGlobalLight()$>
color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light);
return color;
@ -60,45 +59,27 @@ vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obsc
<$declareLightingAmbient(1, 0, 0, supportScattering)$>
<$declareLightingDirectional(supportScattering)$>
vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
vec3 albedo, float metallic, vec3 emissive, float roughness) {
<$prepareGlobalLight()$>
// Ambient
vec3 ambientDiffuse;
vec3 ambientSpecular;
evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance);
color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled();
color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled();
// Directional
vec3 directionalDiffuse;
vec3 directionalSpecular;
evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation);
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled();
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();
return color;
}
<@if supportScattering@>
<$declareDeferredCurvature()$>
<@endif@>
vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
vec3 albedo, float metallic, vec3 emissive, float roughness, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature) {
vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
vec3 albedo, float metallic, float roughness
<@if supportScattering@>
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@>
) {
<$prepareGlobalLight(1)$>
<$prepareGlobalLight(supportScattering)$>
// Ambient
vec3 ambientDiffuse;
vec3 ambientSpecular;
evalLightingAmbientScattering(ambientDiffuse, ambientSpecular, light,
fragEyeDir, fragNormal, roughness,
metallic, fresnel, albedo, obscurance,
isScatteringEnabled() * scattering, midNormalCurvature, lowNormalCurvature);
evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance
<@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature
<@endif@>
);
color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled();
color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled();
@ -106,18 +87,17 @@ vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenua
// Directional
vec3 directionalDiffuse;
vec3 directionalSpecular;
evalLightingDirectionalScattering(directionalDiffuse, directionalSpecular, light,
fragEyeDir, fragNormal, roughness,
metallic, fresnel, albedo, shadowAttenuation,
isScatteringEnabled() * scattering, midNormalCurvature, lowNormalCurvature);
evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation
<@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature
<@endif@>
);
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled();
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();
return color;
}
<@endif@>
<@endfunc@>
@ -126,13 +106,26 @@ vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenua
<$declareLightingAmbient(0, 1, 0, supportScattering)$>
<$declareLightingDirectional(supportScattering)$>
vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) {
<$prepareGlobalLight()$>
<@if supportScattering@>
<$declareDeferredCurvature()$>
<@endif@>
vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
vec3 albedo, float metallic, float roughness
<@if supportScattering@>
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@>
) {
<$prepareGlobalLight(supportScattering)$>
// Ambient
vec3 ambientDiffuse;
vec3 ambientSpecular;
evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance);
evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance
<@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature
<@endif@>
);
color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled();
color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled();
@ -140,45 +133,17 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu
// Directional
vec3 directionalDiffuse;
vec3 directionalSpecular;
evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation);
evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation
<@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature
<@endif@>
);
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled();
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();
return color;
}
<@if supportScattering@>
<$declareDeferredCurvature()$>
vec3 evalSkyboxGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness, float scattering, vec4 blurredCurvature, vec4 diffusedCurvature) {
<$prepareGlobalLight(1)$>
// Ambient
vec3 ambientDiffuse;
vec3 ambientSpecular;
evalLightingAmbientScattering(ambientDiffuse, ambientSpecular, light,
fragEyeDir, fragNormal, roughness,
metallic, fresnel, albedo, obscurance,
isScatteringEnabled() * scattering, lowNormal, highCurvature, lowCurvature);
color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled();
color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled();
// Directional
vec3 directionalDiffuse;
vec3 directionalSpecular;
evalLightingDirectionalScattering(directionalDiffuse, directionalSpecular, light,
fragEyeDir, fragNormal, roughness,
metallic, fresnel, albedo, shadowAttenuation,
isScatteringEnabled() * scattering, , midNormalCurvature, lowNormalCurvature);
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled();
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();
return vec3(color);
}
<@endif@>
<@endfunc@>
<@func declareEvalLightmappedColor()@>
@ -215,6 +180,8 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur
vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness, float opacity) {
<$prepareGlobalLight()$>
color += emissive * isEmissiveEnabled();
// Ambient
vec3 ambientDiffuse;

View file

@ -209,11 +209,13 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo
state->setDepthTest(true, false, gpu::LESS_EQUAL);
// TODO: We should use DepthClamp and avoid changing geometry for inside /outside cases
// additive blending
state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
} else {
state->setCullMode(gpu::State::CULL_BACK);
// additive blending
state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
}
pipeline = gpu::Pipeline::create(program, state);
@ -334,11 +336,11 @@ void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderC
batch.setStateScissorRect(args->_viewport);
// Clear Lighting buffer
auto lightingFbo = DependencyManager::get<FramebufferCache>()->getLightingFramebuffer();
/* auto lightingFbo = DependencyManager::get<FramebufferCache>()->getLightingFramebuffer();
batch.setFramebuffer(lightingFbo);
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, vec4(vec3(0), 0), true);
*/
// Clear deferred
auto deferredFbo = DependencyManager::get<FramebufferCache>()->getDeferredFramebuffer();

View file

@ -104,6 +104,7 @@ void FramebufferCache::createPrimaryFramebuffer() {
_lightingFramebuffer->setRenderBuffer(0, _lightingTexture);
_lightingFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
_deferredFramebuffer->setRenderBuffer(3, _lightingTexture);
// For AO:
auto pointMipSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_POINT);

View file

@ -57,44 +57,38 @@ vec3 evalAmbientSpecularIrradiance(Light light, vec3 fragEyeDir, vec3 fragNormal
}
<@endfunc@>
<@func declareLightingAmbient(supportAmbientSphere, supportAmbientMap, supportIfAmbientMapElseAmbientSphere, supportScattering)@>
<@func declareLightingAmbient(supportAmbientSphere1, supportAmbientMap1, supportIfAmbientMapElseAmbientSphere1, supportScattering)@>
<$declareEvalAmbientSpecularIrradiance(supportAmbientSphere, supportAmbientMap, supportIfAmbientMapElseAmbientSphere)$>
void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3 eyeDir, vec3 normal, float roughness, float metallic, vec3 fresnel, vec3 albedo, float obscurance) {
// Diffuse from ambient
diffuse = (1 - metallic) * albedo * evalSphericalLight(getLightAmbientSphere(light), normal).xyz * obscurance * getLightAmbientIntensity(light);
// Specular highlight from ambient
specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light);
}
<$declareEvalAmbientSpecularIrradiance(supportAmbientSphere1, supportAmbientMap1, supportIfAmbientMapElseAmbientSphere1)$>
<@if supportScattering@>
<!<@include SubsurfaceScattering.slh@>!>
float curvatureAO(in float k) {
return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369;
}
<@endif@>
void evalLightingAmbientScattering(out vec3 diffuse, out vec3 specular, Light light,
vec3 eyeDir, vec3 normal, float roughness,
float metallic, vec3 fresnel, vec3 albedo, float obscurance,
float scatttering, vec3 lowNormal, float highCurvature, float lowCurvature) {
void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3 eyeDir, vec3 normal,
float roughness, float metallic, vec3 fresnel, vec3 albedo, float obscurance
<@if supportScattering@>
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@>
) {
float ambientOcclusion = curvatureAO(lowCurvature * 20.0f) * 0.5f;
float ambientOcclusionHF = curvatureAO(highCurvature * 8.0f) * 0.5f;
<@if supportScattering@>
float ambientOcclusion = curvatureAO(lowNormalCurvature.w * 20.0f) * 0.5f;
float ambientOcclusionHF = curvatureAO(midNormalCurvature.w * 8.0f) * 0.5f;
ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF);
/* if (showCurvature()) {
diffuse = vec3(ambientOcclusion);
specular = vec3(0.0);
return;
}*/
/* if (showCurvature()) {
diffuse = vec3(ambientOcclusion);
specular = vec3(0.0);
return;
}*/
// Diffuse from ambient
diffuse = ambientOcclusion * albedo * evalSphericalLight(getLightAmbientSphere(light), lowNormal).xyz *getLightAmbientIntensity(light);
diffuse = ambientOcclusion * albedo * evalSphericalLight(getLightAmbientSphere(light), lowNormalCurvature.xyz).xyz *getLightAmbientIntensity(light);
// Specular highlight from ambient
// vec3 specularLighting = evalGlobalSpecularIrradiance(light, fragEyeDir, fragNormal, roughness, fresnel);
@ -102,10 +96,16 @@ void evalLightingAmbientScattering(out vec3 diffuse, out vec3 specular, Light li
// Specular highlight from ambient
// specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light);
// specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light);
specular = vec3(0.0);
<@else@>
// Diffuse from ambient
diffuse = (1 - metallic) * albedo * evalSphericalLight(getLightAmbientSphere(light), normal).xyz * obscurance * getLightAmbientIntensity(light);
// Specular highlight from ambient
specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light);
<@endif@>
}
<@endif@>
<@endfunc@>

View file

@ -10,34 +10,20 @@
<@func declareLightingDirectional(supportScattering)@>
<@include DeferredLighting.slh@>
void evalLightingDirectional(out vec3 diffuse, out vec3 specular, Light light,
vec3 eyeDir, vec3 normal, float roughness,
float metallic, vec3 fresnel, vec3 albedo, float shadow) {
vec4 shading = evalFragShading(normal, -getLightDirection(light), eyeDir, metallic, fresnel, roughness);
vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light);
diffuse = albedo * shading.w * lightEnergy;
specular = shading.rgb * lightEnergy;
}
float metallic, vec3 fresnel, vec3 albedo, float shadow
<@if supportScattering@>
void evalLightingDirectionalScattering(out vec3 diffuse, out vec3 specular, Light light,
vec3 eyeDir, vec3 normal, float roughness,
float metallic, vec3 fresnel, vec3 albedo, float shadow,
float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature) {
vec3 fragLightDir = -normalize(getLightDirection(light));
evalFragShading(diffuse, specular,
normal, fragLightDir, eyeDir,
metallic, fresnel, roughness,
scattering, midNormalCurvature, lowNormalCurvature);
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@>
) {
evalFragShading(diffuse, specular, normal, -getLightDirection(light), eyeDir, metallic, fresnel, roughness
<@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature
<@endif@>
);
vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light);
@ -46,7 +32,5 @@ void evalLightingDirectionalScattering(out vec3 diffuse, out vec3 specular, Ligh
specular *= lightEnergy;
}
<@endif@>
<@endfunc@>

View file

@ -11,12 +11,13 @@
<@func declareLightingPoint(supportScattering)@>
<@include DeferredLighting.slh@>
void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light,
vec3 fragLightVec, vec3 fragEyeDir, vec3 normal, float roughness,
float metallic, vec3 fresnel, vec3 albedo, float shadow) {
float metallic, vec3 fresnel, vec3 albedo, float shadow
<@if supportScattering@>
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@>
) {
// Allright we re valid in the volume
float fragLightDistance = length(fragLightVec);
@ -28,43 +29,11 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light,
vec3 lightEnergy = radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light);
// Eval shading
vec4 shading = evalFragShading(normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness);
diffuse = albedo * shading.w * lightEnergy;
specular = shading.rgb * lightEnergy;
if (getLightShowContour(light) > 0.0) {
// Show edge
float edge = abs(2.0 * ((getLightRadius(light) - fragLightDistance) / (0.1)) - 1.0);
if (edge < 1) {
float edgeCoord = exp2(-8.0*edge*edge);
diffuse = vec3(edgeCoord * edgeCoord * getLightShowContour(light) * getLightColor(light));
}
}
}
evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness
<@if supportScattering@>
void evalLightingPointScattering(out vec3 diffuse, out vec3 specular, Light light,
vec3 fragLightVec, vec3 fragEyeDir, vec3 normal, float roughness,
float metallic, vec3 fresnel, vec3 albedo, float shadow,
float scattering, vec3 midNormal, vec3 lowNormal, float curvature) {
// Allright we re valid in the volume
float fragLightDistance = length(fragLightVec);
vec3 fragLightDir = fragLightVec / fragLightDistance;
// Eval attenuation
float radialAttenuation = evalLightAttenuation(light, fragLightDistance);
vec3 lightEnergy = radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light);
// Eval shading
evalFragShading(diffuse, specular,
normal, fragLightDir, fragEyeDir,
metallic, fresnel, roughness,
scattering, midNormalCurvature, lowNormalCurvature);
,scattering, midNormalCurvature, lowNormalCurvature
<@endif@>
);
diffuse *= albedo * lightEnergy;
@ -80,8 +49,6 @@ void evalLightingPointScattering(out vec3 diffuse, out vec3 specular, Light ligh
}
}
<@endif@>
<@endfunc@>

View file

@ -13,7 +13,11 @@
void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light,
vec4 fragLightDirLen, float cosSpotAngle, vec3 fragEyeDir, vec3 normal, float roughness,
float metallic, vec3 fresnel, vec3 albedo, float shadow) {
float metallic, vec3 fresnel, vec3 albedo, float shadow
<@if supportScattering@>
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@>
) {
// Allright we re valid in the volume
float fragLightDistance = fragLightDirLen.w;
@ -25,49 +29,14 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light,
vec3 lightEnergy = angularAttenuation * radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light);
// Eval shading
vec4 shading = evalFragShading(normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness);
diffuse = albedo * shading.w * lightEnergy;
specular = shading.rgb * lightEnergy;
if (getLightShowContour(light) > 0.0) {
// Show edges
float edgeDistR = (getLightRadius(light) - fragLightDistance);
float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -getLightSpotOutsideNormal2(light));
float edgeDist = min(edgeDistR, edgeDistS);
float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0);
if (edge < 1) {
float edgeCoord = exp2(-8.0*edge*edge);
diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light));
}
}
}
evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness
<@if supportScattering@>
void evalLightingSpotScattering(out vec3 diffuse, out vec3 specular, Light light,
vec4 fragLightDirLen, float cosSpotAngle, vec3 fragEyeDir, vec3 normal, float roughness,
float metallic, vec3 fresnel, vec3 albedo, float shadow,
float scattering, vec3 midNormal, vec3 lowNormal, float curvature) {
// Allright we re valid in the volume
float fragLightDistance = fragLightDirLen.w;
vec3 fragLightDir = fragLightDirLen.xyz;
// Eval attenuation
float radialAttenuation = evalLightAttenuation(light, fragLightDistance);
float angularAttenuation = evalLightSpotAttenuation(light, cosSpotAngle);
vec3 lightEnergy = angularAttenuation * radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light);
// Eval shading
evalFragShading(diffuse, specular,
normal, fragLightDir, fragEyeDir,
metallic, fresnel, roughness,
scattering, midNormalCurvature, lowNormalCurvature);
,scattering, midNormalCurvature, lowNormalCurvature
<@endif@>
);
diffuse *= albedo * lightEnergy;
specular *= lightEnergy;
if (getLightShowContour(light) > 0.0) {
@ -83,8 +52,6 @@ void evalLightingSpotScattering(out vec3 diffuse, out vec3 specular, Light light
}
}
<@endif@>
<@endfunc@>

View file

@ -143,10 +143,17 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float m
<$declareEvalPBRShading()$>
// Return xyz the specular/reflection component and w the diffuse component
vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 fresnel, float roughness) {
return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, fresnel, roughness);
}
//vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 fresnel, float roughness) {
// return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, fresnel, roughness);
//}
void evalFragShading(out vec3 diffuse, out vec3 specular,
vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir,
float metallic, vec3 fresnel, float roughness) {
vec4 shading = evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, fresnel, roughness);
diffuse = vec3(shading.w);
specular = shading.xyz;
}
<$declareBeckmannSpecular()$>
<@include SubsurfaceScattering.slh@>

View file

@ -16,6 +16,7 @@
<@include DeferredGlobalLight.slh@>
<$declareEvalLightmappedColor()$>
<$declareEvalAmbientSphereGlobalColor(supportScattering)$>
@ -29,24 +30,26 @@ void main(void) {
float shadowAttenuation = 1.0;
if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
// _fragColor = vec4(frag.diffuse, 1.0);
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard;
} else {
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texcoord0, midNormalCurvature, lowNormalCurvature);
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
}
vec3 color = evalAmbientSphereGlobalColorScattering(
vec3 color = evalAmbientSphereGlobalColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
@ -54,7 +57,7 @@ void main(void) {
frag.normal,
frag.diffuse,
frag.metallic,
frag.emissive,
// frag.emissive,
frag.roughness,
frag.scattering,
midNormalCurvature,

View file

@ -17,7 +17,7 @@
<@include DeferredGlobalLight.slh@>
<$declareEvalLightmappedColor()$>
<$declareEvalAmbientSphereGlobalColor()$>
<$declareEvalAmbientSphereGlobalColor(isScattering)$>
in vec2 _texCoord0;
out vec4 _fragColor;
@ -30,17 +30,24 @@ void main(void) {
float shadowAttenuation = evalShadowAttenuation(worldPos);
if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
// _fragColor = vec4(frag.diffuse, 1.0);
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard;
} else {
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
}
vec3 color = evalAmbientSphereGlobalColor(
getViewInverse(),
shadowAttenuation,
@ -49,8 +56,12 @@ void main(void) {
frag.normal,
frag.diffuse,
frag.metallic,
frag.emissive,
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);
// frag.emissive,
frag.roughness,
frag.scattering,
midNormalCurvature,
lowNormalCurvature);
_fragColor = vec4(color, 1.0);
}
}

View file

@ -29,16 +29,18 @@ void main(void) {
// Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
// _fragColor = vec4(frag.diffuse, 1.0);
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor(
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);
_fragColor = vec4(color, 1.0);*/
discard;
} else {
vec3 color = evalAmbientGlobalColor(
getViewInverse(),
@ -48,8 +50,8 @@ void main(void) {
frag.normal,
frag.diffuse,
frag.metallic,
frag.emissive,
// frag.emissive,
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);
_fragColor = vec4(color, 1.0);
}
}

View file

@ -31,16 +31,18 @@ void main(void) {
// Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
// _fragColor = vec4(frag.diffuse, 1.0);
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard;
} else {
vec3 color = evalAmbientGlobalColor(
getViewInverse(),
@ -50,8 +52,8 @@ void main(void) {
frag.normal,
frag.diffuse,
frag.metallic,
frag.emissive,
// frag.emissive,
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);
_fragColor = vec4(color, 1.0);
}
}

View file

@ -16,7 +16,7 @@
<@include DeferredGlobalLight.slh@>
<$declareEvalLightmappedColor()$>
<$declareEvalSkyboxGlobalColor(supportScattering)$>
<$declareEvalSkyboxGlobalColor(isScattering)$>
in vec2 _texCoord0;
out vec4 _fragColor;
@ -29,23 +29,25 @@ void main(void) {
// Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
// _fragColor = vec4(frag.diffuse, 1.0);
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard;
} else {
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texcoord0, midNormalCurvature, lowNormalCurvature);
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
}
vec3 color = evalSkyboxGlobalColorScattering(
vec3 color = evalSkyboxGlobalColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
@ -53,7 +55,7 @@ void main(void) {
frag.normal,
frag.diffuse,
frag.metallic,
frag.emissive,
// frag.emissive,
frag.roughness,
frag.scattering,
midNormalCurvature,

View file

@ -17,7 +17,7 @@
<@include DeferredGlobalLight.slh@>
<$declareEvalLightmappedColor()$>
<$declareEvalSkyboxGlobalColor()$>
<$declareEvalSkyboxGlobalColor(isScattering)$>
in vec2 _texCoord0;
out vec4 _fragColor;
@ -31,17 +31,24 @@ void main(void) {
// Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
// _fragColor = vec4(frag.diffuse, 1.0);
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard;
} else {
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
}
vec3 color = evalSkyboxGlobalColor(
getViewInverse(),
shadowAttenuation,
@ -50,9 +57,13 @@ void main(void) {
frag.normal,
frag.diffuse,
frag.metallic,
frag.emissive,
frag.roughness);
//frag.emissive,
frag.roughness,
frag.scattering,
midNormalCurvature,
lowNormalCurvature);
_fragColor = vec4(color, frag.normalVal.a);
_fragColor = vec4(color, 1.0);
}
}

View file

@ -11,13 +11,19 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include LightingModel.slh@>
<@include model/Light.slh@>
<@include LightingModel.slh@>
<$declareLightingModel()$>
<@include LightDirectional.slh@>
<$declareLightingDirectional()$>
<@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$>
vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 specular, float roughness, float opacity) {
vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 fresnel, float roughness, float opacity) {
// Need the light now
Light light = getLight();
@ -30,9 +36,12 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a
vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(light);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, specular, roughness);
color += vec3(albedo * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light);
// Directional
vec3 directionalDiffuse;
vec3 directionalSpecular;
evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation);
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled();
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();
return vec4(color, opacity);
}

View file

@ -12,13 +12,18 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include LightingModel.slh@>
<@include model/Light.slh@>
<@include LightingModel.slh@>
<$declareLightingModel()$>
<@include LightDirectional.slh@>
<$declareLightingDirectional()$>
<@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$>
vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 specular, float roughness, float opacity) {
vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 fresnel, float roughness, float opacity) {
// Need the light now
Light light = getLight();
@ -31,9 +36,12 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a
vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(light);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, specular, roughness);
color += vec3(albedo * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light);
// Directional
vec3 directionalDiffuse;
vec3 directionalSpecular;
evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation);
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled();
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();
return vec4(color, opacity);
}

View file

@ -68,23 +68,15 @@ void main(void) {
vec3 diffuse;
vec3 specular;
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) {
vec4 blurredCurvature = fetchCurvature(texCoord);
vec4 diffusedCurvature = fetchDiffusedCurvature(texCoord);
vec3 midNormal = normalize((blurredCurvature.xyz - 0.5f) * 2.0f);
vec3 lowNormal = normalize((diffusedCurvature.xyz - 0.5f) * 2.0f);
float highCurvature = unpackCurvature(blurredCurvature.w);
float lowCurvature = unpackCurvature(diffusedCurvature.w);
evalLightingPointScattering(diffuse, specular, light,
fragLightVecLen2.xyz, fragEyeDir, frag.normal, frag.roughness,
frag.metallic, frag.specular, frag.diffuse, 1.0,
frag.scattering * isScatteringEnabled(), midNormal, lowNormal, lowCurvature);
} else {
evalLightingPoint(diffuse, specular, light,
fragLightVecLen2.xyz, fragEyeDir, frag.normal, frag.roughness,
frag.metallic, frag.specular, frag.diffuse, 1.0);
unpackMidLowNormalCurvature(texCoord, midNormalCurvature, lowNormalCurvature);
}
evalLightingPoint(diffuse, specular, light,
fragLightVecLen2.xyz, fragEyeDir, frag.normal, frag.roughness,
frag.metallic, frag.specular, frag.diffuse, 1.0,
frag.scattering * isScatteringEnabled(), midNormalCurvature, lowNormalCurvature);
_fragColor.rgb += diffuse * isDiffuseEnabled() * isPointEnabled();
_fragColor.rgb += specular * isSpecularEnabled() * isPointEnabled();

View file

@ -70,22 +70,15 @@ void main(void) {
vec3 diffuse;
vec3 specular;
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) {
vec4 blurredCurvature = fetchCurvature(texCoord);
vec4 diffusedCurvature = fetchDiffusedCurvature(texCoord);
vec3 midNormal = normalize((blurredCurvature.xyz - 0.5f) * 2.0f);
vec3 lowNormal = normalize((diffusedCurvature.xyz - 0.5f) * 2.0f);
float highCurvature = unpackCurvature(blurredCurvature.w);
float lowCurvature = unpackCurvature(diffusedCurvature.w);
evalLightingSpotScattering(diffuse, specular, light,
fragLightDirLen.xyzw, cosSpotAngle, fragEyeDir, frag.normal, frag.roughness,
frag.metallic, frag.specular, frag.diffuse, 1.0,
frag.scattering * isScatteringEnabled(), midNormal, lowNormal, lowCurvature);
} else {
evalLightingSpot(diffuse, specular, light,
fragLightDirLen.xyzw, cosSpotAngle, fragEyeDir, frag.normal, frag.roughness,
frag.metallic, frag.specular, frag.diffuse, 1.0);
unpackMidLowNormalCurvature(texCoord, midNormalCurvature, lowNormalCurvature);
}
evalLightingSpot(diffuse, specular, light,
fragLightDirLen.xyzw, cosSpotAngle, fragEyeDir, frag.normal, frag.roughness,
frag.metallic, frag.specular, frag.diffuse, 1.0,
frag.scattering * isScatteringEnabled(), midNormalCurvature, lowNormalCurvature);
_fragColor.rgb += diffuse * isDiffuseEnabled() * isSpotEnabled();
_fragColor.rgb += specular * isSpecularEnabled() * isSpotEnabled();