Exemplo n.º 1
0
        public Color getIrradiance(ShadingState state, Color diffuseReflectance)
        {
            OrthoNormalBasis onb    = state.getBasis();
            Vector3          w      = new Vector3();
            Color            result = Color.black();

            for (int i = 0; i < samples; i++)
            {
                float xi       = (float)state.getRandom(i, 0, samples);
                float xj       = (float)state.getRandom(i, 1, samples);
                float phi      = (float)(2 * Math.PI * xi);
                float cosPhi   = (float)Math.Cos(phi);
                float sinPhi   = (float)Math.Sin(phi);
                float sinTheta = (float)Math.Sqrt(xj);
                float cosTheta = (float)Math.Sqrt(1.0f - xj);
                w.x = cosPhi * sinTheta;
                w.y = sinPhi * sinTheta;
                w.z = cosTheta;
                onb.transform(w);
                Ray r = new Ray(state.getPoint(), w);
                r.setMax(maxDist);
                result.add(Color.blend(bright, dark, state.traceShadow(r)));
            }
            return(result.mul((float)Math.PI / samples));
        }
Exemplo n.º 2
0
        public void ScatterPhoton(ShadingState state, Color power)
        {
            Color diffuse;

            // make sure we are on the right side of the material
            if (Vector3.dot(state.getNormal(), state.getRay().getDirection()) > 0.0)
            {
                state.getNormal().negate();
                state.getGeoNormal().negate();
            }
            diffuse = Color.GRAY;
            state.storePhoton(state.getRay().getDirection(), power, diffuse);
            float  avg = diffuse.getAverage();
            double rnd = state.getRandom(0, 0, 1);

            if (rnd < avg)
            {
                // photon is scattered
                power.mul(diffuse).mul(1.0f / avg);
                OrthoNormalBasis onb = state.getBasis();
                double           u   = 2 * Math.PI * rnd / avg;
                double           v   = state.getRandom(0, 1, 1);
                float            s   = (float)Math.Sqrt(v);
                float            s1  = (float)Math.Sqrt(1.0 - v);
                Vector3          w   = new Vector3((float)Math.Cos(u) * s, (float)Math.Sin(u) * s, s1);
                w = onb.transform(w, new Vector3());
                state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
            }
        }
Exemplo n.º 3
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Instance parent = state.getInstance();
            // get local point
            Point3 p = state.transformWorldToObject(state.getPoint());
            // compute local normal
            float deriv = p.x * p.x + p.y * p.y + p.z * p.z - ri2 - ro2;

            state.getNormal().set(p.x * deriv, p.y * deriv, p.z * deriv + 2 * ro2 * p.z);
            state.getNormal().normalize();

            double phi   = Math.Asin(MathUtils.clamp(p.z / ri, -1, 1));
            double theta = Math.Atan2(p.y, p.x);

            if (theta < 0)
            {
                theta += 2 * Math.PI;
            }
            state.getUV().x = (float)(theta / (2 * Math.PI));
            state.getUV().y = (float)((phi + Math.PI / 2) / Math.PI);
            state.setShader(parent.getShader(0));
            state.setModifier(parent.getModifier(0));
            // into world space
            Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());

            state.getNormal().set(worldNormal);
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            // make basis in world space
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
        }
Exemplo n.º 4
0
        /**
         * Ambient occlusion routine, returns a value between bright and dark
         * depending on the amount of geometric occlusion in the scene.
         *
         * @param samples number of sample rays
         * @param maxDist maximum Length of the rays
         * @param bright color when nothing is occluded
         * @param dark color when fully occluded
         * @return occlusion color
         */
        public Color occlusion(int samples, float maxDist, Color bright, Color dark)
        {
            if (n == null)
            {
                // in case we got called on a geometry without orientation
                return(bright);
            }
            // make sure we are on the right side of the material
            faceforward();
            OrthoNormalBasis onb    = getBasis();
            Vector3          w      = new Vector3();
            Color            result = Color.black();

            for (int i = 0; i < samples; i++)
            {
                float xi       = (float)getRandom(i, 0, samples);
                float xj       = (float)getRandom(i, 1, samples);
                float phi      = (float)(2 * Math.PI * xi);
                float cosPhi   = (float)Math.Cos(phi);
                float sinPhi   = (float)Math.Sin(phi);
                float sinTheta = (float)Math.Sqrt(xj);
                float cosTheta = (float)Math.Sqrt(1.0f - xj);
                w.x = cosPhi * sinTheta;
                w.y = sinPhi * sinTheta;
                w.z = cosTheta;
                onb.transform(w);
                Ray r = new Ray(p, w);
                r.setMax(maxDist);
                result.add(Color.blend(bright, dark, traceShadow(r)));
            }
            return(result.mul(1.0f / samples));
        }
