//---------------------------------------------------------------------------- DefaultEffect::DefaultEffect () { VertexShader* vshader = new0 VertexShader("Wm5.Default", 1, 1, 1, 0, false); vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3, Shader::VS_POSITION); vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT, Shader::VS_POSITION); vshader->SetConstant(0, "PVWMatrix", 4); vshader->SetBaseRegisters(msVRegisters); vshader->SetPrograms(msVPrograms); PixelShader* pshader = new0 PixelShader("Wm5.Default", 1, 1, 0, 0, false); pshader->SetInput(0, "vertexTCoord", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); 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); }
//---------------------------------------------------------------------------- VisualEffectInstance* Texture2ColorBlendEffect::CreateInstance ( Texture2D* texture0, Texture2D* texture1) const { VisualEffectInstance* instance = new0 VisualEffectInstance(this, 0); instance->SetVertexConstant(0, 0, new0 PVWMatrixConstant()); instance->SetPixelTexture(0, 0, texture0); instance->SetPixelTexture(0, 1, texture1); PixelShader* pshader = GetPixelShader(); Shader::SamplerFilter filter0 = pshader->GetFilter(0); if (filter0 != Shader::SF_NEAREST && filter0 != Shader::SF_LINEAR && !texture0->HasMipmaps()) { texture0->GenerateMipmaps(); } Shader::SamplerFilter filter1 = pshader->GetFilter(1); if (filter1 != Shader::SF_NEAREST && filter1 != Shader::SF_LINEAR && !texture1->HasMipmaps()) { texture1->GenerateMipmaps(); } return instance; }
void GameObjectMaterialComponentsWidget::on_m_PSPropsButton_clicked() { if(!m_IsReady) { return; } MeshMaterialGOC* meshMat = GetMeshMaterialGOC(); if(meshMat == nullptr) { return; } PixelShader* ps = meshMat->GetPixelShaderResource(); if(ps == nullptr) { return; } ShaderProperties* psProps = meshMat->GetPixelShaderProperties(); GameObjectShaderPropsDialog shaderPropsDiag(meshMat->GetName(), ps->GetName(), m_GameApp->GetGameAssetManager(), psProps); shaderPropsDiag.exec(); }
//---------------------------------------------------------------------------- void Smoke2D::CreateAdjustVelocityEffect (VisualEffect*& effect, VisualEffectInstance*& instance) { PixelShader* pshader = new0 PixelShader("Wm5.AdjustVelocity2", 1, 1, 1, 2, false); pshader->SetInput(0, "vertexTCoord", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetConstant(0, "SpaceParam", 1); pshader->SetSampler(0, "StateSampler", Shader::ST_2D); pshader->SetSampler(1, "PoissonSampler", Shader::ST_2D); pshader->SetBaseRegisters(msAdjustVelocityPRegisters); pshader->SetTextureUnits(msAdjustVelocityPTextureUnits); pshader->SetPrograms(msAdjustVelocityPPrograms); mIP->CreateEffect(pshader, effect, instance); ShaderFloat* spaceParamConstant = new0 ShaderFloat(1); float* spaceParam = spaceParamConstant->GetData(); spaceParam[0] = mDx; spaceParam[1] = mDy; spaceParam[2] = mHalfDivDx; spaceParam[3] = mHalfDivDy; instance->SetPixelConstant(0, "SpaceParam", spaceParamConstant); instance->SetPixelTexture(0, "StateSampler", mIP->GetTarget(1)->GetColorTexture(0)); instance->SetPixelTexture(0, "PoissonSampler", mIP->GetTarget(0)->GetColorTexture(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); }
//---------------------------------------------------------------------------- JunglerMaterial::JunglerMaterial () { VertexShader* vshader = new0 VertexShader("PX2.JunglerMaterial", 3, 3, 8, 0, false); vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3, Shader::VS_POSITION); vshader->SetInput(1, "modelNormal", Shader::VT_FLOAT3, Shader::VS_NORMAL); vshader->SetInput(2, "modelTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT4, Shader::VS_POSITION); vshader->SetOutput(1, "vertexTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); vshader->SetOutput(2, "vertexTCoord1", Shader::VT_FLOAT4, Shader::VS_TEXCOORD1); vshader->SetConstant(0, "gPVWMatrix", 4); vshader->SetConstant(1, "gShineEmissive", 1); vshader->SetConstant(2, "gShineAmbient", 1); vshader->SetConstant(3, "gShineDiffuse", 1); vshader->SetConstant(4, "gLightColour", 1); vshader->SetConstant(5, "gLightAttenuation", 1); vshader->SetConstant(6, "gLightModelDirection", 1); vshader->SetConstant(7, "gUser", 1); vshader->SetBaseRegisters(msVRegisters); vshader->SetPrograms(msVPrograms); PixelShader* pshader = new0 PixelShader("PX2.JunglerMaterial", 2, 1, 0, 1, false); pshader->SetInput(0, "vertexTCoord0", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); pshader->SetInput(1, "vertexTCoord1", Shader::VT_FLOAT4, Shader::VS_TEXCOORD1); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetSampler(0, "gDiffuseSampler", Shader::ST_2D); pshader->SetFilter(0, Shader::SF_LINEAR); pshader->SetCoordinate(0, 0, Shader::SC_REPEAT); pshader->SetCoordinate(0, 1, Shader::SC_REPEAT); 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()); MaterialTechnique* technique = new0 MaterialTechnique(); technique->InsertPass(pass); InsertTechnique(technique); }
//---------------------------------------------------------------------------- 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); }
//---------------------------------------------------------------------------- VisualEffectInstance* Texture2DEffect::CreateUniqueInstance ( Texture2D* texture, Shader::SamplerFilter filter, Shader::SamplerCoordinate coordinate0, Shader::SamplerCoordinate coordinate1) { Texture2DEffect* effect = new0 Texture2DEffect(); PixelShader* pshader = effect->GetPixelShader(); pshader->SetFilter(0, filter); pshader->SetCoordinate(0, 0, coordinate0); pshader->SetCoordinate(0, 1, coordinate1); return effect->CreateInstance(texture); }
//---------------------------------------------------------------------------- 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); }
//---------------------------------------------------------------------------- DLitMatTexEffect::DLitMatTexEffect (const std::string& effectFile) : VisualEffect(effectFile) { // TODO: Once WmfxCompiler parses the Cg FX files, we will not need to // set the sampler state. PixelShader* pshader = GetPixelShader(0, 0); // DiffuseSampler pshader->SetFilter(0, Shader::SF_LINEAR_LINEAR); pshader->SetCoordinate(0, 0, Shader::SC_REPEAT); pshader->SetCoordinate(0, 1, Shader::SC_REPEAT); }
//---------------------------------------------------------------------------- SMBlurEffect::SMBlurEffect (const std::string& effectFile) : VisualEffect(effectFile) { // TODO: Once WmfxCompiler parses the Cg FX files, we will not need to // set the sampler state. PixelShader* pshader = GetPixelShader(0, 0); // BaseSampler pshader->SetFilter(0, Shader::SF_LINEAR); pshader->SetCoordinate(0, 0, Shader::SC_CLAMP_EDGE); pshader->SetCoordinate(0, 1, Shader::SC_CLAMP_EDGE); }
//---------------------------------------------------------------------------- void Smoke2D::CreateDrawDensityEffect (VisualEffect*& effect, VisualEffectInstance*& instance) { PixelShader* pshader = new0 PixelShader("Wm5.DrawDensity2", 1, 1, 0, 3, false); pshader->SetInput(0, "vertexTCoord", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetSampler(0, "StateSampler", Shader::ST_2D); pshader->SetSampler(1, "ColorTableSampler", Shader::ST_1D); pshader->SetSampler(2, "VortexSampler", Shader::ST_2D); pshader->SetFilter(1, Shader::SF_LINEAR); pshader->SetTextureUnits(msDrawDensityPTextureUnits); pshader->SetPrograms(msDrawDensityPPrograms); mIP->CreateEffect(pshader, effect, instance); // For pseudocoloring density. mGrayTexture = new0 Texture1D(Texture::TF_A8R8G8B8, 8, 1); unsigned char* gray = (unsigned char*)mGrayTexture->GetData(0); gray[ 0] = 0; gray[ 1] = 0; gray[ 2] = 0; gray[ 3] = 255; gray[ 4] = 32; gray[ 5] = 32; gray[ 6] = 32; gray[ 7] = 255; gray[ 8] = 64; gray[ 9] = 64; gray[10] = 64; gray[11] = 255; gray[12] = 96; gray[13] = 96; gray[14] = 96; gray[15] = 255; gray[16] = 128; gray[17] = 128; gray[18] = 128; gray[19] = 255; gray[20] = 160; gray[21] = 160; gray[22] = 160; gray[23] = 255; gray[24] = 192; gray[25] = 192; gray[26] = 192; gray[27] = 255; gray[28] = 255; gray[29] = 255; gray[30] = 255; gray[31] = 255; mColorTexture = new0 Texture1D(Texture::TF_A8R8G8B8, 8, 1); unsigned char* color = (unsigned char*)mColorTexture->GetData(0); color[ 0] = 0; color[ 1] = 0; color[ 2] = 0; color[ 3] = 255; color[ 4] = 255; color[ 5] = 0; color[ 6] = 128; color[ 7] = 255; color[ 8] = 255; color[ 9] = 0; color[10] = 0; color[11] = 255; color[12] = 0; color[13] = 255; color[14] = 0; color[15] = 255; color[16] = 0; color[17] = 255; color[18] = 255; color[19] = 255; color[20] = 0; color[21] = 128; color[22] = 255; color[23] = 255; color[24] = 0; color[25] = 0; color[26] = 255; color[27] = 255; color[28] = 255; color[29] = 255; color[30] = 255; color[31] = 255; // For vortex-center overlay. mVortexTexture = new0 Texture2D(Texture::TF_A8R8G8B8, mIMaxP1, mJMaxP1, 1); memset(mVortexTexture->GetData(0), 0, 4*mNumPixels); instance->SetPixelTexture(0, "StateSampler", mIP->GetTarget(1)->GetColorTexture(0)); instance->SetPixelTexture(0, "ColorTableSampler", mGrayTexture); instance->SetPixelTexture(0, "VortexSampler", mVortexTexture); mRenderer->Bind(mGrayTexture); mRenderer->Bind(mColorTexture); mRenderer->Bind(mVortexTexture); }
//============================================================================== PixelShader * CGraphicsMgr::LoadPixelShader ( const std::wstring & name, const std::wstring & filepath, const std::string & entryFunction ) { PixelShader * shader = FindPixelShaderRaii(name); if (!shader->Compile(name, filepath, entryFunction)) return NULL; return shader; }
int main (int argc, char **argv) { cairo_t *cr; cairo_surface_t *dst, *src; CustomEffect *effect; PixelShader *shader; int stride = width * 4; Rect bounds = Rect (0, 0, width, height); gpointer data; bool status; if (argc < 2) { printf ("usage: %s SHADERFILE\n", argv[0]); return 1; } gtk_init (&argc, &argv); runtime_init_desktop (); data = g_malloc0 (height * stride); dst = cairo_image_surface_create_for_data ((unsigned char *) data, CAIRO_FORMAT_ARGB32, width, height, stride); src = cairo_surface_create_similar (dst, CAIRO_CONTENT_COLOR_ALPHA, width, height); cr = cairo_create (dst); effect = new CustomEffect (); shader = new PixelShader (); shader->SetTokensFromPath (argv[1]); effect->SetPixelShader (shader); status = effect->Render (cr, src, NULL, 0, 0, width, height); effect->unref (); shader->unref (); cairo_destroy (cr); cairo_surface_destroy (src); cairo_surface_destroy (dst); g_free (data); runtime_shutdown (); return status != true; }
void PipelineStateCache::setPixelShader(const PixelShader& pixelShader) { // FIXME: cache this ID3D11Buffer* const* constantBuffers; uint32 numConstantBuffers = pixelShader.queryBuffersArray(constantBuffers); m_deviceContext->PSSetConstantBuffers(0, numConstantBuffers, constantBuffers); ID3D11PixelShader* shaderResourcePtr = pixelShader.getResourcePtr(); if (shaderResourcePtr != m_currentPixelShader) { m_currentPixelShader = shaderResourcePtr; m_deviceContext->PSSetShader(shaderResourcePtr, NULL, 0); } }
//---------------------------------------------------------------------------- LightPntPerVerEffect::LightPntPerVerEffect () { VertexShader* vshader = new0 VertexShader("Wm5.LightPntPerVer", 2, 2, 12, 0, false); vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3, Shader::VS_POSITION); vshader->SetInput(1, "modelNormal", Shader::VT_FLOAT3, Shader::VS_NORMAL); vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT4, Shader::VS_POSITION); vshader->SetOutput(1, "vertexColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); vshader->SetConstant(0, "PVWMatrix", 4); vshader->SetConstant(1, "WMatrix", 4); vshader->SetConstant(2, "CameraModelPosition", 1); vshader->SetConstant(3, "MaterialEmissive", 1); vshader->SetConstant(4, "MaterialAmbient", 1); vshader->SetConstant(5, "MaterialDiffuse", 1); vshader->SetConstant(6, "MaterialSpecular", 1); vshader->SetConstant(7, "LightModelPosition", 1); vshader->SetConstant(8, "LightAmbient", 1); vshader->SetConstant(9, "LightDiffuse", 1); vshader->SetConstant(10, "LightSpecular", 1); vshader->SetConstant(11, "LightAttenuation", 1); vshader->SetBaseRegisters(msVRegisters); vshader->SetPrograms(msVPrograms); PixelShader* pshader = new0 PixelShader("Wm5.LightPntPerVer", 1, 1, 0, 0, false); pshader->SetInput(0, "vertexColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); 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); }
//------------------------------------------------------------------------- // @brief //------------------------------------------------------------------------- const unsigned int ShaderCache::getPixelShader(const tinyxml2::XMLElement* element, const DeviceManager& deviceManager) { PixelShader shader; shader.deserialise(element); unsigned int resourceName = hashString(getResourceNameFromFileName(shader.getFileName())); if (getPixelShader(resourceName) == nullptr) { if (shader.createShader(deviceManager)) { m_pixelShaders.emplace(PixelShaderHandle(resourceName, shader)); } } return resourceName; }
//---------------------------------------------------------------------------- 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); }
void Renderer::FillSpan( float x0, float x1, int y, VertexShaderOutput& va0, VertexShaderOutput& va1, PixelShader& ps ) { int startX = Float2Int(x0); int endX = Float2Int(x1); float lenR = 1.0f / (x1 - x0); float xt = x0; VertexShaderOutput va; for (int x = startX; x < endX; x++) { xt = float(x + 1); Lerp(va, va0, va1, (x1 - xt) * lenR); // early z-test (before executing pixel shader) if (!m_depthBuffer->TestDepth(x, y, va.position.z)) { continue; } // execute the pixel shader Vector4& color = ps.Main(va); int r = Float2Int(color.x * 255.0f); int g = Float2Int(color.y * 255.0f); int b = Float2Int(color.z * 255.0f); m_renderTarget->SetPixel(x, y, COLOR_RGB(r, g, b)); } }
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; }
//---------------------------------------------------------------------------- PixelShader* GpuGaussianBlur3::CreateBlurPixelShader () { PixelShader* pshader = new0 PixelShader("Wm5.GaussianBlur3", 1, 1, 2, 2, false); pshader->SetInput(0, "vertexTCoord", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetConstant(0, "Delta", 1); pshader->SetConstant(1, "Weight", 1); pshader->SetSampler(0, "OffsetSampler", Shader::ST_2D); pshader->SetSampler(1, "StateSampler", Shader::ST_2D); pshader->SetBaseRegisters(msPRegisters); pshader->SetTextureUnits(msPTextureUnits); pshader->SetPrograms(msPPrograms); return pshader; }
void AGALWriter::WriteShader(const PixelShader& shader, std::ostream& stream) { stream << shader.GetInfo(); for (const Statement& statement : shader.GetStatements()) { stream << statement; if (statement.opcode == Opcode::TEXLD) stream << " <2d, " << (wrapMode == TextureSampling::CLAMP? "clamp, " : "wrap, ") << (textureFiltering == TextureSampling::LINEAR? "linear, " : "nearest, ") << (mipFiltering == TextureSampling::MIPNONE? "mipnone" : mipFiltering == TextureSampling::MIPLINEAR? "miplinear" : "mipnearest") << ">"; stream << std::endl; } }
PixelShader RemoveMADTransformation::Transform(const PixelShader& original) { PixelShader shader; shader.SetInfo(original.GetInfo()); unsigned int i = 0; for (const Statement& statement : original.GetStatements()) { if (statement.opcode == Opcode::MAD) Replace(original, &shader, statement, i); else shader.PushStatement(statement); ++i; } return shader; }
//---------------------------------------------------------------------------- VisualEffectInstance* Texture2ColorBlendEffect::CreateUniqueInstance ( Texture2D* texture0, Shader::SamplerFilter filter0, Shader::SamplerCoordinate coordinate00, Shader::SamplerCoordinate coordinate01, Texture2D* texture1, Shader::SamplerFilter filter1, Shader::SamplerCoordinate coordinate10, Shader::SamplerCoordinate coordinate11) { Texture2ColorBlendEffect* effect = new0 Texture2ColorBlendEffect(); PixelShader* pshader = effect->GetPixelShader(); pshader->SetFilter(0, filter0); pshader->SetCoordinate(0, 0, coordinate00); pshader->SetCoordinate(0, 1, coordinate01); pshader->SetFilter(1, filter1); pshader->SetCoordinate(1, 0, coordinate10); pshader->SetCoordinate(1, 1, coordinate11); return effect->CreateInstance(texture0, texture1); }
//---------------------------------------------------------------------------- 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); }
//---------------------------------------------------------------------------- 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); }
PixelShader RemoveNegationTransformation::Transform(const PixelShader& original) { PixelShader shader; shader.SetInfo(original.GetInfo()); unsigned int i = 0; for (const Statement& statement : original.GetStatements()) { if (statement.source1.negated || statement.source2.negated) { Replace(original, &shader, statement, i); } else shader.PushStatement(statement); ++i; } return shader; }
int main() { RenderTarget *renderTarget = new RenderTarget(); Surface *colorBuffer = new (memalign(64, sizeof(Surface))) Surface(kFbWidth, kFbHeight, (void*) 0x200000); Surface *zBuffer = new (memalign(64, sizeof(Surface))) Surface(kFbWidth, kFbHeight); renderTarget->setColorBuffer(colorBuffer); renderTarget->setZBuffer(zBuffer); RenderContext *context = new RenderContext(renderTarget); VertexShader *vertexShader = new (memalign(64, sizeof(PhongVertexShader))) PhongVertexShader(); PixelShader *pixelShader = new PhongPixelShader(renderTarget); pixelShader->enableZBuffer(true); context->bindShader(vertexShader, pixelShader); PhongUniforms *uniforms = new PhongUniforms; uniforms->fLightVector[0] = 0.7071067811f; uniforms->fLightVector[1] = 0.7071067811f; uniforms->fLightVector[2] = 0.0f; uniforms->fDirectional = 0.6f; uniforms->fAmbient = 0.2f; context->bindUniforms(uniforms); Matrix projectionMatrix = Matrix::getProjectionMatrix(kFbWidth, kFbHeight); Matrix modelViewMatrix; Matrix rotationMatrix; context->bindGeometry(kTeapotVertices, kNumTeapotVertices, kTeapotIndices, kNumTeapotIndices); modelViewMatrix = Matrix::getTranslationMatrix(0.0f, 0.1f, 0.25f); modelViewMatrix = modelViewMatrix * Matrix::getRotationMatrix(M_PI, -1.0f, 0.0f, 0.0f); rotationMatrix = Matrix::getRotationMatrix(M_PI / 8, 0.707f, 0.707f, 0.0f); for (int frame = 0; frame < 1; frame++) { uniforms->fMVPMatrix = projectionMatrix * modelViewMatrix; uniforms->fNormalMatrix = modelViewMatrix.upper3x3(); context->renderFrame(); modelViewMatrix = modelViewMatrix * rotationMatrix; } return 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; }
//---------------------------------------------------------------------------- void ImageProcessing2::CreateDrawMaterial (Material*& material, MaterialInstance*& instance) { // sampler2D StateSampler = sampler_state // { // MinFilter = Nearest; // MagFilter = Nearest; // WrapS = Clamp; // WrapT = Clamp; // }; // void p_ScreenShader2 // ( // in float2 vertexTCoord : TEXCOORD0, // out float4 pixelColor : COLOR // ) // { // pixelColor = tex2D(StateSampler, vertexTCoord); // } PixelShader* pshader = new0 PixelShader("PX2.DrawImage2", 1, 1, 0, 1, false); pshader->SetInput(0, "vertexTCoord", Shader::VT_FLOAT2, Shader::VS_TEXCOORD0); pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4, Shader::VS_COLOR0); pshader->SetSampler(0, "StateSampler", Shader::ST_2D); pshader->SetTextureUnits(msDrawPTextureUnits); pshader->SetPrograms(msDrawPPrograms); CreateMaterial(pshader, material, instance); }