@@ -15,42 +15,66 @@ public class LightShader {
1515 {
1616 ambient .direction = null ;
1717 }
18-
1918 public static void addLight (Light yourLight )
2019 {
2120 diffuseLights .add (yourLight );
2221 }
2322 private static boolean currentlyRendering = false ;
24- public static void clearLights ()
23+
24+ private static boolean hideDiffuse = false ;
25+ private static boolean hideAmbient = false ;
26+ private static boolean hideSpecular = false ;
27+ private static boolean hideTexture = false ;
28+ private static boolean shadeChunky = false ;
29+ public static boolean specRdotZ = true ;
30+ private static int numberOfChunks = 3 ;
31+
32+ //public interface for settings
33+
34+ public static void setDefaults ()
2535 {
26- if (!currentlyRendering )
27- diffuseLights .clear ();
36+ hideDiffuse = false ;
37+ hideAmbient = false ;
38+ hideSpecular = false ;
39+ hideTexture = false ;
40+ shadeChunky = false ;
41+ specRdotZ = true ;
2842 }
29- public static Color shadeChunky ( Vec3f surfaceNormal , int numberOfChunks )
43+ public static void toggleChunky ( )
3044 {
31- currentlyRendering = true ;
32-
33- Color result = Color .black ;
34- for (int i = 0 ; i < diffuseLights .size (); i ++)
35- {
36- float intensity = Math .max (dot (surfaceNormal .getNormalized (), diffuseLights .get (i ).direction .getNormalized ().neg ()), 0.0f );
37- intensity = map (0 ,1 ,0 ,numberOfChunks ,intensity ).floatValue ();
38- for (int j = 0 ; j < numberOfChunks ; j ++)
39- {
40- if (Math .abs (j -intensity )<0.5 )
41- intensity = j ;
42- }
43- intensity = map (0 ,numberOfChunks , 0 ,1 , intensity ).floatValue ();
44- result = sumColor (result , scaleColor (diffuseLights .get (i ).lightColor , intensity ));
45- }
46- currentlyRendering = false ;
47- return sumColor (result , ambient .lightColor );
45+ shadeChunky = !shadeChunky ;
46+ if (shadeChunky == true )
47+ hideTexture = true ;
48+ }
49+ public static void toggleDiffuse ()
50+ {
51+ hideDiffuse = !hideDiffuse ;
52+ }
53+ public static void toggleSpec ()
54+ {
55+ hideSpecular = !hideSpecular ;
56+ }
57+ public static void toggleAmbient ()
58+ {
59+ hideAmbient = !hideAmbient ;
60+ }
61+ public static void toggleTex ()
62+ {
63+ hideTexture = !hideTexture ;
64+ }
65+ public static void toggleSpecMode ()
66+ {
67+ specRdotZ = !specRdotZ ;
4868 }
4969
70+ public static void clearLights ()
71+ {
72+ if (!currentlyRendering )
73+ diffuseLights .clear ();
74+ }
5075 public static Color shade (Vec3f normal , Vec3f interpolatedPosition , float fragSpecStregnth , Color fragDiffuseColor )
5176 {
5277 currentlyRendering = true ;
53-
5478 surfaceNormal = normal ;
5579 Color result = Color .black ;
5680 for (int i = 0 ; i < diffuseLights .size (); i ++)
@@ -59,23 +83,45 @@ public static Color shade(Vec3f normal, Vec3f interpolatedPosition, float fragSp
5983 {
6084 diffuseLights .get (i ).direction = minus (interpolatedPosition , diffuseLights .get (i ).position );
6185 }
62- result = sumColor (result , shadeDiffuseLight (diffuseLights .get (i )));
63- result = mulColor (result , 0.75f ); //scale down diffuse
64- result = sumColor (result , mulColor (diffuseLights .get (i ).lightColor ,
65- shadeSpecLight (diffuseLights .get (i ), fragSpecStregnth , interpolatedPosition )));
86+ if (shadeChunky )
87+ { //TODO : this is repeating code
88+
89+ float intensity = Math .max (dot (surfaceNormal .getNormalized (), diffuseLights .get (i ).direction .getNormalized ().neg ()), 0.0f );
90+ float specIntensity = shadeSpecLight (diffuseLights .get (i ), fragSpecStregnth , interpolatedPosition );
91+ intensity = map (0 ,1 ,0 ,numberOfChunks ,intensity ).floatValue ();
92+ specIntensity = map (0 ,1 , 0 , numberOfChunks , specIntensity ).floatValue ();
93+ for (int j = 0 ; j < numberOfChunks ; j ++)
94+ {
95+ if (Math .abs (j - intensity )<0.5 )
96+ intensity = j ;
97+ if (Math .abs (j - specIntensity )<0.5 )
98+ specIntensity = j ;
99+ }
100+ intensity = map (0 , numberOfChunks , 0 , 1 , intensity ).floatValue ();
101+ specIntensity = map (0 , numberOfChunks , 0 , 1 , specIntensity ).floatValue ();
102+ result = hideDiffuse ? result : sumColor (result , scaleColor (diffuseLights .get (i ).lightColor , intensity ));
103+ result = hideSpecular ? result : sumColor (result , mulColor (diffuseLights .get (i ).lightColor , specIntensity ));
104+ }
105+ else
106+ {
107+ result = hideDiffuse ? result : sumColor (result , shadeDiffuseLight (diffuseLights .get (i )));
108+ result = hideDiffuse ? result : mulColor (result , 0.75f ); //scale down diffuse
109+ result = hideSpecular ? result : sumColor (result , mulColor (diffuseLights .get (i ).lightColor ,
110+ shadeSpecLight (diffuseLights .get (i ), fragSpecStregnth , interpolatedPosition )));
111+ }
66112 }
67- //multiply texture once and only once. Order matters ?
68- result = mulColor (fragDiffuseColor , result );
113+ //multiply texture once and only once. Order probably matters here.
114+ result = hideTexture ? result : mulColor (fragDiffuseColor , result );
69115 currentlyRendering = false ;
70- return sumColor (result , ambient .lightColor );
116+ return hideAmbient ? result : sumColor (result , ambient .lightColor );
71117 }
72118 private static float shadeSpecLight (Light specular , float specStrength , Vec3f interpolatedPos )
73119 {
74120 Vec3f n = surfaceNormal .getNormalized ();
75121 Vec3f l = specular .direction .getNormalized ();
76122 Vec3f r = minus (l , n .scale (2.f *dot (l , n ))).getNormalized ();
77123 Vec3f v = minus (CommonTransformations .camPos , interpolatedPos ).getNormalized ();
78- float spec = max (r .z (), 0.f );
124+ float spec = max (specRdotZ ? r .z () : dot ( r , v ), 0.f );
79125 spec = (float )pow (spec , specStrength );
80126 return spec ;
81127 }
0 commit comments