Working on GL 4

This commit is contained in:
Brad Davis 2015-06-20 22:54:04 -07:00
parent 0000b5a8c8
commit fbf3a0cbe6
23 changed files with 240 additions and 128 deletions

View file

@ -13,6 +13,6 @@
<@def GPU_FEATURE_PROFILE GPU_CORE@> <@def GPU_FEATURE_PROFILE GPU_CORE@>
<@def GPU_TRANSFORM_PROFILE GPU_CORE@> <@def GPU_TRANSFORM_PROFILE GPU_CORE@>
<@def VERSION_HEADER #version 410 core@> <@def VERSION_HEADER #version 430 core@>
<@endif@> <@endif@>

View file

@ -165,8 +165,8 @@ GLBackend::GLShader* compileShader(const Shader& shader) {
char* temp = new char[infoLength] ; char* temp = new char[infoLength] ;
glGetShaderInfoLog(glshader, infoLength, NULL, temp); glGetShaderInfoLog(glshader, infoLength, NULL, temp);
qCDebug(gpulogging) << "GLShader::compileShader - failed to compile the gl shader object:"; qWarning() << "GLShader::compileShader - failed to compile the gl shader object:";
qCDebug(gpulogging) << temp; qWarning() << temp;
/* /*
filestream.open("debugshader.glsl.info.txt"); filestream.open("debugshader.glsl.info.txt");

View file

@ -10,17 +10,14 @@
!> !>
<@if not GPU_INPUTS_SLH@> <@if not GPU_INPUTS_SLH@>
<@def GPU_INPUTS_SLH@> <@def GPU_INPUTS_SLH@>
layout(location = 0) in vec4 inPosition; layout(location = 0) in vec4 inPosition;
layout(location = 1) in vec3 inNormal; layout(location = 1) in vec4 inNormal;
layout(location = 2) in vec4 inColor; layout(location = 2) in vec4 inColor;
layout(location = 3) in vec2 inTexCoord0; layout(location = 3) in vec4 inTexCoord0;
layout(location = 4) in vec3 inTangent; layout(location = 4) in vec4 inTangent;
layout(location = 5) in ivec4 inSkinClusterIndex; layout(location = 5) in ivec4 inSkinClusterIndex;
layout(location = 6) in vec4 inSkinClusterWeight; layout(location = 6) in vec4 inSkinClusterWeight;
layout(location = 7) in vec2 inTexCoord1; layout(location = 7) in vec4 inTexCoord1;
layout(location = 9) in vec4 inInstanceScaleTranslate;
layout(location = 8) in mat4 inInstanceXfm; layout(location = 8) in mat4 inInstanceXfm;
layout(location = 9) in vec2 inInstanceScale;
layout(location = 10) in vec2 inInstanceTranslate;
<@endif@> <@endif@>

View file

@ -18,32 +18,12 @@ struct Material {
vec4 _spare; vec4 _spare;
}; };
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 GPU_FEATURE_PROFILE == GPU_CORE@>
uniform materialBuffer { uniform materialBuffer {
Material _mat; Material _mat;
}; };
Material getMaterial() { Material getMaterial() {
return _mat; return _mat;
} }
<@else@>
uniform vec4 materialBuffer[4];
Material getMaterial() {
Material mat;
mat._diffuse = materialBuffer[0];
mat._specular = materialBuffer[1];
mat._emissive = materialBuffer[2];
mat._spare = materialBuffer[3];
return mat;
}
<@endif@>
<@endif@> <@endif@>

View file

@ -11,6 +11,10 @@
<@if not DEFERRED_BUFFER_WRITE_SLH@> <@if not DEFERRED_BUFFER_WRITE_SLH@>
<@def DEFERRED_BUFFER_WRITE_SLH@> <@def DEFERRED_BUFFER_WRITE_SLH@>
layout(location = 0) out vec4 _fragColor0;
layout(location = 1) out vec4 _fragColor1;
layout(location = 2) out vec4 _fragColor2;
// the glow intensity // the glow intensity
uniform float glowIntensity; uniform float glowIntensity;
@ -25,9 +29,9 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular,
if (alpha != glowIntensity) { if (alpha != glowIntensity) {
discard; discard;
} }
gl_FragData[0] = vec4(diffuse.rgb, alpha); _fragColor0 = vec4(diffuse.rgb, alpha);
gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
gl_FragData[2] = vec4(specular, shininess / 128.0); _fragColor2 = vec4(specular, shininess / 128.0);
} }
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) { void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) {
@ -35,10 +39,10 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 s
discard; discard;
} }
gl_FragData[0] = vec4(diffuse.rgb, alpha); _fragColor0 = vec4(diffuse.rgb, alpha);
//gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); //_fragColor1 = 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); _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);
gl_FragData[2] = vec4(emissive, shininess / 128.0); _fragColor2 = vec4(emissive, shininess / 128.0);
} }
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) { void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) {
@ -46,9 +50,9 @@ void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec
discard; discard;
} }
gl_FragData[0] = vec4(diffuse.rgb, alpha); _fragColor0 = vec4(diffuse.rgb, alpha);
// gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); // _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
// gl_FragData[2] = vec4(specular, shininess / 128.0); // _fragColor2 = vec4(specular, shininess / 128.0);
} }
<@endif@> <@endif@>

View file

@ -16,12 +16,7 @@
uniform samplerCube skyboxMap; uniform samplerCube skyboxMap;
vec4 evalSkyboxLight(vec3 direction, float lod) { vec4 evalSkyboxLight(vec3 direction, float lod) {
vec4 skytexel = textureLod(skyboxMap, direction, lod * textureQueryLevels(skyboxMap));
<@if GPU_TRANSFORM_PROFILE == GPU_CORE@>
vec4 skytexel = textureCubeLod(skyboxMap, direction, lod * textureQueryLevels(skyboxMap));
<@else@>
vec4 skytexel = textureCube(skyboxMap, direction);
<@endif@>
return skytexel; return skytexel;
} }

View file

@ -14,13 +14,25 @@
// the shadow texture // the shadow texture
uniform sampler2DShadow shadowMap; uniform sampler2DShadow shadowMap;
struct EyePlanes {
vec4 _S[1];
vec4 _T[1];
vec4 _R[1];
vec4 _Q[1];
};
uniform eyePlanes {
EyePlanes _eyePlanes;
};
EyePlanes getEyePlanes() {
return _eyePlanes;
}
// Fetching it // Fetching it
float fetchShadow(vec3 texcoord) { float fetchShadow(vec3 texcoord) {
<@if GPU_FEATURE_PROFILE == GPU_CORE @>
return texture(shadowMap, texcoord); return texture(shadowMap, texcoord);
<@else@>
return shadow2D(shadowMap, texcoord).r;
<@endif@>
} }
// the distances to the cascade sections // the distances to the cascade sections
@ -44,17 +56,22 @@ vec2 samples[8] = vec2[8](
vec4 evalShadowTexcoord(vec4 position) { vec4 evalShadowTexcoord(vec4 position) {
// compute the corresponding texture coordinates // compute the corresponding texture coordinates
vec3 shadowTexcoord = vec3(dot(gl_EyePlaneS[0], position), dot(gl_EyePlaneT[0], position), dot(gl_EyePlaneR[0], position)); EyePlanes eyePlanes = getEyePlanes();
vec3 shadowTexcoord = vec3(dot(eyePlanes._S[0], position), dot(eyePlanes._T[0], position), dot(eyePlanes._R[0], position));
return vec4(shadowTexcoord, 0.0); return vec4(shadowTexcoord, 0.0);
} }
vec4 evalCascadedShadowTexcoord(vec4 position) { vec4 evalCascadedShadowTexcoord(vec4 position) {
EyePlanes eyePlanes = getEyePlanes();
// compute the index of the cascade to use and the corresponding texture coordinates // compute the index of the cascade to use and the corresponding texture coordinates
int shadowIndex = int(dot(step(vec3(position.z), shadowDistances), vec3(1.0, 1.0, 1.0))); 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), vec3 shadowTexcoord = vec3(
dot(gl_EyePlaneR[shadowIndex], position)); dot(eyePlanes._S[shadowIndex], position),
dot(eyePlanes._T[shadowIndex], position),
dot(eyePlanes._R[shadowIndex], position));
return vec4(shadowTexcoord, shadowIndex); return vec4(shadowTexcoord, shadowIndex);
} }
float evalShadowAttenuationPCF(vec4 shadowTexcoord) { float evalShadowAttenuationPCF(vec4 shadowTexcoord) {

View file

@ -12,7 +12,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Inputs.slh@>
out vec2 _texCoord0;
void main(void) { void main(void) {
gl_TexCoord[0] = gl_MultiTexCoord0; _texCoord0 = inTexCoord0.st;
gl_Position = inPosition; gl_Position = inPosition;
} }

View file

@ -12,13 +12,35 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Transform.slh@>
<$declareStandardTransform()$>
<@include gpu/Inputs.slh@> <@include gpu/Inputs.slh@>
out vec4 texCoord0; struct ObjectPlanes {
vec4 _S[4];
vec4 _T[4];
vec4 _R[4];
vec4 _Q[4];
};
uniform objPlanes {
ObjectPlanes _objPlanes;
};
ObjectPlanes getObjectPlanes() {
return _objPlanes;
}
out vec4 _texCoord0;
void main(void) { void main(void) {
gl_Position = ftransform(); ObjectPlanes objPlanes = getObjectPlanes();
TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, inPosition, gl_Position)$>
vec4 projected = gl_Position / gl_Position.w; vec4 projected = gl_Position / gl_Position.w;
texCoord0 = vec4(dot(projected, gl_ObjectPlaneS[3]) * gl_Position.w, _texCoord0 = vec4(dot(projected, objPlanes._S[3]) * gl_Position.w,
dot(projected, gl_ObjectPlaneT[3]) * gl_Position.w, 0.0, gl_Position.w); dot(projected, objPlanes._T[3]) * gl_Position.w, 0.0, gl_Position.w);
} }

View file

@ -17,8 +17,11 @@
<@include DeferredGlobalLight.slh@> <@include DeferredGlobalLight.slh@>
in vec2 _texCoord0;
out vec4 _fragColor;
void main(void) { void main(void) {
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); DeferredFragment frag = unpackDeferredFragment(_texCoord0);
// Light mapped or not ? // Light mapped or not ?
@ -29,7 +32,7 @@ void main(void) {
frag.diffuse, frag.diffuse,
frag.specularVal.xyz); frag.specularVal.xyz);
gl_FragColor = vec4(color, 1.0); _fragColor = vec4(color, 1.0);
} else { } else {
vec3 color = evalAmbienSphereGlobalColor(1.0, vec3 color = evalAmbienSphereGlobalColor(1.0,
frag.position.xyz, frag.position.xyz,
@ -38,6 +41,6 @@ void main(void) {
frag.specular, frag.specular,
frag.gloss); frag.gloss);
gl_FragColor = vec4(color, frag.normalVal.a); _fragColor = vec4(color, frag.normalVal.a);
} }
} }

View file

@ -20,8 +20,11 @@
// Everything about shadow // Everything about shadow
<@include Shadow.slh@> <@include Shadow.slh@>
in vec2 _texCoord0;
out vec4 _fragColor;
void main(void) { void main(void) {
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); DeferredFragment frag = unpackDeferredFragment(_texCoord0);
// Eval shadow Texcoord and then Attenuation // Eval shadow Texcoord and then Attenuation
vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position); vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position);
@ -29,7 +32,7 @@ void main(void) {
// Light mapped or not ? // Light mapped or not ?
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
gl_FragColor = vec4(evalLightmappedColor( _fragColor = vec4(evalLightmappedColor(
shadowAttenuation, shadowAttenuation,
frag.normal, frag.normal,
frag.diffuse, frag.diffuse,
@ -43,6 +46,6 @@ void main(void) {
frag.specular, frag.specular,
frag.gloss); frag.gloss);
gl_FragColor = vec4(color, frag.normalVal.a); _fragColor = vec4(color, frag.normalVal.a);
} }
} }

View file

@ -20,9 +20,11 @@
// Everything about shadow // Everything about shadow
<@include Shadow.slh@> <@include Shadow.slh@>
in vec2 _texCoord0;
out vec4 _fragColor;
void main(void) { void main(void) {
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); DeferredFragment frag = unpackDeferredFragment(_texCoord0);
// Eval shadow Texcoord and then Attenuation // Eval shadow Texcoord and then Attenuation
vec4 shadowTexcoord = evalShadowTexcoord(frag.position); vec4 shadowTexcoord = evalShadowTexcoord(frag.position);
@ -30,7 +32,7 @@ void main(void) {
// Light mapped or not ? // Light mapped or not ?
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
gl_FragColor = vec4(evalLightmappedColor( _fragColor = vec4(evalLightmappedColor(
shadowAttenuation, shadowAttenuation,
frag.normal, frag.normal,
frag.diffuse, frag.diffuse,
@ -44,6 +46,6 @@ void main(void) {
frag.specular, frag.specular,
frag.gloss); frag.gloss);
gl_FragColor = vec4(color, frag.normalVal.a); _fragColor = vec4(color, frag.normalVal.a);
} }
} }

View file

@ -17,12 +17,15 @@
<@include DeferredGlobalLight.slh@> <@include DeferredGlobalLight.slh@>
in vec2 _texCoord0;
out vec4 _fragColor;
void main(void) { void main(void) {
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); DeferredFragment frag = unpackDeferredFragment(_texCoord0);
// Light mapped or not ? // Light mapped or not ?
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
gl_FragColor = vec4( evalLightmappedColor( _fragColor = vec4( evalLightmappedColor(
1.0, 1.0,
frag.normal, frag.normal,
frag.diffuse, frag.diffuse,
@ -36,6 +39,6 @@ void main(void) {
frag.specular, frag.specular,
frag.gloss); frag.gloss);
gl_FragColor = vec4(color, frag.normalVal.a); _fragColor = vec4(color, frag.normalVal.a);
} }
} }

View file

@ -20,8 +20,11 @@
// Everything about shadow // Everything about shadow
<@include Shadow.slh@> <@include Shadow.slh@>
in vec2 _texCoord0;
out vec4 _fragColor;
void main(void) { void main(void) {
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); DeferredFragment frag = unpackDeferredFragment(_texCoord0);
// Eval shadow Texcoord and then Attenuation // Eval shadow Texcoord and then Attenuation
vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position); vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position);
@ -29,7 +32,7 @@ void main(void) {
// Light mapped or not ? // Light mapped or not ?
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
gl_FragColor = vec4(evalLightmappedColor( _fragColor = vec4(evalLightmappedColor(
shadowAttenuation, shadowAttenuation,
frag.normal, frag.normal,
frag.diffuse, frag.diffuse,
@ -43,6 +46,6 @@ void main(void) {
frag.specular, frag.specular,
frag.gloss); frag.gloss);
gl_FragColor = vec4(color, frag.normalVal.a); _fragColor = vec4(color, frag.normalVal.a);
} }
} }

View file

@ -20,9 +20,11 @@
// Everything about shadow // Everything about shadow
<@include Shadow.slh@> <@include Shadow.slh@>
in vec2 _texCoord0;
out vec4 _fragColor;
void main(void) { void main(void) {
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); DeferredFragment frag = unpackDeferredFragment(_texCoord0);
// Eval shadow Texcoord and then Attenuation // Eval shadow Texcoord and then Attenuation
vec4 shadowTexcoord = evalShadowTexcoord(frag.position); vec4 shadowTexcoord = evalShadowTexcoord(frag.position);
@ -30,7 +32,7 @@ void main(void) {
// Light mapped or not ? // Light mapped or not ?
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
gl_FragColor = vec4(evalLightmappedColor( _fragColor = vec4(evalLightmappedColor(
shadowAttenuation, shadowAttenuation,
frag.normal, frag.normal,
frag.diffuse, frag.diffuse,
@ -44,6 +46,6 @@ void main(void) {
frag.specular, frag.specular,
frag.gloss); frag.gloss);
gl_FragColor = vec4(color, frag.normalVal.a); _fragColor = vec4(color, frag.normalVal.a);
} }
} }

View file

@ -17,8 +17,11 @@
<@include DeferredGlobalLight.slh@> <@include DeferredGlobalLight.slh@>
in vec2 _texCoord0;
out vec4 _fragColor;
void main(void) { void main(void) {
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); DeferredFragment frag = unpackDeferredFragment(_texCoord0);
// Light mapped or not ? // Light mapped or not ?
@ -29,7 +32,7 @@ void main(void) {
frag.diffuse, frag.diffuse,
frag.specularVal.xyz); frag.specularVal.xyz);
gl_FragColor = vec4(color, 1.0); _fragColor = vec4(color, 1.0);
} else { } else {
vec3 color = evalSkyboxGlobalColor(1.0, vec3 color = evalSkyboxGlobalColor(1.0,
frag.position.xyz, frag.position.xyz,
@ -38,6 +41,6 @@ void main(void) {
frag.specular, frag.specular,
frag.gloss); frag.gloss);
gl_FragColor = vec4(color, frag.normalVal.a); _fragColor = vec4(color, frag.normalVal.a);
} }
} }

View file

@ -20,8 +20,11 @@
// Everything about shadow // Everything about shadow
<@include Shadow.slh@> <@include Shadow.slh@>
in vec2 _texCoord0;
out vec4 _fragColor;
void main(void) { void main(void) {
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); DeferredFragment frag = unpackDeferredFragment(_texCoord0);
// Eval shadow Texcoord and then Attenuation // Eval shadow Texcoord and then Attenuation
vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position); vec4 shadowTexcoord = evalCascadedShadowTexcoord(frag.position);
@ -29,7 +32,7 @@ void main(void) {
// Light mapped or not ? // Light mapped or not ?
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
gl_FragColor = vec4(evalLightmappedColor( _fragColor = vec4(evalLightmappedColor(
shadowAttenuation, shadowAttenuation,
frag.normal, frag.normal,
frag.diffuse, frag.diffuse,
@ -43,6 +46,6 @@ void main(void) {
frag.specular, frag.specular,
frag.gloss); frag.gloss);
gl_FragColor = vec4(color, frag.normalVal.a); _fragColor = vec4(color, frag.normalVal.a);
} }
} }

View file

@ -20,9 +20,11 @@
// Everything about shadow // Everything about shadow
<@include Shadow.slh@> <@include Shadow.slh@>
in vec2 _texCoord0;
out vec4 _fragColor;
void main(void) { void main(void) {
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); DeferredFragment frag = unpackDeferredFragment(_texCoord0);
// Eval shadow Texcoord and then Attenuation // Eval shadow Texcoord and then Attenuation
vec4 shadowTexcoord = evalShadowTexcoord(frag.position); vec4 shadowTexcoord = evalShadowTexcoord(frag.position);
@ -30,7 +32,7 @@ void main(void) {
// Light mapped or not ? // Light mapped or not ?
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
gl_FragColor = vec4(evalLightmappedColor( _fragColor = vec4(evalLightmappedColor(
shadowAttenuation, shadowAttenuation,
frag.normal, frag.normal,
frag.diffuse, frag.diffuse,
@ -44,6 +46,6 @@ void main(void) {
frag.specular, frag.specular,
frag.gloss); frag.gloss);
gl_FragColor = vec4(color, frag.normalVal.a); _fragColor = vec4(color, frag.normalVal.a);
} }
} }

View file

@ -13,15 +13,18 @@
// //
<@include DeferredBufferWrite.slh@> <@include DeferredBufferWrite.slh@>
<@include model/Material.slh@>
// the interpolated normal // the interpolated normal
varying vec4 interpolatedNormal; in vec3 _normal;
in vec3 _color;
void main(void) { void main(void) {
Material material = getMaterial();
packDeferredFragment( packDeferredFragment(
normalize(interpolatedNormal.xyz), normalize(_normal.xyz),
glowIntensity, glowIntensity,
gl_Color.rgb, _color.rgb,
gl_FrontMaterial.specular.rgb, material._specular.rgb,
gl_FrontMaterial.shininess); 0.0);
} }

View file

@ -12,24 +12,25 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Inputs.slh@>
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardTransform()$> <$declareStandardTransform()$>
// the interpolated normal // the interpolated normal
varying vec4 interpolatedNormal;
out vec3 _normal;
out vec3 _color;
out vec2 _texCoord0;
void main(void) { void main(void) {
gl_TexCoord[0] = gl_MultiTexCoord0; _color = inColor.rgb;
_texCoord0 = inTexCoord0.st;
// pass along the diffuse color
gl_FrontColor = gl_Color;
// standard transform // standard transform
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, gl_Vertex, gl_Position)$> <$transformModelToClipPos(cam, obj, inPosition, gl_Position)$>
<$transformModelToEyeDir(cam, obj, gl_Normal, interpolatedNormal.xyz)$> <$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal)$>
interpolatedNormal = vec4(normalize(interpolatedNormal.xyz), 0.0);
} }

View file

@ -13,20 +13,24 @@
// //
<@include DeferredBufferWrite.slh@> <@include DeferredBufferWrite.slh@>
<@include model/Material.slh@>
// the diffuse texture // the diffuse texture
uniform sampler2D originalTexture; uniform sampler2D originalTexture;
// the interpolated normal // the interpolated normal
varying vec4 interpolatedNormal; in vec3 _normal;
in vec3 _color;
in vec2 _texCoord0;
void main(void) { void main(void) {
vec4 texel = texture2D(originalTexture, gl_TexCoord[0].st); Material material = getMaterial();
vec4 texel = texture(originalTexture, _texCoord0);
packDeferredFragment( packDeferredFragment(
normalize(interpolatedNormal.xyz), normalize(_normal.xyz),
glowIntensity * texel.a, glowIntensity * texel.a,
gl_Color.rgb * texel.rgb, _color.rgb * texel.rgb,
gl_FrontMaterial.specular.rgb, material._specular.rgb,
gl_FrontMaterial.shininess); 0.0);
} }

View file

@ -7,6 +7,7 @@ setup_hifi_project(Quick Gui OpenGL)
# link in the shared libraries # link in the shared libraries
link_hifi_libraries(render-utils gpu shared) link_hifi_libraries(render-utils gpu shared)
include_directories("${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_BINARY_DIR}/../../libraries/render-utils/")
message(${PROJECT_BINARY_DIR}) message(${PROJECT_BINARY_DIR})
copy_dlls_beside_windows_executable() copy_dlls_beside_windows_executable()

View file

@ -18,6 +18,7 @@
#include <mutex> #include <mutex>
#include <QWindow> #include <QWindow>
#include <QtGlobal>
#include <QFile> #include <QFile>
#include <QTime> #include <QTime>
#include <QImage> #include <QImage>
@ -47,8 +48,30 @@
#include "gpu/Batch.h" #include "gpu/Batch.h"
#include "gpu/Context.h" #include "gpu/Context.h"
#include "../../libraries/model/Skybox_vert.h" #include "../model/Skybox_vert.h"
#include "../../libraries/model/Skybox_frag.h" #include "..//model/Skybox_frag.h"
#include "simple_vert.h"
#include "simple_frag.h"
#include "simple_textured_frag.h"
#include "deferred_light_vert.h"
#include "deferred_light_limited_vert.h"
#include "directional_light_frag.h"
#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 "directional_skybox_light_frag.h"
#include "directional_skybox_light_shadow_map_frag.h"
#include "directional_skybox_light_cascaded_shadow_map_frag.h"
#include "point_light_frag.h"
#include "spot_light_frag.h"
class RateCounter { class RateCounter {
@ -137,17 +160,6 @@ public:
show(); show();
makeCurrent(); makeCurrent();
{
QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this);
logger->initialize(); // initializes in the current context, i.e. ctx
logger->enableMessages();
connect(logger, &QOpenGLDebugLogger::messageLogged, this, [&](const QOpenGLDebugMessage & debugMessage) {
qDebug() << debugMessage;
});
logger->startLogging(QOpenGLDebugLogger::SynchronousLogging);
}
qDebug() << (const char*)glGetString(GL_VERSION);
#ifdef WIN32 #ifdef WIN32
glewExperimental = true; glewExperimental = true;
GLenum err = glewInit(); GLenum err = glewInit();
@ -165,6 +177,18 @@ public:
glGetError(); glGetError();
#endif #endif
{
QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this);
logger->initialize(); // initializes in the current context, i.e. ctx
logger->enableMessages();
connect(logger, &QOpenGLDebugLogger::messageLogged, this, [&](const QOpenGLDebugMessage & debugMessage) {
qDebug() << debugMessage;
});
logger->startLogging(QOpenGLDebugLogger::SynchronousLogging);
}
qDebug() << (const char*)glGetString(GL_VERSION);
// _textRenderer[0] = TextRenderer::getInstance(SANS_FONT_FAMILY, 12, false); // _textRenderer[0] = TextRenderer::getInstance(SANS_FONT_FAMILY, 12, false);
// _textRenderer[1] = TextRenderer::getInstance(SERIF_FONT_FAMILY, 12, false, // _textRenderer[1] = TextRenderer::getInstance(SERIF_FONT_FAMILY, 12, false,
// TextRenderer::SHADOW_EFFECT); // TextRenderer::SHADOW_EFFECT);
@ -252,6 +276,13 @@ void QTestWindow::renderText() {
} }
} }
void testShaderBuild(const char* vs_src, const char * fs_src) {
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(vs_src)));
auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(fs_src)));
auto pr = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs));
gpu::Shader::makeProgram(*pr);
}
void QTestWindow::draw() { void QTestWindow::draw() {
if (!isVisible()) { if (!isVisible()) {
return; return;
@ -263,10 +294,21 @@ void QTestWindow::draw() {
static std::once_flag once; static std::once_flag once;
std::call_once(once, [&]{ std::call_once(once, [&]{
auto skyVS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(Skybox_vert))); testShaderBuild(Skybox_vert, Skybox_frag);
auto skyFS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(Skybox_frag))); testShaderBuild(simple_vert, simple_frag);
auto skyShader = gpu::ShaderPointer(gpu::Shader::createProgram(skyVS, skyFS)); testShaderBuild(simple_vert, simple_textured_frag);
gpu::Shader::makeProgram(*skyShader); testShaderBuild(deferred_light_vert, directional_light_frag);
testShaderBuild(deferred_light_vert, directional_light_shadow_map_frag);
testShaderBuild(deferred_light_vert, directional_light_cascaded_shadow_map_frag);
testShaderBuild(deferred_light_vert, directional_ambient_light_frag);
testShaderBuild(deferred_light_vert, directional_ambient_light_shadow_map_frag);
testShaderBuild(deferred_light_vert, directional_ambient_light_cascaded_shadow_map_frag);
testShaderBuild(deferred_light_vert, directional_skybox_light_frag);
testShaderBuild(deferred_light_vert, directional_skybox_light_shadow_map_frag);
testShaderBuild(deferred_light_vert, directional_skybox_light_cascaded_shadow_map_frag);
testShaderBuild(deferred_light_limited_vert, point_light_frag);
testShaderBuild(deferred_light_limited_vert, spot_light_frag);
}); });
// renderText(); // renderText();
@ -280,8 +322,26 @@ void QTestWindow::draw() {
} }
} }
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
if (!message.isEmpty()) {
#ifdef Q_OS_WIN
OutputDebugStringA(message.toLocal8Bit().constData());
OutputDebugStringA("\n");
#else
std::cout << message.toLocal8Bit().constData() << std::endl;
#endif
}
}
const char * LOG_FILTER_RULES = R"V0G0N(
hifi.gpu=true
)V0G0N";
int main(int argc, char** argv) { int main(int argc, char** argv) {
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
qInstallMessageHandler(messageHandler);
QLoggingCategory::setFilterRules(LOG_FILTER_RULES);
QTestWindow window; QTestWindow window;
QTimer timer; QTimer timer;
timer.setInterval(1); timer.setInterval(1);