Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Cg
- void vshader(
- uniform float4x4 trans_model_to_view,
- out float4 l_eye_position : TEXCOORD0,
- uniform float4x4 tpose_view_to_model,
- out float4 l_eye_normal : TEXCOORD1,
- in float4 vtx_normal : TEXCOORD0,
- float4 vtx_position : POSITION,
- out float4 l_position : POSITION,
- uniform float4x4 mat_modelproj
- ) {
- l_position = mul(mat_modelproj, vtx_position);
- l_eye_position = mul(trans_model_to_view, vtx_position);
- l_eye_normal.xyz = mul((float3x3)tpose_view_to_model, vtx_normal.xyz);
- l_eye_normal.w = 0;
- }
- void fshader(
- in float4 l_eye_position : TEXCOORD0,
- in float4 l_eye_normal : TEXCOORD1,
- uniform float4 alight_alight0,
- uniform float4x4 dlight_dlight0_rel_view,
- uniform float4x4 dlight_dlight1_rel_view,
- uniform float4x4 dlight_dlight2_rel_view,
- uniform float4x4 dlight_dlight3_rel_view,
- uniform float4x4 attr_material,
- uniform float4 row1_view_to_model,
- out float4 o_color : COLOR0,
- uniform float4 attr_color,
- uniform float4 attr_colorscale
- ) {
- float4 result;
- // Fetch all textures.
- // Correct the surface normal for interpolation effects
- l_eye_normal.xyz = normalize(l_eye_normal.xyz);
- // Begin view-space light calculations
- float ldist,lattenv,langle;
- float4 lcolor,lspec,lvec,lpoint,latten,ldir,leye,lhalf; float4 tot_ambient = float4(0,0,0,0);
- float4 tot_diffuse = float4(0,0,0,0);
- float4 tot_specular = float4(0,0,0,0);
- float shininess = attr_material[3].w;
- // Ambient Light 0
- lcolor = alight_alight0;
- tot_ambient += lcolor;
- // Directional Light 0
- lcolor = dlight_dlight0_rel_view[0];
- lspec = dlight_dlight0_rel_view[1];
- lvec = dlight_dlight0_rel_view[2];
- lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
- tot_diffuse += lcolor;
- lhalf = dlight_dlight0_rel_view[3];
- lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
- tot_specular += lspec;
- // Directional Light 1
- lcolor = dlight_dlight1_rel_view[0];
- lspec = dlight_dlight1_rel_view[1];
- lvec = dlight_dlight1_rel_view[2];
- lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
- tot_diffuse += lcolor;
- lhalf = dlight_dlight1_rel_view[3];
- lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
- tot_specular += lspec;
- // Directional Light 2
- lcolor = dlight_dlight2_rel_view[0];
- lspec = dlight_dlight2_rel_view[1];
- lvec = dlight_dlight2_rel_view[2];
- lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
- tot_diffuse += lcolor;
- lhalf = dlight_dlight2_rel_view[3];
- lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
- tot_specular += lspec;
- // Directional Light 3
- lcolor = dlight_dlight3_rel_view[0];
- lspec = dlight_dlight3_rel_view[1];
- lvec = dlight_dlight3_rel_view[2];
- lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
- tot_diffuse += lcolor;
- lhalf = dlight_dlight3_rel_view[3];
- lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
- tot_specular += lspec;
- // Begin view-space light summation
- result = float4(0,0,0,0);
- result += tot_ambient * attr_material[0];
- result += tot_diffuse * attr_material[1];
- result = saturate(result);
- // End view-space light calculations
- result *= attr_colorscale;
- tot_specular *= attr_material[3];
- result.rgb = result.rgb + tot_specular.rgb;
- o_color = result * 1.000001;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement