Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


anujkaliaiitd

Member Since 17 Oct 2011
Offline Last Active Apr 24 2012 08:10 AM

Topics I've Started

Octrees (Ray-Triangle Intersection) help needed

20 April 2012 - 05:08 AM

Hi all!

We've implemented a hybrid shadow algorithm where shadow mapping gives us some boundary pixels which need to be further checked. One of the ways to check whether this boundary pixel is in shadow (or not) is to shoot a ray towards the light and check for intersection with the scene's triangles.

Currently, we're thinking of storing the scene in an octree (in the texture memory of the GPU). Then shoot rays from every pixel and check for intersection by traversing the octree in the fragment shader.

Can you point me to some tutorials/papers regarding such intersection detection? I couldn't find much information about how the octree should be stored in the texture, and how the octree should be traversed inside the fragment shader etc..

Shadow volume hybrid algorithm

14 April 2012 - 04:42 AM

Hi all!

We've implemented Eric Chan's hybrid algorithm for accurate shadows, and we're now taking another step. Our shadow volumes algorithm involves extruding silhouette edges in the Geometry Shader.

The question I want to ask is this:

Suppose in the Geometry Shader, we were able to check whether a silhouette edge is already in shadow (using, perhaps, the shadow map). Is it O.K to not extrude this silhouette edge? i.e. simply neglect the shadow planes that will be created when this edge is extruded? We're only dealing with watertight meshes, if that is relevant.

We expect some performance gain if we can reject some edges inside the geometry shader, as that will reduce the fragment shader's load.

Thanks for your help!

Shadow Volumes reference code

28 January 2012 - 01:39 AM

Hi!

Does someone know where I can find good code for Shadow Volumes (Z-fail using a geometry shader)? Actually I have written some code for it and it would be good to have a reference to check for bugs etc.

Applications of Shaders for a semester project

03 January 2012 - 03:38 AM

Hi!

I am searching for some cool applications of shaders (openGL) for a 4-months long college project. We want to write shaders for certain graphics applications which people sometimes do on the CPU, but which perform better when done on the GPU using shaders.

We have thought about the following 2 applications:

1)Shadow Voumes: create the shadow planes using the Geometry Shader.
2)Hardware Skinning/Animation: use vertex shaders to apply bone matrix transformations.

Can some share more interesting applications of shaders (Vertex/Geometry/Fragment) which we can consider in our project?
Thanks!

Shadow mapping: Objects are textured

12 November 2011 - 09:26 AM

I am using a shadow mapping code from Paul's Projects. It works fine for untextured objects but not for textured objects:

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <stdio.h>
#include <gl/glew.h>
#include <gl/glfw.h>
#include <gl/GLU.h>
#include "Maths/Maths.h"

GLuint textureID;
VECTOR3D cameraPosition(-2.5f, 3.5f,-2.5f);    	//Camera & light positions
VECTOR3D lightPosition(2.0f, 3.0f,-2.0f);
GLUquadricObj *quadric;		

const int shadowMapSize=600;                	//Size of shadow map
GLuint shadowMapTexture;                    	//Textures
int windowWidth, windowHeight;                	//window size

MATRIX4X4 lightProjectionMatrix, lightViewMatrix;	//Matrices
MATRIX4X4 cameraProjectionMatrix, cameraViewMatrix;

void DrawScene(float angle)
	{
	//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
	glBindTexture(GL_TEXTURE_2D,textureID);
	glPushMatrix();
		glColor3f(.8,.8,.8);
    	gluSphere(quadric,.5,50,50);
    	glTranslatef(-1,-.6,.4);
    	gluSphere(quadric,.5,50,50);
	glPopMatrix();

	glPushMatrix();
		glBegin(GL_POLYGON);
		glTexCoord2f(.5,.5);
    	glVertex2f(.5,.5);
		glTexCoord2f(.5,-.5);
    	glVertex2f(.5,-.5);
		glTexCoord2f(-.5,-.5);
		glVertex2f(-.5,-.5);
		glTexCoord2f(-.5,.5);
		glVertex2f(-.5,.5);
    	glEnd();
	glPopMatrix();
	}

bool Init(void)                                	//Called for initiation
	{
	glMatrixMode(GL_MODELVIEW);                	//Load identity modelview
	glLoadIdentity();

	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	//Depth states
	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_DEPTH_TEST);

	glEnable(GL_CULL_FACE);

	//We use glScale when drawing the scene
	glEnable(GL_NORMALIZE);

	//Create the shadow map texture
	glGenTextures(1, &shadowMapTexture);
	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize, 0,GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	//Use the color as the ambient and diffuse material
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	glEnable(GL_COLOR_MATERIAL);
   
	//White specular material color, shininess 16
	glMaterialfv(GL_FRONT, GL_SPECULAR, white);
	glMaterialf(GL_FRONT, GL_SHININESS, 16.0f);

	//Calculate & save matrices
	glPushMatrix();
   
	glLoadIdentity();
	gluPerspective(45.0f, (float)windowWidth/windowHeight, 1.0f, 100.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, cameraProjectionMatrix);
   
	glLoadIdentity();
	gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z,0.0f, 0.0f, 0.0f,0.0f, 1.0f, 0.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, cameraViewMatrix);
   
	glLoadIdentity();
	gluPerspective(45.0f, 1.0f, 2.0f, 8.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, lightProjectionMatrix);
   
	glLoadIdentity();
	gluLookAt(lightPosition.x, lightPosition.y, lightPosition.z,0.0f, 0.0f, 0.0f,0.0f, 1.0f, 0.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix);
   
	glPopMatrix();

	glGenTextures(1,&textureID);										// Generate and bind our texture ID
	printf("\n\ntextureID=%d\n",textureID);
	glBindTexture(GL_TEXTURE_2D,textureID);
	printf("check\n%d\n",glfwLoadTexture2D("ranger.tga",GLFW_BUILD_MIPMAPS_BIT|GLFW_ORIGIN_UL_BIT));
	glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR );	// Use trilinear interpolation (GL_LINEAR_MIPMAP_LINEAR)
	glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR );

	return true;
	}

