void GameObjectMaterialComponentsWidget::on_m_VSPropsButton_clicked()
{
	if(!m_IsReady)
	{
		return;
	}

	MeshMaterialGOC* meshMat = GetMeshMaterialGOC();

	if(meshMat == nullptr)
	{
		return;
	}

	VertexShader* vs = meshMat->GetVertexShaderResource();
	if(vs == nullptr)
	{
		return;
	}

	ShaderProperties* vsProps = meshMat->GetVertexShaderProperties();

	GameObjectShaderPropsDialog shaderPropsDiag(meshMat->GetName(), vs->GetName(), m_GameApp->GetGameAssetManager(), vsProps);

	shaderPropsDiag.exec();
}
Ejemplo n.º 2
0
	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);
	}
Ejemplo n.º 3
0
	static Program make(void)
	{
		Program prog;

		VertexShader vs;
		vs.Source(
			"#version 330\n"
			"uniform vec2 ScreenSize;"
			"in vec4 Position;"
			"in vec2 TexCoord;"
			"out vec2 vertTexCoord;"
			"void main(void)"
			"{"
			"	gl_Position = Position;"
			"	vertTexCoord = TexCoord*ScreenSize;"
			"}"
		).Compile();

		FragmentShader fs;
		fs.Source(
			"#version 330\n"
			"uniform sampler1D Palette;"
			"uniform sampler2DRect Tex;"
			"in vec2 vertTexCoord;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	float Overdraw = texture(Tex, vertTexCoord).r;"
			"	fragColor = texture(Palette, Overdraw);"
			"}"
		).Compile();

		prog.AttachShader(vs).AttachShader(fs).Link().Use();
		return std::move(prog);
	}
Ejemplo n.º 4
0
	static Program make(void)
	{
		VertexShader vs;
		vs.Source(
			"#version 330\n"
			"uniform mat4  CameraMatrix,ModelMatrix;"

			"in vec4 Position;"

			"void main(void)"
			"{"
			"	gl_Position = CameraMatrix * ModelMatrix * Position;"
			"}"
		).Compile();

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

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

		return std::move(prog);
	}
Ejemplo n.º 5
0
	// 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;
	}
Ejemplo n.º 6
0
	static Program make(void)
	{
		Program prog;

		VertexShader vs;
		vs.Source(
			"#version 330\n"
			"uniform mat4 ProjectionMatrix, CameraMatrix;"
			"layout (std140) uniform OffsetBlock {vec3 Offset[16*16*16];};"
			"in vec3 Position;"
			"void main(void)"
			"{"
			"	gl_Position = "
			"		ProjectionMatrix *"
			"		CameraMatrix *"
			"		vec4(Position+Offset[gl_InstanceID], 1.0);"
			"}"
		).Compile();

		FragmentShader fs;
		fs.Source(
			"#version 330\n"
			"out float fragValue;"
			"void main(void)"
			"{"
			"	fragValue = 1.0/16.0;"
			"}"
		).Compile();

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

		return std::move(prog);
	}
Ejemplo n.º 7
0
   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;
      }
Ejemplo n.º 8
0
	bool MicroManagerTest::initalize(float width, float height)
	{
		VertexShader vertexShader;
	
		vertexShader.set(  mData->sManager.loadVertexFromFile(&md3d, L"EngineVSPosNormalUV") );
		mData->ps = mData->sManager.loadPixelFromFile(&md3d, L"PSPosNormalUV");

	
		VertexShaderHandle modelShader = VertexShaderManager::newVertexShader( vertexShader );

		md3d.getDeviceContext()->PSSetShader(mData->ps,NULL,NULL);

		Procedural::MeshBuilderType mbt;
		Procedural::BoxGenerator	bg;
		bg.addToMeshBuilder( mbt );

		auto mesh = mbt.toMeshVertexCPU();

		mData->model = ModelBuilder::makeStaticGeometryModel( md3d, VertexTypeManager::getVertexType(VertexTypeManager::Pos_Normal_UV), D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, mesh->toMeshCPU() );
		ModelManager::fromHandle(mData->model).mVSShader = modelShader;

		mbt.clear();

		Procedural::SphereGenerator sg(1,128,128);

		sg.addToMeshBuilder( mbt );
		auto meshSphere = mbt.toMeshVertexCPU();
		mData->sphere = ModelBuilder::makeStaticGeometryModel( md3d, VertexTypeManager::getVertexType(VertexTypeManager::Pos_Normal_UV), D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, meshSphere->toMeshCPU() );
		ModelManager::fromHandle(mData->sphere).mVSShader = modelShader;

		mData->cam.setPerspectiveFOV( DirectX::XMConvertToRadians(45),width / height, 0.1, 500 );
		mData->cam.lookAt( .0f,.0f,.0f );
		mData->cam.setPosition( .0f, .0f, -30.0f );
		mData->cam.setRotationEuler( .0f,.0f,.0f);


		int count = 0;
		MaterialHandle fakeMaterial;
		// Generate the box Array and positions
		for( float xPos = -10.0f; xPos < 10.0f; xPos += 2.0f )
		{
			for( float yPos = -10.0f; yPos < 10.0f; yPos += 2.0f )
			{
				count++;
				BoxDemo2 bx = {xPos, yPos, 0.0f, 0.0f, 0.0f, 0.0f, mData->mang->newRi( count % 2 == 0 ? mData->model : mData->sphere, fakeMaterial )};
				mData->boxes.push_back( bx );
			}
		}

		mIsOk = true;

		matrix proj;
		mData->cam.getProjData( &proj );
		mData->mang->displayUpdate( proj );


		return mIsOk;

	}
