1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
// Geometric Tools, LLC
// Copyright (c) 1998-2014
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
//
// File Version: 5.0.0 (2010/01/01)
#include "Wm5GraphicsPCH.h"
#include "Wm5Texture2ColorBlendEffect.h"
#include "Wm5PVWMatrixConstant.h"
using namespace Wm5;
WM5_IMPLEMENT_RTTI(Wm5, VisualEffect, Texture2ColorBlendEffect);
WM5_IMPLEMENT_STREAM(Texture2ColorBlendEffect);
WM5_IMPLEMENT_FACTORY(Texture2ColorBlendEffect);
WM5_IMPLEMENT_DEFAULT_NAMES(VisualEffect, Texture2ColorBlendEffect);
//----------------------------------------------------------------------------
Texture2ColorBlendEffect::Texture2ColorBlendEffect ()
{
VertexShader* vshader = new0 VertexShader("Wm5.Texture2ColorBlend",
3, 3, 1, 0, false);
vshader->SetInput(0, "modelPosition", Shader::VT_FLOAT3,
Shader::VS_POSITION);
vshader->SetInput(1, "modelTCoord0", Shader::VT_FLOAT2,
Shader::VS_TEXCOORD0);
vshader->SetInput(2, "modelTCoord1", Shader::VT_FLOAT2,
Shader::VS_TEXCOORD1);
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_FLOAT2,
Shader::VS_TEXCOORD1);
vshader->SetConstant(0, "PVWMatrix", 4);
vshader->SetBaseRegisters(msVRegisters);
vshader->SetPrograms(msVPrograms);
PixelShader* pshader = new0 PixelShader("Wm5.Texture2ColorBlend",
2, 1, 0, 2, false);
pshader->SetInput(0, "vertexTCoord0", Shader::VT_FLOAT2,
Shader::VS_TEXCOORD0);
pshader->SetInput(1, "vertexTCoord1", Shader::VT_FLOAT2,
Shader::VS_TEXCOORD1);
pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4,
Shader::VS_COLOR0);
pshader->SetSampler(0, "Sampler0", Shader::ST_2D);
pshader->SetSampler(1, "Sampler1", Shader::ST_2D);
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);
}
//----------------------------------------------------------------------------
Texture2ColorBlendEffect::~Texture2ColorBlendEffect ()
{
}
//----------------------------------------------------------------------------
PixelShader* Texture2ColorBlendEffect::GetPixelShader () const
{
return mTechniques[0]->GetPass(0)->GetPixelShader();
}
//----------------------------------------------------------------------------
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* 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);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Streaming support.
//----------------------------------------------------------------------------
Texture2ColorBlendEffect::Texture2ColorBlendEffect (LoadConstructor value)
:
VisualEffect(value)
{
}
//----------------------------------------------------------------------------
void Texture2ColorBlendEffect::Load (InStream& source)
{
WM5_BEGIN_DEBUG_STREAM_LOAD(source);
VisualEffect::Load(source);
WM5_END_DEBUG_STREAM_LOAD(Texture2ColorBlendEffect, source);
}
//----------------------------------------------------------------------------
void Texture2ColorBlendEffect::Link (InStream& source)
{
VisualEffect::Link(source);
}
//----------------------------------------------------------------------------
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);
}
//----------------------------------------------------------------------------
bool Texture2ColorBlendEffect::Register (OutStream& target) const
{
return VisualEffect::Register(target);
}
//----------------------------------------------------------------------------
void Texture2ColorBlendEffect::Save (OutStream& target) const
{
WM5_BEGIN_DEBUG_STREAM_SAVE(target);
VisualEffect::Save(target);
WM5_END_DEBUG_STREAM_SAVE(Texture2ColorBlendEffect, target);
}
//----------------------------------------------------------------------------
int Texture2ColorBlendEffect::GetStreamingSize () const
{
return VisualEffect::GetStreamingSize();
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Profiles.
//----------------------------------------------------------------------------
int Texture2ColorBlendEffect::msDx9VRegisters[1] = { 0 };
int Texture2ColorBlendEffect::msOglVRegisters[1] = { 1 };
int* Texture2ColorBlendEffect::msVRegisters[Shader::MAX_PROFILES] =
{
0,
msDx9VRegisters,
msDx9VRegisters,
msDx9VRegisters,
msOglVRegisters
};
std::string Texture2ColorBlendEffect::msVPrograms[Shader::MAX_PROFILES] =
{
// VP_NONE
"",
// VP_VS_1_1
"vs_1_1\n"
"def c4, 1.00000000, 0, 0, 0\n"
"dcl_position0 v0\n"
"dcl_texcoord0 v1\n"
"dcl_texcoord1 v2\n"
"mov r0.w, c4.x\n"
"mov r0.xyz, v0\n"
"dp4 oPos.w, r0, c3\n"
"dp4 oPos.z, r0, c2\n"
"dp4 oPos.y, r0, c1\n"
"dp4 oPos.x, r0, c0\n"
"mov oT0.xy, v1\n"
"mov oT1.xy, v2\n",
// VP_VS_2_0
"vs_2_0\n"
"def c4, 1.00000000, 0, 0, 0\n"
"dcl_position v0\n"
"dcl_texcoord0 v1\n"
"dcl_texcoord1 v2\n"
"mov r0.w, c4.x\n"
"mov r0.xyz, v0\n"
"dp4 oPos.w, r0, c3\n"
"dp4 oPos.z, r0, c2\n"
"dp4 oPos.y, r0, c1\n"
"dp4 oPos.x, r0, c0\n"
"mov oT0.xy, v1\n"
"mov oT1.xy, v2\n",
// VP_VS_3_0
"vs_3_0\n"
"dcl_position o0\n"
"dcl_texcoord0 o1\n"
"dcl_texcoord1 o2\n"
"def c4, 1.00000000, 0, 0, 0\n"
"dcl_position0 v0\n"
"dcl_texcoord0 v1\n"
"dcl_texcoord1 v2\n"
"mov r0.w, c4.x\n"
"mov r0.xyz, v0\n"
"dp4 o0.w, r0, c3\n"
"dp4 o0.z, r0, c2\n"
"dp4 o0.y, r0, c1\n"
"dp4 o0.x, r0, c0\n"
"mov o1.xy, v1\n"
"mov o2.xy, v2\n",
// VP_ARBVP1
"!!ARBvp1.0\n"
"PARAM c[5] = { { 1 }, program.local[1..4] };\n"
"TEMP R0;\n"
"MOV R0.w, c[0].x;\n"
"MOV R0.xyz, vertex.position;\n"
"DP4 result.position.w, R0, c[4];\n"
"DP4 result.position.z, R0, c[3];\n"
"DP4 result.position.y, R0, c[2];\n"
"DP4 result.position.x, R0, c[1];\n"
"MOV result.texcoord[0].xy, vertex.texcoord[0];\n"
"MOV result.texcoord[1].xy, vertex.texcoord[1];\n"
"END\n"
};
int Texture2ColorBlendEffect::msAllPTextureUnits[2] = { 0, 1 };
int* Texture2ColorBlendEffect::msPTextureUnits[Shader::MAX_PROFILES] =
{
0,
msAllPTextureUnits,
msAllPTextureUnits,
msAllPTextureUnits,
msAllPTextureUnits
};
std::string Texture2ColorBlendEffect::msPPrograms[Shader::MAX_PROFILES] =
{
// PP_NONE
"",
// PP_PS_1_1
"ps.1.1\n"
"tex t0\n"
"tex t1\n"
"mov_sat r0, t0\n"
"mad r0, 1-r0, t1, t0\n",
// PP_PS_2_0
"ps_2_0\n"
"dcl_2d s0\n"
"dcl_2d s1\n"
"def c0, 1.00000000, 0, 0, 0\n"
"dcl t0.xy\n"
"dcl t1.xy\n"
"texld r1, t0, s0\n"
"texld r0, t1, s1\n"
"add r2, -r1, c0.x\n"
"mad r0, r2, r0, r1\n"
"mov oC0, r0\n",
// PP_PS_3_0
"ps_3_0\n"
"dcl_2d s0\n"
"dcl_2d s1\n"
"def c0, 1.00000000, 0, 0, 0\n"
"dcl_texcoord0 v0.xy\n"
"dcl_texcoord1 v1.xy\n"
"texld r0, v0, s0\n"
"texld r1, v1, s1\n"
"add r2, -r0, c0.x\n"
"mad oC0, r2, r1, r0\n",
// PP_ARBFP1
"!!ARBfp1.0\n"
"PARAM c[1] = { { 1 } };\n"
"TEMP R0;\n"
"TEMP R1;\n"
"TEMP R2;\n"
"TEX R0, fragment.texcoord[0], texture[0], 2D;\n"
"TEX R1, fragment.texcoord[1], texture[1], 2D;\n"
"ADD R2, -R0, c[0].x;\n"
"MAD result.color, R2, R1, R0;\n"
"END\n"
};
//----------------------------------------------------------------------------
|