View Issue Details

IDProjectCategoryView StatusLast Update
0002400FSSCPscriptingpublic2012-01-10 20:33
ReporterNuke Assigned ToSwifty  
PrioritynormalSeverityblockReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.6.13 
Target Version3.6.14Fixed in Version3.6.13 
Summary0002400: Render to texture scripts do not seem to render correctly in 3.6.13 builds.
Description3.6.13 builds seem to break scripts that use render to texture features. it seems to band a correctly rendered horizontal line across the whole vertical area of the texture. pic here:

http://i213.photobucket.com/albums/cc103/Emperor_of_Nihil/brokertt.jpg
Additional Informationi was going to just link to my cockpit mod svn, but because of the size of the mod and im not sure how the version on svn runs under 3.6.13 builds, i will make a script later today for testing.
TagsNo tags attached.

Activities

Nuke

2011-02-18 10:20

reporter   ~0012626

so i go a little bit carried away and write a new version of my hudpong script, with rtt capabilities. unfortunately this script doesn't seem to break rtt. at least in that case it seems to work. i figure that it has something to do with calling renderFrame() while rendering to a texture. which makes me question why the radar in the cockpit demo doesnt render right (it doesnt use renderFrame()).

il have to try tomorrow to come up with another script that breaks rtt, so far it seems that only my cockpit demo manages to break it. there is a possibility that there is something wrong with my script, but that doesn't explain why 3.6.12 builds work fine with it and 3.6.13 screws up the textures. more investigation is in order.

Nuke

2011-02-24 08:31

reporter   ~0012629

i wrote yet another rtt script and still cannot replicate the bug. what has changed with regards to rtt since 3.6.12?

chief1983

2011-04-12 19:20

administrator   ~0012656

Not sure about RTT specifically, but 3.6.13 has go_faster and new HUD code. In a case like this, using the nightly builds to narrow it down might be beneficial. I will even make builds for certain revisions if it will help narrow it down, but someone who can reproduce it would need to do the testing. I might even checkout the cockpit mod myself to see if I can narrow it down some.

Nuke

2011-04-13 18:26

reporter   ~0012657

works in 6626, but not in 6627

chief1983

2011-04-13 18:44

administrator   ~0012658

So we know it was a change made in the go_faster Antipodes 6 commit that was responsible.

Nuke

2011-09-03 09:26

reporter   ~0012795

i think this bug can be closed, i just downloaded 7613 and my script runs fine now. dont know when this was fixed but it doesnt seem to be an issue no more.

chief1983

2011-09-03 14:17

administrator   ~0012796

Closing as resolved/fixed :)

Nuke

2011-09-05 07:08

reporter   ~0012801

hate to say this but i got my builds crossed, where i thought i was running a recent nightly somehow i ended up running 3.6.12. rtt is more broke than ever. this should render a camera view to texture and replace every texture on every ship in the game with it. scripting.tbl:

#Conditional Hooks
$Application: FS2_Open
$State: GS_STATE_GAME_PLAY
$On State Start:
[
tex = gr.createTexture(512,512,TEXTURE_DYNAMIC)
tex2 = gr.createTexture(512,512,TEXTURE_DYNAMIC)
cam = gr.createCamera("spotcam")
cam2 = gr.createCamera("topscam")
]
$On Frame:
[
ship = mn.Ships["Alpha 1"]
if cam:isValid() and ship:isValid() and tex:isValid() then
    --make the camera do stuff
    cam.Self = ship
    cam.Orientation = ba.createOrientation(0,0,math.pi)
    --look at ship
    local oldTarget = gr.CurrentRenderTarget
    gr.CurrentRenderTarget = tex
    --backfill
    gr.setColor(0,0,0,255)
    gr.drawRectangle(0,0,512,512)
    --set camera
    gr.setCamera(cam)
    --draw scene
    mn.renderFrame()
    --reset camera
    gr.setCamera()
    --do other view
    gr.CurrentRenderTarget = tex2
    gr.setColor(0,0,0,255)
    gr.drawRectangle(0,0,512,512)
    cam2.Orientation = ba.createOrientation(math.pi*0.5,0,0)
    cam2.Position = ba.createVector(ship.Position.x, 5000, ship.Position.z)
    gr.setCamera(cam2)
    mn.renderFrame()
    gr.setCamera()
    --unset target
    gr.CurrentRenderTarget = oldTarget
    --replace textures
    for j=1, #mn.Ships do
        local aship = mn.Ships[j]
        if aship :isValid() then
            if aship ~= ship then
                for i=1, #aship.Textures do
                    aship.Textures[i] = tex
                end
            else
                for i=1, #aship.Textures do
                    aship.Textures[i] = tex2
                end
            end
        end
    end
end
]
$On State End:
[
tex:unload()
]
#end

