Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit dca2baf

Browse files
committed
added initial OF and Cinder ports
1 parent 9e112eb commit dca2baf

File tree

64 files changed

+3346
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3346
-0
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#version 150
2+
3+
uniform float fraction;
4+
5+
in vec4 vertColor;
6+
in vec3 vertNormal;
7+
in vec3 vertLightDir;
8+
9+
out vec4 fragColor;
10+
11+
void main() {
12+
float intensity;
13+
vec4 color;
14+
intensity = max(0.0, dot(vertLightDir, vertNormal));
15+
16+
if (intensity > pow(0.95, fraction)) {
17+
color = vec4(vec3(1.0), 1.0);
18+
} else if (intensity > pow(0.5, fraction)) {
19+
color = vec4(vec3(0.6), 1.0);
20+
} else if (intensity > pow(0.25, fraction)) {
21+
color = vec4(vec3(0.4), 1.0);
22+
} else {
23+
color = vec4(vec3(0.2), 1.0);
24+
}
25+
26+
fragColor = color * vertColor;
27+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#version 150
2+
3+
uniform mat4 ciModelViewProjection;
4+
uniform mat3 ciNormalMatrix;
5+
uniform vec3 lightNormal;
6+
7+
in vec4 ciPosition;
8+
in vec3 ciNormal;
9+
in vec4 ciColor;
10+
11+
out vec4 vertColor;
12+
out vec3 vertNormal;
13+
out vec3 vertLightDir;
14+
15+
void main() {
16+
gl_Position = ciModelViewProjection * ciPosition;
17+
vertNormal = normalize(ciNormalMatrix * ciNormal);
18+
vertColor = ciColor;
19+
vertLightDir = -normalize(ciNormalMatrix * lightNormal);
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
#include "cinder/CinderResources.h"
3+
4+
//#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE )
5+
6+
7+
8+
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "cinder/app/App.h"
2+
#include "cinder/app/RendererGl.h"
3+
#include "cinder/gl/gl.h"
4+
5+
using namespace ci;
6+
using namespace ci::app;
7+
using namespace std;
8+
9+
class Ex_2_1_toonApp : public App {
10+
public:
11+
void setup() override;
12+
void resize() override;
13+
void draw() override;
14+
void mouseMove(MouseEvent event) override;
15+
16+
float cameraFOV;
17+
float cameraZ;
18+
CameraPersp mCam;
19+
gl::BatchRef mSphere;
20+
gl::GlslProgRef mGlsl;
21+
ivec2 mLastMousePos;
22+
vec3 lightDir;
23+
};
24+
25+
void Ex_2_1_toonApp::setup() {
26+
setWindowSize(640, 360);
27+
cameraFOV = 60;
28+
cameraZ = 0.125f * getWindowHeight() / tan(0.5f * glm::radians(cameraFOV));
29+
mCam.lookAt(vec3(0, 0, cameraZ), vec3(0));
30+
31+
mGlsl = gl::GlslProg::create(loadAsset("vert.glsl"), loadAsset("frag.glsl"));
32+
mSphere = gl::Batch::create(geom::Sphere().radius(30).subdivisions(30), mGlsl);
33+
34+
gl::enableDepthWrite();
35+
gl::enableDepthRead();
36+
37+
mGlsl->uniform("fraction", 1.0f);
38+
}
39+
40+
void Ex_2_1_toonApp::resize() {
41+
mCam.setPerspective(60, getWindowAspectRatio(), cameraZ / 10, cameraZ * 10);
42+
}
43+
44+
void Ex_2_1_toonApp::draw() {
45+
gl::clear(Color(0, 0, 0));
46+
47+
gl::setMatrices(mCam);
48+
49+
float dirY = 1 - (mLastMousePos[1] / float(getWindowHeight()) - 0.5) * 2;
50+
float dirX = (mLastMousePos[0] / float(getWindowWidth()) - 0.5) * 2;
51+
lightDir[0] = -dirX;
52+
lightDir[1] = -dirY;
53+
lightDir[2] = -1;
54+
mGlsl->uniform("lightNormal", lightDir);
55+
56+
gl::color(0.8f, 0.8f, 0.8f);
57+
mSphere->draw();
58+
}
59+
60+
void Ex_2_1_toonApp::mouseMove( MouseEvent event ) {
61+
mLastMousePos = event.getPos();
62+
}
63+
64+
CINDER_APP( Ex_2_1_toonApp, RendererGl )

0 commit comments

Comments
 (0)