FC Sample 03

cbuffer VSConsts: register(b0)
{
  float4x4 MVPMatrix;

  float3 P1;
  float Divi1;
  float3 P2;
  float Divi2;
  float3 P3;
  float Divi3;
  float3 P4;
  float Divi4;

  float4 ParamL;
  float4 ParamK;
  float4 OptioM;
  float4 TE;

  float4 MP01;
  float4 MP02;
  float4 MP03;
  float4 MP04;
}

struct VSInput
{
  float3 Pos: POSITION;
};

struct VSOutput
{
  float4 Pos: SV_POSITION;
  float2 Tex: TEXCOORD;
};
//vs-calc.begin;

float sqr(float x) { return x * x; }

float Force(float k, float l, float l0, int m)
{
  float result;
  if (Divi4 == 1.0)
    result = k * (l - l0);
  else
    result = k * sqr(l - l0) / 50;
  if (m == 1) result = max(result, 0);
  if (m == 2) result = min(result, 0);
  return result;
}

float Calc(float x, float y, int Plot)
{
//Calc3XX
  float3 p = float3(x, y, 0.0f);
  const float Epsilon = 0.0001f;

  float3 p1 = P1.xyz;
  float3 p2 = P2.xyz;
  float3 p3 = P3.xyz;

  float4 l = ParamL;
  float4 k = ParamK;
  int3 m;
  m.x = OptioM.x;
  m.y = OptioM.y;
  m.z = OptioM.z;

  float3 Offset = MP01.xyz;
  float FaktorEQ = MP01.w;

  bool SolutionMode = MP03.x;
  bool WantGleich = MP03.y;
  bool Vorzeichen = MP03.z;

  float3 t;
  t.x = length(p-p1);
  t.y = length(p-p2);
  t.z = length(p-p3);

  float3 b;
  float3 f;
  float3 u;
  float3 v;
  float su;
  float sv;
  if (SolutionMode) {
    b.x = t.y * t.z * (t.x-l.x) * k.x;
    b.y = t.x * t.z * (t.y-l.y) * k.y;
    b.z = t.x * t.y * (t.z-l.z) * k.z;

    u.x = b.x * (x-p1.x);
    u.y = b.y * (x-p2.x);
    u.z = b.z * (x-p3.x);

    v.x = b.x * (y-p1.y);
    v.y = b.y * (y-p2.y);
    v.z = b.z * (y-p3.y);

    su = u.x + u.y + u.z;
    sv = v.x + v.y + v.z;
  }
  else {
    if (t.x > Epsilon && t.y > Epsilon && t.z > Epsilon)
    {
      f.x = Force(k.x, t.x, l.x, m.x);
      f.y = Force(k.y, t.y, l.y, m.y);
      f.z = Force(k.z, t.z, l.z, m.z);

      u.x = f.x * (x-p1.x) / t.x;
      u.y = f.y * (x-p2.x) / t.y;
      u.z = f.z * (x-p3.x) / t.z;

      v.x = f.x * (y-p1.y) / t.x;
      v.y = f.y * (y-p2.y) / t.y;
      v.z = f.z * (y-p3.y) / t.z;

      su = (u.x + u.y + u.z) * 100000;
      sv = (v.x + v.y + v.z) * 100000;
    }
    else
    {
      switch (Plot) {
        case 11:
          su = k.x * l.x * 1.5 * 100000;
          sv = 0;
          break;
        default:
          su = 0;
          sv = 0;
          break;
      }
    }
  }
  float g7 = 0;
  switch (Plot) {
    case  0: g7 = sv; break;
    case  1:
    if (SolutionMode)
             g7 = (b.x + b.y + b.z) * 20;
      else
             g7 = (f.x + f.y + f.z) * 100000;
      break;
    case  2: g7 = sqrt(sqr(su) + sqr(sv)) + 5; break;
    case  3: g7 = su + sv; break;
//  case  4: Amount
    case  5: g7 = abs(su + sv); break;
//  case  6: g7 = Richtung; break;
    case  7: g7 = abs(sv); break;
//  case  8: Energy
    case  9: g7 = su; break;
    case 10: g7 = abs(su); break;
    case 11: g7 = abs(su) + abs(sv); break;
  }
  return g7;
}

