Jump to content

  • Log In with Google      Sign In   
  • Create Account


crims

Member Since 27 Feb 2005
Offline Last Active Sep 08 2012 12:12 AM
-----

Topics I've Started

Corporation-States

28 May 2012 - 03:28 PM

Work in progress

Latest download: http://corpstates.myftp.org/downloads/CorpStates2.zip

Website: http://www.dmdware.com

http://www.youtube.com/watch?v=SLYuyCEyTic

Pathogen

24 May 2012 - 06:28 PM

Will post updates here about my Counter-Strike 1.6 zombie infection mod-like MMOFPS project


Shadows:




Muzzle flash, flashlight:




Reloading:


GLSL spotlight problem [SOLVED]

01 May 2012 - 04:35 PM

It points correctly at 0/359 degrees but seems to rotate twice of what is necessary at other angles.

http://www.youtube.com/watch?v=AbH4h4tD62U

Is there something wrong with this?

spotEffect = dot(normalize(-lightDir), normalize(gl_LightSource[0].spotDirection));



flashlight3.vert
varying vec4 diffuse,ambientGlobal, ambient;
varying vec3 normal,lightDir,halfVector;
varying float dist;
varying vec4 ecPos;

void main()
{
vec3 aux;

normal = normalize(gl_NormalMatrix * gl_Normal);

/* now normalize the light's direction. Note that according to the
OpenGL specification, the light is stored in eye space.*/
ecPos = gl_ModelViewMatrix * gl_Vertex;
aux = vec3(gl_LightSource[0].position-ecPos);
lightDir = normalize(aux);

dist = length(aux);

halfVector = normalize(gl_LightSource[0].halfVector.xyz);

diffuse = gl_FrontMaterial.diffuse; // * gl_LightSource[0].diffuse;
ambient = gl_FrontMaterial.ambient; // * gl_LightSource[0].ambient;
ambientGlobal = gl_LightModel.ambient; // * gl_FrontMaterial.ambient;

gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord0;

gl_Position = ftransform();
}

flashlight3.frag
varying vec4 diffuse,ambientGlobal, ambient;
varying vec3 normal,lightDir,halfVector;
varying float dist;

uniform sampler2D texture1;
uniform sampler2D texture2;

void main()
{
vec3 n,halfV;
float NdotL,NdotHV;
vec4 color = vec4(0,0,0,1);
float att,spotEffect;
n = normalize(normal);

NdotL = max(dot(n,normalize(lightDir)),0.0);

if (NdotL > 0.0) {

spotEffect = dot(normalize(-lightDir), normalize(gl_LightSource[0].spotDirection));

if (spotEffect > gl_LightSource[0].spotCosCutoff) {

color += spotEffect * (diffuse * NdotL + ambient);


halfV = normalize(halfVector);
NdotHV = max(dot(n,halfV),0.0);
color += gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(NdotHV,gl_FrontMaterial.shininess);
}
}

gl_FragColor = color  * texture2D(texture1, gl_TexCoord[0].st) * texture2D(texture2, gl_TexCoord[1].st);
}

flashlight.h


// Set up light
void InitFlashlight()
{
float ambience[4] = {0.0f, 0.0f, 0.0f, 1.0};
float diffuse[4] = {1,1,1,1};
glLightfv( GL_LIGHT0, GL_AMBIENT,  ambience );
glLightfv( GL_LIGHT0, GL_DIFFUSE,  diffuse );
glLightfv( GL_LIGHT0, GL_SPECULAR,  diffuse );

glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 20.0);
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 2.0);
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.01f);
	glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.01f);
	glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.000001f);  

float LightPosition[4];
LightPosition[0] = g_Camera->Position().x;
LightPosition[1] = g_Camera->Position().y;
LightPosition[2] = g_Camera->Position().z;
LightPosition[3] = 1;

glLightfv( GL_LIGHT0, GL_POSITION, LightPosition );
glEnable(  GL_LIGHT0   );
glEnable(  GL_LIGHTING );
glEnable(GL_COLOR_MATERIAL);

   GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat mat_shininess[] = { 50.0 };
   glShadeModel (GL_SMOOTH);

   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_specular);
   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
}

// Update each frame
void UpdateFlashlight()
{
float LightPosition[4];
LightPosition[0] = g_Camera->Position().x;
LightPosition[1] = g_Camera->Position().y;
LightPosition[2] = g_Camera->Position().z;
LightPosition[3] = 1;

CVector3 direction = Normalize(g_Camera->View() - g_Camera->Position());
float LightDirection[3];
LightDirection[0] = direction.x;
LightDirection[1] = direction.y;
LightDirection[2] = direction.z;

glLightfv( GL_LIGHT0, GL_POSITION, LightPosition );
glLightfv( GL_LIGHT0, GL_SPOT_DIRECTION, LightDirection );
}

PARTNERS