本文整理汇总了C++中GeometryShader::Compile方法的典型用法代码示例。如果您正苦于以下问题:C++ GeometryShader::Compile方法的具体用法?C++ GeometryShader::Compile怎么用?C++ GeometryShader::Compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeometryShader
的用法示例。
在下文中一共展示了GeometryShader::Compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: attr
TessellationExample(void)
: shape_instr(make_shape.Instructions(PrimitiveType::Patches))
, shape_indices(make_shape.Indices())
, vs(ObjectDesc("Vertex"))
, cs(ObjectDesc("Tessellation Control"))
, es(ObjectDesc("Tessellation Evaluation"))
, gs(ObjectDesc("Geometry"))
, fs(ObjectDesc("Fragment"))
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
, offset(prog, "Offset")
, view_position(prog, "ViewPosition")
, viewport_dimensions(prog, "ViewportDimensions")
{
vs.Source(
"#version 330\n"
"uniform vec3 ViewPosition;"
"in vec3 Position;"
"out vec3 vertPosition;"
"out float vertDistance;"
"void main(void)"
"{"
" vertPosition = Position;"
" vertDistance = length(ViewPosition - vertPosition);"
"}"
);
vs.Compile();
cs.Source(
"#version 330\n"
"#extension ARB_tessellation_shader : enable\n"
"layout(vertices = 3) out;"
"in vec3 vertPosition[];"
"in float vertDistance[];"
"out vec3 tecoPosition[];"
"int tessLevel(float dist)"
"{"
" return int(9.0 / sqrt(dist+0.1));"
"}"
"void main(void)"
"{"
" tecoPosition[gl_InvocationID] ="
" vertPosition[gl_InvocationID];"
" if(gl_InvocationID == 0)"
" {"
" gl_TessLevelInner[0] = tessLevel(("
" vertDistance[0]+"
" vertDistance[1]+"
" vertDistance[2] "
" )*0.333);"
" gl_TessLevelOuter[0] = tessLevel(("
" vertDistance[1]+"
" vertDistance[2] "
" )*0.5);"
" gl_TessLevelOuter[1] = tessLevel(("
" vertDistance[2]+"
" vertDistance[0] "
" )*0.5);"
" gl_TessLevelOuter[2] = tessLevel(("
" vertDistance[0]+"
" vertDistance[1] "
" )*0.5);"
" }"
"}"
);
cs.Compile();
es.Source(
"#version 330\n"
"#extension ARB_tessellation_shader : enable\n"
"layout(triangles, equal_spacing, ccw) in;"
"const vec3 LightPosition = vec3(12.0, 10.0, 7.0);"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"in vec3 tecoPosition[];"
"out vec3 teevNormal;"
"out vec3 teevLightDir;"
"void main(void)"
"{"
" vec3 p0 = gl_TessCoord.x * tecoPosition[0];"
" vec3 p1 = gl_TessCoord.y * tecoPosition[1];"
" vec3 p2 = gl_TessCoord.z * tecoPosition[2];"
" vec4 tempPosition = vec4(normalize(p0+p1+p2), 0.0);"
//.........这里部分代码省略.........
示例2: attr
LandscapeExample(void)
: grid_side(8)
, make_plane(
Vec3f(0.0f, 0.0f, 0.0f),
Vec3f(1.0f, 0.0f, 0.0f),
Vec3f(0.0f, 0.0f,-1.0f),
grid_side, grid_side
), plane_instr(make_plane.Instructions())
, plane_indices(make_plane.Indices())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, vc_int(prog, "vc_int")
, gc_int(prog, "gc_int")
, fc_int(prog, "fc_int")
{
VertexShader vs;
vs.Source(StrLit(
"#version 420\n"
"uniform mat4 ProjectionMatrix, CameraMatrix;"
"layout(binding = 0, offset = 0) uniform atomic_uint vc;"
"const float mult = 1.0/128.0;"
"uniform float vc_int;"
"in vec4 Position;"
"out vec3 vertColor;"
"void main(void)"
"{"
" gl_Position = "
" ProjectionMatrix *"
" CameraMatrix *"
" Position;"
" vertColor = vec3("
" fract(atomicCounterIncrement(vc)*mult),"
" 0.0,"
" 0.0 "
" )*max(vc_int, 0.0);"
"}"
));
vs.Compile();
prog.AttachShader(vs);
GeometryShader gs;
gs.Source(StrLit(
"#version 420\n"
"layout (triangles) in;"
"layout (triangle_strip, max_vertices = 3) out;"
"layout(binding = 0, offset = 4) uniform atomic_uint gc;"
"const float mult = 1.0/128.0;"
"uniform float gc_int;"
"in vec3 vertColor[3];"
"out vec3 geomColor;"
"void main(void)"
"{"
" vec3 Color = vec3("
" 0.0,"
" fract(atomicCounterIncrement(gc)*mult),"
" 0.0 "
" )*max(gc_int, 0.0);"
" for(int v=0; v!=3; ++v)"
" {"
" gl_Position = gl_in[v].gl_Position;"
" geomColor = vertColor[v] + Color;"
" EmitVertex();"
" }"
" EndPrimitive();"
"}"
));
gs.Compile();
prog.AttachShader(gs);
FragmentShader fs;
fs.Source(StrLit(
"#version 420\n"
"layout(binding = 0, offset = 8) uniform atomic_uint fc;"
"const float mult = 1.0/4096.0;"
"uniform float fc_int;"
"in vec3 geomColor;"
"out vec3 fragColor;"
"void main(void)"
"{"
" vec3 Color = vec3("
" 0.0,"
" 0.0,"
" sqrt(fract(atomicCounterIncrement(fc)*mult))"
" )*max(fc_int, 0.0);"
" fragColor = geomColor + Color;"
"}"
));
fs.Compile();
//.........这里部分代码省略.........
示例3: 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 = "
//.........这里部分代码省略.........
示例4: attr
CubeMapExample(void)
: make_shape(4)
, shape_instr(make_shape.Instructions())
, shape_indices(make_shape.Indices())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
{
vs.Source(
"#version 330\n"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"in vec4 Position;"
"out vec3 vertNormal;"
"out vec3 vertTexCoord;"
"out vec3 vertLightDir;"
"out vec3 vertViewDir;"
"uniform vec3 LightPos;"
"void main(void)"
"{"
" vec3 Normal = Position.xyz;"
" gl_Position = ModelMatrix * Position;"
" vertNormal = mat3(ModelMatrix)*Normal;"
" vertTexCoord = Normal;"
" vertLightDir = LightPos - gl_Position.xyz;"
" vertViewDir = (vec4(0.0, 0.0, 1.0, 1.0)*CameraMatrix).xyz;"
" gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
"}"
);
vs.Compile();
gs.Source(
"#version 330\n"
"layout (triangles) in;"
"layout (triangle_strip, max_vertices = 3) out;"
"in vec3 vertNormal[3];"
"in vec3 vertTexCoord[3];"
"in vec3 vertLightDir[3];"
"in vec3 vertViewDir[3];"
"out vec3 geomNormal;"
"out vec3 geomTexCoord;"
"out vec3 geomLightDir;"
"out vec3 geomLightRefl;"
"out vec3 geomViewDir;"
"void main(void)"
"{"
" vec3 FaceNormal = 0.333333*("
" vertNormal[0]+"
" vertNormal[1]+"
" vertNormal[2] "
" );"
" for(int v=0; v!=3; ++v)"
" {"
" gl_Position = gl_in[v].gl_Position;"
" geomNormal = 0.5*(vertNormal[v]+FaceNormal);"
" geomTexCoord = vertTexCoord[v];"
" geomLightDir = vertLightDir[v];"
" geomLightRefl = reflect("
" -normalize(geomLightDir),"
" normalize(FaceNormal)"
" );"
" geomViewDir = vertViewDir[v];"
" EmitVertex();"
" }"
" EndPrimitive();"
"}"
);
gs.Compile();
fs.Source(
"#version 330\n"
"uniform samplerCube TexUnit;"
"in vec3 geomNormal;"
"in vec3 geomTexCoord;"
"in vec3 geomLightDir;"
"in vec3 geomLightRefl;"
"in vec3 geomViewDir;"
"out vec3 fragColor;"
"void main(void)"
"{"
" vec3 lt = vec3(1.0, 1.0, 1.0);"
" vec3 tex = texture(TexUnit, geomTexCoord).rgb;"
" float d = dot("
" normalize(geomNormal), "
" normalize(geomLightDir)"
" );"
" float s = dot("
" normalize(geomLightRefl),"
" normalize(geomViewDir)"
" );"
" float b = 1.0-sqrt(max(dot("
" normalize(geomNormal),"
" normalize(geomViewDir)"
" ), 0.0));"
" float ea = clamp(tex.b*(-d+0.2), 0.0, 1.0);"
" float sr = 1.0-tex.b*0.8;"
" fragColor = "
//.........这里部分代码省略.........
示例5: attr
SmokeExample(void)
: emitters()
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
{
emitters.push_back(
ParticleSystem(
ListOf<Vec3f>
(Vec3f(-20.0f, -10.0f, 10.0f))
(Vec3f( 20.0f, 0.0f, -20.0f))
(Vec3f( 20.0f, 10.0f, 20.0f))
(Vec3f(-20.0f, 0.0f, -10.0f))
.As<std::vector<Vec3f>>(), 5.0, 200.0
)
);
emitters.push_back(
ParticleSystem(
ListOf<Vec3f>
(Vec3f( 30.0f, 0.0f, 0.0f))
(Vec3f(-30.0f, 0.0f, 0.0f))
(Vec3f(-20.0f, 20.0f, 0.0f))
(Vec3f( 20.0f, -10.0f, 0.0f))
.As<std::vector<Vec3f>>(), 3.0, 200.0
)
);
emitters.push_back(
ParticleSystem(
ListOf<Vec3f>
(Vec3f( 5.0f, 20.0f, 20.0f))
(Vec3f( -5.0f, 20.0f, -20.0f))
(Vec3f( 5.0f, -20.0f, -20.0f))
(Vec3f( -5.0f, -20.0f, 20.0f))
.As<std::vector<Vec3f>>(), 20.0, 100.0
)
);
// Set the vertex shader source
vs.Source(
"#version 330\n"
"uniform mat4 CameraMatrix;"
"in vec4 Position;"
"in float Age;"
"out float vertAge;"
"void main(void)"
"{"
" gl_Position = CameraMatrix * Position;"
" vertAge = Age;"
"}"
);
// compile it
vs.Compile();
// Set the geometry shader source
gs.Source(
"#version 330\n"
"layout(points) in;"
"layout(triangle_strip, max_vertices = 4) out;"
"uniform mat4 ProjectionMatrix;"
"in float vertAge[];"
"out float geomAge;"
"void main(void)"
"{"
" if(vertAge[0] > 1.0) return;"
" float s = 0.5;"
" float yo[2] = float[2](-1.0, 1.0);"
" float xo[2] = float[2](-1.0, 1.0);"
" for(int j=0;j!=2;++j)"
" for(int i=0;i!=2;++i)"
" {"
" float xoffs = xo[i]*(1.0+vertAge[0])*s;"
" float yoffs = yo[j]*(1.0+vertAge[0])*s;"
" gl_Position = ProjectionMatrix * vec4("
" gl_in[0].gl_Position.x-xoffs,"
" gl_in[0].gl_Position.y-yoffs,"
" gl_in[0].gl_Position.z,"
" 1.0"
" );"
" geomAge = vertAge[0];"
" EmitVertex();"
" }"
" EndPrimitive();"
"}"
);
// compile it
gs.Compile();
// set the fragment shader source
fs.Source(
"#version 330\n"
"in float geomAge;"
"out vec4 fragColor;"
"void main(void)"
"{"
" vec3 Color1 = vec3(1.0, 0.5, 0.5);"
" vec3 Color2 = vec3(0.3, 0.1, 0.1);"
" fragColor = vec4("
" mix(Color1, Color2, geomAge),"
" 1.0 - geomAge"
" );"
"}"
);
//.........这里部分代码省略.........
示例6: 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)"
//.........这里部分代码省略.........
示例7: attr
ShadowExample()
: make_torus(1.0, 0.7, 72, 48)
, torus_indices(make_torus.Indices())
, torus_instr(make_torus.Instructions())
, object_projection_matrix(object_prog)
, object_camera_matrix(object_prog)
, object_model_matrix(object_prog)
, shadow_projection_matrix(shadow_prog)
, shadow_camera_matrix(shadow_prog)
, shadow_model_matrix(shadow_prog)
, object_color(object_prog)
, object_light_mult(object_prog) {
vs_object.Source(
"#version 140\n"
"in vec4 Position;"
"in vec3 Normal;"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"uniform vec3 LightPos;"
"out vec3 vertNormal;"
"out vec3 vertLight;"
"void main()"
"{"
" gl_Position = ModelMatrix * Position;"
" vertNormal = mat3(ModelMatrix)*Normal;"
" vertLight = LightPos - gl_Position.xyz;"
" gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
"}");
vs_object.Compile();
fs_object.Source(
"#version 140\n"
"in vec3 vertNormal;"
"in vec3 vertLight;"
"uniform vec3 Color;"
"uniform float LightMult;"
"out vec4 fragColor;"
"void main()"
"{"
" float l = sqrt(length(vertLight));"
" float d = l > 0.0 ?"
" dot("
" vertNormal,"
" normalize(vertLight)"
" ) / l : 0.0;"
" float i = 0.3 + max(d, 0.0) * LightMult;"
" fragColor = vec4(Color*i, 1.0);"
"}");
fs_object.Compile();
object_prog.AttachShader(vs_object);
object_prog.AttachShader(fs_object);
object_prog.Link().Use();
object_projection_matrix.BindTo("ProjectionMatrix");
object_camera_matrix.BindTo("CameraMatrix");
object_model_matrix.BindTo("ModelMatrix");
object_color.BindTo("Color");
object_light_mult.BindTo("LightMult");
vs_shadow.Source(
"#version 150\n"
"in vec4 Position;"
"in vec3 Normal;"
"uniform mat4 ModelMatrix;"
"uniform vec3 LightPos;"
"out float ld;"
"void main()"
"{"
" gl_Position = ModelMatrix * Position;"
" vec3 geomNormal = mat3(ModelMatrix)*Normal;"
" vec3 lightDir = LightPos - gl_Position.xyz;"
" ld = dot(geomNormal, normalize(lightDir));"
"}");
vs_shadow.Compile();
gs_shadow.Source(
"#version 150\n"
"layout(triangles) in;"
"layout(triangle_strip, max_vertices = 12) out;"
"in float ld[];"
"uniform mat4 CameraMatrix, ProjectionMatrix;"
"uniform vec3 LightPos;"
"void main()"
"{"
" for(int v=0; v!=3; ++v)"
" {"
" int a = v, b = (v+1)%3, c = (v+2)%3;"
" vec4 pa = gl_in[a].gl_Position;"
" vec4 pb = gl_in[b].gl_Position;"
" vec4 pc = gl_in[c].gl_Position;"
" vec4 px, py;"
" if(ld[a] == 0.0 && ld[b] == 0.0)"
" {"
" px = pa;"
" py = pb;"
" }"
" else if(ld[a] > 0.0 && ld[b] < 0.0)"
//.........这里部分代码省略.........
示例8: attr
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: attr
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;"
//.........这里部分代码省略.........
示例10: input
BlenderMeshExample(int argc, const char* argv[])
: prog()
, camera_matrix(prog, "CameraMatrix")
, light_position(prog, "LightPosition")
, camera_position(prog, "CameraPosition")
, face_normals(prog, "FaceNormals")
, element_count(0)
{
using namespace oglplus;
VertexShader vs;
vs.Source(
"#version 330\n"
"uniform mat4 CameraMatrix, ProjectionMatrix;"
"uniform vec3 LightPosition, CameraPosition;"
"mat4 Matrix = ProjectionMatrix * CameraMatrix;"
"in vec3 Position;"
"in vec3 Normal;"
"out vec3 vertNormal;"
"out vec3 vertLightDir;"
"out vec3 vertViewDir;"
"void main(void)"
"{"
" vertNormal = Normal;"
" vertLightDir = LightPosition - Position;"
" vertViewDir = CameraPosition - Position;"
" gl_Position = Matrix * vec4(Position, 1.0);"
"}"
);
vs.Compile();
prog.AttachShader(vs);
GeometryShader gs;
gs.Source(
"#version 330\n"
"layout (triangles) in;"
"layout (triangle_strip, max_vertices=3) out;"
"uniform bool FaceNormals;"
"in vec3 vertNormal[3];"
"in vec3 vertLightDir[3];"
"in vec3 vertViewDir[3];"
"out vec3 geomNormal;"
"out vec3 geomLightDir;"
"out vec3 geomViewDir;"
"void main(void)"
"{"
" vec3 fn;"
" if(FaceNormals)"
" {"
" vec3 p0 = gl_in[0].gl_Position.xyz;"
" vec3 p1 = gl_in[1].gl_Position.xyz;"
" vec3 p2 = gl_in[2].gl_Position.xyz;"
" fn = normalize(cross(p1-p0, p2-p0));"
" }"
" for(int v=0; v!=3; ++v)"
" {"
" gl_Position = gl_in[v].gl_Position;"
" if(FaceNormals) geomNormal = fn;"
" else geomNormal = vertNormal[v];"
" geomLightDir = vertLightDir[v];"
" geomViewDir = vertViewDir[v];"
" EmitVertex();"
" }"
" EndPrimitive();"
"}"
);
gs.Compile();
prog.AttachShader(gs);
FragmentShader fs;
fs.Source(
"#version 330\n"
"in vec3 geomNormal;"
"in vec3 geomLightDir;"
"in vec3 geomViewDir;"
"out vec3 fragColor;"
"void main(void)"
"{"
" vec3 LightColor = vec3(1.0, 1.0, 1.0);"
" vec3 MatColor = vec3(0.5, 0.5, 0.5);"
" vec3 LightRefl = reflect(-geomLightDir, geomNormal);"
" float Ambient = 0.3;"
" float Diffuse = max(dot("
" normalize(geomNormal),"
" normalize(geomLightDir)"
" ), 0.0);"
//.........这里部分代码省略.........
示例11: attr
TorusExample(void)
: make_torus(1.0, 0.5, 18, 36)
, torus_instr(make_torus.Instructions())
, torus_indices(make_torus.Indices())
, vs(ObjectDesc("Vertex"))
, gs(ObjectDesc("Geometry"))
, face_fs(ObjectDesc("Face fragment"))
, frame_fs(ObjectDesc("Frame fragment"))
, transf_prog(ObjectDesc("Transformation"))
, face_prog(ObjectDesc("Face"))
, frame_prog(ObjectDesc("Frame"))
, projection_matrix(transf_prog, "ProjectionMatrix")
, camera_matrix(transf_prog, "CameraMatrix")
, model_matrix(transf_prog, "ModelMatrix")
, transf_time(transf_prog, "Time")
{
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();
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);"
//.........这里部分代码省略.........
示例12: 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());
//.........这里部分代码省略.........
示例13: 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]);"
//.........这里部分代码省略.........
示例14: 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;"
//.........这里部分代码省略.........
示例15: attr
TessellationExample(void)
: shape_instr(make_shape.Instructions())
, shape_indices(make_shape.Indices())
, tess_level(prog, "TessLevel")
, viewport_dimensions(prog, "ViewportDimensions")
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
{
vs.Source(
"#version 330\n"
"in vec4 Position;"
"void main(void)"
"{"
" gl_Position = Position;"
"}"
);
vs.Compile();
gs.Source(
"#version 330\n"
"layout (triangles) in;"
"layout (triangle_strip, max_vertices = 48) out;"
"const vec3 LightPosition = vec3(12.0, 10.0, 7.0);"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"uniform vec2 ViewportDimensions;"
"uniform int TessLevel;"
"noperspective out vec3 geomDist;"
"flat out vec3 geomNormal;"
"out vec3 geomColor;"
"out vec3 geomLightDir;"
"void make_triangle(vec4 p0, vec4 p1, vec4 p2)"
"{"
" vec3 n0 = (ModelMatrix*vec4(p0.xyz, 0)).xyz;"
" vec3 n1 = (ModelMatrix*vec4(p1.xyz, 0)).xyz;"
" vec3 n2 = (ModelMatrix*vec4(p2.xyz, 0)).xyz;"
" vec4 m0 = ModelMatrix*p0;"
" vec4 m1 = ModelMatrix*p1;"
" vec4 m2 = ModelMatrix*p2;"
" vec4 c0 = ProjectionMatrix*CameraMatrix*m0;"
" vec4 c1 = ProjectionMatrix*CameraMatrix*m1;"
" vec4 c2 = ProjectionMatrix*CameraMatrix*m2;"
" vec2 s0 = ViewportDimensions * c0.xy/c0.w;"
" vec2 s1 = ViewportDimensions * c1.xy/c1.w;"
" vec2 s2 = ViewportDimensions * c2.xy/c2.w;"
" vec2 v0 = s2 - s1;"
" vec2 v1 = s0 - s2;"
" vec2 v2 = s1 - s0;"
" float d0 = abs(v1.x*v2.y-v1.y*v2.x)/length(v0);"
" float d1 = abs(v2.x*v0.y-v2.y*v0.x)/length(v1);"
" float d2 = abs(v0.x*v1.y-v0.y*v1.x)/length(v2);"
" geomNormal = normalize(n0+n1+n2);"
" gl_Position = c0;"
" geomColor = normalize(abs(vec3(1, 1, 1) - n0));"
" geomLightDir = LightPosition - m0.xyz;"
" geomDist = vec3(d0, 0.0, 0.0);"
" EmitVertex();"
" gl_Position = c1;"
" geomColor = normalize(abs(vec3(1, 1, 1) - n1));"
" geomLightDir = LightPosition - m1.xyz;"
" geomDist = vec3(0.0, d1, 0.0);"
" EmitVertex();"
" gl_Position = c2;"
" geomColor = normalize(abs(vec3(1, 1, 1) - n2));"
" geomLightDir = LightPosition - m2.xyz;"
" geomDist = vec3(0.0, 0.0, d2);"
" EmitVertex();"
" EndPrimitive();"
"}"
"void do_tess_1(vec4 p_0, vec4 p_1, vec4 p_2, int l)"
"{"
" if(l == 1) make_triangle(p_0, p_1, p_2);"
" else"
" {"
" vec4 p01 = vec4(normalize(p_0.xyz+p_1.xyz), 1.0);"
" vec4 p12 = vec4(normalize(p_1.xyz+p_2.xyz), 1.0);"
" vec4 p20 = vec4(normalize(p_2.xyz+p_0.xyz), 1.0);"
" make_triangle(p_0, p01, p20);"
" make_triangle(p01, p_1, p12);"
" make_triangle(p20, p12, p_2);"
" make_triangle(p01, p12, p20);"
" }"
"}"
//.........这里部分代码省略.........