/* Copyright (c) 2002-2012 Croteam Ltd. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "Shaders/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, 127); slAG = ClampUp( slAG, 127); slAB = ClampUp( slAB, 127); } // for each vertex INDEX ivx; for(ivx=0;ivx>CT_ASHIFT); colSrfSpec.ub.r = ClampUp( (colSrfSpec.ub.r *slLR)>>8, 255); colSrfSpec.ub.g = ClampUp( (colSrfSpec.ub.g *slLG)>>8, 255); colSrfSpec.ub.b = ClampUp( (colSrfSpec.ub.b *slLB)>>8, 255); GFXColor *pcolSpec = shaGetNewColorArray(); GFXColor *pcolBase = shaGetColorArray();; // for each vertex in the surface for(ivx=0;ivx>8) | (((colSrfSpec.ub.g)*slShade)&0x0000FF00) |((((colSrfSpec.ub.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