#include <mesh_blender.h>
Nevrax France
Definition at line 48 of file mesh_blender.h.
Public Member Functions | |
CMeshBlender () | |
Constructor. | |
void | prepareRenderForGlobalAlpha (CMaterial &material, IDriver *drv, float globalAlpha, uint8 globalAlphaInt, bool gaDisableZWrite) |
Modify the material and the driver for Global Alpha Use. | |
void | prepareRenderForGlobalAlphaCoarseMesh (CMaterial &material, IDriver *drv, NLMISC::CRGBA color, float globalAlpha, bool gaDisableZWrite) |
Same method, but special for CoarseMesh (used by CMeshMultiLod::renderMeshGeom). | |
void | restoreRender (CMaterial &material, IDriver *drv, bool gaDisableZWrite) |
Restore the material and driver in their initial state. | |
void | restoreRenderCoarseMesh (CMaterial &material, IDriver *drv, bool gaDisableZWrite) |
Same method, but special for CoarseMesh (used by CMeshMultiLod::renderMeshGeom). | |
Private Attributes | |
float | _BkAlphaTestThreshold |
bool | _BkBlend |
CMaterial::TBlend | _BkDstBlend |
uint8 | _BkOpacity |
CMaterial::TBlend | _BkSrcBlend |
NLMISC::CRGBA | _BkupColor |
bool | _BkZWrite |
|
Constructor.
Definition at line 53 of file mesh_blender.h.
00053 {} |
|
Modify the material and the driver for Global Alpha Use.
Definition at line 37 of file mesh_blender.cpp. References _BkAlphaTestThreshold, _BkBlend, _BkDstBlend, _BkOpacity, _BkSrcBlend, _BkZWrite, NL3D::CMaterial::getAlphaTest(), NL3D::CMaterial::getAlphaTestThreshold(), NL3D::CMaterial::getBlend(), NL3D::CMaterial::getDstBlend(), NL3D::CMaterial::getOpacity(), NL3D::CMaterial::getSrcBlend(), NL3D::CMaterial::getZWrite(), NL3D::CMaterial::setAlphaTestThreshold(), NL3D::CMaterial::setBlend(), NL3D::IDriver::setBlendConstantColor(), NL3D::CMaterial::setDstBlend(), NL3D::CMaterial::setOpacity(), NL3D::CMaterial::setSrcBlend(), NL3D::CMaterial::setZWrite(), NL3D::IDriver::supportBlendConstantColor(), and uint8. Referenced by NL3D::CMeshMRMSkinnedGeom::render(), NL3D::CMeshMRMGeom::render(), and NL3D::CMeshGeom::render().
00038 { 00039 // Disable ZWrite?? 00040 if(gaDisableZWrite) 00041 { 00042 // Backup and set new the zwrite 00043 _BkZWrite=material.getZWrite (); 00044 material.setZWrite (false); 00045 } 00046 00047 // Backup blend 00048 _BkBlend=material.getBlend (); 00049 material.setBlend (true); 00050 00051 // Backup opacity and blend 00052 _BkOpacity= material.getOpacity (); 00053 _BkSrcBlend= material.getSrcBlend(); 00054 _BkDstBlend= material.getDstBlend(); 00055 00056 // 2 ways: if Blend Constant Color is supported or not. 00057 if(drv->supportBlendConstantColor()) 00058 { 00059 // Set opacity to 255 => If AlphaTest is used, AlphaTexture will be multiplied by 1. 00060 material.setOpacity ( 255 ); 00061 00062 // set the Blend constant Alpha. 00063 drv->setBlendConstantColor( CRGBA(0,0,0, globalAlphaInt) ); 00064 00065 // Active Blend with Blend Constant Alpha . 00066 material.setSrcBlend(CMaterial::blendConstantAlpha); 00067 00068 // Don't set dest if we are in additive blend mode 00069 if ((_BkBlend == false) || (_BkDstBlend != CMaterial::one)) 00070 material.setDstBlend(CMaterial::blendConstantInvAlpha); 00071 00072 // if material is Alpha Test, no-op. Keep same threshold, since Use Alpha of the BlendConstantColor 00073 // to do the alpha-blending. 00074 } 00075 // not supported, ugly way: modify Opacity, and alpha threshold 00076 else 00077 { 00078 // New opacity 00079 material.setOpacity (globalAlphaInt); 00080 00081 // must ensure Std Blend. 00082 material.setSrcBlend(CMaterial::srcalpha); 00083 00084 // Don't set dest if we are in additive blend mode 00085 if ((_BkBlend == false) || (_BkDstBlend != CMaterial::one)) 00086 material.setDstBlend(CMaterial::invsrcalpha); 00087 00088 // if material is Alpha Test, must modulate AlphaTest limit to avoid Pop effects 00089 if(material.getAlphaTest()) 00090 { 00091 _BkAlphaTestThreshold= material.getAlphaTestThreshold(); 00092 material.setAlphaTestThreshold(_BkAlphaTestThreshold * globalAlpha); 00093 } 00094 } 00095 00096 } |
|
Same method, but special for CoarseMesh (used by CMeshMultiLod::renderMeshGeom).
Definition at line 132 of file mesh_blender.cpp. References _BkDstBlend, _BkSrcBlend, _BkupColor, NLMISC::CRGBA::A, NL3D::CMaterial::getColor(), NL3D::CMaterial::getDstBlend(), NL3D::CMaterial::getSrcBlend(), NLMISC::OptFastFloor(), NL3D::CMaterial::setAlphaTestThreshold(), NL3D::CMaterial::setBlend(), NL3D::IDriver::setBlendConstantColor(), NL3D::CMaterial::setColor(), NL3D::CMaterial::setDstBlend(), NL3D::CMaterial::setSrcBlend(), NL3D::CMaterial::setZWrite(), NL3D::IDriver::supportBlendConstantColor(), and uint8. Referenced by NL3D::CMeshMultiLod::renderMeshGeom().
00133 { 00134 // Don't need to bkup some values, because CoarseMesh. 00135 00136 uint8 globalAlphaInt= (uint8)NLMISC::OptFastFloor(255 * globalAlpha); 00137 00138 // Disable ZWrite?? 00139 if(gaDisableZWrite) 00140 material.setZWrite (false); 00141 // Enable blend 00142 material.setBlend (true); 00143 00144 // bkup color and blend factors. 00145 _BkupColor= material.getColor(); 00146 _BkSrcBlend= material.getSrcBlend(); 00147 _BkDstBlend= material.getDstBlend(); 00148 00149 // 2 ways: if Blend Constant Color is supported or not. 00150 if(drv->supportBlendConstantColor()) 00151 { 00152 // Set opacity to 255 => AlphaTexture will be multiplied by 1. 00153 color.A= 255; 00154 // change color 00155 material.setColor ( color ); 00156 00157 // set the Blend constant Alpha. 00158 drv->setBlendConstantColor( CRGBA(0,0,0, globalAlphaInt) ); 00159 00160 // Active Blend with Blend Constant Alpha . 00161 material.setSrcBlend(CMaterial::blendConstantAlpha); 00162 material.setDstBlend(CMaterial::blendConstantInvAlpha); 00163 } 00164 else 00165 { 00166 // Set current Alpha blend transparency (in color becausematerial is unlit) 00167 color.A= globalAlphaInt; 00168 // change color 00169 material.setColor ( color ); 00170 00171 // Active Blend with Blend Constant Alpha . 00172 material.setSrcBlend(CMaterial::srcalpha); 00173 material.setDstBlend(CMaterial::invsrcalpha); 00174 00175 // must modulate AlphaTest limit to avoid Pop effects 00176 material.setAlphaTestThreshold(0.5f * globalAlpha); 00177 } 00178 } |
|
Restore the material and driver in their initial state.
Definition at line 99 of file mesh_blender.cpp. References _BkAlphaTestThreshold, _BkBlend, _BkDstBlend, _BkOpacity, _BkSrcBlend, _BkZWrite, NL3D::CMaterial::getAlphaTest(), NL3D::CMaterial::setAlphaTestThreshold(), NL3D::CMaterial::setBlend(), NL3D::CMaterial::setDstBlend(), NL3D::CMaterial::setOpacity(), NL3D::CMaterial::setSrcBlend(), NL3D::CMaterial::setZWrite(), and NL3D::IDriver::supportBlendConstantColor(). Referenced by NL3D::CMeshMRMSkinnedGeom::render(), NL3D::CMeshMRMGeom::render(), and NL3D::CMeshGeom::render().
00100 { 00101 // Resetup backuped zwrite 00102 if(gaDisableZWrite) 00103 { 00104 material.setZWrite (_BkZWrite); 00105 } 00106 00107 // Resetup backuped blend 00108 material.setBlend (_BkBlend); 00109 00110 // Resetup backuped opacity and blend factors 00111 material.setOpacity (_BkOpacity); 00112 material.setSrcBlend(_BkSrcBlend); 00113 material.setDstBlend(_BkDstBlend); 00114 00115 // 2 ways: if Blend Constant Color is supported or not. 00116 if(drv->supportBlendConstantColor()) 00117 { 00118 // nop 00119 } 00120 else 00121 { 00122 // Resetup backuped AlphaTest threshold 00123 if(material.getAlphaTest()) 00124 { 00125 material.setAlphaTestThreshold(_BkAlphaTestThreshold); 00126 } 00127 } 00128 } |
|
Same method, but special for CoarseMesh (used by CMeshMultiLod::renderMeshGeom).
Definition at line 181 of file mesh_blender.cpp. References _BkDstBlend, _BkSrcBlend, _BkupColor, NL3D::CMaterial::setAlphaTestThreshold(), NL3D::CMaterial::setBlend(), NL3D::CMaterial::setColor(), NL3D::CMaterial::setDstBlend(), NL3D::CMaterial::setSrcBlend(), NL3D::CMaterial::setZWrite(), and NL3D::IDriver::supportBlendConstantColor(). Referenced by NL3D::CMeshMultiLod::renderMeshGeom().
00182 { 00183 // Resetup backuped color and blend factors 00184 material.setColor ( _BkupColor ); 00185 material.setSrcBlend(_BkSrcBlend); 00186 material.setDstBlend(_BkDstBlend); 00187 00188 // ReEnable ZWrite?? 00189 if(gaDisableZWrite) 00190 material.setZWrite (true); 00191 // Reset blend 00192 material.setBlend (false); 00193 00194 // 2 ways: if Blend Constant Color is supported or not. 00195 if(drv->supportBlendConstantColor()) 00196 { 00197 // nop 00198 } 00199 else 00200 { 00201 // reset AlphaTest limit 00202 material.setAlphaTestThreshold(0.5f); 00203 } 00204 } |
|
Definition at line 73 of file mesh_blender.h. Referenced by prepareRenderForGlobalAlpha(), and restoreRender(). |
|
Definition at line 70 of file mesh_blender.h. Referenced by prepareRenderForGlobalAlpha(), and restoreRender(). |
|
Definition at line 72 of file mesh_blender.h. Referenced by prepareRenderForGlobalAlpha(), prepareRenderForGlobalAlphaCoarseMesh(), restoreRender(), and restoreRenderCoarseMesh(). |
|
Definition at line 68 of file mesh_blender.h. Referenced by prepareRenderForGlobalAlpha(), and restoreRender(). |
|
Definition at line 71 of file mesh_blender.h. Referenced by prepareRenderForGlobalAlpha(), prepareRenderForGlobalAlphaCoarseMesh(), restoreRender(), and restoreRenderCoarseMesh(). |
|
Definition at line 74 of file mesh_blender.h. Referenced by prepareRenderForGlobalAlphaCoarseMesh(), and restoreRenderCoarseMesh(). |
|
Definition at line 69 of file mesh_blender.h. Referenced by prepareRenderForGlobalAlpha(), and restoreRender(). |