Category Archives: Phil

Phil 2.29.12

8:30 – 11:00, 12:30 – 3:00 VISIBILITY

  • Worked on getting Data Visualization working
  • ISR/PMO meeting from 1:00 – 3:00

11:00 – 12:30, 3:00 – 5:00 FP

  • Working on multiple rendering surfaces. For the trivial case, I’m going to try to take the blurred image and invert the colors.
  • Added definition of the vertex and fragment shaders in the ScreenRepaint class, since it’s pretty generic.
  • Took screen rendering out of the Gl_ShaderWindow base class and added two instances to the GeoTestShaderWindow. Everything works just as it should.
  • Meeting at UMBC on surface displays, journals and other things. Looks like I’m on a team to build a “Surface-style” interface for the visually impaired. Meetings are every Wednesday at 4:30

Phil 2.24.12

8:30 – FP

  • I think I found GLSL documentation! http://www.opengl.org/sdk/docs/manglsl/
  • A working convolution filter that blurs anything above a certain luminance:
  • #version 150
    // glow.fs
    // outputs the color negative of a texture
    //
    
    in vec2 vTexCoord;
    
    uniform int screenWidth;
    uniform int screenHeight;
    
    uniform sampler2D textureUnit0;
    
    vec4 getTexOffset(const sampler2D texUnit, const vec2 texCoord, const float dx, const float dy){
    	vec2 offset = texCoord + vec2(dx, dy);
    	return texture(textureUnit0, offset);
    }
    
    void main(void)
    {
    	float dx = 1.0 / float(screenWidth);
    	float dy = 1.0 / float (screenHeight);
    
    	float x;
    	float y;
    	vec4 blurSum = vec4(0, 0, 0, 0);
    	float patchSize = 4.0;
    	float xmin = -patchSize*dx;
    	float xmax = patchSize*dx+dx*0.5;
    	float ymin = -patchSize*dy;
    	float ymax = patchSize*dy+dx*0.5;
    	float count = 0;
    
    	for(x = xmin; x < xmax; x += dx){
    		for(y = ymin; y < ymax; y += dy){
     			blurSum += getTexOffset(textureUnit1, vTexCoord, x, y);
     			if(count > 1000){
    				discard;
    			}
    			count += 1.0;
    		}
    	}
    	float weight = 1.0/count;
    	vec4 blured = vec4(blurSum.r*weight, blurSum.g*weight, blurSum.b*weight, 1.0);
    	vec4 sharp = texture(textureUnit0, vTexCoord);
    
    	float luminance = blured.r + blured.g + blured.b;
    	if(luminance > 1.0){
    		gl_FragColor = blured;
    	}else{
    		gl_FragColor = sharp;
    	}
    }
  • And here’s the picture it produces. Note the sharp moon and gridlines with the blurry sun 🙂
  • Next on the hit parade, add a test to see if the corners of the convolution filter touch anything above the luminance threshold and discard if it doesn’t. My guess is that should speed up things a lot. Done. Discovered that there are some odd problems that crop up as the screen gets made quite large. This could have something to do with the fact that I’m not checking to see that the convolution patch’s coordinates can run off the texture (i.e not clamped between 0.0 and 1.0)?
  • Migrate the screen drawing to a DrawableObject class. I’m pretty sure it should work there, as long as it’s called after postDraw3D(). In fact, it should be possible to have multiple screen drawing classes, though I’m not sure why.
  • Add shader directory to svn repo – done
  • And it appears that after a while, something is clogging the graphics pipeline, because the drawing slows way done. This does look like it’s due to the shader, as the neg.fs doesn’t seem to be slowing things down. Yep,  adding clamping to the glow.fs shader fixed that problem. Still have the problem where the screen texture gets messed up if the window gets too big…
  • So here’s the better version of the fragment shader
  • #version 150
    // glow.fs
    // outputs the color negative of a texture
    //
    
    in vec2 vTexCoord;
    
    uniform int screenWidth;
    uniform int screenHeight;
    
    uniform sampler2D textureUnit0;
    
    void luminanceTest(const sampler2D texUnit, const vec2 texCoord, const float xmin, const float xmax, const float ymin, const float ymax, const float luminance){
    	vec2 ll = clamp(texCoord + vec2(xmin, ymin), 0.0, 1.0);
    	vec2 lr = clamp(texCoord + vec2(xmax, ymin), 0.0, 1.0);
    	vec2 ur = clamp(texCoord + vec2(xmax, ymax), 0.0, 1.0);
    	vec2 ul = clamp(texCoord + vec2(xmin, ymax), 0.0, 1.0);
    
    	vec4 total = texture(texUnit, ll);
    	total += texture(texUnit, lr);
    	total += texture(texUnit, ur);
    	total += texture(texUnit, ul);
    
    	float weight = 1.0/4.0;
    	float val = (total.r + total.g + total.b)*weight;
    	if(val < luminance){
    		discard;
    	}
    }
    
    vec4 getTexOffset(const sampler2D texUnit, const vec2 texCoord, const float dx, const float dy){
    	vec2 offset = texCoord + vec2(dx, dy);
    	clamp(offset, 0.0, 1.0);
    	return texture(texUnit, offset);
    }
    
    void main(void)
    {
    	float dx = 1.0 / float(screenWidth);
    	float dy = 1.0 / float (screenHeight);
    
    	float x;
    	float y;
    	vec4 blurSum = vec4(0, 0, 0, 0);
    	float patchSize = 4.0;
    	float xmin = -patchSize*dx;
    	float xmax = patchSize*dx+dx*0.5;
    	float ymin = -patchSize*dy;
    	float ymax = patchSize*dy+dx*0.5;
    	float count = 0;
    
    	luminanceTest(textureUnit0, vTexCoord, xmin, xmax, ymin, ymax, 1.0);
    
    	for(x = xmin; x < xmax; x += dx){
    		for(y = ymin; y < ymax; y += dy){
     			blurSum += getTexOffset(textureUnit0, vTexCoord, x, y);
     			if(count > 1000){
    				discard;
    			}
    			count += 1.0;
    		}
    	}
    	vec4 sharp = texture(textureUnit0, vTexCoord);
    	float weight = 1.0/count;
    	vec4 blured = vec4(blurSum.r*weight, blurSum.g*weight, blurSum.b*weight, sharp.a);
    
    	float luminance = blured.r + blured.g + blured.b;
    	if(luminance > 1.0){
    		gl_FragColor = blured;
    	}else{
    		gl_FragColor = sharp;
    	}
    }

