📄 d3dfixedfuncshaders.fx
字号:
displ_pos*v_str_array[vi_prev].normal - displ_neg*v_str_array[vi_first_pos].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_prev].normal; } else { mod_v_str_array[num_v_bld].normal = v_str_array[vi_first_pos].normal; } } }#endif#endif ++num_v_bld; } /* END if (prev_vertex_is_neg) */ /* Set up for another clip plane: update parameters and data of current polygon in v_str_array */ num_v = num_v_bld; for (i=0; i<num_v; ++i) { v_str_array[i] = mod_v_str_array[i]; } } /* END for (pi=0; pi<NumSectionPlanes; ++pi) */ return (num_v);}#endif// SHADER OUTPUT STRUCTURES/* VS SV_POSITION output that gets routed through GS must be expressed ineye space rather than clip space *///------------------------------------------------------------------------------// VS output structure for use when PS has task of lighting computations//------------------------------------------------------------------------------struct VS_OUTPUT_PePeN{ float4 cPosition : SV_POSITION; // vertex position in clip space float4 ePosition : TEXCOORD0; // vertex position in eye space float3 eNormal : TEXCOORD1; // vertex normal in eye space float4 section_distance0 : SV_ClipDistance0; float4 section_distance1 : SV_ClipDistance1;};//------------------------------------------------------------------------------// VS output structure for use when VS has task of lighting/color computations// for surface//------------------------------------------------------------------------------struct VS_OUTPUT_PfCbC{ float4 cPosition : SV_POSITION; // vertex position in clip space float4 color_front : COLOR0; // vertex diffuse color float4 color_back : COLOR1; // vertex diffuse color // (note that COLOR0 is clamped from 0..1) float4 section_distance0 : SV_ClipDistance0; float4 section_distance1 : SV_ClipDistance1;};//------------------------------------------------------------------------------// VS output structure for use when VS has task of lighting/color computations// for surface//------------------------------------------------------------------------------struct VS_OUTPUT_PfCbC_g{ float4 cPosition : SV_POSITION; // vertex position in clip space float4 color_front : COLOR0; // vertex diffuse color float4 color_back : COLOR1; // vertex diffuse color // note that COLOR0 is clamped to [0, 1]};//------------------------------------------------------------------------------// VS output structure for use when VS has task of lighting/color computations// for surface and PS has task of texturing//------------------------------------------------------------------------------struct VS_OUTPUT_PfCbCT{ float4 cPosition : SV_POSITION; // vertex position in clip spacea float4 color_front : COLOR0; // vertex diffuse color float4 color_back : COLOR1; // vertex diffuse color // (note that COLOR0 is clamped from 0..1) float3 Tex : TEXCOORD0; // vertex UV values float4 section_distance0 : SV_ClipDistance0; float4 section_distance1 : SV_ClipDistance1;};//------------------------------------------------------------------------------// VS output structure for use by unlit texture when PS has task of texturing//------------------------------------------------------------------------------struct VS_OUTPUT_PT{ float4 cPosition : SV_POSITION; // vertex position in clip spacea float2 Tex : TEXCOORD0; // vertex UV values float4 section_distance0 : SV_ClipDistance0; float4 section_distance1 : SV_ClipDistance1;};//------------------------------------------------------------------------------// VS output structure for use when VS has task of computations for curve//------------------------------------------------------------------------------struct VS_OUTPUT_PC{ float4 cPosition : SV_POSITION; // vertex position in clip space float4 color : COLOR0; // vertex color // (note that COLOR0 is clamped from 0..1) float4 section_distance0 : SV_ClipDistance0; float4 section_distance1 : SV_ClipDistance1;};//------------------------------------------------------------------------------// VS output structure for use when VS has task of computations for curve//------------------------------------------------------------------------------struct VS_OUTPUT_PiC{ float4 cPosition : SV_POSITION; // vertex position in clip space int4 color : COLOR0; // vertex color float4 section_distance0 : SV_ClipDistance0; float4 section_distance1 : SV_ClipDistance1;};//------------------------------------------------------------------------------// VS output structure for use when VS has task of computations for curve//------------------------------------------------------------------------------struct VS_OUTPUT_P{ float4 cPosition : SV_POSITION; // vertex position in clip space float4 section_distance0 : SV_ClipDistance0; float4 section_distance1 : SV_ClipDistance1;};//------------------------------------------------------------------------------// VS output structure for use when PS has task of lighting and texturing//------------------------------------------------------------------------------struct VS_OUTPUT_PePeNT{ float4 cPosition : SV_POSITION; // vertex position in clip space float4 ePosition : TEXCOORD0; // vertex position in eye space float3 eNormal : TEXCOORD1; // vertex normal in eye space float2 Tex : TEXCOORD2; // vertex UV values float4 section_distance0 : SV_ClipDistance0; float4 section_distance1 : SV_ClipDistance1;};// VERTEX SHADERS//------------------------------------------------------------------------------/* VS that does lighting computations on surfaces using material properties.This allows both faces to be done in one call even though back material maydiffer from front material. *///------------------------------------------------------------------------------VS_OUTPUT_PfCbC VS_VSLM_PSC (float4 vPos : POSITION, float3 vNormal : NORMAL){ VS_OUTPUT_PfCbC Output; float3 V, N; // vertex and normal in D3D eye space float3 eye_pos = float3 (0,0,0); // eye in D3D eye space float3 light_diffuse_front, light_diffuse_back, light_specular_front, light_specular_back; int i; if (NumSectionPlanes) { /* Improvement in sectioning speed could be achieved by testing zone_mask to prevent sectioning by planes that have already been determined to have no sectioning effect */ /* Alternative code at this point would be used to support sectioning by geometry shader */ set_distances_to_section_planes (vPos, Output.section_distance0, Output.section_distance1); } else { Output.section_distance0 = 1.0; Output.section_distance1 = 1.0; } // Transform the position from object space to clip space Output.cPosition = mul (vPos, MatrixWorldViewProj); // Transform position and normal from object space to D3D eye space V = mul (vPos, MatrixWorldView); N = normalize (mul (vNormal, (float3x3)MatrixWorldView)); if (FacesMask & FRONT_FACE) { Output.color_front.rgb = 0; /* Materials[0].emissive.rgb; */ Output.color_front.a = Materials[0].alpha; } if (FacesMask & BACK_FACE) { Output.color_back.rgb = 0; /* Materials[1].emissive.rgb; */ Output.color_back.a = Materials[1].alpha; } for (i=0; i<NumLights; i++) { if (Lights[i].enabled) { if (Lights[i].type == 0) { // ambient light if (FacesMask & FRONT_FACE) { Output.color_front.rgb += Materials[0].ambient * Lights[i].color; } if (FacesMask & BACK_FACE) { Output.color_back.rgb += Materials[1].ambient * Lights[i].color; } } else if (Lights[i].type == 1) { // directional light directionalLighting (Lights[i], V, N, eye_pos, FacesMask, Materials[0].power, Materials[1].power, light_diffuse_front, light_diffuse_back, light_specular_front, light_specular_back); if (FacesMask & FRONT_FACE) { Output.color_front.rgb += Materials[0].diffuse * light_diffuse_front; Output.color_front.rgb += Materials[0].specular * light_specular_front; } if (FacesMask & BACK_FACE) { Output.color_back.rgb += Materials[1].diffuse * light_diffuse_back; Output.color_back.rgb += Materials[1].specular * light_specular_back; } } else if (Lights[i].type == 2) { // point light pointAttenuatedLighting (Lights[i], V, N, eye_pos, FacesMask, Materials[0].power, Materials[1].power, light_diffuse_front, light_diffuse_back, light_specular_front, light_specular_back); if (FacesMask & FRONT_FACE) { Output.color_front.rgb += Materials[0].diffuse * light_diffuse_front; Output.color_front.rgb += Materials[0].specular * light_specular_front; } if (FacesMask & BACK_FACE) { Output.color_back.rgb += Materials[1].diffuse * light_diffuse_back; Output.color_back.rgb += Materials[1].specular * light_specular_back; } } else if (Lights[i].type == 3) { // spot light spotAttenuatedLighting (Lights[i], V, N, eye_pos, FacesMask, Materials[0].power, Materials[1].power, light_diffuse_front, light_diffuse_back, light_specular_front, light_specular_back); if (FacesMask & FRONT_FACE) { Output.color_front.rgb += Materials[0].diffuse * light_diffuse_front; Output.color_front.rgb += Materials[0].specular * light_specular_front; } if (FacesMask & BACK_FACE) { Output.color_back.rgb += Materials[1].diffuse * light_diffuse_back; Output.color_back.rgb += Materials[1].specular * light_specular_back; } } } } return Output;}//------------------------------------------------------------------------------/* VS that does lighting computations on surfaces using vertex colors in placeof ambient and diffuse material properties.This does not allow both faces to be done in one call if vertex colors for backdiffer from those for front.This is similar to using OpenGL glColorMaterial, and GL_AMBIENT_AND_DIFFUSE isthe default for OpenGL and so far is the only option used by PGL.PGL also only uses glColorMaterial to replace both front and back materials. *///------------------------------------------------------------------------------VS_OUTPUT_PfCbC VS_VSLC_PSC (float4 vPos : POSITION, float3 vNormal : NORMAL, float4 color : COLOR){ VS_OUTPUT_PfCbC Output; float3 V, N; // vertex and normal in D3D eye space float3 eye_pos = float3 (0,0,0); // eye in D3D eye space float3 light_diffuse_front, light_diffuse_back, light_specular_front, light_specular_back; int i; if (NumSectionPlanes) { set_distances_to_section_planes (vPos, Output.section_distance0, Output.section_distance1); } else { Output.section_distance0 = 1.0; Output.section_distance1 = 1.0; } // Transform the position from object space to clip space Output.cPosition = mul (vPos, MatrixWorldViewProj); // Transform position and normal from object space to D3D eye space V = mul (vPos, MatrixWorldView); N = normalize (mul (vN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -