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


C++ FragmentShader::Source方法代码示例

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


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

示例1: make_prog

	static Program make_prog(void)
	{
		Program prog;

		VertexShader vs;
		vs.Source(
			"#version 330\n"
			"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
			"mat4 Matrix = ProjectionMatrix*CameraMatrix*ModelMatrix;"
			"in vec4 Position;"

			"void main(void)"
			"{"
			"	gl_Position = Matrix*Position;"
			"}"
		);

		FragmentShader fs;
		fs.Source(
			"#version 330\n"
			"void main(void){ }"
		);

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

		return std::move(prog);
	}
开发者ID:Extrunder,项目名称:oglplus,代码行数:28,代码来源:030_pin_display.cpp

示例2: make_fs

	// makes a fragment shader from the prologe, custom part and epilogue
	static FragmentShader make_fs(StrCRef color_fs)
	{
		FragmentShader shader;
		StrCRef source[3] = {fs_prologue(), color_fs, fs_epilogue()};
		shader.Source(source);
		shader.Compile();
		return shader;
	}
开发者ID:xubingyue,项目名称:oglplus,代码行数:9,代码来源:019_helium.cpp

示例3: 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

示例4: main

	static oglplus::Program make_prog(void)
	{
		using namespace oglplus;

		Program prog;

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

		FragmentShader fs;
		fs.Source(
			"#version 140\n"
			"uniform sampler2D Checker;"
			"in vec3 vertNormal;"
			"in vec3 vertLight;"
			"in vec2 vertTexCoord;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	float d = dot(vertNormal, normalize(vertLight));"
			"	float i = 0.4 + 1.4*max(d, 0.0);"
			"	vec4 t  = texture(Checker, vertTexCoord);"
			"	fragColor = vec4(t.rrr*i, 1.0);"
			"}"
		).Compile();

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

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

示例5: 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

示例6: make_face_prog

	static Program make_face_prog(void)
	{
		FragmentShader fs;
		fs.Source(
			"#version 330\n"
			"in vec3 geomNormal;"
			"in vec3 geomLight;"
			"in float geomGlow;"
			"flat in int geomTop;"
			"uniform vec3 TopColor, SideColor;"
			"const vec3 LightColor = vec3(1.0, 1.0, 1.0);"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	float d = max(dot("
			"		normalize(geomLight),"
			"		normalize(geomNormal)"
			"	), 0.0);"
			"	vec3 color;"
			"	if(geomTop != 0)"
			"	{"
			"		color = TopColor * d +"
			"			LightColor * pow(d, 8.0);"
			"	}"
			"	else"
			"	{"
			"		color = SideColor * geomGlow +"
			"			LightColor *"
			"			pow(d, 2.0) * 0.2;"
			"	}"
			"	fragColor = vec4(color, 1.0);"
			"}"
		);
		fs.Compile();

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

		ProgramUniform<Vec3f>(prog, "TopColor").Set(0.2f, 0.2f, 0.2f);
		ProgramUniform<Vec3f>(prog, "SideColor").Set(0.9f, 0.9f, 0.2f);

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

示例7: make_frame_prog

	static Program make_frame_prog(void)
	{
		FragmentShader fs;
		fs.Source(
			"#version 330\n"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	fragColor = vec4(0.2, 0.1, 0.0, 1.0);"
			"}"
		);
		fs.Compile();

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

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

示例8: make

	static Program make(void)
	{
		Program result;

		VertexShader vs;
		vs.Source(
			"#version 330\n"
			"#define side 128\n"

			"uniform mat4 ProjectionMatrix, CameraMatrix;"
			"uniform float Fade;"
			"uniform sampler2D Offsets;"
			"uniform sampler2D Heights;"

			"in vec4 Position;"

			"void main(void)"
			"{"
			"	ivec2 Coord = ivec2(gl_InstanceID%side, gl_InstanceID/side);"
			"	vec2 Offs = texelFetch(Offsets, Coord, 0).xy;"
			"	float Height = 1.0-texelFetch(Heights, Coord, 0).r;"
			"	gl_Position = Position;"
			"	gl_Position.xz += Offs;"
			"	gl_Position.y  *= max(Height*Fade*side/2, 0.5);"
			"	gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
			"}"
		).Compile();

		FragmentShader fs;
		fs.Source(
			"#version 330\n"
			"void main(void) { }"
		).Compile();

		result.AttachShader(vs).AttachShader(fs);
		result.Link().Validate().Use();
		return std::move(result);
	}
开发者ID:Extrunder,项目名称:oglplus,代码行数:38,代码来源:030_pin_display.cpp

示例9: 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

示例10: 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

示例11: attr

	TorusExample(void)
	 : make_torus(1.0, 0.5, 72, 48)
	 , torus_instr(make_torus.Instructions())
	 , torus_indices(make_torus.Indices())
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	 , model_matrix(prog, "ModelMatrix")
	{
		// Set the vertex shader source and compile it
		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)"
			"{"
			"	gl_Position = ModelMatrix * Position;"
			"	vertNormal = mat3(ModelMatrix)*Normal;"
			"	vertLight = LightPos - gl_Position.xyz;"
			"	vertTexCoord = TexCoord;"
			"	gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
			"}"
		).Compile();

		// set the fragment shader source and compile it
		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.2 + 3.2*max(d, 0.0);"
			"	fragColor = texture(TexUnit, vertTexCoord)*i;"
			"}"
		).Compile();

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

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

		// bind the VBO for the torus vertices
		verts.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_torus.Positions(data);
			// upload the data
			Buffer::Data(Buffer::Target::Array, data);
			// setup the vertex attribs array for the vertices
			VertexAttribArray attr(prog, "Position");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		// bind the VBO for the torus normals
		normals.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_torus.Normals(data);
			// upload the data
			Buffer::Data(Buffer::Target::Array, data);
			// setup the vertex attribs array for the vertices
			VertexAttribArray attr(prog, "Normal");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		// bind the VBO for the torus texture coordinates
		texcoords.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_torus.TexCoordinates(data);
			// upload the data
			Buffer::Data(Buffer::Target::Array, data);
			// setup the vertex attribs array for the vertices
			VertexAttribArray attr(prog, "TexCoord");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		// setup the texture
		Texture::Target tex_tgt = Texture::Target::_2D;
		tex.Bind(tex_tgt);
		{
//.........这里部分代码省略.........
开发者ID:BrainlessLabsInc,项目名称:oglplus,代码行数:101,代码来源:016_noise_torus.cpp

示例12: 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);
	}
开发者ID:AdamSimpson,项目名称:oglplus,代码行数:88,代码来源:026_ssao.cpp

示例13: 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

示例14: attr

	TorusExample(void)
	 : make_torus(1.0, 0.5, 72, 48)
	 , torus_instr(make_torus.Instructions())
	 , torus_indices(make_torus.Indices())
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	 , model_matrix(prog, "ModelMatrix")
	{
		// Set the vertex shader source and compile it
		vs.Source(
			"#version 330\n"
			"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
			"in vec4 Position;"
			"in vec3 Normal;"
			"out vec3 vertNormal;"
			"void main(void)"
			"{"
			"	vertNormal = mat3(CameraMatrix)*mat3(ModelMatrix)*Normal;"
			"	gl_Position = "
			"		ProjectionMatrix *"
			"		CameraMatrix *"
			"		ModelMatrix *"
			"		Position;"
			"}"
		).Compile();

		// set the fragment shader source and compile it
		fs.Source(
			"#version 330\n"
			"uniform int ColorCount;"
			"uniform vec4 Color[8];"
			"in vec3 vertNormal;"
			"vec3 ViewDir = vec3(0.0, 0.0, 1.0);"
			"vec3 TopDir = vec3(0.0, 1.0, 0.0);"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	float k = dot(vertNormal, ViewDir);"
			"	vec3 reflDir = 2.0*k*vertNormal - ViewDir;"
			"	float a = dot(reflDir, TopDir);"
			"	vec3 reflColor;"
			"	for(int i = 0; i != (ColorCount - 1); ++i)"
			"	{"
			"		if(a<Color[i].a && a>=Color[i+1].a)"
			"		{"
			"			float m = "
			"				(a - Color[i].a)/"
			"				(Color[i+1].a-Color[i].a);"
			"			reflColor = mix("
			"				Color[i].rgb,"
			"				Color[i+1].rgb,"
			"				m"
			"			);"
			"			break;"
			"		}"
			"	}"
			"	float i = max(dot(vertNormal, TopDir), 0.0);"
			"	vec3 diffColor = vec3(i, i, i);"
			"	fragColor = vec4("
			"		mix(reflColor, diffColor, 0.3 + i*0.7),"
			"		1.0"
			"	);"
			"}"
		).Compile();

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

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

		// bind the VBO for the torus vertices
		verts.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_torus.Positions(data);
			// upload the data
			Buffer::Data(Buffer::Target::Array, data);
			// setup the vertex attribs array for the vertices
			VertexAttribArray attr(prog, "Position");
			attr.Setup(n_per_vertex, DataType::Float).Enable();
		}

		// bind the VBO for the torus normals
		normals.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_torus.Normals(data);
			// upload the data
			Buffer::Data(Buffer::Target::Array, data);
			// setup the vertex attribs array for the vertices
			VertexAttribArray attr(prog, "Normal");
			attr.Setup(n_per_vertex, DataType::Float).Enable();
		}

		// setup the color gradient
		Uniform<GLint>(prog, "ColorCount").Set(8);
//.........这里部分代码省略.........
开发者ID:xdray,项目名称:oglplus,代码行数:101,代码来源:016_metallic_torus.cpp

示例15: attr

	HaloExample(void)
	 : make_shape()
	 , shape_indices(make_shape.Indices())
	 , shape_instr(make_shape.Instructions())
	 , vs_shape(ObjectDesc("Shape VS"))
	 , vs_plane(ObjectDesc("Plane VS"))
	 , fs_shape(ObjectDesc("Shape FS"))
	 , fs_plane(ObjectDesc("Plane FS"))
	 , vs_halo(ObjectDesc("Halo VS"))
	 , gs_halo(ObjectDesc("Halo GS"))
	 , fs_halo(ObjectDesc("Halo FS"))
	 , shape_projection_matrix(shape_prog, "ProjectionMatrix")
	 , shape_camera_matrix(shape_prog, "CameraMatrix")
	 , shape_model_matrix(shape_prog, "ModelMatrix")
	 , plane_projection_matrix(plane_prog, "ProjectionMatrix")
	 , plane_camera_matrix(plane_prog, "CameraMatrix")
	 , halo_projection_matrix(halo_prog, "ProjectionMatrix")
	 , halo_camera_matrix(halo_prog, "CameraMatrix")
	 , halo_model_matrix(halo_prog, "ModelMatrix")
	{
		vs_shape.Source(
			"#version 140\n"
			"in vec4 Position;"
			"in vec3 Normal;"
			"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
			"uniform vec3 LightPos;"
			"out vec3 vertNormal;"
			"out vec3 vertViewNormal;"
			"out vec3 vertLight;"
			"void main(void)"
			"{"
			"	gl_Position = ModelMatrix * Position;"
			"	vertNormal = mat3(ModelMatrix)*Normal;"
			"	vertViewNormal = mat3(CameraMatrix)*vertNormal;"
			"	vertLight = LightPos - gl_Position.xyz;"
			"	gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
			"}"
		);
		vs_shape.Compile();

		fs_shape.Source(
			"#version 140\n"
			"in vec3 vertNormal;"
			"in vec3 vertViewNormal;"
			"in vec3 vertLight;"
			"uniform mat4 CameraMatrix;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	float ltlen = sqrt(length(vertLight));"
			"	float ltexp = dot("
			"		normalize(vertNormal),"
			"		normalize(vertLight)"
			"	);"
			"	float lview = dot("
			"		normalize(vertLight),"
			"		normalize(vec3("
			"			CameraMatrix[0][2],"
			"			CameraMatrix[1][2],"
			"			CameraMatrix[2][2] "
			"		))"
			"	);"
			"	float depth = normalize(vertViewNormal).z;"
			"	vec3 ftrefl = vec3(0.9, 0.8, 0.7);"
			"	vec3 scatter = vec3(0.9, 0.6, 0.1);"
			"	vec3 bklt = vec3(0.8, 0.6, 0.4);"
			"	vec3 ambient = vec3(0.5, 0.4, 0.3);"
			"	fragColor = vec4("
			"		pow(max(ltexp, 0.0), 8.0)*ftrefl+"
			"		( ltexp+1.0)/ltlen*pow(depth,2.0)*scatter+"
			"		(-ltexp+1.0)/ltlen*(1.0-depth)*scatter+"
			"		(-lview+1.0)*0.6*(1.0-abs(depth))*bklt+"
			"		0.2*ambient,"
			"		1.0"
			"	);"
			"}"
		);
		fs_shape.Compile();

		shape_prog.AttachShader(vs_shape);
		shape_prog.AttachShader(fs_shape);
		shape_prog.Link();

		vs_plane.Source(
			"#version 140\n"
			"in vec4 Position;"
			"in vec3 Normal;"
			"uniform mat4 ProjectionMatrix, CameraMatrix;"
			"uniform vec3 LightPos;"
			"out vec3 vertNormal;"
			"out vec3 vertLight;"
			"void main(void)"
			"{"
			"	gl_Position = "
			"		ProjectionMatrix *"
			"		CameraMatrix *"
			"		Position;"
			"	vertNormal = Normal;"
			"	vertLight = LightPos-Position.xyz;"
			"}"
//.........这里部分代码省略.........
开发者ID:AdamSimpson,项目名称:oglplus,代码行数:101,代码来源:026_shape_halo.cpp


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