⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d3dfixedfuncshaders.fx

📁 proe5.0野火版下载(中文版免费下载)
💻 FX
📖 第 1 页 / 共 5 页
字号:
  /* bank 13 */      { 0x88888888, 0x00000000, 0x22222222, 0x00000000 },  /* bank 14 - almost completely transparent */      { 0x88888888, 0x00000000, 0x00000000, 0x00000000 }  };#if 0Considerations for naming of Techniques, Vertex Shaders, Pixel Shaders, andShader Output StructuresTechnique names start with Tristrip_ or Polyline_ and generally describe whatcategories of computations are handled by vertex shaders and what categoriesare handled by pixel shaders.Names are short and employ a small set of letter encriptions that indicate whatcomputations are handled by the vertex and pixel shaders.To promote maximum flexibility in forming new techniques using existing vertexand pixel shaders, do not want the name of the vertex shader to indicate whichspecific pixel shader is used downstream and do not want the name of the pixelshader to indicate which specific vertex shader is used upstream.Vertex shader makes no contribution in handling of default color (F).Pixel shaders used for surfaces have _s appended to name and cannot be used forlines or points because of optional surface processing that might need to be nvoked.Currently, lit material is always involved in forming the base color of asurface when a lit texture is employed.If front and back face of a surface are both needed and if single surfacecolors differ for front and back face or if the set of vertex colors differsfor front and back face, PGL sets up two separate face passes with back facedone first.Only material properties can differ between front and back face and still bescheduled by PGL for processing in just one pass that handles both faces.This is brought about because of the limitations of the OpenGL pipeline priorto shader use.Abbreviated symbols used in names of techniques, names of vertex shaders, namesof pixel shaders, and in names of structures that transmit data from vertexshader to pixel shader:    VS  denotes vertex shader;    PS  denotes pixel shader;    eP  denotes position expressed in eye space and appears in names of        structures that transmit data from vertex shader to pixel shader;    eN  denotes normal expressed in eye space and appears in names of        structures that transmit data from vertex shader to pixel shader;    F   denotes fixed color (delivered in the DefaultColor variable) and        appears in names of techniques and in names of vertex shaders or pixel        shaders (depending on where it is actually handled);    fC  denotes color of front face and appears in names of pixel shaders and        in names of structures that transmit data from vertex shader to pixel        shader;    bC  denotes color of back face and appears in names of pixel shaders and in        names of structures that transmit data from vertex shader to pixel        shader;    C   denotes color that will vary over line or surface and appears in        names of techniques and in names of vertex shaders and in names of        pixel shaders and in names of structures that transmit data from vertex        shader to pixel shader;    iC  denotes color that will vary over polyline vertices but stays constant        over edges between vertices and appears in names of techniques and in        names of vertex shaders and in names of pixel shaders and in names of        structures that transmit data from vertex shader to pixel shader;    M   denotes material properties (that deliver lighting parameters) and        appears in names of techniques and in names of vertex shaders and in        names of pixel shaders;    L   denotes lighting calculation and appears in names of techniques and in        names of vertex shaders and in names of pixel shaders;    P   denotes position expressed in clip space and appears in names of        structures that transmit data from vertex shader to pixel shader;    T   denotes texturing calculation and appears in names of techniques and in        names of vertex shaders and in names of pixel shaders and in names of        structures that transmit data from vertex shader to pixel shader;    _mp denotes multi-pass for texturing and appears in names of techniques and        in names of pixel shaders;    _sp denotes single-pass for texturing (all texturing steps handled in one        call to pixel shader) and appears in names of techniques and in names        of pixel shaders;    _s  denotes surface (pixel shaders for surfaces cannot be used for lines)        and appears only in names of pixel shaders;#endif#if 0COORDINATE VALUES (x,y,d,w) DELIVERED BY PIPELINE TO PIXEL SHADERSw always has value of 1.0 if there is no perspective.w can have values larger than 1.0 if there is perspective.x, y, and d components of position arrive at pixel shader already having beendivided by w.x always has fractional value of .5 and increases in value as proceed rightwardfrom 0.5 at left edge of window.y always has fractional value of .5 and increases in value as proceed downwardfrom 0.5 at top edge of window.d always occupies [0.0, 1.0].Above indicates that floor () intrinsic function should be used to computeinteger pixel coordinates (simple truncation will work for positive numbers).#endif// INTERNAL FUNCTIONS#if 0/* Attenuation not currently used by PGL */float attenuation (float3 P, _pgl_d3d_light light){  float d = distance (P, light.position);  return (1/(light.kC + light.kL*d + light.kQ*d*d));}#endiffloat dualConeSpotlight (float3 P, _pgl_d3d_light light){  float3 V = normalize (P - light.position);  float cos_direction = dot (V, light.direction);#if 1/* TODO - This works OK for pixel shader */  return (smoothstep (light.cos_outer_cone, 1.0 /* light.cos_inner_cone */,           cos_direction));  return (smoothstep (light.cos_outer_cone, 1.0 /* light.cos_inner_cone */,           cos_direction));/* TODO - This is necessary for vertex shader in order to see color */  return (13*smoothstep (light.cos_outer_cone, 1.0 /* light.cos_inner_cone */,           cos_direction));#else// explicit smoothstep algorithm  if (cos_direction < light.cos_outer_cone)  {      return (0.0);  }  else if (1.0 /* light.cos_inner_cone */ <= cos_direction)  {      return (1.0);  }  else  {      float x = (cos_direction-light.cos_outer_cone)/          (1.0 /* light.cos_inner_cone */ -light.cos_outer_cone);      return (x*x*(3-2*x));  }#endif}void spotAttenuatedLighting (_pgl_d3d_light light, float3 P, float3 N,         float3 eye, int faces,         float power_front,         float power_back,         out float3 diffuse_color_front,         out float3 diffuse_color_back,         out float3 specular_color_front,         out float3 specular_color_back){  // Compute direction at P that is opposite to direction of light travel   float3 L = normalize (light.position - P);  // cosine of angle between normal and direction to light source  float NdotL = dot (N, L);  float normal_facing_factor;  if (faces & FRONT_FACE)  {      normal_facing_factor = max (NdotL, 0);      if (normal_facing_factor <= 0)      {          specular_color_front = diffuse_color_front = float3 (0,0,0);      }      else      {#if 0          // Compute attenuation with distance          float attenuation_factor;          if (light.range != 0)          {              attenuation_factor = attenuation (P, light);          }          else          {              attenuation_factor = 1.0;          }          if (attenuation_factor == 0)          {              specular_color_front = diffuse_color_front = float3 (0,0,0);          }          else#endif          {              // Compute spotlight angle fade effect              float spot_angle_factor = dualConeSpotlight (P, light);              if (spot_angle_factor == 0)              {                  specular_color_front = diffuse_color_front = float3 (0,0,0);              }              else              {                  // Compute diffuse contribution                  diffuse_color_front = /* attenuation_factor * */                      spot_angle_factor *                      normal_facing_factor * light.color;                  // Compute specular contribution                  float3 V = normalize (eye - P);                  float3 H = normalize (L + V);                  float specular_facing_factor =                      pow (max (dot (N, H), 0), power_front);                  specular_color_front = /* attenuation_factor * */                      spot_angle_factor * specular_facing_factor *                      light.color_specular;              }          }      }  }  if (faces & BACK_FACE)  {      normal_facing_factor = max (-NdotL, 0);      if (normal_facing_factor <= 0)      {          specular_color_back = diffuse_color_back = float3 (0,0,0);      }      else      {#if 0          // Compute attenuation with distance          float attenuation_factor;          if (light.range != 0)          {              attenuation_factor = attenuation (P, light);          }          else          {              attenuation_factor = 1.0;          }          if (attenuation_factor == 0)          {              specular_color_back = diffuse_color_back = float3 (0,0,0);          }          else#endif          {              // Compute spotlight angle fade effect              float spot_angle_factor = dualConeSpotlight (P, light);              if (spot_angle_factor == 0)              {                  specular_color_back = diffuse_color_back = float3 (0,0,0);              }              else              {                  // Compute diffuse contribution                  diffuse_color_back = /* attenuation_factor * */                      spot_angle_factor *                      normal_facing_factor * light.color;                  // Compute specular contribution                  float3 V = normalize (eye - P);                  float3 H = normalize (L + V);                  float specular_facing_factor =                      pow (max (dot (-N, H), 0), power_back);                  specular_color_back = /* attenuation_factor * */                      spot_angle_factor *                      specular_facing_factor * light.color_specular;              }          }      }  }}void pointAttenuatedLighting (_pgl_d3d_light light, float3 P, float3 N,         float3 eye, int faces,         float power_front,         float power_back,         out float3 diffuse_color_front,         out float3 diffuse_color_back,         out float3 specular_color_front,         out float3 specular_color_back){  // Compute direction at P that is opposite to direction of light travel   float3 L = normalize (light.position - P);  // cosine of angle between normal and direction to light source  float NdotL = dot (N, L);  float normal_facing_factor;  if (faces & FRONT_FACE)  {      normal_facing_factor = max (NdotL, 0);      if (normal_facing_factor <= 0)      {          specular_color_front = diffuse_color_front = float3 (0,0,0);      }      else      {#if 0          // Compute attenuation with distance          float attenuation_factor;          if (light.range != 0)          {              attenuation_factor = attenuation (P, light);          }          else          {              attenuation_factor = 1.0;          }          if (attenuation_factor == 0)          {              specular_color_front = diffuse_color_front = float3 (0,0,0);          }          else#endif          {              // Compute diffuse contribution              diffuse_color_front = /* attenuation_factor * */                  normal_facing_factor * light.color;              // Compute specular contribution              float3 V = normalize (eye - P);              float3 H = normalize (L + V);              float specular_facing_factor =                  pow (max (dot (N, H), 0), power_front);              specular_color_front = /* attenuation_factor * */                  specular_facing_factor * light.color_specular;          }      }  }  if (faces & BACK_FACE)  {      normal_facing_factor = max (-NdotL, 0);      if (normal_facing_factor <= 0)      {          specular_color_back = diffuse_color_back = float3 (0,0,0);      }      else      {#if 0          // Compute attenuation with distance          float attenuation_factor;          if (light.range != 0)          {              attenuation_factor = attenuation (P, light);          }          else          {              attenuation_factor = 1.0;

⌨️ 快捷键说明

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