Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎯 Unreal

shader problems

Started by Dragon_Strike Sep 23, 2006 at 4:57 PM 0 replies 900+ views
Original Post
Dragon_Strike
Dragon_Strike
ive got some shader problems again... the following shader WORKS


//vertex
#version 110

void main()
{
	
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_Position = ftransform();	
}

//fragment
#version 110

uniform sampler2D normals;
uniform float angle;

void main()
{
	vec3 normal = texture2D(normals, gl_TexCoord[0].st).rgb*2.0-1.0; // get normal from floating point texture
	float horizon = texture2D(normals, gl_TexCoord[0].st).a; // get horizon
	
	vec3 Sun = vec3(-cos(radians(angle)), -sin(radians(angle)), 0.0);// get sun normal
	float SunRay = abs(Sun.y/Sun.x); // get sunslope
	 
	float brightness = dot(Sun , normal);// lambertian lighting
	

	brightness *= max(sign(SunRay-horizon),0); // if sun slope is below horizonslope then brightness *= 0 else brightness *= 1
		
	gl_FragColor = vec4(brightness,brightness,brightness,1.0); // set brightness
}


but when i rewrite it to calcualte the shadows per vertex.. it DOESNT work

// vertex
#version 110


uniform sampler2D normals;
uniform float angle;
varying float shadow;

void main()
{
	horizon = texture2D(normals, gl_TexCoord[0].st).a;
	
	vec3 Sun = vec3(-cos(radians(angle)), -sin(radians(angle)), 0.0);
	float SunRay = abs(Sun.y/Sun.x);
	
	shadow = max(sign(SunRay-horizon),0); 
	
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_Position = ftransform();	
}

//fragment

#version 110

uniform sampler2D normals;
uniform float angle;
varying float shadow;

void main()
{
	vec3 normal = texture2D(normals, gl_TexCoord[0].st).rgb*2.0-1.0; // get normals form flaoting oint texture
		
	vec3 Sun = vec3(-cos(radians(angle)), -sin(radians(angle)), 0.0); // get sun normal
	float SunRay = abs(Sun.y/Sun.x); // get sun slope
	 
	float brightness = (dot(Sun , normal))*shadow; // lambertian lighting
	
	gl_FragColor = vec4(brightness,brightness,brightness,1.0); 
}


the program just crashes and i get an empy shaderprogram error log... it crashes at the following code...

	ShaderProgram->sendUniform("angle", SunAngle);
	ShaderProgram->sendUniform("normals", 0);

	glCallList(Chunk->List);	
_________________________________________________

void GLSLProgram::sendUniform(const std::string &name, float x)
{
	glUniform1f(getLoc(name), x);
}



int GLSLProgram::getLoc(const std::string &name)
{
	int loc = -1;
	uniformmap::const_iterator it = uniforms_.find(name);
	if(it == uniforms_.end())
	{
		loc = glGetUniformLocation(handle_, name.c_str());
		if(loc == -1)
		{
			std::string s;
			s.append(name);
			s.append(" - is not a valid uniform variable name");
			throw logic_error(s);
		}
		uniforms_.insert(uniformmap::value_type(name,loc)); // THIS IS WHERE I GET THE ACCESS VIOLATION
	}
	else
		loc = it->second;

	return loc;
}





Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.