Skip to content
Snippets Groups Projects
Commit 75582ce3 authored by Ansgar Philippsen's avatar Ansgar Philippsen
Browse files

added hemilight model to fast sphere rendering

parent b3f2bf63
No related branches found
No related tags found
No related merge requests found
...@@ -150,10 +150,12 @@ void CPKRenderer::Render3DSprites() ...@@ -150,10 +150,12 @@ void CPKRenderer::Render3DSprites()
geom::Vec3 cz=irot*geom::Vec3(0.0,0.0,1.0); geom::Vec3 cz=irot*geom::Vec3(0.0,0.0,1.0);
uint write_normals = Shader::Instance().GetCurrentName()=="dumpnorm" ? 1 : 0; uint write_normals = Shader::Instance().GetCurrentName()=="dumpnorm" ? 1 : 0;
uint use_hemimodel = Shader::Instance().GetCurrentName()=="hemilight" ? 1 : 0;
Shader::Instance().PushProgram(); Shader::Instance().PushProgram();
Shader::Instance().Activate("fast_sphere"); Shader::Instance().Activate("fast_sphere");
Shader::Instance().UpdateState(); Shader::Instance().UpdateState();
glUniform1i(glGetUniformLocation(Shader::Instance().GetCurrentProgram(),"write_normals"),write_normals); glUniform1i(glGetUniformLocation(Shader::Instance().GetCurrentProgram(),"write_normals"),write_normals);
glUniform1i(glGetUniformLocation(Shader::Instance().GetCurrentProgram(),"use_hemimodel"),use_hemimodel);
glPushAttrib(GL_ALL_ATTRIB_BITS); glPushAttrib(GL_ALL_ATTRIB_BITS);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
......
...@@ -2,6 +2,7 @@ uniform bool lighting_flag; ...@@ -2,6 +2,7 @@ uniform bool lighting_flag;
uniform bool two_sided_flag; uniform bool two_sided_flag;
uniform bool fog_flag; uniform bool fog_flag;
uniform bool write_normals; uniform bool write_normals;
uniform bool use_hemimodel;
// gl_TexCoord[0] is from gl_MultiTexCoord0, which in turn // gl_TexCoord[0] is from gl_MultiTexCoord0, which in turn
// is custom crafted in the fast sphere prep routine // is custom crafted in the fast sphere prep routine
...@@ -43,16 +44,20 @@ void main() ...@@ -43,16 +44,20 @@ void main()
return; return;
} }
vec4 amb = vec4(0.0);
vec4 diff = vec4(0.0);
vec4 spec = vec4(0.0);
vec4 color = vec4(0.0); vec4 color = vec4(0.0);
if(use_hemimodel) {
color = gl_Color;
} else {
vec4 amb = vec4(0.0);
vec4 diff = vec4(0.0);
vec4 spec = vec4(0.0);
DirectionalLight(normal, gl_FrontMaterial.shininess, amb, diff, spec); DirectionalLight(normal, gl_FrontMaterial.shininess, amb, diff, spec);
color = gl_FrontLightModelProduct.sceneColor + color = gl_FrontLightModelProduct.sceneColor +
(amb * gl_FrontMaterial.ambient * gl_Color) + (amb * gl_FrontMaterial.ambient * gl_Color) +
(diff * gl_FrontMaterial.diffuse * gl_Color) + (diff * gl_FrontMaterial.diffuse * gl_Color) +
(spec * gl_FrontMaterial.specular); (spec * gl_FrontMaterial.specular);
}
if(fog_flag) { if(fog_flag) {
float fog = clamp((gl_Fog.end-(gl_FogFragCoord+z1)) * gl_Fog.scale, 0.0, 1.0); float fog = clamp((gl_Fog.end-(gl_FogFragCoord+z1)) * gl_Fog.scale, 0.0, 1.0);
......
bool use_hemimodel;
void main() void main()
{ {
// transformed position // transformed position
...@@ -9,6 +11,23 @@ void main() ...@@ -9,6 +11,23 @@ void main()
gl_TexCoord[0]=gl_MultiTexCoord0; gl_TexCoord[0]=gl_MultiTexCoord0;
gl_FrontColor=gl_Color; if(use_hemimodel) {
gl_BackColor=gl_Color; vec4 ground_color=0.2*gl_Color;
vec4 sky_color=1.0*gl_Color;
// hemisphere lighting contribution
vec3 ec_pos = vec3(gl_ModelViewMatrix* gl_Vertex);
vec3 normal = vec3(0,0,1);
if(dot(gl_Normal,gl_Normal)>0.001) {
normal = normalize(gl_NormalMatrix * gl_Normal);
}
vec3 l_dir = normalize(gl_LightSource[0].position.xyz); // assume directional vector
float a = 0.5+0.5*dot(normal,l_dir);
gl_FrontColor.rgb = mix(ground_color, sky_color, a).rgb;
gl_FrontColor.a = gl_Color.a;
gl_BackColor = gl_FrontColor;
} else {
gl_FrontColor=gl_Color;
gl_BackColor=gl_Color;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment