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


C++ FragmentShader类代码示例

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


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

示例1:

   void ShaderManager<RS>::init()
      {
      //construct safe default shader
      VertexShader<RS>* dv = 0;
      FragmentShader<RS>* df = 0;

      dv = new VertexShader<RS>();
      df = new FragmentShader<RS>();

      Vertex def;
      def.addVector3("POSITION");
      def.finalize();

      dv->associateVertex(def);

      if(RS == RS_DX11)
         {
         dv->initFromDef(Defaults::shaderDefDX, Defaults::vertexFunc);
         df->initFromDef(Defaults::shaderDefDX, Defaults::fragmentFunc);
         }
      else
         {
         dv->initFromDef(Defaults::shaderDefGL, Defaults::vertexFunc);
         df->initFromDef(Defaults::shaderDefGL, Defaults::fragmentFunc);
         }

      vShaders[Defaults::mapName][Defaults::mapName] = dv;
      fShaders[Defaults::mapName][Defaults::mapName] = df;
      }
开发者ID:radneyalquiza,项目名称:GAM531_Emperor,代码行数:29,代码来源:ShaderManager.cpp

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

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

示例4: _name

ShaderProgram::ShaderProgram(
	const string &filename,
	const VertexShader &vertexShader,
	const FragmentShader &fragmentShader) : _name(filename), _handle(0), _linked(0)
{
	try
	{
		if (vertexShader.fail()) throw std::runtime_error("Invalid vertex shader");
		if (fragmentShader.fail()) throw std::runtime_error("Invalid fragment shader");

		if (GLEW_VERSION_2_0)
		{
			// Create program and attach vertex and fragment shaders
			_handle = glCreateProgram();
			glAttachShader(_handle, vertexShader.handle());
			glAttachShader(_handle, fragmentShader.handle());

			// Perform link stage
			glLinkProgram(_handle);
			glGetProgramiv(_handle, GL_LINK_STATUS, &_linked);

			// Validate program
			glValidateProgram(_handle);
			printInfoLog();

			// Check for success
			if (GL_FALSE == _linked)
				throw std::runtime_error("Link stage failed");
		}
		else if (GLEW_VERSION_1_5)
		{
			// Create program and attach vertex and fragment shaders
			_handle = glCreateProgramObjectARB();
			glAttachObjectARB(_handle, vertexShader.handle());
			glAttachObjectARB(_handle, fragmentShader.handle());

			// Perform link stage
			glLinkProgramARB(_handle);
			glGetObjectParameterivARB(_handle, GL_OBJECT_LINK_STATUS_ARB, &_linked);

			// Validate program
			glValidateProgramARB(_handle);
			printInfoLog();

			// Check for success
			if (GL_FALSE == _linked)
				throw std::runtime_error("Link stage failed");
		}

		cout << "* Shader \"" << _name << "\" successfully linked" << endl;
	}
	catch (std::runtime_error &err)
	{
		cerr << "Error: Faild to create shader " << _name << endl;
		cerr << "Reason: " << err.what() << endl;
	}
}
开发者ID:odalet,项目名称:qshaderedit,代码行数:57,代码来源:Shader.cpp

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

示例6: CreateFragmentShader

