public override IRadianceEvaluation Sample(ref Vector wo, ref IRadianceEvaluation radiance, float u0, float u1, float u2, out BsdfSample result, BrdfType flags = BrdfType.All) { result = new BsdfSample() { }; throw new NotImplementedException(); }
public void Sample(ref Vector wo, ref Normal N, ref Normal shadeN, float u0, float u1, float u2,float u3, out BsdfSample sample, BxDFType type = BxDFType.AllTypes) { sample = new BsdfSample(); var fl = type; int matchingComps = NumComponents(fl); if (matchingComps == 0) { sample.Pdf = 0f; sample.Wi = Vector.Zero; sample.Spectrum = new RgbSpectrum(0f).ToArray(); } int which = (int)Math.Min((u0 * matchingComps), matchingComps - 1); BxDFBase bxdf = null; int count = which; for (int i = 0; i < Bxdfs.Length; ++i) if (Bxdfs[i].Type.HasFlag(fl)) if (count-- == 0) { bxdf = Bxdfs[i]; break; } Vector wi = new Vector(); var pdf = 0f; bxdf.Sample(ref wo, ref N, ref shadeN, u1, u2, u3, out sample, type); wi = sample.Wi; pdf = sample.Pdf; var sampled = bxdf.Type; if (pdf > 0f && pdf < MathLab.Epsilon) sample.Spectrum = new float[3]{0f,0f,0f}; //if (sampledTy != null) sampledType = bxdf.Type; //wiW = LocalToWorld(wi); if ((!bxdf.Type.HasFlag(BxDFType.Specular)) && matchingComps > 1) { for (int i = 0; i < Bxdfs.Length; ++i) { if (Bxdfs[i] != bxdf && (Bxdfs[i].Type.HasFlag(fl))) pdf += Bxdfs[i].Pdf(ref wo, ref wi, fl); } } if (matchingComps > 1) pdf /= matchingComps; // Compute value of BSDF for sampled direction if (bxdf.Type.HasFlag(BxDFType.Specular)) //if ((bxdf.Type & BxDFType.BSDF_SPECULAR) == 0) { var f = RgbSpectrum.ZeroSpectrum(); if ((Vector.Dot(ref N,ref wi)) * Vector.Dot(ref N, ref wo) > 0f) // ignore BTDFs { fl = fl & ~BxDFType.Transmission; } else // ignore BRDFs fl = (fl & ~BxDFType.Reflection); for (int i = 0; i < Bxdfs.Length; ++i) if ((Bxdfs[i].Type.HasFlag(fl))) f += new RgbSpectrum(Bxdfs[i].Eval(ref wo, ref wi, ref N)); sample.Spectrum = (f/pdf).ToArray(); } }
public IRadianceEvaluation Sample(ref Vector wo, ref IRadianceEvaluation radiance, float u0, float u1, float u2, out BsdfSample result, BrdfType flags = BrdfType.All) { float selPdf; BaseBsdf bxdf = GetBsdf(out selPdf, flags); if (bxdf == null) { result = new BsdfSample(); return ColorManager.Instance.ZeroRadiance(); } Vector wo1 = bxdf.WorldToLocal(ref wo); var r = bxdf.Sample(ref wo1, ref radiance, u0, u1, u2, out result, flags); result.DirectPdf *= selPdf; result.OutgoingDirection = bxdf.LocalToWorld(ref result.OutgoingDirection); return r; /*Vector wi = new Vector(); var wiW = Vector.Zero; var pdf = 0f; bool specularBounce; if (pdf > 0f && pdf < MathLab.Epsilon) return ColorManager.Instance.ZeroRadiance(); if (flags != BrdfType.All ) flags = bxdf.Type; wiW = bxdf.LocalToWorld(ref wi); if ((!bxdf.Type.Has(BrdfType.Specular)) && matchingComps > 1) { for (int i = 0; i < bxdfs.Count; ++i) { if (bxdfs[i] != bxdf &&bxdfs[i].Type.Has(flags)) pdf += bxdfs[i].Pdf(scene, ref wo); } } if (matchingComps > 1) pdf /= matchingComps; if (bxdf.Type.Has(BrdfType.Specular)) { var f = ColorManager.Instance.ZeroRadiance(); if ((Vector.Dot(ref wiW , ref bxdf.Ng)) * Vector.Dot(ref wo1 ,ref bxdf.Ng) > 0f) // ignore BTDFs { flags = flags & ~BrdfType.Refractive; } else // ignore BRDFs flags = flags & ~BrdfType.Reflection; float cosp, rwp; for (int i = 0; i < bxdfs.Count; ++i) if (bxdfs[i].Type.Has(flags)) f.Add(bxdfs[i].Evaluate(scene, ref wo, Vector.Dot(ref wiW, ref bxdf.Ng), out cosp, out rwp)); f.Div(pdf); } return f;*/ }
public abstract void Sample(ref Vector wo, ref Normal N, ref Normal shadeN, float u0, float u1, float u2,out BsdfSample sample,BxDFType type = BxDFType.AllTypes);