Phil 2.23.12

8:00 – 4:30 FP

  • Step 1 – make a screen-aligned ortho polygon and make sure it’s drawing correctly with a simple shader, and that the text overlay still works – done
  • Step 2 – copy texture code over from modified pix_buffs.cpp – done. Other textures seem to mess everything up.
    • Added glActiveTexture(GL_TEXTURE0); to SolarSystem, which fixed the missing texture problem, but the screen texture still gets messed up. GOing to try putting in pieces of SolarSystem to find where it breaks, since everything works fine with just the Grid
  • Filling out matrix
  • Back to shaders. For some reason, I have to make sure that the screenwidth is evenly divisible by 4. Not sure why, but it’s easily fixed. So now we have this!
  • Committed everything to svn

Phil 2.22.12

8:00 – 1:00 FP

  • More rendering to a texture
  • Yay! Progress!
  • Yeah, I know it doesn’t look like much, but it means I’m that much less confused…
  • Deleting unneeded code for multiple buffers, malloc, etc.
  • Refresh rate drops on screen resize. Why?

1:00 – 4:30 VISIBILITY

  • VisTool Review

Phil 2.20.12

9:30 – 3:00 FP

  • Biting the bullet and installing R on fgmdev. Installed, and working on getting all the packages in.
  • Installed the folllowing
    • install.packages(“Rserve”)
    • apt-get install r-cran-car then library(car)
    • install.packages(“vcd”)
    • apt-get install r-cran-gplots then library(gplots)
    • install.packages(“pwr”)
  • had to re-run library(gplots) so that plotmeans was visible correctly
  • After installing all the packages, I bounced Rserve, and then remembered that I had to bounce tomcat. Which took a *while* to restart.
  • everything appears to be running correctly 🙂

Here’s the current list:

Packages in library '/usr/local/lib/R/site-library':

colorspace              Color Space Manipulation
mvtnorm                 Multivariate Normal and t Distributions
pwr                     Basic functions for power analysis
Rserve                  Binary R server
vcd                     Visualizing Categorical Data

Packages in library '/usr/lib/R/site-library':

car                     Companion to Applied Regression
gdata                   Various R programming tools for data
                        manipulation
gplots                  Various R programming tools for plotting data
gtools                  Various R programming tools
multcomp                Simultaneous Inference in General Parametric
                        Models
mvtnorm                 Multivariate Normal and t Distributions

