Ejemplo n.º 1
0
//----------------------------------------------------------------------------
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 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);
}
Ejemplo n.º 3
0
//----------------------------------------------------------------------------
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);
}
Ejemplo n.º 4
0
//----------------------------------------------------------------------------
void Smoke2D::CreateFluidUpdateEffect (VisualEffect*& effect,
    VisualEffectInstance*& instance)
{
    PixelShader* pshader = new0 PixelShader("Wm5.FluidUpdate2",
        1, 1, 3, 3, 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->SetConstant(1, "TimeParam", 1);
    pshader->SetConstant(2, "ViscParam", 1);
    pshader->SetSampler(0, "StateSampler", Shader::ST_2D);
    pshader->SetSampler(1, "AdvectionSampler", Shader::ST_2D);
    pshader->SetSampler(2, "SourceSampler", Shader::ST_2D);
    pshader->SetFilter(1, Shader::SF_LINEAR);
    pshader->SetBaseRegisters(msFluidUpdatePRegisters);
    pshader->SetTextureUnits(msFluidUpdatePTextureUnits);
    pshader->SetPrograms(msFluidUpdatePPrograms);

    mIP->CreateEffect(pshader, effect, instance);

    ShaderFloat* spaceParamConstant = new0 ShaderFloat(1);
    float* spaceParam = spaceParamConstant->GetData();
    spaceParam[0] = mDx;
    spaceParam[1] = mDy;
    spaceParam[2] = 1.0f/(float)mIMax;
    spaceParam[3] = 1.0f/(float)mJMax;
    instance->SetPixelConstant(0, "SpaceParam", spaceParamConstant);

    ShaderFloat* timeParamConstant = new0 ShaderFloat(1);
    float* timeParam = timeParamConstant->GetData();
    timeParam[0] = mDtDivDx;
    timeParam[1] = mDtDivDy;
    timeParam[2] = mDt;
    instance->SetPixelConstant(0, "TimeParam", timeParamConstant);

    ShaderFloat* viscParamConstant = new0 ShaderFloat(1);
    float* viscParam = viscParamConstant->GetData();
    viscParam[0] = mDenLambdaX;
    viscParam[1] = mDenLambdaY;
    viscParam[2] = mVelLambdaX;
    viscParam[3] = mVelLambdaY;
    instance->SetPixelConstant(0, "ViscParam", viscParamConstant);

    mSourceTexture = new0 Texture2D(Texture::TF_A32B32G32R32F, mIMaxP1,
        mJMaxP1, 1);
    ComputeSource();

    instance->SetPixelTexture(0, "StateSampler",
        mIP->GetTarget(1)->GetColorTexture(0));
    instance->SetPixelTexture(0, "AdvectionSampler",
        mIP->GetTarget(4)->GetColorTexture(0));
    instance->SetPixelTexture(0, "SourceSampler", mSourceTexture);

    mRenderer->Bind(mSourceTexture);
}
Ejemplo n.º 5
0
//----------------------------------------------------------------------------
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);
}
Ejemplo n.º 6
0
//----------------------------------------------------------------------------
void Texture3DEffect::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.º 7
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);
}
//----------------------------------------------------------------------------
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);
}
Ejemplo n.º 9
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);
}
//----------------------------------------------------------------------------
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.º 11
0
//----------------------------------------------------------------------------
PixelShader* GpuGaussianBlur2::CreateBlurPixelShader ()
{
    PixelShader* pshader = new0 PixelShader("Wm5.GaussianBlur2",
        1, 1, 2, 1, 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, "StateSampler", Shader::ST_2D);
    pshader->SetBaseRegisters(msPRegisters);
    pshader->SetTextureUnits(msPTextureUnits);
    pshader->SetPrograms(msPPrograms);
    return pshader;
}
Ejemplo n.º 12
0
//----------------------------------------------------------------------------
void Smoke2D::CreateCopyStateEffect (VisualEffect*& effect,
    VisualEffectInstance*& instance)
{
    PixelShader* pshader = new0 PixelShader("Wm5.CopyState2",
        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(msCopyStatePTextureUnits);
    pshader->SetPrograms(msCopyStatePPrograms);

    mIP->CreateEffect(pshader, effect, instance);

    mInitialTexture = new0 Texture2D(Texture::TF_A32B32G32R32F, mIMaxP1,
        mJMaxP1, 1);

    if (PixelShader::GetProfile() == PixelShader::PP_ARBFP1)
    {
        float* data = (float*)mInitialTexture->GetData(0);
        for (int j = 0; j <= mJMax; ++j)
        {
            for (int i = 0; i <= mIMax; ++i)
            {
                *data++ = 0.0f;  // velocity.x
                *data++ = 0.0f;  // velocity.y
                *data++ = 0.0f;  // empty
                *data++ = Mathf::UnitRandom();
            }
        }
    }
    else
    {
        Float4* data = (Float4*)mInitialTexture->GetData(0);
        for (int j = 0; j <= mJMax; ++j)
        {
            for (int i = 0; i <= mIMax; ++i)
            {
                data[i + mIMaxP1*(mJMax-j)] = Float4(0.0f, 0.0f, 0.0f,
                    Mathf::UnitRandom());
            }
        }
    }

    mRenderer->Bind(mInitialTexture);
}
Ejemplo n.º 13
0
//----------------------------------------------------------------------------
Texture2DMaterial::Texture2DMaterial (Shader::SamplerFilter filter,
								  Shader::SamplerCoordinate coordinate0,
								  Shader::SamplerCoordinate coordinate1)
{
	VertexShader* vshader = new0 VertexShader("PX2.Texture2D",
		2, 2, 1, 0, false);
	vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3,
		Shader::VS_POSITION);
	vshader->SetInput(1, "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->SetConstant(0, "gPVWMatrix", 4);
	vshader->SetBaseRegisters(msVRegisters);
	vshader->SetPrograms(msVPrograms);

	PixelShader* pshader = new0 PixelShader("PX2.Texture2D",
		1, 1, 0, 1, false);
	pshader->SetInput(0, "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, filter);
	pshader->SetCoordinate(0, 0, coordinate0);
	pshader->SetCoordinate(0, 1, coordinate1);
	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);
}
Ejemplo n.º 14
0
//----------------------------------------------------------------------------
void Smoke2D::CreatePoissonSolverEffect (VisualEffect*& effect,
    VisualEffectInstance*& instance)
{
    PixelShader* pshader = new0 PixelShader("Wm5.PoissonSolver2",
        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, "SpaceParam", 1);
    pshader->SetConstant(1, "EpsilonParam", 1);
    pshader->SetSampler(0, "DivergenceSampler", Shader::ST_2D);
    pshader->SetSampler(1, "PoissonSampler", Shader::ST_2D);
    pshader->SetBaseRegisters(msPoissonSolverPRegisters);
    pshader->SetTextureUnits(msPoissonSolverPTextureUnits);
    pshader->SetPrograms(msPoissonSolverPPrograms);

    mIP->CreateEffect(pshader, effect, instance);

    ShaderFloat* spaceParamConstant = new0 ShaderFloat(1);
    float* spaceParam = spaceParamConstant->GetData();
    spaceParam[0] = mDx;
    spaceParam[1] = mDy;
    instance->SetPixelConstant(0, "SpaceParam", spaceParamConstant);

    ShaderFloat* epsilonParamConstant = new0 ShaderFloat(1);
    float* epsilonParam = epsilonParamConstant->GetData();
    epsilonParam[0] = mEpsilonX;
    epsilonParam[1] = mEpsilonY;
    epsilonParam[2] = mEpsilon0;
    instance->SetPixelConstant(0, "EpsilonParam", epsilonParamConstant);

    instance->SetPixelTexture(0, "DivergenceSampler",
        mIP->GetTarget(2)->GetColorTexture(0));
    instance->SetPixelTexture(0, "PoissonSampler",
        mIP->GetTarget(0)->GetColorTexture(0));
}
//----------------------------------------------------------------------------
void ImageProcessing2::CreateBoundaryDirichletMaterial (Material*& material,
													  MaterialInstance*& instance)
{
	// sampler2D MaskSampler = sampler_state
	// {
	//    MinFilter = Nearest;
	//    MagFilter = Nearest;
	//    WrapS     = Clamp;
	//    WrapT     = Clamp;
	// };
	// sampler2D StateSampler = sampler_state
	// {
	//    MinFilter = Nearest;
	//    MagFilter = Nearest;
	//    WrapS     = Clamp;
	//    WrapT     = Clamp;
	// };
	// void p_BoundaryDirichlet
	// (
	//     in float2 vertexTCoord : TEXCOORD0,
	//     out float4 pixelColor : COLOR
	// )
	// {
	//     float4 mask = tex2D(MaskSampler, vertexTCoord);
	//     float4 state = tex2D(StateSampler, vertexTCoord);
	//     pixelColor = mask*state;
	// }

	PixelShader* pshader = new0 PixelShader("PX2.BoundaryDirichlet2",
		1, 1, 0, 2, false);
	pshader->SetInput(0, "vertexTCoord", Shader::VT_FLOAT2,
		Shader::VS_TEXCOORD0);
	pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4,
		Shader::VS_COLOR0);
	pshader->SetSampler(0, "MaskSampler", Shader::ST_2D);
	pshader->SetSampler(1, "StateSampler", Shader::ST_2D);
	pshader->SetTextureUnits(msDirichletPTextureUnits);
	pshader->SetPrograms(msDirichletPPrograms);

	CreateMaterial(pshader, material, instance);

	// 创建mask纹理
	Texture2D* maskTexture = new0 Texture2D(Texture::TF_A32B32G32R32F,
		mBound0, mBound1, 1);

	Float4* mask = (Float4*)maskTexture->GetData(0);
	Float4 one(1.0f, 1.0f, 1.0f, 1.0f);
	Float4 zero(0.0f, 0.0f, 0.0f, 0.0f);
	int x, y;

	// 内部
	for (y = 1; y < mBound1M1; ++y)
	{
		for (x = 1; x < mBound0M1; ++x)
		{
			mask[Index(x,y)] = one;
		}
	}

	// 边
	for (x = 1; x < mBound0M1; ++x)
	{
		mask[Index(x,0)] = zero;
		mask[Index(x,mBound1M1)] = zero;
	}
	for (y = 1; y < mBound1M1; ++y)
	{
		mask[Index(0,y)] = zero;
		mask[Index(mBound0M1,y)] = zero;
	}

	// 角
	mask[Index(0,0)] = zero;
	mask[Index(mBound0M1,0)] = zero;
	mask[Index(0,mBound1M1)] = zero;
	mask[Index(mBound0M1,mBound1M1)] = zero;

	instance->SetPixelTexture(0, "MaskSampler", maskTexture);
}
Ejemplo n.º 16
0
//----------------------------------------------------------------------------
void Smoke2D::CreateBoundaryMixedEffect (VisualEffect*& effect,
    VisualEffectInstance*& instance)
{
    PixelShader* pshader = new0 PixelShader("Wm5.BoundaryMixed2",
        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, "MaskSampler", Shader::ST_2D);
    pshader->SetSampler(1, "OffsetSampler", Shader::ST_2D);
    pshader->SetSampler(2, "StateSampler", Shader::ST_2D);
    pshader->SetTextureUnits(msBoundaryMixedPTextureUnits);
    pshader->SetPrograms(msBoundaryMixedPPrograms);

    mIP->CreateEffect(pshader, effect, instance);

    // Create the mask and offset textures.
    Texture2D* maskMixed = new0 Texture2D(Texture::TF_A32B32G32R32F,
        mIMaxP1, mJMaxP1, 1);
    Texture2D* offsetMixed = new0 Texture2D(Texture::TF_A32B32G32R32F,
        mIMaxP1, mJMaxP1, 1);

    Float4* mask = (Float4*)maskMixed->GetData(0);
    Float4* offset = (Float4*)offsetMixed->GetData(0);
    Float4 one(1.0f, 1.0f, 1.0f, 1.0f);
    Float4 zero(0.0f, 0.0f, 0.0f, 0.0f);
    Float4 xEdgeMask(0.0f, 1.0f, 0.0f, 0.0f);
    Float4 x0EdgeOffset(+mDx, 0.0f, 0.0f, 0.0f);
    Float4 x1EdgeOffset(-mDx, 0.0f, 0.0f, 0.0f);
    Float4 yEdgeMask(1.0f, 0.0f, 0.0f, 0.0f);
    Float4 y0EdgeOffset(0.0f, +mDy, 0.0f, 0.0f);
    Float4 y1EdgeOffset(0.0f, -mDy, 0.0f, 0.0f);
    int x, y;

    // Interior.
    for (y = 1; y < mJMax; ++y)
    {
        for (x = 1; x < mIMax; ++x)
        {
            mask[Index(x,y)] = one;
            offset[Index(x,y)] = zero;
        }
    }

    // Edge-interior.
    for (x = 1; x < mIMax; ++x)
    {
        mask[Index(x,0)] = yEdgeMask;
        offset[Index(x,0)] = y0EdgeOffset;
        mask[Index(x,mJMax)] = yEdgeMask;
        offset[Index(x,mJMax)] = y1EdgeOffset;
    }
    for (y = 1; y < mJMax; ++y)
    {
        mask[Index(0,y)] = xEdgeMask;
        offset[Index(0,y)] = x0EdgeOffset;
        mask[Index(mIMax,y)] = xEdgeMask;
        offset[Index(mIMax,y)] = x1EdgeOffset;
    }

    // Corners.
    mask[Index(0,0)] = zero;
    mask[Index(mIMax,0)] = zero;
    mask[Index(0,mJMax)] = zero;
    mask[Index(mIMax,mJMax)] = zero;
    offset[Index(0,0)] = zero;
    offset[Index(mIMax,0)] = zero;
    offset[Index(0,mJMax)] = zero;
    offset[Index(mIMax,mJMax)] = zero;

    instance->SetPixelTexture(0, "MaskSampler", maskMixed);
    instance->SetPixelTexture(0, "OffsetSampler", offsetMixed);
    instance->SetPixelTexture(0, "StateSampler",
        mIP->GetTarget(2)->GetColorTexture(0));

    mRenderer->Bind(maskMixed);
    mRenderer->Bind(offsetMixed);
}
//----------------------------------------------------------------------------
void ImageProcessing2::CreateBoundaryNeumannMaterial (Material*& material,
													MaterialInstance*& instance)
{
	// sampler2D OffsetSampler = sampler_state
	// {
	//    MinFilter = Nearest;
	//    MagFilter = Nearest;
	//    WrapS     = Clamp;
	//    WrapT     = Clamp;
	// };
	// sampler2D StateSampler = sampler_state
	// {
	//    MinFilter = Nearest;
	//    MagFilter = Nearest;
	//    WrapS     = Clamp;
	//    WrapT     = Clamp;
	// };
	// void p_BoundaryNeumann
	// (
	//     in float2 vertexTCoord : TEXCOORD0,
	//     out float4 pixelColor : COLOR
	// )
	// {
	//     float2 offset = tex2D(OffsetSampler, vertexTCoord).xy;
	//     float2 tc = float2(vertexTCoord.x + offset.x,
	//         vertexTCoord.y + offset.y);
	//     float4 state = tex2D(StateSampler, tc);
	//     pixelColor = state;
	// }

	PixelShader* pshader = new0 PixelShader("PX2.BoundaryNeumann2",
		1, 1, 0, 2, false);
	pshader->SetInput(0, "vertexTCoord", Shader::VT_FLOAT2,
		Shader::VS_TEXCOORD0);
	pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4,
		Shader::VS_COLOR0);
	pshader->SetSampler(0, "OffsetSampler", Shader::ST_2D);
	pshader->SetSampler(1, "StateSampler", Shader::ST_2D);
	pshader->SetTextureUnits(msNeumannPTextureUnits);
	pshader->SetPrograms(msNeumannPPrograms);

	CreateMaterial(pshader, material, instance);

	// 创建offset纹理
	Texture2D* offsetTexture = new0 Texture2D(Texture::TF_A32B32G32R32F,
		mBound0, mBound1, 1);

	Float4* offset = (Float4*)offsetTexture->GetData(0);
	Float4 zero(0.0f, 0.0f, 0.0f, 0.0f);
	Float4 x0EdgeOffset(+mDx, 0.0f, 0.0f, 0.0f);
	Float4 x1EdgeOffset(-mDx, 0.0f, 0.0f, 0.0f);
	Float4 y0EdgeOffset(0.0f, +mDy, 0.0f, 0.0f);
	Float4 y1EdgeOffset(0.0f, -mDy, 0.0f, 0.0f);
	int x, y;

	// 内部
	for (y = 1; y < mBound1M1; ++y)
	{
		for (x = 1; x < mBound0M1; ++x)
		{
			offset[Index(x,y)] = zero;
		}
	}

	// 边
	for (x = 1; x < mBound0M1; ++x)
	{
		offset[Index(x,0)] = y0EdgeOffset;
		offset[Index(x,mBound1M1)] = y1EdgeOffset;
	}
	for (y = 1; y < mBound1M1; ++y)
	{
		offset[Index(0,y)] = x0EdgeOffset;
		offset[Index(mBound0M1,y)] = x1EdgeOffset;
	}

	// 角
	offset[Index(0,0)] = Float4(+mDx, +mDy, 0.0f, 0.0f);
	offset[Index(mBound0M1,0)] = Float4(-mDx, +mDy, 0.0f, 0.0f);
	offset[Index(0,mBound1M1)] = Float4(+mDx, -mDy, 0.0f, 0.0f);
	offset[Index(mBound0M1,mBound1M1)] = Float4(-mDx, -mDy, 0.0f, 0.0f);

	instance->SetPixelTexture(0, "OffsetSampler", offsetTexture);
}
Ejemplo n.º 18
0
//----------------------------------------------------------------------------
VisualEffectInstance* GeodesicHeightField::CreateEffectInstance ()
{
	// Create the vertex shader.
	VertexShader* vshader = new0 VertexShader("Wm5.DLight2MatTex",
	                        3, 3, 16, 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, "modelTCoord", Shader::VT_FLOAT2,
	                  Shader::VS_TEXCOORD0);
	vshader->SetOutput(0, "clipPosition", Shader::VT_FLOAT4,
	                   Shader::VS_POSITION);
	vshader->SetOutput(1, "vertexColor", Shader::VT_FLOAT4,
	                   Shader::VS_COLOR0);
	vshader->SetOutput(2, "vertexTCoord", Shader::VT_FLOAT2,
	                   Shader::VS_TEXCOORD0);
	vshader->SetConstant( 0, "PVWMatrix", 4);
	vshader->SetConstant( 1, "CameraModelPosition", 1);
	vshader->SetConstant( 2, "MaterialEmissive", 1);
	vshader->SetConstant( 3, "MaterialAmbient", 1);
	vshader->SetConstant( 4, "MaterialDiffuse", 1);
	vshader->SetConstant( 5, "MaterialSpecular", 1);
	vshader->SetConstant( 6, "Light0ModelDirection", 1);
	vshader->SetConstant( 7, "Light0Ambient", 1);
	vshader->SetConstant( 8, "Light0Diffuse", 1);
	vshader->SetConstant( 9, "Light0Specular", 1);
	vshader->SetConstant(10, "Light0Attenuation", 1);
	vshader->SetConstant(11, "Light1ModelDirection", 1);
	vshader->SetConstant(12, "Light1Ambient", 1);
	vshader->SetConstant(13, "Light1Diffuse", 1);
	vshader->SetConstant(14, "Light1Specular", 1);
	vshader->SetConstant(15, "Light1Attenuation", 1);
	vshader->SetBaseRegisters(msVRegisters);
	vshader->SetPrograms(msVPrograms);

	// Create the pixel shader.
	PixelShader* pshader = new0 PixelShader("Wm5.DLight2MatTex",
	                                        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, Shader::SF_LINEAR /*_LINEAR */);
	pshader->SetCoordinate(0, 0, Shader::SC_CLAMP_EDGE);
	pshader->SetCoordinate(0, 1, Shader::SC_CLAMP_EDGE);
	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());

	// Create the effect.
	VisualTechnique* technique = new0 VisualTechnique();
	technique->InsertPass(pass);
	VisualEffect* effect = new0 VisualEffect();
	effect->InsertTechnique(technique);

	// Create the material for the effect.
	Float4 black(0.0f, 0.0f, 0.0f, 1.0f);
	Float4 white(1.0f, 1.0f, 1.0f, 1.0f);
	Material* material = new0 Material();
	material->Emissive = black;
	material->Ambient = Float4(0.24725f, 0.2245f, 0.0645f, 1.0f);
	material->Diffuse = Float4(0.34615f, 0.3143f, 0.0903f, 1.0f);
	material->Specular = Float4(0.797357f, 0.723991f, 0.208006f, 83.2f);

	// Create the lights for the effect.
	Light* light0 = new0 Light(Light::LT_DIRECTIONAL);
	light0->SetDirection(AVector(0.0f, 0.0f, -1.0f));
	light0->Ambient = white;
	light0->Diffuse = white;
	light0->Specular = black;

	Light* light1 = new0 Light(Light::LT_DIRECTIONAL);
	light1->SetDirection(AVector(0.0f, 0.0f, 1.0f));
	light1->Ambient = white;
	light1->Diffuse = white;
	light1->Specular = black;

	// Create a texture for the effect.
	mTexture = new0 Texture2D(Texture::TF_A8R8G8B8, 512, 512, 0);
	unsigned char* data = (unsigned char*)mTexture->GetData(0);
	memset(data, 0xFF, mTexture->GetNumLevelBytes(0));

	// Create an instance of the effect.
	VisualEffectInstance* instance = new0 VisualEffectInstance(effect, 0);
	instance->SetVertexConstant(0, 0,
	                            new0 PVWMatrixConstant());
	instance->SetVertexConstant(0, 1,
	                            new0 CameraModelPositionConstant());
	instance->SetVertexConstant(0, 2,
	                            new0 MaterialEmissiveConstant(material));
	instance->SetVertexConstant(0, 3,
	                            new0 MaterialAmbientConstant(material));
	instance->SetVertexConstant(0, 4,
	                            new0 MaterialDiffuseConstant(material));
	instance->SetVertexConstant(0, 5,
	                            new0 MaterialSpecularConstant(material));
	instance->SetVertexConstant(0, 6,
	                            new0 LightModelDVectorConstant(light0));
	instance->SetVertexConstant(0, 7,
	                            new0 LightAmbientConstant(light0));
	instance->SetVertexConstant(0, 8,
	                            new0 LightDiffuseConstant(light0));
	instance->SetVertexConstant(0, 9,
	                            new0 LightSpecularConstant(light0));
	instance->SetVertexConstant(0, 10,
	                            new0 LightAttenuationConstant(light0));
	instance->SetVertexConstant(0, 11,
	                            new0 LightModelDVectorConstant(light1));
	instance->SetVertexConstant(0, 12,
	                            new0 LightAmbientConstant(light1));
	instance->SetVertexConstant(0, 13,
	                            new0 LightDiffuseConstant(light1));
	instance->SetVertexConstant(0, 14,
	                            new0 LightSpecularConstant(light1));
	instance->SetVertexConstant(0, 15,
	                            new0 LightAttenuationConstant(light1));

	instance->SetPixelTexture(0, 0, mTexture);

	return instance;
}
//----------------------------------------------------------------------------
StandardESMaterial_AlphaTest::StandardESMaterial_AlphaTest ()
{
	VertexShader* vshader = new0 VertexShader("PX2.StandardESMaterial_AlphaTest",
		3, 3, 7, 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, "gLightAmbient", 1);
	vshader->SetConstant(5, "gLightDiffuse", 1);
	vshader->SetConstant(6, "gLightModelDirection", 1);
	vshader->SetBaseRegisters(msVRegisters);
	vshader->SetPrograms(msVPrograms);

	PixelShader* pshader = new0 PixelShader("PX2.StandardESMaterial_AlphaTest",
		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_CLAMP);
	pshader->SetCoordinate(0, 1, Shader::SC_CLAMP);
	pshader->SetTextureUnits(msPTextureUnits);
	pshader->SetPrograms(msPPrograms);

	vshader->SetShaderKey(SKT_STANNDES_ALPHATEST);
	pshader->SetShaderKey(SKT_STANNDES_ALPHATEST);

	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()->CompareEnabled = true;
	pass->GetAlphaProperty()->Compare = PX2::AlphaProperty::CM_GREATER;
	pass->GetAlphaProperty()->Reference = 0.25f;

	MaterialTechnique* technique = new0 MaterialTechnique();
	technique->InsertPass(pass);
	InsertTechnique(technique);
}