why does it crash?

Started by
6 comments, last by Dragon_Strike 17 years, 6 months ago
well for some reason when i try to run a perfectly fine shader it either crashes or doesnt work as it shoud.. ive tried writing my own shader calsses but these didnt work.. so now im using Phantoms shaderclass... which for some wierd reason sometimes crashes even if i try to run what i think is working shaders... here is my current code... why do u think it crashes...


// VERTEX
#version 110

varying vec3 Vertex;

void main()
{
	Vertex = gl_Vertex.xyz;
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_TexCoord[1] = gl_MultiTexCoord1;
	gl_Position = ftransform();	
}

// FRAGMENT
#version 110

varying vec3 Vertex;

uniform sampler2D normals;
uniform float angle;
uniform vec3 ViewPos;

void main()
{	

	float RealHeight = texture2D(normals, gl_TexCoord[0].st).a;
	float GeoHeight = Vertex.y;
	
	float s = 0.042;
	float b = -s/2.0;
		
	float HeightDiff = abs(GeoHeight-RealHeight);
	float DevHeight = (HeightDiff*s)+b;	
	float ViewSlope = distance(Vertex.xz, ViewPos.xz)/distance(Vertex.y, ViewPos.y);
	
	vec2 NewTexCoord = gl_TexCoord[0].st+DevHeight*ViewSlope;
	
	vec3 Normal = texture2D(normals, gl_TexCoord[0].st).rgb*2.0-1.0;
	vec3 LightDir = vec3(-cos(angle*0.01745329), -sin(angle*0.01745329), 0.0);
	float brightnes = dot(LightDir, Normal);
	
	gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)*brightnes ;

}
_______________________________
				ShaderProgram->sendUniform("normals", 0);
				ShaderProgram->sendUniform("angle", SunAngle);
				ShaderProgram->sendUniform("ViewPos", m_Cam->Position.x, m_Cam->Position.y, m_Cam->Position.z );

				glCallList(Chunk->List);	

but for some reason it works just fine like this...


// VERTEX
#version 110

varying vec3 Vertex;

void main()
{
	Vertex = gl_Vertex.xyz;
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_TexCoord[1] = gl_MultiTexCoord1;
	gl_Position = ftransform();	
}

// FRAGMENT
#version 110

varying vec3 Vertex;

uniform sampler2D normals;
uniform float angle;

void main()
{	

	
	vec3 Normal = texture2D(normals, gl_TexCoord[0].st).rgb*2.0-1.0;
	vec3 LightDir = vec3(-cos(angle*0.01745329), -sin(angle*0.01745329), 0.0);
	float brightnes = dot(LightDir, Normal);
	
	gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)*brightnes ;

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

				glCallList(Chunk->List);	

Advertisement
define 'crashes'?
i get an unhandled exception in thsi function..

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)); <----- HERE
}
else
loc = it->second;

return loc;
}

is says "std::logic_error"... i think i sent a pm to u regarding this some time ago.. but i dont remember what u replied...

i usually get this when i create a uniform variable and send a variable to it but doesnt use it in the shader... there are few more cases that this happens.. i cnat think of them right know though..
Quote:Original post by Dragon_Strike
i usually get this when i create a uniform variable and send a variable to it but doesnt use it in the shader... there are few more cases that this happens.. i cnat think of them right know though..


This is a perfectly expected error; if you declare a uniform but don't use it then the compiler won't allocate resources for it, thus when you try to set it the above code you listed failed to find it and thus throws an exception to indicate the problem (complete with a description of what went wrong in the exception).
Quote:Original post by phantom
Quote:Original post by Dragon_Strike
i usually get this when i create a uniform variable and send a variable to it but doesnt use it in the shader... there are few more cases that this happens.. i cnat think of them right know though..


This is a perfectly expected error; if you declare a uniform but don't use it then the compiler won't allocate resources for it, thus when you try to set it the above code you listed failed to find it and thus throws an exception to indicate the problem (complete with a description of what went wrong in the exception).


sounds logical... but how do i get around it.. jsut because it cant allocate a variable without any function the shader should still work? shouldnt it?

but anyways.. back to my question then... what is wrong in the code i listed in the first post..?
ive tested some more stuff... i cant even send the cams x position without getting "std::logic_error"

EDIT:: ive tried saving the strin "s" that should describe the problem to a textfile.. but its empty..
uniform float ViewPos;void main(){		float PosX = ViewPos;        gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);}______________ShaderProgram->sendUniform("ViewPos", (float)m_Cam->Position.x);


[Edited by - Dragon_Strike on October 6, 2006 3:22:29 PM]
Have you tried using ViewPos in the vec4 which makes the final fragment colour? the compiler might be working out that you never use the float you assign it to and thus will remove it from the code and thus the uniform is again not allocated.
Quote:Original post by phantom
Have you tried using ViewPos in the vec4 which makes the final fragment colour? the compiler might be working out that you never use the float you assign it to and thus will remove it from the code and thus the uniform is again not allocated.


that might be right... ive avoided this problem by replacing GetLoc with the following...

int GLSLProgram::getLoc(const std::string &name)
{
return glGetUniformLocation(handle_, name.c_str());
}

thx

This topic is closed to new replies.

Advertisement