2011-09-05 07:19

 

brokertt.jpg (48,693 bytes)   
brokertt.jpg (48,693 bytes)   

2011-09-10 00:50

 

texturereplacefail.jpg (116,788 bytes)   
texturereplacefail.jpg (116,788 bytes)   

Nuke

2011-09-10 00:59

reporter   ~0012806

got some new information and a new screenie.

it appears that the issue is not so much about rendering to texture as it is about the uv space not getting scaled correctly at polygon render.

what i did was i wrote a bit of script to draw all the render targets to the screen. (see texturereplacefail.jpg) the far right image is my custom radar display. on the assumption that something was going wrong with the uv mapping i decided to draw a bunch of random pixels over the area to see how they were dispersed on the upper right geometry with the radar texture. sure enough the same banding i encountered when i first reported this bug was occuring.

i assume whats happening is that when the uv coords from the polygons are being multiplied by the image dimentions, that the dimentions are wrong, especially on the v axis. this may also explain why the renderFrame calls are not filling the whole image.

Nuke

2011-09-10 01:05

reporter   ~0012807

also my svn repo is here in case anyone wants to debug the script further:
http://nukedspace.fsmods.net/svn/trunk/cockpitdemo/

Nuke

2011-11-08 20:16

reporter   ~0012942

a small update:

the banding seen in the first screen shot is not an rtt issue. the way i inserted the polygons into the models did not fly with the updated ibx system and this caused uv corruption. this is fixable in the model. i figured this out by setting up a new ship to use my rtt system. the 3rd screenie shows this.

the issue from the second screen shot still happens. although the render target renders to the screen in a different place under the 3.6.14 rc1 build. it seems that 2 things are happening here:

1. render targets are either not being set or reset properly
2. on builds where render targets were being set correctly, there were scaling issues when the frame is rendered to the texture, where it would not fill the texture.

here is yet another test script:
;rtt test script
;creates a rear view camera, then renders it to texture
;this texture is drawn to fill the green and blue box on the hud
;image should completely fill the box

#Conditional Hooks
$Application: FS2_Open
$State: GS_STATE_GAME_PLAY
$On State Start:
[
tex = gr.createTexture(255,255,TEXTURE_DYNAMIC)
cam = gr.createCamera("rearview")
]
$On Frame:
[
ship = mn.Ships["Alpha 1"]
if cam:isValid() and ship:isValid() and tex:isValid() then
    --attatch camera to the ship
    cam.Self = ship
    --point camera backwards
    cam.Orientation = ba.createOrientation(0,0,math.pi)
    cam.Position = ba.createVector(0,0,-15)
    --set render target
    gr.CurrentRenderTarget = tex
    --backfill
    gr.clearScreen(0,0,0,255)
    --set camera
    gr.setCamera(cam)
    --draw scene
    mn.renderFrame()
    --reset camera
    gr.setCamera()
    --reset target
    gr.CurrentRenderTarget = nil
    --draw textures on hud
    x1,y1,x2,y2 = 8, gr.getScreenHeight()-tex:getHeight()-8, tex:getWidth()+8, gr.getScreenHeight()-8
    --draw debug square first
    gr.setColor(0,0,255,255)
    gr.drawRectangle(x1,y1,x2,y2,true)
    gr.setColor(0,254,0,255)
    gr.drawLine(x1-1,y1-1,x2+1,y1-1)
    gr.drawLine(x1-1,y2+1,x2+1,y2+1)
    gr.drawLine(x1-1,y1-1,x1-1,y2+1)
    gr.drawLine(x2+2,y1-1,x2+2,y2+1) --draw primitives are still innacurately positioned, lol
    --now draw the texture
    gr.drawImage(tex,x1,y1,x2,y2)
end
]
$On State End:
[
tex:unload()
]
#end

