idvr / exposure-render

Automatically exported from code.google.com/p/exposure-render
0 stars 0 forks source link

SampleF seems to double the pdf #19

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi again,

It seems to me that SampleF returns the double of the pdf:

When adding 
Pdf += m_Lambertian.Pdf(Wol, Wil);
Pdf += m_Microfacet.Pdf(Wol, Wil);

Pdf is already set and non zero. Furthermore why is here no Importance sampling 
applied.

What I am asking is, could you please tell me the reason behind this.

Regards
Christoph

HOD CColorXyz SampleF(const Vec3f& Wo, Vec3f& Wi, float& Pdf, const 
CBrdfSample& S)
    {
        const Vec3f Wol = WorldToLocal(Wo);
        Vec3f Wil;

        CColorXyz R;

        if (S.m_Component <= 0.5f)
        {
            m_Lambertian.SampleF(Wol, Wil, Pdf, S.m_Dir);
        }
        else
        {
            m_Microfacet.SampleF(Wol, Wil, Pdf, S.m_Dir);
        }

        Pdf += m_Lambertian.Pdf(Wol, Wil);
        Pdf += m_Microfacet.Pdf(Wol, Wil);

        R += m_Lambertian.F(Wol, Wil);
        R += m_Microfacet.F(Wol, Wil);

        Wi = LocalToWorld(Wil);

        return R;
    }

Original issue reported on code.google.com by c.web...@yahoo.de on 13 Jun 2012 at 1:50

GoogleCodeExporter commented 8 years ago
Hi yet again, 
I have thought and talked about this a little more ande come to the conclusion 
that I would do this different.

I base this on a multiple importance sampling formula I have here:

\sum_{overStrategies:i} \sum_{overSamplesPerStrategy:j} w_i * f(xj) 
/(SampleCount_i * p_i(x_j))

I have two strategies, one sample for the chosen, 0 for the other, thus my 
formula becomes

0.5 * f(x_j) / p_i(x_)

The function the scribes:

HOD CColorXyz SampleF(const Vec3f& Wo, Vec3f& Wi, float& Pdf, const 
CBrdfSample& S)
    {
        const Vec3f Wol = WorldToLocal(Wo);
        Vec3f Wil;

        CColorXyz F;

        if (S.m_Component <= 0.5f)
        {
            F = m_Lambertian.SampleF(Wol, Wil, Pdf, S.m_Dir);
        }
        else
        {
            F = m_Microfacet.SampleF(Wol, Wil, Pdf, S.m_Dir);
        }
        Pdf *= 2;

        Wi = LocalToWorld(Wil);

        return F;
    }

Please tell me where my understanding differs from yours, by now I am 
thoroughly confused.

Regards
Christoph

Original comment by c.web...@yahoo.de on 14 Jun 2012 at 8:55

GoogleCodeExporter commented 8 years ago
On the other hand,

if I assume that I shoot half a sample for each pdf, the weights cancel out and 
I am back at:
HOD CColorXyz SampleF(const Vec3f& Wo, Vec3f& Wi, float& Pdf, const 
CBrdfSample& S)
    {
        const Vec3f Wol = WorldToLocal(Wo);
        Vec3f Wil;

        CColorXyz F;

        if (S.m_Component <= 0.5f)
        {
            m_Lambertian.SampleF(Wol, Wil, Pdf, S.m_Dir);
        }
        else
        {
            m_Microfacet.SampleF(Wol, Wil, Pdf, S.m_Dir);
        }

        Pdf = m_Lambertian.Pdf(Wol, Wil);
        Pdf += m_Microfacet.Pdf(Wol, Wil);

        F += m_Lambertian.F(Wol, Wil);
        F += m_Microfacet.F(Wol, Wil);

        Wi = LocalToWorld(Wil);

        return F;
    }

Which still differs in a way, that I have one pdf twice in the code above. 

- still confused

Original comment by c.web...@yahoo.de on 14 Jun 2012 at 9:05