Exemplo n.º 5
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            Instance i = state.getInstance();

            state.getRay().getPoint(state.getPoint());
            Ray     r = state.getRay();
            IShader s = i.getShader(0);

            state.setShader(s != null ? s : this);
            int primID = state.getPrimitiveID();
            int hair   = primID / numSegments;
            int line   = primID % numSegments;
            int vRoot  = hair * 3 * (numSegments + 1);
            int v0     = vRoot + line * 3;

            // tangent vector
            Vector3 v = getTangent(line, v0, state.getV());

            v = state.transformVectorObjectToWorld(v);
            state.setBasis(OrthoNormalBasis.makeFromWV(v, new Vector3(-r.dx, -r.dy, -r.dz)));
            state.getBasis().swapVW();
            // normal
            state.getNormal().set(0, 0, 1);
            state.getBasis().transform(state.getNormal());
            state.getGeoNormal().set(state.getNormal());

            state.getUV().set(0, (line + state.getV()) / numSegments);
        }
Exemplo n.º 6
0
        private float brdf(Vector3 i, Vector3 o, OrthoNormalBasis basis)
        {
            float fr = 4 * (float)Math.PI * alphaX * alphaY;
            float p  = basis.untransformZ(i) * basis.untransformZ(o);

            if (p > 0)
            {
                fr *= (float)Math.Sqrt(p);
            }
            else
            {
                fr = 0;
            }
            Vector3 h = Vector3.add(i, o, new Vector3());

            basis.untransform(h);
            float hx = h.x / alphaX;

            hx *= hx;
            float hy = h.y / alphaY;

            hy *= hy;
            float hn = h.z * h.z;

            if (fr > 0)
            {
                fr = (float)Math.Exp(-(hx + hy) / hn) / fr;
            }
            return(fr);
        }
Exemplo n.º 7
0
        public void getPhoton(double randX1, double randY1, double randX2, double randY2, Point3 p, Vector3 dir, Color power)
        {
            float z   = (float)(1 - 2 * randX2);
            float r   = (float)Math.Sqrt(Math.Max(0, 1 - z * z));
            float phi = (float)(2 * Math.PI * randY2);
            float x   = r * (float)Math.Cos(phi);
            float y   = r * (float)Math.Sin(phi);

            p.x = center.x + x * radius;
            p.y = center.y + y * radius;
            p.z = center.z + z * radius;
            OrthoNormalBasis basis = OrthoNormalBasis.makeFromW(new Vector3(x, y, z));

            phi = (float)(2 * Math.PI * randX1);
            float cosPhi   = (float)Math.Cos(phi);
            float sinPhi   = (float)Math.Sin(phi);
            float sinTheta = (float)Math.Sqrt(randY1);
            float cosTheta = (float)Math.Sqrt(1 - randY1);

            dir.x = cosPhi * sinTheta;
            dir.y = sinPhi * sinTheta;
            dir.z = cosTheta;
            basis.transform(dir);
            power.set(radiance);
            power.mul((float)(Math.PI * Math.PI * 4 * r2));
        }