Packages in library '/usr/lib/R/library':

base                    The R Base Package
boot                    Bootstrap R (S-Plus) Functions (Canty)
class                   Functions for Classification
cluster                 Cluster Analysis Extended Rousseeuw et al.
codetools               Code Analysis Tools for R
datasets                The R Datasets Package
foreign                 Read Data Stored by Minitab, S, SAS, SPSS,
                        Stata, Systat, dBase, ...
graphics                The R Graphics Package
grDevices               The R Graphics Devices and Support for Colours
                        and Fonts
grid                    The Grid Graphics Package
KernSmooth              Functions for kernel smoothing for Wand & Jones
                        (1995)
lattice                 Lattice Graphics
MASS                    Main Package of Venables and Ripley's MASS
methods                 Formal Methods and Classes
mgcv                    GAMs with GCV smoothness estimation and GAMMs
                        by REML/PQL
nlme                    Linear and Nonlinear Mixed Effects Models
nnet                    Feed-forward Neural Networks and Multinomial
                        Log-Linear Models
rpart                   Recursive Partitioning
spatial                 Functions for Kriging and Point Pattern
                        Analysis
splines                 Regression Spline Functions and Classes
stats                   The R Stats Package
stats4                  Statistical Functions using S4 Classes
survival                Survival analysis, including penalised
                        likelihood.
tcltk                   Tcl/Tk Interface
tools                   Tools for Package Development
utils                   The R Utils Package
  • Came upon an interesting thing: http://rapache.net/ it’s a pretty slick VISIBILITY-ish looking thing. Need to spend some time figuring out how it works. Not all that clear yet.
  • OK, back to shaders and such.
  • And I just got why rendering the entire scene to a framebuffer that you then process is important. It’s because you can post process the texture (i.e. the entire scene) to get blur, bloom, and other effects. Cool. Well, I know what I’m doing tomorrow.

Phil 2.17.12

8:30 – FP

  • Started off the day with sprites. Here’s a starfield:
  • The neat thing about this is that the stars are handled as sprites, which means that it’s possible to handle text overlay with a shader now. I think that the way it could be done would be to create a single grid with all the characters and pass that to the vertex shader with the XY index and size of the letter. The vertex shader moves the texture so that the letter is centered and then passes off the texture and size to the fragment shader, which clips the output so only the particular letter is shown. Not going to do that yet, but it’s probably the first tool after I finish the book.
  • Worked my way through the pixBuffer/motion blur section, but I don’t think it’s worth incorporating into the framework.

Phil 2.16.12

8:30 – 4:30 FP

    • Reflection cube maps today
    • And they are working! The trick to handling rotating reflections is the following (note that the camera matrix is determined before the model roation, and the surface normal is calculated after the rotation.):
	M3DMatrix44f mCameraRotOnly;
	M3DMatrix44f mInverseCamera;
	M3DMatrix33f mNormalMat;

	const M3DMatrix44f &mCamera = modelViewStack.GetMatrix();

	modelViewStack.PushMatrix();
		modelViewStack.Rotate(angle, 0.0f, 1.0f, 0.0f);

		orient44fromMat44(mCameraRotOnly, mCamera);
		orient33fromMat44(mNormalMat, modelViewStack.GetMatrix());
		m3dInvertMatrix44(mInverseCamera, mCameraRotOnly);

		projectionStack.PushMatrix();
			projectionStack.MultMatrix(modelViewStack.GetMatrix());
			glUseProgram(reflectionShader);
			glUniformMatrix4fv(locMVPReflect, 1, GL_FALSE, projectionStack.GetMatrix());
			glUniformMatrix4fv(locMVReflect, 1, GL_FALSE, modelViewStack.GetMatrix());
			glUniformMatrix3fv(locNormalReflect, 1, GL_FALSE, mNormalMat);
			glUniformMatrix4fv(locInvertedCamera, 1, GL_FALSE, mInverseCamera);
			triangleBatch.Draw();
			glUseProgram(NULL);
		projectionStack.PopMatrix();
	modelViewStack.PopMatrix();
  • It seems to be a nice day for pretty pictures. Here’s an example of multitexturing:
  • And now that our connection is better, maybe I’ll install R on fgmdev

Phil 2.15.12

8:30 – 4:30 FP

  • Making good, albiet slow progress on shaders. It’s kind of like programming in pre IDE-days; edit in vim then submit to the GPU compiler for a cryptic message. On the list of things to do is a framework that allows for the more sophisticated editing of shaders in the context of a running program. Will probably do this is Java for eclipse. Looks like there’s a starting point here: http://glshaders.sourceforge.net/
  • Nice progress so far. Let’s see if this video uploads…
  • solarSystem
  • Useful post on how to make a skybox with photoshop: http://www.interlopers.net/forum/viewtopic.php?f=44&t=31549
  • Going to set up a new project – ShaderLearning2
    • Use frame this time in Gl_ShaderWindow. Nope, I need Euler Angles for this.
  • Need to install R on the new server.

Phil 2.10.12

8:00 – 6:00 FP

  • Cleaning up the texture allocation scheme by going to a singleton class like Dprint. Nope, after looking into it, the glGenTextures is guaranteed to return unique handles to textures each time it’s called.
  • Pretty picture:
  • Oh, boy, I get to redo my security form! I guess that’s what I’m spending the rest of the day on.
  • But then the Internet broke, and I had my graphics book cached locally. Can’t work on forms. Darn.

Phil 2.9.12

8:00 –  4:30 FP

  • Onward to the next chapter!
  • Texture maps – we get to make shiny things…
  • Adding a callback to the main window so that textures are released on closing.
  • Textures are working! Going to make things a bit fancier tomorrow.

Phil 2.7.12

8:30 – 5:00 FP

  • Working on how to chain matrices.
  • Old-school:
  • glRotatef(eyeOrient[0], 1, 0, 0);
    glRotatef(eyeOrient[2], 0, 1, 0);
    glTranslatef(eyePos[0], eyePos[1], eyePos[2]);
    
    // global world transformations
    glTranslatef(worldPos[0], worldPos[1], worldPos[2]);
    
    glRotatef(worldOrient[0], 1, 0, 0);
    glRotatef(worldOrient[1], 0, 1, 0);
  • And How it’s done now:
  • m3dLoadIdentity44(workingMatrix);
    m3dLoadIdentity44(worldMat);
    m3dLoadIdentity44(eyeMat);
    m3dLoadIdentity44(tmat);
    m3dLoadIdentity44(rmat1);
    m3dLoadIdentity44(rmat2);
    
    // handle eyepoint transformations
    m3dRotationMatrix44(rmat1, eyeOrient[0], 1, 0, 0);
    m3dRotationMatrix44(rmat2, eyeOrient[2], 0, 1, 0);
    m3dTranslationMatrix44(tmat, eyePos[0], eyePos[1], eyePos[2]);
    
    m3dMatrixMultiply44(eyeMat, rmat2, eyeMat);
    m3dMatrixMultiply44(eyeMat, rmat1, eyeMat);
    m3dMatrixMultiply44(eyeMat, tmat, eyeMat);
    
    // handle global world transformations
    m3dTranslationMatrix44(tmat, worldPos[0], worldPos[1], worldPos[2]);
    m3dRotationMatrix44(rmat1, worldOrient[0], 1, 0, 0);
    m3dRotationMatrix44(rmat2, worldOrient[1], 0, 1, 0);
    m3dMatrixMultiply44(worldMat, rmat1, rmat2);
    m3dMatrixMultiply44(worldMat, tmat, worldMat);
    
    // combine the eye and eorld xforms
    m3dMatrixMultiply44(workingMatrix, eyeMat, worldMat);
  • Isn’t that better?
  • Ok, cleaned things up a bit, and now I’ve got something I can live with:
  • // global eye transformations
    modelViewMatrix.Rotate(eyeOrient[0], 1, 0, 0);
    modelViewMatrix.Rotate(eyeOrient[2], 0, 1, 0);
    modelViewMatrix.Translate(eyePos[0], eyePos[1], eyePos[2]);
    
    // global world transformations
    modelViewMatrix.Translate(worldPos[0], worldPos[1], worldPos[2]);
    
    modelViewMatrix.Rotate(worldOrient[0], 1, 0, 0);
    modelViewMatrix.Rotate(worldOrient[1], 0, 1, 0);
  • Putting the stage and other bits in

Phil 2.6.12

8:30 – 5:30 FP

  • Hey, it’s my 2 month anniversary of my broken leg. On the whole, progress has been pretty good.
  • Working out how to put all the matrix pieces of a shader system together.
  • After flailing for pretty much most of the day, I discovered that I had set up the view frustum incorrectly, due to a typo. Most things work, but the viewframe isn’t reset ti identity each time through. I need to revisit how to set that up.
  • This was the hint that clued me in, BTW. Yuck.