Ejemplo n.º 9
0
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;
	}
}
Ejemplo n.º 10
0
	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;
	}
Ejemplo n.º 11
0
//----------------------------------------------------------------------------
void LightAmbEffect::PostLink ()
{
	VisualEffect::PostLink();

	VisualPass* pass = mTechniques[0]->GetPass(0);
	VertexShader* vshader = pass->GetVertexShader();
	PixelShader* pshader = pass->GetPixelShader();
	vshader->SetBaseRegisters(msVRegisters);
	vshader->SetPrograms(msVPrograms);
	pshader->SetPrograms(msPPrograms);
}
Ejemplo n.º 12
0
//----------------------------------------------------------------------------
void Texture2ColorBlendEffect::PostLink ()
{
    VisualEffect::PostLink();

    VisualPass* pass = mTechniques[0]->GetPass(0);
    VertexShader* vshader = pass->GetVertexShader();
    PixelShader* pshader = pass->GetPixelShader();
    vshader->SetBaseRegisters(msVRegisters);
    vshader->SetPrograms(msVPrograms);
    pshader->SetTextureUnits(msPTextureUnits);
    pshader->SetPrograms(msPPrograms);
}
Ejemplo n.º 13
0
//----------------------------------------------------------------------------
VertexShader* VertexShader::Load (const char* acFilename)
{
    // open stream, load
    ifstream kIStr(acFilename,ios::in|ios::binary);
    if ( !kIStr )
        return NULL;

    VertexShader* pkShader = new VertexShader;
    pkShader->Read(kIStr);
    kIStr.close();
    return pkShader;
}
Ejemplo n.º 14
0
//----------------------------------------------------------------------------
void JunglerMaterial::PostLink ()
{
	Material::PostLink();

	MaterialPass* pass = mTechniques[0]->GetPass(0);
	VertexShader* vshader = pass->GetVertexShader();
	PixelShader* pshader = pass->GetPixelShader();
	vshader->SetBaseRegisters(msVRegisters);
	vshader->SetPrograms(msVPrograms);
	pshader->SetTextureUnits(msPTextureUnits);
	pshader->SetPrograms(msPPrograms);
}
Ejemplo n.º 15
0
/**
*  @brief
*    Creates a vertex shader and sets the shader source code
*/
VertexShader *ShaderLanguage::CreateVertexShader(const String &sSourceCode, const String &sProfile, const String &sArguments, const String &sEntry)
{
	// Create the vertex shader instance
	VertexShader *pVertexShader = CreateVertexShader();

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

	// Return the created vertex shader instance
	return pVertexShader;
}
//----------------------------------------------------------------------------
VertexColor4TextureEffect::VertexColor4TextureEffect (
    Shader::SamplerFilter filter, Shader::SamplerCoordinate coordinate0,
    Shader::SamplerCoordinate coordinate1)
{
    VertexShader* vshader = new0 VertexShader("Wm5.VertexColorTexture",
        3, 3, 1, 0, false);
    vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3,
        Shader::VS_POSITION);
    vshader->SetInput(1, "modelTCoord", Shader::VT_FLOAT2,
        Shader::VS_TEXCOORD0);
    vshader->SetInput(2, "modelColor", Shader::VT_FLOAT4,
        Shader::VS_COLOR0);
    vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT4,
        Shader::VS_POSITION);
    vshader->SetOutput(1, "vertexTCoord", Shader::VT_FLOAT2,
        Shader::VS_TEXCOORD0);
    vshader->SetOutput(2, "vertexColor", Shader::VT_FLOAT4,
        Shader::VS_COLOR0);
    vshader->SetConstant(0, "PVWMatrix", 4);
    vshader->SetBaseRegisters(msVRegisters);
    vshader->SetPrograms(msVPrograms);

    PixelShader* pshader = new0 PixelShader("Wm5.VertexColorTexture",
        2, 1, 0, 1, false);
    pshader->SetInput(0, "vertexColor", Shader::VT_FLOAT4,
        Shader::VS_COLOR0);
    pshader->SetInput(1, "vertexTCoord", Shader::VT_FLOAT2,
        Shader::VS_TEXCOORD0);
    pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4,
        Shader::VS_COLOR0);
    pshader->SetSampler(0, "BaseSampler", Shader::ST_2D);
    pshader->SetFilter(0, filter);
    pshader->SetCoordinate(0, 0, coordinate0);
    pshader->SetCoordinate(0, 1, coordinate1);
    pshader->SetTextureUnits(msPTextureUnits);
    pshader->SetPrograms(msPPrograms);

    VisualPass* pass = new0 VisualPass();
    pass->SetVertexShader(vshader);
    pass->SetPixelShader(pshader);
    pass->SetAlphaState(new0 AlphaState());
    pass->SetCullState(new0 CullState());
    pass->SetDepthState(new0 DepthState());
    pass->SetOffsetState(new0 OffsetState());
    pass->SetStencilState(new0 StencilState());
    pass->SetWireState(new0 WireState());

    VisualTechnique* technique = new0 VisualTechnique();
    technique->InsertPass(pass);
    InsertTechnique(technique);
}
//----------------------------------------------------------------------------
LightSptPerPixEffect::LightSptPerPixEffect ()
{
    VertexShader* vshader = new0 VertexShader("Wm5.LightSptPerPix",
        2, 3, 1, 0, false);
    vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3,
        Shader::VS_POSITION);
    vshader->SetInput(1, "modelNormal", Shader::VT_FLOAT3,
        Shader::VS_TEXCOORD1);
    vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT4,
        Shader::VS_POSITION);
    vshader->SetOutput(1, "vertexPosition", Shader::VT_FLOAT3,
        Shader::VS_TEXCOORD0);
    vshader->SetOutput(2, "vertexNormal", Shader::VT_FLOAT3,
        Shader::VS_TEXCOORD1);
    vshader->SetConstant(0, "PVWMatrix", 4);
    vshader->SetBaseRegisters(msVRegisters);
    vshader->SetPrograms(msVPrograms);

    PixelShader* pshader = new0 PixelShader("Wm5.LightSptPerPix",
        2, 1, 13, 0, false);
    pshader->SetInput(0, "vertexPosition", Shader::VT_FLOAT3,
        Shader::VS_TEXCOORD0);
    pshader->SetInput(1, "vertexNormal", Shader::VT_FLOAT3,
        Shader::VS_TEXCOORD1);
    pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4,
        Shader::VS_COLOR0);
    pshader->SetConstant(0, "WMatrix", 4);
    pshader->SetConstant(1, "CameraModelPosition", 1);
    pshader->SetConstant(2, "MaterialEmissive", 1);
    pshader->SetConstant(3, "MaterialAmbient", 1);
    pshader->SetConstant(4, "MaterialDiffuse", 1);
    pshader->SetConstant(5, "MaterialSpecular", 1);
    pshader->SetConstant(6, "LightModelPosition", 1);
    pshader->SetConstant(7, "LightModelDirection", 1);
    pshader->SetConstant(8, "LightAmbient", 1);
    pshader->SetConstant(9, "LightDiffuse", 1);
    pshader->SetConstant(10, "LightSpecular", 1);
    pshader->SetConstant(11, "LightSpotCutoff", 1);
    pshader->SetConstant(12, "LightAttenuation", 1);
    pshader->SetBaseRegisters(msPRegisters);
    pshader->SetPrograms(msPPrograms);

    VisualPass* pass = new0 VisualPass();
    pass->SetVertexShader(vshader);
    pass->SetPixelShader(pshader);
    pass->SetAlphaState(new0 AlphaState());
    pass->SetCullState(new0 CullState());
    pass->SetDepthState(new0 DepthState());
    pass->SetOffsetState(new0 OffsetState());
    pass->SetStencilState(new0 StencilState());
    pass->SetWireState(new0 WireState());

    VisualTechnique* technique = new0 VisualTechnique();
    technique->InsertPass(pass);
    InsertTechnique(technique);
}
Ejemplo n.º 18
0
void PipelineStateCache::setVertexShader(const VertexShader& vertexShader)
{
  // FIXME: cache this
  ID3D11Buffer* const* constantBuffers;
  uint32 numConstantBuffers = vertexShader.queryBuffersArray(constantBuffers);
  m_deviceContext->VSSetConstantBuffers(0, numConstantBuffers, constantBuffers);

  ID3D11VertexShader* shaderResourcePtr = vertexShader.getResourcePtr();
  if (shaderResourcePtr != m_currentVertexShader)
  {
    m_currentVertexShader = shaderResourcePtr;
    m_deviceContext->VSSetShader(shaderResourcePtr, NULL, 0);
  }
}
Ejemplo n.º 19
0
//----------------------------------------------------------------------------
UIMaterial::UIMaterial ()
{
    VertexShader* vshader = new0 VertexShader("PX2.UI",
                            3, 3, 1, 0, false);
    vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3,
                      Shader::VS_POSITION);
    vshader->SetInput(1, "modelColor0", Shader::VT_FLOAT4,
                      Shader::VS_COLOR0);
    vshader->SetInput(2, "modelTCoord0", Shader::VT_FLOAT2,
                      Shader::VS_TEXCOORD0);
    vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT4,
                       Shader::VS_POSITION);
    vshader->SetOutput(1, "vertexColor0", Shader::VT_FLOAT4,
                       Shader::VS_COLOR0);
    vshader->SetOutput(2, "vertexTCoord0", Shader::VT_FLOAT2,
                       Shader::VS_TEXCOORD0);
    vshader->SetConstant(0, "gPVWMatrix", 4);
    vshader->SetBaseRegisters(msVRegisters);
    vshader->SetPrograms(msVPrograms);

    PixelShader* pshader = new0 PixelShader("PX2.UI",
                                            2, 1, 0, 1, false);
    pshader->SetInput(0, "vertexColor0", Shader::VT_FLOAT4,
                      Shader::VS_COLOR0);
    pshader->SetInput(1, "vertexTCoord0", Shader::VT_FLOAT2,
                      Shader::VS_TEXCOORD0);
    pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4,
                       Shader::VS_COLOR0);
    pshader->SetSampler(0, "gDiffuseSampler", Shader::ST_2D);
    pshader->SetFilter(0, Shader::SF_NEAREST);
    pshader->SetCoordinate(0, 0, Shader::SC_CLAMP_EDGE);
    pshader->SetCoordinate(0, 1, Shader::SC_CLAMP_EDGE);
    pshader->SetTextureUnits(msPTextureUnits);
    pshader->SetPrograms(msPPrograms);

    MaterialPass* pass = new0 MaterialPass();
    pass->SetVertexShader(vshader);
    pass->SetPixelShader(pshader);
    pass->SetAlphaProperty(new0 AlphaProperty());
    pass->SetCullProperty(new0 CullProperty());
    pass->SetDepthProperty(new0 DepthProperty());
    pass->SetOffsetProperty(new0 OffsetProperty());
    pass->SetStencilProperty(new0 StencilProperty());
    pass->SetWireProperty(new0 WireProperty());
    pass->GetAlphaProperty()->BlendEnabled = true;

    MaterialTechnique* technique = new0 MaterialTechnique();
    technique->InsertPass(pass);
    InsertTechnique(technique);
}
Ejemplo n.º 20
0
 VertexShader<RS>* ShaderManager<RS>::getVertexShader(const String& file, const String&
    function, const Vertex* p)
    {
    VertexShader<RS>* out = 0;
    auto f = vShaders.find(file);
    if(f != vShaders.end())
       {
       auto fn = (*f).second.find(function);
       if(fn != (*f).second.end())
          {
          out  = (*fn).second;
          }
       else
          {
          out = new VertexShader<RS>();
          if(p)
             out->associateVertex(*p);
          try
             {
             out->Shader::init(file, function);
             vShaders[file][function] = out;
             }
          catch(DeviceFailureException e)
             {
             LOG(e.what());
             out->destroy();
             out = vShaders[Defaults::mapName][Defaults::mapName];
             }
          }
       }
    else
       {
       vShaders[file] = HashMap<String,VertexShader<RS>*>();
       out = new VertexShader<RS>();
       if(p)
          out->associateVertex(*p);
       try
          {
          out->Shader::init(file, function);
          vShaders[file][function] = out;
          }
       catch(DeviceFailureException e)
          {
          LOG(e.what());
          out->destroy();
          out = vShaders[Defaults::mapName][Defaults::mapName];
          }
       }
    return out;
    }