Exemplo n.º 8
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Instance parent     = state.getInstance();
            Point3   localPoint = state.transformWorldToObject(state.getPoint());

            state.getNormal().set(localPoint.x, localPoint.y, 0);
            state.getNormal().normalize();

            float phi = (float)Math.Atan2(state.getNormal().y, state.getNormal().x);

            if (phi < 0)
            {
                phi += (float)(2.0 * Math.PI);
            }
            state.getUV().x = phi / (float)(2 * Math.PI);
            state.getUV().y = (localPoint.z + 1) * 0.5f;
            state.setShader(parent.getShader(0));
            state.setModifier(parent.getModifier(0));
            // into world space
            Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());
            Vector3 v           = state.transformVectorObjectToWorld(new Vector3(0, 0, 1));

            state.getNormal().set(worldNormal);
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            // compute basis in world space
            state.setBasis(OrthoNormalBasis.makeFromWV(state.getNormal(), v));
        }
Exemplo n.º 9
0
        public void scatterPhoton(ShadingState state, Color power)
        {
            Color diffuse, specular;

            // make sure we are on the right side of the material
            state.faceforward();
            diffuse  = getDiffuse(state);
            specular = getSpecular(state);
            state.storePhoton(state.getRay().getDirection(), power, diffuse);
            float  d   = diffuse.getAverage();
            float  r   = specular.getAverage();
            double rnd = state.getRandom(0, 0, 1);

            if (rnd < d)
            {
                // photon is scattered
                power.mul(diffuse).mul(1.0f / d);
                OrthoNormalBasis onb = state.getBasis();
                double           u   = 2 * Math.PI * rnd / d;
                double           v   = state.getRandom(0, 1, 1);
                float            s   = (float)Math.Sqrt(v);
                float            s1  = (float)Math.Sqrt(1.0 - v);
                Vector3          w   = new Vector3((float)Math.Cos(u) * s, (float)Math.Sin(u) * s, s1);
                w = onb.transform(w, new Vector3());
                state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
            }
            else if (rnd < d + r)
            {
                if (glossyness == 0)
                {
                    float cos = -Vector3.dot(state.getNormal(), state.getRay().getDirection());
                    power.mul(diffuse).mul(1.0f / d);
                    // photon is reflected
                    float   dn  = 2 * cos;
                    Vector3 dir = new Vector3();
                    dir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x;
                    dir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y;
                    dir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z;
                    state.traceReflectionPhoton(new Ray(state.getPoint(), dir), power);
                }
                else
                {
                    float dn = 2.0f * state.getCosND();
                    // reflected direction
                    Vector3 refDir = new Vector3();
                    refDir.x = (dn * state.getNormal().x) + state.getRay().dx;
                    refDir.y = (dn * state.getNormal().y) + state.getRay().dy;
                    refDir.z = (dn * state.getNormal().z) + state.getRay().dz;
                    power.mul(spec).mul(1.0f / r);
                    OrthoNormalBasis onb = state.getBasis();
                    double           u   = 2 * Math.PI * (rnd - r) / r;
                    double           v   = state.getRandom(0, 1, 1);
                    float            s   = (float)Math.Pow(v, 1 / ((1.0f / glossyness) + 1));
                    float            s1  = (float)Math.Sqrt(1 - s * s);
                    Vector3          w   = new Vector3((float)Math.Cos(u) * s1, (float)Math.Sin(u) * s1, s);
                    w = onb.transform(w, new Vector3());
                    state.traceReflectionPhoton(new Ray(state.getPoint(), w), power);
                }
            }
        }
Exemplo n.º 10
0
        private bool updateCameraMatrix(int index, ParameterList pl)
        {
            string offset = index < 0 ? "" : string.Format("[{0}]", index);

            if (index < 0)
            {
                index = 0;
            }
            Matrix4 transform = pl.getMatrix(string.Format("transform{0}", offset), null);

            if (transform == null)
            {
                // no transform was specified, check eye/target/up
                Point3  eye    = pl.getPoint(string.Format("eye{0}", offset), null);
                Point3  target = pl.getPoint(string.Format("target{0}", offset), null);
                Vector3 up     = pl.getVector(string.Format("up{0}", offset), null);
                if (eye != null && target != null && up != null)
                {
                    c2w[index] = Matrix4.fromBasis(OrthoNormalBasis.makeFromWV(Point3.sub(eye, target, new Vector3()), up));
                    c2w[index] = Matrix4.translation(eye.x, eye.y, eye.z).multiply(c2w[index]);
                }
                else
                {
                    // the matrix for this index was not specified
                    // return an error, unless this is a regular update
                    return(offset.Length == 0);
                }
            }
            else
            {
                c2w[index] = transform;
            }
            return(true);
        }
