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 <GPUIdent.h>
#include <NumericalConstants.h> #include <NumericalConstants.h>
#include <fstream>
Q_LOGGING_CATEGORY(gpugllogging, "hifi.gpu.gl") 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 compilation fails
if (!compiled) { if (!compiled) {
// save the source code to a temp file so we can debug easily // save the source code to a temp file so we can debug easily
/* std::ofstream filestream; std::ofstream filestream;
filestream.open("debugshader.glsl"); filestream.open("debugshader.glsl");
if (filestream.is_open()) { if (filestream.is_open()) {
filestream << shaderSource->source; filestream << srcstr[0];
filestream << srcstr[1];
filestream.close(); filestream.close();
} }
*/
GLint infoLength = 0; GLint infoLength = 0;
glGetShaderiv(glshader, GL_INFO_LOG_LENGTH, &infoLength); glGetShaderiv(glshader, GL_INFO_LOG_LENGTH, &infoLength);

View file

@ -33,9 +33,6 @@ uniform sampler2D lightingMap;
struct DeferredFragment { struct DeferredFragment {
vec4 normalVal;
vec4 diffuseVal;
vec4 specularVal;
vec4 position; vec4 position;
vec3 normal; vec3 normal;
float metallic; float metallic;
@ -43,44 +40,47 @@ struct DeferredFragment {
float obscurance; float obscurance;
vec3 specular; vec3 specular;
float roughness; float roughness;
vec3 emissive; // vec3 emissive;
int mode; int mode;
float scattering; float scattering;
float depthVal; float depthVal;
}; };
DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) {
vec4 normalVal;
vec4 diffuseVal;
vec4 specularVal;
DeferredFragment frag; DeferredFragment frag;
frag.depthVal = -1; frag.depthVal = -1;
frag.normalVal = texture(normalMap, texcoord); normalVal = texture(normalMap, texcoord);
frag.diffuseVal = texture(albedoMap, texcoord); diffuseVal = texture(albedoMap, texcoord);
frag.specularVal = texture(specularMap, texcoord); specularVal = texture(specularMap, texcoord);
frag.obscurance = texture(obscuranceMap, texcoord).x; frag.obscurance = texture(obscuranceMap, texcoord).x;
// Unpack the normal from the map // Unpack the normal from the map
frag.normal = unpackNormal(frag.normalVal.xyz); frag.normal = unpackNormal(normalVal.xyz);
frag.roughness = frag.normalVal.a; frag.roughness = normalVal.a;
// Diffuse color and unpack the mode and the metallicness // Diffuse color and unpack the mode and the metallicness
frag.diffuse = frag.diffuseVal.xyz; frag.diffuse = diffuseVal.xyz;
frag.scattering = 0.0; 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.emissive = specularVal.xyz;
frag.obscurance = min(frag.specularVal.w, frag.obscurance); frag.obscurance = min(specularVal.w, frag.obscurance);
if (frag.mode == FRAG_MODE_SCATTERING) { if (frag.mode == FRAG_MODE_SCATTERING) {
frag.scattering = frag.emissive.x; frag.scattering = specularVal.x;
frag.emissive = vec3(0.0); //frag.emissive = vec3(0.0);
} }
if (frag.metallic <= 0.5) { if (frag.metallic <= 0.5) {
frag.metallic = 0.0; frag.metallic = 0.0;
frag.specular = vec3(0.03); // Default Di-electric fresnel value frag.specular = vec3(0.03); // Default Di-electric fresnel value
} else { } else {
frag.specular = vec3(frag.diffuseVal.xyz); frag.specular = vec3(diffuseVal.xyz);
frag.metallic = 1.0; frag.metallic = 1.0;
} }
@ -135,9 +135,9 @@ vec4 fetchDiffusedCurvature(vec2 texcoord) {
return texture(diffusedCurvatureMap, texcoord); return texture(diffusedCurvatureMap, texcoord);
} }
void unpackMidLowNormalCurvature(vec2 texcoord, out vec4 midNormalCurvature, out vec4 vec4 lowNormalCurvature) { void unpackMidLowNormalCurvature(vec2 texcoord, out vec4 midNormalCurvature, out vec4 lowNormalCurvature) {
midNormalCurvature = fetchCurvature(_texCoord0); midNormalCurvature = fetchCurvature(texcoord);
lowNormalCurvature = fetchDiffusedCurvature(_texCoord0); lowNormalCurvature = fetchDiffusedCurvature(texcoord);
midNormalCurvature.xyz = normalize((midNormalCurvature.xyz - 0.5f) * 2.0f); midNormalCurvature.xyz = normalize((midNormalCurvature.xyz - 0.5f) * 2.0f);
lowNormalCurvature.xyz = normalize((lowNormalCurvature.xyz - 0.5f) * 2.0f); lowNormalCurvature.xyz = normalize((lowNormalCurvature.xyz - 0.5f) * 2.0f);
midNormalCurvature.w = (midNormalCurvature.w * 2 - 1); 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 = 1) out vec4 _fragColor1;
layout(location = 2) out vec4 _fragColor2; layout(location = 2) out vec4 _fragColor2;
layout(location = 3) out vec4 _fragColor3;
// the alpha threshold // the alpha threshold
const float alphaThreshold = 0.5; 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))); _fragColor0 = vec4(albedo, ((scattering > 0.0) ? packScatteringMetallic(metallic) : packShadedMetallic(metallic)));
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
_fragColor2 = vec4(((scattering > 0.0) ? vec3(scattering) : emissive), occlusion); _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) { if (alpha != 1.0) {
discard; discard;
} }
_fragColor0 = vec4(albedo, packLightmappedMetallic(metallic)); _fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); _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) { void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {
@ -59,6 +64,8 @@ void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {
_fragColor0 = vec4(color, packUnlit()); _fragColor0 = vec4(color, packUnlit());
_fragColor1 = vec4(packNormal(normal), 1.0); _fragColor1 = vec4(packNormal(normal), 1.0);
//_fragColor2 = vec4(vec3(0.0), 1.0); // If unlit, do not worry about the emissive color target //_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) { void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) {

View file

@ -12,7 +12,6 @@
<@def DEFERRED_GLOBAL_LIGHT_SLH@> <@def DEFERRED_GLOBAL_LIGHT_SLH@>
<@include model/Light.slh@> <@include model/Light.slh@>
<!<@include DeferredLighting.slh@>!>
<@include LightingModel.slh@> <@include LightingModel.slh@>
<$declareLightingModel()$> <$declareLightingModel()$>
@ -35,9 +34,9 @@
<@if isScattering@> <@if isScattering@>
<@else@> <@else@>
color += emissive * isEmissiveEnabled(); // color += emissive * isEmissiveEnabled();
<@endif@> <@endif@>
//color += emissive * isEmissiveEnabled();
vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value
if (metallic > 0.5) { if (metallic > 0.5) {
fresnel = albedo; fresnel = albedo;
@ -48,7 +47,7 @@
<@func declareEvalAmbientGlobalColor()@> <@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()$> <$prepareGlobalLight()$>
color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light); color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light);
return color; return color;
@ -60,45 +59,27 @@ vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obsc
<$declareLightingAmbient(1, 0, 0, supportScattering)$> <$declareLightingAmbient(1, 0, 0, supportScattering)$>
<$declareLightingDirectional(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@> <@if supportScattering@>
<$declareDeferredCurvature()$> <$declareDeferredCurvature()$>
<@endif@>
vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 evalAmbientSphereGlobalColor(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 albedo, float metallic, float roughness
<@if supportScattering@>
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@>
) {
<$prepareGlobalLight(1)$> <$prepareGlobalLight(supportScattering)$>
// Ambient // Ambient
vec3 ambientDiffuse; vec3 ambientDiffuse;
vec3 ambientSpecular; vec3 ambientSpecular;
evalLightingAmbientScattering(ambientDiffuse, ambientSpecular, light, evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance
fragEyeDir, fragNormal, roughness, <@if supportScattering@>
metallic, fresnel, albedo, obscurance, ,scattering, midNormalCurvature, lowNormalCurvature
isScatteringEnabled() * scattering, midNormalCurvature, lowNormalCurvature); <@endif@>
);
color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled(); color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled();
color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled(); color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled();
@ -106,18 +87,17 @@ vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenua
// Directional // Directional
vec3 directionalDiffuse; vec3 directionalDiffuse;
vec3 directionalSpecular; vec3 directionalSpecular;
evalLightingDirectionalScattering(directionalDiffuse, directionalSpecular, light, evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation
fragEyeDir, fragNormal, roughness, <@if supportScattering@>
metallic, fresnel, albedo, shadowAttenuation, ,scattering, midNormalCurvature, lowNormalCurvature
isScatteringEnabled() * scattering, midNormalCurvature, lowNormalCurvature); <@endif@>
);
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled();
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled(); color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();
return color; return color;
} }
<@endif@>
<@endfunc@> <@endfunc@>
@ -126,13 +106,26 @@ vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenua
<$declareLightingAmbient(0, 1, 0, supportScattering)$> <$declareLightingAmbient(0, 1, 0, supportScattering)$>
<$declareLightingDirectional(supportScattering)$> <$declareLightingDirectional(supportScattering)$>
vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) { <@if supportScattering@>
<$prepareGlobalLight()$> <$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 // Ambient
vec3 ambientDiffuse; vec3 ambientDiffuse;
vec3 ambientSpecular; 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 += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled();
color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled(); color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled();
@ -140,45 +133,17 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu
// Directional // Directional
vec3 directionalDiffuse; vec3 directionalDiffuse;
vec3 directionalSpecular; 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 += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled();
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled(); color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();
return color; 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@> <@endfunc@>
<@func declareEvalLightmappedColor()@> <@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) { vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness, float opacity) {
<$prepareGlobalLight()$> <$prepareGlobalLight()$>
color += emissive * isEmissiveEnabled();
// Ambient // Ambient
vec3 ambientDiffuse; 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); state->setDepthTest(true, false, gpu::LESS_EQUAL);
// TODO: We should use DepthClamp and avoid changing geometry for inside /outside cases // TODO: We should use DepthClamp and avoid changing geometry for inside /outside cases
// additive blending // additive blending
state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
} else { } else {
state->setCullMode(gpu::State::CULL_BACK); 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); pipeline = gpu::Pipeline::create(program, state);
@ -334,11 +336,11 @@ void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderC
batch.setStateScissorRect(args->_viewport); batch.setStateScissorRect(args->_viewport);
// Clear Lighting buffer // Clear Lighting buffer
auto lightingFbo = DependencyManager::get<FramebufferCache>()->getLightingFramebuffer(); /* auto lightingFbo = DependencyManager::get<FramebufferCache>()->getLightingFramebuffer();
batch.setFramebuffer(lightingFbo); batch.setFramebuffer(lightingFbo);
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, vec4(vec3(0), 0), true); batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, vec4(vec3(0), 0), true);
*/
// Clear deferred // Clear deferred
auto deferredFbo = DependencyManager::get<FramebufferCache>()->getDeferredFramebuffer(); auto deferredFbo = DependencyManager::get<FramebufferCache>()->getDeferredFramebuffer();