//----------------------------------------------------------------------------
void StandardESMaterial_AlphaTest::PostLink ()
{
	Material::PostLink();

	MaterialPass* pass = mTechniques[0]->GetPass(0);
	VertexShader* vshader = pass->GetVertexShader();
	PixelShader* pshader = pass->GetPixelShader();
	vshader->SetBaseRegisters(msVRegisters);
	vshader->SetPrograms(msVPrograms);
	pshader->SetTextureUnits(msPTextureUnits);
	pshader->SetPrograms(msPPrograms);

	vshader->SetShaderKey(SKT_STANNDES_ALPHATEST);
	pshader->SetShaderKey(SKT_STANNDES_ALPHATEST);
}
Ejemplo n.º 22
0
const unsigned int ShaderCache::getVertexShader(const tinyxml2::XMLElement* element, const DeviceManager& deviceManager)
{
    VertexShader shader;
    shader.deserialise(element);
    unsigned int resourceName = hashString(getResourceNameFromFileName(shader.getFileName()));
    if (getVertexShader(resourceName) == nullptr)
    {
        if (shader.createShader(deviceManager))
        {
            m_vertexShaders.emplace(VertexShaderHandle(resourceName, shader));
        }
    }
    
    return resourceName;
}
Ejemplo n.º 23
0
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();
}
Ejemplo n.º 24
0
	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;
	}