Exemplo n.º 11
0
 /**
  * Create objects needed for surface shading: point, normal, texture
  * coordinates and basis.
  */
 public void init()
 {
     p     = new Point3();
     n     = new Vector3();
     tex   = new Point2();
     ng    = new Vector3();
     basis = null;
 }
Exemplo n.º 12
0
 public SunSkyLight()
 {
     numSkySamples = 64;
     sunDirWorld   = new Vector3(1, 1, 1);
     turbidity     = 6;
     basis         = OrthoNormalBasis.makeFromWV(new Vector3(0, 0, 1), new Vector3(0, 1, 0));
     initSunSky();
 }
Exemplo n.º 13
0
 private void updateBasis(Vector3 center, Vector3 up)
 {
     if (center != null && up != null)
     {
         basis = OrthoNormalBasis.makeFromWV(center, up);
         basis.swapWU();
         basis.flipV();
     }
 }
Exemplo n.º 14
0
 public SunSkyLight()
 {
     numSkySamples   = 64;
     sunDirWorld     = new Vector3(1, 1, 1);
     turbidity       = 6;
     basis           = OrthoNormalBasis.makeFromWV(new Vector3(0, 0, 1), new Vector3(0, 1, 0));
     groundExtendSky = true;
     groundColor     = Color.BLACK;
     initSunSky();
 }
Exemplo n.º 15
0
 public DirectionalSpotlight()
 {
     src = new Point3(0, 0, 0);
     dir = new Vector3(0, 0, -1);
     dir.normalize();
     basis    = OrthoNormalBasis.makeFromW(dir);
     r        = 1;
     r2       = r * r;
     radiance = Color.WHITE;
 }
Exemplo n.º 16
0
        public Vector3 getBump(float x, float y, OrthoNormalBasis basis, float scale)
        {
            Bitmap bitmap = getBitmap();
            float  dx     = 1.0f / bitmap.getWidth();
            float  dy     = 1.0f / bitmap.getHeight();
            float  b0     = getPixel(x, y).getLuminance();
            float  bx     = getPixel(x + dx, y).getLuminance();
            float  by     = getPixel(x, y + dy).getLuminance();

            return(basis.transform(new Vector3(scale * (b0 - bx), scale * (b0 - by), 1)).normalize());
        }
Exemplo n.º 17
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     src = pl.getPoint("source", src);
     dir = pl.getVector("dir", dir);
     dir.normalize();
     r        = pl.getFloat("radius", r);
     basis    = OrthoNormalBasis.makeFromW(dir);
     r2       = r * r;
     radiance = pl.getColor("radiance", radiance);
     return(true);
 }
Exemplo n.º 18
0
        /**
         * Computes a phong specular response to the current light samples and
         * global illumination.
         *
         * @param spec specular color
         * @param power phong exponent
         * @param numRays number of glossy rays to trace
         * @return shaded color
         */
        public Color specularPhong(Color spec, float power, int numRays)
        {
            // integrate a phong specular function
            Color lr = Color.black();

            if (!includeSpecular || spec.isBlack())
            {
                return(lr);
            }
            // reflected direction
            float   dn     = 2 * cosND;
            Vector3 refDir = new Vector3();

            refDir.x = (dn * n.x) + r.dx;
            refDir.y = (dn * n.y) + r.dy;
            refDir.z = (dn * n.z) + r.dz;
            // direct lighting
            foreach (LightSample sample in this)
            {
                float cosNL = sample.dot(n);
                float cosLR = sample.dot(refDir);
                if (cosLR > 0)
                {
                    lr.madd(cosNL * (float)Math.Pow(cosLR, power), sample.getSpecularRadiance());
                }
            }
            // indirect lighting
            if (numRays > 0)
            {
                int numSamples       = getDepth() == 0 ? numRays : 1;
                OrthoNormalBasis onb = OrthoNormalBasis.makeFromW(refDir);
                float            mul = (2.0f * (float)Math.PI / (power + 1)) / numSamples;
                for (int i = 0; i < numSamples; i++)
                {
                    // specular indirect lighting
                    double  r1 = getRandom(i, 0, numSamples);
                    double  r2 = getRandom(i, 1, numSamples);
                    double  u  = 2 * Math.PI * r1;
                    double  s  = (float)Math.Pow(r2, 1 / (power + 1));
                    double  s1 = (float)Math.Sqrt(1 - s * s);
                    Vector3 w  = new Vector3((float)(Math.Cos(u) * s1), (float)(Math.Sin(u) * s1), (float)s);
                    w = onb.transform(w, new Vector3());
                    float wn = Vector3.dot(w, n);
                    if (wn > 0)
                    {
                        lr.madd(wn * mul, traceGlossy(new Ray(p, w), i));
                    }
                }
            }
            lr.mul(spec).mul((power + 2) / (2.0f * (float)Math.PI));
            return(lr);
        }
