当前位置: 首页>>代码示例>>C++>>正文


C++ VertexShader::Compile方法代码示例

本文整理汇总了C++中VertexShader::Compile方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexShader::Compile方法的具体用法?C++ VertexShader::Compile怎么用?C++ VertexShader::Compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VertexShader的用法示例。


在下文中一共展示了VertexShader::Compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: make_vs

	// Makes the common shared vertex shader
	static VertexShader make_vs(void)
	{
		VertexShader shader;

		shader.Source(
			"#version 140\n"
			"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
			"in vec4 Position;"
			"in vec3 Normal;"
			"in vec2 TexCoord;"
			"out vec2 vertTexCoord;"
			"out vec3 vertNormal;"
			"out vec3 vertLight;"
			"uniform vec3 LightPos;"
			"void main(void)"
			"{"
			"	vertTexCoord = TexCoord;"
			"	gl_Position = ModelMatrix * Position;"
			"	vertNormal = mat3(ModelMatrix)*Normal;"
			"	vertLight = LightPos - gl_Position.xyz;"
			"	gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
			"}"
		);

		shader.Compile();
		return shader;
	}
开发者ID:AdamSimpson,项目名称:oglplus,代码行数:28,代码来源:020_shaded_objects.cpp

示例2: make_prog

	static Program make_prog(void)
	{
		VertexShader vs;
		vs.Source(
			"#version 130\n"
			"uniform mat4 ProjectionMatrix, ModelMatrix, CameraMatrix;"
			"uniform vec4 ClipPlane;"
			"attribute vec4 Position;"
			"attribute vec2 TexCoord;"
			"varying vec2 vertTexCoord;"
			"void main(void)"
			"{"
			"	vertTexCoord = TexCoord;"
			"	gl_Position = "
			"		ModelMatrix *"
			"		Position;"
			"	gl_ClipDistance[0] = dot(ClipPlane, gl_Position);"
			"	gl_Position = "
			"		ProjectionMatrix *"
			"		CameraMatrix *"
			"		gl_Position;"
			"}"
		);
		vs.Compile();

		FragmentShader fs;
		fs.Source(
			"#version 130\n"
			"varying vec2 vertTexCoord;"
			"void main(void)"
			"{"
			"	float i = ("
			"		int(vertTexCoord.x*36) % 2+"
			"		int(vertTexCoord.y*24) % 2"
			"	) % 2;"
			"	if(gl_FrontFacing)"
			"	{"
			"		gl_FragColor = vec4(1-i/2, 1-i/2, 1-i/2, 1.0);"
			"	}"
			"	else"
			"	{"
			"		gl_FragColor = vec4(0+i/2, 0+i/2, 0+i/2, 1.0);"
			"	}"
			"}"
		);
		fs.Compile();

		Program prog;
		prog.AttachShader(vs);
		prog.AttachShader(fs);
		prog.Link();
		prog.Use();

		return prog;
	}
开发者ID:AdamSimpson,项目名称:oglplus,代码行数:55,代码来源:017_clipped_torus.cpp

示例3: FindVertexShaderRaii

//==============================================================================
VertexShader * CGraphicsMgr::LoadVertexShader (
    const std::wstring &             name,
    const std::wstring &             filepath,
    const std::string &              entryFunction,
    const D3D11_INPUT_ELEMENT_DESC * inputDesc,
    unsigned                         inputElementCount
) {

    VertexShader * shader = FindVertexShaderRaii(name);
    
    if (!shader->Compile(name, filepath, entryFunction, inputDesc, inputElementCount))
        return nullptr;

    return shader;

}
开发者ID:Akaito,项目名称:codesaru-environ_src_csaru-dx11_graphics-cpp,代码行数:17,代码来源:GraphicsMgr.cpp

示例4: make_prog

	static Program make_prog(void)
	{
		VertexShader vs;
		vs.Source(
			"#version 330\n"
			"in vec4 Position;"
			"in vec3 Normal;"
			"out vec3 vertColor;"
			"out vec3 vertNormal;"
			"out vec3 vertLight;"
			"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
			"uniform vec3 LightPos;"
			"void main(void)"
			"{"
			"	gl_Position = ModelMatrix * Position;"
			"	vertColor = abs(normalize(Normal+vec3(1, 1, 1)));"
			"	vertNormal = mat3(ModelMatrix)*Normal;"
			"	vertLight = LightPos - gl_Position.xyz;"
			"	gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
			"}"
		);
		vs.Compile();

		FragmentShader fs;
		fs.Source(
			"#version 330\n"
			"in vec3 vertColor;"
			"in vec3 vertNormal;"
			"in vec3 vertLight;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	float l = dot(vertLight, vertLight);"
			"	float d = l > 0.0 ? dot(vertNormal, normalize(vertLight)) / l : 0.0;"
			"	float i = 0.2 + max(d*3.2, 0.0);"
			"	fragColor = vec4(vertColor*i, 1.0);"
			"}"
		);
		fs.Compile();

		Program prog;
		prog.AttachShader(vs);
		prog.AttachShader(fs);
		prog.Link();

		return prog;
	}
