• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
medevilenemy

odd parallax effect

4 posts in this topic

I've been writing a nice shiny new lighitng system, but have run into a small snag... I can render the new lighting stuff (a texture to which I have drawn an appropriate lighting mask), but when I move my camera, the lights (which are holes punched through an opaque cover) don't seem to move at the same rate as the underlying scene. I use the same camera placement code in the FBO (to make the texture) rendering context as I do in the underlying scene. The only real difference I can think of is that the local Z coords happen to be set up backwards between the two (but that shouldn't have any effect on horizontal camera movement, I think).

The relevant camera code is:

gluLookAt( Position.x,Position.y,Position.z,
ViewPoint.x,ViewPoint.y,ViewPoint.z,
UpVector.x,UpVector.y,UpVector.z);

where ViewPoint = the sum of the Position and ViewDir 3d vectors, ViewDir = (0.0, 0.0, -1.0) (i've tried flipping the z coord for the camera setting in the z flipped FBO context with no apparant effect), and UpVector = (0.0, 1.0, 0.0).

I'm using an ortho projection for both the main scene and the FBO. I tried using gltranslated for the FBO local camera but that seemed to make the problem worse.

Sorry for reposting this, but I see the last one as having 0 views... that seems broken. Edited by medevilenemy
0

Share this post


Link to post
Share on other sites
I think you should post the whole rendering code, including the lightmap rendering.
It's not quite clear what you are saying. Is the scene moving while the light is static? Or is it the other way around?

It's important to note, that there is no camera object in openGL. There is [i]view[/i]. And a view (modelview) transformation is actually the inverse of the virtual camera's transformation. By that I mean you are not moving the camera backwards, but moving the scene forwards for example.
Maybe that's the confusion, so maybe you have to use the inverse modelview transformation for the lightmap.

There can also be problems with scaling. By scaling I mean the FBO and the world scene will probably have different scales.

I haven't worked with lightmaps yet, so it's quite hard to visualize how you can render to it. I figure that you'll have to either use different transformations for each face, or are you using screen sized screen aligned texture mask?
If so how are you applying the transformation?


So to sum it up: post code.
0

Share this post


Link to post
Share on other sites
When I say camera I'm referring to my engine's own camera class, which in its current configuration pretty much just moves the view via some vector transformations and glulookat. The scene is 2D, though there is a 3D component in that some things are drawn on different "layers" than others (the light texture is drawn a little on top of the underlying scene). The "light texture" is a texture to which I have rendered, through an FBO, an opaque black box and blended in shapes representing lights. These blended shapes make parts of the texture transparent, allowing you to see through to the underlying game scene. The FBO texture is specified as being the same pixel size as the screen, and uses an identical orthographic setup except for reversed Z coords (which can probably be swapped back, come to think of it). In theory, the view on the scene is moving while the opaque box is always drawn to cover the screen, thus lights should appear to move onto and off it based on the current camera location. Similarly, what you see on the underlying scene appears to move. The problem is that the apparant motion is at different rates for the underlying scene and the blended lights, such that a blended light doesn't always cover the same area of the screen... Note that this only applies to horizontal camera movement. When the camera moves vertically, the lights seem to sync up appropriately.

Relevant code:

FBO Init:
[CODE]
void LightingInit()
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
glGenTextures(1, &lighting_rtt_number);

glBindTexture(GL_TEXTURE_2D, lighting_rtt_number);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, screen_width, screen_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);


glBindTexture(GL_TEXTURE_2D, 0);

// create a renderbuffer object to store depth info
GLuint rboId = 1;
glGenRenderbuffers(1, &rboId);

glBindRenderbuffer(GL_RENDERBUFFER, rboId);

glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, screen_width, screen_height);

// create a framebuffer object
glGenFramebuffers(1, &lighting_fbo_number);

glBindFramebuffer(GL_FRAMEBUFFER, lighting_fbo_number);

// attach the texture to FBO color attachment point
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, lighting_rtt_number, 0);

// attach the renderbuffer to depth attachment point
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboId);

// switch back to window-system-provided framebuffer
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
[/CODE]

Get ready to render lights through the FBO, and draw the opaque box
[CODE]
// Unbind any texture that might currently be bound
glBindTexture(GL_TEXTURE_2D, 0);

// set rendering destination to FBO
glBindFramebuffer(GL_FRAMEBUFFER, lighting_fbo_number);

