-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support simple shader switch in scene mode
- Loading branch information
Sian Cao
committed
Apr 30, 2014
1 parent
d85bbcb
commit 937663c
Showing
7 changed files
with
78 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
precision mediump float; | ||
|
||
uniform float time; | ||
uniform vec3 resolution; | ||
|
||
vec3 beam(vec2 position) { | ||
float brightness = 1.0 - abs(position.y - 0.5) * 2.0; | ||
brightness = smoothstep(0.7, 1.0, brightness); | ||
return vec3(0.25, 0.75, 1.0) * brightness; | ||
} | ||
|
||
vec4 wave(vec2 position, float frequency, float height, float speed, vec3 color) { | ||
float sinVal = sin(position.x * frequency - time * speed) * height; | ||
sinVal = sinVal * 0.5 + 0.5; | ||
|
||
float brightness = 1.0 - abs(sinVal - position.y) * 1.5; | ||
|
||
brightness = smoothstep(0.5, 1.2, brightness); | ||
float opacity = brightness; | ||
|
||
return vec4(color*brightness, opacity); | ||
} | ||
|
||
void main( void ) { | ||
vec2 position = (gl_FragCoord.xy / resolution.xy); | ||
vec4 result; | ||
|
||
result += wave(position, 2.5, 0.5, 0.2, vec3(0.65, 0.22, 0.47)); | ||
result += wave(position, 3.0, 0.3, 0.5, vec3(0.82, 0.5, 0.07)); | ||
//result += wave(position, 5.0, 0.4, -0.6, vec3(0.0, 1.0, 0.0)); | ||
|
||
gl_FragColor =result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,24 @@ | ||
#ifndef _OPTIONS_H | ||
#define _OPTIONS_H | ||
|
||
#include <string> | ||
#include <map> | ||
#include <type_traits> | ||
|
||
class OptionManager { | ||
public: | ||
static OptionManager* get(int argc, char *argv[]); | ||
template <typename T> | ||
T get(string opt); | ||
std::string get(std::string opt); | ||
|
||
private: | ||
static OptionManager* _instance; | ||
string _progName; | ||
string _mode; | ||
std::string _progName; | ||
std::map<std::string, std::string> _opts; | ||
|
||
OptionManager(); | ||
void parse(int argc, char *argv[]); | ||
void usage(); | ||
}; | ||
|
||
|
||
template <typename T> | ||
T OptionManager::get(string opt) | ||
{ | ||
if (opt == "mode") | ||
return _mode; | ||
|
||
return ""; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
#ifndef _SCENE_H | ||
#define _SCENE_H | ||
|
||
#include <string> | ||
#include "actionmode.h" | ||
|
||
class SceneMode: public ActionMode { | ||
public: | ||
SceneMode(); | ||
|
||
void setThemeFile(const std::string& glsl); | ||
bool init(int width, int height); | ||
void deinit(); | ||
void render(); | ||
private: | ||
std::string _theme; // right now only a frag shader file | ||
}; | ||
|
||
#endif |