Ejemplo n.º 25
0
    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);
    }
Ejemplo n.º 26
0
ShaderProgram* WindowsGame::createShaderProgram()
{
    ShaderProgram* program = new ShaderProgram();

    VertexShader vertexShader;
    vertexShader.initialize(graphicsDevice, VertexShaderSource, sizeof(VertexShaderSource));

    PixelShader pixelShader;
    pixelShader.initialize(graphicsDevice, PixelShaderSource, sizeof(PixelShaderSource));

    program->initialize(graphicsDevice);
    program->setVertexShader(&vertexShader);
    program->setPixelShader(&pixelShader);

    return program;
}
//==============================================================================
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;

}
Ejemplo n.º 28
0
	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;
	}
Ejemplo n.º 29
0
//-----------------------------------------------------------------------------------------------------------------------------------------------------
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 );
}
Ejemplo n.º 30
0
const RightDrawer::WaterPlaneShaderProgramAndParameters& RightDrawer::getWaterPlaneProgram(WaterPlaneShaderProgramIndex params)
{
	boolean bNew;
	auto it = waterPlaneShaderPrograms.insert(bNew, params);
	if(!bNew)
		return *it->val;

	it->val = new WaterPlaneShaderProgramAndParameters();

	boolean bNewPS;
	auto psIt = waterPlanePixelShaders.insert(bNewPS, params.ps);
	PixelShader* ps;
	if(bNewPS){
		ps = new PixelShader(*this);
		String code = getWaterPlanePixelShaderCode(params.ps);
		ps->init(code);
		psIt->val = ps;
	}
	else
		ps = psIt->val;

	boolean bNewVS;
	auto vsIt = meshVertexShaders.insert(bNewVS, params.vs);
	VertexShader* vs;
	if(bNewVS){
		vs = new VertexShader(*this);
		String code = getMeshVertexShaderCode(params.vs);
		vs->init(code);
		vsIt->val = vs;
	}
	else
		vs = vsIt->val;

	ShaderProgram* prog = new ShaderProgram(*this);
	Array<String> args = getVertexShaderAttributesCode((EVertexFormat)params.vs.format);
	Array<ConstString> arr;
	foreach(it, args)
		arr.push(it->toConst());
	prog->init(*vs, *ps, arr.constRange());
	it->val->init(prog);
	return *it->val;
}