mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
Merge pull request #4126 from samcake/temp1
Remove glMaterial from Entity rendering, Add Ambient Sphere lighting
This commit is contained in:
commit
9beb493a45
35 changed files with 886 additions and 180 deletions
|
@ -2797,7 +2797,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs
|
|||
}
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
DependencyManager::get<DeferredLightingEffect>()->prepare();
|
||||
|
||||
if (!selfAvatarOnly) {
|
||||
|
@ -2848,6 +2848,8 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs
|
|||
|
||||
|
||||
{
|
||||
DependencyManager::get<DeferredLightingEffect>()->setAmbientLightMode(getRenderAmbientLight());
|
||||
|
||||
PROFILE_RANGE("DeferredLighting");
|
||||
PerformanceTimer perfTimer("lighting");
|
||||
DependencyManager::get<DeferredLightingEffect>()->render();
|
||||
|
@ -3973,3 +3975,31 @@ float Application::getRenderResolutionScale() const {
|
|||
return 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
int Application::getRenderAmbientLight() const {
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLightGlobal)) {
|
||||
return -1;
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLight0)) {
|
||||
return 0;
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLight1)) {
|
||||
return 1;
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLight2)) {
|
||||
return 2;
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLight3)) {
|
||||
return 3;
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLight4)) {
|
||||
return 4;
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLight5)) {
|
||||
return 5;
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLight6)) {
|
||||
return 6;
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLight7)) {
|
||||
return 7;
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLight8)) {
|
||||
return 8;
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderAmbientLight9)) {
|
||||
return 9;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -287,6 +287,7 @@ public:
|
|||
bool isLookingAtMyAvatar(Avatar* avatar);
|
||||
|
||||
float getRenderResolutionScale() const;
|
||||
int getRenderAmbientLight() const;
|
||||
|
||||
unsigned int getRenderTargetFramerate() const;
|
||||
bool isVSyncOn() const;
|
||||
|
|
|
@ -343,6 +343,21 @@ Menu::Menu() :
|
|||
addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::AmbientOcclusion);
|
||||
addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::DontFadeOnOctreeServerChanges);
|
||||
addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::DisableAutoAdjustLOD);
|
||||
|
||||
QMenu* ambientLightMenu = renderOptionsMenu->addMenu(MenuOption::RenderAmbientLight);
|
||||
QActionGroup* ambientLightGroup = new QActionGroup(ambientLightMenu);
|
||||
ambientLightGroup->setExclusive(true);
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLightGlobal, 0, true));
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLight0, 0, false));
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLight1, 0, false));
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLight2, 0, false));
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLight3, 0, false));
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLight4, 0, false));
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLight5, 0, false));
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLight6, 0, false));
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLight7, 0, false));
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLight8, 0, false));
|
||||
ambientLightGroup->addAction(addCheckableActionToQMenuAndActionHash(ambientLightMenu, MenuOption::RenderAmbientLight9, 0, false));
|
||||
|
||||
QMenu* shadowMenu = renderOptionsMenu->addMenu("Shadows");
|
||||
QActionGroup* shadowGroup = new QActionGroup(shadowMenu);
|
||||
|
|
|
@ -440,6 +440,18 @@ namespace MenuOption {
|
|||
const QString RenderResolutionHalf = "1/2";
|
||||
const QString RenderResolutionThird = "1/3";
|
||||
const QString RenderResolutionQuarter = "1/4";
|
||||
const QString RenderAmbientLight = "Ambient Light";
|
||||
const QString RenderAmbientLightGlobal = "Global";
|
||||
const QString RenderAmbientLight0 = "OLD_TOWN_SQUARE";
|
||||
const QString RenderAmbientLight1 = "GRACE_CATHEDRAL";
|
||||
const QString RenderAmbientLight2 = "EUCALYPTUS_GROVE";
|
||||
const QString RenderAmbientLight3 = "ST_PETERS_BASILICA";
|
||||
const QString RenderAmbientLight4 = "UFFIZI_GALLERY";
|
||||
const QString RenderAmbientLight5 = "GALILEOS_TOMB";
|
||||
const QString RenderAmbientLight6 = "VINE_STREET_KITCHEN";
|
||||
const QString RenderAmbientLight7 = "BREEZEWAY";
|
||||
const QString RenderAmbientLight8 = "CAMPUS_SUNSET";
|
||||
const QString RenderAmbientLight9 = "FUNSTON_BEACH_SUNSET";
|
||||
const QString ResetAvatarSize = "Reset Avatar Size";
|
||||
const QString ResetSensors = "Reset Sensors";
|
||||
const QString RunningScripts = "Running Scripts";
|
||||
|
|
|
@ -494,13 +494,16 @@ void GLBackend::do_setUniformBuffer(Batch& batch, uint32 paramOffset) {
|
|||
#if defined(Q_OS_MAC)
|
||||
GLfloat* data = (GLfloat*) (uniformBuffer->getData() + rangeStart);
|
||||
glUniform4fv(slot, rangeSize / sizeof(GLfloat[4]), data);
|
||||
#else
|
||||
|
||||
// NOT working so we ll stick to the uniform float array until we move to core profile
|
||||
// GLuint bo = getBufferID(*uniformBuffer);
|
||||
//glUniformBufferEXT(_shader._program, slot, bo);
|
||||
#elif defined(Q_OS_WIN)
|
||||
GLuint bo = getBufferID(*uniformBuffer);
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, slot, bo, rangeStart, rangeSize);
|
||||
|
||||
// glUniformBufferEXT(_shader._program, slot, bo);
|
||||
|
||||
//glBindBufferBase(GL_UNIFORM_BUFFER, slot, bo);
|
||||
#else
|
||||
GLfloat* data = (GLfloat*) (uniformBuffer->getData() + rangeStart);
|
||||
glUniform4fv(slot, rangeSize / sizeof(GLfloat[4]), data);
|
||||
#endif
|
||||
CHECK_GL_ERROR();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
<@if not DEFERRED_BUFFER_SLH@>
|
||||
<@def DEFERRED_BUFFER_SLH@>
|
||||
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -43,6 +42,10 @@ struct DeferredFragment {
|
|||
vec4 specularVal;
|
||||
vec4 position;
|
||||
vec3 normal;
|
||||
vec3 diffuse;
|
||||
float opacity;
|
||||
vec3 specular;
|
||||
float gloss;
|
||||
};
|
||||
|
||||
DeferredFragment unpackDeferredFragment(vec2 texcoord) {
|
||||
|
@ -59,6 +62,11 @@ DeferredFragment unpackDeferredFragment(vec2 texcoord) {
|
|||
// Unpack the normal from the map
|
||||
frag.normal = normalize(frag.normalVal.xyz * 2.0 - vec3(1.0));
|
||||
|
||||
frag.diffuse = frag.diffuseVal.xyz;
|
||||
frag.opacity = frag.diffuseVal.w;
|
||||
frag.specular = frag.specularVal.xyz;
|
||||
frag.gloss = frag.specularVal.w;
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
|
|
43
libraries/render-utils/src/DeferredBufferWrite.slh
Executable file
43
libraries/render-utils/src/DeferredBufferWrite.slh
Executable file
|
@ -0,0 +1,43 @@
|
|||
<!
|
||||
// DeferredBufferWrite.slh
|
||||
// libraries/render-utils/src
|
||||
//
|
||||
// Created by Sam Gateau on 1/12/15.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
!>
|
||||
<@if not DEFERRED_BUFFER_WRITE_SLH@>
|
||||
<@def DEFERRED_BUFFER_WRITE_SLH@>
|
||||
|
||||
// the glow intensity
|
||||
uniform float glowIntensity;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
float evalOpaqueFinalAlpha(float alpha, float mapAlpha) {
|
||||
return mix(alpha * glowIntensity, 1.0 - alpha * glowIntensity, step(mapAlpha, alphaThreshold));
|
||||
}
|
||||
|
||||
void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) {
|
||||
gl_FragData[0] = vec4(diffuse.rgb, alpha);
|
||||
gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[2] = vec4(specular, shininess / 128.0);
|
||||
}
|
||||
|
||||
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) {
|
||||
gl_FragData[0] = vec4(diffuse.rgb, alpha);
|
||||
//gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);
|
||||
gl_FragData[2] = vec4(emissive, shininess / 128.0);
|
||||
}
|
||||
|
||||
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) {
|
||||
gl_FragData[0] = vec4(diffuse.rgb, alpha);
|
||||
// gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
// gl_FragData[2] = vec4(specular, shininess / 128.0);
|
||||
}
|
||||
|
||||
<@endif@>
|
96
libraries/render-utils/src/DeferredLighting.slh
Executable file
96
libraries/render-utils/src/DeferredLighting.slh
Executable file
|
@ -0,0 +1,96 @@
|
|||
<!
|
||||
// DeferredLighting.slh
|
||||
// libraries/render-utils/src
|
||||
//
|
||||
// Created by Sam Gateau on 1/15/15.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
!>
|
||||
<@if not DEFERRED_LIGHTING_SLH@>
|
||||
<@def DEFERRED_LIGHTING_SLH@>
|
||||
|
||||
struct SphericalHarmonics {
|
||||
vec4 L00;
|
||||
vec4 L1m1;
|
||||
vec4 L10;
|
||||
vec4 L11;
|
||||
vec4 L2m2;
|
||||
vec4 L2m1;
|
||||
vec4 L20;
|
||||
vec4 L21;
|
||||
vec4 L22;
|
||||
};
|
||||
|
||||
vec4 evalSphericalLight(SphericalHarmonics sh, vec3 direction ) {
|
||||
|
||||
const float C1 = 0.429043;
|
||||
const float C2 = 0.511664;
|
||||
const float C3 = 0.743125;
|
||||
const float C4 = 0.886227;
|
||||
const float C5 = 0.247708;
|
||||
|
||||
vec4 value = C1 * sh.L22 * (direction.x * direction.x - direction.y * direction.y) +
|
||||
C3 * sh.L20 * direction.z * direction.z +
|
||||
C4 * sh.L00 - C5 * sh.L20 +
|
||||
2.0 * C1 * ( sh.L2m2 * direction.x * direction.y +
|
||||
sh.L21 * direction.x * direction.z +
|
||||
sh.L2m1 * direction.y * direction.z ) +
|
||||
2.0 * C2 * ( sh.L11 * direction.x +
|
||||
sh.L1m1 * direction.y +
|
||||
sh.L10 * direction.z ) ;
|
||||
return value;
|
||||
}
|
||||
|
||||
uniform SphericalHarmonics ambientSphere;
|
||||
|
||||
vec3 evalAmbientColor(vec3 normal, vec3 diffuse, vec3 specular, float gloss) {
|
||||
return diffuse.rgb * gl_FrontLightProduct[0].ambient.rgb;
|
||||
}
|
||||
|
||||
vec3 evalAmbientSphereColor(vec3 normal, vec3 diffuse, vec3 specular, float gloss) {
|
||||
vec3 ambientLight = 0.5 * evalSphericalLight(ambientSphere, normal).xyz;
|
||||
|
||||
return diffuse.rgb * ambientLight;
|
||||
}
|
||||
|
||||
vec3 evalDirectionalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss) {
|
||||
// Diffuse Lighting
|
||||
float diffuseDot = dot(normal, gl_LightSource[0].position.xyz);
|
||||
float facingLight = step(0.0, diffuseDot) * shadowAttenuation;
|
||||
vec3 diffuseColor = diffuse * (gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontLightProduct[0].diffuse.rgb * (diffuseDot * facingLight));
|
||||
|
||||
// compute the specular multiplier (sans exponent)
|
||||
float specularPower = facingLight * max(0.0,
|
||||
dot(normalize(gl_LightSource[0].position.xyz - normalize(position)), normal));
|
||||
vec3 specularColor = pow(specularPower, gloss * 128.0) * specular;
|
||||
|
||||
// add specular contribution
|
||||
return vec3(diffuseColor + specularColor);
|
||||
}
|
||||
|
||||
|
||||
vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) {
|
||||
|
||||
float diffuseDot = dot(normal, gl_LightSource[0].position.xyz);
|
||||
|
||||
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
||||
// it should be just 0, but we have innacurracy so we need to overshoot
|
||||
const float PERPENDICULAR_THRESHOLD = -0.005;
|
||||
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot);
|
||||
|
||||
// evaluate the shadow test but only relevant for light facing fragments
|
||||
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
|
||||
|
||||
// diffuse light is the lightmap dimmed by shadow
|
||||
vec3 diffuseLight = lightAttenuation * lightmap;
|
||||
|
||||
// ambient is a tiny percentage of the lightmap and only when in the shadow
|
||||
vec3 ambientLight = (1 - lightAttenuation) * 0.5 * lightmap;
|
||||
|
||||
return diffuse * (ambientLight + diffuseLight);
|
||||
}
|
||||
|
||||
|
||||
<@endif@>
|
|
@ -35,9 +35,152 @@
|
|||
#include "directional_light_shadow_map_frag.h"
|
||||
#include "directional_light_cascaded_shadow_map_frag.h"
|
||||
|
||||
#include "directional_ambient_light_frag.h"
|
||||
#include "directional_ambient_light_shadow_map_frag.h"
|
||||
#include "directional_ambient_light_cascaded_shadow_map_frag.h"
|
||||
|
||||
#include "point_light_frag.h"
|
||||
#include "spot_light_frag.h"
|
||||
|
||||
class SphericalHarmonics {
|
||||
public:
|
||||
glm::vec3 L00 ; float spare0;
|
||||
glm::vec3 L1m1 ; float spare1;
|
||||
glm::vec3 L10 ; float spare2;
|
||||
glm::vec3 L11 ; float spare3;
|
||||
glm::vec3 L2m2 ; float spare4;
|
||||
glm::vec3 L2m1 ; float spare5;
|
||||
glm::vec3 L20 ; float spare6;
|
||||
glm::vec3 L21 ; float spare7;
|
||||
glm::vec3 L22 ; float spare8;
|
||||
|
||||
static const int NUM_COEFFICIENTS = 9;
|
||||
|
||||
void assignPreset(int p) {
|
||||
switch (p) {
|
||||
case DeferredLightingEffect::OLD_TOWN_SQUARE: {
|
||||
L00 = glm::vec3( 0.871297f, 0.875222f, 0.864470f);
|
||||
L1m1 = glm::vec3( 0.175058f, 0.245335f, 0.312891f);
|
||||
L10 = glm::vec3( 0.034675f, 0.036107f, 0.037362f);
|
||||
L11 = glm::vec3(-0.004629f,-0.029448f,-0.048028f);
|
||||
L2m2 = glm::vec3(-0.120535f,-0.121160f,-0.117507f);
|
||||
L2m1 = glm::vec3( 0.003242f, 0.003624f, 0.007511f);
|
||||
L20 = glm::vec3(-0.028667f,-0.024926f,-0.020998f);
|
||||
L21 = glm::vec3(-0.077539f,-0.086325f,-0.091591f);
|
||||
L22 = glm::vec3(-0.161784f,-0.191783f,-0.219152f);
|
||||
}
|
||||
break;
|
||||
case DeferredLightingEffect::GRACE_CATHEDRAL: {
|
||||
L00 = glm::vec3( 0.79f, 0.44f, 0.54f);
|
||||
L1m1 = glm::vec3( 0.39f, 0.35f, 0.60f);
|
||||
L10 = glm::vec3(-0.34f, -0.18f, -0.27f);
|
||||
L11 = glm::vec3(-0.29f, -0.06f, 0.01f);
|
||||
L2m2 = glm::vec3(-0.11f, -0.05f, -0.12f);
|
||||
L2m1 = glm::vec3(-0.26f, -0.22f, -0.47f);
|
||||
L20 = glm::vec3(-0.16f, -0.09f, -0.15f);
|
||||
L21 = glm::vec3( 0.56f, 0.21f, 0.14f);
|
||||
L22 = glm::vec3( 0.21f, -0.05f, -0.30f);
|
||||
}
|
||||
break;
|
||||
case DeferredLightingEffect::EUCALYPTUS_GROVE: {
|
||||
L00 = glm::vec3( 0.38f, 0.43f, 0.45f);
|
||||
L1m1 = glm::vec3( 0.29f, 0.36f, 0.41f);
|
||||
L10 = glm::vec3( 0.04f, 0.03f, 0.01f);
|
||||
L11 = glm::vec3(-0.10f, -0.10f, -0.09f);
|
||||
L2m2 = glm::vec3(-0.06f, -0.06f, -0.04f);
|
||||
L2m1 = glm::vec3( 0.01f, -0.01f, -0.05f);
|
||||
L20 = glm::vec3(-0.09f, -0.13f, -0.15f);
|
||||
L21 = glm::vec3(-0.06f, -0.05f, -0.04f);
|
||||
L22 = glm::vec3( 0.02f, 0.00f, -0.05f);
|
||||
}
|
||||
break;
|
||||
case DeferredLightingEffect::ST_PETERS_BASILICA: {
|
||||
L00 = glm::vec3( 0.36f, 0.26f, 0.23f);
|
||||
L1m1 = glm::vec3( 0.18f, 0.14f, 0.13f);
|
||||
L10 = glm::vec3(-0.02f, -0.01f, 0.00f);
|
||||
L11 = glm::vec3( 0.03f, 0.02f, -0.00f);
|
||||
L2m2 = glm::vec3( 0.02f, 0.01f, -0.00f);
|
||||
L2m1 = glm::vec3(-0.05f, -0.03f, -0.01f);
|
||||
L20 = glm::vec3(-0.09f, -0.08f, -0.07f);
|
||||
L21 = glm::vec3( 0.01f, 0.00f, 0.00f);
|
||||
L22 = glm::vec3(-0.08f, -0.03f, -0.00f);
|
||||
}
|
||||
break;
|
||||
case DeferredLightingEffect::UFFIZI_GALLERY: {
|
||||
L00 = glm::vec3( 0.32f, 0.31f, 0.35f);
|
||||
L1m1 = glm::vec3( 0.37f, 0.37f, 0.43f);
|
||||
L10 = glm::vec3( 0.00f, 0.00f, 0.00f);
|
||||
L11 = glm::vec3(-0.01f, -0.01f, -0.01f);
|
||||
L2m2 = glm::vec3(-0.02f, -0.02f, -0.03f);
|
||||
L2m1 = glm::vec3(-0.01f, -0.01f, -0.01f);
|
||||
L20 = glm::vec3(-0.28f, -0.28f, -0.32f);
|
||||
L21 = glm::vec3( 0.00f, 0.00f, 0.00f);
|
||||
L22 = glm::vec3(-0.24f, -0.24f, -0.28f);
|
||||
}
|
||||
break;
|
||||
case DeferredLightingEffect::GALILEOS_TOMB: {
|
||||
L00 = glm::vec3( 1.04f, 0.76f, 0.71f);
|
||||
L1m1 = glm::vec3( 0.44f, 0.34f, 0.34f);
|
||||
L10 = glm::vec3(-0.22f, -0.18f, -0.17f);
|
||||
L11 = glm::vec3( 0.71f, 0.54f, 0.56f);
|
||||
L2m2 = glm::vec3( 0.64f, 0.50f, 0.52f);
|
||||
L2m1 = glm::vec3(-0.12f, -0.09f, -0.08f);
|
||||
L20 = glm::vec3(-0.37f, -0.28f, -0.32f);
|
||||
L21 = glm::vec3(-0.17f, -0.13f, -0.13f);
|
||||
L22 = glm::vec3( 0.55f, 0.42f, 0.42f);
|
||||
}
|
||||
break;
|
||||
case DeferredLightingEffect::VINE_STREET_KITCHEN: {
|
||||
L00 = glm::vec3( 0.64f, 0.67f, 0.73f);
|
||||
L1m1 = glm::vec3( 0.28f, 0.32f, 0.33f);
|
||||
L10 = glm::vec3( 0.42f, 0.60f, 0.77f);
|
||||
L11 = glm::vec3(-0.05f, -0.04f, -0.02f);
|
||||
L2m2 = glm::vec3(-0.10f, -0.08f, -0.05f);
|
||||
L2m1 = glm::vec3( 0.25f, 0.39f, 0.53f);
|
||||
L20 = glm::vec3( 0.38f, 0.54f, 0.71f);
|
||||
L21 = glm::vec3( 0.06f, 0.01f, -0.02f);
|
||||
L22 = glm::vec3(-0.03f, -0.02f, -0.03f);
|
||||
}
|
||||
break;
|
||||
case DeferredLightingEffect::BREEZEWAY: {
|
||||
L00 = glm::vec3( 0.32f, 0.36f, 0.38f);
|
||||
L1m1 = glm::vec3( 0.37f, 0.41f, 0.45f);
|
||||
L10 = glm::vec3(-0.01f, -0.01f, -0.01f);
|
||||
L11 = glm::vec3(-0.10f, -0.12f, -0.12f);
|
||||
L2m2 = glm::vec3(-0.13f, -0.15f, -0.17f);
|
||||
L2m1 = glm::vec3(-0.01f, -0.02f, 0.02f);
|
||||
L20 = glm::vec3(-0.07f, -0.08f, -0.09f);
|
||||
L21 = glm::vec3( 0.02f, 0.03f, 0.03f);
|
||||
L22 = glm::vec3(-0.29f, -0.32f, -0.36f);
|
||||
}
|
||||
break;
|
||||
case DeferredLightingEffect::CAMPUS_SUNSET: {
|
||||
L00 = glm::vec3( 0.79f, 0.94f, 0.98f);
|
||||
L1m1 = glm::vec3( 0.44f, 0.56f, 0.70f);
|
||||
L10 = glm::vec3(-0.10f, -0.18f, -0.27f);
|
||||
L11 = glm::vec3( 0.45f, 0.38f, 0.20f);
|
||||
L2m2 = glm::vec3( 0.18f, 0.14f, 0.05f);
|
||||
L2m1 = glm::vec3(-0.14f, -0.22f, -0.31f);
|
||||
L20 = glm::vec3(-0.39f, -0.40f, -0.36f);
|
||||
L21 = glm::vec3( 0.09f, 0.07f, 0.04f);
|
||||
L22 = glm::vec3( 0.67f, 0.67f, 0.52f);
|
||||
}
|
||||
break;
|
||||
case DeferredLightingEffect::FUNSTON_BEACH_SUNSET: {
|
||||
L00 = glm::vec3( 0.68f, 0.69f, 0.70f);
|
||||
L1m1 = glm::vec3( 0.32f, 0.37f, 0.44f);
|
||||
L10 = glm::vec3(-0.17f, -0.17f, -0.17f);
|
||||
L11 = glm::vec3(-0.45f, -0.42f, -0.34f);
|
||||
L2m2 = glm::vec3(-0.17f, -0.17f, -0.15f);
|
||||
L2m1 = glm::vec3(-0.08f, -0.09f, -0.10f);
|
||||
L20 = glm::vec3(-0.03f, -0.02f, -0.01f);
|
||||
L21 = glm::vec3( 0.16f, 0.14f, 0.10f);
|
||||
L22 = glm::vec3( 0.37f, 0.31f, 0.20f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
|
||||
_viewState = viewState;
|
||||
|
@ -54,6 +197,13 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
|
|||
_directionalLightShadowMapLocations);
|
||||
loadLightProgram(directional_light_cascaded_shadow_map_frag, false, _directionalLightCascadedShadowMap,
|
||||
_directionalLightCascadedShadowMapLocations);
|
||||
|
||||
loadLightProgram(directional_ambient_light_frag, false, _directionalAmbientSphereLight, _directionalAmbientSphereLightLocations);
|
||||
loadLightProgram(directional_ambient_light_shadow_map_frag, false, _directionalAmbientSphereLightShadowMap,
|
||||
_directionalAmbientSphereLightShadowMapLocations);
|
||||
loadLightProgram(directional_ambient_light_cascaded_shadow_map_frag, false, _directionalAmbientSphereLightCascadedShadowMap,
|
||||
_directionalAmbientSphereLightCascadedShadowMapLocations);
|
||||
|
||||
loadLightProgram(point_light_frag, true, _pointLight, _pointLightLocations);
|
||||
loadLightProgram(spot_light_frag, true, _spotLight, _spotLightLocations);
|
||||
}
|
||||
|
@ -169,7 +319,8 @@ void DeferredLightingEffect::render() {
|
|||
QOpenGLFramebufferObject* freeFBO = DependencyManager::get<GlowEffect>()->getFreeFramebufferObject();
|
||||
freeFBO->bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, primaryFBO->texture());
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
|
@ -205,18 +356,43 @@ void DeferredLightingEffect::render() {
|
|||
if (_viewState->getCascadeShadowsEnabled()) {
|
||||
program = &_directionalLightCascadedShadowMap;
|
||||
locations = &_directionalLightCascadedShadowMapLocations;
|
||||
_directionalLightCascadedShadowMap.bind();
|
||||
_directionalLightCascadedShadowMap.setUniform(locations->shadowDistances, _viewState->getShadowDistances());
|
||||
if (_ambientLightMode > -1) {
|
||||
program = &_directionalAmbientSphereLightCascadedShadowMap;
|
||||
locations = &_directionalAmbientSphereLightCascadedShadowMapLocations;
|
||||
}
|
||||
program->bind();
|
||||
program->setUniform(locations->shadowDistances, _viewState->getShadowDistances());
|
||||
|
||||
} else {
|
||||
if (_ambientLightMode > -1) {
|
||||
program = &_directionalAmbientSphereLightShadowMap;
|
||||
locations = &_directionalAmbientSphereLightShadowMapLocations;
|
||||
}
|
||||
program->bind();
|
||||
}
|
||||
program->setUniformValue(locations->shadowScale,
|
||||
1.0f / textureCache->getShadowFramebufferObject()->width());
|
||||
|
||||
} else {
|
||||
if (_ambientLightMode > -1) {
|
||||
program = &_directionalAmbientSphereLight;
|
||||
locations = &_directionalAmbientSphereLightLocations;
|
||||
}
|
||||
program->bind();
|
||||
}
|
||||
|
||||
if (locations->ambientSphere >= 0) {
|
||||
SphericalHarmonics sh;
|
||||
if (_ambientLightMode < NUM_PRESET) {
|
||||
sh.assignPreset(_ambientLightMode);
|
||||
} else {
|
||||
sh.assignPreset(0);
|
||||
}
|
||||
|
||||
for (int i =0; i <SphericalHarmonics::NUM_COEFFICIENTS; i++) {
|
||||
program->setUniformValue(locations->ambientSphere + i, *(((QVector4D*) &sh) + i));
|
||||
}
|
||||
}
|
||||
|
||||
float left, right, bottom, top, nearVal, farVal;
|
||||
glm::vec4 nearClipPlane, farClipPlane;
|
||||
|
@ -371,6 +547,7 @@ void DeferredLightingEffect::render() {
|
|||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
freeFBO->release();
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
|
@ -431,5 +608,12 @@ void DeferredLightingEffect::loadLightProgram(const char* fragSource, bool limit
|
|||
locations.depthTexCoordOffset = program.uniformLocation("depthTexCoordOffset");
|
||||
locations.depthTexCoordScale = program.uniformLocation("depthTexCoordScale");
|
||||
locations.radius = program.uniformLocation("radius");
|
||||
locations.ambientSphere = program.uniformLocation("ambientSphere.L00");
|
||||
program.release();
|
||||
}
|
||||
|
||||
void DeferredLightingEffect::setAmbientLightMode(int preset) {
|
||||
if ((preset >= -1) && (preset < NUM_PRESET)) {
|
||||
_ambientLightMode = preset;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,23 @@ public:
|
|||
void prepare();
|
||||
void render();
|
||||
|
||||
enum AmbientLightPreset {
|
||||
OLD_TOWN_SQUARE = 0,
|
||||
GRACE_CATHEDRAL,
|
||||
EUCALYPTUS_GROVE,
|
||||
ST_PETERS_BASILICA,
|
||||
UFFIZI_GALLERY,
|
||||
GALILEOS_TOMB,
|
||||
VINE_STREET_KITCHEN,
|
||||
BREEZEWAY,
|
||||
CAMPUS_SUNSET,
|
||||
FUNSTON_BEACH_SUNSET,
|
||||
|
||||
NUM_PRESET,
|
||||
};
|
||||
|
||||
void setAmbientLightMode(int preset);
|
||||
|
||||
private:
|
||||
DeferredLightingEffect() { }
|
||||
virtual ~DeferredLightingEffect() { }
|
||||
|
@ -84,6 +101,7 @@ private:
|
|||
int depthTexCoordOffset;
|
||||
int depthTexCoordScale;
|
||||
int radius;
|
||||
int ambientSphere;
|
||||
};
|
||||
|
||||
static void loadLightProgram(const char* fragSource, bool limited, ProgramObject& program, LightLocations& locations);
|
||||
|
@ -91,12 +109,20 @@ private:
|
|||
ProgramObject _simpleProgram;
|
||||
int _glowIntensityLocation;
|
||||
|
||||
ProgramObject _directionalAmbientSphereLight;
|
||||
LightLocations _directionalAmbientSphereLightLocations;
|
||||
ProgramObject _directionalAmbientSphereLightShadowMap;
|
||||
LightLocations _directionalAmbientSphereLightShadowMapLocations;
|
||||
ProgramObject _directionalAmbientSphereLightCascadedShadowMap;
|
||||
LightLocations _directionalAmbientSphereLightCascadedShadowMapLocations;
|
||||
|
||||
ProgramObject _directionalLight;
|
||||
LightLocations _directionalLightLocations;
|
||||
ProgramObject _directionalLightShadowMap;
|
||||
LightLocations _directionalLightShadowMapLocations;
|
||||
ProgramObject _directionalLightCascadedShadowMap;
|
||||
LightLocations _directionalLightCascadedShadowMapLocations;
|
||||
|
||||
ProgramObject _pointLight;
|
||||
LightLocations _pointLightLocations;
|
||||
ProgramObject _spotLight;
|
||||
|
@ -126,6 +152,8 @@ private:
|
|||
QVector<PostLightingRenderable*> _postLightingRenderables;
|
||||
|
||||
AbstractViewStateInterface* _viewState;
|
||||
|
||||
int _ambientLightMode = 0;
|
||||
};
|
||||
|
||||
/// Simple interface for objects that require something to be rendered after deferred lighting.
|
||||
|
|
63
libraries/render-utils/src/Material.slh
Executable file
63
libraries/render-utils/src/Material.slh
Executable file
|
@ -0,0 +1,63 @@
|
|||
<!
|
||||
// Material.slh
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Sam Gateau on 12/16/14.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
!>
|
||||
<@if not MATERIAL_SLH@>
|
||||
<@def MATERIAL_SLH@>
|
||||
|
||||
struct Material {
|
||||
vec4 _diffuse;
|
||||
vec4 _specular;
|
||||
|
||||
};
|
||||
|
||||
float getMaterialOpacity(Material m) { return m._diffuse.a; }
|
||||
vec3 getMaterialDiffuse(Material m) { return m._diffuse.rgb; }
|
||||
vec3 getMaterialSpecular(Material m) { return m._specular.rgb; }
|
||||
float getMaterialShininess(Material m) { return m._specular.a; }
|
||||
|
||||
|
||||
|
||||
<@if GLPROFILE == PC_GL@>
|
||||
uniform materialBuffer {
|
||||
Material mat;
|
||||
};
|
||||
Material getMaterial() {
|
||||
return mat;
|
||||
}
|
||||
<@elif GLPROFILE == MAC_GL@>
|
||||
uniform vec4 materialBuffer[2];
|
||||
Material getMaterial() {
|
||||
Material mat;
|
||||
mat._diffuse = materialBuffer[0];
|
||||
mat._specular = materialBuffer[1];
|
||||
return mat;
|
||||
}
|
||||
<!/* tryed and failed...
|
||||
bindable uniform struct {
|
||||
Material mat;
|
||||
} materialBuffer;
|
||||
|
||||
Material getMaterial() {
|
||||
return materialBuffer.mat;
|
||||
}
|
||||
*/!>
|
||||
<@else@>
|
||||
uniform vec4 materialBuffer[2];
|
||||
Material getMaterial() {
|
||||
Material mat;
|
||||
mat._diffuse = materialBuffer[0];
|
||||
mat._specular = materialBuffer[1];
|
||||
return mat;
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
|
||||
|
||||
<@endif@>
|
|
@ -178,7 +178,7 @@ void Model::initProgram(ProgramObject& program, Model::Locations& locations, boo
|
|||
locations.alphaThreshold = program.uniformLocation("alphaThreshold");
|
||||
locations.texcoordMatrices = program.uniformLocation("texcoordMatrices");
|
||||
locations.emissiveParams = program.uniformLocation("emissiveParams");
|
||||
|
||||
locations.glowIntensity = program.uniformLocation("glowIntensity");
|
||||
program.setUniformValue("diffuseMap", 0);
|
||||
program.setUniformValue("normalMap", 1);
|
||||
|
||||
|
@ -198,6 +198,35 @@ void Model::initProgram(ProgramObject& program, Model::Locations& locations, boo
|
|||
locations.emissiveTextureUnit = -1;
|
||||
}
|
||||
|
||||
// bindable uniform version
|
||||
#if defined(Q_OS_MAC)
|
||||
loc = program.uniformLocation("materialBuffer");
|
||||
if (loc >= 0) {
|
||||
locations.materialBufferUnit = loc;
|
||||
} else {
|
||||
locations.materialBufferUnit = -1;
|
||||
}
|
||||
#elif defined(Q_OS_WIN)
|
||||
loc = glGetUniformBlockIndex(program.programId(), "materialBuffer");
|
||||
if (loc >= 0) {
|
||||
glUniformBlockBinding(program.programId(), loc, 1);
|
||||
locations.materialBufferUnit = 1;
|
||||
} else {
|
||||
locations.materialBufferUnit = -1;
|
||||
}
|
||||
#else
|
||||
loc = program.uniformLocation("materialBuffer");
|
||||
if (loc >= 0) {
|
||||
locations.materialBufferUnit = loc;
|
||||
} else {
|
||||
locations.materialBufferUnit = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!program.isLinked()) {
|
||||
program.release();
|
||||
}
|
||||
|
||||
program.release();
|
||||
}
|
||||
|
||||
|
@ -2348,6 +2377,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
|
|||
for (int j = 0; j < networkMesh.parts.size(); j++) {
|
||||
const NetworkMeshPart& networkPart = networkMesh.parts.at(j);
|
||||
const FBXMeshPart& part = mesh.parts.at(j);
|
||||
model::MaterialPointer material = part._material;
|
||||
if ((networkPart.isTranslucent() || part.opacity != 1.0f) != translucent) {
|
||||
offset += (part.quadIndices.size() + part.triangleIndices.size()) * sizeof(int);
|
||||
continue;
|
||||
|
@ -2365,16 +2395,17 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
|
|||
qDebug() << "part INDEX:" << j;
|
||||
qDebug() << "NEW part.materialID:" << part.materialID;
|
||||
}
|
||||
|
||||
glm::vec4 diffuse = glm::vec4(part.diffuseColor, part.opacity);
|
||||
if (!(translucent && alphaThreshold == 0.0f)) {
|
||||
GLBATCH(glAlphaFunc)(GL_EQUAL, diffuse.a = glowEffect->getIntensity());
|
||||
|
||||
if (locations->glowIntensity >= 0) {
|
||||
GLBATCH(glUniform1f)(locations->glowIntensity, glowEffect->getIntensity());
|
||||
}
|
||||
if (!(translucent && alphaThreshold == 0.0f)) {
|
||||
GLBATCH(glAlphaFunc)(GL_EQUAL, glowEffect->getIntensity());
|
||||
}
|
||||
|
||||
if (locations->materialBufferUnit >= 0) {
|
||||
batch.setUniformBuffer(locations->materialBufferUnit, material->getSchemaBuffer());
|
||||
}
|
||||
glm::vec4 specular = glm::vec4(part.specularColor, 1.0f);
|
||||
GLBATCH(glMaterialfv)(GL_FRONT, GL_AMBIENT, (const float*)&diffuse);
|
||||
GLBATCH(glMaterialfv)(GL_FRONT, GL_DIFFUSE, (const float*)&diffuse);
|
||||
GLBATCH(glMaterialfv)(GL_FRONT, GL_SPECULAR, (const float*)&specular);
|
||||
GLBATCH(glMaterialf)(GL_FRONT, GL_SHININESS, (part.shininess > 128.0f ? 128.0f: part.shininess));
|
||||
|
||||
Texture* diffuseMap = networkPart.diffuseTexture.data();
|
||||
if (mesh.isEye && diffuseMap) {
|
||||
|
|
|
@ -338,6 +338,8 @@ private:
|
|||
int specularTextureUnit;
|
||||
int emissiveTextureUnit;
|
||||
int emissiveParams;
|
||||
int glowIntensity;
|
||||
int materialBufferUnit;
|
||||
};
|
||||
|
||||
static Locations _locations;
|
||||
|
|
42
libraries/render-utils/src/directional_ambient_light.slf
Executable file
42
libraries/render-utils/src/directional_ambient_light.slf
Executable file
|
@ -0,0 +1,42 @@
|
|||
<@include Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// directional_light.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/3/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// Everything about deferred buffer
|
||||
<@include DeferredBuffer.slh@>
|
||||
|
||||
<@include DeferredLighting.slh@>
|
||||
|
||||
void main(void) {
|
||||
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st);
|
||||
|
||||
// Light mapped or not ?
|
||||
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
|
||||
gl_FragColor = vec4( evalLightmappedColor(
|
||||
1.0,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
||||
+ evalDirectionalColor(1.0,
|
||||
frag.position.xyz,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specular,
|
||||
frag.gloss);
|
||||
|
||||
gl_FragColor = vec4(color, frag.normalVal.a);
|
||||
}
|
||||
}
|
49
libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf
Executable file
49
libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf
Executable file
|
@ -0,0 +1,49 @@
|
|||
<@include Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// directional_light.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/3/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// Everything about deferred buffer
|
||||
<@include DeferredBuffer.slh@>
|
||||
|
||||
<@include DeferredLighting.slh@>
|
||||
|
||||
// Everything about shadow
|
||||
<@include Shadow.slh@>
|
||||
|
||||
void main(void) {
|
||||
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st);
|
||||
|
||||
// Eval shadow Texcoord and then Attenuation
|
||||
vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position);
|
||||
float shadowAttenuation = evalShadowAttenuation(shadowTexcoord);
|
||||
|
||||
// Light mapped or not ?
|
||||
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
|
||||
gl_FragColor = vec4(evalLightmappedColor(
|
||||
shadowAttenuation,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
||||
+ evalDirectionalColor(shadowAttenuation,
|
||||
frag.position.xyz,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specular,
|
||||
frag.gloss);
|
||||
|
||||
gl_FragColor = vec4(color, frag.normalVal.a);
|
||||
}
|
||||
}
|
50
libraries/render-utils/src/directional_ambient_light_shadow_map.slf
Executable file
50
libraries/render-utils/src/directional_ambient_light_shadow_map.slf
Executable file
|
@ -0,0 +1,50 @@
|
|||
<@include Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// directional_light.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/3/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// Everything about deferred buffer
|
||||
<@include DeferredBuffer.slh@>
|
||||
|
||||
<@include DeferredLighting.slh@>
|
||||
|
||||
// Everything about shadow
|
||||
<@include Shadow.slh@>
|
||||
|
||||
|
||||
void main(void) {
|
||||
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st);
|
||||
|
||||
// Eval shadow Texcoord and then Attenuation
|
||||
vec4 shadowTexcoord = evalShadowTexcoord(frag.position);
|
||||
float shadowAttenuation = evalShadowAttenuation(shadowTexcoord);
|
||||
|
||||
// Light mapped or not ?
|
||||
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
|
||||
gl_FragColor = vec4(evalLightmappedColor(
|
||||
shadowAttenuation,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
||||
+ evalDirectionalColor(shadowAttenuation,
|
||||
frag.position.xyz,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specular,
|
||||
frag.gloss);
|
||||
|
||||
gl_FragColor = vec4(color, frag.normalVal.a);
|
||||
}
|
||||
}
|
|
@ -15,29 +15,28 @@
|
|||
// Everything about deferred buffer
|
||||
<@include DeferredBuffer.slh@>
|
||||
|
||||
<@include DeferredLighting.slh@>
|
||||
|
||||
void main(void) {
|
||||
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st);
|
||||
|
||||
vec4 normalVal = frag.normalVal;
|
||||
vec4 diffuseVal = frag.diffuseVal;
|
||||
vec4 specularVal = frag.specularVal;
|
||||
|
||||
// Light mapped or not ?
|
||||
if ((normalVal.a >= 0.45) && (normalVal.a <= 0.55)) {
|
||||
gl_FragColor = vec4(diffuseVal.rgb * specularVal.rgb, 1.0);
|
||||
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
|
||||
gl_FragColor = vec4( evalLightmappedColor(
|
||||
1.0,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
1.0);
|
||||
} else {
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(frag.normal, gl_LightSource[0].position.xyz);
|
||||
float facingLight = step(0.0, diffuse);
|
||||
vec3 baseColor = diffuseVal.rgb * (gl_FrontLightModelProduct.sceneColor.rgb +
|
||||
gl_FrontLightProduct[0].ambient.rgb + gl_FrontLightProduct[0].diffuse.rgb * (diffuse * facingLight));
|
||||
|
||||
// compute the specular multiplier (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position.xyz - normalize(frag.position.xyz)),
|
||||
frag.normal));
|
||||
|
||||
// add specular contribution
|
||||
vec4 specularColor = specularVal;
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normalVal.a);
|
||||
vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
||||
+ evalDirectionalColor(1.0,
|
||||
frag.position.xyz,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specular,
|
||||
frag.gloss);
|
||||
|
||||
gl_FragColor = vec4(color, frag.normalVal.a);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,55 +15,35 @@
|
|||
// Everything about deferred buffer
|
||||
<@include DeferredBuffer.slh@>
|
||||
|
||||
<@include DeferredLighting.slh@>
|
||||
|
||||
// Everything about shadow
|
||||
<@include Shadow.slh@>
|
||||
|
||||
void main(void) {
|
||||
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st);
|
||||
vec4 normalVal = frag.normalVal;
|
||||
vec4 diffuseVal = frag.diffuseVal;
|
||||
vec4 specularVal = frag.specularVal;
|
||||
|
||||
// Eval shadow Texcoord and then Attenuation
|
||||
vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position);
|
||||
float shadowAttenuation = evalShadowAttenuation(shadowTexcoord);
|
||||
|
||||
// how much this fragment faces the light direction
|
||||
float diffuse = dot(frag.normal, gl_LightSource[0].position.xyz);
|
||||
|
||||
// Light mapped or not ?
|
||||
if ((normalVal.a >= 0.45) && (normalVal.a <= 0.55)) {
|
||||
normalVal.a = 1.0;
|
||||
|
||||
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
||||
// it should be just 0, but we have innacurracy so we need to overshoot
|
||||
const float PERPENDICULAR_THRESHOLD = -0.005;
|
||||
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuse);
|
||||
|
||||
// evaluate the shadow test but only relevant for light facing fragments
|
||||
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
|
||||
|
||||
// diffuse light is the lightmap dimmed by shadow
|
||||
vec3 diffuseLight = lightAttenuation * specularVal.rgb;
|
||||
// ambient is a tiny percentage of the lightmap and only when in the shadow
|
||||
vec3 ambientLight = (1 - lightAttenuation) * 0.5 * specularVal.rgb;
|
||||
|
||||
gl_FragColor = vec4(diffuseVal.rgb * (ambientLight + diffuseLight), 1.0);
|
||||
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
|
||||
gl_FragColor = vec4(evalLightmappedColor(
|
||||
shadowAttenuation,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
||||
+ evalDirectionalColor(shadowAttenuation,
|
||||
frag.position.xyz,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specular,
|
||||
frag.gloss);
|
||||
|
||||
// average values from the shadow map
|
||||
float facingLight = step(0.0, diffuse) * shadowAttenuation;
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
vec3 baseColor = diffuseVal.rgb * (gl_FrontLightModelProduct.sceneColor.rgb +
|
||||
gl_FrontLightProduct[0].ambient.rgb + gl_FrontLightProduct[0].diffuse.rgb * (diffuse * facingLight));
|
||||
|
||||
// compute the specular multiplier (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position.xyz - normalize(frag.position.xyz)),
|
||||
frag.normal));
|
||||
|
||||
// add specular contribution
|
||||
vec4 specularColor = specularVal;
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normalVal.a);
|
||||
gl_FragColor = vec4(color, frag.normalVal.a);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,54 +15,36 @@
|
|||
// Everything about deferred buffer
|
||||
<@include DeferredBuffer.slh@>
|
||||
|
||||
<@include DeferredLighting.slh@>
|
||||
|
||||
// Everything about shadow
|
||||
<@include Shadow.slh@>
|
||||
<@include Shadow.slh@>
|
||||
|
||||
|
||||
void main(void) {
|
||||
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st);
|
||||
vec4 normalVal = frag.normalVal;
|
||||
vec4 diffuseVal = frag.diffuseVal;
|
||||
vec4 specularVal = frag.specularVal;
|
||||
|
||||
// Eval shadow Texcoord and then Attenuation
|
||||
vec4 shadowTexcoord = evalShadowTexcoord(frag.position);
|
||||
float shadowAttenuation = evalShadowAttenuation(shadowTexcoord);
|
||||
|
||||
// how much this fragment faces the light direction
|
||||
float diffuse = dot(frag.normal, gl_LightSource[0].position.xyz);
|
||||
|
||||
// Light mapped or not ?
|
||||
if ((normalVal.a >= 0.45) && (normalVal.a <= 0.55)) {
|
||||
normalVal.a = 0.0;
|
||||
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
|
||||
gl_FragColor = vec4(evalLightmappedColor(
|
||||
shadowAttenuation,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specularVal.xyz),
|
||||
1.0);
|
||||
} else {
|
||||
vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
||||
+ evalDirectionalColor(shadowAttenuation,
|
||||
frag.position.xyz,
|
||||
frag.normal,
|
||||
frag.diffuse,
|
||||
frag.specular,
|
||||
frag.gloss);
|
||||
|
||||
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
||||
// it should be just 0, be we have innacurracy so we need to overshoot
|
||||
const float PERPENDICULAR_THRESHOLD = -0.005;
|
||||
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuse);
|
||||
|
||||
// evaluate the shadow test but only relevant for light facing fragments
|
||||
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
|
||||
|
||||
// diffuse light is the lightmap dimmed by shadow
|
||||
vec3 diffuseLight = lightAttenuation * specularVal.rgb;
|
||||
// ambient is a tiny percentage of the lightmap and only when in the shadow
|
||||
vec3 ambientLight = (1 - lightAttenuation) * 0.5 * specularVal.rgb;
|
||||
|
||||
gl_FragColor = vec4(diffuseVal.rgb * (ambientLight + diffuseLight), 1.0);
|
||||
} else {
|
||||
// average values from the shadow map
|
||||
float facingLight = step(0.0, diffuse) * shadowAttenuation;
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
vec3 baseColor = diffuseVal.rgb * (gl_FrontLightModelProduct.sceneColor.rgb +
|
||||
gl_FrontLightProduct[0].ambient.rgb + gl_FrontLightProduct[0].diffuse.rgb * (diffuse * facingLight));
|
||||
|
||||
// compute the specular multiplier (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position.xyz - normalize(frag.position.xyz)),
|
||||
frag.normal));
|
||||
|
||||
// add specular contribution
|
||||
vec4 specularColor = specularVal;
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normalVal.a);
|
||||
gl_FragColor = vec4(color, frag.normalVal.a);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,19 +11,26 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
<@include Material.slh@>
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
void main(void) {
|
||||
// set the diffuse, normal, specular data
|
||||
// Fetch diffuse map
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold)));
|
||||
gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0);
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragment(
|
||||
normalize(normal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat));
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ void main(void) {
|
|||
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse;
|
||||
gl_FrontColor = gl_Color;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
<@include Material.slh@>
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -19,9 +23,6 @@ uniform sampler2D diffuseMap;
|
|||
uniform sampler2D emissiveMap;
|
||||
uniform vec2 emissiveParams;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
|
@ -32,7 +33,14 @@ void main(void) {
|
|||
// set the diffuse, normal, specular data
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st);
|
||||
gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold)));
|
||||
gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);
|
||||
gl_FragData[2] = vec4((vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), gl_FrontMaterial.shininess / 128.0);
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragmentLightmap(
|
||||
normalize(normal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ void main(void) {
|
|||
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse;
|
||||
gl_FrontColor = gl_Color;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
<@include Material.slh@>
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -22,9 +26,6 @@ uniform sampler2D normalMap;
|
|||
uniform sampler2D emissiveMap;
|
||||
uniform vec2 emissiveParams;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 interpolatedNormal;
|
||||
|
||||
|
@ -45,7 +46,14 @@ void main(void) {
|
|||
// set the diffuse, normal, specular data
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st);
|
||||
gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold)));
|
||||
gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0);
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragmentLightmap(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ void main(void) {
|
|||
interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0);
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse;
|
||||
gl_FrontColor = gl_Color;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
<@include Material.slh@>
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -25,9 +29,6 @@ uniform sampler2D normalMap;
|
|||
// the specular map texture
|
||||
uniform sampler2D specularMap;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 interpolatedNormal;
|
||||
|
||||
|
@ -47,9 +48,16 @@ void main(void) {
|
|||
|
||||
// set the diffuse, normal, specular data
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
vec3 specular = texture2D(specularMap, gl_TexCoord[0].st).rgb;
|
||||
vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st);
|
||||
gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold)));
|
||||
gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb,
|
||||
gl_FrontMaterial.shininess / 128.0);
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragmentLightmap(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
specular, // no use of getMaterialSpecular(mat)
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
<@include Material.slh@>
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -22,9 +26,6 @@ uniform vec2 emissiveParams;
|
|||
// the specular texture
|
||||
uniform sampler2D specularMap;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
|
@ -33,9 +34,16 @@ varying vec2 interpolatedTexcoord1;
|
|||
void main(void) {
|
||||
// set the diffuse, normal, specular data
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
vec3 specular = texture2D(specularMap, gl_TexCoord[0].st).rgb;
|
||||
vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st);
|
||||
gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold)));
|
||||
gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb,
|
||||
gl_FrontMaterial.shininess / 128.0);
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragmentLightmap(
|
||||
normalize(normal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
specular, // no use of getMaterialSpecular(mat)
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
}
|
||||
|
|
|
@ -12,15 +12,16 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
<@include Material.slh@>
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
// the normal map texture
|
||||
uniform sampler2D normalMap;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 interpolatedNormal;
|
||||
|
||||
|
@ -35,10 +36,15 @@ void main(void) {
|
|||
vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5);
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
|
||||
// set the diffuse, normal, specular data
|
||||
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold)));
|
||||
gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0);
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragment(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat));
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ void main(void) {
|
|||
interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0);
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse;
|
||||
gl_FrontColor = gl_Color;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
<@include Material.slh@>
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -21,9 +25,6 @@ uniform sampler2D normalMap;
|
|||
// the specular map texture
|
||||
uniform sampler2D specularMap;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 interpolatedNormal;
|
||||
|
||||
|
@ -41,8 +42,14 @@ void main(void) {
|
|||
|
||||
// set the diffuse, normal, specular data
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold)));
|
||||
gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb,
|
||||
gl_FrontMaterial.shininess / 128.0);
|
||||
vec3 specular = texture2D(specularMap, gl_TexCoord[0].st).rgb;
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragment(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
specular, //getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat));
|
||||
}
|
||||
|
|
|
@ -12,23 +12,30 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
<@include Material.slh@>
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
// the specular texture
|
||||
uniform sampler2D specularMap;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
void main(void) {
|
||||
// set the diffuse, normal, specular data
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold)));
|
||||
gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb,
|
||||
gl_FrontMaterial.shininess / 128.0);
|
||||
vec3 specular = texture2D(specularMap, gl_TexCoord[0].st).rgb;
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragment(
|
||||
normalize(normal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
specular, //getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat));
|
||||
}
|
||||
|
|
|
@ -12,10 +12,29 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
<@include Material.slh@>
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
varying vec4 normal;
|
||||
|
||||
void main(void) {
|
||||
|
||||
// Fetch diffuse map
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
||||
packDeferredFragmentTranslucent(
|
||||
normalize(normal.xyz),
|
||||
getMaterialOpacity(mat) * diffuse.a,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat));
|
||||
|
||||
// set the diffuse data
|
||||
gl_FragData[0] = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
// gl_FragData[0] = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
}
|
||||
|
|
|
@ -12,15 +12,25 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
// the glow intensity
|
||||
uniform float glowIntensity;
|
||||
//uniform float glowIntensity;
|
||||
|
||||
void main(void) {
|
||||
// set the diffuse, normal, specular data
|
||||
/* // set the diffuse, normal, specular data
|
||||
gl_FragData[0] = vec4(gl_Color.rgb, glowIntensity);
|
||||
gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0);
|
||||
*/
|
||||
|
||||
packDeferredFragment(
|
||||
normalize(normal.xyz),
|
||||
glowIntensity,
|
||||
gl_Color.rgb,
|
||||
gl_FrontMaterial.specular.rgb,
|
||||
gl_FrontMaterial.shininess);
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ void main(void) {
|
|||
normal = normalize(gl_ModelViewMatrix * normal);
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_FrontMaterial.diffuse;
|
||||
|
||||
gl_FrontColor = gl_Color;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
||||
|
|
|
@ -46,8 +46,8 @@ void main(void) {
|
|||
interpolatedTangent = gl_ModelViewMatrix * interpolatedTangent;
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_FrontMaterial.diffuse;
|
||||
|
||||
gl_FrontColor = gl_Color;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
||||
|
|
Loading…
Reference in a new issue