开发者ID:Extrunder,项目名称:oglplus,代码行数:47,代码来源:023_reflected_cube.cpp

示例5: CreateGPUProgram

//-----------------------------------------------------------------------------------------------------------------------------------------------------
Ptr<GPUProgram> Context::CreateGPUProgram( LPCTSTR VertexShaderSource, LPCTSTR FragmentShaderSource )
{
	VertexShader* pVertexShader = 0;
	FragmentShader* pFragmentShader = 0;

	if (VertexShaderSource)
	{
		pVertexShader = new VertexShader(this);
		pVertexShader->Compile(VertexShaderSource);
	}

	if (FragmentShaderSource)
	{
		pFragmentShader = new FragmentShader(this);
		pFragmentShader->Compile(FragmentShaderSource);
	}

	return CreateGPUProgram( pVertexShader, pFragmentShader );
}
开发者ID:anareboucas,项目名称:nanook,代码行数:20,代码来源:Context.cpp

示例6: Load

bool ShaderLoader::Load(ShaderResource** resource, Handle handle, const std::string& filename1, const std::string& filename2)
{
	*resource = new ShaderResource(handle, filename1);
	Program* shader = new Program();
	(*resource)->mRaw = shader;

	VertexShader vs;
	vs.Source(readFile(filename1));
	vs.Compile();

	FragmentShader fs;
	fs.Source(readFile(filename2));
	fs.Compile();

	shader->AttachShader(vs).AttachShader(fs);
	shader->BindAttribute(VertexAttributes::POSITION, "in_Position");
	shader->BindAttribute(VertexAttributes::NORMAL, "in_Normal");
	shader->BindAttribute(VertexAttributes::TANGENT, "in_Tangent");
	shader->BindAttribute(VertexAttributes::TEXCOORD, "in_TexCoords");
	shader->Link();

	return true;
}
开发者ID:shadept,项目名称:AVT,代码行数:23,代码来源:Shader.cpp

示例7: defS

	Program * ProgramFromShaderMap(const map<string, string> &mapShdString, const string &root) {
		VertexShader vs;
		FragmentShader fs;
		Program *prog = new Program();

		string defS("#version 420\n");
		defS.append("#define MAX_BONES ");      defS.append(ConvertIntString(G_MAX_BONES_UNIFORM));     defS.append("\n");
		defS.append("#define MAX_BONES_INFL "); defS.append(ConvertIntString(G_MAX_BONES_INFLUENCING)); defS.append("\n");

		string vsSrc(defS);
		vsSrc.append(mapShdString.at(string("vs").append(root)));
		string fsSrc(defS);
		fsSrc.append(mapShdString.at(string("fs").append(root)));

		vs.Source(vsSrc);
		fs.Source(fsSrc);
		vs.Compile();
		fs.Compile();
		prog->AttachShader(vs);
		prog->AttachShader(fs);
		prog->Link();

		return prog;
	}
开发者ID:nOOb3167,项目名称:BlendUtil,代码行数:24,代码来源:Main.cpp

