From c314077f1d1a224ad750d1cf002b952bd40c94e5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 1 Aug 2016 22:43:51 +0200 Subject: [PATCH] (D3D) Cleanups of shaders --- gfx/drivers/d3d_shaders/font.hlsl.d3d9.h | 67 +++++++++-------- gfx/drivers/d3d_shaders/opaque.cg.d3d9.h | 49 +++++++------ gfx/drivers/d3d_shaders/opaque.hlsl.d3d9.h | 85 +++++++++++----------- gfx/drivers/d3d_shaders/shaders_common.h | 15 ++++ 4 files changed, 122 insertions(+), 94 deletions(-) create mode 100644 gfx/drivers/d3d_shaders/shaders_common.h diff --git a/gfx/drivers/d3d_shaders/font.hlsl.d3d9.h b/gfx/drivers/d3d_shaders/font.hlsl.d3d9.h index 32e9462c7c..e438db7356 100644 --- a/gfx/drivers/d3d_shaders/font.hlsl.d3d9.h +++ b/gfx/drivers/d3d_shaders/font.hlsl.d3d9.h @@ -1,30 +1,37 @@ -static const char *font_hlsl_d3d9_program = -"struct VS_IN\n" -"{\n" -"float2 Pos : POSITION;\n" -"float2 Tex : TEXCOORD0;\n" -"};\n" -"struct VS_OUT\n" -"{\n" -"float4 Position : POSITION;\n" -"float2 TexCoord0 : TEXCOORD0;\n" -"};\n" -"uniform float4 Color : register(c1);\n" -"uniform float2 TexScale : register(c2);\n" -"sampler FontTexture : register(s0);\n" -"VS_OUT main_vertex( VS_IN In )\n" -"{\n" -"VS_OUT Out;\n" -"Out.Position.x = (In.Pos.x-0.5);\n" -"Out.Position.y = (In.Pos.y-0.5);\n" -"Out.Position.z = ( 0.0 );\n" -"Out.Position.w = ( 1.0 );\n" -"Out.TexCoord0.x = In.Tex.x * TexScale.x;\n" -"Out.TexCoord0.y = In.Tex.y * TexScale.y;\n" -"return Out;\n" -"}\n" -"float4 main_fragment( VS_OUT In ) : COLOR0\n" -"{\n" -"float4 FontTexel = tex2D( FontTexture, In.TexCoord0 );\n" -"return FontTexel;\n" -"}\n"; +#include "shaders_common.h" + +static const char *font_hlsl_d3d9_program = CG( + struct VS_IN + { + float2 Pos : POSITION; + float2 Tex : TEXCOORD0; + }; + + struct VS_OUT + { + float4 Position : POSITION; + float2 TexCoord0 : TEXCOORD0; + }; + + uniform float4 Color : register(c1); + uniform float2 TexScale : register(c2); + sampler FontTexture : register(s0); + + VS_OUT main_vertex( VS_IN In ) + { + VS_OUT Out; + Out.Position.x = (In.Pos.x-0.5); + Out.Position.y = (In.Pos.y-0.5); + Out.Position.z = ( 0.0 ); + Out.Position.w = ( 1.0 ); + Out.TexCoord0.x = In.Tex.x * TexScale.x; + Out.TexCoord0.y = In.Tex.y * TexScale.y; + return Out; + } + + float4 main_fragment( VS_OUT In ) : COLOR0 + { + float4 FontTexel = tex2D( FontTexture, In.TexCoord0 ); + return FontTexel; + } +); diff --git a/gfx/drivers/d3d_shaders/opaque.cg.d3d9.h b/gfx/drivers/d3d_shaders/opaque.cg.d3d9.h index 3c4c5566d9..3b9869049e 100644 --- a/gfx/drivers/d3d_shaders/opaque.cg.d3d9.h +++ b/gfx/drivers/d3d_shaders/opaque.cg.d3d9.h @@ -1,23 +1,26 @@ -static const char *stock_cg_d3d9_program = - "void main_vertex" - "(" - " float4 position : POSITION," - " float2 texCoord : TEXCOORD0," - " float4 color : COLOR," - "" - " uniform float4x4 modelViewProj," - "" - " out float4 oPosition : POSITION," - " out float2 otexCoord : TEXCOORD0," - " out float4 oColor : COLOR" - ")" - "{" - " oPosition = mul(modelViewProj, position);" - " otexCoord = texCoord;" - " oColor = color;" - "}" - "" - "float4 main_fragment(in float4 color : COLOR, float2 tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0) : COLOR" - "{" - " return color * tex2D(s0, tex);" - "}"; +#include "shaders_common.h" + +static const char *stock_cg_d3d9_program = CG( + void main_vertex + ( + float4 position : POSITION, + float2 texCoord : TEXCOORD0, + float4 color : COLOR, + + uniform float4x4 modelViewProj, + + out float4 oPosition : POSITION, + out float2 otexCoord : TEXCOORD0, + out float4 oColor : COLOR + ) + { + oPosition = mul(modelViewProj, position); + otexCoord = texCoord; + oColor = color; + } + + float4 main_fragment(in float4 color : COLOR, float2 tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0) : COLOR + { + return color * tex2D(s0, tex); + } +); diff --git a/gfx/drivers/d3d_shaders/opaque.hlsl.d3d9.h b/gfx/drivers/d3d_shaders/opaque.hlsl.d3d9.h index e5029c9d73..fb97c870cc 100644 --- a/gfx/drivers/d3d_shaders/opaque.hlsl.d3d9.h +++ b/gfx/drivers/d3d_shaders/opaque.hlsl.d3d9.h @@ -1,41 +1,44 @@ -static const char *stock_hlsl_program = - "void main_vertex\n" - "(\n" - " float4 position : POSITION,\n" - " float4 color : COLOR,\n" - "\n" - " uniform float4x4 modelViewProj,\n" - "\n" - " float4 texCoord : TEXCOORD0,\n" - " out float4 oPosition : POSITION,\n" - " out float4 oColor : COLOR,\n" - " out float2 otexCoord : TEXCOORD\n" - ")\n" - "{\n" - " oPosition = mul(modelViewProj, position);\n" - " oColor = color;\n" - " otexCoord = texCoord;\n" - "}\n" - "\n" - "struct output\n" - "{\n" - " float4 color: COLOR;\n" - "};\n" - "\n" - "struct input\n" - "{\n" - " float2 video_size;\n" - " float2 texture_size;\n" - " float2 output_size;\n" - " float frame_count;\n" - " float frame_direction;\n" - " float frame_rotation;\n" - "};\n" - "\n" - "output main_fragment(float2 texCoord : TEXCOORD0,\n" - "uniform sampler2D decal : TEXUNIT0, uniform input IN)\n" - "{\n" - " output OUT;\n" - " OUT.color = tex2D(decal, texCoord);\n" - " return OUT;\n" - "}\n"; +#include "shaders_common.h" + +static const char *stock_hlsl_program = CG( + void main_vertex + ( + float4 position : POSITION, + float4 color : COLOR, + + uniform float4x4 modelViewProj, + + float4 texCoord : TEXCOORD0, + out float4 oPosition : POSITION, + out float4 oColor : COLOR, + out float2 otexCoord : TEXCOORD + ) + { + oPosition = mul(modelViewProj, position); + oColor = color; + otexCoord = texCoord; + } + + struct outpu + { + float4 color: COLOR; + }; + + struct input + { + float2 video_size; + float2 texture_size; + float2 output_size; + float frame_count; + float frame_direction; + float frame_rotation; + }; + + output main_fragment(float2 texCoord : TEXCOORD0, + uniform sampler2D decal : TEXUNIT0, uniform input IN) + { + output OUT; + OUT.color = tex2D(decal, texCoord); + return OUT; + } +); diff --git a/gfx/drivers/d3d_shaders/shaders_common.h b/gfx/drivers/d3d_shaders/shaders_common.h new file mode 100644 index 0000000000..ce09b6eed8 --- /dev/null +++ b/gfx/drivers/d3d_shaders/shaders_common.h @@ -0,0 +1,15 @@ +#ifndef _SHADERS_COMMON +#define _SHADERS_COMMON + +#if defined(HAVE_OPENGLES) +#define CG(src) "" #src +#define GLSL(src) "precision mediump float;\n" #src +#define GLSL_330(src) "#version 330 es\nprecision mediump float;\n" #src +#else +#define CG(src) "" #src +#define GLSL(src) "" #src +#define GLSL_300(src) "#version 300 es\n" #src +#define GLSL_330(src) "#version 330 core\n" #src +#endif + +#endif