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.