float3 CalcEG(float3 q, float yin)
{
  float eggx = TE.z;
  float eggz = TE.w;
  float3 p = float3(q.x, q.y, q.z);
  float lpxy = length(p.xy);
  float r = lpxy / MP02.w;
  float pz = MP02.w * sqrt(1.0 - r * r);

  //Flat Mesh
  if (Divi3 == 1.0) p.z = Divi2;

  //Dia Mesh
  if (Divi3 == 2.0) p.z = Divi1 * lpxy;

  //Kegel Mesh
  if (Divi3 == 3.0) p.z = Divi1 * (MP02.w - lpxy);

  //Kugel Mesh
  if (Divi3 == 4.0) {
    p.z = MP02.w * sqrt(1.0 - r * r);
    p.z = Divi1 * max(p.z, 0.0);
  }

  //Egg Mesh
  if (Divi3 == 5.0) {
    float fx1 = (64 + eggx) / 100;
    float fx2 = (14 + eggz) / 100 * yin;
    float fx = fx1 + fx2;
    float fz = fx;
    p.x = fx * p.x;
    p.z = pz;
    p.z = Divi1 * fz * max(p.z, 0.0);
  }

  //Eli Mesh
  if (Divi3 == 6.0) {
    float fx = (64 + eggx) / 100;
    float fz = fx;
    p.x = fx * p.x;
    p.z = pz;
    p.z = Divi1 * fz * max(p.z, 0.0);
  }

  //Soap Mesh
  if (Divi3 == 7.0) {
    float fx = (74 + eggx) / 100;
    float fz = (29 + eggz) / 100;
    p.x = fx * p.x;
    p.z = pz;
    p.z = Divi1 * fz * max(p.z, 0.0);
  }

  return p;
}

//vs-calc.end;
VSOutput VSMain(VSInput input)
{
  VSOutput o;
  float OffsetX = MP01.x;
  float OffsetY = MP01.y;
  float OffsetZ = MP01.z;
  float RangeX = MP02.w;
  float RangeY = MP03.w;

  int Scene = max(MP02.x, 0);
  int Plot = max(MP02.y, 0);
  int PlotFigure = max(MP02.z, 0);

  bool PlusCap = MP04.x;
  bool MinusCap = MP04.y;
  float pcap = MP04.z;
  float fcap = MP04.w;

  float mcap = -pcap;
  fcap = max(fcap, 1);

  float x, y, z;
  x = RangeX * input.Pos.x + OffsetX;
  y = RangeY * input.Pos.y + OffsetY;
  z = Calc(x, y, Plot);

  z = z / fcap - OffsetZ;
  if (PlusCap && z > pcap) z = pcap;
  if (MinusCap && z < mcap) z = mcap;

  float4 p = float4(x, y, z, 1.0);

  float te1 = TE.x;
  float te2 = TE.y;

  o.Tex.x = (input.Pos.x + te1) / te2;
  o.Tex.y = (z + te1) / te2;

  float3 q = CalcEG(p.xyz, input.Pos.y);
  p.x = q.x;
  p.y = q.y;
  p.z = q.z;

  o.Pos = mul(MVPMatrix, p);
  return o;
};
//model.begin;
Version := 2;
x1 := -0.11;
x2 := -285.89;
x3 := -143;
x4 := -215.680595397949;
y1 := 0.5;
y2 := 0.5;
y3 := -247;
y4 := -99.6502532958984;
l1 := 191;
l2 := 191;
l3 := 191;
l4 := 191;
k1 := 3;
k2 := 3;
k3 := 3;
k4 := 3;
Gain := 83;
Range := 80;
Plot := 10;
Figure := 2;
Param := 32;
Bitmap := 10;
AngleX := 118.51;
AngleY := 11.05;
AngleZ := 178.53;
PosZ := 4.21;
T1 := 3;
T2 := 85;
ShowCylinder := False;
ShowDiameter := False;
OrthoZoom := 0.58;
Lux := True;
Lux1 := True;
//model.end;

//color.begin;
BlindColorCount := 1;
StripWidth := 1;
BandWidth := 11;
StandardColor := 10;
WantContour := True;
WantShirtColor := False;
SquareBitmap := False;
HorizontalBitmap := False;
SquareSym := False;
RandomPaint := False;
StandardPaint := False;
MonoPaint := True;

//BandInfo := Width-R-G-B;
Bands[0] := '001-000-000-000';
Bands[1] := '011-250-250-255';
Bands[2] := '011-245-245-255';
Bands[3] := '011-240-240-255';
Bands[4] := '011-235-235-255';
Bands[5] := '011-230-230-255';
Bands[6] := '011-225-225-255';
Bands[7] := '011-220-220-255';
Bands[8] := '011-215-215-255';
Bands[9] := '011-210-210-255';
Bands[10] := '011-205-205-255';
Bands[11] := '011-200-200-255';
Bands[12] := '011-195-195-255';
Bands[13] := '011-190-190-255';
Bands[14] := '011-185-185-255';
Bands[15] := '011-180-180-255';
Bands[16] := '011-175-175-255';
Bands[17] := '011-170-170-255';
Bands[18] := '011-165-165-255';
Bands[19] := '011-160-160-255';
Bands[20] := '011-155-155-255';
Bands[21] := '011-150-150-255';
Bands[22] := '011-145-145-255';
Bands[23] := '011-140-140-255';
Bands[24] := '011-135-135-255';
Bands[25] := '011-130-130-255';
Bands[26] := '011-125-125-255';
Bands[27] := '011-120-120-255';
Bands[28] := '011-115-115-255';
Bands[29] := '011-110-110-255';
Bands[30] := '011-105-105-255';
Bands[31] := '011-100-100-255';
Bands[32] := '011-095-095-255';
Bands[33] := '011-090-090-255';
Bands[34] := '011-085-085-255';
Bands[35] := '255-051-051-051';
//color.end;