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(); }