m_m

2011-12-21 19:04

developer   ~0013005

I think that I fixed this issue and another problem with post-processing which caused the current OpenGL framebuffer object to be reset to the screen instead of the RTT framebuffer which should be used. The first problem was because the scene gets rendered into a fixed size framebuffer texture of the configured resolution. When the scene gets finally drawn to the texture the scene texture which is the size of the screen resolution where the target texture is usually smaller than this. To fix that I added an U and a V scale variable which gets set in gr_opengl_scene_texture_begin (either to 1.0f when not doing RTT or to the correct UV values).
I also added a check for the non-power-of-two texture sizes to make_render_target to add more freedom to render targets if it's possible.
I added the patch to this issue.

There are still problems when FXAA is enabled as something is going wrong there but I have no idea what is causing that.

2011-12-21 19:04

 

rtt.patch (8,678 bytes)   
Index: code/graphics/gropenglbmpman.cpp
===================================================================
--- code/graphics/gropenglbmpman.cpp	(revision 8105)
+++ code/graphics/gropenglbmpman.cpp	(working copy)
@@ -582,7 +582,11 @@
 		MIN(*width, *height) = MAX(*width, *height);
 	}
 
-	Assert( is_power_of_two(*width, *height) );
+	// Only enforce power of two size if not supported
+	if (!(Is_Extension_Enabled(OGL_ARB_TEXTURE_NON_POWER_OF_TWO)))
+	{
+		Assert( is_power_of_two(*width, *height) );
+	}
 
 	if ( opengl_make_render_target(bm_bitmaps[n].handle, n, width, height, bpp, mm_lvl, flags) ) {
 		return 1;
Index: code/graphics/gropengldraw.cpp
===================================================================
--- code/graphics/gropengldraw.cpp	(revision 8105)
+++ code/graphics/gropengldraw.cpp	(working copy)
@@ -50,6 +50,9 @@
 int Scene_texture_width;
 int Scene_texture_height;
 
+GLfloat Scene_texture_u_scale = 1.0f;
+GLfloat Scene_texture_v_scale = 1.0f;
+
 void gr_opengl_pixel(int x, int y, bool resize)
 {
 	gr_line(x, y, x, y, resize);
@@ -2234,6 +2237,20 @@
 
 	vglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, Scene_framebuffer);
 
+	if (GL_rendering_to_framebuffer)
+	{
+		Scene_texture_u_scale = i2fl(gr_screen.max_w) / i2fl(Scene_texture_width);
+		Scene_texture_v_scale = i2fl(gr_screen.max_h) / i2fl(Scene_texture_height);
+
+		CLAMP(Scene_texture_u_scale, 0.0f, 1.0f);
+		CLAMP(Scene_texture_v_scale, 0.0f, 1.0f);
+	}
+	else
+	{
+		Scene_texture_u_scale = 1.0f;
+		Scene_texture_v_scale = 1.0f;
+	}
+
 	GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT };
 	vglDrawBuffers(2, buffers);
 
@@ -2266,7 +2283,7 @@
 		GLboolean blend = GL_state.Blend(GL_FALSE);
 		GLboolean cull = GL_state.CullFace(GL_FALSE);
 
-		vglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+		vglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, opengl_get_rtt_framebuffer());
 
 		GL_state.Texture.SetActiveUnit(0);
 		GL_state.Texture.SetTarget(GL_TEXTURE_2D);
@@ -2276,19 +2293,38 @@
 		glClear(GL_COLOR_BUFFER_BIT);
 		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 
