BumpMappingModifier.java :  » Graphic-Library » Sunflow-0.07.2 » org » sunflow » core » modifiers » Java Open Source

Java Open Source » Graphic Library » Sunflow 0.07.2 
Sunflow 0.07.2 » org » sunflow » core » modifiers » BumpMappingModifier.java
package org.sunflow.core.modifiers;

import org.sunflow.SunflowAPI;
import org.sunflow.core.Modifier;
import org.sunflow.core.ParameterList;
import org.sunflow.core.ShadingState;
import org.sunflow.core.Texture;
import org.sunflow.core.TextureCache;
import org.sunflow.math.OrthoNormalBasis;

public class BumpMappingModifier implements Modifier {
    private Texture bumpTexture;
    private float scale;

    public BumpMappingModifier() {
        bumpTexture = null;
        scale = 1;
    }

    public boolean update(ParameterList pl, SunflowAPI api) {
        String filename = pl.getString("texture", null);
        if (filename != null)
            bumpTexture = TextureCache.getTexture(api.resolveTextureFilename(filename), true);
        scale = pl.getFloat("scale", scale);
        return bumpTexture != null;
    }

    public void modify(ShadingState state) {
        // apply bump
        state.getNormal().set(bumpTexture.getBump(state.getUV().x, state.getUV().y, state.getBasis(), scale));
        state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.