Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions samples/_opengl/CubeMapping/assets/env_map.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#version 150

uniform samplerCube uCubeMapTex;

in vec3 NormalWorldSpace;
Expand Down
16 changes: 16 additions & 0 deletions samples/_opengl/CubeMapping/emscripten/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
set( CMAKE_VERBOSE_MAKEFILE ON )

project( CubeMapping )

get_filename_component( CINDER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../" ABSOLUTE )
get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../" ABSOLUTE )

include( "${CINDER_PATH}/proj/cmake/modules/cinderEmscriptenApp.cmake" )


ci_emscripten_app(
SOURCES ${APP_PATH}/src/CubeMappingApp.cpp
CINDER_PATH ${CINDER_PATH}
ASSETS ${APP_PATH}/assets
)
17 changes: 17 additions & 0 deletions samples/_opengl/DeferredShading/emscripten/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
set( CMAKE_VERBOSE_MAKEFILE ON )

project( DeferredShading )

get_filename_component( CINDER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../" ABSOLUTE )
get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../" ABSOLUTE )

include( "${CINDER_PATH}/proj/cmake/modules/cinderEmscriptenApp.cmake" )


ci_emscripten_app(
SOURCES ${APP_PATH}/src/DeferredShadingApp.cpp ${APP_PATH}/src/Light.cpp
CINDER_PATH ${CINDER_PATH}
INCLUDES ${APP_PATH}/include
ASSETS ${APP_PATH}/assets
)
15 changes: 15 additions & 0 deletions samples/_opengl/MotionBlurFbo/emscripten/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
set( CMAKE_VERBOSE_MAKEFILE ON )

project( MotionBlurFbo )

get_filename_component( CINDER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../" ABSOLUTE )
get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../" ABSOLUTE )

include( "${CINDER_PATH}/proj/cmake/modules/cinderEmscriptenApp.cmake" )


ci_emscripten_app(
SOURCES ${APP_PATH}/src/MotionBlurFboApp.cpp
CINDER_PATH ${CINDER_PATH}
)
9 changes: 9 additions & 0 deletions samples/_opengl/MotionBlurFbo/src/MotionBlurFboApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ void MotionBlurFboApp::setup()
gl::Fbo::Format().colorTexture( gl::Texture::Format().dataType( GL_HALF_FLOAT_OES )
.internalFormat( GL_RGB ) ).disableDepth() );
#else

// For some reason - not sure if Emscripten or gl loader issue but GL_RGB16F doesn't exist, but this does exist in WebGL2,
// use RGBA for now.
#if defined( CINDER_EMSCRIPTEN )
mAccumFbo = gl::Fbo::create( getWindowWidth(), getWindowHeight(),
gl::Fbo::Format().colorTexture( gl::Fbo::Format().getDefaultColorTextureFormat().internalFormat( GL_RGBA16F ) ).disableDepth() );
#else
mAccumFbo = gl::Fbo::create( getWindowWidth(), getWindowHeight(),
gl::Fbo::Format().colorTexture( gl::Fbo::Format().getDefaultColorTextureFormat().internalFormat( GL_RGB16F ) ).disableDepth() );

#endif
#endif

mPaused = false;
Expand Down
2 changes: 0 additions & 2 deletions samples/_opengl/NormalMapping/assets/normal_mapping_frag.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#version 150

// inputs passed from the vertex shader
in vec4 vVertex;
in vec3 vNormal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#version 150

uniform mat4 ciModelView;
uniform mat4 ciModelViewProjection;
Expand Down
18 changes: 18 additions & 0 deletions samples/_opengl/NormalMapping/emscripten/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
set( CMAKE_VERBOSE_MAKEFILE ON )

project( NormalMapping )

get_filename_component( CINDER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../" ABSOLUTE )
get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../" ABSOLUTE )

include( "${CINDER_PATH}/proj/cmake/modules/cinderEmscriptenApp.cmake" )


ci_emscripten_app(
SOURCES ${APP_PATH}/src/NormalMappingApp.cpp ${APP_PATH}/src/DebugMesh.cpp
CINDER_PATH ${CINDER_PATH}
INCLUDES ${APP_PATH}/include
ASSETS ${APP_PATH}/assets
RESOURCES ${APP_PATH}/resources
)
Binary file not shown.
21 changes: 18 additions & 3 deletions samples/_opengl/NormalMapping/src/NormalMappingApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ console() << "Asset size: " << ci::app::android::AssetFileSystem_flength( asset

// load mesh file and create missing data (normals, tangents) if necessary
try {
fs::path mshFile = getAssetPath( "leprechaun.msh" );
#if defined( CINDER_EMSCRIPTEN )
fs::path mshFile = fs::path( "leprechaun.msh" );
#else
fs::path mshFile = getAssetPath( "leprechaun.msh" );
#endif
TriMesh mesh = createMesh( mshFile );

mMesh = gl::VboMesh::create( mesh );
Expand Down Expand Up @@ -382,20 +386,31 @@ TriMesh NormalMappingApp::createMesh( const fs::path& mshFile )
TriMesh mesh( TriMesh::Format().positions(3).texCoords(2).normals() );
Timer timer;

// try to load the msh file
// It's technically not possible to check for the existance of a file on the Web so we
// need to split things up a bit in the check.
// Also for some reason - when loading as asset the version number is read incorrectly so bundle model as a resource
#if defined( CINDER_EMSCRIPTEN )
timer.start();
mesh.read( loadResource( mshFile.string() ) );
CI_LOG_I( "Loading the mesh took " << timer.getSeconds() << " seconds." );
#else
// try to load the msh file
#if defined( CINDER_ANDROID )
if( ci::android::fs::exists( mshFile ) ) {
#else
if( fs::exists( mshFile ) ) {
#endif
timer.start();
mesh.read( loadFile( mshFile ) );

mesh.read( loadAsset( mshFile ) );

CI_LOG_I( "Loading the mesh took " << timer.getSeconds() << " seconds." );
}
else {
std::string msg = "File does not exist (" + mshFile.string() + ")";
throw std::runtime_error( msg );
}
#endif

// if the mesh does not have normals, calculate them on-the-fly
if( ! mesh.hasNormals() ) {
Expand Down
17 changes: 17 additions & 0 deletions samples/_opengl/SuperformulaGPU/emscripten/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
set( CMAKE_VERBOSE_MAKEFILE ON )

project( HTMLApp )

get_filename_component( CINDER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../" ABSOLUTE )
get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../" ABSOLUTE )
include( "${CINDER_PATH}/proj/cmake/modules/cinderEmscriptenApp.cmake" )


ci_emscripten_app(
SOURCES ${APP_PATH}/src/SuperformulaGPUApp.cpp
CINDER_PATH ${CINDER_PATH}
FLAGS "--pre-js ${APP_PATH}/include/dat.gui.js"
ASSETS ${APP_PATH}/assets
INCLUDES ${APP_PATH}/include
)
109 changes: 109 additions & 0 deletions samples/_opengl/SuperformulaGPU/include/Gui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <emscripten.h>
#include <emscripten/val.h>
#include <emscripten/bind.h>
#include "cinder/emscripten/CinderEmscripten.h"
#include <memory>


EM_JS(void,load_gui,(),{

window.gui = new dat.GUI();

window.settings = {
A1:1,
B1:1,
M1:4,
N1:1,
N2:1,
N3:2,
A2:1,
B2:1,
M2:6,
N12:30,
N22:2,
N32:2.5,
Subdivisions:100,
Checkerboard:7,
drawNormals:false,
normalsLength:0.2
};
// remember to call "load_gui" in your c++
});

typedef std::shared_ptr<class Gui> GuiRef;

/**
* A simple class to handle parameters for the simulation.
*/
class Gui {
public:
Gui():gui(emscripten::val::undefined()),
settings(emscripten::val::undefined())
{
load_gui();

gui = emscripten::val::global( "gui" );
settings = emscripten::val::global( "settings" );

gui.call<void>( "add",settings, emscripten::val( "A1" ), emscripten::val( 0 ), emscripten::val( 5 ), emscripten::val( 0.05f ) );
gui.call<void>( "add",settings, emscripten::val( "B1" ), emscripten::val( 0 ), emscripten::val( 5 ), emscripten::val( 0.05f ) );
gui.call<void>( "add",settings, emscripten::val( "M1" ), emscripten::val( 0 ), emscripten::val( 20 ), emscripten::val( 0.25f ) );
gui.call<void>( "add",settings, emscripten::val( "N1" ), emscripten::val( 0 ), emscripten::val( 100 ), emscripten::val( 1.0f ) );
gui.call<void>( "add",settings, emscripten::val( "N2" ), emscripten::val( -50 ), emscripten::val( 100 ), emscripten::val( 0.5f ) );
gui.call<void>( "add",settings, emscripten::val( "N3" ), emscripten::val( -50 ), emscripten::val( 100 ), emscripten::val( 0.5f ) );

gui.call<void>( "add",settings, emscripten::val( "A2" ), emscripten::val( 0 ), emscripten::val( 5 ), emscripten::val( 0.05f ) );
gui.call<void>( "add",settings, emscripten::val( "B2" ), emscripten::val( 0 ), emscripten::val( 5 ), emscripten::val( 0.05f ) );
gui.call<void>( "add",settings, emscripten::val( "M2" ), emscripten::val( 0 ), emscripten::val( 20 ), emscripten::val( 0.25f ) );
gui.call<void>( "add",settings, emscripten::val( "N12" ), emscripten::val( 0 ), emscripten::val( 100 ), emscripten::val( 1.0f ) );
gui.call<void>( "add",settings, emscripten::val( "N22" ), emscripten::val( -50 ), emscripten::val( 100 ), emscripten::val( 0.5f ) );
gui.call<void>( "add",settings, emscripten::val( "N32" ), emscripten::val( -50 ), emscripten::val( 100 ), emscripten::val( 0.5f ) );
}

static GuiRef create(){
return GuiRef(new Gui);
}

void setupGeometryChange( std::function<void( emscripten::val )> func )
{
auto controller = gui.call< emscripten::val >( "add",settings, emscripten::val( "Subdivisions" ), emscripten::val( 5 ), emscripten::val( 500 ), emscripten::val( 30.5f ) );
controller.call<void>( "onChange",ci::em::helpers::generateCallback( func ) );
}


void updateGUI(FormulaData &mFormulaParams){
mFormulaParams.mA1 = settings[ "A1" ].as<int>();
mFormulaParams.mB1 = settings[ "B1" ].as<int>();
mFormulaParams.mM1 = settings[ "M1" ].as<int>();
mFormulaParams.mN11 = settings[ "N1" ].as<int>();
mFormulaParams.mN21 = settings["N2"].as<int>();
mFormulaParams.mN31 = settings["N3"].as<int>();

mFormulaParams.mA2 = settings[ "A2" ].as<int>();
mFormulaParams.mB2 = settings[ "B2" ].as<int>();
mFormulaParams.mM2 = settings[ "M2" ].as<int>();
mFormulaParams.mN12 = settings[ "N12" ].as<int>();
mFormulaParams.mN22 = settings["N22"].as<int>();
mFormulaParams.mN32 = settings["N32"].as<int>();
/*
mFormulaParams.mA1 = settings[ "A1" ].as<int>();
mFormulaParams.mB1 = settings[ "B1" ].as<int>();
mFormulaParams.mM1 = settings[ "M1" ].as<int>();
mFormulaParams.mN11 = settings[ "N1" ].as<int>();
mFormulaParams.mN21 = settings["N2"].as<int>();
mFormulaParams.mN31 = settings["N3"].as<int>();

mFormulaParams.mA2 = settings[ "A2" ].as<int>();
mFormulaParams.mB2 = settings[ "B2" ].as<int>();
mFormulaParams.mM2 = settings[ "M2" ].as<int>();
mFormulaParams.mN12 = settings[ "N12" ].as<int>();
mFormulaParams.mN22 = settings["N22"].as<int>();
mFormulaParams.mN32 = settings["N32"].as<int>();
*/
}


private:
emscripten::val gui;
emscripten::val settings;
};
Loading