Commit 17b80ebc authored by Thomas Jund's avatar Thomas Jund
Browse files

ajout shaders pr export direct

parent 0bf72574
...@@ -9,13 +9,25 @@ ELSE (WIN32) ...@@ -9,13 +9,25 @@ ELSE (WIN32)
ENDIF (WIN32) ENDIF (WIN32)
include_directories( include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
../include ../include
${CGoGN_ROOT_DIR}/include ${CGoGN_ROOT_DIR}/include
${COMMON_INCLUDES} ${COMMON_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
file(
GLOB
shaders_srcD
../include/*.frag
../include/*.vert
../include/*.geom
)
add_custom_target(shader_targetD ${CGoGN_ROOT_DIR}/ThirdParty/bin/shader_to_h ${shaders_srcD}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${shaders_srcD} )
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -p") #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -p")
QT4_WRAP_UI( socialAgents_ui ../include/socialAgents.ui ) QT4_WRAP_UI( socialAgents_ui ../include/socialAgents.ui )
...@@ -30,8 +42,11 @@ add_executable( socialAgentsD ...@@ -30,8 +42,11 @@ add_executable( socialAgentsD
../src/moving_mesh.cpp ../src/moving_mesh.cpp
../src/gl2ps.c ../src/gl2ps.c
../src/ShapeMatching/rigidXfComputation.cpp ../src/ShapeMatching/rigidXfComputation.cpp
../src/shaderCustom.cpp
${socialAgents_moc} ${socialAgents_moc}
${socialAgents_ui} ${socialAgents_ui}
) )
add_dependencies(socialAgentsD shader_targetD )
target_link_libraries( socialAgentsD ${CGoGN_LIBS_D} ${COMMON_LIBS} ) target_link_libraries( socialAgentsD ${CGoGN_LIBS_D} ${COMMON_LIBS} )
...@@ -9,13 +9,25 @@ ELSE (WIN32) ...@@ -9,13 +9,25 @@ ELSE (WIN32)
ENDIF (WIN32) ENDIF (WIN32)
include_directories( include_directories(
${CMAKE_CURRENT_BINARY_DIR}
../include ../include
${CGoGN_ROOT_DIR}/include ${CGoGN_ROOT_DIR}/include
${COMMON_INCLUDES} ${COMMON_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
) )
file(
GLOB
shaders_src
../include/*.frag
../include/*.vert
../include/*.geom
)
add_custom_target(shader_target ${CGoGN_ROOT_DIR}/ThirdParty/bin/shader_to_h ${shaders_src}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${shaders_src} )
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
QT4_WRAP_UI( socialAgents_ui ../include/socialAgents.ui ) QT4_WRAP_UI( socialAgents_ui ../include/socialAgents.ui )
...@@ -30,8 +42,11 @@ add_executable( socialAgents ...@@ -30,8 +42,11 @@ add_executable( socialAgents
../src/moving_mesh.cpp ../src/moving_mesh.cpp
../src/gl2ps.c ../src/gl2ps.c
../src/ShapeMatching/rigidXfComputation.cpp ../src/ShapeMatching/rigidXfComputation.cpp
../src/shaderCustom.cpp
${socialAgents_moc} ${socialAgents_moc}
${socialAgents_ui} ${socialAgents_ui}
) )
add_dependencies(socialAgents shader_target )
target_link_libraries( socialAgents ${CGoGN_LIBS_R} ${COMMON_LIBS} ) target_link_libraries( socialAgents ${CGoGN_LIBS_R} ${COMMON_LIBS} )
...@@ -270,6 +270,7 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d) ...@@ -270,6 +270,7 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
assert(map.getCurrentLevel() == map.getMaxLevel()) ; assert(map.getCurrentLevel() == map.getMaxLevel()) ;
removeElementFromVector<Agent*>(agentvect[d], agent) ; removeElementFromVector<Agent*>(agentvect[d], agent) ;
// nbAgentsDecrease(d) ; // nbAgentsDecrease(d) ;
Dart dd = d ; Dart dd = d ;
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
inline void renderDart(EnvMap& m, Dart d) inline void renderDart(EnvMap& m, Dart d)
{ {
PFP::VEC3 p1 = m.position[d] ; // PFP::VEC3 p1 = m.position[d] ;
PFP::VEC3 p2 = m.position[m.map.phi1(d)] ; // PFP::VEC3 p2 = m.position[m.map.phi1(d)] ;
std::cout << __FILE__ << " " << __LINE__ << " to update" << std::endl; std::cout << __FILE__ << " " << __LINE__ << " to update" << std::endl;
...@@ -147,20 +147,18 @@ inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false, ...@@ -147,20 +147,18 @@ inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false,
std::cout << __FILE__ << " " << __LINE__ << " to update" << std::endl; std::cout << __FILE__ << " " << __LINE__ << " to update" << std::endl;
#ifdef SPATIAL_HASHING //#ifdef SPATIAL_HASHING
const VEC3& pos = agent->pos ; // const VEC3& pos = agent->pos ;
#else //#else
VEC3 pos = agent->part_.getPosition() ; // VEC3 pos = agent->part_.getPosition() ;
#endif //#endif
float radius = agent->radius_ ; // float radius = agent->radius_ ;
// Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,agent->part_.d,m.position); // Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,agent->part_.d,m.position);
// pos[2] -= 1000; // pos[2] -= 1000;
// Geom::intersectionPlaneRay(pl,pos,VEC3(0,0,-1),pos); // Geom::intersectionPlaneRay(pl,pos,VEC3(0,0,-1),pos);
// VEC3 col = Utils::color_map_BCGYR(float(agent->agentNo)/float(agent->sim_->agents_.size()));
VEC3 col = Utils::color_map_BCGYR(float(agent->agentNo)/float(agent->sim_->agents_.size()));
// glLineWidth(1.0f) ; // glLineWidth(1.0f) ;
......
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
#include "Algo/Import/import.h" #include "Algo/Import/import.h"
#include "ShapeMatching/shapeMatchingQuadratic.h" #include "ShapeMatching/shapeMatchingQuadratic.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/vbo.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Qt/qtSimple.h"
using namespace std; using namespace std;
...@@ -39,6 +44,11 @@ public: ...@@ -39,6 +44,11 @@ public:
VertexAttribute<VEC3> position; VertexAttribute<VEC3> position;
VertexAttribute<VEC3> normal; VertexAttribute<VEC3> normal;
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO;
Utils::ShaderSimpleColor* m_simpleColorShader;
float scaleValue; float scaleValue;
ShapeMatchingQuadratic<PFP> * smg; ShapeMatchingQuadratic<PFP> * smg;
......
// ShaderCustom::fragmentShaderText
VARYING_FRAG vec4 ColorFS;
VARYING_FRAG vec3 N;
void main()
{
gl_FragData[0] = ColorFS;
gl_FragData[1] = vec4( 0.5*normalize(N)+vec3(0.5), 1.0 );
}
// ShaderCustom::geometryShaderText
uniform float explode;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition;
uniform vec4 diffuse;
uniform vec4 ambient;
VARYING_OUT vec4 ColorFS;
VARYING_OUT vec3 N;
void main(void)
{
vec3 v1 = POSITION_IN(1).xyz - POSITION_IN(0).xyz;
vec3 v2 = POSITION_IN(2).xyz - POSITION_IN(0).xyz;
N = cross(v1,v2);
N = normalize (vec3(NormalMatrix*vec4(N,0.0)));
vec3 center = POSITION_IN(0).xyz + POSITION_IN(1).xyz + POSITION_IN(2).xyz;
center /= 3.0;
vec4 newPos = ModelViewMatrix * vec4(center,0.0);
vec3 L = normalize (lightPosition - newPos.xyz);
float lambertTerm = dot(N,L);
ColorFS = ambient;
if(lambertTerm > 0.0)
ColorFS += diffuse * lambertTerm;
int i;
for(i=0; i< NBVERTS_IN; i++)
{
vec4 pos = explode * POSITION_IN(i) + (1.0-explode)* vec4(center,1.0);
gl_Position = ModelViewProjectionMatrix * pos;
EmitVertex();
}
EndPrimitive();
}
#ifndef __SHADER_CUSTOM__
#define __SHADER_CUSTOM__
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
using namespace CGoGN;
class ShaderCustom : public Utils::GLSLShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string fragmentShaderText;
static std::string geometryShaderText;
// uniform locations
CGoGNGLuint m_unif_ambiant;
CGoGNGLuint m_unif_diffuse;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_explode;
float m_explode;
Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse;
Geom::Vec3f m_light_pos;
Utils::VBO* m_vboPos;
void getLocations();
void restoreUniformsAttribs();
public:
ShaderCustom();
void setExplode(float explode);
void setAmbiant(const Geom::Vec4f& ambiant);
void setDiffuse(const Geom::Vec4f& diffuse);
void setLightPosition(const Geom::Vec3f& lp);
void setParams(float explode, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos);
unsigned int setAttributePosition(Utils::VBO* vbo);
};
#endif
// ShaderCustom::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
void main()
{
gl_Position = vec4(VertexPosition, 1.0);
}
...@@ -47,9 +47,14 @@ ...@@ -47,9 +47,14 @@
#include "Utils/Shaders/shaderPhong.h" #include "Utils/Shaders/shaderPhong.h"
#include "Utils/colorMaps.h" #include "Utils/colorMaps.h"
#include "Utils/vbo.h" #include "Utils/vbo.h"
#include "Utils/fbo.h"
#include "Utils/drawer.h" #include "Utils/drawer.h"
#include "Utils/pointSprite.h" #include "Utils/pointSprite.h"
#include "shaderCustom.h"
//#define EXPORTING
using namespace CGoGN ; using namespace CGoGN ;
typedef PFP::MAP MAP ; typedef PFP::MAP MAP ;
...@@ -71,6 +76,7 @@ public: ...@@ -71,6 +76,7 @@ public:
void updateAgentPredTriVBO(); void updateAgentPredTriVBO();
void updateObstaclePredTriVBO(); void updateObstaclePredTriVBO();
void moveCameraTo(VEC3 newPos);
void cb_redraw() ; void cb_redraw() ;
#ifndef SPATIAL_HASHING #ifndef SPATIAL_HASHING
...@@ -91,6 +97,7 @@ public: ...@@ -91,6 +97,7 @@ public:
//navigation map //navigation map
Algo::Render::GL2::MapRender* m_render; Algo::Render::GL2::MapRender* m_render;
Algo::Render::GL2::MapRender* m_renderPedway;
Algo::Render::GL2::TopoRender* m_renderTopo; Algo::Render::GL2::TopoRender* m_renderTopo;
Utils::VBO* m_positionVBO; Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO; Utils::VBO* m_normalVBO;
...@@ -102,7 +109,11 @@ public: ...@@ -102,7 +109,11 @@ public:
Utils::VBO* m_positionVBO_scenary; Utils::VBO* m_positionVBO_scenary;
Utils::VBO* m_normalVBO_scenary; Utils::VBO* m_normalVBO_scenary;
Utils::VBO* m_colorVBO_scenary; Utils::VBO* m_colorVBO_scenary;
#ifdef EXPORTING
ShaderCustom* m_flatShader_scenary;
#else
Utils::ShaderFlat* m_flatShader_scenary; Utils::ShaderFlat* m_flatShader_scenary;
#endif
//agents //agents
Utils::VBO* m_agentsVBO; Utils::VBO* m_agentsVBO;
...@@ -113,6 +124,10 @@ public: ...@@ -113,6 +124,10 @@ public:
std::vector<Utils::VBO*> m_obst_VBO; std::vector<Utils::VBO*> m_obst_VBO;
std::vector<Utils::ShaderFlat*> m_obstShader; std::vector<Utils::ShaderFlat*> m_obstShader;
//city ground
Utils::ShaderFlat* m_Ground_Shader;
Utils::VBO* m_Ground_VBO;
//prediction triangles //prediction triangles
std::vector<Algo::Render::GL2::MapRender*> m_triObst_render; std::vector<Algo::Render::GL2::MapRender*> m_triObst_render;
std::vector<Utils::VBO*> m_triObst_VBO; std::vector<Utils::VBO*> m_triObst_VBO;
...@@ -121,10 +136,19 @@ public: ...@@ -121,10 +136,19 @@ public:
std::vector<Utils::VBO*> m_triAgent_VBO; std::vector<Utils::VBO*> m_triAgent_VBO;
std::vector<Utils::ShaderSimpleColor*> m_triAgent_Shader; std::vector<Utils::ShaderSimpleColor*> m_triAgent_Shader;
static const unsigned int N_THETA = 64;
static const unsigned int N_PHI = 128;
static const float RADIUS = 3950.0f;
Utils::GLSLShader m_DeferedShader;
Utils::GLSLShader m_DeferedShader2;
enum renderMode {SIMPLE} ; enum renderMode {SIMPLE} ;
int m_renderStyle; int m_renderStyle;
////// //////
Geom::BoundingBox<PFP::VEC3> bb ;
Utils::QT::uiDockInterface dock ; Utils::QT::uiDockInterface dock ;
QTimer* timer ; QTimer* timer ;
......
uniform sampler2D u_FrameBufferColor;
uniform sampler2D u_FrameBufferDepth;
uniform sampler2D u_FrameBufferNormal;
ivec2 tsize = textureSize( u_FrameBufferDepth, 0 );
vec2 pixelSize = 1.0 / vec2( tsize );
const vec3 FOG_COLOR = vec3( 1.0, 1.0, 1.0 );
const float FOG_STRENGTH = 0.0;
vec3 fetch( int x, int y )
{
return normalize(texture2D( u_FrameBufferNormal, gl_TexCoord[0].xy+vec2(x*pixelSize.x,y*pixelSize.y) ).xyz * 2.0 - vec3(1.0));
}
void main()
{
float edgeEnhancement;
// if( gl_TexCoord[0].x > 0.5 )
// {
// // Computes the Laplacian of the normal field at the current pixel.
// const int NLap = 2;
//
// vec3 lap = vec3( 0.0 );
// vec3 centralVal = fetch( 0, 0 );
//
// for( int i=-NLap; i<=NLap; ++i )
// for( int j=-NLap; j<=NLap; ++j )
// if( i || j )
// lap += fetch(j,i) - centralVal;
//
// lap /= float((2*NLap+1)*(2*NLap+1)) - 1;
// edgeEnhancement = 1.0 - length(lap);
// }
// else
{
// Computes a Sobel operator considering the screen space normal vectors.
const int NSobel = 2;
vec3 sobelV = vec3( 0.0 );
vec3 sobelH = vec3( 0.0 );
for( int i=-NSobel; i<=NSobel; ++i )
for( int j=-NSobel; j<=NSobel; ++j )
if( j )
{
sobelV += j*fetch(j,i);
sobelH += j*fetch(i,j);
}
sobelV /= 2*NSobel + 1;
sobelH /= 2*NSobel + 1;
edgeEnhancement = 1.0 - length( 0.5*( abs(sobelV)+abs(sobelH) ) );
}
// Computes the fog factor.
// vec3 fog = (1.0 - 1.0 / (1.0 + texture2D( u_FrameBufferDepth, gl_TexCoord[0] ).x)) * FOG_COLOR;
// gl_FragColor = vec4( FOG_STRENGTH*fog + (1.0-FOG_STRENGTH) * edgeEnhancement * texture2D(u_FrameBufferColor,gl_TexCoord[0]).xyz, 1.0 );
gl_FragColor = vec4( vec3(edgeEnhancement), texture2D(u_FrameBufferDepth,gl_TexCoord[0].xy).z );
}
uniform sampler2D u_FrameBufferColor;
uniform sampler2D u_FrameBufferDepth;
uniform sampler2D u_FrameBufferNormal;
ivec2 tsize = textureSize( u_FrameBufferDepth, 0 );
vec2 pixelSize = 1.0 / vec2( tsize );
const vec3 FOG_COLOR = vec3( 1.0, 1.0, 1.0 );
const float FOG_STRENGTH = 0.0;
vec3 fetch( int x, int y )
{
return normalize(texture2D( u_FrameBufferNormal, gl_TexCoord[0].xy+vec2(x*pixelSize.x,y*pixelSize.y) ).xyz * 2.0 - vec3(1.0));
}
void main()
{
float edgeEnhancement;
if( gl_TexCoord[0].x > 0.5 )
{
// Computes the Laplacian of the normal field at the current pixel.
const int NLap = 2;
vec3 lap = vec3( 0.0 );
vec3 centralVal = fetch( 0, 0 );
for( int i=-NLap; i<=NLap; ++i )
for( int j=-NLap; j<=NLap; ++j )
if( i || j )
lap += fetch(j,i) - centralVal;
lap /= float((2*NLap+1)*(2*NLap+1)) - 1;
edgeEnhancement = 1.0 - length(lap);
}
else
{
// Computes a Sobel operator considering the screen space normal vectors.
const int NSobel = 2;
vec3 sobelV = vec3( 0.0 );
vec3 sobelH = vec3( 0.0 );
for( int i=-NSobel; i<=NSobel; ++i )
for( int j=-NSobel; j<=NSobel; ++j )
if( j )
{
sobelV += j*fetch(j,i);
sobelH += j*fetch(i,j);
}
sobelV /= 2*NSobel + 1;
sobelH /= 2*NSobel + 1;
edgeEnhancement = 1.0 - length( 0.5*( abs(sobelV)+abs(sobelH) ) );
}
// Computes the fog factor.
// vec3 fog = (1.0 - 1.0 / (1.0 + texture2D( u_FrameBufferDepth, gl_TexCoord[0] ).x)) * FOG_COLOR;
// gl_FragColor = vec4( FOG_STRENGTH*fog + (1.0-FOG_STRENGTH) * edgeEnhancement * texture2D(u_FrameBufferColor,gl_TexCoord[0]).xyz, 1.0 );
gl_FragColor = vec4( vec3(edgeEnhancement), texture2D(u_FrameBufferDepth,gl_TexCoord[0].xy).z );
}
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
void main()
{
gl_MultiTexCoord0 = gl_TexCoord[0];
gl_Position = ftransform();
}
uniform sampler2D u_FrameBufferColor;
uniform sampler2D u_FrameBufferEdgeDepth;
uniform sampler2D u_FrameBufferNormal;
ivec2 tsize = textureSize( u_FrameBufferEdgeDepth, 0 );
vec2 pixelSize = 1.0 / vec2( tsize );
const vec3 FOG_COLOR = vec3( 1.0, 1.0, 1.0 );
const float FOG_STRENGTH = 0.0;
float fetch( int x, int y )
{
return texture2D( u_FrameBufferEdgeDepth, gl_TexCoord[0].xy+vec2(x*pixelSize.x,y*pixelSize.y) ).x;
}
vec3 fetchNor( float x, float y )
{
return normalize(texture2D( u_FrameBufferNormal, gl_TexCoord[0].xy+vec2(x*pixelSize.x,y*pixelSize.y) ).xyz * 2.0 - vec3(1.0));
}
float fetchDepth( float x, float y )
{
return texture2D( u_FrameBufferEdgeDepth, gl_TexCoord[0].xy+vec2(x*pixelSize.x,y*pixelSize.y) ).w;
}
float SobelAt( int x, int y )
{
const int NSobel = 1;
// Computes a Sobel operator considering the screen space normal vectors.
float sobelV = 0.0;
float sobelH = 0.0;
for( int i=-NSobel; i<=NSobel; ++i )
for( int j=-NSobel; j<=NSobel; ++j )
if( j )
{
sobelV += j*fetch(x+j,y+i);
sobelH += j*fetch(x+i,y+j);
}
return clamp( 0.5*( abs(sobelV)+abs(sobelH) ), 0.0, 1.0 );
}
float SmoothAt( int x, int y )
{
const int NSmooth = 2;
// Computes a Sobel operator considering the screen space normal vectors.
float sum = 0.0;
for( int i=-NSmooth; i<=NSmooth; ++i )
for( int j=-NSmooth; j<=NSmooth; ++j )
sum += fetch(x+j,y+i);
sum /= (2*NSmoo