示例#1
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()));
        }
示例#2
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));
        }
示例#3
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));
        }
示例#4
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()));
 }
示例#5
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()));
        }
示例#6
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));
        }
示例#7
0
        public void modify(ShadingState state)
        {
            Point3 p = state.transformWorldToObject(state.getPoint());
            p.x *= size;
            p.y *= size;
            p.z *= size;
            Vector3 normal = state.transformNormalWorldToObject(state.getNormal());
            double f0 = f(p.x, p.y, p.z);
            double fx = f(p.x + .0001, p.y, p.z);
            double fy = f(p.x, p.y + .0001, p.z);
            double fz = f(p.x, p.y, p.z + .0001);

            normal.x -= scale * (float)((fx - f0) / .0001);
            normal.y -= scale * (float)((fy - f0) / .0001);
            normal.z -= scale * (float)((fz - f0) / .0001);
            normal.normalize();

            state.getNormal().set(state.transformNormalObjectToWorld(normal));
            state.getNormal().normalize();
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
        }
示例#8
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Point3 localPoint = state.transformWorldToObject(state.getPoint());

            localPoint.x -= particles[3 * state.getPrimitiveID() + 0];
            localPoint.y -= particles[3 * state.getPrimitiveID() + 1];
            localPoint.z -= particles[3 * state.getPrimitiveID() + 2];

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

            state.setShader(state.getInstance().getShader(0));
            state.setModifier(state.getInstance().getModifier(0));
            // into object space
            Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());
            state.getNormal().set(worldNormal);
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
        }
示例#9
0
        public void modify(ShadingState state)
        {
            Point3 p = state.transformWorldToObject(state.getPoint());

            p.x *= size;
            p.y *= size;
            p.z *= size;
            Vector3 normal = state.transformNormalWorldToObject(state.getNormal());
            double  f0     = f(p.x, p.y, p.z);
            double  fx     = f(p.x + .0001, p.y, p.z);
            double  fy     = f(p.x, p.y + .0001, p.z);
            double  fz     = f(p.x, p.y, p.z + .0001);

            normal.x -= scale * (float)((fx - f0) / .0001);
            normal.y -= scale * (float)((fy - f0) / .0001);
            normal.z -= scale * (float)((fz - f0) / .0001);
            normal.normalize();

            state.getNormal().set(state.transformNormalObjectToWorld(normal));
            state.getNormal().normalize();
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
        }
示例#10
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Point3 localPoint = state.transformWorldToObject(state.getPoint());

            localPoint.x -= particles[3 * state.getPrimitiveID() + 0];
            localPoint.y -= particles[3 * state.getPrimitiveID() + 1];
            localPoint.z -= particles[3 * state.getPrimitiveID() + 2];

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

            state.setShader(state.getInstance().getShader(0));
            state.setModifier(state.getInstance().getModifier(0));
            // into object space
            Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());

            state.getNormal().set(worldNormal);
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
        }
示例#11
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));
        }
示例#12
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Instance parent = state.getInstance();
            // compute local normal
            Point3 p    = state.transformWorldToObject(state.getPoint());
            float  gx1w = p.x - DELTA;
            float  gx1x = p.y;
            float  gx1y = p.z;
            float  gx1z = 0;
            float  gx2w = p.x + DELTA;
            float  gx2x = p.y;
            float  gx2y = p.z;
            float  gx2z = 0;

            float gy1w = p.x;
            float gy1x = p.y - DELTA;
            float gy1y = p.z;
            float gy1z = 0;
            float gy2w = p.x;
            float gy2x = p.y + DELTA;
            float gy2y = p.z;
            float gy2z = 0;

            float gz1w = p.x;
            float gz1x = p.y;
            float gz1y = p.z - DELTA;
            float gz1z = 0;
            float gz2w = p.x;
            float gz2x = p.y;
            float gz2y = p.z + DELTA;
            float gz2z = 0;

            for (int i = 0; i < maxIterations; i++)
            {
                {
                    // z = z*z + c
                    float nw = gx1w * gx1w - gx1x * gx1x - gx1y * gx1y - gx1z * gx1z + cw;
                    gx1x = 2 * gx1w * gx1x + cx;
                    gx1y = 2 * gx1w * gx1y + cy;
                    gx1z = 2 * gx1w * gx1z + cz;
                    gx1w = nw;
                }
                {
                    // z = z*z + c
                    float nw = gx2w * gx2w - gx2x * gx2x - gx2y * gx2y - gx2z * gx2z + cw;
                    gx2x = 2 * gx2w * gx2x + cx;
                    gx2y = 2 * gx2w * gx2y + cy;
                    gx2z = 2 * gx2w * gx2z + cz;
                    gx2w = nw;
                }
                {
                    // z = z*z + c
                    float nw = gy1w * gy1w - gy1x * gy1x - gy1y * gy1y - gy1z * gy1z + cw;
                    gy1x = 2 * gy1w * gy1x + cx;
                    gy1y = 2 * gy1w * gy1y + cy;
                    gy1z = 2 * gy1w * gy1z + cz;
                    gy1w = nw;
                }
                {
                    // z = z*z + c
                    float nw = gy2w * gy2w - gy2x * gy2x - gy2y * gy2y - gy2z * gy2z + cw;
                    gy2x = 2 * gy2w * gy2x + cx;
                    gy2y = 2 * gy2w * gy2y + cy;
                    gy2z = 2 * gy2w * gy2z + cz;
                    gy2w = nw;
                }
                {
                    // z = z*z + c
                    float nw = gz1w * gz1w - gz1x * gz1x - gz1y * gz1y - gz1z * gz1z + cw;
                    gz1x = 2 * gz1w * gz1x + cx;
                    gz1y = 2 * gz1w * gz1y + cy;
                    gz1z = 2 * gz1w * gz1z + cz;
                    gz1w = nw;
                }
                {
                    // z = z*z + c
                    float nw = gz2w * gz2w - gz2x * gz2x - gz2y * gz2y - gz2z * gz2z + cw;
                    gz2x = 2 * gz2w * gz2x + cx;
                    gz2y = 2 * gz2w * gz2y + cy;
                    gz2z = 2 * gz2w * gz2z + cz;
                    gz2w = nw;
                }
            }
            float   gradX = Length(gx2w, gx2x, gx2y, gx2z) - Length(gx1w, gx1x, gx1y, gx1z);
            float   gradY = Length(gy2w, gy2x, gy2y, gy2z) - Length(gy1w, gy1x, gy1y, gy1z);
            float   gradZ = Length(gz2w, gz2x, gz2y, gz2z) - Length(gz1w, gz1x, gz1y, gz1z);
            Vector3 n     = new Vector3(gradX, gradY, gradZ);

            state.getNormal().set(state.transformNormalObjectToWorld(n));
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));

            state.getPoint().x += state.getNormal().x *epsilon * 20;
            state.getPoint().y += state.getNormal().y *epsilon * 20;
            state.getPoint().z += state.getNormal().z *epsilon * 20;

            state.setShader(parent.getShader(0));
            state.setModifier(parent.getModifier(0));
        }