-		glBegin(GL_QUADS);
-		glTexCoord2f(0.0f, 0.0f);
-		glVertex2f(0.0f, (float)gr_screen.max_h);
+		if (GL_rendering_to_framebuffer)
+		{
+			glBegin(GL_QUADS);
+				glTexCoord2f(Scene_texture_u_scale, 0.0f);
+				glVertex2f(0.0f, (float)gr_screen.max_h);
+				
+				glTexCoord2f(0.0f, 0.0f);
+				glVertex2f((float)gr_screen.max_w, (float)gr_screen.max_h);
+				
+				glTexCoord2f(0.0f, Scene_texture_v_scale);
+				glVertex2f((float)gr_screen.max_w, 0.0f);
+				
+				glTexCoord2f(Scene_texture_u_scale, Scene_texture_v_scale);
+				glVertex2f(0.0f, 0.0f);
+			glEnd();
+		}
+		else
+		{
+			glBegin(GL_QUADS);
+				glTexCoord2f(0.0f, 0.0f);
+				glVertex2f(0.0f, (float)gr_screen.max_h);
 
-		glTexCoord2f(1.0f, 0.0f);
-		glVertex2f((float)gr_screen.max_w, (float)gr_screen.max_h);
+				glTexCoord2f(Scene_texture_u_scale, 0.0f);
+				glVertex2f((float)gr_screen.max_w, (float)gr_screen.max_h);
 
-		glTexCoord2f(1.0f, 1.0f);
-		glVertex2f((float)gr_screen.max_w, 0.0f);
+				glTexCoord2f(Scene_texture_u_scale, Scene_texture_v_scale);
+				glVertex2f((float)gr_screen.max_w, 0.0f);
 
-		glTexCoord2f(0.0f, 1.0f);
-		glVertex2f(0.0f, 0.0f);
-		glEnd();
+				glTexCoord2f(0.0f, Scene_texture_v_scale);
+				glVertex2f(0.0f, 0.0f);
+			glEnd();
+		}
 
 		GL_state.Texture.SetActiveUnit(0);
 		GL_state.Texture.Disable();
@@ -2301,6 +2337,11 @@
 		GL_state.CullFace(cull);
 	}
 
+	// Reset the UV scale values
+	
+	Scene_texture_u_scale = 1.0f;
+	Scene_texture_v_scale = 1.0f;
+
 	Scene_framebuffer_in_frame = false;
 }
 
Index: code/graphics/gropengldraw.h
===================================================================
--- code/graphics/gropengldraw.h	(revision 8105)
+++ code/graphics/gropengldraw.h	(working copy)
@@ -56,4 +56,7 @@
 extern int Scene_texture_width;
 extern int Scene_texture_height;
 
+extern float Scene_texture_u_scale;
+extern float Scene_texture_v_scale;
+
 #endif	// !GR_OPENGLDRAW_H
Index: code/graphics/gropenglpostprocessing.cpp
===================================================================
--- code/graphics/gropenglpostprocessing.cpp	(revision 8105)
+++ code/graphics/gropenglpostprocessing.cpp	(working copy)
@@ -209,9 +209,9 @@
 	// reset viewport, scissor test and exit
 	glViewport(0, 0, gr_screen.max_w, gr_screen.max_h);
 	GL_state.ScissorTest(scissor_test);
+	
+	vglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, opengl_get_rtt_framebuffer());
 
-	vglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-
 	return true;
 }
 
@@ -308,14 +308,14 @@
 	glBegin(GL_QUADS);
 		glTexCoord2f(0.0f, 0.0f);
 		glVertex2f(-1.0f, -1.0f);
-
-		glTexCoord2f(1.0f, 0.0f);
+		
+		glTexCoord2f(Scene_texture_u_scale, 0.0f);
 		glVertex2f(1.0f, -1.0f);
-
-		glTexCoord2f(1.0f, 1.0f);
+		
+		glTexCoord2f(Scene_texture_u_scale, Scene_texture_v_scale);
 		glVertex2f(1.0f, 1.0f);
-
-		glTexCoord2f(0.0f, 1.0f);
+		
+		glTexCoord2f(0.0f, Scene_texture_v_scale);
 		glVertex2f(-1.0f, 1.0f);
 	glEnd();
 
@@ -336,14 +336,14 @@
 	glBegin(GL_QUADS);
 		glTexCoord2f(0.0f, 0.0f);
 		glVertex2f(-1.0f, -1.0f);