Exemplo n.º 19
0
 protected Camera(Point3D eye, Point3D lookAt, Vector3D up, float fov, float resX, float resY)
 {
     this.ResX   = resX;
     this.ResY   = resY;
     this.aspect = resX / resY;
     this.eye    = eye;
     this.Fov    = fov;
     this.up     = up;
     this.LookAt = lookAt;
     this.basis  = OrthoNormalBasis.MakeFromWV(eye - lookAt, up);
     this.au     = (float)Math.Tan(fov * 0.5f);
     this.av     = this.au * 1.0f / this.aspect;
 }
Exemplo n.º 20
0
        public Vector3 getBump(float x, float y, OrthoNormalBasis basis, float scale)
        {
            Bitmap bitmap = getBitmap();

            if (bitmap == null)
            {
                return(basis.transform(new Vector3(0, 0, 1)));
            }
            float dx = 1.0f / (bitmap.Width - 1);
            float dy = 1.0f / (bitmap.Height - 1);
            float b0 = getPixel(x, y).getLuminance();
            float bx = getPixel(x + dx, y).getLuminance();
            float by = getPixel(x, y + dy).getLuminance();

            return(basis.transform(new Vector3(scale * (bx - b0) / dx, scale * (by - b0) / dy, 1)).normalize());
        }
Exemplo n.º 21
0
    public Camera(Vec3 origin, Vec3 lookAt, Vec3 up, int width, int height, float verticalFov)
    {
        this.width       = new SpecializedValue <int>(width);
        this.height      = new SpecializedValue <int>(height);
        this.verticalFov = verticalFov;
        this.origin      = origin;
        this.lookAt      = lookAt;
        this.up          = up;

        axis = OrthoNormalBasis.fromZY(Vec3.unitVector(lookAt - origin), up);

        aspectRatio      = ((float)width / (float)height);
        cameraPlaneDist  = 1.0f / XMath.Tan(verticalFov * XMath.PI / 360.0f);
        reciprocalHeight = 1.0f / height;
        reciprocalWidth  = 1.0f / width;
    }
Exemplo n.º 22
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Instance parent      = state.getInstance();
            Vector3  worldNormal = state.transformNormalObjectToWorld(normal);

            state.getNormal().set(worldNormal);
            state.getGeoNormal().set(worldNormal);
            state.setShader(parent.getShader(0));
            state.setModifier(parent.getModifier(0));
            Point3 p = state.transformWorldToObject(state.getPoint());
            float  hu, hv;

            switch (k)
            {
            case 0:
            {
                hu = p.y;
                hv = p.z;
                break;
            }

            case 1:
            {
                hu = p.z;
                hv = p.x;
                break;
            }

            case 2:
            {
                hu = p.x;
                hv = p.y;
                break;
            }

            default:
                hu = hv = 0;
                break;
            }
            state.getUV().x = hu * bnu + hv * bnv + bnd;
            state.getUV().y = hu * cnu + hv * cnv + cnd;
            state.setBasis(OrthoNormalBasis.makeFromW(normal));
        }