View file

@ -104,6 +104,7 @@ void FramebufferCache::createPrimaryFramebuffer() {
_lightingFramebuffer->setRenderBuffer(0, _lightingTexture); _lightingFramebuffer->setRenderBuffer(0, _lightingTexture);
_lightingFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _lightingFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
_deferredFramebuffer->setRenderBuffer(3, _lightingTexture);
// For AO: // For AO:
auto pointMipSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_POINT); 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@> <@endfunc@>
<@func declareLightingAmbient(supportAmbientSphere, supportAmbientMap, supportIfAmbientMapElseAmbientSphere, supportScattering)@> <@func declareLightingAmbient(supportAmbientSphere1, supportAmbientMap1, supportIfAmbientMapElseAmbientSphere1, supportScattering)@>
<$declareEvalAmbientSpecularIrradiance(supportAmbientSphere, supportAmbientMap, supportIfAmbientMapElseAmbientSphere)$> <$declareEvalAmbientSpecularIrradiance(supportAmbientSphere1, supportAmbientMap1, supportIfAmbientMapElseAmbientSphere1)$>
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);
}
<@if supportScattering@> <@if supportScattering@>
<!<@include SubsurfaceScattering.slh@>!>
float curvatureAO(in float k) { float curvatureAO(in float k) {
return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369; return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369;
} }
<@endif@>
void evalLightingAmbientScattering(out vec3 diffuse, out vec3 specular, Light light, void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3 eyeDir, vec3 normal,
vec3 eyeDir, vec3 normal, float roughness, float roughness, float metallic, vec3 fresnel, vec3 albedo, float obscurance
float metallic, vec3 fresnel, vec3 albedo, float obscurance, <@if supportScattering@>
float scatttering, vec3 lowNormal, float highCurvature, float lowCurvature) { , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@>
) {
float ambientOcclusion = curvatureAO(lowCurvature * 20.0f) * 0.5f; <@if supportScattering@>
float ambientOcclusionHF = curvatureAO(highCurvature * 8.0f) * 0.5f;
float ambientOcclusion = curvatureAO(lowNormalCurvature.w * 20.0f) * 0.5f;
float ambientOcclusionHF = curvatureAO(midNormalCurvature.w * 8.0f) * 0.5f;
ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF); ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF);
/* if (showCurvature()) { /* if (showCurvature()) {
diffuse = vec3(ambientOcclusion); diffuse = vec3(ambientOcclusion);
specular = vec3(0.0); specular = vec3(0.0);
return; return;
}*/ }*/
// Diffuse from ambient // 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 // Specular highlight from ambient
// vec3 specularLighting = evalGlobalSpecularIrradiance(light, fragEyeDir, fragNormal, roughness, fresnel); // 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 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); 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@> <@endfunc@>