示例8: lightPos

	GlassExample(void)
	 : make_plane(Vec3f(2.0f, 0.0f, 0.0f), Vec3f(0.0f, 0.0f, -2.0f))
	 , plane_instr(make_plane.Instructions())
	 , plane_indices(make_plane.Indices())
	 , make_shape()
	 , shape_instr(make_shape.Instructions())
	 , shape_indices(make_shape.Indices())
	 , plane_vs(ObjectDesc("Plane vertex"))
	 , shape_vs(ObjectDesc("Shape vertex"))
	 , plane_fs(ObjectDesc("Plane fragment"))
	 , shape_fs(ObjectDesc("Shape fragment"))
	 , plane_proj_matrix(plane_prog)
	 , plane_camera_matrix(plane_prog)
	 , plane_model_matrix(plane_prog)
	 , shape_proj_matrix(shape_prog)
	 , shape_camera_matrix(shape_prog)
	 , shape_model_matrix(shape_prog)
	 , shape_clip_plane(shape_prog)
	 , shape_clip_direction(shape_prog)
	 , width(512)
	 , height(512)
	 , tex_side(512)
	{
		plane_vs.Source(
			"#version 140\n"
			"uniform vec3 LightPosition;"
			"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
			"in vec4 Position;"
			"in vec2 TexCoord;"
			"out vec3 vertLightDir;"
			"out vec2 vertTexCoord;"
			"void main(void)"
			"{"
			"	gl_Position = "
			"		ModelMatrix* "
			"		Position;"
			"	vertLightDir = normalize("
			"		LightPosition - gl_Position.xyz"
			"	);"
			"	gl_Position = "
			"		ProjectionMatrix *"
			"		CameraMatrix *"
			"		gl_Position;"
			"	vertTexCoord = TexCoord;"
			"}"
		);
		plane_vs.Compile();

		plane_fs.Source(
			"#version 140\n"
			"uniform vec3 Normal;"
			"in vec3 vertLightDir;"
			"in vec2 vertTexCoord;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	float checker = ("
			"		int(vertTexCoord.x*18) % 2+"
			"		int(vertTexCoord.y*18) % 2"
			"	) % 2;"
			"	vec3 color = mix("
			"		vec3(0.2, 0.4, 0.9),"
			"		vec3(0.2, 0.2, 0.7),"
			"		checker"
			"	);"
			"	float d = dot("
			"		Normal, "
			"		vertLightDir"
			"	);"
			"	float intensity = 0.5 + pow(1.4*d, 2.0);"
			"	fragColor = vec4(color*intensity, 1.0);"
			"}"
		);
		plane_fs.Compile();

		plane_prog.AttachShader(plane_vs);
		plane_prog.AttachShader(plane_fs);
		plane_prog.Link();
		plane_prog.Use();
		plane_proj_matrix.BindTo("ProjectionMatrix");
		plane_camera_matrix.BindTo("CameraMatrix");
		plane_model_matrix.BindTo("ModelMatrix");

		Vec3f lightPos(3.0f, 3.0f, 3.0f);
		Uniform<Vec3f>(plane_prog, "LightPosition").Set(lightPos);
		Uniform<Vec3f>(plane_prog, "Normal").Set(make_plane.Normal());

		gl.Bind(plane);

		gl.Bind(Buffer::Target::Array, plane_verts);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_plane.Positions(data);
			Buffer::Data(Buffer::Target::Array, data);
			VertexArrayAttrib attr(plane_prog, "Position");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		gl.Bind(Buffer::Target::Array, plane_texcoords);
//.........这里部分代码省略.........
开发者ID:AdamSimpson,项目名称:oglplus,代码行数:101,代码来源:028_glass_shape.cpp

示例9: attr

	LandscapeExample(void)
	 : grid_side(128)
	 , make_plane(
		Vec3f(0.0f, 0.0f, 0.0f),
		Vec3f(9.0f, 0.0f, 0.0f),
		Vec3f(0.0f, 0.0f,-9.0f),
		grid_side*3, grid_side*3
	), plane_instr(make_plane.Instructions())
	 , plane_indices(make_plane.Indices())
	 , light_pos(prog, "LightPos")
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	 , light_path(
		ListOf<Vec3f>
			(Vec3f(-3.0f,  2.0f, -3.5f))
			(Vec3f( 0.0f,  5.0f,  0.5f))
			(Vec3f( 3.0f,  3.0f,  3.0f))
			(Vec3f( 3.0f,  3.0f, -3.0f))
			(Vec3f( 0.0f,  5.0f,  0.5f))
			(Vec3f(-3.2f,  2.0f,  3.0f))
		.Get()
	)
	{
		VertexShader vs;
		vs.Source(
			"#version 330\n"
			"uniform mat4 ProjectionMatrix, CameraMatrix;"
			"uniform sampler2D TexUnit;"
			"in vec4 Position;"
			"in vec2 TexCoord;"
			"out vec3 vertLight;"
			"out vec3 vertNormal;"
			"uniform vec3 LightPos;"
			"void main(void)"
			"{"
			"	gl_Position = Position;"
			"	float o = 0.0;"
			"	float s[9];"
			"	int k=0;"
			"	for(int y=-1; y!=2; ++y)"
			"	for(int x=-1; x!=2; ++x)"
			"	{"
			"		s[k] = sqrt(texture("
			"			TexUnit, "
			"			TexCoord*3.0+"
			"			vec2(x, y)/128.0"
			"		).r);"
			"		o += s[k++];"
			"	}"
			"	gl_Position.y += o*0.5;"
			"	vec3 c = vec3( 0.0, s[4], 0.0);"
			"	float d = 1.0/32.0;"
			"	vertNormal = normalize("
			"		cross("
			"			vec3( 0.0, s[1],  -d) - c,"
			"			vec3(  -d, s[3], 0.0) - c"
			"		)+"
			"		cross("
			"			vec3(   d, s[5], 0.0) - c,"
			"			vec3( 0.0, s[1],  -d) - c"
			"		)+"
			"		cross("
			"			vec3( 0.0, s[7],   d) - c,"
			"			vec3(   d, s[5], 0.0) - c"
			"		)+"
			"		cross("
			"			vec3(  -d, s[3], 0.0) - c,"
			"			vec3( 0.0, s[7],   d) - c"
			"		)"
			"	);"
			"	vertLight = LightPos - gl_Position.xyz;"
			"	gl_Position = "
			"		ProjectionMatrix *"
			"		CameraMatrix *"
			"		gl_Position;"
			"}"
		);
		vs.Compile();

		FragmentShader fs;
		fs.Source(
			"#version 330\n"
			"in vec3 vertNormal;"
			"in vec3 vertLight;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	float l = length(vertLight);"
			"	float d = l > 0? dot("
			"		normalize(vertNormal), "
			"		normalize(vertLight)"
			"	) / l : 0.0;"
			"	float i = 0.1 + 1.2*max(d, 0.0) + 4.2*pow(d, 2.0);"
			"	fragColor = vec4(i*0.7, i*0.7, i*0.3, 1.0);"
			"}"
		);
		fs.Compile();

		// attach the shaders to the program
		prog.AttachShader(vs);
//.........这里部分代码省略.........
开发者ID:James-Z,项目名称:oglplus,代码行数:101,代码来源:018_newton_landscape.cpp

示例10: 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;"
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例11: 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();
//.........这里部分代码省略.........
开发者ID:GLDRorg,项目名称:oglplus,代码行数:101,代码来源:018_atomic_counters.cpp

示例12: 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);"
//.........这里部分代码省略.........
开发者ID:BrainlessLabsInc,项目名称:oglplus,代码行数:101,代码来源:019_tessellation.cpp

示例13: lightPos

    ReflectionExample()
      : make_plane(
          Vec3f(), Vec3f(3.0f, 0.0f, 0.0f), Vec3f(0.0f, 0.0f, -3.0f), 15, 15)
      , plane_instr(make_plane.Instructions())
      , plane_indices(make_plane.Indices())
      , make_shape()
      , shape_instr(make_shape.Instructions())
      , shape_indices(make_shape.Indices())
      , plane_vs(ObjectDesc("Plane vertex"))
      , shape_vs(ObjectDesc("Shape vertex"))
      , plane_fs(ObjectDesc("Plane fragment"))
      , shape_fs(ObjectDesc("Shape fragment"))
      , plane_projection_matrix(plane_prog)
      , plane_camera_matrix(plane_prog)
      , plane_model_matrix(plane_prog)
      , shape_projection_matrix(shape_prog)
      , shape_camera_matrix(shape_prog)
      , shape_model_matrix(shape_prog)
      , width(800)
      , height(600)
      , tex_size_div(2) {
        plane_vs.Source(
          "#version 140\n"
          "uniform vec3 LightPosition;"
          "uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
          "in vec4 Position;"
          "out vec3 vertLightDir;"
          "out vec4 vertTexCoord;"
          "void main()"
          "{"
          "	gl_Position = ModelMatrix*Position;"
          "	vertLightDir = LightPosition - gl_Position.xyz;"
          "	gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
          "	vertTexCoord = gl_Position;"
          "}");
        plane_vs.Compile();

        plane_fs.Source(
          "#version 140\n"
          "uniform sampler2DRect ReflectTex;"
          "uniform vec3 Normal;"
          "in vec3 vertLightDir;"
          "in vec4 vertTexCoord;"
          "out vec3 fragColor;"
          "const int n = 5;"
          "const int ns = (n*n);"
          "const float blur = 0.15/n;"
          "void main()"
          "{"
          "	float d = dot(Normal, normalize(vertLightDir));"
          "	float intensity = 0.5 + pow(1.4*d, 2.0);"
          "	vec3 color = vec3(0.0, 0.0, 0.0);"
          "	int n = 2;"
          "	float pct = 0.5/vertTexCoord.w;"
          "	for(int y=-n; y!=(n+1); ++y)"
          "	for(int x=-n; x!=(n+1); ++x)"
          "	{"
          "		vec2 coord = vertTexCoord.xy;"
          "		coord += vec2(blur*x, blur*y);"
          "		coord *= pct;"
          "		coord += vec2(0.5, 0.5);"
          "		coord *= textureSize(ReflectTex);"
          "		color += texture(ReflectTex, coord).rgb/ns;"
          "	}"
          "	fragColor = color*intensity;"
          "}");
        plane_fs.Compile();

        plane_prog.AttachShader(plane_vs);
        plane_prog.AttachShader(plane_fs);
        plane_prog.Link();
        plane_prog.Use();

        plane_projection_matrix.BindTo("ProjectionMatrix");
        plane_camera_matrix.BindTo("CameraMatrix");
        plane_model_matrix.BindTo("ModelMatrix");

        Vec3f lightPos(3.0f, 0.5f, 2.0f);
        Uniform<Vec3f>(plane_prog, "LightPosition").Set(lightPos);
        Uniform<Vec3f>(plane_prog, "Normal").Set(make_plane.Normal());

        plane.Bind();

        plane_verts.Bind(Buffer::Target::Array);
        {
            std::vector<GLfloat> data;
            GLuint n_per_vertex = make_plane.Positions(data);
            Buffer::Data(Buffer::Target::Array, data);
            VertexArrayAttrib attr(plane_prog, "Position");
            attr.Setup<GLfloat>(n_per_vertex);
            attr.Enable();
        }
        //
        Texture::Active(1);
        gl.Bound(Texture::Target::Rectangle, depth_tex)
          .MinFilter(TextureMinFilter::Linear)
          .MagFilter(TextureMagFilter::Linear)
          .WrapS(TextureWrap::ClampToEdge)
          .WrapT(TextureWrap::ClampToEdge);

//.........这里部分代码省略.........
开发者ID:matus-chochlik,项目名称:oglplus,代码行数:101,代码来源:027_reflected_shape.cpp

示例14: vert_attr

	MetaballExample(void)
	{
		for(GLuint i=0; i!=64; ++i)
		{
			GLuint j = 0, n = 3+std::rand()%3;
			std::vector<Vec4f> points(n);
			while(j != n)
			{
				points[j] = Vec4f(
					1.4*std::rand()/GLdouble(RAND_MAX) - 0.7,
					1.4*std::rand()/GLdouble(RAND_MAX) - 0.7,
					0.0,
					0.1*std::rand()/GLdouble(RAND_MAX) + 0.1
				);
				++j;
			}
			ball_paths.push_back(CubicBezierLoop<Vec4f, double>(points));
			++i;
		}

		// Set the vertex shader source
		vs.Source(StrLit(
			"#version 330\n"
			"in vec2 Position;"
			"out vec3 vertPosition;"
			"void main(void)"
			"{"
			"	vertPosition = vec3(Position, 0.0);"
			"	gl_Position = vec4(vertPosition, 1.0);"
			"}"
		));
		// compile it
		vs.Compile();

		// set the fragment shader source
		fs.Source(StrLit(
			"#version 330\n"
			"uniform sampler1D Metaballs;"
			"in vec3 vertPosition;"
			"out vec3 fragColor;"

			"const vec3 AmbientColor = vec3(0.3, 0.4, 0.9);"
			"const vec3 DiffuseColor = vec3(0.5, 0.6, 1.0);"
			"const vec3 LightDir = normalize(vec3(1.0, 1.0, 1.0));"

			"void main(void)"
			"{"
			"	int i = 0, n = textureSize(Metaballs, 0);"

			"	float InvN = 1.0/n;"
			"	float Value = 0.0;"
			"	vec3 Normal = vec3(0.0, 0.0, 0.0);"
			"	while(i != n)"
			"	{"
			"		vec4 Metaball = texelFetch(Metaballs, i, 0);"
			"		float Radius = Metaball.w;"
			"		vec3 Vect = vertPosition - Metaball.xyz;"
			"		float Tmp = pow(Radius,2.0)/dot(Vect, Vect)-0.25;"
			"		Value += Tmp;"
			"		float Mul = max(Tmp, 0.0);"
			"		Normal += Mul*vec3(Vect.xy, Mul*InvN/Radius);"
			"		++i;"
			"	}"
			"	if(Value > 0.0)"
			"	{"
			"		float Diffuse = 1.4*max(dot("
			"			LightDir,"
			"			normalize(Normal)"
			"		), 0.0);"
			"		float Ambient = 0.3;"
			"		fragColor = "
			"			Ambient*AmbientColor+"
			"			Diffuse*DiffuseColor;"
			"	}"
			"	else fragColor = vec3(0.4, 0.4, 0.4);"
			"}"
		));
		// compile it
		fs.Compile();

		// attach the shaders to the program
		prog << vs << fs;
		// link and use it
		prog.Link().Use();

		// bind the VAO for the rectangle
		rectangle.Bind();

		GLfloat rectangle_verts[8] = {
			-1.0f, -1.0f,
			-1.0f,  1.0f,
			 1.0f, -1.0f,
			 1.0f,  1.0f
		};
		// bind the VBO for the rectangle vertices
		verts.Bind(Buffer::Target::Array);
		// upload the data
		Buffer::Data(Buffer::Target::Array, rectangle_verts);
		// setup the vertex attribs array for the vertices
		VertexAttribArray vert_attr(prog, "Position");
//.........这里部分代码省略.........
开发者ID:xdray,项目名称:oglplus,代码行数:101,代码来源:009_metaballs.cpp

示例15: attr

	FBTexExample(void)
	 : make_cube()
	 , cube_instr(make_cube.Instructions())
	 , cube_indices(make_cube.Indices())
	 , make_torus(1.0, 0.5, 72, 48)
	 , torus_instr(make_torus.Instructions())
	 , torus_indices(make_torus.Indices())
	 , cube_fs(ObjectDesc("Cube fragment"))
	 , torus_fs(ObjectDesc("Torus fragment"))
	 , torus_projection_matrix(torus_prog, "ProjectionMatrix")
	 , torus_camera_matrix(torus_prog, "CameraMatrix")
	 , torus_model_matrix(torus_prog, "ModelMatrix")
	 , cube_projection_matrix(cube_prog, "ProjectionMatrix")
	 , cube_camera_matrix(cube_prog, "CameraMatrix")
	 , cube_model_matrix(cube_prog, "ModelMatrix")
	 , tex_side(512)
	 , width(tex_side)
	 , height(tex_side)
	{
		vs.Source(
			"#version 330\n"
			"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
			"in vec4 Position;"
			"in vec3 Normal;"
			"in vec2 TexCoord;"
			"out vec3 vertNormal;"
			"out vec3 vertLight;"
			"out vec2 vertTexCoord;"
			"uniform vec3 LightPos;"
			"void main(void)"
			"{"
			"	vertNormal = mat3(ModelMatrix)*Normal;"
			"	gl_Position = ModelMatrix * Position;"
			"	vertLight = LightPos-gl_Position.xyz;"
			"	vertTexCoord = TexCoord;"
			"	gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
			"}"
		);
		vs.Compile();

		cube_fs.Source(
			"#version 330\n"
			"uniform sampler2D TexUnit;"
			"in vec3 vertNormal;"
			"in vec3 vertLight;"
			"in vec2 vertTexCoord;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	float l = sqrt(length(vertLight));"
			"	float d = l > 0? dot(vertNormal, normalize(vertLight)) / l : 0.0;"
			"	float i = 0.6 + max(d, 0.0);"
			"	fragColor = texture(TexUnit, vertTexCoord)*i;"
			"}"
		);
		cube_fs.Compile();

		cube_prog.AttachShader(vs);
		cube_prog.AttachShader(cube_fs);
		cube_prog.Link();
		cube_prog.Use();

		cube.Bind();

		cube_verts.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.Positions(data);
			Buffer::Data(Buffer::Target::Array, data);
			VertexAttribArray attr(cube_prog, "Position");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		cube_normals.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.Normals(data);
			Buffer::Data(Buffer::Target::Array, data);
			VertexAttribArray attr(cube_prog, "Normal");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		cube_texcoords.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.TexCoordinates(data);
			Buffer::Data(Buffer::Target::Array, data);
			VertexAttribArray attr(cube_prog, "TexCoord");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		UniformSampler(cube_prog, "TexUnit").Set(0);
		Uniform<Vec3f>(cube_prog, "LightPos").Set(4.0f, 4.0f, -8.0f);

		torus_fs.Source(
			"#version 330\n"
			"in vec3 vertNormal;"
//.........这里部分代码省略.........
开发者ID:GLDRorg,项目名称:oglplus,代码行数:101,代码来源:025_rendered_texture.cpp


注:本文中的VertexShader::Compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。