Exemplo n.º 23
0
        public void scatterPhoton(ShadingState state, Color power)
        {
            // make sure we are on the right side of the material
            state.faceforward();
            Color d = getDiffuse(state);

            state.storePhoton(state.getRay().getDirection(), power, d);
            float  avgD = d.getAverage();
            float  avgS = spec.getAverage();
            double rnd  = state.getRandom(0, 0, 1);

            if (rnd < avgD)
            {
                // photon is scattered diffusely
                power.mul(d).mul(1.0f / avgD);
                OrthoNormalBasis onb = state.getBasis();
                double           u   = 2 * Math.PI * rnd / avgD;
                double           v   = state.getRandom(0, 1, 1);
                float            s   = (float)Math.Sqrt(v);
                float            s1  = (float)Math.Sqrt(1.0f - v);
                Vector3          w   = new Vector3((float)Math.Cos(u) * s, (float)Math.Sin(u) * s, s1);
                w = onb.transform(w, new Vector3());
                state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
            }
            else if (rnd < avgD + avgS)
            {
                // photon is scattered specularly
                float dn = 2.0f * state.getCosND();
                // reflected direction
                Vector3 refDir = new Vector3();
                refDir.x = (dn * state.getNormal().x) + state.getRay().dx;
                refDir.y = (dn * state.getNormal().y) + state.getRay().dy;
                refDir.z = (dn * state.getNormal().z) + state.getRay().dz;
                power.mul(spec).mul(1.0f / avgS);
                OrthoNormalBasis onb = state.getBasis();
                double           u   = 2 * Math.PI * (rnd - avgD) / avgS;
                double           v   = state.getRandom(0, 1, 1);
                float            s   = (float)Math.Pow(v, 1 / (this.power + 1));
                float            s1  = (float)Math.Sqrt(1 - s * s);
                Vector3          w   = new Vector3((float)Math.Cos(u) * s1, (float)Math.Sin(u) * s1, s);
                w = onb.transform(w, new Vector3());
                state.traceReflectionPhoton(new Ray(state.getPoint(), w), power);
            }
        }
Exemplo n.º 24
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Instance parent = state.getInstance();
            Vector3  normal;

            switch (state.getPrimitiveID())
            {
            case 0:
                normal = new Vector3(-1, 0, 0);
                break;

            case 1:
                normal = new Vector3(1, 0, 0);
                break;

            case 2:
                normal = new Vector3(0, -1, 0);
                break;

            case 3:
                normal = new Vector3(0, 1, 0);
                break;

            case 4:
                normal = new Vector3(0, 0, -1);
                break;

            case 5:
                normal = new Vector3(0, 0, 1);
                break;

            default:
                normal = new Vector3(0, 0, 0);
                break;
            }
            state.getNormal().set(state.transformNormalObjectToWorld(normal));
            state.getGeoNormal().set(state.getNormal());
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
            state.setShader(parent.getShader(0));
            state.setModifier(parent.getModifier(0));
        }
Exemplo n.º 25
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            int n = state.getPrimitiveID();

            /*
             *
             *
             * switch (n)
             * {
             *  case 0:
             *      state.getNormal().set(new Vector3(1, 0, 0));
             *      break;
             *  case 1:
             *      state.getNormal().set(new Vector3(-1, 0, 0));
             *      break;
             *  case 2:
             *      state.getNormal().set(new Vector3(0, 1, 0));
             *      break;
             *  case 3:
             *      state.getNormal().set(new Vector3(0, -1, 0));
             *      break;
             *  case 4:
             *      state.getNormal().set(new Vector3(0, 0, 1));
             *      break;
             *  case 5:
             *      state.getNormal().set(new Vector3(0, 0, -1));
             *      break;
             *  default:
             *      state.getNormal().set(new Vector3(0, 0, 0));
             *      break;
             * }
             *
             */

            state.getNormal().set(normalVectors[n]);

            state.getGeoNormal().set(state.getNormal());
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
            state.setShader(state.getInstance().getShader(0));
            state.setModifier(state.getInstance().getModifier(0));
        }
