From 05931234240c84ccea236ef87e0c52d7a5631167 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 26 Jan 2011 11:33:58 +0000 Subject: [PATCH] implemented SHADERMODE_LIGHTSOURCE with specular, shadowmapping and cubefilter are not yet implemented git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10747 d7cf8633-e32d-0410-b094-e92efae38249 --- dpsoftrast.c | 353 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 350 insertions(+), 3 deletions(-) diff --git a/dpsoftrast.c b/dpsoftrast.c index 285ede0c..b33a5dca 100644 --- a/dpsoftrast.c +++ b/dpsoftrast.c @@ -2029,6 +2029,18 @@ void DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(const DPSOFTRAST_State_Draw_Span } } +void DPSOFTRAST_Draw_Span_TextureCubeVaryingBGRA8(const DPSOFTRAST_State_Draw_Span * RESTRICT span, unsigned char * RESTRICT out4ub, int texunitindex, int arrayindex, const float * RESTRICT zf) +{ + // TODO: IMPLEMENT + memset(out4ub, 255, span->length*4); +} + +float DPSOFTRAST_SampleShadowmap(const float *vector) +{ + // TODO: IMPLEMENT + return 1.0f; +} + void DPSOFTRAST_Draw_Span_MultiplyVarying(const DPSOFTRAST_State_Draw_Span * RESTRICT span, float *out4f, const float *in4f, int arrayindex, const float *zf) { int x; @@ -2778,7 +2790,7 @@ void DPSOFTRAST_PixelShader_LightDirection(const DPSOFTRAST_State_Draw_Span * RE Color_Specular[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+1]; Color_Specular[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+2]; Color_Specular[3] = 0.0f; - SpecularPower = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_SpecularPower*4+0]; + SpecularPower = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_SpecularPower*4+0] * (1.0f / 255.0f); EyeVectordata[0] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD2][0]; EyeVectordata[1] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD2][1]; EyeVectordata[2] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD2][2]; @@ -2943,16 +2955,351 @@ void DPSOFTRAST_PixelShader_LightDirection(const DPSOFTRAST_State_Draw_Span * RE void DPSOFTRAST_VertexShader_LightSource(void) { + int i; + int numvertices = dpsoftrast.draw.numvertices; + float LightPosition[4]; + float LightVector[4]; + float LightVectorModelSpace[4]; + float EyePosition[4]; + float EyeVectorModelSpace[4]; + float EyeVector[4]; + float position[4]; + float svector[4]; + float tvector[4]; + float normal[4]; + LightPosition[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightPosition*4+0]; + LightPosition[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightPosition*4+1]; + LightPosition[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightPosition*4+2]; + LightPosition[3] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightPosition*4+3]; + EyePosition[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+0]; + EyePosition[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+1]; + EyePosition[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+2]; + EyePosition[3] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+3]; DPSOFTRAST_Array_Transform(dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_POSITION], dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_POSITION], dpsoftrast.draw.numvertices, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1); + DPSOFTRAST_Array_Transform(dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD0], dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD0], dpsoftrast.draw.numvertices, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_TexMatrixM1); + DPSOFTRAST_Array_Transform(dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD3], dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_POSITION], dpsoftrast.draw.numvertices, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelToLightM1); + DPSOFTRAST_Array_Copy(dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD4], dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD4], dpsoftrast.draw.numvertices); + for (i = 0;i < numvertices;i++) + { + position[0] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+0]; + position[1] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+1]; + position[2] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+2]; + svector[0] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+0]; + svector[1] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+1]; + svector[2] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+2]; + tvector[0] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+0]; + tvector[1] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+1]; + tvector[2] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+2]; + normal[0] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+0]; + normal[1] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+1]; + normal[2] = dpsoftrast.draw.in_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+2]; + LightVectorModelSpace[0] = LightPosition[0] - position[0]; + LightVectorModelSpace[1] = LightPosition[1] - position[1]; + LightVectorModelSpace[2] = LightPosition[2] - position[2]; + LightVector[0] = svector[0] * LightVectorModelSpace[0] + svector[1] * LightVectorModelSpace[1] + svector[2] * LightVectorModelSpace[2]; + LightVector[1] = tvector[0] * LightVectorModelSpace[0] + tvector[1] * LightVectorModelSpace[1] + tvector[2] * LightVectorModelSpace[2]; + LightVector[2] = normal[0] * LightVectorModelSpace[0] + normal[1] * LightVectorModelSpace[1] + normal[2] * LightVectorModelSpace[2]; + dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+0] = LightVector[0]; + dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+1] = LightVector[1]; + dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+2] = LightVector[2]; + dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+3] = 0.0f; + EyeVectorModelSpace[0] = EyePosition[0] - position[0]; + EyeVectorModelSpace[1] = EyePosition[1] - position[1]; + EyeVectorModelSpace[2] = EyePosition[2] - position[2]; + EyeVector[0] = svector[0] * EyeVectorModelSpace[0] + svector[1] * EyeVectorModelSpace[1] + svector[2] * EyeVectorModelSpace[2]; + EyeVector[1] = tvector[0] * EyeVectorModelSpace[0] + tvector[1] * EyeVectorModelSpace[1] + tvector[2] * EyeVectorModelSpace[2]; + EyeVector[2] = normal[0] * EyeVectorModelSpace[0] + normal[1] * EyeVectorModelSpace[1] + normal[2] * EyeVectorModelSpace[2]; + dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+0] = EyeVector[0]; + dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+1] = EyeVector[1]; + dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+2] = EyeVector[2]; + dpsoftrast.draw.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+3] = 0.0f; + } } void DPSOFTRAST_PixelShader_LightSource(const DPSOFTRAST_State_Draw_Span * RESTRICT span) { - // TODO: IMPLEMENT float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH]; + unsigned char buffer_texture_colorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4]; + unsigned char buffer_texture_normalbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4]; + unsigned char buffer_texture_glossbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4]; + unsigned char buffer_texture_cubebgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4]; + unsigned char buffer_texture_pantsbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4]; + unsigned char buffer_texture_shirtbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4]; unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4]; + int x, startx = span->startx, endx = span->endx; + float Color_Ambient[4], Color_Diffuse[4], Color_Specular[4], Color_Glow[4], Color_Pants[4], Color_Shirt[4], LightColor[4]; + float CubeVectordata[4]; + float CubeVectorslope[4]; + float LightVectordata[4]; + float LightVectorslope[4]; + float EyeVectordata[4]; + float EyeVectorslope[4]; + float z; + float diffusetex[4]; + float glosstex[4]; + float surfacenormal[4]; + float lightnormal[4]; + float eyenormal[4]; + float specularnormal[4]; + float diffuse; + float specular; + float SpecularPower; + float CubeVector[4]; + float attenuation; + int d[4]; + Color_Glow[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+0]; + Color_Glow[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+1]; + Color_Glow[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+2]; + Color_Glow[3] = 0.0f; + Color_Ambient[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+0]; + Color_Ambient[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+1]; + Color_Ambient[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+2]; + Color_Ambient[3] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Alpha*4+0]; + Color_Diffuse[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+0]; + Color_Diffuse[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+1]; + Color_Diffuse[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+2]; + Color_Diffuse[3] = 0.0f; + Color_Specular[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+0]; + Color_Specular[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+1]; + Color_Specular[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+2]; + Color_Specular[3] = 0.0f; + Color_Pants[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Pants*4+0]; + Color_Pants[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Pants*4+1]; + Color_Pants[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Pants*4+2]; + Color_Pants[3] = 0.0f; + Color_Shirt[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Shirt*4+0]; + Color_Shirt[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Shirt*4+1]; + Color_Shirt[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_Color_Shirt*4+2]; + Color_Shirt[3] = 0.0f; + LightColor[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+0]; + LightColor[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+1]; + LightColor[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+2]; + LightColor[3] = 0.0f; + SpecularPower = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_SpecularPower*4+0] * (1.0f / 255.0f); + EyeVectordata[0] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD2][0]; + EyeVectordata[1] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD2][1]; + EyeVectordata[2] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD2][2]; + EyeVectordata[3] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD2][3]; + EyeVectorslope[0] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD2][0]; + EyeVectorslope[1] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD2][1]; + EyeVectorslope[2] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD2][2]; + EyeVectorslope[3] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD2][3]; + LightVectordata[0] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD1][0]; + LightVectordata[1] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD1][1]; + LightVectordata[2] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD1][2]; + LightVectordata[3] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD1][3]; + LightVectorslope[0] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD1][0]; + LightVectorslope[1] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD1][1]; + LightVectorslope[2] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD1][2]; + LightVectorslope[3] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD1][3]; + CubeVectordata[0] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD3][0]; + CubeVectordata[1] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD3][1]; + CubeVectordata[2] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD3][2]; + CubeVectordata[3] = span->data[0][DPSOFTRAST_ARRAY_TEXCOORD3][3]; + CubeVectorslope[0] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD3][0]; + CubeVectorslope[1] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD3][1]; + CubeVectorslope[2] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD3][2]; + CubeVectorslope[3] = span->data[1][DPSOFTRAST_ARRAY_TEXCOORD3][3]; DPSOFTRAST_Draw_Span_Begin(span, buffer_z); - memset(buffer_FragColorbgra8, 0, span->length*4); + DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(span, buffer_texture_colorbgra8, GL20TU_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z); + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_COLORMAPPING) + { + DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(span, buffer_texture_pantsbgra8, GL20TU_PANTS, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z); + DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(span, buffer_texture_shirtbgra8, GL20TU_SHIRT, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z); + } + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_CUBEFILTER) + DPSOFTRAST_Draw_Span_TextureCubeVaryingBGRA8(span, buffer_texture_cubebgra8, GL20TU_CUBE, DPSOFTRAST_ARRAY_TEXCOORD3, buffer_z); + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_SPECULAR) + { + DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(span, buffer_texture_normalbgra8, GL20TU_NORMAL, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z); + DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(span, buffer_texture_glossbgra8, GL20TU_GLOSS, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z); + for (x = startx;x < endx;x++) + { + z = buffer_z[x]; + diffusetex[0] = buffer_texture_colorbgra8[x*4+0]; + diffusetex[1] = buffer_texture_colorbgra8[x*4+1]; + diffusetex[2] = buffer_texture_colorbgra8[x*4+2]; + diffusetex[3] = buffer_texture_colorbgra8[x*4+3]; + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_COLORMAPPING) + { + diffusetex[0] += buffer_texture_pantsbgra8[x*4+0] * Color_Pants[0] + buffer_texture_shirtbgra8[x*4+0] * Color_Shirt[0]; + diffusetex[1] += buffer_texture_pantsbgra8[x*4+1] * Color_Pants[1] + buffer_texture_shirtbgra8[x*4+1] * Color_Shirt[1]; + diffusetex[2] += buffer_texture_pantsbgra8[x*4+2] * Color_Pants[2] + buffer_texture_shirtbgra8[x*4+2] * Color_Shirt[2]; + diffusetex[3] += buffer_texture_pantsbgra8[x*4+3] * Color_Pants[3] + buffer_texture_shirtbgra8[x*4+3] * Color_Shirt[3]; + } + glosstex[0] = buffer_texture_glossbgra8[x*4+0]; + glosstex[1] = buffer_texture_glossbgra8[x*4+1]; + glosstex[2] = buffer_texture_glossbgra8[x*4+2]; + glosstex[3] = buffer_texture_glossbgra8[x*4+3]; + surfacenormal[0] = buffer_texture_normalbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f; + surfacenormal[1] = buffer_texture_normalbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f; + surfacenormal[2] = buffer_texture_normalbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f; + DPSOFTRAST_Vector3Normalize(surfacenormal); + + CubeVector[0] = (CubeVectordata[0] + CubeVectorslope[0]*x) * z; + CubeVector[1] = (CubeVectordata[1] + CubeVectorslope[1]*x) * z; + CubeVector[2] = (CubeVectordata[2] + CubeVectorslope[2]*x) * z; + + lightnormal[0] = (LightVectordata[0] + LightVectorslope[0]*x) * z; + lightnormal[1] = (LightVectordata[1] + LightVectorslope[1]*x) * z; + lightnormal[2] = (LightVectordata[2] + LightVectorslope[2]*x) * z; + DPSOFTRAST_Vector3Normalize(lightnormal); + + eyenormal[0] = (EyeVectordata[0] + EyeVectorslope[0]*x) * z; + eyenormal[1] = (EyeVectordata[1] + EyeVectorslope[1]*x) * z; + eyenormal[2] = (EyeVectordata[2] + EyeVectorslope[2]*x) * z; + DPSOFTRAST_Vector3Normalize(eyenormal); + + specularnormal[0] = lightnormal[0] + eyenormal[0]; + specularnormal[1] = lightnormal[1] + eyenormal[1]; + specularnormal[2] = lightnormal[2] + eyenormal[2]; + DPSOFTRAST_Vector3Normalize(specularnormal); + + attenuation = 1.0f - DPSOFTRAST_Vector3LengthSquared(CubeVector);if (attenuation < 0.0f) attenuation = 0.0f; + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_SHADOWMAP2D) + attenuation *= DPSOFTRAST_SampleShadowmap(CubeVector); + diffuse = DPSOFTRAST_Vector3Dot(surfacenormal, lightnormal);if (diffuse < 0.0f) diffuse = 0.0f; + specular = DPSOFTRAST_Vector3Dot(surfacenormal, specularnormal);if (specular < 0.0f) specular = 0.0f; + specular = pow(specular, SpecularPower * glosstex[3]); + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_CUBEFILTER) + { + // scale down the attenuation to account for the cubefilter multiplying everything by 255 + attenuation *= (1.0f / 255.0f); + d[0] = (int)((diffusetex[0] * (Color_Ambient[0] + Color_Diffuse[0] * diffuse) + glosstex[0] * Color_Specular[0] * specular) * LightColor[0] * buffer_texture_cubebgra8[x*4+0] * attenuation);if (d[0] > 255) d[0] = 255; + d[1] = (int)((diffusetex[1] * (Color_Ambient[1] + Color_Diffuse[1] * diffuse) + glosstex[1] * Color_Specular[1] * specular) * LightColor[1] * buffer_texture_cubebgra8[x*4+1] * attenuation);if (d[1] > 255) d[1] = 255; + d[2] = (int)((diffusetex[2] * (Color_Ambient[2] + Color_Diffuse[2] * diffuse) + glosstex[2] * Color_Specular[2] * specular) * LightColor[2] * buffer_texture_cubebgra8[x*4+2] * attenuation);if (d[2] > 255) d[2] = 255; + d[3] = (int)( diffusetex[3] );if (d[3] > 255) d[3] = 255; + } + else + { + d[0] = (int)((diffusetex[0] * (Color_Ambient[0] + Color_Diffuse[0] * diffuse) + glosstex[0] * Color_Specular[0] * specular) * LightColor[0] * attenuation);if (d[0] > 255) d[0] = 255; + d[1] = (int)((diffusetex[1] * (Color_Ambient[1] + Color_Diffuse[1] * diffuse) + glosstex[1] * Color_Specular[1] * specular) * LightColor[1] * attenuation);if (d[1] > 255) d[1] = 255; + d[2] = (int)((diffusetex[2] * (Color_Ambient[2] + Color_Diffuse[2] * diffuse) + glosstex[2] * Color_Specular[2] * specular) * LightColor[2] * attenuation);if (d[2] > 255) d[2] = 255; + d[3] = (int)( diffusetex[3] );if (d[3] > 255) d[3] = 255; + } + buffer_FragColorbgra8[x*4+0] = d[0]; + buffer_FragColorbgra8[x*4+1] = d[1]; + buffer_FragColorbgra8[x*4+2] = d[2]; + buffer_FragColorbgra8[x*4+3] = d[3]; + } + } + else if (dpsoftrast.shader_permutation & SHADERPERMUTATION_DIFFUSE) + { + DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(span, buffer_texture_normalbgra8, GL20TU_NORMAL, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z); + for (x = startx;x < endx;x++) + { + z = buffer_z[x]; + diffusetex[0] = buffer_texture_colorbgra8[x*4+0]; + diffusetex[1] = buffer_texture_colorbgra8[x*4+1]; + diffusetex[2] = buffer_texture_colorbgra8[x*4+2]; + diffusetex[3] = buffer_texture_colorbgra8[x*4+3]; + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_COLORMAPPING) + { + diffusetex[0] += buffer_texture_pantsbgra8[x*4+0] * Color_Pants[0] + buffer_texture_shirtbgra8[x*4+0] * Color_Shirt[0]; + diffusetex[1] += buffer_texture_pantsbgra8[x*4+1] * Color_Pants[1] + buffer_texture_shirtbgra8[x*4+1] * Color_Shirt[1]; + diffusetex[2] += buffer_texture_pantsbgra8[x*4+2] * Color_Pants[2] + buffer_texture_shirtbgra8[x*4+2] * Color_Shirt[2]; + diffusetex[3] += buffer_texture_pantsbgra8[x*4+3] * Color_Pants[3] + buffer_texture_shirtbgra8[x*4+3] * Color_Shirt[3]; + } + glosstex[0] = buffer_texture_glossbgra8[x*4+0]; + glosstex[1] = buffer_texture_glossbgra8[x*4+1]; + glosstex[2] = buffer_texture_glossbgra8[x*4+2]; + glosstex[3] = buffer_texture_glossbgra8[x*4+3]; + surfacenormal[0] = buffer_texture_normalbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f; + surfacenormal[1] = buffer_texture_normalbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f; + surfacenormal[2] = buffer_texture_normalbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f; + DPSOFTRAST_Vector3Normalize(surfacenormal); + + CubeVector[0] = (CubeVectordata[0] + CubeVectorslope[0]*x) * z; + CubeVector[1] = (CubeVectordata[1] + CubeVectorslope[1]*x) * z; + CubeVector[2] = (CubeVectordata[2] + CubeVectorslope[2]*x) * z; + + lightnormal[0] = (LightVectordata[0] + LightVectorslope[0]*x) * z; + lightnormal[1] = (LightVectordata[1] + LightVectorslope[1]*x) * z; + lightnormal[2] = (LightVectordata[2] + LightVectorslope[2]*x) * z; + DPSOFTRAST_Vector3Normalize(lightnormal); + + attenuation = 1.0f - DPSOFTRAST_Vector3LengthSquared(CubeVector);if (attenuation < 0.0f) attenuation = 0.0f; + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_SHADOWMAP2D) + attenuation *= DPSOFTRAST_SampleShadowmap(CubeVector); + diffuse = DPSOFTRAST_Vector3Dot(surfacenormal, lightnormal);if (diffuse < 0.0f) diffuse = 0.0f; + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_CUBEFILTER) + { + d[0] = (int)(diffusetex[0] * (Color_Ambient[0] + Color_Diffuse[0] * diffuse) * LightColor[0] * buffer_texture_cubebgra8[x*4+0] * attenuation);if (d[0] > 255) d[0] = 255; + d[1] = (int)(diffusetex[1] * (Color_Ambient[1] + Color_Diffuse[1] * diffuse) * LightColor[1] * buffer_texture_cubebgra8[x*4+1] * attenuation);if (d[1] > 255) d[1] = 255; + d[2] = (int)(diffusetex[2] * (Color_Ambient[2] + Color_Diffuse[2] * diffuse) * LightColor[2] * buffer_texture_cubebgra8[x*4+2] * attenuation);if (d[2] > 255) d[2] = 255; + d[3] = (int)(diffusetex[3] );if (d[3] > 255) d[3] = 255; + } + else + { + d[0] = (int)(diffusetex[0] * (Color_Ambient[0] + Color_Diffuse[0] * diffuse) * LightColor[0] * attenuation);if (d[0] > 255) d[0] = 255; + d[1] = (int)(diffusetex[1] * (Color_Ambient[1] + Color_Diffuse[1] * diffuse) * LightColor[1] * attenuation);if (d[1] > 255) d[1] = 255; + d[2] = (int)(diffusetex[2] * (Color_Ambient[2] + Color_Diffuse[2] * diffuse) * LightColor[2] * attenuation);if (d[2] > 255) d[2] = 255; + d[3] = (int)(diffusetex[3] );if (d[3] > 255) d[3] = 255; + } + buffer_FragColorbgra8[x*4+0] = d[0]; + buffer_FragColorbgra8[x*4+1] = d[1]; + buffer_FragColorbgra8[x*4+2] = d[2]; + buffer_FragColorbgra8[x*4+3] = d[3]; + } + } + else + { + for (x = startx;x < endx;x++) + { + z = buffer_z[x]; + diffusetex[0] = buffer_texture_colorbgra8[x*4+0]; + diffusetex[1] = buffer_texture_colorbgra8[x*4+1]; + diffusetex[2] = buffer_texture_colorbgra8[x*4+2]; + diffusetex[3] = buffer_texture_colorbgra8[x*4+3]; + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_COLORMAPPING) + { + diffusetex[0] += buffer_texture_pantsbgra8[x*4+0] * Color_Pants[0] + buffer_texture_shirtbgra8[x*4+0] * Color_Shirt[0]; + diffusetex[1] += buffer_texture_pantsbgra8[x*4+1] * Color_Pants[1] + buffer_texture_shirtbgra8[x*4+1] * Color_Shirt[1]; + diffusetex[2] += buffer_texture_pantsbgra8[x*4+2] * Color_Pants[2] + buffer_texture_shirtbgra8[x*4+2] * Color_Shirt[2]; + diffusetex[3] += buffer_texture_pantsbgra8[x*4+3] * Color_Pants[3] + buffer_texture_shirtbgra8[x*4+3] * Color_Shirt[3]; + } + glosstex[0] = buffer_texture_glossbgra8[x*4+0]; + glosstex[1] = buffer_texture_glossbgra8[x*4+1]; + glosstex[2] = buffer_texture_glossbgra8[x*4+2]; + glosstex[3] = buffer_texture_glossbgra8[x*4+3]; + surfacenormal[0] = buffer_texture_normalbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f; + surfacenormal[1] = buffer_texture_normalbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f; + surfacenormal[2] = buffer_texture_normalbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f; + DPSOFTRAST_Vector3Normalize(surfacenormal); + + CubeVector[0] = (CubeVectordata[0] + CubeVectorslope[0]*x) * z; + CubeVector[1] = (CubeVectordata[1] + CubeVectorslope[1]*x) * z; + CubeVector[2] = (CubeVectordata[2] + CubeVectorslope[2]*x) * z; + + lightnormal[0] = (LightVectordata[0] + LightVectorslope[0]*x) * z; + lightnormal[1] = (LightVectordata[1] + LightVectorslope[1]*x) * z; + lightnormal[2] = (LightVectordata[2] + LightVectorslope[2]*x) * z; + DPSOFTRAST_Vector3Normalize(lightnormal); + + attenuation = 1.0f - DPSOFTRAST_Vector3LengthSquared(CubeVector);if (attenuation < 0.0f) attenuation = 0.0f; + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_SHADOWMAP2D) + attenuation *= DPSOFTRAST_SampleShadowmap(CubeVector); + diffuse = DPSOFTRAST_Vector3Dot(surfacenormal, lightnormal);if (diffuse < 0.0f) diffuse = 0.0f; + if (dpsoftrast.shader_permutation & SHADERPERMUTATION_CUBEFILTER) + { + d[0] = (int)(diffusetex[0] * Color_Ambient[0] * LightColor[0] * buffer_texture_cubebgra8[x*4+0] * attenuation);if (d[0] > 255) d[0] = 255; + d[1] = (int)(diffusetex[1] * Color_Ambient[1] * LightColor[1] * buffer_texture_cubebgra8[x*4+1] * attenuation);if (d[1] > 255) d[1] = 255; + d[2] = (int)(diffusetex[2] * Color_Ambient[2] * LightColor[2] * buffer_texture_cubebgra8[x*4+2] * attenuation);if (d[2] > 255) d[2] = 255; + d[3] = (int)(diffusetex[3] );if (d[3] > 255) d[3] = 255; + } + else + { + d[0] = (int)(diffusetex[0] * Color_Ambient[0] * LightColor[0] * attenuation);if (d[0] > 255) d[0] = 255; + d[1] = (int)(diffusetex[1] * Color_Ambient[1] * LightColor[1] * attenuation);if (d[1] > 255) d[1] = 255; + d[2] = (int)(diffusetex[2] * Color_Ambient[2] * LightColor[2] * attenuation);if (d[2] > 255) d[2] = 255; + d[3] = (int)(diffusetex[3] );if (d[3] > 255) d[3] = 255; + } + buffer_FragColorbgra8[x*4+0] = d[0]; + buffer_FragColorbgra8[x*4+1] = d[1]; + buffer_FragColorbgra8[x*4+2] = d[2]; + buffer_FragColorbgra8[x*4+3] = d[3]; + } + } DPSOFTRAST_Draw_Span_FinishBGRA8(span, buffer_FragColorbgra8); } -- 2.39.2