Search in sources :

Example 1 with Shader

use of org.sunflow.core.Shader in project joons-renderer by joonhyublee.

the class Hair method prepareShadingState.

@Override
public void prepareShadingState(ShadingState state) {
    state.init();
    Instance i = state.getInstance();
    state.getRay().getPoint(state.getPoint());
    Ray r = state.getRay();
    Shader 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);
}
Also used : Instance(org.sunflow.core.Instance) Vector3(org.sunflow.math.Vector3) Ray(org.sunflow.core.Ray) Shader(org.sunflow.core.Shader)

Example 2 with Shader

use of org.sunflow.core.Shader in project joons-renderer by joonhyublee.

the class SunflowAPI method render.

@Override
public final void render(String optionsName, Display display) {
    renderObjects.updateScene(scene);
    Options opt = lookupOptions(optionsName);
    if (opt == null) {
        opt = new Options();
    }
    scene.setCamera(lookupCamera(opt.getString("camera", null)));
    // shader override
    String shaderOverrideName = opt.getString("override.shader", "none");
    boolean overridePhotons = opt.getBoolean("override.photons", false);
    if (shaderOverrideName.equals("none")) {
        scene.setShaderOverride(null, false);
    } else {
        Shader shader = lookupShader(shaderOverrideName);
        if (shader == null) {
            UI.printWarning(Module.API, "Unable to find shader \"%s\" for override, disabling", shaderOverrideName);
        }
        scene.setShaderOverride(shader, overridePhotons);
    }
    // baking
    String bakingInstanceName = opt.getString("baking.instance", null);
    if (bakingInstanceName != null) {
        Instance bakingInstance = lookupInstance(bakingInstanceName);
        if (bakingInstance == null) {
            UI.printError(Module.API, "Unable to bake instance \"%s\" - not found", bakingInstanceName);
            return;
        }
        scene.setBakingInstance(bakingInstance);
    } else {
        scene.setBakingInstance(null);
    }
    ImageSampler sampler = PluginRegistry.imageSamplerPlugins.createObject(opt.getString("sampler", "bucket"));
    scene.render(opt, sampler, display);
}
Also used : Options(org.sunflow.core.Options) Instance(org.sunflow.core.Instance) ImageSampler(org.sunflow.core.ImageSampler) Shader(org.sunflow.core.Shader)

Example 3 with Shader

use of org.sunflow.core.Shader in project joons-renderer by joonhyublee.

the class SunflowAPI method shader.

@Override
public final void shader(String name, String shaderType) {
    if (!isIncremental(shaderType)) {
        // we are declaring a shader for the first time
        if (renderObjects.has(name)) {
            UI.printError(Module.API, "Unable to declare shader \"%s\", name is already in use", name);
            parameterList.clear(true);
            return;
        }
        Shader shader = PluginRegistry.shaderPlugins.createObject(shaderType);
        if (shader == null) {
            UI.printError(Module.API, "Unable to create shader of type \"%s\"", shaderType);
            return;
        }
        renderObjects.put(name, shader);
    }
    // update existing shader (only if it is valid)
    if (lookupShader(name) != null) {
        update(name);
    } else {
        UI.printError(Module.API, "Unable to update shader \"%s\" - shader object was not found", name);
        parameterList.clear(true);
    }
}
Also used : Shader(org.sunflow.core.Shader)

Example 4 with Shader

use of org.sunflow.core.Shader in project joons-renderer by joonhyublee.

the class RenderObjectMap method remove.

final void remove(String name) {
    RenderObjectHandle obj = renderObjects.get(name);
    if (obj == null) {
        UI.printWarning(Module.API, "Unable to remove \"%s\" - object was not defined yet");
        return;
    }
    UI.printDetailed(Module.API, "Removing object \"%s\"", name);
    renderObjects.remove(name);
    // references to the old object still around
    switch(obj.type) {
        case SHADER:
            Shader s = obj.getShader();
            for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
                Instance i = e.getValue().getInstance();
                if (i != null) {
                    UI.printWarning(Module.API, "Removing shader \"%s\" from instance \"%s\"", name, e.getKey());
                    i.removeShader(s);
                }
            }
            break;
        case MODIFIER:
            Modifier m = obj.getModifier();
            for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
                Instance i = e.getValue().getInstance();
                if (i != null) {
                    UI.printWarning(Module.API, "Removing modifier \"%s\" from instance \"%s\"", name, e.getKey());
                    i.removeModifier(m);
                }
            }
            break;
        case GEOMETRY:
            {
                Geometry g = obj.getGeometry();
                for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
                    Instance i = e.getValue().getInstance();
                    if (i != null && i.hasGeometry(g)) {
                        UI.printWarning(Module.API, "Removing instance \"%s\" because it referenced geometry \"%s\"", e.getKey(), name);
                        remove(e.getKey());
                    }
                }
                break;
            }
        case INSTANCE:
            rebuildInstanceList = true;
            break;
        case LIGHT:
            rebuildLightList = true;
            break;
        default:
            // no dependencies
            break;
    }
}
Also used : Geometry(org.sunflow.core.Geometry) Instance(org.sunflow.core.Instance) Shader(org.sunflow.core.Shader) FastHashMap(org.sunflow.util.FastHashMap) Modifier(org.sunflow.core.Modifier)

Aggregations

Shader (org.sunflow.core.Shader)4 Instance (org.sunflow.core.Instance)3 Geometry (org.sunflow.core.Geometry)1 ImageSampler (org.sunflow.core.ImageSampler)1 Modifier (org.sunflow.core.Modifier)1 Options (org.sunflow.core.Options)1 Ray (org.sunflow.core.Ray)1 Vector3 (org.sunflow.math.Vector3)1 FastHashMap (org.sunflow.util.FastHashMap)1