Using Custom Shaders in WorldWind Java / JOGL

or Create IR effect in WorldWind Java

I need to emulate an infrared (IR) view in WorldWind, and I'm not sure about the best way to do this. I must point out that I do not need to simulate IR (i.e. no heatmaps). I just need to create a reasonable facsimile black and white infrared display. I have very limited graphics knowledge and lack of experience with OpenGL, JOGL or WorldWind.

Based on my research so far, it seems like the best approach is to use a custom shader. However, as far as I can tell, WorldWind does not support high-level shader support.

I found the following relevant topics on the WorldWind forum, but I'm still not sure how to do this:

To clarify my question (s):

How to integrate a GLSL shader into a WorldWind application if this is truly the best approach? If not, how do I implement this effect?

+3
source share
1 answer

This turned out to be quite simple thanks to the contributions of tve and what_nick in this thread: Support for GLSL Shader, which displays tiles correctly . In particular, I reused the GLSL class introduced by tve (in shader_support_051308.zip ) and changed the code for what_nick code.

DecoratedLayer, "" , ShadingDecorator, GLSL render:

public class DecoratedLayer implements Layer {
    private final Layer _layer;
    private final I_LayerDecorator _decorator;

    public DecoratedLayer(Layer layer, I_LayerDecorator decorator) {
        _layer = layer;
        _decorator = decorator;
    }

    @Override
    public void preRender(DrawContext dc) {
       _decorator.preRender(dc, _layer);
    }

    @Override
    public void render(DrawContext dc) {
       _decorator.render(dc, _layer);
    }

    // all other methods delegate to _layer
}

public class ShadingDecorator implements I_LayerDecorator {
    private GLSL glsl;
    private final File vertfile;
    private final File fragfile;

    public ShadingDecorator(final File vertexShaderFile, 
                            final File fragmentShaderFile) {
        vertfile = vertexShaderFile;
        fragfile = fragmentShaderFile;
    }

    @Override
    public void preRender(DrawContext dc, Layer layer) {
        if (glsl == null) {
            glsl = new GLSL(dc.getGL());
            glsl.loadVertexShader(vertfile);
            glsl.loadFragmentShader(fragfile);
        }
        layer.preRender(dc);
    }

    @Override
    public void render(DrawContext dc, Layer layer) {
        if (glsl != null) {
            glsl.useShaders();
            glsl.startShader();
            GL gl = dc.getGL();
            gl.glUniform1i(glsl.getUniformLocation("tile_image"), 0);

            layer.render(dc);

            glsl.endShader();
        }
    }
}

, , .

+1

Source: https://habr.com/ru/post/1789836/


All Articles