Skip to content

Commit

Permalink
Separate versions of each shader are now more easily available for co…
Browse files Browse the repository at this point in the history
…mpilation

TODO: write up some way to share shader code and use platform-specific features
  • Loading branch information
juanjp600 committed Dec 31, 2017
1 parent 959e5df commit 5c2872c
Show file tree
Hide file tree
Showing 38 changed files with 111,660 additions and 2 deletions.
44 changes: 44 additions & 0 deletions Barotrauma/BarotraumaShared/Content/Content_opengl.mgcb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#----------------------------- Global Properties ----------------------------#

/outputDir:bin/$(Platform)
/intermediateDir:obj/$(Platform)
/platform:DesktopGL
/config:
/profile:Reach
/compress:False

#-------------------------------- References --------------------------------#


#---------------------------------- Content ---------------------------------#

#begin watershader_opengl.fx
/importer:EffectImporter
/processor:EffectProcessor
/processorParam:DebugMode=Auto
/build:watershader_opengl.fx

#begin blurshader_opengl.fx
/importer:EffectImporter
/processor:EffectProcessor
/processorParam:DebugMode=Auto
/build:blurshader_opengl.fx

#begin damageshader_opengl.fx
/importer:EffectImporter
/processor:EffectProcessor
/processorParam:DebugMode=Auto
/build:damageshader_opengl.fx

#begin losshader_opengl.fx
/importer:EffectImporter
/processor:EffectProcessor
/processorParam:DebugMode=Auto
/build:losshader_opengl.fx

#begin utg_4.mp4
/importer:H264Importer
/processor:VideoProcessor
/build:utg_4.mp4

33 changes: 33 additions & 0 deletions Barotrauma/BarotraumaShared/Content/blurshader_opengl.fx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Pixel shader applies a one dimensional gaussian blur filter.
// This is used twice by the bloom postprocess, first to
// blur horizontally, and then again to blur vertically.

sampler TextureSampler : register(s0);

#define SAMPLE_COUNT 15

float2 SampleOffsets[SAMPLE_COUNT];
float SampleWeights[SAMPLE_COUNT];


float4 PixelShaderF(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 c = 0;

// Combine a number of weighted image filter taps.
for (int i = 0; i < SAMPLE_COUNT; i++)
{
c += tex2D(TextureSampler, texCoord + SampleOffsets[i]) * SampleWeights[i];
}

return c;
}


technique GaussianBlur
{
pass Pass1
{
PixelShader = compile ps_2_0 PixelShaderF();
}
}
Binary file modified Barotrauma/BarotraumaShared/Content/blurshader_opengl.xnb
Binary file not shown.
2 changes: 1 addition & 1 deletion Barotrauma/BarotraumaShared/Content/damageshader.fx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ technique StencilShader
{
pass Pass1
{
PixelShader = compile ps_2_0 main();
PixelShader = compile ps_4_0_level_9_1 main();
}
}
39 changes: 39 additions & 0 deletions Barotrauma/BarotraumaShared/Content/damageshader_opengl.fx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Texture xTexture;
sampler TextureSampler : register (s0) = sampler_state { Texture = <xTexture>; };

Texture xStencil;
sampler StencilSampler = sampler_state { Texture = <xStencil>; };

float4 color;

float aCutoff;
float aMultiplier;

float cCutoff;
float cMultiplier;

float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 c = tex2D(TextureSampler, texCoord) * color;

float4 stencilColor = tex2D(StencilSampler, texCoord);

float aDiff = stencilColor.a - aCutoff;

clip(aDiff);

float cDiff = stencilColor.a - cCutoff;

return float4(
lerp(stencilColor.rgb, c.rgb, clamp(cDiff * cMultiplier, 0.0f, 1.0f)),
min(aDiff * aMultiplier, c.a));
}

technique StencilShader
{
pass Pass1
{
PixelShader = compile ps_2_0 main();
}
}
Binary file modified Barotrauma/BarotraumaShared/Content/damageshader_opengl.xnb
Binary file not shown.
2 changes: 1 addition & 1 deletion Barotrauma/BarotraumaShared/Content/losshader.fx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ technique LosShader
{
pass Pass1
{
PixelShader = compile ps_2_0 main();
PixelShader = compile ps_4_0_level_9_1 main();
}
}
24 changes: 24 additions & 0 deletions Barotrauma/BarotraumaShared/Content/losshader_opengl.fx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

Texture2D xTexture;
sampler TextureSampler : register (s0) = sampler_state { Texture = <xTexture>; };

Texture2D xLosTexture;
sampler LosSampler = sampler_state { Texture = <xLosTexture>; };

float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 losColor = tex2D(LosSampler, texCoord);
float4 sample = tex2D(TextureSampler, texCoord);

float4 outColor = float4(sample.x*losColor.x, sample.y*losColor.x, sample.z*losColor.x, losColor.x);

return outColor;
}

technique LosShader
{
pass Pass1
{
PixelShader = compile ps_2_0 main();
}
}
Binary file modified Barotrauma/BarotraumaShared/Content/losshader_opengl.xnb
Binary file not shown.
Binary file modified Barotrauma/BarotraumaShared/Content/watershader.xnb
Binary file not shown.
50 changes: 50 additions & 0 deletions Barotrauma/BarotraumaShared/Content/watershader_opengl.fx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
float xBlurDistance;

Texture xTexture;
sampler TextureSampler = sampler_state { Texture = <xTexture>; };

Texture xWaterBumpMap;
sampler WaterBumpSampler =
sampler_state
{
Texture = <xWaterBumpMap>;
MagFilter = LINEAR;
MinFilter = LINEAR;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};

float xWaveWidth;
float xWaveHeight;
float2 xWavePos;
float2 xBumpPos;

float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 bumpColor = tex2D(WaterBumpSampler, texCoord+xWavePos+xBumpPos);
bumpColor = (bumpColor + tex2D(WaterBumpSampler, texCoord-xWavePos*2.0f+xBumpPos))*0.5f;

float2 samplePos = texCoord;

samplePos.x+=(bumpColor.r-0.5f)*xWaveWidth;
samplePos.y+=(bumpColor.g-0.5f)*xWaveHeight;

float4 sample;
sample = tex2D( TextureSampler, float2(samplePos.x+xBlurDistance, samplePos.y+xBlurDistance));
sample += tex2D( TextureSampler, float2(samplePos.x-xBlurDistance, samplePos.y-xBlurDistance));
sample += tex2D( TextureSampler, float2(samplePos.x+xBlurDistance, samplePos.y-xBlurDistance));
sample += tex2D( TextureSampler, float2(samplePos.x-xBlurDistance, samplePos.y+xBlurDistance));

sample = sample * 0.25;

return sample;
}

technique WaterShader
{
pass Pass1
{
PixelShader = compile ps_2_0 main();
}
}
Binary file modified Barotrauma/BarotraumaShared/Content/watershader_opengl.xnb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 5c2872c

Please sign in to comment.