예제 #1
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));
        }
예제 #2
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));
        }