mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into metavoxels
This commit is contained in:
commit
bbd977777a
27 changed files with 491 additions and 468 deletions
|
@ -20,7 +20,7 @@
|
|||
|
||||
set(VISAGE_SEARCH_DIRS "${VISAGE_ROOT_DIR}" "$ENV{VISAGE_ROOT_DIR}" "$ENV{HIFI_LIB_DIR}/visage")
|
||||
|
||||
find_path(VISAGE_INCLUDE_DIR VisageTracker2.h PATH_SUFFIXES include HINTS ${VISAGE_SEARCH_DIRS})
|
||||
find_path(VISAGE_BASE_INCLUDE_DIR VisageTracker2.h PATH_SUFFIXES include HINTS ${VISAGE_SEARCH_DIRS})
|
||||
|
||||
if (APPLE)
|
||||
find_path(VISAGE_XML_INCLUDE_DIR libxml/xmlreader.h HINTS /usr/include/libxml2 ${VISAGE_SEARCH_DIRS})
|
||||
|
@ -43,15 +43,15 @@ endif ()
|
|||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(VISAGE DEFAULT_MSG
|
||||
VISAGE_INCLUDE_DIR VISAGE_XML_INCLUDE_DIR VISAGE_OPENCV_INCLUDE_DIR VISAGE_OPENCV2_INCLUDE_DIR
|
||||
VISAGE_BASE_INCLUDE_DIR VISAGE_XML_INCLUDE_DIR VISAGE_OPENCV_INCLUDE_DIR VISAGE_OPENCV2_INCLUDE_DIR
|
||||
VISAGE_CORE_LIBRARY VISAGE_VISION_LIBRARY VISAGE_OPENCV_LIBRARY
|
||||
)
|
||||
|
||||
set(VISAGE_INCLUDE_DIRS "${VISAGE_XML_INCLUDE_DIR}" "${VISAGE_OPENCV_INCLUDE_DIR}" "${VISAGE_OPENCV2_INCLUDE_DIR}")
|
||||
set(VISAGE_INCLUDE_DIRS "${VISAGE_XML_INCLUDE_DIR}" "${VISAGE_OPENCV_INCLUDE_DIR}" "${VISAGE_OPENCV2_INCLUDE_DIR}" "${VISAGE_BASE_INCLUDE_DIR}")
|
||||
set(VISAGE_LIBRARIES "${VISAGE_CORE_LIBRARY}" "${VISAGE_VISION_LIBRARY}" "${VISAGE_OPENCV_LIBRARY}")
|
||||
|
||||
mark_as_advanced(
|
||||
VISAGE_INCLUDE_DIRS VISAGE_LIBRARIES
|
||||
VISAGE_INCLUDE_DIR VISAGE_XML_INCLUDE_DIR VISAGE_OPENCV_INCLUDE_DIR VISAGE_OPENCV2_INCLUDE_DIR
|
||||
VISAGE_BASE_INCLUDE_DIR VISAGE_XML_INCLUDE_DIR VISAGE_OPENCV_INCLUDE_DIR VISAGE_OPENCV2_INCLUDE_DIR
|
||||
VISAGE_CORE_LIBRARY VISAGE_VISION_LIBRARY VISAGE_OPENCV_LIBRARY
|
||||
)
|
||||
|
|
|
@ -10,174 +10,127 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var localLightDirections = [ {x: 1.0, y:1.0, z: 0.0}, {x: 0.0, y:1.0, z: 1.0} ];
|
||||
var localLightColors = [ {x: 0.0, y:1.0, z: 0.0}, {x: 1.0, y:0.0, z: 0.0} ];
|
||||
var localLightDirections = [ {x: 1.0, y:0.0, z: 0.0}, {x: 0.0, y:0.0, z: 1.0} ];
|
||||
var localLightColors = [ {x: 0.4, y:0.335, z: 0.266}, {x: 0.4, y:0.335, z: 0.266} ];
|
||||
|
||||
var currentSelection = 0;
|
||||
var currentNumLights = 1;
|
||||
var currentNumLights = 2;
|
||||
var maxNumLights = 2;
|
||||
var currentNumAvatars = 0;
|
||||
var changeDelta = 0.1;
|
||||
var lightsDirty = true;
|
||||
|
||||
function keyPressEvent(event) {
|
||||
|
||||
var choice = parseInt(event.text);
|
||||
|
||||
if (event.text == "1") {
|
||||
currentSelection = 0;
|
||||
print("light election = " + currentSelection);
|
||||
currentSelection = 0;
|
||||
print("light election = " + currentSelection);
|
||||
}
|
||||
else if (event.text == "2" ) {
|
||||
currentSelection = 1;
|
||||
print("light selection = " + currentSelection);
|
||||
currentSelection = 1;
|
||||
print("light selection = " + currentSelection);
|
||||
}
|
||||
else if (event.text == "3" ) {
|
||||
currentSelection = 2;
|
||||
print("light selection = " + currentSelection);
|
||||
currentSelection = 2;
|
||||
print("light selection = " + currentSelection);
|
||||
}
|
||||
else if (event.text == "4" ) {
|
||||
currentSelection = 3;
|
||||
print("light selection = " + currentSelection);
|
||||
currentSelection = 3;
|
||||
print("light selection = " + currentSelection);
|
||||
}
|
||||
else if (event.text == "5" ) {
|
||||
localLightColors[currentSelection].x += changeDelta;
|
||||
if ( localLightColors[currentSelection].x > 1.0) {
|
||||
localLightColors[currentSelection].x = 0.0;
|
||||
}
|
||||
|
||||
setAllLightColors();
|
||||
print("CHANGE RED light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
|
||||
localLightColors[currentSelection].x += changeDelta;
|
||||
if ( localLightColors[currentSelection].x > 1.0) {
|
||||
localLightColors[currentSelection].x = 0.0;
|
||||
}
|
||||
|
||||
lightsDirty = true;
|
||||
print("CHANGE RED light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
|
||||
}
|
||||
else if (event.text == "6" ) {
|
||||
localLightColors[currentSelection].y += changeDelta;
|
||||
if ( localLightColors[currentSelection].y > 1.0) {
|
||||
localLightColors[currentSelection].y = 0.0;
|
||||
}
|
||||
|
||||
setAllLightColors();
|
||||
print("CHANGE GREEN light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
|
||||
localLightColors[currentSelection].y += changeDelta;
|
||||
if ( localLightColors[currentSelection].y > 1.0) {
|
||||
localLightColors[currentSelection].y = 0.0;
|
||||
}
|
||||
|
||||
lightsDirty = true;
|
||||
print("CHANGE GREEN light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
|
||||
}
|
||||
else if (event.text == "7" ) {
|
||||
localLightColors[currentSelection].z += changeDelta;
|
||||
if ( localLightColors[currentSelection].z > 1.0) {
|
||||
localLightColors[currentSelection].z = 0.0;
|
||||
}
|
||||
|
||||
setAllLightColors();
|
||||
print("CHANGE BLUE light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
|
||||
localLightColors[currentSelection].z += changeDelta;
|
||||
if ( localLightColors[currentSelection].z > 1.0) {
|
||||
localLightColors[currentSelection].z = 0.0;
|
||||
}
|
||||
|
||||
lightsDirty = true;
|
||||
print("CHANGE BLUE light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
|
||||
}
|
||||
else if (event.text == "8" ) {
|
||||
localLightDirections[currentSelection].x += changeDelta;
|
||||
if (localLightDirections[currentSelection].x > 1.0) {
|
||||
localLightDirections[currentSelection].x = -1.0;
|
||||
}
|
||||
|
||||
setAllLightDirections();
|
||||
print("PLUS X light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
|
||||
localLightDirections[currentSelection].x += changeDelta;
|
||||
if (localLightDirections[currentSelection].x > 1.0) {
|
||||
localLightDirections[currentSelection].x = -1.0;
|
||||
}
|
||||
|
||||
lightsDirty = true;
|
||||
print("PLUS X light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
|
||||
}
|
||||
else if (event.text == "9" ) {
|
||||
localLightDirections[currentSelection].x -= changeDelta;
|
||||
if (localLightDirections[currentSelection].x < -1.0) {
|
||||
localLightDirections[currentSelection].x = 1.0;
|
||||
}
|
||||
|
||||
setAllLightDirections();
|
||||
print("MINUS X light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
|
||||
localLightDirections[currentSelection].x -= changeDelta;
|
||||
if (localLightDirections[currentSelection].x < -1.0) {
|
||||
localLightDirections[currentSelection].x = 1.0;
|
||||
}
|
||||
|
||||
lightsDirty = true;
|
||||
print("MINUS X light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
|
||||
}
|
||||
else if (event.text == "0" ) {
|
||||
localLightDirections[currentSelection].y += changeDelta;
|
||||
if (localLightDirections[currentSelection].y > 1.0) {
|
||||
localLightDirections[currentSelection].y = -1.0;
|
||||
}
|
||||
|
||||
setAllLightDirections();
|
||||
print("PLUS Y light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
|
||||
localLightDirections[currentSelection].y += changeDelta;
|
||||
if (localLightDirections[currentSelection].y > 1.0) {
|
||||
localLightDirections[currentSelection].y = -1.0;
|
||||
}
|
||||
|
||||
lightsDirty = true;
|
||||
print("PLUS Y light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
|
||||
}
|
||||
else if (event.text == "-" ) {
|
||||
localLightDirections[currentSelection].y -= changeDelta;
|
||||
if (localLightDirections[currentSelection].y < -1.0) {
|
||||
localLightDirections[currentSelection].y = 1.0;
|
||||
}
|
||||
|
||||
setAllLightDirections();
|
||||
print("MINUS Y light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
|
||||
localLightDirections[currentSelection].y -= changeDelta;
|
||||
if (localLightDirections[currentSelection].y < -1.0) {
|
||||
localLightDirections[currentSelection].y = 1.0;
|
||||
}
|
||||
|
||||
lightsDirty = true;
|
||||
print("MINUS Y light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
|
||||
}
|
||||
else if (event.text == "," ) {
|
||||
if (currentNumLights + 1 <= maxNumLights) {
|
||||
++currentNumLights;
|
||||
|
||||
for (var i = 0; i < currentNumAvatars; i++) {
|
||||
AvatarManager.addAvatarLocalLight(i);
|
||||
|
||||
for (var j = 0; j < currentNumLights; j++) {
|
||||
AvatarManager.setAvatarLightColor(localLightColors[j], j, i);
|
||||
AvatarManager.setAvatarLightDirection(localLightDirections[j], j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print("ADD LIGHT, number of lights " + currentNumLights);
|
||||
if (currentNumLights + 1 <= maxNumLights) {
|
||||
++currentNumLights;
|
||||
lightsDirty = true;
|
||||
}
|
||||
|
||||
print("ADD LIGHT, number of lights " + currentNumLights);
|
||||
}
|
||||
else if (event.text == "." ) {
|
||||
if (currentNumLights - 1 >= 0 ) {
|
||||
--currentNumLights;
|
||||
|
||||
for (var i = 0; i < currentNumAvatars; i++) {
|
||||
AvatarManager.removeAvatarLocalLight(i);
|
||||
|
||||
for (var j = 0; j < currentNumLights; j++) {
|
||||
AvatarManager.setAvatarLightColor(localLightColors[j], j, i);
|
||||
AvatarManager.setAvatarLightDirection(localLightDirections[j], j, i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
print("REMOVE LIGHT, number of lights " + currentNumLights);
|
||||
if (currentNumLights - 1 >= 0 ) {
|
||||
--currentNumLights;
|
||||
lightsDirty = true;
|
||||
}
|
||||
|
||||
print("REMOVE LIGHT, number of lights " + currentNumLights);
|
||||
}
|
||||
}
|
||||
|
||||
function updateLocalLights()
|
||||
{
|
||||
// new avatars, so add lights
|
||||
var numAvatars = AvatarManager.getNumAvatars();
|
||||
if (numAvatars != currentNumAvatars) {
|
||||
|
||||
for (var i = 0; i < numAvatars; i++) {
|
||||
var numLights = AvatarManager.getNumLightsInAvatar(i);
|
||||
|
||||
// check if new avatar has lights
|
||||
if (numLights <= 0) {
|
||||
AvatarManager.addAvatarLocalLight(i);
|
||||
|
||||
// set color and direction for new avatar
|
||||
for (var j = 0; j < maxNumLights; j++) {
|
||||
AvatarManager.setAvatarLightColor(localLightColors[j], j, i);
|
||||
AvatarManager.setAvatarLightDirection(localLightDirections[j], j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentNumAvatars = numAvatars;
|
||||
}
|
||||
}
|
||||
|
||||
function setAllLightColors()
|
||||
{
|
||||
for (var i = 0; i < currentNumAvatars; i++) {
|
||||
for (var j = 0; j < maxNumLights; j++) {
|
||||
AvatarManager.setAvatarLightColor(localLightColors[j], j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setAllLightDirections()
|
||||
{
|
||||
for (var i = 0; i < currentNumAvatars; i++) {
|
||||
for (var j = 0; j < maxNumLights; j++) {
|
||||
AvatarManager.setAvatarLightDirection(localLightDirections[j], j, i);
|
||||
}
|
||||
}
|
||||
if (lightsDirty) {
|
||||
var localLights = [];
|
||||
for (var i = 0; i < currentNumLights; i++) {
|
||||
localLights.push({ direction: localLightDirections[i], color: localLightColors[i] });
|
||||
}
|
||||
AvatarManager.setLocalLights(localLights);
|
||||
lightsDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
// main
|
||||
|
|
|
@ -11,16 +11,18 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
// local lights
|
||||
const int MAX_LOCAL_LIGHTS = 2; // 2 lights for now, will probably need more later on
|
||||
uniform int numLocalLights;
|
||||
uniform vec3 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
uniform vec3 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the interpolated position
|
||||
varying vec4 position;
|
||||
|
||||
|
@ -28,23 +30,18 @@ varying vec4 position;
|
|||
varying vec4 normal;
|
||||
|
||||
void main(void) {
|
||||
// compute the base color based on OpenGL lighting model
|
||||
// add up the local lights
|
||||
vec4 normalizedNormal = normalize(normal);
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse);
|
||||
|
||||
// the local light that is always present
|
||||
vec4 totalLocalLight = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
for (int i = 0; i < numLocalLights; i++) {
|
||||
float localDiffuse = dot(normalizedNormal, vec4(localLightDirections[i], 1.0));
|
||||
float localLight = step(0.0, localDiffuse);
|
||||
float localLightVal = localDiffuse * localLight;
|
||||
|
||||
totalLocalLight += (localLightVal * vec4( localLightColors[i], 0.0));
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(normalizedNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + totalLocalLight);
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position - normalize(vec4(position.xyz, 0.0))),
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -34,9 +43,15 @@ void main(void) {
|
|||
int shadowIndex = int(dot(step(vec3(position.z), shadowDistances), vec3(1.0, 1.0, 1.0)));
|
||||
vec3 shadowTexCoord = vec3(dot(gl_EyePlaneS[shadowIndex], position), dot(gl_EyePlaneT[shadowIndex], position),
|
||||
dot(gl_EyePlaneR[shadowIndex], position));
|
||||
|
||||
// add up the local lights
|
||||
vec4 normalizedNormal = normalize(normal);
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(normalizedNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
vec4 normalizedNormal = normalize(normal);
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse) * 0.25 *
|
||||
(shadow2D(shadowMap, shadowTexCoord + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
|
@ -44,7 +59,7 @@ void main(void) {
|
|||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, shadowScale, 0.0)).r);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position - normalize(vec4(position.xyz, 0.0))),
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -46,10 +55,16 @@ void main(void) {
|
|||
vec3 shadowTexCoord = vec3(dot(gl_EyePlaneS[shadowIndex], interpolatedPosition),
|
||||
dot(gl_EyePlaneT[shadowIndex], interpolatedPosition),
|
||||
dot(gl_EyePlaneR[shadowIndex], interpolatedPosition));
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
|
||||
// add up the local lights
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(viewNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(viewNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse) * 0.25 *
|
||||
(shadow2D(shadowMap, shadowTexCoord + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
|
@ -57,7 +72,7 @@ void main(void) {
|
|||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, shadowScale, 0.0)).r);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position -
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -50,9 +59,15 @@ void main(void) {
|
|||
dot(gl_EyePlaneT[shadowIndex], interpolatedPosition),
|
||||
dot(gl_EyePlaneR[shadowIndex], interpolatedPosition));
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
// add up the local lights
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(viewNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(viewNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse) * 0.25 *
|
||||
(shadow2D(shadowMap, shadowTexCoord + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
|
@ -60,7 +75,7 @@ void main(void) {
|
|||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, shadowScale, 0.0)).r);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position -
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -38,8 +47,14 @@ void main(void) {
|
|||
vec3 shadowTexCoord = vec3(dot(gl_EyePlaneS[shadowIndex], position), dot(gl_EyePlaneT[shadowIndex], position),
|
||||
dot(gl_EyePlaneR[shadowIndex], position));
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
// add up the local lights
|
||||
vec4 normalizedNormal = normalize(normal);
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(normalizedNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse) * 0.25 *
|
||||
(shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
|
@ -47,7 +62,7 @@ void main(void) {
|
|||
shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(shadowScale, shadowScale, 0.0)).r);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position - normalize(vec4(position.xyz, 0.0))),
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -32,19 +41,20 @@ void main(void) {
|
|||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||
vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) * 2.0 - vec3(1.0, 1.0, 1.0);
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
// add up the local lights
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(viewNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(viewNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse);
|
||||
float localDiffuse = dot(viewNormal, gl_LightSource[1].position);
|
||||
float localLight = step(0.0, localDiffuse);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + gl_FrontLightProduct[1].diffuse * (localDiffuse * localLight));
|
||||
|
||||
|
||||
|
||||
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position -
|
||||
normalize(vec4(vec3(interpolatedPosition), 0.0))), viewNormal));
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -35,13 +44,19 @@ void main(void) {
|
|||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||
vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) * 2.0 - vec3(1.0, 1.0, 1.0);
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
// add up the local lights
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(viewNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(viewNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position -
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -27,8 +36,14 @@ varying vec4 position;
|
|||
varying vec4 normal;
|
||||
|
||||
void main(void) {
|
||||
// compute the base color based on OpenGL lighting model
|
||||
// add up the local lights
|
||||
vec4 normalizedNormal = normalize(normal);
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(normalizedNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse) * 0.25 *
|
||||
(shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
|
@ -36,7 +51,7 @@ void main(void) {
|
|||
shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(shadowScale, shadowScale, 0.0)).r);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position - normalize(vec4(position.xyz, 0.0))),
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -38,9 +47,15 @@ void main(void) {
|
|||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||
vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) * 2.0 - vec3(1.0, 1.0, 1.0);
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
// add up the local lights
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(viewNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(viewNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse) * 0.25 *
|
||||
(shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
|
@ -48,7 +63,7 @@ void main(void) {
|
|||
shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(shadowScale, shadowScale, 0.0)).r);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position -
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -41,9 +50,15 @@ void main(void) {
|
|||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||
vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) * 2.0 - vec3(1.0, 1.0, 1.0);
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
// add up the local lights
|
||||
vec4 viewNormal = vec4(normalizedTangent * localNormal.x +
|
||||
normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0);
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(viewNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(viewNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse) * 0.25 *
|
||||
(shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
|
@ -51,7 +66,7 @@ void main(void) {
|
|||
shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(shadowScale, shadowScale, 0.0)).r);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position -
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -30,8 +39,14 @@ varying vec4 position;
|
|||
varying vec4 normal;
|
||||
|
||||
void main(void) {
|
||||
// compute the base color based on OpenGL lighting model
|
||||
// add up the local lights
|
||||
vec4 normalizedNormal = normalize(normal);
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(normalizedNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse) * 0.25 *
|
||||
(shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
|
@ -39,7 +54,7 @@ void main(void) {
|
|||
shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, gl_TexCoord[1].stp + vec3(shadowScale, shadowScale, 0.0)).r);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position - normalize(vec4(position.xyz, 0.0))),
|
||||
|
|
|
@ -10,11 +10,15 @@
|
|||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// the maximum number of local lights to apply
|
||||
const int MAX_LOCAL_LIGHTS = 2;
|
||||
|
||||
uniform int numLocalLights;
|
||||
uniform vec3 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
uniform vec3 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
// the color of each local light
|
||||
uniform vec4 localLightColors[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the direction of each local light
|
||||
uniform vec4 localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
@ -29,23 +33,18 @@ varying vec4 position;
|
|||
varying vec4 normal;
|
||||
|
||||
void main(void) {
|
||||
// compute the base color based on OpenGL lighting model
|
||||
// add up the local lights
|
||||
vec4 normalizedNormal = normalize(normal);
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse);
|
||||
|
||||
// the local light that is always present
|
||||
vec4 totalLocalLight = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
for (int i = 0; i < numLocalLights; i++) {
|
||||
float localDiffuse = dot(normalizedNormal, vec4(localLightDirections[i], 1.0));
|
||||
float localLight = step(0.0, localDiffuse);
|
||||
float localLightVal = localDiffuse * localLight;
|
||||
|
||||
totalLocalLight += (localLightVal * vec4( localLightColors[i], 0.0));
|
||||
vec4 localLight = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
localLight += localLightColors[i] * max(0.0, dot(normalizedNormal, localLightDirections[i]));
|
||||
}
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse);
|
||||
vec4 base = gl_Color * (gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + totalLocalLight);
|
||||
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight) + localLight);
|
||||
|
||||
// compute the specular component (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position - normalize(vec4(position.xyz, 0.0))),
|
||||
|
|
|
@ -2600,7 +2600,9 @@ void Application::updateShadowMap() {
|
|||
glViewport(0, 0, _glWidget->width(), _glWidget->height());
|
||||
}
|
||||
|
||||
const GLfloat WHITE_SPECULAR_COLOR[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
const GLfloat WORLD_AMBIENT_COLOR[] = { 0.525f, 0.525f, 0.6f };
|
||||
const GLfloat WORLD_DIFFUSE_COLOR[] = { 0.6f, 0.525f, 0.525f };
|
||||
const GLfloat WORLD_SPECULAR_COLOR[] = { 0.94f, 0.94f, 0.737f, 1.0f };
|
||||
const GLfloat NO_SPECULAR_COLOR[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
void Application::setupWorldLight() {
|
||||
|
@ -2612,13 +2614,10 @@ void Application::setupWorldLight() {
|
|||
glm::vec3 sunDirection = getSunDirection();
|
||||
GLfloat light_position0[] = { sunDirection.x, sunDirection.y, sunDirection.z, 0.0 };
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||
GLfloat ambient_color[] = { 0.7f, 0.7f, 0.8f };
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
|
||||
GLfloat diffuse_color[] = { 0.8f, 0.7f, 0.7f };
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, WHITE_SPECULAR_COLOR);
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, WHITE_SPECULAR_COLOR);
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, WORLD_AMBIENT_COLOR);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, WORLD_DIFFUSE_COLOR);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, WORLD_SPECULAR_COLOR);
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, WORLD_SPECULAR_COLOR);
|
||||
glMateriali(GL_FRONT, GL_SHININESS, 96);
|
||||
}
|
||||
|
||||
|
@ -2796,7 +2795,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
|
|||
}
|
||||
|
||||
// restore default, white specular
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, WHITE_SPECULAR_COLOR);
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, WORLD_SPECULAR_COLOR);
|
||||
|
||||
_nodeBoundsDisplay.draw();
|
||||
|
||||
|
@ -3628,6 +3627,9 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript
|
|||
scriptEngine->getModelsScriptingInterface()->setPacketSender(&_modelEditSender);
|
||||
scriptEngine->getModelsScriptingInterface()->setModelTree(_models.getTree());
|
||||
|
||||
// model has some custom types
|
||||
Model::registerMetaTypes(scriptEngine->getEngine());
|
||||
|
||||
// hook our avatar object into this script engine
|
||||
scriptEngine->setAvatarData(_myAvatar, "MyAvatar"); // leave it as a MyAvatar class to expose thrust features
|
||||
|
||||
|
|
|
@ -258,6 +258,8 @@ public:
|
|||
/// the view matrix translation.
|
||||
void updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation = glm::vec3());
|
||||
|
||||
const glm::mat4& getUntranslatedViewMatrix() const { return _untranslatedViewMatrix; }
|
||||
|
||||
/// Loads a view matrix that incorporates the specified model translation without the precision issues that can
|
||||
/// result from matrix multiplication at high translation magnitudes.
|
||||
void loadTranslatedViewMatrix(const glm::vec3& translation);
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
const float HAIR_DAMPING = 0.99f;
|
||||
const float CONSTRAINT_RELAXATION = 10.0f;
|
||||
const float HAIR_ACCELERATION_COUPLING = 0.025f;
|
||||
const float HAIR_ANGULAR_VELOCITY_COUPLING = 0.10f;
|
||||
const float HAIR_ANGULAR_VELOCITY_COUPLING = 0.01f;
|
||||
const float HAIR_ANGULAR_ACCELERATION_COUPLING = 0.001f;
|
||||
const float HAIR_MAX_LINEAR_ACCELERATION = 4.0f;
|
||||
const float HAIR_STIFFNESS = 0.005f;
|
||||
const glm::vec3 HAIR_COLOR1(0.98f, 0.92f, 0.843f);
|
||||
|
@ -36,6 +37,7 @@ Hair::Hair(int strands,
|
|||
_radius(radius),
|
||||
_acceleration(0.0f),
|
||||
_angularVelocity(0.0f),
|
||||
_angularAcceleration(0.0f),
|
||||
_gravity(0.0f)
|
||||
{
|
||||
_hairPosition = new glm::vec3[_strands * _links];
|
||||
|
@ -127,13 +129,15 @@ void Hair::simulate(float deltaTime) {
|
|||
const float ANGULAR_VELOCITY_MIN = 0.001f;
|
||||
if (glm::length(_angularVelocity) > ANGULAR_VELOCITY_MIN) {
|
||||
glm::vec3 yawVector = _hairPosition[vertexIndex];
|
||||
glm::vec3 angularVelocity = _angularVelocity * HAIR_ANGULAR_VELOCITY_COUPLING;
|
||||
glm::vec3 angularAcceleration = _angularAcceleration * HAIR_ANGULAR_ACCELERATION_COUPLING;
|
||||
yawVector.y = 0.f;
|
||||
if (glm::length(yawVector) > EPSILON) {
|
||||
float radius = glm::length(yawVector);
|
||||
yawVector = glm::normalize(yawVector);
|
||||
float angle = atan2f(yawVector.x, -yawVector.z) + PI;
|
||||
glm::vec3 delta = glm::vec3(-1.f, 0.f, 0.f) * glm::angleAxis(angle, glm::vec3(0, 1, 0));
|
||||
_hairPosition[vertexIndex] -= delta * radius * _angularVelocity.y * HAIR_ANGULAR_VELOCITY_COUPLING * deltaTime;
|
||||
_hairPosition[vertexIndex] -= delta * radius * (angularVelocity.y - angularAcceleration.y) * deltaTime;
|
||||
}
|
||||
glm::vec3 pitchVector = _hairPosition[vertexIndex];
|
||||
pitchVector.x = 0.f;
|
||||
|
@ -142,7 +146,7 @@ void Hair::simulate(float deltaTime) {
|
|||
pitchVector = glm::normalize(pitchVector);
|
||||
float angle = atan2f(pitchVector.y, -pitchVector.z) + PI;
|
||||
glm::vec3 delta = glm::vec3(0.0f, 1.0f, 0.f) * glm::angleAxis(angle, glm::vec3(1, 0, 0));
|
||||
_hairPosition[vertexIndex] -= delta * radius * _angularVelocity.x * HAIR_ANGULAR_VELOCITY_COUPLING * deltaTime;
|
||||
_hairPosition[vertexIndex] -= delta * radius * (angularVelocity.x - angularAcceleration.x) * deltaTime;
|
||||
}
|
||||
glm::vec3 rollVector = _hairPosition[vertexIndex];
|
||||
rollVector.z = 0.f;
|
||||
|
@ -151,7 +155,7 @@ void Hair::simulate(float deltaTime) {
|
|||
pitchVector = glm::normalize(rollVector);
|
||||
float angle = atan2f(rollVector.x, rollVector.y) + PI;
|
||||
glm::vec3 delta = glm::vec3(-1.0f, 0.0f, 0.f) * glm::angleAxis(angle, glm::vec3(0, 0, 1));
|
||||
_hairPosition[vertexIndex] -= delta * radius * _angularVelocity.z * HAIR_ANGULAR_VELOCITY_COUPLING * deltaTime;
|
||||
_hairPosition[vertexIndex] -= delta * radius * (angularVelocity.z - angularAcceleration.z) * deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
void render();
|
||||
void setAcceleration(const glm::vec3& acceleration) { _acceleration = acceleration; }
|
||||
void setAngularVelocity(const glm::vec3& angularVelocity) { _angularVelocity = angularVelocity; }
|
||||
void setAngularAcceleration(const glm::vec3& angularAcceleration) { _angularAcceleration = angularAcceleration; }
|
||||
void setGravity(const glm::vec3& gravity) { _gravity = gravity; }
|
||||
|
||||
private:
|
||||
|
@ -58,6 +59,7 @@ private:
|
|||
int* _hairConstraints;
|
||||
glm::vec3 _acceleration;
|
||||
glm::vec3 _angularVelocity;
|
||||
glm::vec3 _angularAcceleration;
|
||||
glm::vec3 _gravity;
|
||||
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ Avatar::Avatar() :
|
|||
_lastVelocity(0.0f, 0.0f, 0.0f),
|
||||
_acceleration(0.0f, 0.0f, 0.0f),
|
||||
_angularVelocity(0.0f, 0.0f, 0.0f),
|
||||
_lastAngularVelocity(0.0f, 0.0f, 0.0f),
|
||||
_angularAcceleration(0.0f, 0.0f, 0.0f),
|
||||
_lastOrientation(),
|
||||
_leanScale(0.5f),
|
||||
_scale(1.0f),
|
||||
|
@ -60,7 +62,6 @@ Avatar::Avatar() :
|
|||
_mouseRayDirection(0.0f, 0.0f, 0.0f),
|
||||
_moving(false),
|
||||
_collisionGroups(0),
|
||||
_numLocalLights(0),
|
||||
_initialized(false),
|
||||
_shouldRenderBillboard(true)
|
||||
{
|
||||
|
@ -151,7 +152,8 @@ void Avatar::simulate(float deltaTime) {
|
|||
if (Menu::getInstance()->isOptionChecked(MenuOption::StringHair)) {
|
||||
PerformanceTimer perfTimer("hair");
|
||||
_hair.setAcceleration(getAcceleration() * getHead()->getFinalOrientationInWorldFrame());
|
||||
_hair.setAngularVelocity(getAngularVelocity() + getHead()->getAngularVelocity() * getHead()->getFinalOrientationInWorldFrame());
|
||||
_hair.setAngularVelocity((getAngularVelocity() + getHead()->getAngularVelocity()) * getHead()->getFinalOrientationInWorldFrame());
|
||||
_hair.setAngularAcceleration(getAngularAcceleration() * getHead()->getFinalOrientationInWorldFrame());
|
||||
_hair.setGravity(Application::getInstance()->getEnvironment()->getGravity(getPosition()) * getHead()->getFinalOrientationInWorldFrame());
|
||||
_hair.simulate(deltaTime);
|
||||
}
|
||||
|
@ -187,6 +189,7 @@ void Avatar::updateAcceleration(float deltaTime) {
|
|||
glm::quat orientation = getOrientation();
|
||||
glm::quat delta = glm::inverse(_lastOrientation) * orientation;
|
||||
_angularVelocity = safeEulerAngles(delta) * (1.f / deltaTime);
|
||||
_angularAcceleration = (_angularVelocity - _lastAngularVelocity) * (1.f / deltaTime);
|
||||
_lastOrientation = getOrientation();
|
||||
}
|
||||
|
||||
|
@ -245,19 +248,9 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode) {
|
|||
|
||||
|
||||
// local lights directions and colors
|
||||
getSkeletonModel().setNumLocalLights(_numLocalLights);
|
||||
getHead()->getFaceModel().setNumLocalLights(_numLocalLights);
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
glm::vec3 normalized = glm::normalize(_localLightDirections[i]);
|
||||
|
||||
// body
|
||||
getSkeletonModel().setLocalLightColor(_localLightColors[i], i);
|
||||
getSkeletonModel().setLocalLightDirection(normalized, i);
|
||||
|
||||
// head
|
||||
getHead()->getFaceModel().setLocalLightColor(_localLightColors[i], i);
|
||||
getHead()->getFaceModel().setLocalLightDirection(_localLightDirections[i], i);
|
||||
}
|
||||
const QVector<Model::LocalLight>& localLights = Application::getInstance()->getAvatarManager().getLocalLights();
|
||||
_skeletonModel.setLocalLights(localLights);
|
||||
getHead()->getFaceModel().setLocalLights(localLights);
|
||||
|
||||
// render body
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Avatars)) {
|
||||
|
@ -926,36 +919,3 @@ void Avatar::setShowDisplayName(bool showDisplayName) {
|
|||
|
||||
}
|
||||
|
||||
void Avatar::setLocalLightDirection(const glm::vec3& direction, int lightIndex) {
|
||||
_localLightDirections[lightIndex] = direction;
|
||||
}
|
||||
|
||||
void Avatar::setLocalLightColor(const glm::vec3& color, int lightIndex) {
|
||||
_localLightColors[lightIndex] = color;
|
||||
}
|
||||
|
||||
void Avatar::addLocalLight() {
|
||||
if (_numLocalLights + 1 <= MAX_LOCAL_LIGHTS) {
|
||||
++_numLocalLights;
|
||||
}
|
||||
}
|
||||
|
||||
void Avatar::removeLocalLight() {
|
||||
if (_numLocalLights - 1 >= 0) {
|
||||
--_numLocalLights;
|
||||
}
|
||||
}
|
||||
|
||||
int Avatar::getNumLocalLights() {
|
||||
return _numLocalLights;
|
||||
}
|
||||
|
||||
glm::vec3 Avatar::getLocalLightDirection(int lightIndex) {
|
||||
return _localLightDirections[lightIndex];
|
||||
}
|
||||
|
||||
glm::vec3 Avatar::getLocalLightColor(int lightIndex) {
|
||||
return _localLightColors[lightIndex];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -152,6 +152,8 @@ public:
|
|||
|
||||
glm::vec3 getAcceleration() const { return _acceleration; }
|
||||
glm::vec3 getAngularVelocity() const { return _angularVelocity; }
|
||||
glm::vec3 getAngularAcceleration() const { return _angularAcceleration; }
|
||||
|
||||
|
||||
/// Scales a world space position vector relative to the avatar position and scale
|
||||
/// \param vector position to be scaled. Will store the result
|
||||
|
@ -159,14 +161,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void updateCollisionGroups();
|
||||
void setLocalLightDirection(const glm::vec3& direction, int lightIndex);
|
||||
void setLocalLightColor(const glm::vec3& color, int lightIndex);
|
||||
void addLocalLight();
|
||||
void removeLocalLight();
|
||||
int getNumLocalLights();
|
||||
glm::vec3 getLocalLightDirection(int lightIndex);
|
||||
glm::vec3 getLocalLightColor(int lightIndex);
|
||||
|
||||
|
||||
signals:
|
||||
void collisionWithAvatar(const QUuid& myUUID, const QUuid& theirUUID, const CollisionInfo& collision);
|
||||
|
||||
|
@ -179,6 +174,8 @@ protected:
|
|||
glm::vec3 _lastVelocity;
|
||||
glm::vec3 _acceleration;
|
||||
glm::vec3 _angularVelocity;
|
||||
glm::vec3 _lastAngularVelocity;
|
||||
glm::vec3 _angularAcceleration;
|
||||
glm::quat _lastOrientation;
|
||||
float _leanScale;
|
||||
float _scale;
|
||||
|
@ -189,11 +186,6 @@ protected:
|
|||
bool _moving; ///< set when position is changing
|
||||
|
||||
quint32 _collisionGroups;
|
||||
|
||||
// always-present local lighting for the avatar
|
||||
glm::vec3 _localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
glm::vec3 _localLightColors[MAX_LOCAL_LIGHTS];
|
||||
int _numLocalLights;
|
||||
|
||||
// protected methods...
|
||||
glm::vec3 getBodyRightDirection() const { return getOrientation() * IDENTITY_RIGHT; }
|
||||
|
|
|
@ -159,58 +159,21 @@ void AvatarManager::clearOtherAvatars() {
|
|||
_myAvatar->clearLookAtTargetAvatar();
|
||||
}
|
||||
|
||||
Avatar* AvatarManager::getAvatarFromIndex(int avatarIndex) {
|
||||
Avatar* avatar = NULL;
|
||||
int numAvatars = _avatarHash.count();
|
||||
if (avatarIndex < numAvatars) {
|
||||
QUuid key = (_avatarHash.keys())[avatarIndex];
|
||||
|
||||
const AvatarSharedPointer& avatarPointer = _avatarHash.value(key);
|
||||
avatar = static_cast<Avatar*>(avatarPointer.data());
|
||||
void AvatarManager::setLocalLights(const QVector<Model::LocalLight>& localLights) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "setLocalLights", Q_ARG(const QVector<Model::LocalLight>&, localLights));
|
||||
return;
|
||||
}
|
||||
|
||||
return avatar;
|
||||
_localLights = localLights;
|
||||
}
|
||||
|
||||
void AvatarManager::addAvatarLocalLight(int avatarIndex) {
|
||||
Avatar* avatar = getAvatarFromIndex(avatarIndex);
|
||||
if (avatar) {
|
||||
avatar->addLocalLight();
|
||||
QVector<Model::LocalLight> AvatarManager::getLocalLights() const {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QVector<Model::LocalLight> result;
|
||||
QMetaObject::invokeMethod(const_cast<AvatarManager*>(this), "getLocalLights", Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QVector<Model::LocalLight>, result));
|
||||
return result;
|
||||
}
|
||||
return _localLights;
|
||||
}
|
||||
|
||||
void AvatarManager::removeAvatarLocalLight(int avatarIndex) {
|
||||
Avatar* avatar = getAvatarFromIndex(avatarIndex);
|
||||
if (avatar) {
|
||||
avatar->removeLocalLight();
|
||||
}
|
||||
}
|
||||
|
||||
void AvatarManager::setAvatarLightDirection(const glm::vec3& direction, int lightIndex, int avatarIndex) {
|
||||
Avatar* avatar = getAvatarFromIndex(avatarIndex);
|
||||
if (avatar) {
|
||||
avatar->setLocalLightDirection(direction, lightIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void AvatarManager::setAvatarLightColor(const glm::vec3& color, int lightIndex, int avatarIndex) {
|
||||
Avatar* avatar = getAvatarFromIndex(avatarIndex);
|
||||
if (avatar) {
|
||||
avatar->setLocalLightColor(color, lightIndex);
|
||||
}
|
||||
}
|
||||
|
||||
int AvatarManager::getNumLightsInAvatar(int avatarIndex) {
|
||||
int numLights = 0;
|
||||
|
||||
Avatar* avatar = getAvatarFromIndex(avatarIndex);
|
||||
if (avatar) {
|
||||
numLights = avatar->getNumLocalLights();
|
||||
}
|
||||
|
||||
return numLights;
|
||||
}
|
||||
|
||||
int AvatarManager::getNumAvatars() {
|
||||
return _avatarHash.count();
|
||||
}
|
||||
|
|
|
@ -37,13 +37,8 @@ public:
|
|||
|
||||
void clearOtherAvatars();
|
||||
|
||||
public slots:
|
||||
void setAvatarLightColor(const glm::vec3& color, int lightIndex, int avatarIndex);
|
||||
void setAvatarLightDirection(const glm::vec3& direction, int lightIndex, int avatarIndex);
|
||||
void removeAvatarLocalLight(int avatarIndex);
|
||||
void addAvatarLocalLight(int avatarIndex);
|
||||
int getNumLightsInAvatar(int avatarIndex);
|
||||
int getNumAvatars();
|
||||
Q_INVOKABLE void setLocalLights(const QVector<Model::LocalLight>& localLights);
|
||||
Q_INVOKABLE QVector<Model::LocalLight> getLocalLights() const;
|
||||
|
||||
private:
|
||||
AvatarManager(const AvatarManager& other);
|
||||
|
@ -53,13 +48,13 @@ private:
|
|||
|
||||
AvatarSharedPointer newSharedAvatar();
|
||||
|
||||
Avatar* getAvatarFromIndex(int avatarIndex);
|
||||
|
||||
// virtual override
|
||||
AvatarHash::iterator erase(const AvatarHash::iterator& iterator);
|
||||
|
||||
QVector<AvatarSharedPointer> _avatarFades;
|
||||
QSharedPointer<MyAvatar> _myAvatar;
|
||||
|
||||
QVector<Model::LocalLight> _localLights;
|
||||
};
|
||||
|
||||
#endif // hifi_AvatarManager_h
|
||||
|
|
|
@ -187,7 +187,8 @@ void MyAvatar::simulate(float deltaTime) {
|
|||
PerformanceTimer perfTimer("hair");
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::StringHair)) {
|
||||
_hair.setAcceleration(getAcceleration() * getHead()->getFinalOrientationInWorldFrame());
|
||||
_hair.setAngularVelocity(getAngularVelocity() + getHead()->getAngularVelocity() * getHead()->getFinalOrientationInWorldFrame());
|
||||
_hair.setAngularVelocity((getAngularVelocity() + getHead()->getAngularVelocity()) * getHead()->getFinalOrientationInWorldFrame());
|
||||
_hair.setAngularAcceleration(getAngularAcceleration() * getHead()->getFinalOrientationInWorldFrame());
|
||||
_hair.setGravity(Application::getInstance()->getEnvironment()->getGravity(getPosition()) * getHead()->getFinalOrientationInWorldFrame());
|
||||
_hair.simulate(deltaTime);
|
||||
}
|
||||
|
|
|
@ -16,9 +16,7 @@
|
|||
#include <QUdpSocket>
|
||||
|
||||
#ifdef HAVE_FACESHIFT
|
||||
|
||||
#include <fsbinarystream.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include "FaceTracker.h"
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <QMetaType>
|
||||
#include <QRunnable>
|
||||
#include <QScriptEngine>
|
||||
#include <QThreadPool>
|
||||
|
||||
#include <glm/gtx/transform.hpp>
|
||||
|
@ -19,6 +20,7 @@
|
|||
#include <CapsuleShape.h>
|
||||
#include <GeometryUtil.h>
|
||||
#include <PhysicsEntity.h>
|
||||
#include <RegisteredMetaTypes.h>
|
||||
#include <ShapeCollider.h>
|
||||
#include <SphereShape.h>
|
||||
|
||||
|
@ -31,6 +33,23 @@ static int modelPointerTypeId = qRegisterMetaType<QPointer<Model> >();
|
|||
static int weakNetworkGeometryPointerTypeId = qRegisterMetaType<QWeakPointer<NetworkGeometry> >();
|
||||
static int vec3VectorTypeId = qRegisterMetaType<QVector<glm::vec3> >();
|
||||
|
||||
static QScriptValue localLightToScriptValue(QScriptEngine* engine, const Model::LocalLight& light) {
|
||||
QScriptValue object = engine->newObject();
|
||||
object.setProperty("direction", vec3toScriptValue(engine, light.direction));
|
||||
object.setProperty("color", vec3toScriptValue(engine, light.color));
|
||||
return object;
|
||||
}
|
||||
|
||||
static void localLightFromScriptValue(const QScriptValue& value, Model::LocalLight& light) {
|
||||
vec3FromScriptValue(value.property("direction"), light.direction);
|
||||
vec3FromScriptValue(value.property("color"), light.color);
|
||||
}
|
||||
|
||||
void Model::registerMetaTypes(QScriptEngine* engine) {
|
||||
qScriptRegisterMetaType(engine, localLightToScriptValue, localLightFromScriptValue);
|
||||
qScriptRegisterSequenceMetaType<QVector<Model::LocalLight> >(engine);
|
||||
}
|
||||
|
||||
Model::Model(QObject* parent) :
|
||||
QObject(parent),
|
||||
_scale(1.0f, 1.0f, 1.0f),
|
||||
|
@ -85,17 +104,18 @@ ProgramObject Model::_skinCascadedShadowNormalSpecularMapProgram;
|
|||
|
||||
ProgramObject Model::_skinShadowProgram;
|
||||
|
||||
int Model::_normalMapTangentLocation;
|
||||
int Model::_normalSpecularMapTangentLocation;
|
||||
int Model::_shadowNormalMapTangentLocation;
|
||||
int Model::_shadowNormalSpecularMapTangentLocation;
|
||||
int Model::_cascadedShadowNormalMapTangentLocation;
|
||||
int Model::_cascadedShadowNormalSpecularMapTangentLocation;
|
||||
|
||||
int Model::_cascadedShadowMapDistancesLocation;
|
||||
int Model::_cascadedShadowNormalMapDistancesLocation;
|
||||
int Model::_cascadedShadowSpecularMapDistancesLocation;
|
||||
int Model::_cascadedShadowNormalSpecularMapDistancesLocation;
|
||||
Model::Locations Model::_locations;
|
||||
Model::Locations Model::_normalMapLocations;
|
||||
Model::Locations Model::_specularMapLocations;
|
||||
Model::Locations Model::_normalSpecularMapLocations;
|
||||
Model::Locations Model::_shadowMapLocations;
|
||||
Model::Locations Model::_shadowNormalMapLocations;
|
||||
Model::Locations Model::_shadowSpecularMapLocations;
|
||||
Model::Locations Model::_shadowNormalSpecularMapLocations;
|
||||
Model::Locations Model::_cascadedShadowMapLocations;
|
||||
Model::Locations Model::_cascadedShadowNormalMapLocations;
|
||||
Model::Locations Model::_cascadedShadowSpecularMapLocations;
|
||||
Model::Locations Model::_cascadedShadowNormalSpecularMapLocations;
|
||||
|
||||
Model::SkinLocations Model::_skinLocations;
|
||||
Model::SkinLocations Model::_skinNormalMapLocations;
|
||||
|
@ -141,15 +161,13 @@ void Model::setOffset(const glm::vec3& offset) {
|
|||
_snappedToCenter = false;
|
||||
}
|
||||
|
||||
|
||||
void Model::initSkinProgram(ProgramObject& program, Model::SkinLocations& locations,
|
||||
void Model::initProgram(ProgramObject& program, Model::Locations& locations,
|
||||
int specularTextureUnit, int shadowTextureUnit) {
|
||||
program.bind();
|
||||
locations.clusterMatrices = program.uniformLocation("clusterMatrices");
|
||||
locations.clusterIndices = program.attributeLocation("clusterIndices");
|
||||
locations.clusterWeights = program.attributeLocation("clusterWeights");
|
||||
locations.tangent = program.attributeLocation("tangent");
|
||||
locations.shadowDistances = program.uniformLocation("shadowDistances");
|
||||
locations.localLightColors = program.uniformLocation("localLightColors");
|
||||
locations.localLightDirections = program.uniformLocation("localLightDirections");
|
||||
program.setUniformValue("diffuseMap", 0);
|
||||
program.setUniformValue("normalMap", 1);
|
||||
program.setUniformValue("specularMap", specularTextureUnit);
|
||||
|
@ -157,6 +175,17 @@ void Model::initSkinProgram(ProgramObject& program, Model::SkinLocations& locati
|
|||
program.release();
|
||||
}
|
||||
|
||||
void Model::initSkinProgram(ProgramObject& program, Model::SkinLocations& locations,
|
||||
int specularTextureUnit, int shadowTextureUnit) {
|
||||
initProgram(program, locations, specularTextureUnit, shadowTextureUnit);
|
||||
|
||||
program.bind();
|
||||
locations.clusterMatrices = program.uniformLocation("clusterMatrices");
|
||||
locations.clusterIndices = program.attributeLocation("clusterIndices");
|
||||
locations.clusterWeights = program.attributeLocation("clusterWeights");
|
||||
program.release();
|
||||
}
|
||||
|
||||
QVector<JointState> Model::createJointStates(const FBXGeometry& geometry) {
|
||||
QVector<JointState> jointStates;
|
||||
foreach (const FBXJoint& joint, geometry.joints) {
|
||||
|
@ -193,9 +222,7 @@ void Model::init() {
|
|||
_program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/model.frag");
|
||||
_program.link();
|
||||
|
||||
_program.bind();
|
||||
_program.setUniformValue("diffuseMap", 0);
|
||||
_program.release();
|
||||
initProgram(_program, _locations);
|
||||
|
||||
_normalMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
Application::resourcesPath() + "shaders/model_normal_map.vert");
|
||||
|
@ -203,11 +230,7 @@ void Model::init() {
|
|||
Application::resourcesPath() + "shaders/model_normal_map.frag");
|
||||
_normalMapProgram.link();
|
||||
|
||||
_normalMapProgram.bind();
|
||||
_normalMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_normalMapProgram.setUniformValue("normalMap", 1);
|
||||
_normalMapTangentLocation = _normalMapProgram.attributeLocation("tangent");
|
||||
_normalMapProgram.release();
|
||||
initProgram(_normalMapProgram, _normalMapLocations);
|
||||
|
||||
_specularMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
Application::resourcesPath() + "shaders/model.vert");
|
||||
|
@ -215,10 +238,7 @@ void Model::init() {
|
|||
Application::resourcesPath() + "shaders/model_specular_map.frag");
|
||||
_specularMapProgram.link();
|
||||
|
||||
_specularMapProgram.bind();
|
||||
_specularMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_specularMapProgram.setUniformValue("specularMap", 1);
|
||||
_specularMapProgram.release();
|
||||
initProgram(_specularMapProgram, _specularMapLocations);
|
||||
|
||||
_normalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
Application::resourcesPath() + "shaders/model_normal_map.vert");
|
||||
|
@ -226,12 +246,7 @@ void Model::init() {
|
|||
Application::resourcesPath() + "shaders/model_normal_specular_map.frag");
|
||||
_normalSpecularMapProgram.link();
|
||||
|
||||
_normalSpecularMapProgram.bind();
|
||||
_normalSpecularMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_normalSpecularMapProgram.setUniformValue("normalMap", 1);
|
||||
_normalSpecularMapProgram.setUniformValue("specularMap", 2);
|
||||
_normalSpecularMapTangentLocation = _normalSpecularMapProgram.attributeLocation("tangent");
|
||||
_normalSpecularMapProgram.release();
|
||||
initProgram(_normalSpecularMapProgram, _normalSpecularMapLocations, 2);
|
||||
|
||||
|
||||
_shadowMapProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/model.vert");
|
||||
|
@ -239,10 +254,7 @@ void Model::init() {
|
|||
"shaders/model_shadow_map.frag");
|
||||
_shadowMapProgram.link();
|
||||
|
||||
_shadowMapProgram.bind();
|
||||
_shadowMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_shadowMapProgram.setUniformValue("shadowMap", 1);
|
||||
_shadowMapProgram.release();
|
||||
initProgram(_shadowMapProgram, _shadowMapLocations);
|
||||
|
||||
_shadowNormalMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
Application::resourcesPath() + "shaders/model_normal_map.vert");
|
||||
|
@ -250,12 +262,7 @@ void Model::init() {
|
|||
Application::resourcesPath() + "shaders/model_shadow_normal_map.frag");
|
||||
_shadowNormalMapProgram.link();
|
||||
|
||||
_shadowNormalMapProgram.bind();
|
||||
_shadowNormalMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_shadowNormalMapProgram.setUniformValue("normalMap", 1);
|
||||
_shadowNormalMapProgram.setUniformValue("shadowMap", 2);
|
||||
_shadowNormalMapTangentLocation = _shadowNormalMapProgram.attributeLocation("tangent");
|
||||
_shadowNormalMapProgram.release();
|
||||
initProgram(_shadowNormalMapProgram, _shadowNormalMapLocations, 1, 2);
|
||||
|
||||
_shadowSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
Application::resourcesPath() + "shaders/model.vert");
|
||||
|
@ -263,11 +270,7 @@ void Model::init() {
|
|||
Application::resourcesPath() + "shaders/model_shadow_specular_map.frag");
|
||||
_shadowSpecularMapProgram.link();
|
||||
|
||||
_shadowSpecularMapProgram.bind();
|
||||
_shadowSpecularMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_shadowSpecularMapProgram.setUniformValue("specularMap", 1);
|
||||
_shadowSpecularMapProgram.setUniformValue("shadowMap", 2);
|
||||
_shadowSpecularMapProgram.release();
|
||||
initProgram(_shadowSpecularMapProgram, _shadowSpecularMapLocations, 1, 2);
|
||||
|
||||
_shadowNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
Application::resourcesPath() + "shaders/model_normal_map.vert");
|
||||
|
@ -275,13 +278,7 @@ void Model::init() {
|
|||
Application::resourcesPath() + "shaders/model_shadow_normal_specular_map.frag");
|
||||
_shadowNormalSpecularMapProgram.link();
|
||||
|
||||
_shadowNormalSpecularMapProgram.bind();
|
||||
_shadowNormalSpecularMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_shadowNormalSpecularMapProgram.setUniformValue("normalMap", 1);
|
||||
_shadowNormalSpecularMapProgram.setUniformValue("specularMap", 2);
|
||||
_shadowNormalSpecularMapProgram.setUniformValue("shadowMap", 3);
|
||||
_shadowNormalSpecularMapTangentLocation = _shadowNormalSpecularMapProgram.attributeLocation("tangent");
|
||||
_shadowNormalSpecularMapProgram.release();
|
||||
initProgram(_shadowNormalSpecularMapProgram, _shadowNormalSpecularMapLocations, 2, 3);
|
||||
|
||||
|
||||
_cascadedShadowMapProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
|
||||
|
@ -290,11 +287,7 @@ void Model::init() {
|
|||
"shaders/model_cascaded_shadow_map.frag");
|
||||
_cascadedShadowMapProgram.link();
|
||||
|
||||
_cascadedShadowMapProgram.bind();
|
||||
_cascadedShadowMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_cascadedShadowMapProgram.setUniformValue("shadowMap", 1);
|
||||
_cascadedShadowMapDistancesLocation = _cascadedShadowMapProgram.uniformLocation("shadowDistances");
|
||||
_cascadedShadowMapProgram.release();
|
||||
initProgram(_cascadedShadowMapProgram, _cascadedShadowMapLocations);
|
||||
|
||||
_cascadedShadowNormalMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
Application::resourcesPath() + "shaders/model_normal_map.vert");
|
||||
|
@ -302,13 +295,7 @@ void Model::init() {
|
|||
Application::resourcesPath() + "shaders/model_cascaded_shadow_normal_map.frag");
|
||||
_cascadedShadowNormalMapProgram.link();
|
||||
|
||||
_cascadedShadowNormalMapProgram.bind();
|
||||
_cascadedShadowNormalMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_cascadedShadowNormalMapProgram.setUniformValue("normalMap", 1);
|
||||
_cascadedShadowNormalMapProgram.setUniformValue("shadowMap", 2);
|
||||
_cascadedShadowNormalMapDistancesLocation = _cascadedShadowNormalMapProgram.uniformLocation("shadowDistances");
|
||||
_cascadedShadowNormalMapTangentLocation = _cascadedShadowNormalMapProgram.attributeLocation("tangent");
|
||||
_cascadedShadowNormalMapProgram.release();
|
||||
initProgram(_cascadedShadowNormalMapProgram, _cascadedShadowNormalMapLocations, 1, 2);
|
||||
|
||||
_cascadedShadowSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
Application::resourcesPath() + "shaders/model.vert");
|
||||
|
@ -316,12 +303,7 @@ void Model::init() {
|
|||
Application::resourcesPath() + "shaders/model_cascaded_shadow_specular_map.frag");
|
||||
_cascadedShadowSpecularMapProgram.link();
|
||||
|
||||
_cascadedShadowSpecularMapProgram.bind();
|
||||
_cascadedShadowSpecularMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_cascadedShadowSpecularMapProgram.setUniformValue("specularMap", 1);
|
||||
_cascadedShadowSpecularMapProgram.setUniformValue("shadowMap", 2);
|
||||
_cascadedShadowSpecularMapDistancesLocation = _cascadedShadowSpecularMapProgram.uniformLocation("shadowDistances");
|
||||
_cascadedShadowSpecularMapProgram.release();
|
||||
initProgram(_cascadedShadowSpecularMapProgram, _cascadedShadowSpecularMapLocations, 1, 2);
|
||||
|
||||
_cascadedShadowNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
Application::resourcesPath() + "shaders/model_normal_map.vert");
|
||||
|
@ -329,15 +311,7 @@ void Model::init() {
|
|||
Application::resourcesPath() + "shaders/model_cascaded_shadow_normal_specular_map.frag");
|
||||
_cascadedShadowNormalSpecularMapProgram.link();
|
||||
|
||||
_cascadedShadowNormalSpecularMapProgram.bind();
|
||||
_cascadedShadowNormalSpecularMapProgram.setUniformValue("diffuseMap", 0);
|
||||
_cascadedShadowNormalSpecularMapProgram.setUniformValue("normalMap", 1);
|
||||
_cascadedShadowNormalSpecularMapProgram.setUniformValue("specularMap", 2);
|
||||
_cascadedShadowNormalSpecularMapProgram.setUniformValue("shadowMap", 3);
|
||||
_cascadedShadowNormalSpecularMapDistancesLocation =
|
||||
_cascadedShadowNormalSpecularMapProgram.uniformLocation("shadowDistances");
|
||||
_cascadedShadowNormalSpecularMapTangentLocation = _cascadedShadowNormalSpecularMapProgram.attributeLocation("tangent");
|
||||
_cascadedShadowNormalSpecularMapProgram.release();
|
||||
initProgram(_cascadedShadowNormalSpecularMapProgram, _cascadedShadowNormalSpecularMapLocations, 2, 3);
|
||||
|
||||
|
||||
_shadowProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/model_shadow.vert");
|
||||
|
@ -609,6 +583,17 @@ bool Model::render(float alpha, RenderMode mode, bool receiveShadows) {
|
|||
glEnable(GL_CULL_FACE);
|
||||
if (mode == SHADOW_RENDER_MODE) {
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
} else if (mode == DEFAULT_RENDER_MODE) {
|
||||
// update the local lights
|
||||
for (int i = 0; i < MAX_LOCAL_LIGHTS; i++) {
|
||||
if (i < _localLights.size()) {
|
||||
_localLightDirections[i] = glm::normalize(Application::getInstance()->getUntranslatedViewMatrix() *
|
||||
glm::vec4(_rotation * _localLights.at(i).direction, 0.0f));
|
||||
} else {
|
||||
_localLightColors[i] = glm::vec4();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1384,10 +1369,9 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
|
|||
const_cast<QOpenGLBuffer&>(networkMesh.vertexBuffer).bind();
|
||||
|
||||
ProgramObject* program = &_program;
|
||||
Locations* locations = &_locations;
|
||||
ProgramObject* skinProgram = &_skinProgram;
|
||||
SkinLocations* skinLocations = &_skinLocations;
|
||||
int tangentLocation = _normalMapTangentLocation;
|
||||
int shadowDistancesLocation = _cascadedShadowMapDistancesLocation;
|
||||
GLenum specularTextureUnit = 0;
|
||||
GLenum shadowTextureUnit = 0;
|
||||
if (mode == SHADOW_RENDER_MODE) {
|
||||
|
@ -1400,41 +1384,40 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
|
|||
if (receiveShadows) {
|
||||
if (cascadedShadows) {
|
||||
program = &_cascadedShadowNormalSpecularMapProgram;
|
||||
locations = &_cascadedShadowNormalSpecularMapLocations;
|
||||
skinProgram = &_skinCascadedShadowNormalSpecularMapProgram;
|
||||
skinLocations = &_skinCascadedShadowNormalSpecularMapLocations;
|
||||
tangentLocation = _cascadedShadowNormalSpecularMapTangentLocation;
|
||||
shadowDistancesLocation = _cascadedShadowNormalSpecularMapDistancesLocation;
|
||||
} else {
|
||||
program = &_shadowNormalSpecularMapProgram;
|
||||
locations = &_shadowNormalSpecularMapLocations;
|
||||
skinProgram = &_skinShadowNormalSpecularMapProgram;
|
||||
skinLocations = &_skinShadowNormalSpecularMapLocations;
|
||||
tangentLocation = _shadowNormalSpecularMapTangentLocation;
|
||||
}
|
||||
shadowTextureUnit = GL_TEXTURE3;
|
||||
} else {
|
||||
program = &_normalSpecularMapProgram;
|
||||
locations = &_normalSpecularMapLocations;
|
||||
skinProgram = &_skinNormalSpecularMapProgram;
|
||||
skinLocations = &_skinNormalSpecularMapLocations;
|
||||
tangentLocation = _normalSpecularMapTangentLocation;
|
||||
}
|
||||
specularTextureUnit = GL_TEXTURE2;
|
||||
|
||||
} else if (receiveShadows) {
|
||||
if (cascadedShadows) {
|
||||
program = &_cascadedShadowNormalMapProgram;
|
||||
locations = &_cascadedShadowNormalMapLocations;
|
||||
skinProgram = &_skinCascadedShadowNormalMapProgram;
|
||||
skinLocations = &_skinCascadedShadowNormalMapLocations;
|
||||
tangentLocation = _cascadedShadowNormalMapTangentLocation;
|
||||
shadowDistancesLocation = _cascadedShadowNormalMapDistancesLocation;
|
||||
} else {
|
||||
program = &_shadowNormalMapProgram;
|
||||
locations = &_shadowNormalMapLocations;
|
||||
skinProgram = &_skinShadowNormalMapProgram;
|
||||
skinLocations = &_skinShadowNormalMapLocations;
|
||||
tangentLocation = _shadowNormalMapTangentLocation;
|
||||
}
|
||||
shadowTextureUnit = GL_TEXTURE2;
|
||||
} else {
|
||||
program = &_normalMapProgram;
|
||||
locations = &_normalMapLocations;
|
||||
skinProgram = &_skinNormalMapProgram;
|
||||
skinLocations = &_skinNormalMapLocations;
|
||||
}
|
||||
|
@ -1442,17 +1425,19 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
|
|||
if (receiveShadows) {
|
||||
if (cascadedShadows) {
|
||||
program = &_cascadedShadowSpecularMapProgram;
|
||||
locations = &_cascadedShadowSpecularMapLocations;
|
||||
skinProgram = &_skinCascadedShadowSpecularMapProgram;
|
||||
skinLocations = &_skinCascadedShadowSpecularMapLocations;
|
||||
shadowDistancesLocation = _cascadedShadowSpecularMapDistancesLocation;
|
||||
} else {
|
||||
program = &_shadowSpecularMapProgram;
|
||||
locations = &_shadowSpecularMapLocations;
|
||||
skinProgram = &_skinShadowSpecularMapProgram;
|
||||
skinLocations = &_skinShadowSpecularMapLocations;
|
||||
}
|
||||
shadowTextureUnit = GL_TEXTURE2;
|
||||
} else {
|
||||
program = &_specularMapProgram;
|
||||
locations = &_specularMapLocations;
|
||||
skinProgram = &_skinSpecularMapProgram;
|
||||
skinLocations = &_skinSpecularMapLocations;
|
||||
}
|
||||
|
@ -1461,10 +1446,12 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
|
|||
} else if (receiveShadows) {
|
||||
if (cascadedShadows) {
|
||||
program = &_cascadedShadowMapProgram;
|
||||
locations = &_cascadedShadowMapLocations;
|
||||
skinProgram = &_skinCascadedShadowMapProgram;
|
||||
skinLocations = &_skinCascadedShadowMapLocations;
|
||||
} else {
|
||||
program = &_shadowMapProgram;
|
||||
locations = &_shadowMapLocations;
|
||||
skinProgram = &_skinShadowMapProgram;
|
||||
skinLocations = &_skinShadowMapLocations;
|
||||
}
|
||||
|
@ -1473,6 +1460,7 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
|
|||
|
||||
const MeshState& state = _meshStates.at(i);
|
||||
ProgramObject* activeProgram = program;
|
||||
Locations* activeLocations = locations;
|
||||
glPushMatrix();
|
||||
Application::getInstance()->loadTranslatedViewMatrix(_translation);
|
||||
|
||||
|
@ -1489,27 +1477,22 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
|
|||
skinProgram->enableAttributeArray(skinLocations->clusterIndices);
|
||||
skinProgram->enableAttributeArray(skinLocations->clusterWeights);
|
||||
activeProgram = skinProgram;
|
||||
tangentLocation = skinLocations->tangent;
|
||||
if (cascadedShadows) {
|
||||
program->setUniform(skinLocations->shadowDistances, Application::getInstance()->getShadowDistances());
|
||||
}
|
||||
activeLocations = skinLocations;
|
||||
|
||||
// local light uniforms
|
||||
skinProgram->setUniformValue("numLocalLights", _numLocalLights);
|
||||
skinProgram->setUniformArray("localLightDirections", _localLightDirections, MAX_LOCAL_LIGHTS);
|
||||
skinProgram->setUniformArray("localLightColors", _localLightColors, MAX_LOCAL_LIGHTS);
|
||||
} else {
|
||||
glMultMatrixf((const GLfloat*)&state.clusterMatrices[0]);
|
||||
program->bind();
|
||||
if (cascadedShadows) {
|
||||
program->setUniform(shadowDistancesLocation, Application::getInstance()->getShadowDistances());
|
||||
}
|
||||
}
|
||||
|
||||
if (cascadedShadows) {
|
||||
activeProgram->setUniform(activeLocations->shadowDistances, Application::getInstance()->getShadowDistances());
|
||||
}
|
||||
activeProgram->setUniformValueArray(activeLocations->localLightDirections,
|
||||
(const GLfloat*)_localLightDirections, MAX_LOCAL_LIGHTS, 4);
|
||||
|
||||
if (mesh.blendshapes.isEmpty()) {
|
||||
if (!(mesh.tangents.isEmpty() || mode == SHADOW_RENDER_MODE)) {
|
||||
activeProgram->setAttributeBuffer(tangentLocation, GL_FLOAT, vertexCount * 2 * sizeof(glm::vec3), 3);
|
||||
activeProgram->enableAttributeArray(tangentLocation);
|
||||
activeProgram->setAttributeBuffer(activeLocations->tangent, GL_FLOAT, vertexCount * 2 * sizeof(glm::vec3), 3);
|
||||
activeProgram->enableAttributeArray(activeLocations->tangent);
|
||||
}
|
||||
glColorPointer(3, GL_FLOAT, 0, (void*)(vertexCount * 2 * sizeof(glm::vec3) +
|
||||
mesh.tangents.size() * sizeof(glm::vec3)));
|
||||
|
@ -1518,8 +1501,8 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
|
|||
|
||||
} else {
|
||||
if (!(mesh.tangents.isEmpty() || mode == SHADOW_RENDER_MODE)) {
|
||||
activeProgram->setAttributeBuffer(tangentLocation, GL_FLOAT, 0, 3);
|
||||
activeProgram->enableAttributeArray(tangentLocation);
|
||||
activeProgram->setAttributeBuffer(activeLocations->tangent, GL_FLOAT, 0, 3);
|
||||
activeProgram->enableAttributeArray(activeLocations->tangent);
|
||||
}
|
||||
glColorPointer(3, GL_FLOAT, 0, (void*)(mesh.tangents.size() * sizeof(glm::vec3)));
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, (void*)((mesh.tangents.size() + mesh.colors.size()) * sizeof(glm::vec3)));
|
||||
|
@ -1557,6 +1540,12 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
|
|||
glMaterialfv(GL_FRONT, GL_SPECULAR, (const float*)&specular);
|
||||
glMaterialf(GL_FRONT, GL_SHININESS, part.shininess);
|
||||
|
||||
for (int k = 0; k < qMin(MAX_LOCAL_LIGHTS, _localLights.size()); k++) {
|
||||
_localLightColors[k] = glm::vec4(_localLights.at(k).color, 1.0f) * diffuse;
|
||||
}
|
||||
activeProgram->setUniformValueArray(activeLocations->localLightColors,
|
||||
(const GLfloat*)_localLightColors, MAX_LOCAL_LIGHTS, 4);
|
||||
|
||||
Texture* diffuseMap = networkPart.diffuseTexture.data();
|
||||
if (mesh.isEye && diffuseMap) {
|
||||
diffuseMap = (_dilatedTextures[i][j] =
|
||||
|
@ -1607,7 +1596,7 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
|
|||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
activeProgram->disableAttributeArray(tangentLocation);
|
||||
activeProgram->disableAttributeArray(activeLocations->tangent);
|
||||
}
|
||||
|
||||
if (specularTextureUnit) {
|
||||
|
@ -1632,20 +1621,6 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
|
|||
}
|
||||
}
|
||||
|
||||
void Model::setLocalLightDirection(const glm::vec3& direction, int lightIndex) {
|
||||
assert(lightIndex >= 0 && lightIndex < MAX_LOCAL_LIGHTS);
|
||||
_localLightDirections[lightIndex] = direction;
|
||||
}
|
||||
|
||||
void Model::setLocalLightColor(const glm::vec3& color, int lightIndex) {
|
||||
assert(lightIndex >= 0 && lightIndex < MAX_LOCAL_LIGHTS);
|
||||
_localLightColors[lightIndex] = color;
|
||||
}
|
||||
|
||||
void Model::setNumLocalLights(int numLocalLights) {
|
||||
_numLocalLights = numLocalLights;
|
||||
}
|
||||
|
||||
void AnimationHandle::setURL(const QUrl& url) {
|
||||
if (_url != url) {
|
||||
_animation = Application::getInstance()->getAnimationCache()->getAnimation(_url = url);
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "ProgramObject.h"
|
||||
#include "TextureCache.h"
|
||||
|
||||
class QScriptEngine;
|
||||
|
||||
class AnimationHandle;
|
||||
class Shape;
|
||||
|
||||
|
@ -40,6 +42,9 @@ class Model : public QObject, public PhysicsEntity {
|
|||
|
||||
public:
|
||||
|
||||
/// Registers the script types associated with models.
|
||||
static void registerMetaTypes(QScriptEngine* engine);
|
||||
|
||||
Model(QObject* parent = NULL);
|
||||
virtual ~Model();
|
||||
|
||||
|
@ -145,9 +150,14 @@ public:
|
|||
/// Sets blended vertices computed in a separate thread.
|
||||
void setBlendedVertices(const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& normals);
|
||||
|
||||
void setLocalLightDirection(const glm::vec3& direction, int lightIndex);
|
||||
void setLocalLightColor(const glm::vec3& color, int lightIndex);
|
||||
void setNumLocalLights(int numLocalLights);
|
||||
class LocalLight {
|
||||
public:
|
||||
glm::vec3 color;
|
||||
glm::vec3 direction;
|
||||
};
|
||||
|
||||
void setLocalLights(const QVector<LocalLight>& localLights) { _localLights = localLights; }
|
||||
const QVector<LocalLight>& getLocalLights() const { return _localLights; }
|
||||
|
||||
void setShowTrueJointTransforms(bool show) { _showTrueJointTransforms = show; }
|
||||
|
||||
|
@ -165,10 +175,8 @@ protected:
|
|||
bool _snappedToCenter; /// are we currently snapped to center
|
||||
bool _showTrueJointTransforms;
|
||||
|
||||
glm::vec3 _localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
glm::vec3 _localLightColors[MAX_LOCAL_LIGHTS];
|
||||
int _numLocalLights;
|
||||
|
||||
QVector<LocalLight> _localLights;
|
||||
|
||||
QVector<JointState> _jointStates;
|
||||
|
||||
class MeshState {
|
||||
|
@ -250,6 +258,9 @@ private:
|
|||
|
||||
QList<AnimationHandlePointer> _runningAnimations;
|
||||
|
||||
glm::vec4 _localLightColors[MAX_LOCAL_LIGHTS];
|
||||
glm::vec4 _localLightDirections[MAX_LOCAL_LIGHTS];
|
||||
|
||||
static ProgramObject _program;
|
||||
static ProgramObject _normalMapProgram;
|
||||
static ProgramObject _specularMapProgram;
|
||||
|
@ -296,13 +307,35 @@ private:
|
|||
static int _cascadedShadowSpecularMapDistancesLocation;
|
||||
static int _cascadedShadowNormalSpecularMapDistancesLocation;
|
||||
|
||||
class SkinLocations {
|
||||
class Locations {
|
||||
public:
|
||||
int localLightColors;
|
||||
int localLightDirections;
|
||||
int tangent;
|
||||
int shadowDistances;
|
||||
};
|
||||
|
||||
static Locations _locations;
|
||||
static Locations _normalMapLocations;
|
||||
static Locations _specularMapLocations;
|
||||
static Locations _normalSpecularMapLocations;
|
||||
static Locations _shadowMapLocations;
|
||||
static Locations _shadowNormalMapLocations;
|
||||
static Locations _shadowSpecularMapLocations;
|
||||
static Locations _shadowNormalSpecularMapLocations;
|
||||
static Locations _cascadedShadowMapLocations;
|
||||
static Locations _cascadedShadowNormalMapLocations;
|
||||
static Locations _cascadedShadowSpecularMapLocations;
|
||||
static Locations _cascadedShadowNormalSpecularMapLocations;
|
||||
|
||||
static void initProgram(ProgramObject& program, Locations& locations,
|
||||
int specularTextureUnit = 1, int shadowTextureUnit = 1);
|
||||
|
||||
class SkinLocations : public Locations {
|
||||
public:
|
||||
int clusterMatrices;
|
||||
int clusterIndices;
|
||||
int clusterWeights;
|
||||
int tangent;
|
||||
int shadowDistances;
|
||||
int clusterWeights;
|
||||
};
|
||||
|
||||
static SkinLocations _skinLocations;
|
||||
|
@ -326,6 +359,8 @@ private:
|
|||
Q_DECLARE_METATYPE(QPointer<Model>)
|
||||
Q_DECLARE_METATYPE(QWeakPointer<NetworkGeometry>)
|
||||
Q_DECLARE_METATYPE(QVector<glm::vec3>)
|
||||
Q_DECLARE_METATYPE(Model::LocalLight)
|
||||
Q_DECLARE_METATYPE(QVector<Model::LocalLight>)
|
||||
|
||||
/// Represents a handle to a model animation.
|
||||
class AnimationHandle : public QObject {
|
||||
|
|
|
@ -828,19 +828,19 @@ void Stats::display(
|
|||
}
|
||||
|
||||
// draw local light stats
|
||||
int numLocalLights = myAvatar->getNumLocalLights();
|
||||
QVector<Model::LocalLight> localLights = Application::getInstance()->getAvatarManager().getLocalLights();
|
||||
verticalOffset = 400;
|
||||
horizontalOffset = 20;
|
||||
|
||||
char buffer[128];
|
||||
for (int i = 0; i < numLocalLights; i++) {
|
||||
glm::vec3 lightDirection = myAvatar->getLocalLightDirection(i);
|
||||
for (int i = 0; i < localLights.size(); i++) {
|
||||
glm::vec3 lightDirection = localLights.at(i).direction;
|
||||
snprintf(buffer, sizeof(buffer), "Light %d direction (%.2f, %.2f, %.2f)", i, lightDirection.x, lightDirection.y, lightDirection.z);
|
||||
drawText(horizontalOffset, verticalOffset, scale, rotation, font, buffer, color);
|
||||
|
||||
verticalOffset += STATS_PELS_PER_LINE;
|
||||
|
||||
glm::vec3 lightColor = myAvatar->getLocalLightColor(i);
|
||||
glm::vec3 lightColor = localLights.at(i).color;
|
||||
snprintf(buffer, sizeof(buffer), "Light %d color (%.2f, %.2f, %.2f)", i, lightColor.x, lightColor.y, lightColor.z);
|
||||
drawText(horizontalOffset, verticalOffset, scale, rotation, font, buffer, color);
|
||||
|
||||
|
|
Loading…
Reference in a new issue