示例#13
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()));
        }
示例#14
0
        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Instance parent = state.getInstance();
            // compute local normal
            Point3 p = state.transformWorldToObject(state.getPoint());
            float gx1w = p.x - DELTA;
            float gx1x = p.y;
            float gx1y = p.z;
            float gx1z = 0;
            float gx2w = p.x + DELTA;
            float gx2x = p.y;
            float gx2y = p.z;
            float gx2z = 0;

            float gy1w = p.x;
            float gy1x = p.y - DELTA;
            float gy1y = p.z;
            float gy1z = 0;
            float gy2w = p.x;
            float gy2x = p.y + DELTA;
            float gy2y = p.z;
            float gy2z = 0;

            float gz1w = p.x;
            float gz1x = p.y;
            float gz1y = p.z - DELTA;
            float gz1z = 0;
            float gz2w = p.x;
            float gz2x = p.y;
            float gz2y = p.z + DELTA;
            float gz2z = 0;

            for (int i = 0; i < maxIterations; i++)
            {
                {
                    // z = z*z + c
                    float nw = gx1w * gx1w - gx1x * gx1x - gx1y * gx1y - gx1z * gx1z + cw;
                    gx1x = 2 * gx1w * gx1x + cx;
                    gx1y = 2 * gx1w * gx1y + cy;
                    gx1z = 2 * gx1w * gx1z + cz;
                    gx1w = nw;
                }
                {
                    // z = z*z + c
                    float nw = gx2w * gx2w - gx2x * gx2x - gx2y * gx2y - gx2z * gx2z + cw;
                    gx2x = 2 * gx2w * gx2x + cx;
                    gx2y = 2 * gx2w * gx2y + cy;
                    gx2z = 2 * gx2w * gx2z + cz;
                    gx2w = nw;
                }
                {
                    // z = z*z + c
                    float nw = gy1w * gy1w - gy1x * gy1x - gy1y * gy1y - gy1z * gy1z + cw;
                    gy1x = 2 * gy1w * gy1x + cx;
                    gy1y = 2 * gy1w * gy1y + cy;
                    gy1z = 2 * gy1w * gy1z + cz;
                    gy1w = nw;
                }
                {
                    // z = z*z + c
                    float nw = gy2w * gy2w - gy2x * gy2x - gy2y * gy2y - gy2z * gy2z + cw;
                    gy2x = 2 * gy2w * gy2x + cx;
                    gy2y = 2 * gy2w * gy2y + cy;
                    gy2z = 2 * gy2w * gy2z + cz;
                    gy2w = nw;
                }
                {
                    // z = z*z + c
                    float nw = gz1w * gz1w - gz1x * gz1x - gz1y * gz1y - gz1z * gz1z + cw;
                    gz1x = 2 * gz1w * gz1x + cx;
                    gz1y = 2 * gz1w * gz1y + cy;
                    gz1z = 2 * gz1w * gz1z + cz;
                    gz1w = nw;
                }
                {
                    // z = z*z + c
                    float nw = gz2w * gz2w - gz2x * gz2x - gz2y * gz2y - gz2z * gz2z + cw;
                    gz2x = 2 * gz2w * gz2x + cx;
                    gz2y = 2 * gz2w * gz2y + cy;
                    gz2z = 2 * gz2w * gz2z + cz;
                    gz2w = nw;
                }
            }
            float gradX = Length(gx2w, gx2x, gx2y, gx2z) - Length(gx1w, gx1x, gx1y, gx1z);
            float gradY = Length(gy2w, gy2x, gy2y, gy2z) - Length(gy1w, gy1x, gy1y, gy1z);
            float gradZ = Length(gz2w, gz2x, gz2y, gz2z) - Length(gz1w, gz1x, gz1y, gz1z);
            Vector3 n = new Vector3(gradX, gradY, gradZ);
            state.getNormal().set(state.transformNormalObjectToWorld(n));
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));

            state.getPoint().x += state.getNormal().x * epsilon * 20;
            state.getPoint().y += state.getNormal().y * epsilon * 20;
            state.getPoint().z += state.getNormal().z * epsilon * 20;

            state.setShader(parent.getShader(0));
            state.setModifier(parent.getModifier(0));
        }