//---------------------------------------------------------------------------- VisualEffectInstance* SimpleBumpMapEffect::CreateInstance ( Texture2D* baseTexture, Texture2D* normalTexture) { VisualEffectInstance* instance = new0 VisualEffectInstance(this, 0); instance->SetVertexConstant(0, 0, new0 PVWMatrixConstant()); instance->SetPixelTexture(0, 0, baseTexture); instance->SetPixelTexture(0, 1, normalTexture); return instance; }
//---------------------------------------------------------------------------- VisualEffectInstance* BlendedTerrainEffect::CreateInstance ( ShaderFloat* flowDirection, ShaderFloat* powerFactor, Texture2D* grassTexture, Texture2D* stoneTexture, Texture2D* cloudTexture) { VisualEffectInstance* instance = new0 VisualEffectInstance(this, 0); instance->SetVertexConstant(0, 0, new0 PVWMatrixConstant()); instance->SetVertexConstant(0, 1, flowDirection); instance->SetPixelConstant(0, 0, powerFactor); instance->SetPixelTexture(0, 0, grassTexture); instance->SetPixelTexture(0, 1, stoneTexture); instance->SetPixelTexture(0, 2, mBlendTexture); instance->SetPixelTexture(0, 3, cloudTexture); return instance; }
//---------------------------------------------------------------------------- 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; }
//---------------------------------------------------------------------------- VisualEffectInstance* VolumeFogEffect::CreateInstance (Texture2D* baseTexture) { VisualEffectInstance* instance = new0 VisualEffectInstance(this, 0); instance->SetVertexConstant(0, 0, new0 PVWMatrixConstant()); instance->SetPixelTexture(0, 0, baseTexture); return instance; }
//---------------------------------------------------------------------------- VisualEffectInstance* MRTEffect::CreateInstance (Texture2D* texture0, Texture2D* texture1) { VisualEffectInstance* instance = new0 VisualEffectInstance(this, 0); instance->SetVertexConstant(0, 0, new0 PVWMatrixConstant()); instance->SetPixelTexture(0, 0, texture0); instance->SetPixelTexture(0, 1, texture1); return instance; }
//---------------------------------------------------------------------------- VisualEffectInstance* SphereMapEffect::CreateInstance ( Texture2D* environmentTexture) { VisualEffectInstance* instance = new0 VisualEffectInstance(this, 0); instance->SetVertexConstant(0, 0, new0 PVWMatrixConstant()); instance->SetVertexConstant(0, 1, new0 VWMatrixConstant()); instance->SetPixelTexture(0, 0, environmentTexture); return instance; }
//---------------------------------------------------------------------------- VisualEffectInstance* SMBlurEffect::CreateInstance (ShaderFloat* weights, ShaderFloat* offsets, Texture2D* baseTexture) const { VisualEffectInstance* instance = new0 VisualEffectInstance(this, 0); instance->SetVertexConstant(0, 0, new0 PVWMatrixConstant()); instance->SetPixelConstant(0, 0, weights); instance->SetPixelConstant(0, 1, offsets); instance->SetPixelTexture(0, 0, baseTexture); return instance; }
//---------------------------------------------------------------------------- VisualEffectInstance* SMSceneEffect::CreateInstance ( ProjectorWorldPositionConstant* lightWorldPosition, ProjectorMatrixConstant* lightPVMatrix, ShaderFloat* lightBSMatrix, ShaderFloat* screenBSMatrix, ShaderFloat* lightColor, Texture2D* baseTexture, Texture2D* blurTexture, Texture2D* projectedTexture) const { VisualEffectInstance* instance = new0 VisualEffectInstance(this, 0); instance->SetVertexConstant(0, 0, new0 PVWMatrixConstant()); instance->SetVertexConstant(0, 1, new0 WMatrixConstant()); instance->SetVertexConstant(0, 2, lightPVMatrix); instance->SetVertexConstant(0, 3, lightBSMatrix); instance->SetVertexConstant(0, 4, screenBSMatrix); instance->SetVertexConstant(0, 5, lightWorldPosition); instance->SetVertexConstant(0, 6, new0 CameraWorldPositionConstant()); instance->SetPixelConstant(0, 0, lightColor); instance->SetPixelTexture(0, 0, baseTexture); instance->SetPixelTexture(0, 1, blurTexture); instance->SetPixelTexture(0, 2, projectedTexture); return instance; }
//---------------------------------------------------------------------------- VisualEffectInstance* Texture3DEffect::CreateInstance (Texture3D* texture) const { VisualEffectInstance* instance = new0 VisualEffectInstance(this, 0); instance->SetVertexConstant(0, 0, new0 PVWMatrixConstant()); instance->SetPixelTexture(0, 0, texture); Shader::SamplerFilter filter = GetPixelShader()->GetFilter(0); if (filter != Shader::SF_NEAREST && filter != Shader::SF_LINEAR && !texture->HasMipmaps()) { texture->GenerateMipmaps(); } return instance; }
//---------------------------------------------------------------------------- VisualEffectInstance* DLitMatTexEffect::CreateInstance ( Light* directionalLight, Material* material, Texture2D* diffuseTexture) { VisualEffectInstance* instance = new0 VisualEffectInstance(this, 0); instance->SetVertexConstant(0, 0, new0 PVWMatrixConstant()); instance->SetPixelConstant(0, 0, new0 CameraModelPositionConstant()); instance->SetPixelConstant(0, 1, new0 MaterialAmbientConstant(material)); instance->SetPixelConstant(0, 2, new0 MaterialSpecularConstant(material)); instance->SetPixelConstant(0, 3, new0 LightModelDVectorConstant(directionalLight)); instance->SetPixelConstant(0, 4, new0 LightAmbientConstant(directionalLight)); instance->SetPixelTexture(0, 0, diffuseTexture); return instance; }
//---------------------------------------------------------------------------- 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; }
//---------------------------------------------------------------------------- void GpuGaussianBlur3::SetBlurInput () { VisualEffectInstance* instance = mIP->GetMainEffectInstance(); int bound0M1 = mIP->GetBound0() - 1; int bound1M1 = mIP->GetBound1() - 1; int bound2M1 = mIP->GetBound2() - 1; float dCol = mIP->GetColSpacing(); float dRow = mIP->GetRowSpacing(); ShaderFloat* deltaConstant = new0 ShaderFloat(1); float* delta = deltaConstant->GetData(); delta[0] = dCol; delta[1] = 0.0f; delta[2] = 0.0f; delta[3] = dRow; instance->SetPixelConstant(0, "Delta", deltaConstant); ShaderFloat* weightConstant = new0 ShaderFloat(1); float* weight = weightConstant->GetData(); weight[0] = 0.01f; // = kappa*DeltaT/DeltaX^2 weight[1] = 0.01f; // = kappa*DeltaT/DeltaY^2 weight[2] = 0.01f; // = kappa*DeltaT/DeltaZ^2 weight[3] = 1.0f - 2.0f*(weight[0] + weight[1] + weight[2]); // w[3] > 0 instance->SetPixelConstant(0, "Weight", weightConstant); Texture2D* offsetTexture = new Texture2D(Texture::TF_A32B32G32R32F, 1024, 1024, 1); Float4* offset = (Float4*)offsetTexture->GetData(0); memset(offset, 0, 1024*1024*sizeof(Float4)); // Interior voxels. The offsets at the boundary are all zero, so the // finite differences are incorrect at those locations. However, the // boundary effect will overwrite those voxels, so it is irrelevant // about the finite difference approximations at those locations. for (int z = 1; z < bound2M1; ++z) { for (int y = 1; y < bound1M1; ++y) { for (int x = 1; x < bound0M1; ++x) { // Get the 2D location of the voxel. int u, v; mIP->Map3Dto2D(x, y, z, u, v); // Get the 2D location of the z+ neighbor. int upos, vpos; mIP->Map3Dto2D(x, y, z+1, upos, vpos); // Get the 2D location of the z- neighbor. int uneg, vneg; mIP->Map3Dto2D(x, y, z-1, uneg, vneg); Float4& color = offset[mIP->Index(u, v)]; color[0] = (upos - u)*dCol; color[1] = (vpos - v)*dRow; color[2] = (uneg - u)*dCol; color[3] = (vneg - v)*dRow; } } } instance->SetPixelTexture(0, "OffsetSampler", offsetTexture); }