├── .gitignore
├── README.md
├── data
├── MatCapZBrush
│ ├── Lib
│ │ ├── 755_large.jpg
│ │ ├── 93e1bbcf77ece0c0f7fc79ecb8ff0d00.png
│ │ ├── 944_large_remake2.jpg
│ │ ├── BazC_SkinMat.jpg
│ │ ├── Bronze.png
│ │ ├── Copper.png
│ │ ├── Gloss_Black.png
│ │ ├── JG_Drink01.png
│ │ ├── Jade_Light.png
│ │ ├── MatcapBronze.jpg
│ │ ├── MatcapQuartz.jpg
│ │ ├── Shiny_Fire_1c.png
│ │ ├── _00_material3.jpg
│ │ ├── _00_material3_.png
│ │ ├── _01_egg.png
│ │ ├── droplet_01.png
│ │ ├── green_glass_860.png
│ │ ├── greencarpaint_alpha.jpg
│ │ ├── mydarkgreymetal_zbrush_matcap_by_digitalinkrod.jpg
│ │ ├── mygreenmetal_zbrush_matcap_by_digitalinkrod.jpg
│ │ ├── myredmetal_zbrush_matcap_by_digitalinkrod.jpg
│ │ ├── skin1.jpg
│ │ ├── skin2.jpg
│ │ ├── thuglee-chrome-02b.jpg
│ │ └── white.jpg
│ ├── MatCap.v4p
│ └── effects
│ │ └── litSphere.fx
└── shaders
│ ├── litsphere
│ ├── frag.glsl
│ └── vert.glsl
│ └── phong
│ ├── frag.glsl
│ └── vert.glsl
├── example
├── addons.make
└── src
│ ├── main.cpp
│ ├── ofApp.cpp
│ └── ofApp.h
├── example_displacement
├── addons.make
└── src
│ ├── DisplacementSphereMesh.cpp
│ ├── DisplacementSphereMesh.h
│ ├── main.cpp
│ ├── ofApp.cpp
│ └── ofApp.h
├── ofxaddons_thumbnail.png
└── src
├── ofxLitSphere.cpp
└── ofxLitSphere.h
/.gitignore:
--------------------------------------------------------------------------------
1 | *exampleDebug.app
2 | *DS_Store
3 |
4 | *.app
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ofxLitSphere
2 | =============================
3 | This port of vvvv contribution can help create nice material in OpenFrameworks.
4 |
5 | http://vvvv.org/contribution/matcap™-technique-from-zbrush
6 |
7 |
8 | 
9 |
10 | demo:
11 | https://vimeo.com/100656279
12 |
13 | WebGL demo http://arthew0.online/cc/js/js.projects/sphere_dance/
14 |
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/755_large.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/755_large.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/93e1bbcf77ece0c0f7fc79ecb8ff0d00.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/93e1bbcf77ece0c0f7fc79ecb8ff0d00.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/944_large_remake2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/944_large_remake2.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/BazC_SkinMat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/BazC_SkinMat.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/Bronze.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/Bronze.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/Copper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/Copper.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/Gloss_Black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/Gloss_Black.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/JG_Drink01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/JG_Drink01.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/Jade_Light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/Jade_Light.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/MatcapBronze.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/MatcapBronze.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/MatcapQuartz.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/MatcapQuartz.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/Shiny_Fire_1c.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/Shiny_Fire_1c.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/_00_material3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/_00_material3.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/_00_material3_.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/_00_material3_.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/_01_egg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/_01_egg.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/droplet_01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/droplet_01.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/green_glass_860.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/green_glass_860.png
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/greencarpaint_alpha.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/greencarpaint_alpha.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/mydarkgreymetal_zbrush_matcap_by_digitalinkrod.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/mydarkgreymetal_zbrush_matcap_by_digitalinkrod.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/mygreenmetal_zbrush_matcap_by_digitalinkrod.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/mygreenmetal_zbrush_matcap_by_digitalinkrod.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/myredmetal_zbrush_matcap_by_digitalinkrod.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/myredmetal_zbrush_matcap_by_digitalinkrod.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/skin1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/skin1.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/skin2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/skin2.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/thuglee-chrome-02b.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/thuglee-chrome-02b.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/Lib/white.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/data/MatCapZBrush/Lib/white.jpg
--------------------------------------------------------------------------------
/data/MatCapZBrush/MatCap.v4p:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
--------------------------------------------------------------------------------
/data/MatCapZBrush/effects/litSphere.fx:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////////////////
2 | // litSphere.fx
3 | // Matballz.fx
4 | //
5 | // Shader by Charles Hollemeersch http://charles.hollemeersch.net/
6 | // Public domain.
7 | //
8 | // Parameters:
9 | //
10 | // Bumpmap Strength: Scales the bumps to be flatter/steeper
11 | // (i.e. more/less towards 0,0,1).
12 | // Normal Map : Provides a bumpmap if no map is provided the
13 | // geometry normal is used.
14 | // Lit Sphere Map : The prelighted sphere to apply as a light. Check
15 | // http://www.cs.utah.edu/npr/papers/LitSphere_HTML/
16 | // to get some inspiration.
17 | //
18 | // Edited: 12/13/2009 - Leonardo Covarrubias - For use in Maya
19 | //
20 | //
21 | ////////////////////////////////////////////////////////////////////////
22 |
23 |
24 |
25 | ////////////////////////
26 | // User interface
27 | ////////////////////////
28 |
29 | float normalPower <
30 | string UIName = "Bumpmap Strength";
31 | string UIWidget = "slider";
32 | float UIMin = 0.0;
33 | float UIMax = 2.0;
34 | float UIStep = 0.1;
35 | > = 1.0;
36 |
37 | bool flipGreen
38 | <
39 | string UIName = "Invert Normal Map Green Channel?";
40 | > = false;
41 |
42 | texture normalMap : Normal <
43 | string UIName = "Normal Map";
44 | string ResourceName = "";
45 | string ResourceType = "2D";
46 | >;
47 |
48 | texture litSphereMap : LitSphere <
49 | string UIName = "Lit Sphere Map";
50 | string ResourceName = "";
51 | string ResourceType = "2D";
52 | >;
53 |
54 | ////////////////////////
55 | // Samplers
56 | ////////////////////////
57 |
58 | sampler NormalSampler = sampler_state {
59 | Texture = ;
60 | MIPFILTER = LINEAR;
61 | MINFILTER = LINEAR;
62 | MAGFILTER = LINEAR;
63 | AddressU = CLAMP;
64 | AddressV = CLAMP;
65 | };
66 |
67 | sampler LightSampler = sampler_state {
68 | Texture = ;
69 | MIPFILTER = LINEAR;
70 | MINFILTER = LINEAR;
71 | MAGFILTER = LINEAR;
72 | AddressU = CLAMP;
73 | AddressV = CLAMP;
74 | };
75 |
76 | ////////////////////////
77 | // Matrices
78 | ////////////////////////
79 |
80 | float4x4 WorldView : WORLDVIEW;
81 | float4x4 WorldViewProjection : WORLDVIEWPROJECTION;
82 |
83 | ////////////////////////
84 | // Exchange structs
85 | ////////////////////////
86 |
87 | struct a2v
88 | {
89 | float4 Position : POSITION;
90 | float2 TexCoord : TEXCOORD0;
91 | float3 Tangent : TANGENT;
92 | float3 Binormal : BINORMAL;
93 | float3 Normal : NORMAL;
94 | };
95 |
96 | struct v2f
97 | {
98 | float4 Position : POSITION;
99 | float2 TexCoord : TEXCOORD0;
100 | float3 TexCoord1 : TEXCOORD1;
101 | float3 TexCoord2 : TEXCOORD2;
102 | float3 TexCoord3 : TEXCOORD3;
103 | };
104 |
105 | ////////////////////////
106 | // Vertex shader
107 | ////////////////////////
108 |
109 | v2f BumpReflectVS(a2v IN)
110 | {
111 | v2f OUT;
112 |
113 | // Pos to NDC
114 | OUT.Position = mul(float4(IN.Position.xyz,1), WorldViewProjection);
115 |
116 | // Texcoords (for normal map)
117 | OUT.TexCoord.xy = IN.TexCoord;
118 |
119 | // Tangent space vectors
120 | float3 vtan = IN.Tangent;
121 | float3 vbinorm = -IN.Binormal;
122 | float3 vnorm = IN.Normal;
123 |
124 | OUT.TexCoord1.xyz = mul(vtan,WorldView);
125 | OUT.TexCoord2.xyz = mul(vbinorm,WorldView);
126 | OUT.TexCoord3.xyz = mul(vnorm,WorldView);
127 |
128 | return OUT;
129 | }
130 |
131 | ////////////////////////
132 | // Pixel shader
133 | ////////////////////////
134 |
135 | float4 BumpReflectPS(v2f IN) : COLOR {
136 |
137 | float3 texNormal = tex2D(NormalSampler, IN.TexCoord.xy).xyz;
138 | if(flipGreen)texNormal.g = 1-texNormal.g;
139 | texNormal.rgb = texNormal.rgb*2.0-1.0;
140 | // Fixes normals if no normal map texture is supplied
141 | if ( dot(texNormal,texNormal) > 2.0 ) {
142 | texNormal = float3(0,0,1);
143 | }
144 |
145 | // The normalizes can probably go away... but meh...
146 | float3 T = normalize(IN.TexCoord1.xyz) * normalPower;
147 | float3 B = normalize(IN.TexCoord2.xyz) * normalPower;
148 | float3 N = normalize(IN.TexCoord3.xyz);
149 |
150 | // Put in world space and renormalize (after scaling)
151 | float3 worldNorm = normalize(N + texNormal.y * B + texNormal.x * T);
152 |
153 | // Swap it around a bit...
154 | worldNorm.y = - worldNorm.y;
155 |
156 | // Look up in the litsphere!
157 | float3 light = tex2D(LightSampler, worldNorm.xy * 0.5 + 0.5).xyz;
158 | return float4( light, 1.0 );
159 | }
160 |
161 | ////////////////////////
162 | // Pixel shader
163 | ////////////////////////
164 |
165 | technique litSphere
166 | {
167 | pass one
168 | {
169 | VertexShader = compile vs_2_0 BumpReflectVS();
170 | PixelShader = compile ps_2_0 BumpReflectPS();
171 | }
172 | }
173 |
174 |
--------------------------------------------------------------------------------
/data/shaders/litsphere/frag.glsl:
--------------------------------------------------------------------------------
1 | //#version 120
2 |
3 | //uniform sampler2DRect litsphereTexture;
4 | uniform sampler2D litsphereTexture;
5 |
6 | varying vec2 texCoord;
7 | varying vec3 position;
8 | varying vec3 normal;
9 |
10 | void main (void)
11 | {
12 | vec3 eyeNormal = normal;
13 | vec3 L = normalize(gl_LightSource[0].position.xyz - position);
14 | vec3 E = normalize(-position); // we are in Eye Coordinates, so EyePos is (0,0,0)
15 | vec3 R = normalize(-reflect(L, eyeNormal));
16 |
17 | //calculate Ambient Term:
18 | vec4 Iamb = gl_FrontLightProduct[0].ambient;
19 |
20 | //calculate Diffuse Term:
21 | vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(eyeNormal, L), 0.0);
22 | Idiff = clamp(Idiff, 0.0, 1.0);
23 |
24 | // calculate Specular Term:
25 | vec4 Ispec = gl_FrontLightProduct[0].specular * pow(max(dot(R, E), 0.0),0.3 * gl_FrontMaterial.shininess);
26 | Ispec = clamp(Ispec, 0.0, 1.0);
27 |
28 | vec4 shading = texture2D(litsphereTexture, vec2(normal.xyz * vec3(0.495) + vec3(0.5)));
29 | gl_FragColor = (gl_FrontLightModelProduct.sceneColor + Iamb + Idiff + Ispec) * shading + Ispec;// + color;
30 | }
--------------------------------------------------------------------------------
/data/shaders/litsphere/vert.glsl:
--------------------------------------------------------------------------------
1 | //#version 120
2 |
3 | varying vec2 texCoord;
4 | varying vec3 position;
5 | varying vec3 normal;
6 |
7 | void main()
8 | {
9 | gl_FrontColor = gl_Color;
10 | gl_Position = gl_Vertex;
11 | gl_Position = ftransform();
12 |
13 | position = vec3(gl_ModelViewMatrix * gl_Vertex);
14 | normal = normalize(gl_NormalMatrix * gl_Normal);
15 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
16 |
17 | gl_TexCoord[0] = gl_MultiTexCoord0;
18 | texCoord = gl_MultiTexCoord0.st;
19 | }
20 |
--------------------------------------------------------------------------------
/data/shaders/phong/frag.glsl:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | uniform sampler2D litsphereTexture;
4 |
5 | varying vec2 texCoord;
6 | varying vec3 position;
7 | varying vec3 normal;
8 |
9 | void main (void)
10 | {
11 | // gl_FragColor = gl_Color;
12 |
13 | vec3 eyeNormal = normal;
14 | vec3 L = normalize(gl_LightSource[0].position.xyz - position);
15 | vec3 E = normalize(-position); // we are in Eye Coordinates, so EyePos is (0,0,0)
16 | vec3 R = normalize(-reflect(L, eyeNormal));
17 |
18 | //calculate Ambient Term:
19 | vec4 Iamb = gl_FrontLightProduct[0].ambient;
20 |
21 | //calculate Diffuse Term:
22 | vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(eyeNormal, L), 0.0);
23 | Idiff = clamp(Idiff, 0.0, 1.0);
24 |
25 | // calculate Specular Term:
26 | vec4 Ispec = gl_FrontLightProduct[0].specular * pow(max(dot(R, E), 0.0),0.3 * gl_FrontMaterial.shininess);
27 | Ispec = clamp(Ispec, 0.0, 1.0);
28 |
29 | // vec4 shading = texture2D(litsphereTexture, vec2(normal.xyz * vec3(0.495) + vec3(0.5)));
30 |
31 | vec4 color = texture2D(litsphereTexture, texCoord);
32 | gl_FragColor = gl_FrontLightModelProduct.sceneColor + Iamb + Idiff + Ispec + color;// + color;
33 | // gl_FragColor = shading;
34 | }
--------------------------------------------------------------------------------
/data/shaders/phong/vert.glsl:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | uniform sampler2D litsphereTexture;
4 |
5 | varying vec2 texCoord;
6 | varying vec3 position;
7 | varying vec3 normal;
8 |
9 | void main()
10 | {
11 | gl_FrontColor = gl_Color;
12 | gl_TexCoord[0] = gl_MultiTexCoord00
13 | gl_Position = gl_Vertex;
14 |
15 | texCoord = vec2(gl_MultiTexCoord);
16 |
17 | position = vec3(gl_ModelViewMatrix * gl_Vertex);
18 | normal = normalize(gl_NormalMatrix * gl_Normal);
19 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
20 | }
21 |
--------------------------------------------------------------------------------
/example/addons.make:
--------------------------------------------------------------------------------
1 | ofxLitSphere
2 |
--------------------------------------------------------------------------------
/example/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
7 |
8 | // this kicks off the running of my app
9 | // can be OF_WINDOW or OF_FULLSCREEN
10 | // pass in width and height too:
11 | ofRunApp(new ofApp());
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/example/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup(){
5 | ofSetDataPathRoot("../../../../../data/");
6 |
7 | ofDisableArbTex();
8 | ofEnableDepthTest();
9 | ofSetVerticalSync(true);
10 | litSphere.setup();
11 | ofSetConeResolution(40, 40, 40);
12 | }
13 |
14 | //--------------------------------------------------------------
15 | void ofApp::update(){
16 |
17 | }
18 |
19 | //--------------------------------------------------------------
20 | void ofApp::draw(){
21 | ofClear(0);
22 | ofPushMatrix();
23 | ofScale(2, 2);
24 | ofBackgroundGradient(ofColor(180), ofColor(70), OF_GRADIENT_CIRCULAR);
25 | ofPopMatrix();
26 |
27 | litSphere.begin();
28 | ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
29 | ofRotateX(ofGetFrameNum());
30 | ofDrawCone(100, 140);
31 | ofDrawSphere(200, 0, 70);
32 | ofDrawBox(-200, 0, 0, 80);
33 | litSphere.end();
34 |
35 | ofDrawBitmapStringHighlight("click to change sourse", ofPoint(0, 0));
36 | }
37 |
38 |
39 | //--------------------------------------------------------------
40 | void ofApp::mousePressed(int x, int y, int button){
41 | litSphere.loadNext();
42 | }
43 |
--------------------------------------------------------------------------------
/example/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxLitSphere.h"
5 |
6 | class ofApp : public ofBaseApp{
7 |
8 | public:
9 | void setup();
10 | void update();
11 | void draw();
12 |
13 | void mousePressed(int x, int y, int button);
14 |
15 | ofxLitSphere litSphere;
16 | };
17 |
--------------------------------------------------------------------------------
/example_displacement/addons.make:
--------------------------------------------------------------------------------
1 | ofxLitSphere
2 |
--------------------------------------------------------------------------------
/example_displacement/src/DisplacementSphereMesh.cpp:
--------------------------------------------------------------------------------
1 | #include "DisplacementSphereMesh.h"
2 |
3 | void DisplacementSphereMesh::setup() {
4 |
5 | settings = new ofParameterGroup();
6 | settings->setName("displacement");
7 | settings->add(details.set("details", 0.06, 0 ,1));
8 | settings->add(displace.set("displace", 0.8, 0, 1));
9 | settings->add(speed.set("speed", 0.1, 0 ,1));
10 |
11 | sphere.setRadius(150);
12 | sphere.setResolution(96);
13 | mainMesh = sphere.getMesh();
14 | depths = new float[sphere.getMesh().getNumVertices()];
15 | speeds = new float[sphere.getMesh().getNumVertices()];
16 | forces = new float[sphere.getMesh().getNumVertices()];
17 | for (int i = 0; i < sphere.getMesh().getNumVertices(); i++) {
18 | depths[i] = sphere.getMesh().getVertices()[i].length();
19 | speeds[i] = 0;
20 | forces[i] = 0;
21 | }
22 | }
23 |
24 | void DisplacementSphereMesh::update() {
25 | mainMesh = sphere.getMesh();
26 | float time = speed * ofGetElapsedTimef();
27 | for (int i = 0; i < mainMesh.getNumVertices(); i++) {
28 | ofVec3f v = mainMesh.getVertex(i);
29 | float d = ofNoise(v.x * details * 0.1, v.y * details * 0.1, time) * displace * 100.0;
30 | //displace += 10.0 * ofNoise(v.x * 0.01, v.y * 0.01, time * .3);
31 | v = v + mainMesh.getNormal(i) * d;
32 | mainMesh.setVertex(i, v);
33 | }
34 | setNormals(mainMesh);
35 | }
36 |
37 | void DisplacementSphereMesh::draw(bool triagles, bool type) {
38 | ofSetHexColor(0xffffff);
39 | ofPushMatrix();
40 | ofRotate(180, 0, 1, 0);
41 | if (type == true) ofRotate(180, 0, 1, 0);
42 | if (!triagles)
43 | mainMesh.drawFaces();
44 |
45 | ofSetHexColor(0x333333);
46 | ofSetLineWidth(1.0);
47 | ofEnableSmoothing();
48 | if (triagles)
49 | mainMesh.drawWireframe();
50 | ofSetHexColor(0xffffff);
51 | ofPopMatrix();
52 | }
53 |
54 | void DisplacementSphereMesh::setNormals( ofMesh &mesh ){
55 | int nV = mesh.getNumVertices();
56 | int nT = mesh.getNumIndices() / 3;
57 | vector norm( nV ); //Array for the normals
58 | for (int t=0; t details;
10 | ofParameter displace;
11 | ofParameter speed;
12 |
13 | // From GUI
14 | float positionX;
15 | float positionY;
16 |
17 | //OSC
18 | bool isPlaying;
19 | float touch_power;
20 |
21 | // Mesh
22 | ofLight light;
23 | ofEasyCam cam;
24 | ofVboMesh mainMesh;
25 |
26 | float *depths;
27 | float *speeds;
28 | float *forces;
29 |
30 | ofSpherePrimitive sphere;
31 |
32 | void setup();
33 | void update();
34 | void draw(bool triagles = false, bool type = false);
35 | void setNormals(ofMesh &mesh);
36 | };
37 |
--------------------------------------------------------------------------------
/example_displacement/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofSetupOpenGL(1280, 720, OF_WINDOW);
7 | ofRunApp(new ofApp());
8 | }
9 |
--------------------------------------------------------------------------------
/example_displacement/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup(){
5 |
6 | ofSetDataPathRoot("../../../../../data/");
7 |
8 | ofSetLogLevel(OF_LOG_VERBOSE);
9 | ofDisableArbTex();
10 | ofEnableDepthTest();
11 | ofSetVerticalSync(true);
12 |
13 | litSphere.setup();
14 | litSphere.loadAt(2);
15 |
16 | litSphere02.setup();
17 | litSphere02.loadAt(24);
18 |
19 | ofSetConeResolution(40, 40, 40);
20 |
21 | displacement.setup();
22 |
23 | light.setAmbientColor(ofColor(200));
24 | light.setDiffuseColor(ofColor(200));
25 | light.setSpecularColor(ofColor(200));
26 | ofSetSmoothLighting(true);
27 |
28 | material.setAmbientColor(ofColor(150));
29 | material.setDiffuseColor(ofColor(150));
30 | material.setSpecularColor(ofColor(150));
31 | material.setEmissiveColor(ofFloatColor(10.0));
32 | material.setShininess(0.8);
33 | }
34 |
35 | //--------------------------------------------------------------
36 | void ofApp::update(){
37 | displacement.update();
38 | }
39 |
40 | //--------------------------------------------------------------
41 | void ofApp::draw(){
42 |
43 | ofSetColor(255);
44 |
45 | ofClear(0);
46 | ofPushMatrix();
47 | ofScale(2, 2);
48 | ofBackgroundGradient(ofColor(180), ofColor(70), OF_GRADIENT_CIRCULAR);
49 | ofPopMatrix();
50 |
51 | ofPushMatrix();
52 | ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
53 |
54 | ofEnableAlphaBlending();
55 | ofEnableDepthTest();
56 | ofDisableNormalizedTexCoords();
57 |
58 | light.enable();
59 |
60 | // first
61 | litSphere.begin();
62 | displacement.draw();
63 | litSphere.end();
64 |
65 | // second
66 | litSphere02.begin();
67 | glPushMatrix();
68 | ofDrawSphere(0, 0, 150);
69 | ofPopMatrix();
70 | litSphere02.end();
71 | //
72 | // light.disable();
73 |
74 | ofDisableDepthTest();
75 | ofEnableAlphaBlending();
76 | ofPopMatrix();
77 | ofDrawBitmapString(". , change sourse", ofPoint(20, 20));
78 | }
79 |
80 | //--------------------------------------------------------------
81 | void ofApp::keyPressed(int key){
82 |
83 | if (key == 'f') ofToggleFullscreen();
84 | if (key == '.') litSphere.loadNext();
85 | if (key == ',') litSphere.loadPrevious();
86 | if (key == ' ') ofLogVerbose(ofToString(litSphere.getCurrent()) + " " + ofToString(litSphere02.getCurrent()) + " " + ofToString(ofGetMouseY()));
87 |
88 | }
89 |
90 | //--------------------------------------------------------------
91 | void ofApp::mousePressed(int x, int y, int button){}
92 |
--------------------------------------------------------------------------------
/example_displacement/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxLitSphere.h"
5 | #include "DisplacementSphereMesh.h"
6 |
7 | class ofApp : public ofBaseApp{
8 |
9 | public:
10 | void setup();
11 | void update();
12 | void draw();
13 |
14 | void keyPressed(int key);
15 | void mousePressed(int x, int y, int button);
16 |
17 | ofxLitSphere litSphere;
18 | ofxLitSphere litSphere02;
19 | DisplacementSphereMesh displacement;
20 | ofMaterial material;
21 | ofLight light;
22 | };
23 |
--------------------------------------------------------------------------------
/ofxaddons_thumbnail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexeyroudenko/ofxLitSphere/78bb510458a1862ac36ef8190ede0207605a19f2/ofxaddons_thumbnail.png
--------------------------------------------------------------------------------
/src/ofxLitSphere.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "ofxLitSphere.h"
3 |
4 | //--------------------------------------------------------------
5 | void ofxLitSphere::setup(){
6 | ofEnableNormalizedTexCoords();
7 | ofDisableNormalizedTexCoords();
8 | ofEnableAlphaBlending();
9 |
10 | current = 0;
11 |
12 | shader.load("shaders/litsphere/vert.glsl", "shaders/litsphere/frag.glsl");
13 | loadNext();
14 | loadPrevious();
15 | }
16 |
17 | void ofxLitSphere::loadAt(int number) {
18 | string directory = "MatCapZBrush/Lib/";
19 | dir.listDir(directory);
20 |
21 | current = number;
22 | if (dir.size() <= current) current = 0;
23 |
24 | string fileName = dir.getPath(current);
25 | ofLogVerbose("ofxLitSphere", "fileName " + fileName);
26 | texture.load(fileName);
27 | }
28 |
29 | void ofxLitSphere::loadNext() {
30 | string directory = "MatCapZBrush/Lib/";
31 | dir.listDir(directory);
32 |
33 | current++;
34 | if (dir.size() <= current) current = 0;
35 |
36 | string fileName = dir.getPath(current);
37 | ofLogVerbose("ofxLitSphere", "fileName " + fileName);
38 | texture.load(fileName);
39 | }
40 |
41 | void ofxLitSphere::loadPrevious() {
42 | string directory = "MatCapZBrush/Lib/";
43 | dir.listDir(directory);
44 |
45 | current--;
46 | if (current < 0) current = dir.size() - 1;
47 |
48 | string fileName = dir.getPath(current);
49 | ofLogVerbose("ofxLitSphere", "fileName " + fileName);
50 | texture.load(fileName);
51 |
52 | }
53 |
54 | int ofxLitSphere::getCurrent() {
55 | return current;
56 | }
57 |
58 | //--------------------------------------------------------------
59 | void ofxLitSphere::update(){}
60 |
61 | void ofxLitSphere::begin() {
62 | ofEnableNormalizedTexCoords();
63 | ofEnableTextureEdgeHack();
64 | shader.begin();
65 | shader.setUniformTexture("litsphereTexture", texture, 1);
66 | }
67 |
68 | void ofxLitSphere::end() {
69 | shader.end();
70 | ofDisableNormalizedTexCoords();
71 | ofDisableTextureEdgeHack();
72 | }
73 |
74 | void ofxLitSphere::reload() {
75 | shader.load("shaders/litsphere/vert.glsl", "shaders/litsphere/frag.glsl");
76 | }
--------------------------------------------------------------------------------
/src/ofxLitSphere.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 |
5 | class ofxLitSphere {
6 |
7 | public:
8 |
9 | ofImage texture;
10 |
11 | //--------------------------------------------------------------
12 | void setup();
13 |
14 | void loadAt(int number);
15 |
16 | void loadNext();
17 |
18 | void loadPrevious();
19 |
20 | //--------------------------------------------------------------
21 | void update();
22 |
23 | void begin();
24 |
25 | void end();
26 |
27 | void reload();
28 |
29 | int getCurrent();
30 |
31 | protected:
32 | ofShader shader;
33 | ofDirectory dir;
34 | int current;
35 | };
36 |
--------------------------------------------------------------------------------