Browse Source

Shaders: ambient also changes color with VertexColor in Phong.

Also adapt the test to explicitly check for this.
catastrophic-cross
Michael Tao 7 years ago committed by Vladimír Vondruš
parent
commit
e5a6f543a0
  1. 3
      src/Magnum/Shaders/Phong.frag
  2. 9
      src/Magnum/Shaders/Test/PhongGLTest.cpp
  3. BIN
      src/Magnum/Shaders/Test/PhongTestFiles/vertexColor.tga

3
src/Magnum/Shaders/Phong.frag

@ -176,6 +176,9 @@ void main() {
#ifdef AMBIENT_TEXTURE
texture(ambientTexture, interpolatedTextureCoordinates)*
#endif
#ifdef VERTEX_COLOR
interpolatedVertexColor*
#endif
ambientColor;
#if LIGHT_COUNT
lowp const vec4 finalDiffuseColor =

9
src/Magnum/Shaders/Test/PhongGLTest.cpp

@ -973,8 +973,10 @@ template<class T> void PhongGLTest::renderVertexColor() {
Trade::MeshData sphereData = Primitives::uvSphereSolid(16, 32,
Primitives::UVSphereFlag::TextureCoordinates);
/* Highlight the middle rings */
/* Highlight the pole vertices and the middle rings */
Containers::Array<T> colorData{Containers::DirectInit, sphereData.vertexCount(), 0x999999_rgbf};
for(std::size_t i = 0; i != 3*33 + 1; ++i)
colorData[sphereData.vertexCount() - i - 1] = 0xff0000_rgbf*5.0f;
for(std::size_t i = 6*33; i != 9*33; ++i)
colorData[i + 1] = 0xffff99_rgbf*1.5f;
@ -1006,6 +1008,7 @@ template<class T> void PhongGLTest::renderVertexColor() {
.setNormalMatrix((Matrix4::rotationY(-15.0_degf)*
Matrix4::rotationX(15.0_degf)).rotationScaling())
.setProjectionMatrix(Matrix4::perspectiveProjection(60.0_degf, 1.0f, 0.1f, 10.0f))
.setAmbientColor(0x111111_rgbf)
.setDiffuseColor(0x9999ff_rgbf)
.bindDiffuseTexture(diffuse)
.draw(sphere);
@ -1015,10 +1018,10 @@ template<class T> void PhongGLTest::renderVertexColor() {
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
/* SwiftShader has some minor differences on the edges, Apple A8 a bit
more */
const Float maxThreshold = 105.4f, meanThreshold = 0.167f;
const Float maxThreshold = 115.4f, meanThreshold = 0.167f;
#else
/* WebGL 1 doesn't have 8bit renderbuffer storage, so it's worse */
const Float maxThreshold = 105.4f, meanThreshold = 3.254f;
const Float maxThreshold = 115.4f, meanThreshold = 3.254f;
#endif
CORRADE_COMPARE_WITH(
/* Dropping the alpha channel, as it's always 1.0 */

BIN
src/Magnum/Shaders/Test/PhongTestFiles/vertexColor.tga

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Loading…
Cancel
Save