File: NormalMapModifier.java

package info (click to toggle)
sunflow 0.07.2.svn396%2Bdfsg-14
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 11,164 kB
  • ctags: 4,980
  • sloc: lisp: 168,740; java: 25,216; cpp: 3,265; python: 2,058; ruby: 1,276; xml: 105; sh: 85; makefile: 62
file content (30 lines) | stat: -rw-r--r-- 1,053 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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.math.OrthoNormalBasis;

public class NormalMapModifier implements Modifier {
    private Texture normalMap;

    public NormalMapModifier() {
        normalMap = null;
    }

    public boolean update(ParameterList pl, SunflowAPI api) {
        String filename = pl.getString("texture", null);
        if (filename != null)
            // EP : Made texture cache local to a SunFlow API instance
            normalMap = api.getTextureCache().getTexture(api.resolveTextureFilename(filename), true);
        return normalMap != null;
    }

    public void modify(ShadingState state) {
        // apply normal map
        state.getNormal().set(normalMap.getNormal(state.getUV().x, state.getUV().y, state.getBasis()));
        state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
    }
}