cellshading_fp.cg

来自「delphi 最好的3D控件GLScene_Demos」· CG 代码 · 共 45 行

CG
45
字号
// Data structure passed from the vertex program to the fragement
// program
struct vert2frag
{
  float4 HPosition : POSITION;
  float3 TexCoord : TEXCOORD0;
};

// Output from the fragment program
struct fragoutput
{
  float4 Color : COLOR;
};

// Main fragment processing
fragoutput main(
  vert2frag IN,
  uniform sampler2D Map0)
{
  // Declare the frament program output
  fragoutput OUT;

  // Read the intensity from the 3rd element of the texture coordinate
  float i = IN.TexCoord.z;

  // Clamp intensities to specific values based on intensity range.
  // Change or add to these ranges to effect the cells
  if (i >0.9) { i = 1.0; } 
  else if (i >0.6) { i = 0.9; } 
  else if (i >0.2) { i = 0.6; } 
  else { i = 0.0; }

  // Get the color from the texture map using the input texture 
  // coordinate and assign to the output color
  OUT.Color.rgb = f3tex2D(Map0, IN.TexCoord);

  // Multiply output by the clamped intensity value
  OUT.Color.rgb *= i;

  OUT.Color.a = 1.0;

  // Return the fragment processing result
  return OUT;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?