Advertisement
plaYer2k

light_dir.hlsl (r2)

Jul 24th, 2016
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. // -- Credits --
  2. // Special thanks to MrMcGowan from reddit for pointing towards this file over EnvAmbient.h for ambient and specular light changes.
  3.  
  4.  
  5. // This is the multiplier to the diffuse ambient light, which essentially is the "background light" present everywhere.
  6. // Set this to below 0 to skip the diffuse computations and have pitchblack shadows or tweak the value up/down a bit
  7. // to have shadows in your world that are still dark but things within them are visible without lights.
  8. /// 0 = no lights, 1 = full diffuse lights (vanila SE)
  9. #define DIFFUSE_AMBIENT_LIGHT_MULTIPLIER 0.0003f
  10.  
  11. // This multiplier makes the emissives (glowing indicator on blocks) scale with the shadows around to prevent overbrightness of them in darkness.
  12. // A value of 0.0f means that shadows get completely ignored and the emissives will have full brightness.
  13. // A value of 1.0f means that the emissives scale fully with the shadows and if there is no light around the emissivles dont shine as well.
  14. #define EMISSIVE_SHADOW_SCALE 0.9f
  15.  
  16.  
  17.  
  18. #include <Lighting/light.h>
  19.  
  20. Texture2D<float> ShadowsMainView : register(MERGE(t, SHADOW_SLOT));
  21.  
  22.  
  23. float3 GetSunColor(float3 L, float3 V, float3 color, float sizeMult)
  24. {
  25. return (color + 0.5f + float3(0.5f, 0.35f, 0.0f)) * pow(saturate(dot(L, -V)), 4000.0f) * sizeMult;
  26. }
  27.  
  28. void __pixel_shader(PostprocessVertex vertex, out float3 output : SV_Target0
  29. #ifdef SAMPLE_FREQ_PASS
  30. , uint sample_index : SV_SampleIndex
  31. #endif
  32. )
  33. {
  34. #if !defined(MS_SAMPLE_COUNT) || defined(PIXEL_FREQ_PASS)
  35. SurfaceInterface input = read_gbuffer(vertex.position.xy);
  36. #else
  37. SurfaceInterface input = read_gbuffer(vertex.position.xy, sample_index);
  38. #endif
  39.  
  40. float shadow = 1;
  41. float ao = input.ao;
  42. #ifndef NO_SHADOWS
  43. if (input.id == 2)
  44. {
  45. shadow = calculate_shadow_fast(input.position, input.stencil);
  46. }
  47. else
  48. {
  49. #if !defined(MS_SAMPLE_COUNT) || defined(PIXEL_FREQ_PASS)
  50. shadow = ShadowsMainView[vertex.position.xy].x;
  51. #else
  52. shadow = calculate_shadow_fast(input.position, input.stencil);
  53. #endif
  54. }
  55.  
  56. float shadowMultiplier = mad(frame_.shadowFadeout, -frame_.skyboxBrightness, frame_.shadowFadeout);
  57. shadow = mad(shadow, 1 - shadowMultiplier, shadowMultiplier);
  58. #endif
  59.  
  60. if(depth_not_background(input.native_depth))
  61. {
  62. float3 shaded = 0;
  63. float sqrtAo = sqrt(ao);
  64.  
  65. // emissive
  66. shaded += input.base_color * input.emissive * (1.0f - EMISSIVE_SHADOW_SCALE + EMISSIVE_SHADOW_SCALE * shadow);
  67.  
  68. // ambient diffuse & specular
  69. if(DIFFUSE_AMBIENT_LIGHT_MULTIPLIER > 0.0f)
  70. shaded += ambient_diffuse(input.albedo, input.N, input.depth) * ao * DIFFUSE_AMBIENT_LIGHT_MULTIPLIER;
  71. shaded += ambient_specular(input.f0, input.gloss, input.N, input.V) * ao * shadow;
  72.  
  73. // main directional light diffuse & specular
  74. shaded += main_directional_light(input) * shadow * sqrtAo;
  75.  
  76. // additional directional light diffuse & specular
  77. // TODO: purpose of w?
  78. /*float4 ambientSample = SkyboxIBLTex.SampleLevel(TextureSampler, input.N, mad(-input.gloss, IBL_MAX_MIPMAP, IBL_MAX_MIPMAP)) / 10000;
  79. for (int sunIndex = 0; sunIndex < max(1, frame_.additionalSunsInUse); ++sunIndex)
  80. shaded += back_directional_light(input, sunIndex) * sqrtAo * ambientSample.w;*/
  81.  
  82. output = add_fog(shaded, input.depth, -input.V, get_camera_position());
  83. }
  84. else
  85. {
  86. float3 v = mul(float4(-input.V, 0.0f), frame_.background_orientation).xyz;
  87. // This is because DX9 code does the same (see MyBackgroundCube.cs)
  88. v.z *= -1;
  89. output = SkyboxColor(v) * frame_.skyboxBrightness;
  90.  
  91. output += GetSunColor(-frame_.directionalLightVec, input.V, frame_.directionalLightColor, 5);
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement