• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

# _Unicron_

Member Since 08 Mar 2007
Offline Last Active Oct 14 2013 12:21 PM

### Hybrid ortho/perspective view frustum

20 December 2012 - 02:27 PM

I am trying to create an effect where the view frustum provides a perspective effect along the x-axis, but an orthographic effect along the y-axis.

Think of a perspective view frustum but where the top and bottom faces run parallel to each other. Does anyone know how I an achieve this effect?

### Atmospheric Scattering

30 June 2011 - 06:30 PM

I'm trying to implement atmospheric scattering using O'Neill's algorithm from GPU gems 2. I only need to render the atmosphere from the ground. To do this I create a half sphere of radius 6.53745. In the shaders I have hard-coded all of the parameters while I try and get something working. Due to the player remaining at ground level I have also hard-coded the camera position within the vertex shader to be at the planet radius.

Here is the vertex shader (GLSL):
```uniform mat4 mvp;
uniform mat4 mv;

const vec3 v3CameraPos   		= vec3(0.0, 0.0, 6.378);																			// The camera's current position
const vec3 v3LightPos                 = normalize(vec3(0.0, 0.0, 1.0));																// The direction vector to the light source
const vec3 v3InvWavelength   	= vec3(1.0 / pow(0.650, 4.0), 1.0 / pow(0.570, 4.0), 1.0 / pow(0.475, 4.0));		// 1 / pow(wavelength, 4) for the red, green, and blue channels
const float fCameraHeight        = 6.378;																									// The camera's current height
const float fCameraHeight2   	= 6.378 * 6.378;																						// fCameraHeight^2
const float fKrESun              = 0.0025 * 15.0;																						// Kr * ESun
const float fKmESun              = 0.0015 * 15.0;																						// Km * ESun
const float fKr4PI   			= 0.0025 * 4.0 * 3.1415;																			// Kr * 4 * PI
const float fKm4PI   			= 0.0015 * 4.0 * 3.1415;																			// Km * 4 * PI
const float fScale   			= 1.0 / (6.53745 - 6.378);																			// 1 / (fOuterRadius - fInnerRadius)
const float fScaleDepth          = 0.25;																									// The scale depth (i.e. the altitude at which the atmosphere's average density is found)
const float fScaleOverScaleDepth = (1.0 / (6.53745 - 6.378)) / 0.25;																// fScale / fScaleDepth

const int nSamples = 2;
const float fSamples = 2.0;

varying vec3 v3Direction;

float scale(float fCos)
{
float x = 1.0 - fCos;
return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
}

void main(void)
{
// Get the ray from the camera to the vertex, and its length (which is the far point of the ray passing through the atmosphere)
vec3 v3Pos = gl_Vertex.xyz;
vec3 v3Ray = v3Pos - v3CameraPos;
float fFar = length(v3Ray);
v3Ray /= fFar;

// Calculate the ray's starting position, then calculate its scattering offset
vec3 v3Start = v3CameraPos;
float fHeight = length(v3Start);
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fCameraHeight));
float fStartAngle = dot(v3Ray, v3Start) / fHeight;
float fStartOffset = fDepth*scale(fStartAngle);

// Initialize the scattering loop variables
float fSampleLength = fFar / fSamples;
float fScaledLength = fSampleLength * fScale;
vec3 v3SampleRay = v3Ray * fSampleLength;
vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;

// Now loop through the sample rays
vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);
for(int i=0; i<nSamples; i++)
{
float fHeight = length(v3SamplePoint);
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
float fLightAngle = dot(v3LightPos, v3SamplePoint) / fHeight;
float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;
float fScatter = (fStartOffset + fDepth*(scale(fLightAngle) - scale(fCameraAngle)));
vec3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
v3SamplePoint += v3SampleRay;
}

// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
gl_FrontSecondaryColor.rgb = v3FrontColor * fKmESun;
gl_FrontColor.rgb = v3FrontColor * (v3InvWavelength * fKrESun);
gl_Position = mvp * gl_Vertex;
v3Direction = v3CameraPos - v3Pos;
}
```

```
const vec3 v3LightPos = normalize(vec3(0.0, 0.0, 1.0));
const float g 		= -0.95;
const float g2        = -0.95 * -0.95;

varying vec3 v3Direction;

void main (void)
{
float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);
float fRayleighPhase = 0.75 * (1.0 + fCos*fCos);
float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos*fCos) / pow(1.0 + g2 - 2.0*g*fCos, 1.5);
gl_FragColor = fRayleighPhase * gl_Color + fMiePhase * gl_SecondaryColor;
}
```

This is the output I get (when looking up). Just a hit of blue at the top of the sky dome and a grey-white color everywhere else:

Can anyone see where I am going wrong?

### Rendering the depth buffer to texture using a FBO

10 January 2010 - 02:07 AM

Hi guys, I'm having trouble implementing a basic shadow mapping algorithm. At the moment I am trying to render the depth buffer to a texture and then render it to see if it is correct. I have been following the guide from here: http://www.fabiensanglard.net/shadowmapping/index.php When I render the depth texture to a quad I'm getting nothing. I have had render to texture working by rendering the colour buffer to texture and using the a renderbuffer for the depth. Here is the code I use to set up the texture and the FBO:-
```void Scene::generateShadowFBO()
{

GLenum FBOstatus;
glActiveTexture(GL_TEXTURE0);

glGenTextures(1, &m_depthTexture);
glBindTexture(GL_TEXTURE_2D, m_depthTexture);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);

// create a framebuffer object

// Instruct openGL that we won't bind a color texture with the currently binded FBO
glDrawBuffer(GL_NONE);

// attach the texture to FBO depth attachment point
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D, m_depthTexture, 0);

// check FBO status
FBOstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(FBOstatus != GL_FRAMEBUFFER_COMPLETE)
printf("GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO\n");

// switch back to window-system-provided framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
}

```
I then render the fbo pass using:-
```	glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
glClear(GL_DEPTH_BUFFER_BIT);
glCullFace(GL_BACK);
```
Then to render the texture to a quad I use:-
```	glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
```
The texture and viewport sizes are all the same and the fbo status test is saying it is complete. Can anyone see anything glaringly obvious that I am missing?

### Problems creating new application with VS on Vista

11 July 2009 - 09:31 AM

Not strictly a programming problem but couldn't see of a more appropriate board to post on. Anyway.... I'm having a problem creating Win32 console or Windows apps. When I try to create the application two windows pop up -- One saying the navigation to the current page has been cancelled and the other opening up my browser with the project settings. However, the browser with the settings is not complete (there are actually no option, whereas you usually get MFC, blank proj etc..) . There is a finish button but it does nothing. This problem occurs on both VS2005 pro and VS2008 pro and is really p*ssing me off. It's a pain having to create a project on my laptop so that I can transfer it onto my main dev machine. However, I can create c# Windows Forms Applications just fine : I get the feeling this is actually some permission problem with Vista as a very similar thing happened when installing SP1 and repairing the VS installation. Anyone seen this or have any idea on how to fix it. I came across one guy who had the same problem after many hours of trying to fix it (and Ive lost the link now :@), but MS basically gave the response that they couldnt reproduce the problem and so no solution was given :( Uni

### Efficient height calculation for walking on terrain

15 July 2008 - 10:48 AM

I am creating a simple fps and Im trying to decide on the best method of determining the height of the player due to the terrain. The terrain is generated from a heightmap and so it is essentially a set of height values on a cartesian grid. With this in mind, I get the player x,z coordinates to find which height values are relevant with respect to the current player position. Now, Im unsure of the best method for determining the height. Am I better of using collision testing and pushing the player up when the bounding box collides with the terrain? or simply interpolating between the height values and setting the players height position (y-value) that way. Both methods seem to work to me but Im not sure which is the most commonly used approach (im leaning towards interpolation looking easier, but want to make sure Im not missing something), or if another method completely is used :)

PARTNERS