-
-		glTexCoord2f(1.0f, 0.0f);
+		
+		glTexCoord2f(Scene_texture_u_scale, 0.0f);
 		glVertex2f(1.0f, -1.0f);
-
-		glTexCoord2f(1.0f, 1.0f);
+		
+		glTexCoord2f(Scene_texture_u_scale, Scene_texture_v_scale);
 		glVertex2f(1.0f, 1.0f);
-
-		glTexCoord2f(0.0f, 1.0f);
+		
+		glTexCoord2f(0.0f, Scene_texture_v_scale);
 		glVertex2f(-1.0f, 1.0f);
 	glEnd();
 
@@ -373,9 +373,8 @@
 		opengl_post_pass_fxaa();
 	}
 	
-	// done with screen render framebuffer
-	//vglBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
-	
+	// Bind the correct framebuffer. opengl_get_rtt_framebuffer returns 0 if not doing RTT
+	vglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, opengl_get_rtt_framebuffer());	
 	opengl_shader_set_current( &GL_post_shader[6] );
 	float x,y;
 	// should we even be here?
@@ -495,14 +494,14 @@
 	glBegin(GL_QUADS);
 		glTexCoord2f(0.0f, 0.0f);
 		glVertex2f(-1.0f, -1.0f);
-
-		glTexCoord2f(1.0f, 0.0f);
+		
+		glTexCoord2f(Scene_texture_u_scale, 0.0f);
 		glVertex2f(1.0f, -1.0f);
-
-		glTexCoord2f(1.0f, 1.0f);
+		
+		glTexCoord2f(Scene_texture_u_scale, Scene_texture_v_scale);
 		glVertex2f(1.0f, 1.0f);
-
-		glTexCoord2f(0.0f, 1.0f);
+		
+		glTexCoord2f(0.0f, Scene_texture_v_scale);
 		glVertex2f(-1.0f, 1.0f);
 	glEnd();
 
Index: code/graphics/gropengltexture.cpp
===================================================================
--- code/graphics/gropengltexture.cpp	(revision 8105)
+++ code/graphics/gropengltexture.cpp	(working copy)
@@ -1855,6 +1855,30 @@
 	return 1;
 }
 
+/**
+ * @fn	GLuint opengl_get_rtt_framebuffer()
+ *
+ * @brief	Gets the current RTT framebuffer.
+ * 
+ * Gets the OpenGL framebuffer ID of the currently in use RTT framebuffer.
+ * If there is currently none such framebuffer in use then this function returns
+ * 0 so it can be used in any place where the framebuffer should be reset to the
+ * default drawing surface.
+ *
+ * @author	m!m
+ * @date	14.12.2011
+ *
+ * @return	The current RTT FBO ID or 0 when not doing RTT.
+ */
+
+GLuint opengl_get_rtt_framebuffer()
+{
+	if (render_target == NULL || render_target->working_slot < 0)
+		return 0;
+	else
+		return render_target->framebuffer_id;
+}
+
 //
 // End of GL_EXT_framebuffer_object stuff
 // -----------------------------------------------------------------------------
Index: code/graphics/gropengltexture.h
===================================================================
--- code/graphics/gropengltexture.h	(revision 8105)
+++ code/graphics/gropengltexture.h	(working copy)
@@ -78,6 +78,7 @@
 int opengl_export_image(int slot, int width, int height, int alpha, int num_mipmaps, ubyte *image_data = NULL);
 void opengl_set_texture_target(GLenum target = GL_TEXTURE_2D);
 void opengl_set_texture_face(GLenum face = GL_TEXTURE_2D);
+GLuint opengl_get_rtt_framebuffer();
 
 int gr_opengl_tcache_set(int bitmap_handle, int bitmap_type, float *u_scale, float *v_scale, int stage = 0);
 int gr_opengl_preload(int bitmap_num, int is_aabitmap);
Index: code/parse/lua.cpp
===================================================================
--- code/parse/lua.cpp	(revision 8105)
+++ code/parse/lua.cpp	(working copy)
@@ -11955,7 +11955,7 @@
 	return ADE_RETURN_TRUE;
 }
 