View file

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

View file

@ -11,12 +11,13 @@
<@func declareLightingPoint(supportScattering)@> <@func declareLightingPoint(supportScattering)@>
<@include DeferredLighting.slh@>
void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light, void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light,
vec3 fragLightVec, vec3 fragEyeDir, vec3 normal, float roughness, 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 // Allright we re valid in the volume
float fragLightDistance = length(fragLightVec); 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); vec3 lightEnergy = radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light);
// Eval shading // Eval shading
vec4 shading = evalFragShading(normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness); evalFragShading(diffuse, specular, 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));
}
}
}
<@if supportScattering@> <@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature
void evalLightingPointScattering(out vec3 diffuse, out vec3 specular, Light light, <@endif@>
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);
diffuse *= albedo * lightEnergy; diffuse *= albedo * lightEnergy;
@ -80,8 +49,6 @@ void evalLightingPointScattering(out vec3 diffuse, out vec3 specular, Light ligh
} }
} }
<@endif@>
<@endfunc@> <@endfunc@>

View file

@ -13,7 +13,11 @@
void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light, void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light,
vec4 fragLightDirLen, float cosSpotAngle, vec3 fragEyeDir, vec3 normal, float roughness, 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 // Allright we re valid in the volume
float fragLightDistance = fragLightDirLen.w; 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); vec3 lightEnergy = angularAttenuation * radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light);
// Eval shading // Eval shading
vec4 shading = evalFragShading(normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness); evalFragShading(diffuse, specular, 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));
}
}
}
<@if supportScattering@> <@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature
void evalLightingSpotScattering(out vec3 diffuse, out vec3 specular, Light light, <@endif@>
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);
diffuse *= albedo * lightEnergy; diffuse *= albedo * lightEnergy;
specular *= lightEnergy; specular *= lightEnergy;
if (getLightShowContour(light) > 0.0) { if (getLightShowContour(light) > 0.0) {
@ -83,8 +52,6 @@ void evalLightingSpotScattering(out vec3 diffuse, out vec3 specular, Light light
} }
} }
<@endif@>
<@endfunc@> <@endfunc@>

