Skip to content
Snippets Groups Projects
Commit 560513f4 authored by anikhalder's avatar anikhalder
Browse files

Implement separate conditions for drawing 3D axes and objects

parent c4b15039
No related branches found
No related tags found
No related merge requests found
...@@ -2,29 +2,40 @@ uniform highp vec3 lightPos1; ...@@ -2,29 +2,40 @@ uniform highp vec3 lightPos1;
uniform highp vec4 color; uniform highp vec4 color;
uniform highp float ambient; uniform highp float ambient;
uniform highp vec3 eye; uniform highp vec3 eye;
uniform highp bool axis;
varying highp vec3 vo, nm; varying highp vec3 vo, nm, ac;
void main() { void main() {
// ambient if (axis)
highp vec3 amb_col = ambient * color.rgb; {
// for drawing colored 3D axes
gl_FragColor = vec4(ac, 1.0);
}
else
{
// for drawing 3D objects
// diffuse // ambient
highp vec3 L1 = normalize(lightPos1 - vo); highp vec3 amb_col = ambient * color.rgb;
highp vec3 N = normalize(nm);
highp float NL_sum = dot(N,L1);
highp float NL = 0.6*max(0.0, NL_sum);
highp vec3 diff_col = NL * color.rgb;
// specular // diffuse
float spec = 0.0; highp vec3 L1 = normalize(lightPos1 - vo);
highp vec3 E = normalize(eye-vo); highp vec3 N = normalize(nm);
highp float ELN1 = pow(max(0.0, dot(E, reflect(-L1, N))), 20.0); highp float NL_sum = dot(N,L1);
if(NL > 0.0) highp float NL = 0.6*max(0.0, NL_sum);
spec = ELN1; highp vec3 diff_col = NL * color.rgb;
vec3 spec_col = spec * vec3(1.0, 1.0, 1.0);
highp vec3 tot_col = amb_col + diff_col + spec_col; // specular
highp vec4 C = vec4(tot_col, color.a); float spec = 0.0;
gl_FragColor = clamp(C, 0.0, 1.0); highp vec3 E = normalize(eye-vo);
highp float ELN1 = pow(max(0.0, dot(E, reflect(-L1, N))), 20.0);
if(NL > 0.0)
spec = ELN1;
vec3 spec_col = spec * vec3(1.0, 1.0, 1.0);
highp vec3 tot_col = amb_col + diff_col + spec_col;
highp vec4 C = vec4(tot_col, color.a);
gl_FragColor = clamp(C, 0.0, 1.0);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment