本文整理汇总了C++中GeometryShader类的典型用法代码示例。如果您正苦于以下问题:C++ GeometryShader类的具体用法?C++ GeometryShader怎么用?C++ GeometryShader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeometryShader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateGeometryShader
/**
* @brief
* Creates a geometry shader and sets the shader source code
*/
GeometryShader *ShaderLanguage::CreateGeometryShader(const String &sSourceCode, GeometryShader::EInputPrimitiveType nInputPrimitiveType, GeometryShader::EOutputPrimitiveType nOutputPrimitiveType, uint32 nNumOfOutputVertices, const String &sProfile, const String &sArguments, const String &sEntry)
{
// Create the geometry shader instance
GeometryShader *pGeometryShader = CreateGeometryShader();
// Set the geometry shader source code
if (pGeometryShader)
pGeometryShader->SetSourceCode(sSourceCode, nInputPrimitiveType, nOutputPrimitiveType, nNumOfOutputVertices, sProfile, sArguments, sEntry);
// Return the created geometry shader instance
return pGeometryShader;
}
示例2: hashString
//-------------------------------------------------------------------------
// @brief
//-------------------------------------------------------------------------
const unsigned int ShaderCache::getGeometryShader(const tinyxml2::XMLElement* element, const DeviceManager& deviceManager)
{
GeometryShader shader;
shader.deserialise(element);
unsigned int resourceName = hashString(getResourceNameFromFileName(shader.getFileName()));
if (getGeometryShader(resourceName) == nullptr)
{
if (shader.createShader(deviceManager))
{
m_geometryShaders.emplace(GeometryShaderHandle(resourceName, shader));
}
}
return resourceName;
}
示例3: glCreateProgram
//----------------------------------------------------------------------------
ShaderProgramHandle* OpenGLDevice::__CreateProgram(ShaderProgram* program)
{
GLuint __program = glCreateProgram();
std::string linkingString("Linking program");
VertexShader* vShader = program->GetVertexShader();
if( vShader )
{
vShader->CreateDeviceResource(this);
OpenGLShaderHandle* vsHandle =
(OpenGLShaderHandle*)vShader->GetShaderHandle();
glAttachShader(__program, vsHandle->mShader);
linkingString += " ";
linkingString += vShader->GetShaderFileName();
}
FragmentShader* fShader = program->GetFragmentShader();
if( fShader )
{
fShader->CreateDeviceResource(this);
OpenGLShaderHandle* fsHandle =
(OpenGLShaderHandle*)fShader->GetShaderHandle();
glAttachShader(__program, fsHandle->mShader);
linkingString += " ";
linkingString += fShader->GetShaderFileName();
}
GeometryShader* gShader = program->GetGeometryShader();
if( gShader )
{
gShader->CreateDeviceResource(this);
OpenGLShaderHandle* gsHandle =
(OpenGLShaderHandle*)gShader->GetShaderHandle();
glAttachShader(__program, gsHandle->mShader);
linkingString += " ";
linkingString += gShader->GetShaderFileName();
}
ComputeShader* cShader = program->GetComputeShader();
if( cShader )
{
cShader->CreateDeviceResource(this);
OpenGLShaderHandle* csHandle =
(OpenGLShaderHandle*)cShader->GetShaderHandle();
glAttachShader(__program, csHandle->mShader);
linkingString += " ";
linkingString += cShader->GetShaderFileName();
}
TessellationControlShader* tcShader = program->GetTessellationControlShader();
if( tcShader )
{
tcShader->CreateDeviceResource(this);
OpenGLShaderHandle* tcsHandle =
(OpenGLShaderHandle*)tcShader->GetShaderHandle();
glAttachShader(__program, tcsHandle->mShader);
linkingString += " ";
linkingString += tcShader->GetShaderFileName();
}
TessellationEvaluationShader* teShader = program->GetTessellationEvaluationShader();
if( teShader )
{
teShader->CreateDeviceResource(this);
OpenGLShaderHandle* tesHandle =
(OpenGLShaderHandle*)teShader->GetShaderHandle();
glAttachShader(__program, tesHandle->mShader);
linkingString += " ";
linkingString += teShader->GetShaderFileName();
}
glLinkProgram(__program);
GLint linked;
glGetProgramiv(__program, GL_LINK_STATUS, &linked);
if( !linked )
{
GLint iInfoLen = 0;
glGetProgramiv(__program, GL_INFO_LOG_LENGTH, &iInfoLen);
if( iInfoLen > 1 )
{
char* acInfoLog = new char[iInfoLen];
glGetProgramInfoLog(__program, iInfoLen, 0, acInfoLog);
linkingString += " failed";
Terminal::Output(Terminal::OC_Error, "%s\n%s\n",
linkingString.c_str(), acInfoLog);
delete[] acInfoLog;
}
RTGI_ASSERT(false);
return 0;
}
#ifdef RTGI_OUTPUT_SHADER_RESOURCE_LOADING
linkingString += " finished";
Terminal::Output(Terminal::OC_Success, "%s\n", linkingString.c_str());
#endif
OPENGL_DEVICE_CHECK_ERROR;
//.........这里部分代码省略.........
示例4: make
static Program make(void)
{
VertexShader vs;
vs.Source(
"#version 150\n"
"uniform mat4 ModelMatrix;"
"uniform vec3 LightPosition;"
"uniform vec3 CameraPosition;"
"in vec4 Position;"
"out vec3 vertLightDir;"
"out vec3 vertViewDir;"
"void main(void)"
"{"
" gl_Position = ModelMatrix * Position;"
" vertLightDir = LightPosition - gl_Position.xyz;"
" vertViewDir = CameraPosition - gl_Position.xyz;"
"}"
).Compile();
GeometryShader gs;
gs.Source(
"#version 150\n"
"layout (triangles) in;"
"layout (triangle_strip, max_vertices=3) out;"
"uniform mat4 CameraMatrix;"
"in vec3 vertLightDir[3];"
"in vec3 vertViewDir[3];"
"out vec3 geomLightDir;"
"out vec3 geomViewDir;"
"out vec3 geomNormal;"
"void main(void)"
"{"
" geomNormal = normalize("
" cross("
" gl_in[1].gl_Position.xyz-"
" gl_in[0].gl_Position.xyz,"
" gl_in[2].gl_Position.xyz-"
" gl_in[0].gl_Position.xyz "
" )"
" );"
" for(int v=0; v!=3; ++v)"
" {"
" gl_Position = CameraMatrix * gl_in[v].gl_Position;"
" geomLightDir = vertLightDir[v];"
" geomViewDir = vertViewDir[v];"
" EmitVertex();"
" }"
" EndPrimitive();"
"}"
).Compile();
FragmentShader fs;
fs.Source(
"#version 150\n"
"in vec3 geomLightDir;"
"in vec3 geomViewDir;"
"in vec3 geomNormal;"
"out vec4 fragColor;"
"void main(void)"
"{"
" vec3 Normal = normalize(geomNormal);"
" vec3 LightDir = normalize(geomLightDir);"
" vec3 LightRefl = reflect(-LightDir, Normal);"
" vec3 ViewDir = normalize(geomViewDir);"
" fragColor = vec4("
" clamp(dot(Normal, ViewDir), 0, 1),"
" clamp(dot(Normal, LightDir),0, 1),"
" clamp(dot(ViewDir, LightRefl), 0, 1),"
" gl_FragCoord.z"
" );"
"}"
).Compile();
Program prog(ObjectDesc("Data"));
prog << vs << gs << fs;
prog.Link().Use();
return std::move(prog);
}
示例5: make_prog
static Program make_prog(void)
{
Program prog;
VertexShader vs;
vs.Source(StrCRef(
"#version 330\n"
"in vec3 Position;"
"in vec2 TexCoord;"
"out vec2 vertTexCoord;"
"void main(void)"
"{"
" gl_Position = vec4(Position, 1.0);"
" vertTexCoord = TexCoord;"
"}"
)).Compile();
prog.AttachShader(vs);
GeometryShader gs;
gs.Source(StrCRef(
"#version 330\n"
"#extension GL_ARB_gpu_shader5 : enable\n"
"layout(triangles, invocations = 7) in;"
"layout(triangle_strip, max_vertices = 21) out;"
"uniform mat4 ProjectionMatrix, CameraMatrix;"
"mat4 Matrix = ProjectionMatrix * CameraMatrix;"
"uniform vec3 CameraPosition;"
"in vec2 vertTexCoord[3];"
"out gl_PerVertex {"
" vec4 gl_Position;"
" float gl_ClipDistance[3];"
"};"
"flat out mat3 geomPositionFront;"
"flat out mat3 geomTexCoordFront;"
"flat out vec3 geomWFront;"
"noperspective out vec3 geomBarycentric;"
"out vec3 geomPosition;"
"out vec3 geomTexCoord;"
"void main(void)"
"{"
" vec4 world_pos[8*3];"
" vec3 tex_coord[8*3];"
" vec4 view_pos[8*3];"
" vec3 screen_pos[8*3];"
" bool front_facing[8];"
" int ft = gl_InvocationID+1;"
" for(int pass=0; pass!=2; ++pass)"
" {"
" bool first = pass == 0;"
" if(((ft == 0) && first) || (((ft != 0) && !first)))"
" {"
" for(int v=0; v!=3; ++v)"
" {"
" int w = 2-v;"
" world_pos[0+v] = gl_in[w].gl_Position;"
" tex_coord[0+v] = vec3(vertTexCoord[w], 0.0);"
" }"
" }"
" vec4 n = vec4(-0.15 * normalize(cross("
" gl_in[1].gl_Position.xyz-gl_in[0].gl_Position.xyz,"
" gl_in[2].gl_Position.xyz-gl_in[0].gl_Position.xyz "
" )), 0.0);"
" if(((ft == 1) && first) || (((ft != 1) && !first)))"
" {"
" for(int v=0; v!=3; ++v)"
" {"
" world_pos[3+v] = gl_in[v].gl_Position + n;"
" tex_coord[3+v] = vec3(vertTexCoord[v], 1.0);"
" }"
" }"
" for(int v=0; v!=3; ++v)"
" {"
" int w = (v+1)%3;"
" int k = 2+2*v;"
" if(((ft == k) && first) || (((ft != k) && !first)))"
" {"
" world_pos[6+0+v*6] = gl_in[v].gl_Position;"
" tex_coord[6+0+v*6] = vec3(vertTexCoord[v], 0.0);"
" world_pos[6+1+v*6] = gl_in[w].gl_Position;"
" tex_coord[6+1+v*6] = vec3(vertTexCoord[w], 0.0);"
" world_pos[6+2+v*6] = gl_in[v].gl_Position + n;"
" tex_coord[6+2+v*6] = vec3(vertTexCoord[v], 1.0);"
" }"
" k = 3+2*v;"
" if(((ft == k) && first) || (((ft != k) && !first)))"
" {"
" world_pos[6+3+v*6] = gl_in[w].gl_Position;"
" tex_coord[6+3+v*6] = vec3(vertTexCoord[w], 0.0);"
" world_pos[6+4+v*6] = gl_in[w].gl_Position + n;"
" tex_coord[6+4+v*6] = vec3(vertTexCoord[w], 1.0);"
//.........这里部分代码省略.........
示例6: make_transf_prog
static Program make_transf_prog(void)
{
VertexShader vs;
vs.Source(
"#version 330\n"
"uniform mat4 ModelMatrix;"
"in vec4 Position;"
"in vec3 Normal;"
"in vec2 TexCoord;"
"out gl_PerVertex {"
" vec4 gl_Position;"
"};"
"out vec3 vertNormal;"
"out vec2 vertTexCoord;"
"void main(void)"
"{"
" gl_Position = ModelMatrix * Position;"
" vertNormal = (ModelMatrix*vec4(Normal,0.0)).xyz;"
" vertTexCoord = TexCoord;"
"}"
);
vs.Compile();
GeometryShader gs;
gs.Source(
"#version 330\n"
"layout(triangles) in;"
"layout(triangle_strip, max_vertices = 15) out;"
"uniform mat4 CameraMatrix, ProjectionMatrix;"
"uniform vec3 LightPos;"
"uniform float Time;"
"in gl_PerVertex {"
" vec4 gl_Position;"
"} gl_in[];"
"in vec3 vertNormal[];"
"in vec2 vertTexCoord[];"
"out gl_PerVertex {"
" vec4 gl_Position;"
"};"
"out vec3 geomNormal;"
"out vec3 geomLight;"
"out float geomGlow;"
"flat out int geomTop;"
"void main(void)"
"{"
" vec3 FaceNormal = normalize("
" vertNormal[0]+"
" vertNormal[1]+"
" vertNormal[2] "
" );"
" vec2 FaceCoord = 0.33333 * ("
" vertTexCoord[0]+"
" vertTexCoord[1]+"
" vertTexCoord[2] "
" );"
" float Offs = (sin((FaceCoord.s + Time/10.0)* 3.14 * 2.0 * 10)*0.5 + 0.5)*0.4;"
" Offs *= cos(FaceCoord.t * 3.1415 * 2.0)*0.5 + 0.51;"
" vec3 pos[3], norm[3];"
" for(int i=0; i!=3; ++i)"
" pos[i] = gl_in[i].gl_Position.xyz;"
" for(int i=0; i!=3; ++i)"
" norm[i] = cross("
" FaceNormal, "
" normalize(pos[(i+1)%3] - pos[i])"
" );"
" vec3 pofs = FaceNormal * Offs;"
" geomTop = 0;"
" for(int i=0; i!=3; ++i)"
" {"
" geomNormal = norm[i];"
" for(int j=0; j!=2; ++j)"
" {"
" vec3 tpos = pos[(i+j)%3];"
" geomLight = LightPos-tpos;"
" geomGlow = 1.0;"
" gl_Position = "
" ProjectionMatrix *"
" CameraMatrix *"
" vec4(tpos, 1.0);"
" EmitVertex();"
" geomGlow = 0.7;"
" geomLight = LightPos-tpos+pofs;"
" gl_Position = "
" ProjectionMatrix *"
" CameraMatrix *"
" vec4(tpos + pofs, 1.0);"
" EmitVertex();"
" }"
" EndPrimitive();"
" }"
" geomGlow = 0.0;"
" geomTop = 1;"
" for(int i=0; i!=3; ++i)"
" {"
" geomLight = LightPos - (pos[i]+pofs);"
" geomNormal = vertNormal[i];"
" gl_Position = "
//.........这里部分代码省略.........
示例7: make
static Program make(void)
{
Program prog;
VertexShader vs;
vs.Source(
"#version 330\n"
"in vec4 Position;"
"in ivec3 TexCoord;"
"out ivec3 vertTexCoord;"
"void main(void)"
"{"
" gl_Position = Position;"
" vertTexCoord = TexCoord;"
"}"
).Compile();
prog.AttachShader(vs);
GeometryShader gs;
gs.Source(
"#version 330\n"
"layout (points) in;"
"layout (triangle_strip, max_vertices=24) out;"
"uniform float FadeCoef;"
"uniform sampler3D Pattern, FadeMap;"
"uniform mat4 ProjectionMatrix, CameraMatrix;"
"mat4 Matrix = ProjectionMatrix*CameraMatrix;"
"uniform vec3 LightPosition = vec3(100, 120, 150);"
"in ivec3 vertTexCoord[1];"
"out vec3 geomNormal;"
"out vec3 geomLightDir;"
"out vec3 geomTexCoord;"
"out float geomShadow;"
"float get_cell(ivec3 offs)"
"{"
" ivec3 coord = vertTexCoord[0]+offs;"
" float patt = texelFetch(Pattern, coord, 0).r;"
" float fade = texelFetch(FadeMap, coord, 0).r;"
" return clamp("
" (patt != 0.0)?"
" (FadeCoef-fade)*256.0:"
" 0.0, 0.0, 1.0"
" );"
"}"
"const ivec3 coffs[6] = ivec3[6]("
" ivec3(+1, 0, 0),"
" ivec3(-1, 0, 0),"
" ivec3( 0,+1, 0),"
" ivec3( 0,-1, 0),"
" ivec3( 0, 0,+1),"
" ivec3( 0, 0,-1) "
");"
"const mat3 tmats[6] = mat3[6]("
" mat3( 0, 0, 1, 0,-1, 0, 1, 0, 0),"
" mat3( 0, 0,-1, 0,-1, 0, -1, 0, 0),"
" mat3(-1, 0, 0, 0, 0, 1, 0, 1, 0),"
" mat3(-1, 0, 0, 0, 0,-1, 0,-1, 0),"
" mat3( 1, 0, 0, 0, 1, 0, 0, 0, 1),"
" mat3(-1, 0, 0, 0, 1, 0, 0, 0,-1) "
");"
"const vec3[8] nvec = vec3[8]("
" vec3( 0,-1,+1),"
" vec3(+1,-1,+1),"
" vec3(+1, 0,+1),"
" vec3(+1,+1,+1),"
" vec3( 0,+1,+1),"
" vec3(-1,+1,+1),"
" vec3(-1, 0,+1),"
" vec3(-1,-1,+1) "
");"
"void main(void)"
"{"
" float cc = get_cell(ivec3(0,0,0));"
" if(cc > 0.0)"
" {"
" float c05 = 0.5*cc;"
" float c0 = 0.5-c05;"
" float c1 = 0.5+c05;"
" for(int f=0; f!=6; ++f)"
" if(get_cell(coffs[f]) < 1.0)"
" {"
" int config = 0x0;"
" vec3 noffs[8];"
" vec3 nml = tmats[f][2];"
" float aoc = get_cell(ivec3(nml*2));"
" aoc += 0.8*get_cell(ivec3(nml*3));"
" for(int n=0; n!=8; ++n)"
" {"
" noffs[n] = nvec[n]*tmats[f];"
" float nc = get_cell(ivec3(noffs[n]));"
//.........这里部分代码省略.........
示例8: WritingExample
WritingExample(void)
{
VertexShader vs;
// Set the vertex shader source
vs.Source(
"#version 330\n"
"in vec4 Position;"
"void main(void)"
"{"
" gl_Position = Position;"
"}"
);
// compile it
vs.Compile();
GeometryShader gs;
// Set the geometry shader source
gs.Source(
"#version 330\n"
"layout(lines) in;"
"layout(triangle_strip, max_vertices = 4) out;"
"void main(void)"
"{"
" vec4 offs = vec4(0.02, 0.01, 0.0, 0.0);"
" gl_Position = gl_in[0].gl_Position - offs;"
" EmitVertex();"
" gl_Position = gl_in[0].gl_Position + offs;"
" EmitVertex();"
" gl_Position = gl_in[1].gl_Position - offs;"
" EmitVertex();"
" gl_Position = gl_in[1].gl_Position + offs;"
" EmitVertex();"
" EndPrimitive();"
"}"
);
// compile it
gs.Compile();
FragmentShader fs;
// set the fragment shader source
fs.Source(
"#version 330\n"
"out vec4 fragColor;"
"void main(void)"
"{"
" fragColor = vec4(0.0, 0.0, 0.0, 1.0);"
"}"
);
// compile it
fs.Compile();
// attach the shaders to the program
prog.AttachShader(vs);
prog.AttachShader(gs);
prog.AttachShader(fs);
// link and use it
prog.Link();
prog.Use();
const Vec2f points[] = {
Vec2f(-0.33f, +0.50f),
Vec2f(-0.45f, +0.70f),
Vec2f(-0.66f, +0.70f),
Vec2f(-0.66f, +0.30f),
Vec2f(-0.66f, -0.20f),
Vec2f(-0.35f, -0.15f),
Vec2f(-0.30f, +0.05f),
Vec2f(-0.20f, +0.50f),
Vec2f(-0.30f, +0.50f),
Vec2f(-0.33f, +0.50f),
Vec2f(-0.50f, +0.45f),
Vec2f(-0.10f, +0.40f),
Vec2f(+0.10f, +0.55f),
Vec2f(-0.20f, +0.40f),
Vec2f(-0.30f, -0.10f),
Vec2f( 0.00f, -0.10f),
Vec2f(+0.10f, -0.10f),
Vec2f(+0.20f, -0.10f),
Vec2f(+0.10f, +0.55f),
Vec2f(+0.20f, +0.00f),
Vec2f(+0.30f, -0.70f),
Vec2f( 0.00f, -0.75f),
Vec2f(-0.40f, -0.75f),
Vec2f( 0.00f, 0.00f),
Vec2f(+0.40f, +0.10f),
Vec2f(+0.60f, +0.10f),
Vec2f(+0.70f, +0.90f),
Vec2f(+0.55f, +0.90f),
Vec2f(+0.35f, +0.90f),
Vec2f(+0.10f, -0.10f),
Vec2f(+0.55f, 0.00f),
Vec2f(+0.90f, 0.10f),
Vec2f(+0.70f, 0.10f),
Vec2f(+0.90f, 0.20f)
};
BezierCurves<Vec2f, double, 3> bezier(
std::vector<Vec2f>(
points,
points+sizeof(points)/sizeof(points[0])
)
//.........这里部分代码省略.........
示例9: RTGI_ASSERT
//----------------------------------------------------------------------------
void OpenGLDevice::__GetUniformLocation(ShaderProgram* program,
ShaderUniform* uniform, const char* name)
{
OpenGLShaderProgramHandle* programHandle =
(OpenGLShaderProgramHandle*)program->GetProgramHandle();
RTGI_ASSERT(programHandle);
GLint loc = glGetUniformLocation(programHandle->mProgram, name);
if( !uniform->mUniformHandle )
{
uniform->mUniformHandle = new OpenGLShaderUniformHandle();
uniform->mUniformHandle->Device = this;
}
((OpenGLShaderUniformHandle*)uniform->mUniformHandle)->mUniform = loc;
#ifdef _DEBUG
if( loc < 0 )
{
Terminal::Output(Terminal::OC_Warning_Level4,
"Uniform: \'%s\' not found in: \n", name);
VertexShader* vs = program->GetVertexShader();
if( vs )
{
Terminal::Output(Terminal::OC_Warning_Level4, " %s\n",
vs->GetShaderFileName().c_str());
}
FragmentShader* fs = program->GetFragmentShader();
if( fs )
{
Terminal::Output(Terminal::OC_Warning_Level4, " %s\n",
fs->GetShaderFileName().c_str());
}
TessellationControlShader* tcs = program->GetTessellationControlShader();
if( tcs )
{
Terminal::Output(Terminal::OC_Warning_Level4, " %s\n",
tcs->GetShaderFileName().c_str());
}
TessellationEvaluationShader* tes = program->GetTessellationEvaluationShader();
if( tes )
{
Terminal::Output(Terminal::OC_Warning_Level4, " %s\n",
tes->GetShaderFileName().c_str());
}
GeometryShader* gs = program->GetGeometryShader();
if( gs )
{
Terminal::Output(Terminal::OC_Warning_Level4, " %s\n",
gs->GetShaderFileName().c_str());
}
ComputeShader* cs = program->GetComputeShader();
if( cs )
{
Terminal::Output(Terminal::OC_Warning_Level4, " %s\n",
cs->GetShaderFileName().c_str());
}
}
#endif
OPENGL_DEVICE_CHECK_ERROR;
}
示例10:
int ContextD3D11::CreateGeometryShader(void* data, size_t length, GeometryShader& gs) {
void* ptr;
int hr = device_->CreateGeometryShader(data, length, NULL, (ID3D11GeometryShader**)&ptr);
gs.set_internal_pointer(ptr);
return hr;
}
示例11: MultiViewportExample
MultiViewportExample(void)
: make_shape(1.0, 0.1, 8, 4, 48)
, shape_instr(make_shape.Instructions())
, shape_indices(make_shape.Indices())
, camera_position_3(prog, "CameraPosition[3]")
, camera_matrix_0(prog, "CameraMatrix[0]")
, camera_matrix_1(prog, "CameraMatrix[1]")
, camera_matrix_2(prog, "CameraMatrix[2]")
, camera_matrix_3(prog, "CameraMatrix[3]")
, model_matrix(prog, "ModelMatrix")
{
VertexShader vs;
// Set the vertex shader source
vs.Source(
"#version 330\n"
"uniform mat4 ModelMatrix;"
"uniform vec3 LightPos;"
"in vec4 Position;"
"in vec3 Normal;"
"out vec3 vertNormal;"
"out vec3 vertTexCoord;"
"out vec3 vertLightDir;"
"out vec3 vertLightRefl;"
"void main(void)"
"{"
" vertNormal = mat3(ModelMatrix)*Normal;"
" vertTexCoord = Normal;"
" gl_Position = ModelMatrix * Position;"
" vertLightDir = LightPos-gl_Position.xyz;"
" vertLightRefl = reflect(-vertLightDir, vertNormal);"
"}"
);
vs.Compile();
GeometryShader gs;
// Set the geometry shader source
gs.Source(
"#version 330\n"
"#extension GL_ARB_viewport_array : enable\n"
"layout(triangles) in;"
"layout(triangle_strip, max_vertices = 12) out;"
"uniform mat4 CameraMatrix[4];"
"uniform vec3 CameraPosition[4];"
"in vec3 vertNormal[];"
"in vec3 vertTexCoord[];"
"in vec3 vertLightDir[];"
"in vec3 vertLightRefl[];"
"out vec3 geomNormal;"
"out vec3 geomTexCoord;"
"out vec3 geomLightDir;"
"out vec3 geomLightRefl;"
"out vec3 geomViewDir;"
"out vec3 geomViewRefl;"
"void main(void)"
"{"
" for(int vp=0; vp!=4; ++vp)"
" {"
" gl_ViewportIndex = vp;"
" for(int v=0; v!=3; ++v)"
" {"
" geomNormal = vertNormal[v];"
" geomTexCoord = vertTexCoord[v];"
" geomLightDir = vertLightDir[v];"
" geomLightRefl = vertLightRefl[v];"
" geomViewDir = "
" CameraPosition[vp] - "
" gl_in[v].gl_Position.xyz;"
" geomViewRefl = reflect("
" -geomViewDir,"
" geomNormal"
" );"
" gl_Position = "
" CameraMatrix[vp] *"
" gl_in[v].gl_Position;"
" EmitVertex();"
" }"
" EndPrimitive();"
" }"
"}"
);
gs.Compile();
FragmentShader fs;
// set the fragment shader source
fs.Source(
"#version 330\n"
"uniform samplerCube TexUnit;"
"in vec3 geomNormal;"
"in vec3 geomTexCoord;"
"in vec3 geomLightDir;"
"in vec3 geomLightRefl;"
"in vec3 geomViewDir;"
"in vec3 geomViewRefl;"
//.........这里部分代码省略.........
示例12: attr
ReflectionExample(void)
: torus_indices(make_torus.Indices())
, torus_instr(make_torus.Instructions())
, vs_norm(ObjectDesc("Vertex-Normal"))
, vs_refl(ObjectDesc("Vertex-Reflection"))
, gs_refl(ObjectDesc("Geometry-Reflection"))
{
namespace se = oglplus::smart_enums;
// Set the normal object vertex shader source
vs_norm.Source(
"#version 330\n"
"in vec4 Position;"
"in vec3 Normal;"
"out vec3 geomColor;"
"out vec3 geomNormal;"
"out vec3 geomLight;"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"uniform vec3 LightPos;"
"void main(void)"
"{"
" gl_Position = ModelMatrix * Position;"
" geomColor = Normal;"
" geomNormal = mat3(ModelMatrix)*Normal;"
" geomLight = LightPos-gl_Position.xyz;"
" gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
"}"
);
// compile it
vs_norm.Compile();
// Set the reflected object vertex shader source
// which just passes data to the geometry shader
vs_refl.Source(
"#version 330\n"
"in vec4 Position;"
"in vec3 Normal;"
"out vec3 vertNormal;"
"void main(void)"
"{"
" gl_Position = Position;"
" vertNormal = Normal;"
"}"
);
// compile it
vs_refl.Compile();
// Set the reflected object geometry shader source
// This shader creates a reflection matrix that
// relies on the fact that the reflection is going
// to be done by the y-plane
gs_refl.Source(
"#version 330\n"
"layout(triangles) in;"
"layout(triangle_strip, max_vertices = 6) out;"
"in vec3 vertNormal[];"
"uniform mat4 ProjectionMatrix;"
"uniform mat4 CameraMatrix;"
"uniform mat4 ModelMatrix;"
"out vec3 geomColor;"
"out vec3 geomNormal;"
"out vec3 geomLight;"
"uniform vec3 LightPos;"
"mat4 ReflectionMatrix = mat4("
" 1.0, 0.0, 0.0, 0.0,"
" 0.0,-1.0, 0.0, 0.0,"
" 0.0, 0.0, 1.0, 0.0,"
" 0.0, 0.0, 0.0, 1.0 "
");"
"void main(void)"
"{"
" for(int v=0; v!=gl_in.length(); ++v)"
" {"
" vec4 Position = gl_in[v].gl_Position;"
" gl_Position = ModelMatrix * Position;"
" geomColor = vertNormal[v];"
" geomNormal = mat3(ModelMatrix)*vertNormal[v];"
" geomLight = LightPos - gl_Position.xyz;"
" gl_Position = "
" ProjectionMatrix *"
" CameraMatrix *"
" ReflectionMatrix *"
" gl_Position;"
" EmitVertex();"
" }"
" EndPrimitive();"
"}"
);
// compile it
gs_refl.Compile();
// set the fragment shader source
fs.Source(
"#version 330\n"
"in vec3 geomColor;"
"in vec3 geomNormal;"
"in vec3 geomLight;"
//.........这里部分代码省略.........
示例13: attr
CloudExample(void)
: projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
{
// Set the vertex shader source
vs.Source(
"#version 330\n"
"in vec4 Position;"
"uniform mat4 CameraMatrix;"
"void main(void)"
"{"
" gl_Position = "
" CameraMatrix *"
" Position;"
"}"
);
// compile it
vs.Compile();
// Set the geometry shader source
gs.Source(
"#version 330\n"
"layout(points) in;"
"layout(triangle_strip, max_vertices = 100) out;"
"const int p = 25;"
"const float hp = (p-1)*0.5;"
"uniform vec3 LightPos;"
"uniform mat4 CameraMatrix, ProjectionMatrix;"
"out vec3 geomTexCoord;"
"out vec3 geomLightDir;"
"void main(void)"
"{"
" float s = 0.6;"
" float yo[2] = float[2](-1.0, 1.0);"
" float xo[2] = float[2](-1.0, 1.0);"
" vec3 cx = vec3("
" CameraMatrix[0][0],"
" CameraMatrix[1][0],"
" CameraMatrix[2][0] "
" );"
" vec3 cy = vec3("
" CameraMatrix[0][1],"
" CameraMatrix[1][1],"
" CameraMatrix[2][1] "
" );"
" vec3 cz = vec3("
" CameraMatrix[0][2],"
" CameraMatrix[1][2],"
" CameraMatrix[2][2] "
" );"
" for(int k=0;k!=p;++k)"
" {"
" for(int j=0;j!=2;++j)"
" for(int i=0;i!=2;++i)"
" {"
" float zo = ((k - hp) / hp);"
" float xoffs = xo[i]*s;"
" float yoffs = yo[j]*s;"
" float zoffs = zo *s;"
" vec4 v = vec4("
" gl_in[0].gl_Position.x+xoffs,"
" gl_in[0].gl_Position.y+yoffs,"
" gl_in[0].gl_Position.z+zoffs,"
" 1.0"
" );"
" gl_Position = ProjectionMatrix * v;"
" geomLightDir = LightPos - v.xyz;"
" geomTexCoord = "
" vec3(0.5, 0.5, 0.5)+"
" cx*(xo[i])*0.707+"
" cy*(yo[j])*0.707+"
" cz*(zo )*0.707;"
" EmitVertex();"
" }"
" EndPrimitive();"
" }"
"}"
);
// compile it
gs.Compile();
// set the fragment shader source
fs.Source(
"#version 330\n"
"uniform sampler3D cloudTex;"
"in vec3 geomTexCoord;"
"in vec3 geomLightDir;"
"out vec4 fragColor;"
"void main(void)"
"{"
" float d = texture(cloudTex, geomTexCoord).r;"
" float o = 1.0;"
" float s = 2.0/128.0;"
" float r = s * 8.0;"
" vec3 sampleOffs = normalize(geomLightDir) * s;"
" vec3 samplePos = geomTexCoord;"
" if(d > 0.01) while(o > 0.0)"
" {"
" if(samplePos.x<0.0 || samplePos.x>1.0)"
//.........这里部分代码省略.........
示例14: attr
TorusExample(void)
: make_torus(1.0, 0.5, 12, 12)
, torus_instr(make_torus.Instructions())
, torus_indices(make_torus.Indices())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
, light_pos_cam(prog, "LightPosCam")
, front_color(prog, "FrontColor")
, back_color(prog, "BackColor")
{
vs.Source(
"#version 330\n"
"uniform mat4 ModelMatrix, CameraMatrix;"
"in vec4 Position;"
"void main(void)"
"{"
" gl_Position = CameraMatrix *"
" ModelMatrix * Position;"
"}"
);
vs.Compile();
gs.Source(
"#version 330\n"
"layout(triangles) in;"
"layout(triangle_strip, max_vertices = 8) out;"
"uniform mat4 ProjectionMatrix;"
"uniform vec4 LightPosCam;"
"out vec3 geomLightDir;"
"out float geomOpacity;"
"void main(void)"
"{"
" vec4 c = vec4(("
" gl_in[0].gl_Position.xyz+"
" gl_in[1].gl_Position.xyz+"
" gl_in[2].gl_Position.xyz "
" ) * 0.333333, 1.0);"
" for(int v = 0; v != 4; ++v)"
" {"
" vec4 b = gl_in[v%3].gl_Position;"
" vec4 a = vec4("
" b.xyz + (c.xyz - b.xyz)*0.3,"
" 1.0"
" );"
" gl_Position = ProjectionMatrix * a;"
" geomLightDir = (LightPosCam - a).xyz;"
" geomOpacity = 1.0;"
" EmitVertex();"
" gl_Position = ProjectionMatrix * b;"
" geomLightDir = (LightPosCam - b).xyz;"
" geomOpacity = 0.0;"
" EmitVertex();"
" }"
" EndPrimitive();"
"}"
);
gs.Compile();
fs.Source(
"#version 330\n"
"in vec3 geomLightDir;"
"in float geomOpacity;"
"uniform vec3 FrontColor, BackColor;"
"out vec4 fragColor;"
"void main(void)"
"{"
" float l = length(geomLightDir);"
" vec3 color = gl_FrontFacing?"
" FrontColor:"
" BackColor;"
" fragColor = vec4(color*(4.0/l), geomOpacity);"
"}"
);
fs.Compile();
prog.AttachShader(vs);
prog.AttachShader(gs);
prog.AttachShader(fs);
prog.Link();
torus.Bind();
verts.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_torus.Positions(data);
Buffer::Data(Buffer::Target::Array, data);
prog.Use();
VertexAttribArray attr(prog, "Position");
attr.Setup(n_per_vertex, DataType::Float);
attr.Enable();
}
gl.ClearColor(0.8f, 0.7f, 0.6f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.DepthFunc(CompareFn::LEqual);
gl.FrontFace(make_torus.FaceWinding());
//.........这里部分代码省略.........
示例15: attr
SinglePassEdgeExample(void)
: make_shape(1, shapes::SubdivSphereInitialShape::Octohedron)
, shape_instr(make_shape.Instructions())
, shape_indices(make_shape.Indices())
, vs(ObjectDesc("Vertex"))
, gs(ObjectDesc("Geometry"))
, fs(ObjectDesc("Fragment"))
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
, viewport_dimensions(prog, "ViewportDimensions")
, edge_width(prog, "EdgeWidth")
{
vs.Source(StrLit(
"#version 330\n"
"const vec3 LightPosition = vec3(10.0, 10.0, 7.0);"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"in vec4 Position;"
"out vec3 vertNormal;"
"out vec3 vertLightDir;"
"void main(void)"
"{"
" gl_Position = "
" ModelMatrix *"
" Position;"
" vertNormal = ("
" ModelMatrix *"
" vec4(Position.xyz, 0.0)"
" ).xyz;"
" vertLightDir = "
" LightPosition -"
" gl_Position.xyz;"
" gl_Position = "
" ProjectionMatrix *"
" CameraMatrix *"
" gl_Position;"
"}"
));
vs.Compile();
gs.Source(StrLit(
"#version 330\n"
"layout (triangles) in;"
"layout (triangle_strip, max_vertices = 3) out;"
"uniform vec2 ViewportDimensions;"
"in vec3 vertNormal[], vertLightDir[];"
"noperspective out vec3 geomDist;"
"flat out vec3 geomNormal;"
"flat out vec3 geomColor;"
"out vec3 geomLightDir;"
"void main(void)"
"{"
" geomNormal = normalize("
" vertNormal[0]+"
" vertNormal[1]+"
" vertNormal[2]"
" );"
" geomColor = normalize(abs("
" vec3(1.0, 1.0, 1.0)-"
" geomNormal"
" ));"
" vec2 ScreenPos[3];"
" for(int i=0; i!=3; ++i)"
" {"
" ScreenPos[i] = "
" ViewportDimensions*"
" gl_in[i].gl_Position.xy/"
" gl_in[i].gl_Position.w;"
" }"
" vec2 TmpVect[3];"
" for(int i=0; i!=3; ++i)"
" {"
" TmpVect[i] = "
" ScreenPos[(i+2)%3]-"
" ScreenPos[(i+1)%3];"
" }"
" const vec3 EdgeMask[3] = vec3[3]("
" vec3(1.0, 0.0, 0.0),"
" vec3(0.0, 1.0, 0.0),"
" vec3(0.0, 0.0, 1.0) "
" );"
" for(int i=0; i!=3; ++i)"
" {"
" float Dist = abs("
" TmpVect[(i+1)%3].x*TmpVect[(i+2)%3].y-"
" TmpVect[(i+1)%3].y*TmpVect[(i+2)%3].x "
" ) / length(TmpVect[i]);"
//.........这里部分代码省略.........