Java Code Examples for com.jme3.renderer.Renderer#setShader()

The following examples show how to use com.jme3.renderer.Renderer#setShader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SinglePassLightingLogic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
    int nbRenderedLights = 0;
    Renderer renderer = renderManager.getRenderer();
    int batchSize = renderManager.getSinglePassLightBatchSize();
    if (lights.size() == 0) {
        updateLightListUniforms(shader, geometry, lights, batchSize, renderManager, 0);
        renderer.setShader(shader);
        renderMeshFromGeometry(renderer, geometry);
    } else {
        while (nbRenderedLights < lights.size()) {
            nbRenderedLights = updateLightListUniforms(shader, geometry, lights, batchSize, renderManager, nbRenderedLights);
            renderer.setShader(shader);
            renderMeshFromGeometry(renderer, geometry);
        }
    }
}
 
Example 2
Source File: StaticPassLightingLogic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
    Renderer renderer = renderManager.getRenderer();
    Matrix4f viewMatrix = renderManager.getCurrentCamera().getViewMatrix();
    updateLightListUniforms(viewMatrix, shader, lights);
    renderer.setShader(shader);
    renderMeshFromGeometry(renderer, geometry);
}
 
Example 3
Source File: Material.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Preloads this material for the given render manager.
 * <p>
 * Preloading the material can ensure that when the material is first
 * used for rendering, there won't be any delay since the material has
 * been already been setup for rendering.
 *
 * @param rm The render manager to preload for
 */
public void preload(RenderManager rm) {
    autoSelectTechnique(rm);

    Renderer r = rm.getRenderer();
    TechniqueDef techDef = technique.getDef();

    Collection<MatParam> params = paramValues.values();
    for (MatParam param : params) {
        if (param instanceof MatParamTexture) {
            MatParamTexture texParam = (MatParamTexture) param;
            r.setTexture(0, texParam.getTextureValue());
        } else {
            if (!techDef.isUsingShaders()) {
                continue;
            }

            technique.updateUniformParam(param.getName(),
                    param.getVarType(),
                    param.getValue(), true);
        }
    }

    Shader shader = technique.getShader();
    if (techDef.isUsingShaders()) {
        r.setShader(shader);
    }
}
 
Example 4
Source File: DefaultTechniqueDefLogic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
    Renderer renderer = renderManager.getRenderer();
    renderer.setShader(shader);
    renderMeshFromGeometry(renderer, geometry);
}
 
Example 5
Source File: Material.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Called by {@link RenderManager} to render the geometry by
 * using this material.
 *
 * @param geom The geometry to render
 * @param rm The render manager requesting the rendering
 */
public void render(Geometry geom, RenderManager rm) {
    autoSelectTechnique(rm);

    Renderer r = rm.getRenderer();

    TechniqueDef techDef = technique.getDef();
    r.setShaderWithoutUpdateUniforms(technique.getShader());
    if (techDef.getLightMode() == LightMode.MultiPass
            && geom.getWorldLightList().size() == 0) {
        return;
    }

    if (rm.getForcedRenderState() != null) {
        r.applyRenderState(rm.getForcedRenderState());
    } else {
        if (techDef.getRenderState() != null) {
            r.applyRenderState(techDef.getRenderState().copyMergedTo(additionalState, mergedRenderState));
        } else {
            r.applyRenderState(RenderState.DEFAULT.copyMergedTo(additionalState, mergedRenderState));
        }
    }

    boolean needReloadParams = false;
    if (technique.isNeedReload()) {
        technique.makeCurrent(def.getAssetManager(), paramValues);
        needReloadParams = true;
    }
    // update camera and world matrices
    // NOTE: setWorldTransform should have been called already
    if (techDef.isUsingShaders()) {
        // reset unchanged uniform flag
        clearUniformsSetByCurrent(technique.getShader());
        rm.updateUniformBindings(technique.getWorldBindUniforms());
    }

    // setup textures and uniforms
    for (int i = paramValues.size()-1; i >=0 ; i--) {
        MatParam param = paramValues.getValue(i);
        if (param != null) {
            param.apply(r, technique, i);
        }
    }

    Shader shader = technique.getShader();

    // send lighting information, if needed
    switch (techDef.getLightMode()) {
        case Disable:
            r.setLighting(null);
            break;
        case SinglePass:
            updateLightListUniforms(shader, geom, 4);
            break;
        case FixedPipeline:
            r.setLighting(geom.getWorldLightList());
            break;
        case MultiPass:
            // NOTE: Special case!
            resetUniformsNotSetByCurrent(shader);
            renderMultipassLighting(shader, geom, rm);
            // very important, notice the return statement!
            return;
    }

    // upload and bind shader
    if (techDef.isUsingShaders()) {
        // any unset uniforms will be set to 0
        resetUniformsNotSetByCurrent(shader);
        r.setShader(shader);
    }

    r.renderMesh(geom.getMesh(), geom.getLodLevel(), 1);
}