GPUOpen-LibrariesAndSDKs / RadeonProRender-Baikal

MIT License
334 stars 78 forks source link

Instance for Area Light #186

Open zjxeditor opened 6 years ago

zjxeditor commented 6 years ago

Hi, can we create instance for area light? I want to create multi area light with the same mesh geometry. But when I create the second light geometry use instancing, the program will crash. After experiment, I have to create a individual mesh geometry data for the second area light, then it will work.

zjxeditor commented 6 years ago

I found it. In the following code:

RadeonRays::float3 AreaLight::GetPower(Scene1 const& scene) const
    {
        auto mesh = std::static_pointer_cast<Mesh>(m_shape);
        auto indices = mesh->GetIndices();
        auto vertices = mesh->GetVertices();

        auto i0 = indices[m_prim_idx * 3];
        auto i1 = indices[m_prim_idx * 3 + 1];
        auto i2 = indices[m_prim_idx * 3 + 2];

        auto v0 = vertices[i0];
        auto v1 = vertices[i1];
        auto v2 = vertices[i2];

        float area = 0.5f * std::sqrt(cross(v2 - v0, v1 - v0).sqnorm());
        return PI * GetEmittedRadiance() * area;
    }
harokyang commented 6 years ago

I think this GetPower() of AreaLight should respect the transform matrix of the shape If a scale matrix is applied, the calculation of area here gives incorrect result