//Called to draw scene
void Display(void)
	{
	printf("here");
	//First pass - from light's point of view
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(lightProjectionMatrix);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(lightViewMatrix);

	glViewport(0, 0, shadowMapSize, shadowMapSize);    	//Use viewport the same size as the shadow map   
	glCullFace(GL_FRONT);                            	//Draw back faces into the shadow map
	glShadeModel(GL_FLAT);                            	//Disable color writes, and use flat shading for speed
	glColorMask(0, 0, 0, 0);
   
	DrawScene(0);                                    	//Draw the scene

	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);    	//Read the depth buffer into the shadow map texture
	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize);

	//restore states
	glCullFace(GL_BACK);
	glShadeModel(GL_SMOOTH);
	glColorMask(1, 1, 1, 1);
   

	//2nd pass - Draw from camera's point of view
	glClear(GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(cameraProjectionMatrix);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(cameraViewMatrix);

	glViewport(0, 0, windowWidth, windowHeight);

	glLightfv(GL_LIGHT1, GL_POSITION, VECTOR4D(lightPosition));        	//Use dim light to represent shadowed areas
	glLightfv(GL_LIGHT1, GL_AMBIENT, white*0.2f);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, white*0.2f);
	glLightfv(GL_LIGHT1, GL_SPECULAR, black);
	glEnable(GL_LIGHT1);
	glEnable(GL_LIGHTING);

	DrawScene(0);
   
	//3rd pass
	glLightfv(GL_LIGHT1, GL_DIFFUSE, white);                        	//Draw with bright light
	glLightfv(GL_LIGHT1, GL_SPECULAR, white);

	//Calculate texture matrix for projection
	//This matrix takes us from eye space to the light's clip space
	//It is postmultiplied by the inverse of the current view matrix when specifying texgen
	static MATRIX4X4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f,
                            	0.0f, 0.5f, 0.0f, 0.0f,
                            	0.0f, 0.0f, 0.5f, 0.0f,
                            	0.5f, 0.5f, 0.5f, 1.0f);	//bias from [-1, 1] to [0, 1]
	MATRIX4X4 textureMatrix=biasMatrix*lightProjectionMatrix*lightViewMatrix;

	//Set up texture coordinate generation.
	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0));
	glEnable(GL_TEXTURE_GEN_S);

	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.GetRow(1));
	glEnable(GL_TEXTURE_GEN_T);

	glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix.GetRow(2));
	glEnable(GL_TEXTURE_GEN_R);

	glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.GetRow(3));
	glEnable(GL_TEXTURE_GEN_Q);

	//Bind & enable shadow map texture
	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
	glEnable(GL_TEXTURE_2D);

	//Enable shadow comparison
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);

	//Shadow comparison should be true (ie not in shadow) if r<=texture
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);

	//Shadow comparison should generate an INTENSITY result
	glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);

	//Set alpha test to discard false comparisons
	glAlphaFunc(GL_GEQUAL, 0.99f);
	glEnable(GL_ALPHA_TEST);

	DrawScene(0);

	//Disable textures and texgen
	glDisable(GL_TEXTURE_2D);

	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);
	glDisable(GL_TEXTURE_GEN_R);
	glDisable(GL_TEXTURE_GEN_Q);

	//Restore other states
	glDisable(GL_LIGHTING);
	glDisable(GL_ALPHA_TEST);

	glfwSwapBuffers();
	}

//Called on window resize
void Reshape(int w, int h)
	{
	windowWidth=w, windowHeight=h;
	glPushMatrix();
	glLoadIdentity();
	gluPerspective(45.0f, (float)windowWidth/windowHeight, 1.0f, 100.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, cameraProjectionMatrix);
	glPopMatrix();
	}

int main(int argc, char** argv)
	{
	glfwInit();												//start using glfw library
	glfwOpenWindowHint(GLFW_FSAA_SAMPLES,4);					
	glfwOpenWindow(400,400,0,0,0,0,0,0,GLFW_WINDOW );		
	glfwSetWindowTitle( "anuj" );
	Reshape(400,400);
	quadric = gluNewQuadric();
	gluQuadricTexture(quadric,GL_TRUE);

	Init();
	glewInit();
	while(1)
		Display();
	return 0;
	}

I think the problem starts here when the program binds "shadowMapTexture"
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
glEnable(GL_TEXTURE_2D);

However, the first line of my drawScene function binds it to a different texture:
glBindTexture(GL_TEXTURE_2D,textureID);

"textureID" is the texture I want to appear on my spheres.

So, I can't use shadowMapTexture? Is there an alternative?

PARTNERS