View file

@ -143,10 +143,17 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float m
<$declareEvalPBRShading()$> <$declareEvalPBRShading()$>
// Return xyz the specular/reflection component and w the diffuse component // 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) { //vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 fresnel, float roughness) {
return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, fresnel, 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()$> <$declareBeckmannSpecular()$>
<@include SubsurfaceScattering.slh@> <@include SubsurfaceScattering.slh@>

View file

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

View file

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

View file

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

View file

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

View file

@ -17,7 +17,7 @@
<@include DeferredGlobalLight.slh@> <@include DeferredGlobalLight.slh@>
<$declareEvalLightmappedColor()$> <$declareEvalLightmappedColor()$>
<$declareEvalSkyboxGlobalColor()$> <$declareEvalSkyboxGlobalColor(isScattering)$>
in vec2 _texCoord0; in vec2 _texCoord0;
out vec4 _fragColor; out vec4 _fragColor;
@ -31,17 +31,24 @@ void main(void) {
// Light mapped or not ? // Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) { 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) { } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor( /* vec3 color = evalLightmappedColor(
getViewInverse(), getViewInverse(),
shadowAttenuation, shadowAttenuation,
frag.obscurance, frag.obscurance,
frag.normal, frag.normal,
frag.diffuse, frag.diffuse,
frag.specularVal.xyz); frag.specularVal.xyz);
_fragColor = vec4(color, 1.0); _fragColor = vec4(color, 1.0);*/
discard;
} else { } else {
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
}
vec3 color = evalSkyboxGlobalColor( vec3 color = evalSkyboxGlobalColor(
getViewInverse(), getViewInverse(),
shadowAttenuation, shadowAttenuation,
@ -50,9 +57,13 @@ void main(void) {
frag.normal, frag.normal,
frag.diffuse, frag.diffuse,
frag.metallic, frag.metallic,
frag.emissive, //frag.emissive,
frag.roughness); 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 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include LightingModel.slh@>
<@include model/Light.slh@> <@include model/Light.slh@>
<@include LightingModel.slh@>
<$declareLightingModel()$>
<@include LightDirectional.slh@>
<$declareLightingDirectional()$>
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$> <$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 // Need the light now
Light light = getLight(); 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); vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(light);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, specular, roughness); // Directional
vec3 directionalDiffuse;
color += vec3(albedo * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light); 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); 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 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include LightingModel.slh@>
<@include model/Light.slh@> <@include model/Light.slh@>
<@include LightingModel.slh@>
<$declareLightingModel()$>
<@include LightDirectional.slh@>
<$declareLightingDirectional()$>
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$> <$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 // Need the light now
Light light = getLight(); 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); vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(light);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, specular, roughness); // Directional
vec3 directionalDiffuse;
color += vec3(albedo * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light); 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); return vec4(color, opacity);
} }

View file

@ -68,23 +68,15 @@ void main(void) {
vec3 diffuse; vec3 diffuse;
vec3 specular; vec3 specular;
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) { if (frag.mode == FRAG_MODE_SCATTERING) {
vec4 blurredCurvature = fetchCurvature(texCoord); unpackMidLowNormalCurvature(texCoord, midNormalCurvature, lowNormalCurvature);
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);
} }
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 += diffuse * isDiffuseEnabled() * isPointEnabled();
_fragColor.rgb += specular * isSpecularEnabled() * isPointEnabled(); _fragColor.rgb += specular * isSpecularEnabled() * isPointEnabled();

View file

@ -70,22 +70,15 @@ void main(void) {
vec3 diffuse; vec3 diffuse;
vec3 specular; vec3 specular;
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) { if (frag.mode == FRAG_MODE_SCATTERING) {
vec4 blurredCurvature = fetchCurvature(texCoord); unpackMidLowNormalCurvature(texCoord, midNormalCurvature, lowNormalCurvature);
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);
} }
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 += diffuse * isDiffuseEnabled() * isSpotEnabled();
_fragColor.rgb += specular * isSpecularEnabled() * isSpotEnabled(); _fragColor.rgb += specular * isSpecularEnabled() * isSpotEnabled();