Search in sources :

Example 1 with DefineList

use of com.jme3.shader.DefineList in project jmonkeyengine by jMonkeyEngine.

the class StaticPassLightingLogic method makeCurrent.

@Override
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager, EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {
    // TODO: if it ever changes that render isn't called
    // right away with the same geometry after makeCurrent, it would be
    // a problem.
    // Do a radix sort.
    tempDirLights.clear();
    tempPointLights.clear();
    tempSpotLights.clear();
    for (Light light : lights) {
        switch(light.getType()) {
            case Directional:
                tempDirLights.add((DirectionalLight) light);
                break;
            case Point:
                tempPointLights.add((PointLight) light);
                break;
            case Spot:
                tempSpotLights.add((SpotLight) light);
                break;
        }
    }
    defines.set(numDirLightsDefineId, tempDirLights.size());
    defines.set(numPointLightsDefineId, tempPointLights.size());
    defines.set(numSpotLightsDefineId, tempSpotLights.size());
    return techniqueDef.getShader(assetManager, rendererCaps, defines);
}
Also used : DirectionalLight(com.jme3.light.DirectionalLight) SpotLight(com.jme3.light.SpotLight) Light(com.jme3.light.Light) PointLight(com.jme3.light.PointLight)

Example 2 with DefineList

use of com.jme3.shader.DefineList in project jmonkeyengine by jMonkeyEngine.

the class ShaderCheck method checkMatDef.

private static void checkMatDef(String matdefName) {
    MaterialDef def = (MaterialDef) assetManager.loadAsset(matdefName);
    EnumSet<Caps> rendererCaps = EnumSet.noneOf(Caps.class);
    rendererCaps.add(Caps.GLSL100);
    for (TechniqueDef techDef : def.getTechniqueDefs(TechniqueDef.DEFAULT_TECHNIQUE_NAME)) {
        DefineList defines = techDef.createDefineList();
        Shader shader = techDef.getShader(assetManager, rendererCaps, defines);
        for (Validator validator : validators) {
            StringBuilder sb = new StringBuilder();
            validator.validate(shader, sb);
            System.out.println("==== Validator: " + validator.getName() + " " + validator.getInstalledVersion() + " ====");
            System.out.println(sb.toString());
        }
    }
    throw new UnsupportedOperationException();
}
Also used : DefineList(com.jme3.shader.DefineList) MaterialDef(com.jme3.material.MaterialDef) Shader(com.jme3.shader.Shader) Caps(com.jme3.renderer.Caps) TechniqueDef(com.jme3.material.TechniqueDef)

Example 3 with DefineList

use of com.jme3.shader.DefineList in project jmonkeyengine by jMonkeyEngine.

the class MaterialMatParamTest method outDefines.

private void outDefines(Define... expectedDefinesArray) {
    StringBuilder expectedDefineSource = new StringBuilder();
    for (Define define : expectedDefinesArray) {
        expectedDefineSource.append(define.toString());
    }
    if (!evaluated) {
        evaluateTechniqueDef();
    }
    Material mat = geometry.getMaterial();
    Technique tech = mat.getActiveTechnique();
    TechniqueDef def = tech.getDef();
    DefineList actualDefines = tech.getDynamicDefines();
    String[] defineNames = def.getDefineNames();
    VarType[] defineTypes = def.getDefineTypes();
    String actualDefineSource = actualDefines.generateSource(Arrays.asList(defineNames), Arrays.asList(defineTypes));
    assertEquals(expectedDefineSource.toString(), actualDefineSource);
}
Also used : DefineList(com.jme3.shader.DefineList) VarType(com.jme3.shader.VarType)

Example 4 with DefineList

use of com.jme3.shader.DefineList in project jmonkeyengine by jMonkeyEngine.

the class TechniqueDef method loadShader.

private Shader loadShader(AssetManager assetManager, EnumSet<Caps> rendererCaps, DefineList defines) {
    StringBuilder sb = new StringBuilder();
    sb.append(shaderPrologue);
    defines.generateSource(sb, defineNames, defineTypes);
    String definesSourceCode = sb.toString();
    Shader shader;
    if (isUsingShaderNodes()) {
        ShaderGenerator shaderGenerator = assetManager.getShaderGenerator(rendererCaps);
        if (shaderGenerator == null) {
            throw new UnsupportedOperationException("ShaderGenerator was not initialized, " + "make sure assetManager.getGenerator(caps) has been called");
        }
        shaderGenerator.initialize(this);
        shader = shaderGenerator.generateShader(definesSourceCode);
    } else {
        shader = new Shader();
        for (ShaderType type : ShaderType.values()) {
            String language = shaderLanguages.get(type);
            String shaderSourceAssetName = shaderNames.get(type);
            if (language == null || shaderSourceAssetName == null) {
                continue;
            }
            String shaderSourceCode = (String) assetManager.loadAsset(shaderSourceAssetName);
            shader.addSource(type, shaderSourceAssetName, shaderSourceCode, definesSourceCode, language);
        }
    }
    if (getWorldBindings() != null) {
        for (UniformBinding binding : getWorldBindings()) {
            shader.addUniformBinding(binding);
        }
    }
    return shader;
}
Also used : ShaderType(com.jme3.shader.Shader.ShaderType)

Aggregations

DefineList (com.jme3.shader.DefineList)2 DirectionalLight (com.jme3.light.DirectionalLight)1 Light (com.jme3.light.Light)1 PointLight (com.jme3.light.PointLight)1 SpotLight (com.jme3.light.SpotLight)1 MaterialDef (com.jme3.material.MaterialDef)1 TechniqueDef (com.jme3.material.TechniqueDef)1 Caps (com.jme3.renderer.Caps)1 Shader (com.jme3.shader.Shader)1 ShaderType (com.jme3.shader.Shader.ShaderType)1 VarType (com.jme3.shader.VarType)1