Fairly GLSL newb here, question about "stamping"

The title might be slightly misleading since I’m unsure how to properly phrase my question. Also, if I posted in the wrong forum, I apologize in advance.

I’m working on a game based on jME3 engine written in java using LWJGL. I’ve setup a shader for a lens flare effect but I’ve hit a bump that I can’t seem to find an issue out of.

In my 3D scene I have a backdrop containing a star (it’s a 3D space game). Given the camera’s, the sun’s and other variables’ location, I want to “stamp” several images on top of the main rendered scene.

Right now all I get is the five images composing the flare, but they’re “full screen” instead of their own proper sizes (128x128, 64x64, etc). No need to say it doesn’t look very good.

So, my question is: how can I tell the .frag program to use the right scale/size of the image instead of having it stretched across the whole screen?

The .vert and .frag files are pretty simple and contain variables that might not be used right now (but planned on), hopefully that won’t confuse anyone.

.vert file:

precision highp float;

in vec4 inPosition;
in vec2 inTexCoord;

uniform mat4 g_WorldViewProjectionMatrix;

out vec2 gs_TexCoord;

void main() {

    gl_Position = g_WorldViewProjectionMatrix * inPosition;
    gs_TexCoord = inTexCoord;

.frag file:

precision highp float;

in vec2 gs_TexCoord;
out vec4 gs_FragColor;

uniform sampler2D m_Texture;
uniform sampler2D m_LightTexture;
uniform sampler2D m_FlareTexture1;
uniform sampler2D m_FlareTexture2;
uniform sampler2D m_FlareTexture3;
uniform sampler2D m_FlareTexture4;

uniform vec4 m_LensBrightness;
uniform vec4 m_MidBrightness;
uniform vec4 m_SunColor;
uniform vec3 m_CenterScreen;
uniform vec3 m_LightPosition;
uniform bool m_IsInView;
uniform bool m_hasFlare;

void main() {

    vec4 color = vec4(0.0);
    if (m_IsInView) {

        if (m_hasFlare) {
            color = (m_LensBrightness + m_SunColor) * (texture2D(m_FlareTexture1, gs_TexCoord) +
                texture2D(m_FlareTexture2, gs_TexCoord) +
                texture2D(m_FlareTexture3, gs_TexCoord) +
                texture2D(m_FlareTexture4, gs_TexCoord));
            color += (m_MidBrightness + m_SunColor) * texture2D(m_LightTexture, gs_TexCoord);
        } else {
            color = (m_MidBrightness + m_SunColor) * texture2D(m_LightTexture, gs_TexCoord);
    gs_FragColor = color + texture2D(m_Texture, gs_TexCoord);

Thank you. :slight_smile:

I seems to me, that the vertex shader might be the better spot to tackle your problem. I guess you render something similar to a textured quad, right?

So you might want to adjust inPosition and/or the g_WorldViewProjectionMatrix, instead.

The problem has nothing to do with how your are shading your fragments, but everything to do with the geometry you are sending in.
Just how are you calculating the size of the quads you want rendering?

Thanks for the answers guys. It’s appreciated.

@BionicBytes, well, that’s the thing. There are no geometries involved in my shader. What I get is already pre-rendered; what I’m doing is a PostProcessing filter and all I want to do is add those pesky little pngs to it. FYI the pre-rendered frame is m_Texture.

I’ve also been informed after posting this that by using a PostProcessFilter, I was effectively “painting” on a quad that was the size of the screen. :stuck_out_tongue: Is there any way I could still do this?

A quick look on Google found this Post process sun flare in XNA
Should be straight forward to translate parts into OpenGL.

Thanks for the link.

I checked that page a while back but didn’t like the result in the screenshot. Maybe by using difference textures and other tweaks I could make it act/look the way I want…

If anyone cares here’s the video of what it looks like as it is right now.


Edit: Whoops. Forgot the link to the video :facepalm:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.