/****************************************************************************** * The following code was generated by the mental mill(tm) * * * * Copyright 1986-2007 by mental images GmbH, Fasanenstr. 81, D-10623 * * Berlin, Germany. All rights reserved. * /*****************************************************************************/ // // Values for the light_type parameter of light shaders // #define LIGHT_POINT 0 #define LIGHT_SPOT 1 #define LIGHT_INFINITE 2 #define LIGHT_PLANAR 3 // // The light iterator structure holds the return values resulting from // evaluating a light. // struct Light_iterator { float3 _point; float4 contribution; float4 raw_contribution; float dot_nl; float3 direction; float distance; float4 shadow; int count; }; struct Ray { float3 origin; float3 direction; }; Ray __Ray_ctor(float3 o, float3 d) { Ray r; r.origin = o; r.direction = d; return r; } float2 __float2_ctor(float v) { return v.xx; } float3 __float3_ctor(float v) { return v.xxx; } float4 __float4_ctor(float v) { return v.xxxx; } float4 __tex2D_flip_v(sampler2D samp, float2 uv) { return tex2D(samp, float2(uv.x, 1.0-uv.y)); } float4 __tex2D_flip_v(sampler2D samp, float2 uv, float2 ddu, float2 ddv) { return tex2D(samp, float2(uv.x, 1.0-uv.y), ddu, ddv); } void mi_component_illumination_base( float4 ambient_color, float ambient_scalar, float4 diffuse_reflectance_color, float4 diffuse_color, float diffuse_scalar, float4 specular_reflectance_color, float4 specular_color, float specular_scalar, out float4 sum, out float4 ambient, out float4 diffuse, out float4 specular) { sum = (float4(0, 0, 0, 0)); ambient = (float4(0, 0, 0, 0)); diffuse = (float4(0, 0, 0, 0)); specular = (float4(0, 0, 0, 0)); ambient = (ambient_color * ambient_scalar); sum += ambient; diffuse += ((diffuse_reflectance_color * diffuse_color) * diffuse_scalar); sum += diffuse; specular += ((specular_reflectance_color * specular_color) * specular_scalar); sum += specular; sum.a = 1.0; ambient.a = 1.0; diffuse.a = 1.0; specular.a = 1.0; } float mi_SQR( float x) { return x * x; } float mi_phong_specular( float3 lightDir, float3 eyeDir, float3 n, float specular_shininess) { float res = 0.0f; float3 _half = lightDir - eyeDir; float phi = dot(_half, n); phi *= (phi / (dot(_half, _half))); if (phi > 0.0) { res = (exp((((log(phi)) * 0.5f) * specular_shininess))); } return res; } // // The state structure is used internally within the fragment shader to // commonly used values. // struct State { float4 tex_coord[4]; float3 position; float3 normal; float3 direction; float3x3 tangent_space[1]; float3 light_position; float3 light_to_surface; float light_distance; float light_dotnl; }; // // The following are free parameters of the shader that should be set by the // application at runtime. // float4 __light0_color < string UIName = "Light0 Color"; string UIWidget = "Color"; > = float4(1.000000, 1.000000, 1.000000, 1.000000); float __light0_intensity < string UIName = "Light0 Intensity"; float UIMin = 0.000000; float UIMax = 10.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 1.000000; float __light0_distance_falloff_exponent < string UIName = "Light0 Distance Falloff Exponent"; float UIMin = 0.000000; float UIMax = 4.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 1.000000; float __light0_distance_falloff_start < string UIName = "Light0 Distance Falloff Start"; float UIMin = 0.000000; float UIMax = 10.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 0.000000; float __light0_distance_falloff_limit < string UIName = "Light0 Distance Falloff Limit"; float UIMin = 0.000000; float UIMax = 1000.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 1000.000000; float __light0_distance_scale < string UIName = "Light0 Distance Scale"; float UIMin = 0.001000; float UIMax = 100.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 1.000000; float3 __light0_position : Position < string Object = "PointLight0"; string Space = "View"; string UIName = "Light0 Light_position"; > = float3(0.000000, 0.000000, 0.000000); float4 __light1_color < string UIName = "Light1 Color"; string UIWidget = "Color"; > = float4(1.000000, 1.000000, 1.000000, 1.000000); float __light1_intensity < string UIName = "Light1 Intensity"; float UIMin = 0.000000; float UIMax = 10.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 1.000000; float __light1_distance_falloff_exponent < string UIName = "Light1 Distance Falloff Exponent"; float UIMin = 0.000000; float UIMax = 4.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 1.000000; float __light1_distance_falloff_start < string UIName = "Light1 Distance Falloff Start"; float UIMin = 0.000000; float UIMax = 10.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 0.000000; float __light1_distance_falloff_limit < string UIName = "Light1 Distance Falloff Limit"; float UIMin = 0.000000; float UIMax = 1000.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 1000.000000; float __light1_distance_scale < string UIName = "Light1 Distance Scale"; float UIMin = 0.001000; float UIMax = 100.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 1.000000; float3 __light1_position : Position < string Object = "PointLight1"; string Space = "View"; string UIName = "Light1 Light_position"; > = float3(0.000000, 0.000000, 0.000000); texture __Normal_map_1_texture < string UIName = "Normal_map_1_texture"; string ResourceName = "C:\\Users\\Michael\\Desktop\\shaders\\normal_testb.jpg"; string ResourceType = "2D"; >; sampler2D Normal_map_1_texture = sampler_state { Texture = <__Normal_map_1_texture>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; float Normals_make_normal_1_amount < string UIName = "Amount"; float UIMin = 0.000000; float UIMax = 1.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 1.000000; float4 Illumination_phong_1_ambient_color < string UIName = "Ambient Color"; float4 UIMin = float4(0.000000, 0.000000, 0.000000, 0.000000); float4 UIMax = float4(1.000000, 1.000000, 1.000000, 1.000000); float UIStep = 0.01; string UIWidget = "slider"; > = float4(0.000000, 0.000000, 0.000000, 0.000000); float Illumination_phong_1_ambient_scalar < string UIName = "Ambient Scalar"; float UIMin = 0.000000; float UIMax = 1.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 0.500000; float4 Illumination_phong_1_diffuse_color < string UIName = "Diffuse Color"; float4 UIMin = float4(0.000000, 0.000000, 0.000000, 0.000000); float4 UIMax = float4(1.000000, 1.000000, 1.000000, 1.000000); float UIStep = 0.01; string UIWidget = "slider"; > = float4(1.000000, 1.000000, 1.000000, 1.000000); float Illumination_phong_1_diffuse_scalar < string UIName = "Diffuse Scalar"; float UIMin = 0.000000; float UIMax = 1.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 0.900000; float4 Illumination_phong_1_specular_color < string UIName = "Specular Color"; float4 UIMin = float4(0.000000, 0.000000, 0.000000, 0.000000); float4 UIMax = float4(1.000000, 1.000000, 1.000000, 1.000000); float UIStep = 0.01; string UIWidget = "slider"; > = float4(1.000000, 1.000000, 1.000000, 1.000000); float Illumination_phong_1_specular_scalar < string UIName = "Specular Scalar"; float UIMin = 0.000000; float UIMax = 1.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 0.500000; float Illumination_phong_1_specular_shininess < string UIName = "Specular Shininess"; float UIMin = 0.000000; float UIMax = 100.000000; float UIStep = 0.01; string UIWidget = "slider"; > = 50.000000; // // The following are parameters representing non-varying state variables // referenced by the shader. These should be set by the application at runtime. // Note that vector parameters should be provided in camera space. // float4x4 __object_to_camera : WorldView < string UIWidget = "none"; >; float4x4 __object_to_raster : WorldViewProjection < string UIWidget = "none"; >; float4x4 __camera_to_object : WorldViewInverse < string UIWidget = "none"; >; // // The App2vert structure defines the vertex attributes used by the vertex // shader. The application should supply a vertex stream containing these // elements. // struct App2vert { float4 position : POSITION; float3 normal : NORMAL; float4 tex_coord0 : TEXCOORD0; float4 tex_coord1 : TEXCOORD1; float4 tex_coord2 : TEXCOORD2; float4 tex_coord3 : TEXCOORD3; float3 tex_tangent : TANGENT; float3 tex_binormal : BINORMAL; }; // // The Vert2frag structure defines values used by the fragment shader and // supplied by the vertex shader. // struct Vert2frag { float4 hpos : POSITION; float4 tex_coord[4] : TEXCOORD0; float3 tex_tangent[1] : TEXCOORD4; float3 tex_binormal[1] : TEXCOORD5; float3 position : TEXCOORD6; float3 normal : TEXCOORD7; }; // // This function is the main method of the vertex shader. // Vert2frag vertex_main( App2vert vs_in) { Vert2frag vs_out; vs_out.hpos = mul(vs_in.position, __object_to_raster); vs_out.position = mul(vs_in.position, __object_to_camera).xyz; vs_out.normal = mul((float3x3)__camera_to_object, vs_in.normal); vs_out.tex_coord[0] = vs_in.tex_coord0; vs_out.tex_coord[1] = vs_in.tex_coord1; vs_out.tex_coord[2] = vs_in.tex_coord2; vs_out.tex_coord[3] = vs_in.tex_coord3; vs_out.tex_tangent[0] = mul(vs_in.tex_tangent, (float3x3)__object_to_camera); vs_out.tex_binormal[0] = mul(vs_in.tex_binormal, (float3x3)__object_to_camera); return vs_out; } // // The following functions are generated from the MetaSL implementation of // the shaders that are part of the compiled shader graph. // void Light_point_main( float4 color, float intensity, float distance_falloff_exponent, float distance_falloff_start, float distance_falloff_limit, float distance_scale, State state, out float4 result) { { float d = saturate((((state.light_distance) / (distance_scale - distance_falloff_start)) / (distance_falloff_limit - distance_falloff_start))); float f = 1.0 / (1.0 + (pow(d, distance_falloff_exponent))); result = ((color * intensity) * f); } } void Light_point_1_main( float4 color, float intensity, float distance_falloff_exponent, float distance_falloff_start, float distance_falloff_limit, float distance_scale, float3 __light_position, State state, out Light_iterator __light) { { float4 result = float4(0.000000, 0.000000, 0.000000, 0.000000); __light.direction = (__light_position - (state.position)); __light.distance = (length(__light.direction)); __light.direction /= __light.distance; __light.dot_nl = (dot(__light.direction, (state.normal))); (state.light_to_surface) = (-__light.direction); (state.light_distance) = __light.distance; (state.light_dotnl) = __light.dot_nl; (state.light_position) = __light_position; Light_point_main(color, intensity, distance_falloff_exponent, distance_falloff_start, distance_falloff_limit, distance_scale, (state), result); __light._point = __light_position; __light.shadow = 1.0; __light.count = 0; __light.raw_contribution = result; __light.contribution = result; } } void Light_point_2_main( float4 color, float intensity, float distance_falloff_exponent, float distance_falloff_start, float distance_falloff_limit, float distance_scale, float3 __light_position, State state, out Light_iterator __light) { { float4 result = float4(0.000000, 0.000000, 0.000000, 0.000000); __light.direction = (__light_position - (state.position)); __light.distance = (length(__light.direction)); __light.direction /= __light.distance; __light.dot_nl = (dot(__light.direction, (state.normal))); (state.light_to_surface) = (-__light.direction); (state.light_distance) = __light.distance; (state.light_dotnl) = __light.dot_nl; (state.light_position) = __light_position; Light_point_main(color, intensity, distance_falloff_exponent, distance_falloff_start, distance_falloff_limit, distance_scale, (state), result); __light._point = __light_position; __light.shadow = 1.0; __light.count = 1; __light.raw_contribution = result; __light.contribution = result; } } void Texture_lookup_2d_main( sampler2D _texture, int texture_space, float2 texture_uv, State state, out float4 result) { { result = (__tex2D_flip_v(_texture, texture_uv)); } } void Normals_make_normal_main( float4 color, float amount, State state, out float3 result) { { float3 n = (color.xyz - 0.5) * 2.0; n.xy *= amount; result = (normalize((mul((state.tangent_space)[0], n)))); } } void Illumination_phong_main( float4 ambient_color, float ambient_scalar, float4 diffuse_color, float diffuse_scalar, float4 specular_color, float specular_scalar, float specular_shininess, State state, out float4 sum, out float4 ambient, out float4 diffuse, out float4 specular) { { diffuse = (float4(0, 0, 0, 0)); specular = (float4(0, 0, 0, 0)); float3 vdir = state.direction; Light_iterator light; { { Light_point_1_main(__light0_color, __light0_intensity, __light0_distance_falloff_exponent, __light0_distance_falloff_start, __light0_distance_falloff_limit, __light0_distance_scale, __light0_position, (state), light); float d = saturate(light.dot_nl); diffuse += (d * light.contribution); float s = mi_phong_specular(light.direction, vdir, (state.normal), specular_shininess); if (d > 0.0) { specular += (s * light.contribution); } } { Light_point_2_main(__light1_color, __light1_intensity, __light1_distance_falloff_exponent, __light1_distance_falloff_start, __light1_distance_falloff_limit, __light1_distance_scale, __light1_position, (state), light); float d = saturate(light.dot_nl); diffuse += (d * light.contribution); float s = mi_phong_specular(light.direction, vdir, (state.normal), specular_shininess); if (d > 0.0) { specular += (s * light.contribution); } } } diffuse.a = 1.0; specular.a = 1.0; float4 diffuse_reflectance_color = diffuse; float4 specular_reflectance_color = specular; mi_component_illumination_base(ambient_color, ambient_scalar, diffuse_reflectance_color, diffuse_color, diffuse_scalar, specular_reflectance_color, specular_color, specular_scalar, sum, ambient, diffuse, specular); } } // // The following method is the root function of the shader graph // float4 Illumination_phong_1_eval(State state) { float4 sum; float4 ambient; float4 diffuse; float4 specular; float4 Normal_map_1_result = float4(0.000000, 0.000000, 0.000000, 0.000000); Texture_lookup_2d_main(Normal_map_1_texture, 0, (state.tex_coord)[0].xy, (state), Normal_map_1_result); float3 Normals_make_normal_1_result = float3(0.000000, 0.000000, 0.000000); Normals_make_normal_main(Normal_map_1_result, Normals_make_normal_1_amount, (state), Normals_make_normal_1_result); { float3 temp0 = state.normal; (state.normal) = Normals_make_normal_1_result; Illumination_phong_main(Illumination_phong_1_ambient_color, Illumination_phong_1_ambient_scalar, Illumination_phong_1_diffuse_color, Illumination_phong_1_diffuse_scalar, Illumination_phong_1_specular_color, Illumination_phong_1_specular_scalar, Illumination_phong_1_specular_shininess, (state), sum, ambient, diffuse, specular); (state.normal) = temp0; } return sum; } // // This function is the main method of the fragment shader. It initializes the // values in the state structure that are used by nodes in the shader graph // and produces the final result of the shader. // float4 fragment_main( Vert2frag fs_in) : COLOR { State state; state.position = fs_in.position; state.normal = normalize(fs_in.normal); state.tex_coord = fs_in.tex_coord; state.direction = normalize(state.position); state.tangent_space[0] = transpose(float3x3( normalize(fs_in.tex_tangent[0]), normalize(fs_in.tex_binormal[0]), state.normal)); state.light_position = 0; state.light_to_surface = 0; state.light_distance = 0; state.light_dotnl = 0; return Illumination_phong_1_eval(state); } // // The following define the default technique and pass of the effect. // technique T0 { pass P0 { ZEnable = true; ZWriteEnable = true; CullMode = none; VertexShader = compile vs_3_0 vertex_main(); PixelShader = compile ps_3_0 fragment_main(); } }