Guest User

DrawTexture_ColorAdjust.pShader

a guest
Feb 5th, 2015
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. // FILENAME: DrawTexture_ColorAdjust.pShader
  2.  
  3. /********************************************************************************
  4. Copyright (C) 2012 Hugh Bailey <[email protected]>
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  19. ********************************************************************************/
  20.  
  21. uniform Texture2D diffuseTexture;
  22. uniform float4 outputColor;
  23. uniform float gamma;
  24.  
  25. SamplerState textureSampler
  26. {
  27. AddressU = Clamp;
  28. AddressV = Clamp;
  29. Filter = Linear;
  30. };
  31.  
  32. struct VertData
  33. {
  34. float4 pos : SV_Position;
  35. float2 texCoord : TexCoord0;
  36. };
  37.  
  38. float4 main(VertData input) : SV_Target
  39. {
  40. /********************************************************************************
  41. DK2 chromatic aberration removal
  42. by shole ([email protected])
  43. v20150108 - optimized eye bounds checking
  44. v20150103 - added bounds checks for single eye rendering, added eye placement coordinates
  45. v20150102 - initial version
  46. ********************************************************************************/
  47. // enable/disable, for when using OBS with non-dk2 gaming
  48. bool rainbowremoval=true;
  49.  
  50. // your profile eye relief position (0..1)
  51. float eyerelief=1.0;
  52.  
  53. // zoom to one eye?
  54. bool zoom=true;
  55. float zoomlevel=1.5;
  56. // which eye? set true for left eye
  57. bool zoomleft=true;
  58. float2 eyereturn; // where we want to place the eye
  59. eyereturn.x=0.5;
  60. eyereturn.y=0.5;
  61.  
  62. /*******************************************************************************/
  63. float4 outColor;
  64. if (rainbowremoval) {
  65. // color channel scale multipliers - these values eyeballed
  66. float4 scale_in=float4(1.0, 1.013, 1.032, 1.0); // eye relief in
  67. float4 scale_out=float4(1.0, 1.017, 1.038, 1.0); // eye relief out
  68. float4 scale=lerp(scale_in, scale_out, eyerelief);
  69.  
  70. float2 eyepos; // where the original eye is
  71. float2 coord;
  72. if (zoom) { // one eye only?
  73. if (zoomleft) {
  74. eyepos.x=0.25;
  75. } else {
  76. eyepos.x=0.75;
  77. }
  78. eyepos.y=0.5;
  79. scale=scale*zoomlevel;
  80. coord=(((input.texCoord-eyereturn)/scale.r)+eyepos) *float2(2.0,1.0); // 0..1 is left eye, 1..2 is right eye
  81. if (!zoomleft){
  82. coord.x-=1.0; // shift the cutout area to right eye
  83. }
  84. if ( any(floor(coord)) ) { // cut out anything outside the selected eye 0..1 coordinate range
  85. return float4(0,0,0,1);
  86. }
  87. } else {
  88. if (input.texCoord.x<0.5) { // eye centers
  89. eyepos.x=0.25;
  90. eyepos.y=0.5;
  91. } else {
  92. eyepos.x=0.75;
  93. eyepos.y=0.5;
  94. }
  95. eyereturn=eyepos; //return to original position
  96. }
  97.  
  98. //coord=input.texCoord; // red is 1:1
  99. coord=((input.texCoord-eyereturn)/scale.r)+eyepos;
  100. float4 r=diffuseTexture.Sample(textureSampler, coord) * float4(1.0,0.0,0.0,1.0);
  101.  
  102. coord=((input.texCoord-eyereturn)/scale.g)+eyepos;
  103. float4 g=diffuseTexture.Sample(textureSampler, coord) * float4(0.0,1.0,0.0,1.0);
  104.  
  105. coord=((input.texCoord-eyereturn)/scale.b)+eyepos;
  106. float4 b=diffuseTexture.Sample(textureSampler, coord) * float4(0.0,0.0,1.0,1.0);
  107.  
  108. outColor = (r+g+b) * outputColor;
  109. } else {
  110. outColor = diffuseTexture.Sample(textureSampler, input.texCoord) * outputColor;
  111. }
  112. outColor.rgb = pow(outColor.rgb, gamma);
  113. return outColor;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment