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

📄 d3dfixedfuncshaders.fx

📁 proe5.0野火版下载(中文版免费下载)
💻 FX
📖 第 1 页 / 共 5 页
字号:
          }          if (attenuation_factor == 0)          {              specular_color_back = diffuse_color_back = float3 (0,0,0);          }          else#endif          {              // Compute diffuse contribution              diffuse_color_back = /* 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_back);              specular_color_back = /* attenuation_factor * */                  specular_facing_factor * light.color_specular;          }      }  }}void directionalLighting (_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 = -light.direction;  // 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      {          // Compute diffuse contribution          diffuse_color_front = 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 = 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      {          // Compute diffuse contribution          diffuse_color_back = 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 = specular_facing_factor * light.color_specular;      }  }}//------------------------------------------------------------------------------/* Internal Function for Vertex ShaderCompute distance from vertex to each active section plane so as to havepipeline reject pixel when any one of these distances interpolated at thatpixel position is negative (and therefore lies on negative side of that sectionplane *///------------------------------------------------------------------------------void set_distances_to_section_planes (float4 vpos, out float4 distance0,         out float4 distance1){  /* Transform the position from object space to eye space */  float4 pos = mul (vpos, MatrixWorldView);  distance0 = 1.0;  distance1 = 1.0;  distance0.x = dot (pos, SectionPlanes[0]);  if (1 < NumSectionPlanes)  {      distance0.y = dot (pos, SectionPlanes[1]);      if (2 < NumSectionPlanes)      {          distance0.z = dot (pos, SectionPlanes[2]);          if (3 < NumSectionPlanes)          {              distance0.w = dot (pos, SectionPlanes[3]);              if (4 < NumSectionPlanes)              {                  distance1.x = dot (pos, SectionPlanes[4]);                  if (5 < NumSectionPlanes)                  {                      distance1.y = dot (pos, SectionPlanes[5]);                  }              }          }      }  }}//------------------------------------------------------------------------------/* Internal Function for Pixel ShaderCompute whether pixel position maps to a hole (0-bit) in STransparency maskReturn 1 to signal that pixel maps to hole.Return 0 to signal that pixel does not map to hole. *///------------------------------------------------------------------------------int pixel_maps_to_STransparency_hole (float4 vpos){  if (14 < STransparencyIndex)  {      /* Designated opacity bank is completely transparent */      return (1);  }  else  {      /* Designated opacity bank is somewhere between completely opaque and      completely transparent */      int pixel_x, pixel_y;      uint k;      pixel_y = (int)(vpos.y);      if (pixel_y < 0)      {          pixel_y = 0;      }      /* Get designated 32-bit opacity word */      k = STransparencies[STransparencyIndex][pixel_y & 0x3];      pixel_x = (int)(vpos.x);      if (pixel_x < 0)      {          pixel_x = 0;      }      /* Remove all but designated opacity bit */      k &= (0x80000000 >> (pixel_x & 0x1f));      return (!k);//      if (!k)//      {//          return (1);//      }  }//  return (0);}//------------------------------------------------------------------------------/* Internal Function for Pixel ShaderEmulate XOR of the integer color of the current fragment of a primitive beingdrawn in immediate mode with the integer content of the foreground colorbuffer. *///------------------------------------------------------------------------------float4 xor_fb_color_with_in_color (float4 position, float4 color){#if 0// Temporarily saving Rajdeep's original code   float4 Output;   int4 color_fr, color_in; // Current fragment color and input color    int4 xor_out;   int3 uv; /* index into frame buffer texture */   uv[0] = (int)(position.x);   uv[1] = (int)(position.y);   uv[2] = 0; /* We want to index in mip-map 0 */   /* Convert current fragment and Input color to integer */   color_fr = txXOR_frame_buffer.Load(uv) * 255;   color_in = color * 255;   xor_out = color_fr ^ color_in;   /* Convert back to float and send down */   Output = xor_out/255.0;   return Output;#endif  int4 color_fb, color_in; // framebuffer color, input color   int3 texel_indices; /* indices into framebuffer texture */  /* Compute texel coordinates corresponding to the pixel coordinates of the  current fragment */  texel_indices[0] = (int)(position.x);  texel_indices[1] = (int)(position.y);  texel_indices[2] = 0; /* We want to index into mip-map 0 */  /* Compute integer texel color obtained from previously captured  framebuffer */  color_fb = txXOR_frame_buffer.Load (texel_indices) * 255;  /* Return XOR of integer fragment color and integer texel color */  color_in = color * 255;  return ((color_in ^ color_fb)/255.0);}#if 0/* Auxiliary function for ClipTriangleByPlanes () */void construct_new_vertex (uint oa_data_mask,         float displ_neg, float displ_pos, uint num_v_bld,         uint vi_a, uint vi_b){  float n_len, n_len_sq;  float3 normal;  mod_v_str_array[num_v_bld].position =      - displ_neg*v_str_array[vi_a].position      + displ_pos*v_str_array[vi_b].position;/* Can continue to use oa_data_mask, but only one tex is sent to VS, soconvention is used herein that it is tracked by OAMB_VERTEX_UV_FRONT bit */#if 0/* TODO - Temporarily removed to reduce code size to try to make it compile */  if (oa_data_mask & OAMB_VERTEX_UV_FRONT)  {      mod_v_str_array[num_v_bld].tex =          - displ_neg*v_str_array[vi_a].tex          + displ_pos*v_str_array[vi_b].tex;  }#endif  if (oa_data_mask & OAMB_VERTEX_ECOLOR)  {      mod_v_str_array[num_v_bld].rgba_front =          - displ_neg*v_str_array[vi_a].rgba_front          + displ_pos*v_str_array[vi_b].rgba_front;  }  if (oa_data_mask & OAMB_VERTEX_ECOLOR_BACK)  {      mod_v_str_array[num_v_bld].rgba_back =          - displ_neg*v_str_array[vi_a].rgba_back          + displ_pos*v_str_array[vi_b].rgba_back;  }#if 0/* TODO - Temporarily removed to reduce code size to try to make it compile */  if (oa_data_mask & OAMB_VERTEX_AND_NORMAL)  {      normal = mod_v_str_array[num_v_bld].normal =          - displ_neg*v_str_array[vi_a].normal          + displ_pos*v_str_array[vi_b].normal;      n_len_sq = normal.x * normal.x +          normal.y*normal.y + normal.z*normal.z;      if (0.00000001/*PGL_EPSILON_LENGTH_2*/ < n_len_sq)      {          /* Normalize */          n_len = sqrt (n_len_sq);          mod_v_str_array[num_v_bld].normal /= n_len;      }      else      {          /* Use nearest normal */          if (0.5 < displ_pos)          {              mod_v_str_array[num_v_bld].normal =                  v_str_array[vi_b].normal;          }          else          {              mod_v_str_array[num_v_bld].normal =                  v_str_array[vi_a].normal;          }      }  }#endif}#endif#if 0/*----------------------------------------------------------------------------*\| INTERNAL_FUNCTION|| Purpose: Compute the new polygon that results from clipping the original|          convex polygon by the specified set of clip planes.|          Specified optional data will be computed at each new vertex.|          The clip planes must be positioned and oriented in such a way as to|          define a single convex volume on their positive sides.  Such a|          clip operation will produce either a single convex clipped polygon|          or no surviving polygon.  Other alternative clip plane|          configurations will not produce meaningful results.|          The clip planes and polygon vertices must all be expressed relative|          to the same coordinate space.|          No array overflow checks are performed, so it is the responsibility|          of the caller to provide adequate space in all required arrays.|| Input Arguments:Replaced by int NumSectionPlanes [0, 6]|    num_planes  number of unbounded clip planes.|                num_planes must not exceed 16.Replaced by float4 SectionPlanes[6];|    p_planes    address of the first _PglPlane structure in an array of such|                structures that specify each of the planes.Replaced by mask that starts section planes in bit 0|    zone_mask   zone indicators for up to 6 section planes.|                Important bits are the even-numbered bits starting in bit 12|                XXXX XXXX   0101 0101 0101   XXXX XXXX XXXX of PGL zone_mask,|                any on-bit in each consecutive pair of bits indicating|                presence of data on negative side of the corresponding plane.|                These pairs are ordered from right to left to correspond to|                the order of planes in p_planes.|                The on-bits determine which clip planes are actually used in|                the clipping computation.  If an even-numbered bit is 0,|                clipping by the corresponding clip plane is ignored.Incoming polygon is a single triangle (3 vertices)|    num_vertices number of vertices of the incoming polygon.|                num_vertices must not exceed PGL_MAX_VERTICES.Replaced by array of 3 output structures from VS|    p_vertices  address of the first _PglClipvertex structure in an array of|                such structures that specify each of the vertices of the|                incoming polygon.|                The incoming polygon must be convex.|                This list must be ordered so as to proceed around perimeter.Replaced by mask built by specific GS (knowing output structure of VS)|    oa_data_mask Bit-encoded word that indicates which types of vertex data|                need to be developed for each new intersection vertex.|                The vertex coordinate is always developed, and the Id of the|                clip plane producing the edge following a vertex is always|                developed.|                The relevant bits are:|                PGL_OAMB_VERTEX_UV_FRONT|                PGL_OAMB_VERTEX_UV_BACK|                PGL_OAMB_VERTEX_ECOLOR|                PGL_OAMB_VERTEX_ECOLOR_BACK|                PGL_OAMB_VERTEX_AND_NORMAL (signals for normal to be developed)NA               PGL_OAMB_EDGE_TYPE|| Output Arguments:|    p_clip_result address of int that is loaded with the status of the clip|                operation:|                    0 - completely outside (other output arguments are not all|                        set with reliable data)

⌨️ 快捷键说明

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