static std::string join(const COL& col, const std::string& sep = ", ") { std::string the_sep = ""; std::ostringstream buf; // type const_iterator car "COL" est passé "const" (constant) typename COL::const_iterator it; for (it = col.begin(); it != col.end(); ++it) { buf << the_sep << *it; the_sep = sep; }; return buf.str(); }
void calculateValues() { MAT tm; tm.CreateRotationMatrix(rotation); // A bit optimized version, use base vectors directly normal.x = tm.Get(8); normal.y = tm.Get(9); normal.z = tm.Get(10); VC3 biasNormal = normal; biasNormal *= .07f; VC3 right(tm.Get(0), tm.Get(1), tm.Get(2)); VC3 up(tm.Get(4), tm.Get(5), tm.Get(6)); right *= .5f * size.x; up *= .5f * size.y; assert(fabsf(up.GetDotWith(right)) < 0.0001f); vertices[0] = position; vertices[0] -= right; vertices[0] -= up; vertices[0] += biasNormal; vertices[1] = position; vertices[1] -= right; vertices[1] += up; vertices[1] += biasNormal; vertices[2] = position; vertices[2] += right; vertices[2] -= up; vertices[2] += biasNormal; vertices[3] = position; vertices[3] += right; vertices[3] += up; vertices[3] += biasNormal; COL finalColor = light; finalColor.Clamp(); vertexColor = finalColor.GetAsD3DCompatibleARGB() & 0x00FFFFFF; vertexColor |= alpha << 24; if(entity) entity->setRadius(getRadius()); }
void renderShadows(Storm3D_Scene &scene) { // this is BROKEN // FIXME // just clear the list shadowDecals.clear(); return; createIndexBuffers(); int renderAmount = 0; if(!shadowDecals.empty()) { IStorm3D_Camera *camera = scene.GetCamera(); Storm3D_Camera *stormCamera = reinterpret_cast<Storm3D_Camera *> (camera); Frustum frustum = stormCamera->getFrustum(); shadowVertices.create(shadowDecals.size() * 4, VERTEX_SIZE, true); int rawSize = shadowDecals.size() * 4 * VERTEX_SIZE; void *ramBuffer = malloc(rawSize); void *lockPointer = shadowVertices.lock(); VXFORMAT_DECAL *buffer = reinterpret_cast<VXFORMAT_DECAL *> (ramBuffer); float inverseRange =1.f / fogRange; for(unsigned int i = 0; i < shadowDecals.size(); ++i) { const StormDecal &decal = shadowDecals[i]; Sphere sphere(decal.position, decal.getRadius()); if(frustum.visibility(sphere)) { float factor = decal.position.y - fogEnd; factor *= inverseRange; if(factor < 0.f) factor = 0.f; if(factor > 1.f) factor = 1.f; factor = 1.f - factor; COL color = decal.light; color.r += factor * (1.f - color.r); color.g += factor * (1.f - color.g); color.b += factor * (1.f - color.b); DWORD vertexColor = color.GetAsD3DCompatibleARGB() & 0x00FFFFFF; DWORD oldColor = decal.vertexColor; decal.vertexColor = vertexColor; decal.insert(buffer); decal.vertexColor = oldColor; buffer += 4; ++renderAmount; } } if(renderAmount) { if(renderAmount > STORM_MAX_DECAL_AMOUNT) renderAmount = STORM_MAX_DECAL_AMOUNT; memcpy(lockPointer, ramBuffer, renderAmount * 4 * VERTEX_SIZE); } free(ramBuffer); shadowVertices.unlock(); } D3DXMATRIX tm; frozenbyte::storm::VertexShader::disable(); frozenbyte::storm::PixelShader::disable(); Storm3D_ShaderManager::GetSingleton()->SetWorldTransform(tm); applyFVF(DECAL_FVF, VERTEX_SIZE); glActiveTexture(GL_TEXTURE0); glClientActiveTexture(GL_TEXTURE0); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PRIMARY_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glActiveTexture(GL_TEXTURE1); glClientActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_3D); glDisable(GL_TEXTURE_CUBE_MAP); glDepthMask(GL_FALSE); glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); glBlendFunc(GL_ZERO, GL_SRC_COLOR); if(renderAmount && shadowMaterial) { shadowVertices.apply(0); shadowMaterial->applyShadow(); indices.render(renderAmount * 2, renderAmount * 4); scene.AddPolyCounter(renderAmount * 2); } glDepthMask(GL_TRUE); glDisable(GL_BLEND); shadowDecals.clear(); }
//------------------------------------------------------------------ // Storm3D_Scene_PicList_Font::Render //------------------------------------------------------------------ void Storm3D_Scene_PicList_Font::Render() { // Calculate complete letter amount and letters per texture int letters_per_texture=font->tex_letter_rows*font->tex_letter_columns; int letter_amt=font->texture_amount*letters_per_texture; // Create 3d-vector VC3 pos(position.x,position.y,0); // Create color (color+alpha) COL color = font->GetColor(); color *= colorFactor; color.Clamp(); //DWORD col=font->GetColor().GetAsD3DCompatibleARGB(); //DWORD col=color.GetAsD3DCompatibleARGB(); DWORD col = D3DCOLOR_ARGB((int)((alpha)*255.0f),(int)(color.r*255.0f),(int)(color.g*255.0f),(int)(color.b*255.0f)); Storm3D2->GetD3DDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); if(font->font && font->sprite) { #pragma message("** **") #pragma message("** Size to screen boundary and enable clipping **") #pragma message("** **") //VC2 _position,VC2 _size RECT rc = { int(position.x), int(position.y), int(position.x + size.x + 100), int(position.y + size.y + 1000) }; //if(uniText) // font->font->DrawTextW(0, uniText, wcslen(uniText), &rc, DT_SINGLELINE | DT_LEFT | DT_NOCLIP, col); //else if(text) // font->font->DrawText(0, text, strlen(text), &rc, DT_SINGLELINE | DT_LEFT | DT_NOCLIP, col); DWORD flags = D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_ALPHABLEND; font->sprite->Begin(flags); if(uniText) font->font->DrawTextW(font->sprite, uniText, wcslen(uniText), &rc, DT_LEFT | DT_NOCLIP, col); else if(text) font->font->DrawText(font->sprite, text, strlen(text), &rc, DT_LEFT | DT_NOCLIP, col); font->sprite->End(); } else if(text) { for(int l=0;l<int(strlen(text));l++) { // Search for letter int let=-1; for (int i=0;i<letter_amt;i++) { if (font->letter_characters[i]==text[l]) { let=i; // doh, why not break now when we found it and save time! break; } else { // if we find the null terminator, just stop there, because // otherwise we'll go past the character array size if it // does not contain character definitions for total of letter_amt // characters. In my opininion requiring such a thing is not nice. if (font->letter_characters[i] == '\0') break; } } // Is this letter in font if (let>=0) { // Apply the correct texture font->textures[let/letters_per_texture]->Apply(0); // Calculate x/y int x=let%font->tex_letter_columns; int y=(let%letters_per_texture)/font->tex_letter_columns; // Calculate texture coordinates float tx1=1/(float)font->tex_letter_columns; float ty1=1/(float)font->tex_letter_rows; float fx=(float)x*tx1; float fy=(float)y*ty1; // Create a quad VXFORMAT_2D vx[4]; vx[0]=VXFORMAT_2D(pos+VC3(0,size.y,0),1, col,VC2(fx,fy+ty1)); vx[1]=VXFORMAT_2D(pos,1, col,VC2(fx,fy)); vx[2]=VXFORMAT_2D(pos+VC3(size.x,size.y,0),1, col,VC2(fx+tx1,fy+ty1)); vx[3]=VXFORMAT_2D(pos+VC3(size.x,0,0),1, col,VC2(fx+tx1,fy)); // Clip if (Clip2DRectangle(Storm3D2,vx[1],vx[2])) { // Copy clipping vx[0].position.x=vx[1].position.x; vx[0].texcoords.x=vx[1].texcoords.x; vx[3].position.y=vx[1].position.y; vx[3].texcoords.y=vx[1].texcoords.y; vx[0].position.y=vx[2].position.y; vx[0].texcoords.y=vx[2].texcoords.y; vx[3].position.x=vx[2].position.x; vx[3].texcoords.x=vx[2].texcoords.x; for(int i = 0; i < 4; ++i) { vx[i].position.x -= .5f; vx[i].position.y -= .5f; } // Render it Storm3D2->GetD3DDevice()->SetVertexShader(0); Storm3D2->GetD3DDevice()->SetFVF(FVF_VXFORMAT_2D); frozenbyte::storm::validateDevice(*Storm3D2->GetD3DDevice(), Storm3D2->getLogger()); Storm3D2->GetD3DDevice()->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,vx,sizeof(VXFORMAT_2D)); scene->AddPolyCounter(2); } } // Add x-koordinate if (let>=0) pos.x+=((float)font->letter_width[let]/64.0f)*size.x; else pos.x+=size.x/2.0f; } } }
void renderShadows(Storm3D_Scene &scene) { gfx::Renderer& renderer = storm.renderer; gfx::Device& device = renderer.device; gfx::ProgramManager& programManager = renderer.programManager; if (shadowDecals.empty() || !shadowMaterial) return; int renderAmount = 0; IStorm3D_Camera *camera = scene.GetCamera(); Storm3D_Camera *stormCamera = reinterpret_cast<Storm3D_Camera *> (camera); Frustum frustum = stormCamera->getFrustum(); uint32_t baseVertex = 0; Vertex_P3DUV *buffer = 0;; renderer.lockDynVtx<Vertex_P3DUV>(shadowDecals.size() * 4, &buffer, &baseVertex); float inverseRange = 1.f / fogRange; for (unsigned int i = 0; i < shadowDecals.size() && renderAmount < MAX_DECAL_AMOUNT; ++i) { const Decal &decal = shadowDecals[i]; Sphere sphere(decal.position, decal.getRadius()); if (frustum.visibility(sphere)) { float factor = decal.position.y - fogEnd; factor *= inverseRange; factor = std::max(0.0f, factor); factor = std::min(1.0f, factor); factor = 1.f - factor; COL color = decal.light; color.r += factor * (1.f - color.r); color.g += factor * (1.f - color.g); color.b += factor * (1.f - color.b); uint32_t vertexColor = color.as_u32_D3D_ARGB(decal.alpha); decal.insert(buffer, vertexColor); buffer += 4; ++renderAmount; } } renderer.unlockDynVtx(); if (renderAmount == 0) return; D3DXMATRIX tm; D3DXMatrixIdentity(&tm); programManager.setProgram( gfx::ProgramManager::DECAL_SHADOW); programManager.setWorldMatrix(tm); programManager.applyState(device); device.SetRenderState(D3DRS_ZWRITEENABLE, FALSE); device.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); device.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO); device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR); if (shadowMaterial->baseTexture) shadowMaterial->baseTexture->Apply(0); renderer.setFVF(FVF_P3DUV); renderer.setDynVtxBuffer<Vertex_P3DUV>(); renderer.drawQuads(baseVertex, renderAmount); device.SetRenderState(D3DRS_ZWRITEENABLE, TRUE); device.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); shadowDecals.clear(); }
void render(Storm3D_Scene &scene) { gfx::Renderer& renderer = storm.renderer; gfx::Device& device = renderer.device; gfx::ProgramManager& programManager = renderer.programManager; baseDecalVertex = 0; findDecals(scene); if (decals.empty()) return; Vertex_P3NDUV *buffer = 0; renderer.lockDynVtx<Vertex_P3NDUV>(decals.size() * 4, &buffer, &baseDecalVertex); for (unsigned int i = 0; i < decals.size(); ++i) { Decal& decal = *decals[i]; COL decalColor = decal.light * (decal.type == Outside ? outFactor : inFactor); decalColor.Clamp(); uint32_t vertexColor = decalColor.as_u32_D3D_ARGB(decal.alpha); decal.insert(buffer, vertexColor); buffer += 4; } renderer.unlockDynVtx(); // Render if (!decals.empty()) { device.SetRenderState(D3DRS_ZWRITEENABLE, FALSE); device.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); device.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); D3DXMATRIX tm; D3DXMatrixIdentity(&tm); programManager.setWorldMatrix(tm); programManager.setProgram(gfx::ProgramManager::DECAL_LIGHTING); renderer.setDynVtxBuffer<Vertex_P3NDUV>(); renderer.setFVF(FVF_P3NDUV); int materialIndex = 0; int startIndex = 0; int endIndex = 0; for (;;) { materialIndex = decals[startIndex]->materialIndex; if(materials[materialIndex].baseTexture) materials[materialIndex].baseTexture->Apply(0); programManager.setDiffuse(materials[materialIndex].diffuseColor); programManager.applyState(device); int decalAmount = decals.size(); for (int i = startIndex + 1; i < decalAmount; ++i) { if (decals[i]->materialIndex != materialIndex) break; endIndex = i; } int renderAmount = endIndex - startIndex + 1; renderer.drawQuads(baseDecalVertex + startIndex * 4, renderAmount); startIndex = ++endIndex; if (startIndex >= decalAmount) break; } device.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); } }