// Set stuff up
glViewport(0,0,screen_width, screen_height);
glClearDepth(1.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-0.5 * width, 0.5*width, -1, 1, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//glTranslatef(0.0, 0.0, 0.0);

//glLoadIdentity();
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_TRUE);
glDepthRange(0.0f, 1.0f);
glAlphaFunc(GL_GEQUAL, 0.0);

glLoadIdentity();
Camera.Render();

glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

glColor4d(0.0, 0.0, 0.0, 0.0); // Black, 0 alpha!?
glBegin(GL_QUADS);
glVertex3d(-0.5 * width, 1.0, 0.0);
glVertex3d(0.5 * width, 1.0, 0.0);
glVertex3d(0.5 * width, -1.0, 0.0);
glVertex3d(-0.5 * width, -1.0, 0.0);
glEnd();
[/CODE]


Blending a light into the opaque box
[CODE]
void Render()
{
// STUFF NEEDED TO RENDER: COLOR (R, G, B), Max light level, Falloff point, Position, Center Angle, Arc Width
int num_segments = 128;
float r = specifications.GetFloatAttribute("color_red");
float g = specifications.GetFloatAttribute("color_green");
float b = specifications.GetFloatAttribute("color_blue");
float center_a = lights;
float arc_width = specifications.GetFloatAttribute("arc_width");
float start_angle = (specifications.GetFloatAttribute("center_angle") - (arc_width / 2.0)) * DEGTORAD;
float falloff_start = specifications.GetFloatAttribute("falloff_start") / 100;

double theta = (arc_width * DEGTORAD) / (num_segments - 1);
double tangential_factor = tan(theta);
double radial_factor = cos(theta);

double x = (rad * falloff_start) * cos(start_angle);
double y = (rad * falloff_start) * sin(start_angle);

int current_segment;

glColor4f(r, g, b, center_a);
glVertex3d(displacement_x, displacement_y, 0.0);
glBegin(GL_TRIANGLE_FAN);
for(current_segment = 0; current_segment < num_segments; current_segment++)
{
glVertex3f(x + displacement_x, y + displacement_y, 0.0);

float tx = -y;
float ty = x;

x += tx * tangential_factor;
y += ty * tangential_factor;

x *= radial_factor;
y *= radial_factor;
}
glEnd();

}
[/CODE]

And now, blend the FBO drawn texture onto the scene
[CODE]
// Phase 2c: Cleanup
glDisable(GL_LINE_SMOOTH);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

// Phase 2d: Draw texture to screen
glViewport(0,0,screen_width,screen_height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-0.5 * width, 0.5 * width, -1, 1, 1, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND); // allows blending (transparency)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // function for blending
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH); // allows smooth shading (gradients)
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GEQUAL, 0.0);

Camera.Render(); // Shift over to the correct coords

glColor4d(1.0, 1.0, 0.0, 1.0);
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, lighting_rtt_number);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5 * width,-1.0,0.01); // Bottom-Left Vertex
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5 * width,-1.0,0.01); // Bottom-Right Vertex
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5 * width,1.0,0.01); // Top-Right Vertex
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5 * width,1.0,0.01); // Top-Left Vertex
glEnd();
glDisable(GL_TEXTURE_2D);


glBindTexture(GL_TEXTURE_2D, 0);
glAlphaFunc(GL_GREATER, 0.0);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
[/CODE]


Apologies for extraneous commented out stuff... A lot of that are remnants from fiddling with the code to get it to work and from a previous proof-of-concept stage. It will be cleaned up once everything works. The code I posted in my original post is the contents of the camera class's Render function (called as Camera.Render()). Its coords are the only coords changing at the moment. The rest of the scene (including blended lights) have their own static coords (drawn in different positions due to glulookat). Thanks for your help!
0

Share this post


Link to post
Share on other sites
Hmm.
I'm not spotting anything obvious, but I have a hunch that you unintentionally apply the same transformation twice.
Something like you apply the transformation in the FBO rendering, then you apply it again when you render the lightmap onto the scene.

I'm still looking at the code, but you can give some extra help:
Does the lighting layer move faster than the scene? About twice as fast?
What happens if you render something else than the light layer? If it moves, then you have the double transformation.
The light layer quad should be always fixed onto the screen.

Maybe you just need to add a LoadIdentity before rendering the light layer onto the scene.
Try this first.

EDIT: I'm pretty sure now. Just add a glLoadIdentity before the light layer rendering for a quick fix. Edited by szecs
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0