Exemplo n.º 26
0
        public bool update(ParameterList pl, SunflowAPI api)
        {
            Vector3 up   = pl.getVector("up", null);
            Vector3 east = pl.getVector("east", null);

            if (up != null && east != null)
            {
                basis = OrthoNormalBasis.makeFromWV(up, east);
            }
            else if (up != null)
            {
                basis = OrthoNormalBasis.makeFromW(up);
            }
            numSkySamples = pl.getInt("samples", numSkySamples);
            sunDirWorld   = pl.getVector("sundir", sunDirWorld);
            turbidity     = pl.getFloat("turbidity", turbidity);
            // recompute model
            initSunSky();
            return(true);
        }
Exemplo n.º 27
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Instance parent = state.getInstance();
            Point3   n      = state.transformWorldToObject(state.getPoint());

            state.getNormal().set(n.x * (2 * n.x * n.x - 1), n.y * (2 * n.y * n.y - 1), n.z * (2 * n.z * n.z - 1));
            state.getNormal().normalize();
            state.setShader(parent.getShader(0));
            state.setModifier(parent.getModifier(0));
            // into world space
            Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());

            state.getNormal().set(worldNormal);
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            // create basis in world space
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
        }
Exemplo n.º 28
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            int n = state.getPrimitiveID();

            switch (n)
            {
            case 0:
                state.getNormal().set(new Vector3(1, 0, 0));
                break;

            case 1:
                state.getNormal().set(new Vector3(-1, 0, 0));
                break;

            case 2:
                state.getNormal().set(new Vector3(0, 1, 0));
                break;

            case 3:
                state.getNormal().set(new Vector3(0, -1, 0));
                break;

            case 4:
                state.getNormal().set(new Vector3(0, 0, 1));
                break;

            case 5:
                state.getNormal().set(new Vector3(0, 0, -1));
                break;

            default:
                state.getNormal().set(new Vector3(0, 0, 0));
                break;
            }
            state.getGeoNormal().set(state.getNormal());
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
            state.setShader(state.getInstance().getShader(0));
            state.setModifier(state.getInstance().getModifier(0));
        }
Exemplo n.º 29
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Instance parent     = state.getInstance();
            Point3   localPoint = state.transformWorldToObject(state.getPoint());

            float cx = state.getU();
            float cy = state.getV();
            float cz = state.getW();

            state.getNormal().set(localPoint.x - cx, localPoint.y - cy, localPoint.z - cz);
            state.getNormal().normalize();

            float phi = (float)Math.Atan2(state.getNormal().y, state.getNormal().x);

            if (phi < 0)
            {
                phi += (float)(2.0 * Math.PI);
            }
            float theta = (float)Math.Acos(state.getNormal().z);

            state.getUV().y = theta / (float)Math.PI;
            state.getUV().x = phi / (float)(2 * Math.PI);
            Vector3 v       = new Vector3();

            v.x = -2 * (float)Math.PI * state.getNormal().y;
            v.y = 2 * (float)Math.PI * state.getNormal().x;
            v.z = 0;
            state.setShader(parent.getShader(0));
            state.setModifier(parent.getModifier(0));
            // into world space
            Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());

            v = state.transformVectorObjectToWorld(v);
            state.getNormal().set(worldNormal);
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            // compute basis in world space
            state.setBasis(OrthoNormalBasis.makeFromWV(state.getNormal(), v));
        }
Exemplo n.º 30
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Instance parent = state.getInstance();
            float    u      = state.getU();
            float    v      = state.getV();

            float[] bu  = bernstein(u);
            float[] bdu = bernsteinDeriv(u);
            float[] bv  = bernstein(v);
            float[] bdv = bernsteinDeriv(v);
            getPatchPoint(u, v, patches[state.getPrimitiveID()], bu, bv, bdu, bdv, new Point3(), state.getNormal());
            state.getNormal().set(parent.transformNormalObjectToWorld(state.getNormal()));
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            state.getUV().set(u, v);
            state.setShader(parent.getShader(0));
            state.setModifier(parent.getModifier(0));
            // FIXME: use actual derivatives to create basis
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
        }