void DecalMesh::StreamOutMesh( ELightPass light, EPass pass ) { if ( pass == BLEND_PASS ) return; GLASSERT( !Stencil() ); // separate render L3PERFTRACK const Vector3F& eye = Lilith3D::Instance()->GetCamera()->Eye(); float dx = pos.x - eye.x; float dy = pos.y - eye.y; float dSquared = dx*dx + dy*dy - (size*size)*0.25f; // Stencil pass doesn't need individual state. if ( dSquared > OBJECT_FADEOUT_SQUARED ) return; // Has faded out. Do not draw. const Shader* shader = GetShader(); if ( shader && light == SHADOW_PASS ) return; if ( !shader ) { if ( light == BRIGHT_PASS ) shader = ShaderManager::Instance()->GetShader( ShaderManager::DIFFUSE_SHADER ); else if ( light == SHADOW_PASS ) shader = ShaderManager::Instance()->GetShader( ShaderManager::DIFFUSE_SHADOW_SHADER ); else GLASSERT( 0 ); } GLASSERT( shader ); float alpha = Alpha(); if ( dSquared > OBJECT_FADE_SQUARED ) { alpha *= Clamp( Interpolate( OBJECT_FADE, 1.0f, OBJECT_FADEOUT, 0.0f, sqrtf( dSquared ) ), 0.0f, 1.0f ); } glColor4f( Color().r, Color().g, Color().b, alpha ); L3State state; state.blend = true; state.clamp = true; state.lighting = true; state.texture = texture; state.shader = shader; state.depthWrite = false; StateManager::Enable( state ); Rectangle2F bounds; bounds.Set( AABB().min.x, AABB().min.y, AABB().max.x, AABB().max.y ); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadMatrixf( texMat.x ); //glMatrixMode(GL_MODELVIEW); Lilith3D::GetTerrainMesh()->RenderDecal( bounds, false ); //glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); }
Rectangle2F MapScene::GridBounds2(int x, int y, bool useGutter) { float gridSize = mapImage2.Width() / float(MAP2_SIZE); float gutter = useGutter ? gamui2D.TextHeightVirtual() * 0.25f : 0; Rectangle2F r; r.Set(mapImage2.X() + float(x)*gridSize + gutter, mapImage2.Y() + float(y)*gridSize + gutter, mapImage2.X() + float(x + 1)*gridSize - gutter, mapImage2.Y() + float(y + 1)*gridSize - gutter); return r; }
void DecalMesh::StreamAllStencilDecals( Mesh* list ) { L3PERFTRACK // Sort everything to a vector, where it can be sorted. Then // sort on the texture since that is the only state that changes. unsigned count = 0; for( ; list; list = list->nextRender ) { GLASSERT( list->Type() == DECALMESH ); renderVec[count] = (DecalMesh*) list; ++count; GLASSERT( count < MAX_DECAL_STENCIL ); // start throwing away decals... if ( count == MAX_DECAL_STENCIL ) break; } if ( count == 0 ) return; std::sort( &renderVec[0], &renderVec[count], DecalMeshTexture() ); const Texture* texture = renderVec[0]->DecalTexture(); L3State state; state.lighting = false; state.alphaTest = 0.5f; state.texture = texture; state.clamp = true; state.depthWrite = false; StateManager::Enable( state ); const Vector3F& eye = Lilith3D::Instance()->GetCamera()->Eye(); glMatrixMode(GL_TEXTURE); glPushMatrix(); bool suppress = false; for( unsigned i=0; i<count; ++i ) { DecalMesh* decal = renderVec[i]; float dx = decal->pos.x - eye.x; float dy = decal->pos.y - eye.y; float dSquared = dx*dx + dy*dy - (decal->size*decal->size)*0.25f; if ( dSquared > SHADOW_END_FADE_SQUARED ) { continue; } if ( decal->DecalTexture() != texture ) { state.texture = renderVec[i]->DecalTexture(); StateManager::Enable( state ); } Rectangle2F bounds; bounds.Set( decal->AABB().min.x, decal->AABB().min.y, decal->AABB().max.x, decal->AABB().max.y ); glLoadMatrixf( decal->texMat.x ); Lilith3D::GetTerrainMesh()->RenderDecal( bounds, suppress ); suppress = true; } glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); }