From 2f39496ec5ad97feb5610df2dcf003a44e6ef986 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Sun, 25 Nov 2012 17:45:50 +0100 Subject: [PATCH] Use ambient material color when no color in the vertex Fixes color in celshading demo --- GPU/GLES/TransformPipeline.cpp | 30 ++++++++++++++++++++++-------- GPU/GLES/VertexDecoder.h | 1 + 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index ff6d1261df..50d9a37c9c 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -269,10 +269,18 @@ void TransformAndDrawPrim(void *verts, void *inds, int prim, int vertexCount, Li // Do not touch the coordinates or the colors. No lighting. for (int j=0; j<3; j++) v[j] = decoded[index].pos[j]; - // TODO : check if has color - for (int j=0; j<4; j++) { - c0[j] = decoded[index].color[j] / 255.0f; - c1[j] = 0.0f; + if(dec.hasColor()) { + for (int j=0; j<4; j++) { + c0[j] = decoded[index].color[j] / 255.0f; + c1[j] = 0.0f; + } + } + else + { + c0[0] = (gstate.materialambient & 0xFF) / 255.f; + c0[1] = ((gstate.materialambient >> 8) & 0xFF) / 255.f; + c0[2] = ((gstate.materialambient >> 16) & 0xFF) / 255.f; + c0[3] = (gstate.materialalpha & 0xFF) / 255.f; } // TODO : check if has uv @@ -343,10 +351,16 @@ void TransformAndDrawPrim(void *verts, void *inds, int prim, int vertexCount, Li } else { - // no lighting? copy the color. - for (int j = 0; j < 4; j++) { - c0[j] = unlitColor[j]; - c1[j] = 0.0f; + if(dec.hasColor()) { + for (int j = 0; j < 4; j++) { + c0[j] = unlitColor[j]; + c1[j] = 0.0f; + } + } else { + c0[0] = (gstate.materialambient & 0xFF) / 255.f; + c0[1] = ((gstate.materialambient >> 8) & 0xFF) / 255.f; + c0[2] = ((gstate.materialambient >> 16) & 0xFF) / 255.f; + c0[3] = (gstate.materialalpha & 0xFF) / 255.f; } } } diff --git a/GPU/GLES/VertexDecoder.h b/GPU/GLES/VertexDecoder.h index 615d3966c1..e0d256c515 100644 --- a/GPU/GLES/VertexDecoder.h +++ b/GPU/GLES/VertexDecoder.h @@ -56,6 +56,7 @@ public: ~VertexDecoder() {} void SetVertexType(u32 fmt); void DecodeVerts(DecodedVertex *decoded, const void *verts, const void *inds, int prim, int count, int *indexLowerBound, int *indexUpperBound) const; + bool hasColor() const { return col != 0; } private: u32 fmt;