Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // FILENAME: DrawTexture_ColorAdjust.pShader
- /********************************************************************************
- Copyright (C) 2012 Hugh Bailey <[email protected]>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
- ********************************************************************************/
- uniform Texture2D diffuseTexture;
- uniform float4 outputColor;
- uniform float gamma;
- SamplerState textureSampler
- {
- AddressU = Clamp;
- AddressV = Clamp;
- Filter = Linear;
- };
- struct VertData
- {
- float4 pos : SV_Position;
- float2 texCoord : TexCoord0;
- };
- float4 main(VertData input) : SV_Target
- {
- /********************************************************************************
- DK2 chromatic aberration removal
- by shole ([email protected])
- v20150108 - optimized eye bounds checking
- v20150103 - added bounds checks for single eye rendering, added eye placement coordinates
- v20150102 - initial version
- ********************************************************************************/
- // enable/disable, for when using OBS with non-dk2 gaming
- bool rainbowremoval=true;
- // your profile eye relief position (0..1)
- float eyerelief=1.0;
- // zoom to one eye?
- bool zoom=true;
- float zoomlevel=1.5;
- // which eye? set true for left eye
- bool zoomleft=true;
- float2 eyereturn; // where we want to place the eye
- eyereturn.x=0.5;
- eyereturn.y=0.5;
- /*******************************************************************************/
- float4 outColor;
- if (rainbowremoval) {
- // color channel scale multipliers - these values eyeballed
- float4 scale_in=float4(1.0, 1.013, 1.032, 1.0); // eye relief in
- float4 scale_out=float4(1.0, 1.017, 1.038, 1.0); // eye relief out
- float4 scale=lerp(scale_in, scale_out, eyerelief);
- float2 eyepos; // where the original eye is
- float2 coord;
- if (zoom) { // one eye only?
- if (zoomleft) {
- eyepos.x=0.25;
- } else {
- eyepos.x=0.75;
- }
- eyepos.y=0.5;
- scale=scale*zoomlevel;
- coord=(((input.texCoord-eyereturn)/scale.r)+eyepos) *float2(2.0,1.0); // 0..1 is left eye, 1..2 is right eye
- if (!zoomleft){
- coord.x-=1.0; // shift the cutout area to right eye
- }
- if ( any(floor(coord)) ) { // cut out anything outside the selected eye 0..1 coordinate range
- return float4(0,0,0,1);
- }
- } else {
- if (input.texCoord.x<0.5) { // eye centers
- eyepos.x=0.25;
- eyepos.y=0.5;
- } else {
- eyepos.x=0.75;
- eyepos.y=0.5;
- }
- eyereturn=eyepos; //return to original position
- }
- //coord=input.texCoord; // red is 1:1
- coord=((input.texCoord-eyereturn)/scale.r)+eyepos;
- float4 r=diffuseTexture.Sample(textureSampler, coord) * float4(1.0,0.0,0.0,1.0);
- coord=((input.texCoord-eyereturn)/scale.g)+eyepos;
- float4 g=diffuseTexture.Sample(textureSampler, coord) * float4(0.0,1.0,0.0,1.0);
- coord=((input.texCoord-eyereturn)/scale.b)+eyepos;
- float4 b=diffuseTexture.Sample(textureSampler, coord) * float4(0.0,0.0,1.0,1.0);
- outColor = (r+g+b) * outputColor;
- } else {
- outColor = diffuseTexture.Sample(textureSampler, input.texCoord) * outputColor;
- }
- outColor.rgb = pow(outColor.rgb, gamma);
- return outColor;
- }
Advertisement
Add Comment
Please, Sign In to add comment