/**
*  @brief
*    Creates a fragment shader and sets the shader source code
*/
FragmentShader *ShaderLanguage::CreateFragmentShader(const String &sSourceCode, const String &sProfile, const String &sArguments, const String &sEntry)
{
	// Create the fragment shader instance
	FragmentShader *pFragmentShader = CreateFragmentShader();

	// Set the fragment shader source code
	if (pFragmentShader)
		pFragmentShader->SetSourceCode(sSourceCode, sProfile, sArguments, sEntry);

	// Return the created fragment shader instance
	return pFragmentShader;
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:16,代码来源:ShaderLanguage.cpp

示例7: FilePath

HRESULT DX9ShaderIncludeLoader::Open( D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes )
{
   ResourcesManager& resMgr = ResourcesManager::getInstance();
   FragmentShader* res = resMgr.create< FragmentShader >( FilePath( pFileName ) );

   const std::string& script = res->getScript();

   *ppData = (LPCVOID)script.c_str();
   *pBytes = script.length();

   return S_OK;
}
开发者ID:chenwenbin928,项目名称:tamy,代码行数:12,代码来源:DX9ShaderIncludeLoader.cpp

示例8: Init

ShaderProgram::ShaderProgram(const char *pFragmentFile, const char *pVertexFile)
{
    Init();

    FragmentShader	*pFragmentShader	= new FragmentShader(pFragmentFile);
    VertexShader	*pVertexShader		= new VertexShader(pVertexFile);

    SetFragmentShader(pFragmentShader);
    SetVertexShader(pVertexShader);

    pFragmentShader->Release();
    pVertexShader->Release();

    CreateProgram();
}
开发者ID:scottrick,项目名称:dgame,代码行数:15,代码来源:ShaderProgram.cpp

示例9: make_prog

	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

示例10: mRange

    UserInterface::UserInterface(float inRange) : mRange(inRange), mRatio(0.0f),
        mMouseX(0.0f), mMouseY(0.0f), mMouseOverWidget(NULL),
        mClickCandidate(NULL), mModelViewProjection(mMatrix)
    {
        if (mRange < 1.0f) mRange = 1.0f;

        VertexShader vs;

        const char* vertexShader =
            "#version 120\n"
            "uniform mat4 uMVPM;\n"
            "attribute vec2 iPosition;\n"
            "attribute vec2 iTexture;\n"
            "varying vec2 vTexture;\n"
            "void main(void)\n"
            "{\n"
            "    vTexture = iTexture;\n"
            "    vec4 p = vec4(iPosition, 0.0, 1.0);\n"
            "    gl_Position = uMVPM * p;\n"
            "}\n"
            ;

        vs.loadFromBuffer(vertexShader);

        FragmentShader fs;

        const char* fragmentShader =
            "#version 120\n"
            "uniform sampler2D uTexture;\n"
            "varying vec2 vTexture;\n"
            "void main(void)\n"
            "{\n"
            "    gl_FragColor = texture2D(uTexture, vTexture);\n"
            "}\n"
            ;

        fs.loadFromBuffer(fragmentShader);

        mProgram.attachShader(vs);
        mProgram.attachShader(fs);
        mProgram.bindAttribLocation(0, "iVertex");
        mProgram.bindAttribLocation(1, "iTexture");
        mProgram.link();
        mUniMVPM = mProgram.getUniformLocation("uMVPM");
        mUniTexture = mProgram.getUniformLocation("uTexture");

        glUniform1i(mUniTexture, 0);
    }
开发者ID:CYBORUS,项目名称:cyborus-game-engine,代码行数:48,代码来源:UserInterface.cpp

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

示例12: catch

 FragmentShader<RS>* ShaderManager<RS>::getFragmentShader(const String& file, const String& function)
    {
    FragmentShader<RS>* out = 0;
    auto f = fShaders.find(file);
    if(f != fShaders.end())
       {
       auto fn = (*f).second.find(function);
       if(fn != (*f).second.end())
          {
          out  = (*fn).second;
          }
       else
          {
          out = new FragmentShader<RS>();
          try
             {
             out->Shader::init(file, function);
             fShaders[file][function] = out;
             }
          catch(DeviceFailureException e)
             {
             LOG(e.what());
             out->destroy();
             out = fShaders[Defaults::mapName][Defaults::mapName];
             }
          }
       }
    else
       {
       fShaders[file] = HashMap<String,FragmentShader<RS>*>();
       out = new FragmentShader<RS>();
       try
          {
          out->Shader::init(file, function);
          fShaders[file][function] = out;
          }
       catch(DeviceFailureException e)
          {
          LOG(e.what());
          out->destroy();
          out = fShaders[Defaults::mapName][Defaults::mapName];
          }
       }
    return out;
    }
开发者ID:radneyalquiza,项目名称:GAM531_Emperor,代码行数:45,代码来源:ShaderManager.cpp

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

示例14: VertexShader

//-----------------------------------------------------------------------------------------------------------------------------------------------------
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

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


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