Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 3
0
 float AlbedoRefract(Material aMaterial)
 {
     return 1f;
 }
Ejemplo n.º 4
0
 float AlbedoReflect(Material aMaterial)
 {
     return Luminance(aMaterial.mMirrorReflectance);
 }
Ejemplo n.º 5
0
 float AlbedoPhong(Material aMaterial)
 {
     return Luminance(aMaterial.mPhongReflectance);
 }
Ejemplo n.º 6
0
 float AlbedoDiffuse(Material aMaterial)
 {
     return Luminance(aMaterial.mDiffuseReflectance);
 }
Ejemplo n.º 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));
            }
        }