-ADE_FUNC(renderFrame, l_Mission, NULL, "Renders mission frame, but does not move anything", NULL, NULL)
+ADE_FUNC(renderFrame, l_Mission, NULL, "Renders mission frame, but does not move anything<br><b>Important:</b>The maximal resolution this function is able to render is the currently configured screen size.", NULL, NULL)
 {
 	camid cid = game_render_frame_setup();
 	game_render_frame( cid );
rtt.patch (8,678 bytes)   

The_E

2011-12-22 15:10

administrator   ~0013006

Please try again with the changes in revision 8108. FXAA used to rely on undocumented behaviour, which was fixed in that commit.

m_m

2011-12-22 17:29

developer   ~0013007

Last edited: 2011-12-23 12:15

No that didn't help it actually made it worse now there is also a top-down view of the screen rendered onto the texture: http://img502.imageshack.us/img502/8056/fxaabug02.jpg
Without FXAA everything looks good: http://img59.imageshack.us/img59/3176/fxaabug01.jpg

The_E

2011-12-23 13:08

administrator   ~0013008

Fix committed in revision 8111. However, this disables FXAA when rendering to a render target, which I think is a minor nitpick that can be addressed later.

Related Changesets

fs2open: trunk r8111

2011-12-23 08:09

The_E


Ported: N/A

Details Diff
From m|m: Fix for Mantis 2400 (RTT rendering broken in current builds). Also changes GL_rendering_to_framebuffer to the more aptly named GL_rendering_to_texture. Affected Issues
0002400
mod - /trunk/fs2_open/code/graphics/gropengl.cpp Diff File
mod - /trunk/fs2_open/code/graphics/gropenglbmpman.cpp Diff File
mod - /trunk/fs2_open/code/graphics/gropengldraw.cpp Diff File
mod - /trunk/fs2_open/code/graphics/gropengldraw.h Diff File
mod - /trunk/fs2_open/code/graphics/gropenglpostprocessing.cpp Diff File
mod - /trunk/fs2_open/code/graphics/gropengltexture.cpp Diff File
mod - /trunk/fs2_open/code/graphics/gropengltexture.h Diff File
mod - /trunk/fs2_open/code/graphics/gropengltnl.cpp Diff File

Issue History

Date Modified Username Field Change
2011-02-17 18:31 Nuke New Issue
2011-02-18 10:20 Nuke Note Added: 0012626
2011-02-24 08:31 Nuke Note Added: 0012629
2011-04-12 19:20 chief1983 Note Added: 0012656
2011-04-12 19:21 chief1983 Target Version => 3.6.14
2011-04-13 18:26 Nuke Note Added: 0012657
2011-04-13 18:44 chief1983 Note Added: 0012658
2011-09-03 09:26 Nuke Note Added: 0012795
2011-09-03 14:17 chief1983 Note Added: 0012796
2011-09-03 14:17 chief1983 Status new => resolved
2011-09-03 14:17 chief1983 Resolution open => fixed
2011-09-03 14:17 chief1983 Fixed in Version => 3.6.13
2011-09-05 07:08 Nuke Note Added: 0012801
2011-09-05 07:08 Nuke Status resolved => feedback
2011-09-05 07:08 Nuke Resolution fixed => reopened
2011-09-05 07:19 Nuke File Added: brokertt.jpg
2011-09-10 00:50 Nuke File Added: texturereplacefail.jpg
2011-09-10 00:59 Nuke Note Added: 0012806
2011-09-10 01:05 Nuke Note Added: 0012807
2011-10-07 02:54 Swifty Status feedback => assigned
2011-10-07 02:54 Swifty Assigned To => Swifty
2011-11-08 20:16 Nuke Note Added: 0012942
2011-12-21 19:04 m_m Note Added: 0013005
2011-12-21 19:04 m_m File Added: rtt.patch
2011-12-22 15:10 The_E Note Added: 0013006
2011-12-22 17:29 m_m Note Added: 0013007
2011-12-23 12:15 m_m Note Edited: 0013007
2011-12-23 13:08 The_E Note Added: 0013008
2011-12-23 13:08 The_E Status assigned => resolved
2011-12-23 13:08 The_E Resolution reopened => fixed
2012-01-10 20:33 chief1983 Changeset attached => fs2open trunk r8111