diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index 48777dbd4..66684b9e3 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -1025,16 +1025,28 @@ public: /// Activates the specified GPU program object - virtual bool activeProgramObject( IProgramObject *program ) = 0; + virtual bool activeProgramObject( IProgramObject *program ){ return false; }; /// Creates a new GPU program object - virtual IProgramObject* createProgramObject() const = 0; + virtual IProgramObject* createProgramObject() const { return NULL; } /// Creates a new Vertex program - virtual IProgram* createVertexProgram() const = 0; + virtual IProgram* createVertexProgram() const { return NULL; } /// Creates a new Pixel program - virtual IProgram* createPixelProgram() const = 0; + virtual IProgram* createPixelProgram() const { return NULL; } + + virtual int getUniformLocation( const char *name ){ return -1; } + + virtual void setUniform1f( uint index, float f ){} + virtual void setUniform4f( uint index, float f1, float f2, float f3, float f4 ){} + virtual void setUniform1i( uint index, int i ){} + virtual void setUniform4i( uint index, int i1, int i2, int i3, int i4 ){} + virtual void setUniform1u( uint index, uint u ){} + virtual void setUniform4u( uint index, uint u1, uint u2, uint u3, uint u4 ){} + virtual void setUniformMatrix2fv( uint index, uint count, bool transpose, const float *values ){} + virtual void setUniformMatrix3fv( uint index, uint count, bool transpose, const float *values ){} + virtual void setUniformMatrix4fv( uint index, uint count, bool transpose, const float *values ){} /** * Setup constant values. diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp index fdfd0d832..79fa574b8 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp @@ -331,6 +331,8 @@ CDriverGL3::CDriverGL3() _TextureTargetCubeFace = 0; _TextureTargetUpload = false; + + currentProgram = NULL; } // *************************************************************************** diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h index 06ec08247..f90c655c9 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h @@ -1262,6 +1262,18 @@ private: IProgram* createVertexProgram() const; IProgram* createPixelProgram() const; + int getUniformLocation( const char *name ); + + void setUniform1f( uint index, float f ); + void setUniform4f( uint index, float f1, float f2, float f3, float f4 ); + void setUniform1i( uint index, int i ); + void setUniform4i( uint index, int i1, int i2, int i3, int i4 ); + void setUniform1u( uint index, uint u ); + void setUniform4u( uint index, uint u1, uint u2, uint u3, uint u4 ); + void setUniformMatrix2fv( uint index, uint count, bool transpose, const float *values ); + void setUniformMatrix3fv( uint index, uint count, bool transpose, const float *values ); + void setUniformMatrix4fv( uint index, uint count, bool transpose, const float *values ); + void setConstant (uint index, float, float, float, float); void setConstant (uint index, double, double, double, double); void setConstant (uint indexStart, const NLMISC::CVector& value); @@ -1339,6 +1351,8 @@ private: private: + IProgramObject *currentProgram; + bool setupARBVertexProgram (const CVPParser::TProgram &parsedProgram, GLuint id, bool &specularWritten); // init EMBM settings (set each stage to modify the next) diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp index f3638ec02..e087f1a2e 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp @@ -11,6 +11,7 @@ namespace NL3D if( !program ) { _VertexProgramEnabled = false; + currentProgram = NULL; return true; } @@ -31,6 +32,7 @@ namespace NL3D return false; _VertexProgramEnabled = true; + currentProgram = program; return true; } @@ -51,6 +53,60 @@ namespace NL3D return new CGLSLPixelProgram(); } + int CDriverGL3::getUniformLocation( const char *name ) + { + if( currentProgram == NULL ) + return -1; + + return nglGetUniformLocation( currentProgram->getProgramId(), name ); + } + + + void CDriverGL3::setUniform1f( uint index, float f ) + { + nglUniform1f( index, f ); + } + + void CDriverGL3::setUniform4f( uint index, float f1, float f2, float f3, float f4 ) + { + nglUniform4f( index, f1, f2, f3, f4 ); + } + + void CDriverGL3::setUniform1i( uint index, int i ) + { + nglUniform1i( index, i ); + } + + void CDriverGL3::setUniform4i( uint index, int i1, int i2, int i3, int i4 ) + { + nglUniform4i( index, i1, i2, i3, i4 ); + } + + void CDriverGL3::setUniform1u( uint index, uint u ) + { + nglUniform1ui( index, u ); + } + + void CDriverGL3::setUniform4u( uint index, uint u1, uint u2, uint u3, uint u4 ) + { + nglUniform4ui( index, u1, u2, u3, u4 ); + } + + void CDriverGL3::setUniformMatrix2fv( uint index, uint count, bool transpose, const float *values ) + { + nglUniformMatrix2fv( index, count, transpose, values ); + } + + void CDriverGL3::setUniformMatrix3fv( uint index, uint count, bool transpose, const float *values ) + { + nglUniformMatrix3fv( index, count, transpose, values ); + } + + void CDriverGL3::setUniformMatrix4fv( uint index, uint count, bool transpose, const float *values ) + { + nglUniformMatrix4fv( index, count, transpose, values ); + } + bool CDriverGL3::renderRawTriangles2( CMaterial &mat, uint32 startIndex, uint32 numTris ) { glDrawArrays( GL_TRIANGLES, startIndex * 3, numTris * 3 ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp index 31bb46317..41878c14f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp @@ -450,7 +450,7 @@ namespace MaterialEditor const char *vs = "#version 330\n" "\n" - "layout ( location = 0 )in vec4 vertex;\n" + "layout ( location = 0 ) in vec4 vertex;\n" "layout ( location = 3 ) in vec4 color;\n" "out vec4 vColor;\n" "\n" @@ -466,9 +466,13 @@ namespace MaterialEditor "in vec4 vColor;\n" "out vec4 color;\n" "\n" + "uniform float redShift;" + "\n" "void main( void )\n" "{\n" - "color = vColor;\n" + "vec4 finalColor = vColor.rgba;\n" + "finalColor.r = redShift;\n" + "color = finalColor;\n" "}\n"; void CNel3DInterface::drawTriangle() @@ -561,6 +565,10 @@ namespace MaterialEditor return; } + int opacityLocation = id->getUniformLocation( "redShift" ); + if( opacityLocation != -1 ) + id->setUniform1f( opacityLocation, 0.25f ); + id->activeVertexBuffer( vb ); id->activeIndexBuffer( ib );