/* Copyright (c) 2002-2012 Croteam Ltd. All rights reserved. */ #include "StdH.h" #include void DoSpecularLayer(INDEX iSpeculaTexture,INDEX iSpecularColor) { GFXVertex4 *paVertices = shaGetVertexArray(); GFXNormal *paNormals = shaGetNormalArray(); INDEX ctVertices = shaGetVertexCount(); FLOAT3D &vLightDir = -shaGetLightDirection().Normalize(); COLOR colLight = ByteSwap(shaGetLightColor()); COLOR colAmbient = ByteSwap(shaGetAmbientColor()); GFXTexCoord *ptcUVMap = shaGetNewTexCoordArray(); Matrix12 &mObjToView = *shaGetObjToViewMatrix(); shaCalculateLightForSpecular(); // determine multitexturing capability for overbrighting purposes const BOOL bOverbright = shaOverBrightningEnabled(); // cache light intensities (-1 in case of overbrighting compensation) const INDEX iBright = bOverbright ? 0 : 1; SLONG slLR = (colLight & CT_RMASK)>>(CT_RSHIFT-iBright); SLONG slLG = (colLight & CT_GMASK)>>(CT_GSHIFT-iBright); SLONG slLB = (colLight & CT_BMASK)>>(CT_BSHIFT-iBright); SLONG slAR = (colAmbient & CT_RMASK)>>(CT_RSHIFT-iBright); SLONG slAG = (colAmbient & CT_GMASK)>>(CT_GSHIFT-iBright); SLONG slAB = (colAmbient & CT_BMASK)>>(CT_BSHIFT-iBright); if( bOverbright) { slAR = ClampUp( slAR, 127L); slAG = ClampUp( slAG, 127L); slAB = ClampUp( slAB, 127L); } // for each vertex INDEX ivx=0; for(;ivx>CT_ASHIFT); colSrfSpec.r = ClampUp( (colSrfSpec.r *slLR)>>8, 255L); colSrfSpec.g = ClampUp( (colSrfSpec.g *slLG)>>8, 255L); colSrfSpec.b = ClampUp( (colSrfSpec.b *slLB)>>8, 255L); GFXColor *pcolSpec = shaGetNewColorArray(); GFXColor *pcolBase = shaGetColorArray();; // for each vertex in the surface for(ivx=0;ivx>8) | (((colSrfSpec.g)*slShade)&0x0000FF00) |((((colSrfSpec.b)*slShade)<<8)&0x00FF0000); } shaSetTexCoords(ptcUVMap); shaSetVertexColors(pcolSpec); shaSetTexture(iSpeculaTexture); shaBlendFunc( GFX_INV_SRC_ALPHA, GFX_ONE); shaEnableBlend(); shaCullFace(GFX_BACK); shaRender(); shaCullFace(GFX_FRONT); shaRender(); } void DoReflectionLayer(INDEX iReflectionTexture,INDEX iReflectionColor,BOOL bFullBright) { GFXVertex4 *paVertices = NULL; GFXNormal *paNormals = NULL; paVertices = shaGetVertexArray(); paNormals = shaGetNormalArray(); INDEX ctVertices = shaGetVertexCount(); GFXTexCoord *ptcUVMap = shaGetNewTexCoordArray(); Matrix12 &mObjToView = *shaGetObjToViewMatrix(); Matrix12 &mObjToAbs = *shaGetObjToAbsMatrix(); CAnyProjection3D &apr = *shaGetProjection(); // calculate projection of viewer in absolute space FLOATmatrix3D &mViewer = apr->pr_ViewerRotationMatrix; FLOAT3D vViewer = FLOAT3D(-mViewer(3,1),-mViewer(3,2),-mViewer(3,3)); Matrix12 mTemp,mInvert; MatrixVectorToMatrix12(mTemp,mViewer,FLOAT3D(0,0,0)); MatrixTranspose(mInvert,mTemp); // mObjToAbs = !mViewer; // for each vertex for(INDEX ivx=0;ivx>CT_ASHIFT); if(bFullBright) { // just copy reflection color for( INDEX ivx=0;ivx