(D3D) Cleanups of shaders

This commit is contained in:
twinaphex 2016-08-01 22:43:51 +02:00
parent 3787d9d691
commit c314077f1d
4 changed files with 122 additions and 94 deletions

View File

@ -1,30 +1,37 @@
static const char *font_hlsl_d3d9_program = #include "shaders_common.h"
"struct VS_IN\n"
"{\n" static const char *font_hlsl_d3d9_program = CG(
"float2 Pos : POSITION;\n" struct VS_IN
"float2 Tex : TEXCOORD0;\n" {
"};\n" float2 Pos : POSITION;
"struct VS_OUT\n" float2 Tex : TEXCOORD0;
"{\n" };
"float4 Position : POSITION;\n"
"float2 TexCoord0 : TEXCOORD0;\n" struct VS_OUT
"};\n" {
"uniform float4 Color : register(c1);\n" float4 Position : POSITION;
"uniform float2 TexScale : register(c2);\n" float2 TexCoord0 : TEXCOORD0;
"sampler FontTexture : register(s0);\n" };
"VS_OUT main_vertex( VS_IN In )\n"
"{\n" uniform float4 Color : register(c1);
"VS_OUT Out;\n" uniform float2 TexScale : register(c2);
"Out.Position.x = (In.Pos.x-0.5);\n" sampler FontTexture : register(s0);
"Out.Position.y = (In.Pos.y-0.5);\n"
"Out.Position.z = ( 0.0 );\n" VS_OUT main_vertex( VS_IN In )
"Out.Position.w = ( 1.0 );\n" {
"Out.TexCoord0.x = In.Tex.x * TexScale.x;\n" VS_OUT Out;
"Out.TexCoord0.y = In.Tex.y * TexScale.y;\n" Out.Position.x = (In.Pos.x-0.5);
"return Out;\n" Out.Position.y = (In.Pos.y-0.5);
"}\n" Out.Position.z = ( 0.0 );
"float4 main_fragment( VS_OUT In ) : COLOR0\n" Out.Position.w = ( 1.0 );
"{\n" Out.TexCoord0.x = In.Tex.x * TexScale.x;
"float4 FontTexel = tex2D( FontTexture, In.TexCoord0 );\n" Out.TexCoord0.y = In.Tex.y * TexScale.y;
"return FontTexel;\n" return Out;
"}\n"; }
float4 main_fragment( VS_OUT In ) : COLOR0
{
float4 FontTexel = tex2D( FontTexture, In.TexCoord0 );
return FontTexel;
}
);

View File

@ -1,23 +1,26 @@
static const char *stock_cg_d3d9_program = #include "shaders_common.h"
"void main_vertex"
"(" static const char *stock_cg_d3d9_program = CG(
" float4 position : POSITION," void main_vertex
" float2 texCoord : TEXCOORD0," (
" float4 color : COLOR," float4 position : POSITION,
"" float2 texCoord : TEXCOORD0,
" uniform float4x4 modelViewProj," float4 color : COLOR,
""
" out float4 oPosition : POSITION," uniform float4x4 modelViewProj,
" out float2 otexCoord : TEXCOORD0,"
" out float4 oColor : COLOR" out float4 oPosition : POSITION,
")" out float2 otexCoord : TEXCOORD0,
"{" out float4 oColor : COLOR
" oPosition = mul(modelViewProj, position);" )
" otexCoord = texCoord;" {
" 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);" float4 main_fragment(in float4 color : COLOR, float2 tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0) : COLOR
"}"; {
return color * tex2D(s0, tex);
}
);

View File

@ -1,41 +1,44 @@
static const char *stock_hlsl_program = #include "shaders_common.h"
"void main_vertex\n"
"(\n" static const char *stock_hlsl_program = CG(
" float4 position : POSITION,\n" void main_vertex
" float4 color : COLOR,\n" (
"\n" float4 position : POSITION,
" uniform float4x4 modelViewProj,\n" float4 color : COLOR,
"\n"
" float4 texCoord : TEXCOORD0,\n" uniform float4x4 modelViewProj,
" out float4 oPosition : POSITION,\n"
" out float4 oColor : COLOR,\n" float4 texCoord : TEXCOORD0,
" out float2 otexCoord : TEXCOORD\n" out float4 oPosition : POSITION,
")\n" out float4 oColor : COLOR,
"{\n" out float2 otexCoord : TEXCOORD
" oPosition = mul(modelViewProj, position);\n" )
" oColor = color;\n" {
" otexCoord = texCoord;\n" oPosition = mul(modelViewProj, position);
"}\n" oColor = color;
"\n" otexCoord = texCoord;
"struct output\n" }
"{\n"
" float4 color: COLOR;\n" struct outpu
"};\n" {
"\n" float4 color: COLOR;
"struct input\n" };
"{\n"
" float2 video_size;\n" struct input
" float2 texture_size;\n" {
" float2 output_size;\n" float2 video_size;
" float frame_count;\n" float2 texture_size;
" float frame_direction;\n" float2 output_size;
" float frame_rotation;\n" float frame_count;
"};\n" float frame_direction;
"\n" float frame_rotation;
"output main_fragment(float2 texCoord : TEXCOORD0,\n" };
"uniform sampler2D decal : TEXUNIT0, uniform input IN)\n"
"{\n" output main_fragment(float2 texCoord : TEXCOORD0,
" output OUT;\n" uniform sampler2D decal : TEXUNIT0, uniform input IN)
" OUT.color = tex2D(decal, texCoord);\n" {
" return OUT;\n" output OUT;
"}\n"; OUT.color = tex2D(decal, texCoord);
return OUT;
}
);

View File

@ -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