Exemple #1
0
        float mReflectCoeff;     //!< Fresnel reflection coefficient (for glass) 

        Bsdf(
        Ray aRay,
        ref Normal normal,
        Material Material,
        SceneGeometryInfo aScene)
        {
            Setup(aRay, ref normal, Material, aScene);
        }
Exemple #2
0
        void Setup(
            Ray aRay,
            ref Normal normal,
            Material Material,
            SceneGeometryInfo aScene)
        {
            mMaterialID = -1;
            mFrame.SetFromZ(ref normal);
            var invdir = -aRay.Direction;
            mLocalDirFix = mFrame.ToLocal(ref invdir);

            // reject rays that are too parallel with tangent plane
            if (Math.Abs(mLocalDirFix.z) < Consts.EPS_COSINE)
            {
                return;
            }

            GetComponentProbabilities(Material, mProbabilities);

            mIsDelta = (Math.Abs(mProbabilities.diffProb) < MathLab.Epsilon) && (Math.Abs(mProbabilities.phongProb) < MathLab.Epsilon);

            // now it becomes valid
            mMaterialID = 1;//Material.mIOR;
        }
Exemple #3
0
 float AlbedoRefract(Material aMaterial)
 {
     return 1f;
 }
Exemple #4
0
 float AlbedoReflect(Material aMaterial)
 {
     return Luminance(aMaterial.mMirrorReflectance);
 }
Exemple #5
0
 float AlbedoPhong(Material aMaterial)
 {
     return Luminance(aMaterial.mPhongReflectance);
 }
Exemple #6
0
 float AlbedoDiffuse(Material aMaterial)
 {
     return Luminance(aMaterial.mDiffuseReflectance);
 }
Exemple #7
0
        void GetComponentProbabilities(
             Material aMaterial,
            ComponentProbabilities oProbabilities)
        {
            mReflectCoeff = Utils.FresnelDielectric(mLocalDirFix.z, aMaterial.mIOR);

            float albedoDiffuse = AlbedoDiffuse(aMaterial);
            float albedoPhong = AlbedoPhong(aMaterial);
            float albedoReflect = mReflectCoeff * AlbedoReflect(aMaterial);
            float albedoRefract = (1f - mReflectCoeff) * AlbedoRefract(aMaterial);

            float totalAlbedo = albedoDiffuse + albedoPhong + albedoReflect + albedoRefract;

            if (totalAlbedo < 1e-9f)
            {
                oProbabilities.diffProb = 0f;
                oProbabilities.phongProb = 0f;
                oProbabilities.reflProb = 0f;
                oProbabilities.refrProb = 0f;
                mContinuationProb = 0f;
            }
            else
            {
                oProbabilities.diffProb = albedoDiffuse / totalAlbedo;
                oProbabilities.phongProb = albedoPhong / totalAlbedo;
                oProbabilities.reflProb = albedoReflect / totalAlbedo;
                oProbabilities.refrProb = albedoRefract / totalAlbedo;
                // The continuation probability is max component from reflectance.
                // That way the weight of sample will never rise.
                // Luminance is another very valid option.
                mContinuationProb =
                    (aMaterial.mDiffuseReflectance +
                    aMaterial.mPhongReflectance +
                    mReflectCoeff * aMaterial.mMirrorReflectance).Max() +
                    (1f - mReflectCoeff);

                mContinuationProb = Math.Min(1f, Math.Max(0f, mContinuationProb));
            }
        }