Merge branch 'lighting_fix' into 'master'
Fix lighting using some values calculated for last vertex, instead of the current vertex See merge request simulant/GLdc!151
This commit is contained in:
commit
787b873674
41
GL/draw.c
41
GL/draw.c
@ -90,17 +90,6 @@ GL_FORCE_INLINE IndexParseFunc _calcParseIndexFunc(GLenum type) {
|
|||||||
x = __x; y = __y; z = __z; \
|
x = __x; y = __y; z = __z; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GL_FORCE_INLINE void transformToEyeSpace(GLfloat* point) {
|
|
||||||
_glMatrixLoadModelView();
|
|
||||||
mat_trans_single3_nodiv(point[0], point[1], point[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
GL_FORCE_INLINE void transformNormalToEyeSpace(GLfloat* normal) {
|
|
||||||
_glMatrixLoadNormal();
|
|
||||||
mat_trans_normal3(normal[0], normal[1], normal[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
GL_FORCE_INLINE PolyHeader *_glSubmissionTargetHeader(SubmissionTarget* target) {
|
GL_FORCE_INLINE PolyHeader *_glSubmissionTargetHeader(SubmissionTarget* target) {
|
||||||
gl_assert(target->header_offset < aligned_vector_size(&target->output->vector));
|
gl_assert(target->header_offset < aligned_vector_size(&target->output->vector));
|
||||||
return aligned_vector_at(&target->output->vector, target->header_offset);
|
return aligned_vector_at(&target->output->vector, target->header_offset);
|
||||||
@ -622,42 +611,22 @@ static void transform(SubmissionTarget* target) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mat_transform_normal3(const float* xyz, const float* xyzOut, const uint32_t count, const uint32_t inStride, const uint32_t outStride) {
|
static void mat_transform_normal3(VertexExtra* extra, const uint32_t count) {
|
||||||
const uint8_t* dataIn = (const uint8_t*) xyz;
|
|
||||||
uint8_t* dataOut = (uint8_t*) xyzOut;
|
|
||||||
|
|
||||||
ITERATE(count) {
|
ITERATE(count) {
|
||||||
const float* in = (const float*) dataIn;
|
TransformNormalNoMod(extra->nxyz, extra->nxyz);
|
||||||
float* out = (float*) dataOut;
|
extra++;
|
||||||
|
|
||||||
TransformNormalNoMod(in, out);
|
|
||||||
|
|
||||||
dataIn += inStride;
|
|
||||||
dataOut += outStride;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void light(SubmissionTarget* target) {
|
static void light(SubmissionTarget* target) {
|
||||||
|
|
||||||
static AlignedVector* eye_space_data = NULL;
|
|
||||||
|
|
||||||
if(!eye_space_data) {
|
|
||||||
eye_space_data = (AlignedVector*) malloc(sizeof(AlignedVector));
|
|
||||||
aligned_vector_init(eye_space_data, sizeof(EyeSpaceData));
|
|
||||||
}
|
|
||||||
|
|
||||||
aligned_vector_resize(eye_space_data, target->count);
|
|
||||||
|
|
||||||
/* Perform lighting calculations and manipulate the colour */
|
/* Perform lighting calculations and manipulate the colour */
|
||||||
Vertex* vertex = _glSubmissionTargetStart(target);
|
Vertex* vertex = _glSubmissionTargetStart(target);
|
||||||
VertexExtra* extra = aligned_vector_at(target->extras, 0);
|
VertexExtra* extra = aligned_vector_at(target->extras, 0);
|
||||||
EyeSpaceData* eye_space = (EyeSpaceData*) eye_space_data->data;
|
|
||||||
|
|
||||||
_glMatrixLoadNormal();
|
_glMatrixLoadNormal();
|
||||||
mat_transform_normal3(extra->nxyz, eye_space->n, target->count, sizeof(VertexExtra), sizeof(EyeSpaceData));
|
mat_transform_normal3(extra, target->count);
|
||||||
|
|
||||||
EyeSpaceData* ES = aligned_vector_at(eye_space_data, 0);
|
_glPerformLighting(vertex, extra, target->count);
|
||||||
_glPerformLighting(vertex, ES, target->count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_FORCE_INLINE int _calc_pvr_face_culling() {
|
GL_FORCE_INLINE int _calc_pvr_face_culling() {
|
||||||
|
|||||||
@ -499,14 +499,14 @@ GL_FORCE_INLINE void _glLightVertexPoint(
|
|||||||
#undef _PROCESS_COMPONENT
|
#undef _PROCESS_COMPONENT
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glPerformLighting(Vertex* vertices, EyeSpaceData* es, const uint32_t count) {
|
void _glPerformLighting(Vertex* vertices, VertexExtra* extra, const uint32_t count) {
|
||||||
GLubyte i;
|
GLubyte i;
|
||||||
GLuint j;
|
GLuint j;
|
||||||
|
|
||||||
Material* material = _glActiveMaterial();
|
Material* material = _glActiveMaterial();
|
||||||
|
|
||||||
Vertex* vertex = vertices;
|
Vertex* vertex = vertices;
|
||||||
EyeSpaceData* data = es;
|
VertexExtra* data = extra;
|
||||||
|
|
||||||
/* Calculate the colour material function once */
|
/* Calculate the colour material function once */
|
||||||
void (*updateColourMaterial)(const GLubyte*) = NULL;
|
void (*updateColourMaterial)(const GLubyte*) = NULL;
|
||||||
@ -529,32 +529,29 @@ void _glPerformLighting(Vertex* vertices, EyeSpaceData* es, const uint32_t count
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate the ambient lighting and set up colour material */
|
if(!_glEnabledLightCount()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for(j = 0; j < count; ++j, ++vertex, ++data) {
|
for(j = 0; j < count; ++j, ++vertex, ++data) {
|
||||||
|
/* Calculate the ambient lighting and set up colour material */
|
||||||
if(updateColourMaterial) {
|
if(updateColourMaterial) {
|
||||||
updateColourMaterial(vertex->bgra);
|
updateColourMaterial(vertex->bgra);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the base colour across */
|
/* Copy the base colour across */
|
||||||
vec4cpy(data->finalColour, material->baseColour);
|
float finalColour[4];
|
||||||
}
|
vec4cpy(finalColour, material->baseColour);
|
||||||
|
|
||||||
if(!_glEnabledLightCount()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
vertex = vertices;
|
|
||||||
data = es;
|
|
||||||
for(j = 0; j < count; ++j, ++vertex, ++data) {
|
|
||||||
/* Direction to vertex in eye space */
|
/* Direction to vertex in eye space */
|
||||||
float Vx = -vertex->xyz[0];
|
float Vx = -vertex->xyz[0];
|
||||||
float Vy = -vertex->xyz[1];
|
float Vy = -vertex->xyz[1];
|
||||||
float Vz = -vertex->xyz[2];
|
float Vz = -vertex->xyz[2];
|
||||||
VEC3_NORMALIZE(Vx, Vy, Vz);
|
VEC3_NORMALIZE(Vx, Vy, Vz);
|
||||||
|
|
||||||
const float Nx = data->n[0];
|
const float Nx = data->nxyz[0];
|
||||||
const float Ny = data->n[1];
|
const float Ny = data->nxyz[1];
|
||||||
const float Nz = data->n[2];
|
const float Nz = data->nxyz[2];
|
||||||
|
|
||||||
for(i = 0; i < MAX_GLDC_LIGHTS; ++i) {
|
for(i = 0; i < MAX_GLDC_LIGHTS; ++i) {
|
||||||
LightSource* light = _glLightAt(i);
|
LightSource* light = _glLightAt(i);
|
||||||
@ -588,7 +585,7 @@ void _glPerformLighting(Vertex* vertices, EyeSpaceData* es, const uint32_t count
|
|||||||
if(NdotH < 0.0f) NdotH = 0.0f;
|
if(NdotH < 0.0f) NdotH = 0.0f;
|
||||||
|
|
||||||
_glLightVertexDirectional(
|
_glLightVertexDirectional(
|
||||||
data->finalColour,
|
finalColour,
|
||||||
i, LdotN, NdotH
|
i, LdotN, NdotH
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -627,17 +624,17 @@ void _glPerformLighting(Vertex* vertices, EyeSpaceData* es, const uint32_t count
|
|||||||
if(NdotH < 0.0f) NdotH = 0.0f;
|
if(NdotH < 0.0f) NdotH = 0.0f;
|
||||||
|
|
||||||
_glLightVertexPoint(
|
_glLightVertexPoint(
|
||||||
data->finalColour,
|
finalColour,
|
||||||
i, LdotN, NdotH, att
|
i, LdotN, NdotH, att
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vertex->bgra[R8IDX] = clamp(data->finalColour[0] * 255.0f, 0, 255);
|
vertex->bgra[R8IDX] = clamp(finalColour[0] * 255.0f, 0, 255);
|
||||||
vertex->bgra[G8IDX] = clamp(data->finalColour[1] * 255.0f, 0, 255);
|
vertex->bgra[G8IDX] = clamp(finalColour[1] * 255.0f, 0, 255);
|
||||||
vertex->bgra[B8IDX] = clamp(data->finalColour[2] * 255.0f, 0, 255);
|
vertex->bgra[B8IDX] = clamp(finalColour[2] * 255.0f, 0, 255);
|
||||||
vertex->bgra[A8IDX] = clamp(data->finalColour[3] * 255.0f, 0, 255);
|
vertex->bgra[A8IDX] = clamp(finalColour[3] * 255.0f, 0, 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -445,13 +445,7 @@ GL_FORCE_INLINE GLboolean _glCheckImmediateModeInactive(const char* func) {
|
|||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
extern void _glPerformLighting(Vertex* vertices, VertexExtra* extra, const uint32_t count);
|
||||||
float n[3]; // 12 bytes
|
|
||||||
float finalColour[4]; //28 bytes
|
|
||||||
uint32_t padding; // 32 bytes
|
|
||||||
} EyeSpaceData;
|
|
||||||
|
|
||||||
extern void _glPerformLighting(Vertex* vertices, EyeSpaceData *es, const uint32_t count);
|
|
||||||
|
|
||||||
unsigned char _glIsClippingEnabled();
|
unsigned char _glIsClippingEnabled();
|
||||||
void _glEnableClipping(unsigned char v);
|
void _glEnableClipping(unsigned char v);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user