From 8c70c2a136d6412e27550c1c2584d972f9d9812a Mon Sep 17 00:00:00 2001 From: aap Date: Wed, 18 Nov 2020 10:32:18 +0100 Subject: [PATCH] changes to librw layer, GLES now runtime choice --- src/extras/custompipes_gl.cpp | 45 +++------- src/extras/postfx.cpp | 18 +--- src/extras/shaders/Makefile | 58 ++++++------- src/extras/shaders/colourfilterVC.frag | 13 +-- src/extras/shaders/colourfilterVC_fs_gl.inc | 29 +++++++ src/extras/shaders/contrast.frag | 11 +-- src/extras/shaders/contrast_fs_gl.inc | 21 +++++ src/extras/shaders/default_UV2.vert | 14 ++-- src/extras/shaders/default_UV2_gl.inc | 27 ++++++ src/extras/shaders/im2d.vert | 10 +-- src/extras/shaders/im2d_gl.inc | 21 +++++ src/extras/shaders/neoGloss.frag | 14 ++-- src/extras/shaders/neoGloss.vert | 14 ++-- src/extras/shaders/neoGloss_fs_gl.inc | 28 +++++++ src/extras/shaders/neoGloss_vs_gl.inc | 27 ++++++ src/extras/shaders/neoRim.vert | 11 +-- src/extras/shaders/neoRimSkin.vert | 13 +-- src/extras/shaders/neoRimSkin_gl.inc | 45 ++++++++++ src/extras/shaders/neoRim_gl.inc | 36 ++++++++ src/extras/shaders/neoVehicle.frag | 15 ++-- src/extras/shaders/neoVehicle.vert | 15 ++-- src/extras/shaders/neoVehicle_fs_gl.inc | 31 +++++++ src/extras/shaders/neoVehicle_vs_gl.inc | 53 ++++++++++++ src/extras/shaders/neoWorldVC.frag | 15 ++-- src/extras/shaders/neoWorldVC_fs_gl.inc | 28 +++++++ src/extras/shaders/simple.frag | 11 +-- src/extras/shaders/simple_fs_gl.inc | 19 +++++ src/fakerw/fake.cpp | 13 --- src/rw/TexRead.cpp | 93 ++++++++++++++++++++- vendor/librw | 2 +- 30 files changed, 568 insertions(+), 182 deletions(-) create mode 100644 src/extras/shaders/colourfilterVC_fs_gl.inc create mode 100644 src/extras/shaders/contrast_fs_gl.inc create mode 100644 src/extras/shaders/default_UV2_gl.inc create mode 100644 src/extras/shaders/im2d_gl.inc create mode 100644 src/extras/shaders/neoGloss_fs_gl.inc create mode 100644 src/extras/shaders/neoGloss_vs_gl.inc create mode 100644 src/extras/shaders/neoRimSkin_gl.inc create mode 100644 src/extras/shaders/neoRim_gl.inc create mode 100644 src/extras/shaders/neoVehicle_fs_gl.inc create mode 100644 src/extras/shaders/neoVehicle_vs_gl.inc create mode 100644 src/extras/shaders/neoWorldVC_fs_gl.inc create mode 100644 src/extras/shaders/simple_fs_gl.inc diff --git a/src/extras/custompipes_gl.cpp b/src/extras/custompipes_gl.cpp index dbd4d7d6..475680aa 100644 --- a/src/extras/custompipes_gl.cpp +++ b/src/extras/custompipes_gl.cpp @@ -158,13 +158,8 @@ CreateVehiclePipe(void) { -#ifdef RW_GLES2 -#include "gl2_shaders/neoVehicle_fs_gl2.inc" -#include "gl2_shaders/neoVehicle_vs_gl2.inc" -#else -#include "shaders/neoVehicle_fs_gl3.inc" -#include "shaders/neoVehicle_vs_gl3.inc" -#endif +#include "shaders/neoVehicle_fs_gl.inc" +#include "shaders/neoVehicle_vs_gl.inc" const char *vs[] = { shaderDecl, header_vert_src, neoVehicle_vert_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, neoVehicle_frag_src, nil }; neoVehicleShader = Shader::create(vs, fs); @@ -273,13 +268,8 @@ CreateWorldPipe(void) ReadTweakValueTable((char*)work_buff, WorldLightmapBlend); { -#ifdef RW_GLES2 -#include "gl2_shaders/neoWorldIII_fs_gl2.inc" -#include "gl2_shaders/default_UV2_gl2.inc" -#else -#include "shaders/neoWorldVC_fs_gl3.inc" -#include "shaders/default_UV2_gl3.inc" -#endif +#include "shaders/neoWorldVC_fs_gl.inc" +#include "shaders/default_UV2_gl.inc" const char *vs[] = { shaderDecl, header_vert_src, default_UV2_vert_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, neoWorldVC_frag_src, nil }; neoWorldShader = Shader::create(vs, fs); @@ -381,13 +371,8 @@ CreateGlossPipe(void) using namespace rw::gl3; { -#ifdef RW_GLES2 -#include "gl2_shaders/neoGloss_fs_gl2.inc" -#include "gl2_shaders/neoGloss_vs_gl2.inc" -#else -#include "shaders/neoGloss_fs_gl3.inc" -#include "shaders/neoGloss_vs_gl3.inc" -#endif +#include "shaders/neoGloss_fs_gl.inc" +#include "shaders/neoGloss_vs_gl.inc" const char *vs[] = { shaderDecl, header_vert_src, neoGloss_vert_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, neoGloss_frag_src, nil }; neoGlossShader = Shader::create(vs, fs); @@ -558,13 +543,8 @@ CreateRimLightPipes(void) } { -#ifdef RW_GLES2 -#include "gl2_shaders/simple_fs_gl2.inc" -#include "gl2_shaders/neoRimSkin_gl2.inc" -#else -#include "shaders/simple_fs_gl3.inc" -#include "shaders/neoRimSkin_gl3.inc" -#endif +#include "shaders/simple_fs_gl.inc" +#include "shaders/neoRimSkin_gl.inc" const char *vs[] = { shaderDecl, header_vert_src, neoRimSkin_vert_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil }; neoRimSkinShader = Shader::create(vs, fs); @@ -572,13 +552,8 @@ CreateRimLightPipes(void) } { -#ifdef RW_GLES2 -#include "gl2_shaders/simple_fs_gl2.inc" -#include "gl2_shaders/neoRim_gl2.inc" -#else -#include "shaders/simple_fs_gl3.inc" -#include "shaders/neoRim_gl3.inc" -#endif +#include "shaders/simple_fs_gl.inc" +#include "shaders/neoRim_gl.inc" const char *vs[] = { shaderDecl, header_vert_src, neoRim_vert_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil }; neoRimShader = Shader::create(vs, fs); diff --git a/src/extras/postfx.cpp b/src/extras/postfx.cpp index 7e9df4e7..f7b120a8 100644 --- a/src/extras/postfx.cpp +++ b/src/extras/postfx.cpp @@ -152,13 +152,8 @@ CPostFX::Open(RwCamera *cam) using namespace rw::gl3; { -#ifdef RW_GLES2 -#include "gl2_shaders/im2d_gl2.inc" -#include "gl2_shaders/colourfilterVC_fs_gl2.inc" -#else -#include "shaders/im2d_gl3.inc" -#include "shaders/colourfilterVC_fs_gl3.inc" -#endif +#include "shaders/im2d_gl.inc" +#include "shaders/colourfilterVC_fs_gl.inc" const char *vs[] = { shaderDecl, header_vert_src, im2d_vert_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, colourfilterVC_frag_src, nil }; colourFilterVC = Shader::create(vs, fs); @@ -166,17 +161,12 @@ CPostFX::Open(RwCamera *cam) } { -#ifdef RW_GLES2 -#include "gl2_shaders/im2d_gl2.inc" -#include "gl2_shaders/contrast_fs_gl2.inc" -#else -#include "shaders/im2d_gl3.inc" -#include "shaders/contrast_fs_gl3.inc" +#include "shaders/im2d_gl.inc" +#include "shaders/contrast_fs_gl.inc" const char *vs[] = { shaderDecl, header_vert_src, im2d_vert_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, contrast_frag_src, nil }; contrast = Shader::create(vs, fs); assert(contrast); -#endif } #endif diff --git a/src/extras/shaders/Makefile b/src/extras/shaders/Makefile index 605190c9..5260fc3a 100644 --- a/src/extras/shaders/Makefile +++ b/src/extras/shaders/Makefile @@ -1,67 +1,67 @@ -all: im2d_gl3.inc simple_fs_gl3.inc default_UV2_gl3.inc \ - colourfilterVC_fs_gl3.inc contrast_fs_gl3.inc \ - neoRim_gl3.inc neoRimSkin_gl3.inc \ - neoWorldVC_fs_gl3.inc neoGloss_vs_gl3.inc neoGloss_fs_gl3.inc \ - neoVehicle_vs_gl3.inc neoVehicle_fs_gl3.inc +all: im2d_gl.inc simple_fs_gl.inc default_UV2_gl.inc \ + colourfilterVC_fs_gl.inc contrast_fs_gl.inc \ + neoRim_gl.inc neoRimSkin_gl.inc \ + neoWorldVC_fs_gl.inc neoGloss_vs_gl.inc neoGloss_fs_gl.inc \ + neoVehicle_vs_gl.inc neoVehicle_fs_gl.inc -im2d_gl3.inc: im2d.vert +im2d_gl.inc: im2d.vert (echo 'const char *im2d_vert_src =';\ sed 's/..*/"&\\n"/' im2d.vert;\ - echo ';') >im2d_gl3.inc + echo ';') >im2d_gl.inc -colourfilterVC_fs_gl3.inc: colourfilterVC.frag +colourfilterVC_fs_gl.inc: colourfilterVC.frag (echo 'const char *colourfilterVC_frag_src =';\ sed 's/..*/"&\\n"/' colourfilterVC.frag;\ - echo ';') >colourfilterVC_fs_gl3.inc -simple_fs_gl3.inc: simple.frag + echo ';') >colourfilterVC_fs_gl.inc +simple_fs_gl.inc: simple.frag (echo 'const char *simple_frag_src =';\ sed 's/..*/"&\\n"/' simple.frag;\ - echo ';') >simple_fs_gl3.inc + echo ';') >simple_fs_gl.inc -default_UV2_gl3.inc: default_UV2.vert +default_UV2_gl.inc: default_UV2.vert (echo 'const char *default_UV2_vert_src =';\ sed 's/..*/"&\\n"/' default_UV2.vert;\ - echo ';') >default_UV2_gl3.inc + echo ';') >default_UV2_gl.inc -contrast_fs_gl3.inc: contrast.frag +contrast_fs_gl.inc: contrast.frag (echo 'const char *contrast_frag_src =';\ sed 's/..*/"&\\n"/' contrast.frag;\ - echo ';') >contrast_fs_gl3.inc + echo ';') >contrast_fs_gl.inc -neoRim_gl3.inc: neoRim.vert +neoRim_gl.inc: neoRim.vert (echo 'const char *neoRim_vert_src =';\ sed 's/..*/"&\\n"/' neoRim.vert;\ - echo ';') >neoRim_gl3.inc + echo ';') >neoRim_gl.inc -neoRimSkin_gl3.inc: neoRimSkin.vert +neoRimSkin_gl.inc: neoRimSkin.vert (echo 'const char *neoRimSkin_vert_src =';\ sed 's/..*/"&\\n"/' neoRimSkin.vert;\ - echo ';') >neoRimSkin_gl3.inc + echo ';') >neoRimSkin_gl.inc -neoWorldVC_fs_gl3.inc: neoWorldVC.frag +neoWorldVC_fs_gl.inc: neoWorldVC.frag (echo 'const char *neoWorldVC_frag_src =';\ sed 's/..*/"&\\n"/' neoWorldVC.frag;\ - echo ';') >neoWorldVC_fs_gl3.inc + echo ';') >neoWorldVC_fs_gl.inc -neoGloss_fs_gl3.inc: neoGloss.frag +neoGloss_fs_gl.inc: neoGloss.frag (echo 'const char *neoGloss_frag_src =';\ sed 's/..*/"&\\n"/' neoGloss.frag;\ - echo ';') >neoGloss_fs_gl3.inc + echo ';') >neoGloss_fs_gl.inc -neoGloss_vs_gl3.inc: neoGloss.vert +neoGloss_vs_gl.inc: neoGloss.vert (echo 'const char *neoGloss_vert_src =';\ sed 's/..*/"&\\n"/' neoGloss.vert;\ - echo ';') >neoGloss_vs_gl3.inc + echo ';') >neoGloss_vs_gl.inc -neoVehicle_vs_gl3.inc: neoVehicle.vert +neoVehicle_vs_gl.inc: neoVehicle.vert (echo 'const char *neoVehicle_vert_src =';\ sed 's/..*/"&\\n"/' neoVehicle.vert;\ - echo ';') >neoVehicle_vs_gl3.inc + echo ';') >neoVehicle_vs_gl.inc -neoVehicle_fs_gl3.inc: neoVehicle.frag +neoVehicle_fs_gl.inc: neoVehicle.frag (echo 'const char *neoVehicle_frag_src =';\ sed 's/..*/"&\\n"/' neoVehicle.frag;\ - echo ';') >neoVehicle_fs_gl3.inc + echo ';') >neoVehicle_fs_gl.inc diff --git a/src/extras/shaders/colourfilterVC.frag b/src/extras/shaders/colourfilterVC.frag index 5069af52..9db3950e 100644 --- a/src/extras/shaders/colourfilterVC.frag +++ b/src/extras/shaders/colourfilterVC.frag @@ -1,17 +1,15 @@ uniform sampler2D tex0; uniform vec4 u_blurcolor; -in vec4 v_color; -in vec2 v_tex0; -in float v_fog; - -out vec4 color; +FSIN vec4 v_color; +FSIN vec2 v_tex0; +FSIN float v_fog; void main(void) { float a = u_blurcolor.a; - vec4 doublec = clamp(u_blurcolor*2, 0.0, 1.0); + vec4 doublec = clamp(u_blurcolor*2.0, 0.0, 1.0); vec4 dst = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); vec4 prev = dst; for(int i = 0; i < 5; i++){ @@ -20,7 +18,10 @@ main(void) tmp += prev*u_blurcolor; prev = clamp(tmp, 0.0, 1.0); } + vec4 color; color.rgb = prev.rgb; color.a = 1.0f; + + FRAGCOLOR(color); } diff --git a/src/extras/shaders/colourfilterVC_fs_gl.inc b/src/extras/shaders/colourfilterVC_fs_gl.inc new file mode 100644 index 00000000..1f9bf6d8 --- /dev/null +++ b/src/extras/shaders/colourfilterVC_fs_gl.inc @@ -0,0 +1,29 @@ +const char *colourfilterVC_frag_src = +"uniform sampler2D tex0;\n" +"uniform vec4 u_blurcolor;\n" + +"FSIN vec4 v_color;\n" +"FSIN vec2 v_tex0;\n" +"FSIN float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" float a = u_blurcolor.a;\n" +" vec4 doublec = clamp(u_blurcolor*2.0, 0.0, 1.0);\n" +" vec4 dst = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" +" vec4 prev = dst;\n" +" for(int i = 0; i < 5; i++){\n" +" vec4 tmp = dst*(1.0-a) + prev*doublec*a;\n" +" tmp += prev*u_blurcolor;\n" +" tmp += prev*u_blurcolor;\n" +" prev = clamp(tmp, 0.0, 1.0);\n" +" }\n" +" vec4 color;\n" +" color.rgb = prev.rgb;\n" +" color.a = 1.0f;\n" + +" FRAGCOLOR(color);\n" +"}\n" + +; diff --git a/src/extras/shaders/contrast.frag b/src/extras/shaders/contrast.frag index d6dec478..1b93f6fe 100644 --- a/src/extras/shaders/contrast.frag +++ b/src/extras/shaders/contrast.frag @@ -2,17 +2,18 @@ uniform sampler2D tex0; uniform vec3 u_contrastAdd; uniform vec3 u_contrastMult; -in vec4 v_color; -in vec2 v_tex0; -in float v_fog; - -out vec4 color; +FSIN vec4 v_color; +FSIN vec2 v_tex0; +FSIN float v_fog; void main(void) { vec4 dst = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); + vec4 color; color.rgb = dst.rgb*u_contrastMult + u_contrastAdd; color.a = 1.0f; + + FRAGCOLOR(color); } diff --git a/src/extras/shaders/contrast_fs_gl.inc b/src/extras/shaders/contrast_fs_gl.inc new file mode 100644 index 00000000..97f78194 --- /dev/null +++ b/src/extras/shaders/contrast_fs_gl.inc @@ -0,0 +1,21 @@ +const char *contrast_frag_src = +"uniform sampler2D tex0;\n" +"uniform vec3 u_contrastAdd;\n" +"uniform vec3 u_contrastMult;\n" + +"FSIN vec4 v_color;\n" +"FSIN vec2 v_tex0;\n" +"FSIN float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 dst = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" +" vec4 color;\n" +" color.rgb = dst.rgb*u_contrastMult + u_contrastAdd;\n" +" color.a = 1.0f;\n" + +" FRAGCOLOR(color);\n" +"}\n" + +; diff --git a/src/extras/shaders/default_UV2.vert b/src/extras/shaders/default_UV2.vert index 3dbad20f..694c012b 100644 --- a/src/extras/shaders/default_UV2.vert +++ b/src/extras/shaders/default_UV2.vert @@ -1,13 +1,9 @@ -layout(location = 0) in vec3 in_pos; -layout(location = 1) in vec3 in_normal; -layout(location = 2) in vec4 in_color; -layout(location = 3) in vec2 in_tex0; -layout(location = 4) in vec2 in_tex1; +VSIN(ATTRIB_POS) vec3 in_pos; -out vec4 v_color; -out vec2 v_tex0; -out vec2 v_tex1; -out float v_fog; +VSOUT vec4 v_color; +VSOUT vec2 v_tex0; +VSOUT vec2 v_tex1; +VSOUT float v_fog; void main(void) diff --git a/src/extras/shaders/default_UV2_gl.inc b/src/extras/shaders/default_UV2_gl.inc new file mode 100644 index 00000000..450f3d9a --- /dev/null +++ b/src/extras/shaders/default_UV2_gl.inc @@ -0,0 +1,27 @@ +const char *default_UV2_vert_src = +"VSIN(ATTRIB_POS) vec3 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT vec2 v_tex1;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 Vertex = u_world * vec4(in_pos, 1.0);\n" +" gl_Position = u_proj * u_view * Vertex;\n" +" vec3 Normal = mat3(u_world) * in_normal;\n" + +" v_tex0 = in_tex0;\n" +" v_tex1 = in_tex1;\n" + +" v_color = in_color;\n" +" v_color.rgb += u_ambLight.rgb*surfAmbient;\n" +" v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse;\n" +" v_color = clamp(v_color, 0.0, 1.0);\n" +" v_color *= u_matColor;\n" + +" v_fog = DoFog(gl_Position.w);\n" +"}\n" +; diff --git a/src/extras/shaders/im2d.vert b/src/extras/shaders/im2d.vert index 241593b1..fcd81c2c 100644 --- a/src/extras/shaders/im2d.vert +++ b/src/extras/shaders/im2d.vert @@ -1,12 +1,10 @@ uniform vec4 u_xform; -layout(location = 0) in vec4 in_pos; -layout(location = 2) in vec4 in_color; -layout(location = 3) in vec2 in_tex0; +VSIN(ATTRIB_POS) vec4 in_pos; -out vec4 v_color; -out vec2 v_tex0; -out float v_fog; +VSOUT vec4 v_color; +VSOUT vec2 v_tex0; +VSOUT float v_fog; void main(void) diff --git a/src/extras/shaders/im2d_gl.inc b/src/extras/shaders/im2d_gl.inc new file mode 100644 index 00000000..d11f5d33 --- /dev/null +++ b/src/extras/shaders/im2d_gl.inc @@ -0,0 +1,21 @@ +const char *im2d_vert_src = +"uniform vec4 u_xform;\n" + +"VSIN(ATTRIB_POS) vec4 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" gl_Position = in_pos;\n" +" gl_Position.w = 1.0;\n" +" gl_Position.xy = gl_Position.xy * u_xform.xy + u_xform.zw;\n" +" v_fog = DoFog(gl_Position.z);\n" +" gl_Position.xyz *= gl_Position.w;\n" +" v_color = in_color;\n" +" v_tex0 = in_tex0;\n" +"}\n" +; diff --git a/src/extras/shaders/neoGloss.frag b/src/extras/shaders/neoGloss.frag index 14ef0e15..4f097b0b 100644 --- a/src/extras/shaders/neoGloss.frag +++ b/src/extras/shaders/neoGloss.frag @@ -4,17 +4,15 @@ uniform vec4 u_reflProps; #define glossMult (u_reflProps.x) -in vec3 v_normal; -in vec3 v_light; -in vec2 v_tex0; -in float v_fog; - -out vec4 color; +FSIN vec3 v_normal; +FSIN vec3 v_light; +FSIN vec2 v_tex0; +FSIN float v_fog; void main(void) { - color = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); + vec4 color = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); vec3 n = 2.0*v_normal-1.0; // unpack vec3 v = 2.0*v_light-1.0; // @@ -22,5 +20,7 @@ main(void) color = s*s*s*s*s*s*s*s*color*v_fog*glossMult; DoAlphaTest(color.a); + + FRAGCOLOR(color); } diff --git a/src/extras/shaders/neoGloss.vert b/src/extras/shaders/neoGloss.vert index 78dd1b33..41102f3f 100644 --- a/src/extras/shaders/neoGloss.vert +++ b/src/extras/shaders/neoGloss.vert @@ -1,15 +1,11 @@ uniform vec3 u_eye; +VSIN(ATTRIB_POS) vec3 in_pos; -layout(location = 0) in vec3 in_pos; -layout(location = 1) in vec3 in_normal; -layout(location = 2) in vec4 in_color; -layout(location = 3) in vec2 in_tex0; - -out vec3 v_normal; -out vec3 v_light; -out vec2 v_tex0; -out float v_fog; +VSOUT vec3 v_normal; +VSOUT vec3 v_light; +VSOUT vec2 v_tex0; +VSOUT float v_fog; void main(void) diff --git a/src/extras/shaders/neoGloss_fs_gl.inc b/src/extras/shaders/neoGloss_fs_gl.inc new file mode 100644 index 00000000..67e9724e --- /dev/null +++ b/src/extras/shaders/neoGloss_fs_gl.inc @@ -0,0 +1,28 @@ +const char *neoGloss_frag_src = +"uniform sampler2D tex0;\n" + +"uniform vec4 u_reflProps;\n" + +"#define glossMult (u_reflProps.x)\n" + +"FSIN vec3 v_normal;\n" +"FSIN vec3 v_light;\n" +"FSIN vec2 v_tex0;\n" +"FSIN float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 color = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" +" vec3 n = 2.0*v_normal-1.0; // unpack\n" +" vec3 v = 2.0*v_light-1.0; //\n" + +" float s = dot(n, v);\n" +" color = s*s*s*s*s*s*s*s*color*v_fog*glossMult;\n" + +" DoAlphaTest(color.a);\n" + +" FRAGCOLOR(color);\n" +"}\n" + +; diff --git a/src/extras/shaders/neoGloss_vs_gl.inc b/src/extras/shaders/neoGloss_vs_gl.inc new file mode 100644 index 00000000..dffb423f --- /dev/null +++ b/src/extras/shaders/neoGloss_vs_gl.inc @@ -0,0 +1,27 @@ +const char *neoGloss_vert_src = +"uniform vec3 u_eye;\n" + +"VSIN(ATTRIB_POS) vec3 in_pos;\n" + +"VSOUT vec3 v_normal;\n" +"VSOUT vec3 v_light;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 Vertex = u_world * vec4(in_pos, 1.0);\n" +" gl_Position = u_proj * u_view * Vertex;\n" +" vec3 Normal = mat3(u_world) * in_normal;\n" + +" v_tex0 = in_tex0;\n" + +" vec3 viewVec = normalize(u_eye - Vertex.xyz);\n" +" vec3 Light = normalize(viewVec - u_lightDirection[0].xyz);\n" +" v_normal = 0.5*(1.0 + vec3(0.0, 0.0, 1.0)); // compress\n" +" v_light = 0.5*(1.0 + Light); //\n" + +" v_fog = DoFog(gl_Position.w);\n" +"}\n" +; diff --git a/src/extras/shaders/neoRim.vert b/src/extras/shaders/neoRim.vert index 4a2b545f..81ee1090 100644 --- a/src/extras/shaders/neoRim.vert +++ b/src/extras/shaders/neoRim.vert @@ -3,14 +3,11 @@ uniform vec4 u_rampStart; uniform vec4 u_rampEnd; uniform vec3 u_rimData; -layout(location = 0) in vec3 in_pos; -layout(location = 1) in vec3 in_normal; -layout(location = 2) in vec4 in_color; -layout(location = 3) in vec2 in_tex0; +VSIN(ATTRIB_POS) vec3 in_pos; -out vec4 v_color; -out vec2 v_tex0; -out float v_fog; +VSOUT vec4 v_color; +VSOUT vec2 v_tex0; +VSOUT float v_fog; void main(void) diff --git a/src/extras/shaders/neoRimSkin.vert b/src/extras/shaders/neoRimSkin.vert index f16f2310..1515ad71 100644 --- a/src/extras/shaders/neoRimSkin.vert +++ b/src/extras/shaders/neoRimSkin.vert @@ -5,16 +5,11 @@ uniform vec4 u_rampStart; uniform vec4 u_rampEnd; uniform vec3 u_rimData; -layout(location = 0) in vec3 in_pos; -layout(location = 1) in vec3 in_normal; -layout(location = 2) in vec4 in_color; -layout(location = 3) in vec2 in_tex0; -layout(location = 11) in vec4 in_weights; -layout(location = 12) in vec4 in_indices; +VSIN(ATTRIB_POS) vec3 in_pos; -out vec4 v_color; -out vec2 v_tex0; -out float v_fog; +VSOUT vec4 v_color; +VSOUT vec2 v_tex0; +VSOUT float v_fog; void main(void) diff --git a/src/extras/shaders/neoRimSkin_gl.inc b/src/extras/shaders/neoRimSkin_gl.inc new file mode 100644 index 00000000..01b739b2 --- /dev/null +++ b/src/extras/shaders/neoRimSkin_gl.inc @@ -0,0 +1,45 @@ +const char *neoRimSkin_vert_src = +"uniform mat4 u_boneMatrices[64];\n" + +"uniform vec3 u_viewVec;\n" +"uniform vec4 u_rampStart;\n" +"uniform vec4 u_rampEnd;\n" +"uniform vec3 u_rimData;\n" + +"VSIN(ATTRIB_POS) vec3 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec3 SkinVertex = vec3(0.0, 0.0, 0.0);\n" +" vec3 SkinNormal = vec3(0.0, 0.0, 0.0);\n" +" for(int i = 0; i < 4; i++){\n" +" SkinVertex += (u_boneMatrices[int(in_indices[i])] * vec4(in_pos, 1.0)).xyz * in_weights[i];\n" +" SkinNormal += (mat3(u_boneMatrices[int(in_indices[i])]) * in_normal) * in_weights[i];\n" +" }\n" + +" vec4 Vertex = u_world * vec4(SkinVertex, 1.0);\n" +" gl_Position = u_proj * u_view * Vertex;\n" +" vec3 Normal = mat3(u_world) * SkinNormal;\n" + +" v_tex0 = in_tex0;\n" + +" v_color = in_color;\n" +" v_color.rgb += u_ambLight.rgb*surfAmbient;\n" +" v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse;\n" + +" // rim light\n" +" float f = u_rimData.x - u_rimData.y*dot(Normal, u_viewVec);\n" +" vec4 rimlight = clamp(mix(u_rampEnd, u_rampStart, f)*u_rimData.z, 0.0, 1.0);\n" +" v_color.rgb += rimlight.rgb;\n" + +" v_color = clamp(v_color, 0.0, 1.0);\n" +" v_color *= u_matColor;\n" + +" v_fog = DoFog(gl_Position.z);\n" +"}\n" +; diff --git a/src/extras/shaders/neoRim_gl.inc b/src/extras/shaders/neoRim_gl.inc new file mode 100644 index 00000000..7cd199d0 --- /dev/null +++ b/src/extras/shaders/neoRim_gl.inc @@ -0,0 +1,36 @@ +const char *neoRim_vert_src = +"uniform vec3 u_viewVec;\n" +"uniform vec4 u_rampStart;\n" +"uniform vec4 u_rampEnd;\n" +"uniform vec3 u_rimData;\n" + +"VSIN(ATTRIB_POS) vec3 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 Vertex = u_world * vec4(in_pos, 1.0);\n" +" gl_Position = u_proj * u_view * Vertex;\n" +" vec3 Normal = mat3(u_world) * in_normal;\n" + +" v_tex0 = in_tex0;\n" + +" v_color = in_color;\n" +" v_color.rgb += u_ambLight.rgb*surfAmbient;\n" +" v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse;\n" + +" // rim light\n" +" float f = u_rimData.x - u_rimData.y*dot(Normal, u_viewVec);\n" +" vec4 rimlight = clamp(mix(u_rampEnd, u_rampStart, f)*u_rimData.z, 0.0, 1.0);\n" +" v_color.rgb += rimlight.rgb;\n" + +" v_color = clamp(v_color, 0.0, 1.0);\n" +" v_color *= u_matColor;\n" + +" v_fog = DoFog(gl_Position.w);\n" +"}\n" +; diff --git a/src/extras/shaders/neoVehicle.frag b/src/extras/shaders/neoVehicle.frag index 96d4a632..2ac24f70 100644 --- a/src/extras/shaders/neoVehicle.frag +++ b/src/extras/shaders/neoVehicle.frag @@ -1,13 +1,11 @@ uniform sampler2D tex0; uniform sampler2D tex1; -in vec4 v_color; -in vec4 v_reflcolor; -in vec2 v_tex0; -in vec2 v_tex1; -in float v_fog; - -out vec4 color; +FSIN vec4 v_color; +FSIN vec4 v_reflcolor; +FSIN vec2 v_tex0; +FSIN vec2 v_tex1; +FSIN float v_fog; void main(void) @@ -20,9 +18,12 @@ main(void) vec3 pass2 = v_reflcolor.rgb * v_fog; + vec4 color; color.rgb = pass1.rgb*pass1.a + pass2; color.a = pass1.a; // color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog); DoAlphaTest(color.a); + + FRAGCOLOR(color); } diff --git a/src/extras/shaders/neoVehicle.vert b/src/extras/shaders/neoVehicle.vert index f2f54d6d..f0224ddb 100644 --- a/src/extras/shaders/neoVehicle.vert +++ b/src/extras/shaders/neoVehicle.vert @@ -8,16 +8,13 @@ uniform vec4 u_specColor[5]; #define shininess (u_reflProps.z) #define specularity (u_reflProps.w) -layout(location = 0) in vec3 in_pos; -layout(location = 1) in vec3 in_normal; -layout(location = 2) in vec4 in_color; -layout(location = 3) in vec2 in_tex0; +VSIN(ATTRIB_POS) vec3 in_pos; -out vec4 v_color; -out vec4 v_reflcolor; -out vec2 v_tex0; -out vec2 v_tex1; -out float v_fog; +VSOUT vec4 v_color; +VSOUT vec4 v_reflcolor; +VSOUT vec2 v_tex0; +VSOUT vec2 v_tex1; +VSOUT float v_fog; vec3 DoDirLightSpec(vec3 Ldir, vec3 Lcol, vec3 N, vec3 V, float power) { diff --git a/src/extras/shaders/neoVehicle_fs_gl.inc b/src/extras/shaders/neoVehicle_fs_gl.inc new file mode 100644 index 00000000..20537440 --- /dev/null +++ b/src/extras/shaders/neoVehicle_fs_gl.inc @@ -0,0 +1,31 @@ +const char *neoVehicle_frag_src = +"uniform sampler2D tex0;\n" +"uniform sampler2D tex1;\n" + +"FSIN vec4 v_color;\n" +"FSIN vec4 v_reflcolor;\n" +"FSIN vec2 v_tex0;\n" +"FSIN vec2 v_tex1;\n" +"FSIN float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 pass1 = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" +" vec3 envmap = texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y)).rgb;\n" +" pass1.rgb = mix(pass1.rgb, envmap, v_reflcolor.a);\n" +" pass1.rgb = mix(u_fogColor.rgb, pass1.rgb, v_fog);\n" +"// pass1.rgb += v_reflcolor.rgb * v_fog;\n" + +" vec3 pass2 = v_reflcolor.rgb * v_fog;\n" + +" vec4 color;\n" +" color.rgb = pass1.rgb*pass1.a + pass2;\n" +" color.a = pass1.a;\n" + +"// color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n" +" DoAlphaTest(color.a);\n" + +" FRAGCOLOR(color);\n" +"}\n" +; diff --git a/src/extras/shaders/neoVehicle_vs_gl.inc b/src/extras/shaders/neoVehicle_vs_gl.inc new file mode 100644 index 00000000..b7b42622 --- /dev/null +++ b/src/extras/shaders/neoVehicle_vs_gl.inc @@ -0,0 +1,53 @@ +const char *neoVehicle_vert_src = +"uniform vec3 u_eye;\n" +"uniform vec4 u_reflProps;\n" +"uniform vec4 u_specDir[5];\n" +"uniform vec4 u_specColor[5];\n" + +"#define fresnel (u_reflProps.x)\n" +"#define lightStrength (u_reflProps.y) // speclight alpha\n" +"#define shininess (u_reflProps.z)\n" +"#define specularity (u_reflProps.w)\n" + +"VSIN(ATTRIB_POS) vec3 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec4 v_reflcolor;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT vec2 v_tex1;\n" +"VSOUT float v_fog;\n" + +"vec3 DoDirLightSpec(vec3 Ldir, vec3 Lcol, vec3 N, vec3 V, float power)\n" +"{\n" +" return pow(clamp(dot(N, normalize(V + -Ldir)), 0.0, 1.0), power)*Lcol;\n" +"}\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 Vertex = u_world * vec4(in_pos, 1.0);\n" +" gl_Position = u_proj * u_view * Vertex;\n" +" vec3 Normal = mat3(u_world) * in_normal;\n" +" vec3 viewVec = normalize(u_eye - Vertex.xyz);\n" + +" v_tex0 = in_tex0;\n" + +" v_color = in_color;\n" +" v_color.rgb += u_ambLight.rgb*surfAmbient;\n" +" v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse*lightStrength;\n" +" v_color = clamp(v_color, 0.0, 1.0);\n" +" v_color *= u_matColor;\n" + +" // reflect V along Normal\n" +" vec3 uv2 = Normal*dot(viewVec, Normal)*2.0 - viewVec;\n" +" v_tex1 = uv2.xy*0.5 + 0.5;\n" +" float b = 1.0 - clamp(dot(viewVec, Normal), 0.0, 1.0);\n" +" v_reflcolor = vec4(0.0, 0.0, 0.0, 1.0);\n" +" v_reflcolor.a = mix(b*b*b*b*b, 1.0f, fresnel)*shininess;\n" + +" for(int i = 0; i < 5; i++)\n" +" v_reflcolor.rgb += DoDirLightSpec(u_specDir[i].xyz, u_specColor[i].rgb, Normal, viewVec, u_specDir[i].w)*specularity*lightStrength;\n" + +" v_fog = DoFog(gl_Position.w);\n" +"}\n" +; diff --git a/src/extras/shaders/neoWorldVC.frag b/src/extras/shaders/neoWorldVC.frag index 0270f305..08cae743 100644 --- a/src/extras/shaders/neoWorldVC.frag +++ b/src/extras/shaders/neoWorldVC.frag @@ -3,12 +3,10 @@ uniform sampler2D tex1; uniform vec4 u_lightMap; -in vec4 v_color; -in vec2 v_tex0; -in vec2 v_tex1; -in float v_fog; - -out vec4 color; +FSIN vec4 v_color; +FSIN vec2 v_tex0; +FSIN vec2 v_tex1; +FSIN float v_fog; void main(void) @@ -16,10 +14,13 @@ main(void) vec4 t0 = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); vec4 t1 = texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y)); - color = t0*v_color*(1 + u_lightMap*(t1-1)); + vec4 color; + color = t0*v_color*(1.0 + u_lightMap*(t1-1.0)); color.a = v_color.a*t0.a*u_lightMap.a; color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog); DoAlphaTest(color.a); + + FRAGCOLOR(color); } diff --git a/src/extras/shaders/neoWorldVC_fs_gl.inc b/src/extras/shaders/neoWorldVC_fs_gl.inc new file mode 100644 index 00000000..b4385fc7 --- /dev/null +++ b/src/extras/shaders/neoWorldVC_fs_gl.inc @@ -0,0 +1,28 @@ +const char *neoWorldVC_frag_src = +"uniform sampler2D tex0;\n" +"uniform sampler2D tex1;\n" + +"uniform vec4 u_lightMap;\n" + +"FSIN vec4 v_color;\n" +"FSIN vec2 v_tex0;\n" +"FSIN vec2 v_tex1;\n" +"FSIN float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 t0 = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" +" vec4 t1 = texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y));\n" + +" vec4 color;\n" +" color = t0*v_color*(1.0 + u_lightMap*(t1-1.0));\n" +" color.a = v_color.a*t0.a*u_lightMap.a;\n" + +" color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n" +" DoAlphaTest(color.a);\n" + +" FRAGCOLOR(color);\n" +"}\n" + +; diff --git a/src/extras/shaders/simple.frag b/src/extras/shaders/simple.frag index 87157beb..c85bf089 100644 --- a/src/extras/shaders/simple.frag +++ b/src/extras/shaders/simple.frag @@ -1,16 +1,17 @@ uniform sampler2D tex0; -in vec4 v_color; -in vec2 v_tex0; -in float v_fog; - -out vec4 color; +FSIN vec4 v_color; +FSIN vec2 v_tex0; +FSIN float v_fog; void main(void) { + vec4 color; color = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog); DoAlphaTest(color.a); + + FRAGCOLOR(color); } diff --git a/src/extras/shaders/simple_fs_gl.inc b/src/extras/shaders/simple_fs_gl.inc new file mode 100644 index 00000000..614d79a0 --- /dev/null +++ b/src/extras/shaders/simple_fs_gl.inc @@ -0,0 +1,19 @@ +const char *simple_frag_src = +"uniform sampler2D tex0;\n" + +"FSIN vec4 v_color;\n" +"FSIN vec2 v_tex0;\n" +"FSIN float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 color;\n" +" color = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" +" color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n" +" DoAlphaTest(color.a);\n" + +" FRAGCOLOR(color);\n" +"}\n" + +; diff --git a/src/fakerw/fake.cpp b/src/fakerw/fake.cpp index 5d53605d..eb5551f9 100644 --- a/src/fakerw/fake.cpp +++ b/src/fakerw/fake.cpp @@ -936,16 +936,3 @@ RtCharset *RtCharsetSetColors(RtCharset * charSet, const RwRGBA * foreGround, RtCharset *RtCharsetGetDesc(RtCharset * charset, RtCharsetDesc * desc) { *desc = charset->desc; return charset; } RtCharset *RtCharsetCreate(const RwRGBA * foreGround, const RwRGBA * backGround) { return Charset::create(foreGround, backGround); } RwBool RtCharsetDestroy(RtCharset * charSet) { charSet->destroy(); return true; } - - - -// fake shit -RwInt32 _rwD3D8FindCorrectRasterFormat(RwRasterType type, RwInt32 flags) -{ -#ifdef RW_GL3 - if(flags & (rwRASTERFORMATPAL8 | rwRASTERFORMAT8888)) - return 'NOPE'; - return 'YUP'; -#endif - return flags & 0xF00; -} diff --git a/src/rw/TexRead.cpp b/src/rw/TexRead.cpp index ad7d8fec..56b1aacc 100644 --- a/src/rw/TexRead.cpp +++ b/src/rw/TexRead.cpp @@ -165,12 +165,82 @@ RwTexDictionaryGtaStreamRead2(RwStream *stream, RwTexDictionary *texDict) } #ifdef GTA_PC -#ifdef RWLIBS + +#ifdef LIBRW + +#define CAPSVERSION 0 + +struct GPUcaps +{ + uint32 version; // so we can force regeneration easily + uint32 platform; + uint32 subplatform; + uint32 dxtSupport; +}; + +static void +GetGPUcaps(GPUcaps *caps) +{ + caps->version = CAPSVERSION; + caps->platform = rw::platform; + caps->subplatform = 0; + caps->dxtSupport = 0; + // TODO: more later +#ifdef RW_GL3 + caps->subplatform = rw::gl3::gl3Caps.gles; + caps->dxtSupport = rw::gl3::gl3Caps.dxtSupported; +#endif +#ifdef RW_D3D9 + caps->dxtSupport = 1; // TODO, probably +#endif +} + +void +ReadVideoCardCapsFile(GPUcaps *caps) +{ + memset(caps, 0, sizeof(GPUcaps)); + + int32 file = CFileMgr::OpenFile("DATA\\CAPS.DAT", "rb"); + if (file != 0) { + CFileMgr::Read(file, (char*)&caps->version, 4); + CFileMgr::Read(file, (char*)&caps->platform, 4); + CFileMgr::Read(file, (char*)&caps->subplatform, 4); + CFileMgr::Read(file, (char*)&caps->dxtSupport, 4); + CFileMgr::CloseFile(file); + } +} + +bool +CheckVideoCardCaps(void) +{ + GPUcaps caps, fcaps; + GetGPUcaps(&caps); + ReadVideoCardCapsFile(&fcaps); + return caps.version != fcaps.version || + caps.platform != fcaps.platform || + caps.subplatform != fcaps.subplatform || + caps.dxtSupport != fcaps.dxtSupport; +} + +void +WriteVideoCardCapsFile(void) +{ + GPUcaps caps; + GetGPUcaps(&caps); + int32 file = CFileMgr::OpenFile("DATA\\CAPS.DAT", "wb"); + if (file != 0) { + CFileMgr::Write(file, (char*)&caps.version, 4); + CFileMgr::Write(file, (char*)&caps.platform, 4); + CFileMgr::Write(file, (char*)&caps.subplatform, 4); + CFileMgr::Write(file, (char*)&caps.dxtSupport, 4); + CFileMgr::CloseFile(file); + } +} + + +#else extern "C" RwInt32 _rwD3D8FindCorrectRasterFormat(RwRasterType type, RwInt32 flags); extern "C" RwBool _rwD3D8CheckValidTextureFormat(RwInt32 format); -#else -RwInt32 _rwD3D8FindCorrectRasterFormat(RwRasterType type, RwInt32 flags); -#endif void ReadVideoCardCapsFile(uint32 &cap32, uint32 &cap24, uint32 &cap16, uint32 &cap8) { @@ -217,6 +287,7 @@ WriteVideoCardCapsFile(void) CFileMgr::CloseFile(file); } } +#endif bool CanVideoCardDoDXT(void) @@ -313,6 +384,13 @@ CreateTxdImageForVideoCard() return false; } +#ifdef LIBRW + // so we can read back DXT with GLES + // only works for textures that are not yet loaded + // so let's hope that is the case for all + rw::gl3::needToReadBackTextures = true; +#endif + int32 i; for (i = 0; i < TXDSTORESIZE; i++) { ConvertingTexturesScreen(i, TXDSTORESIZE, "CVT_MSG"); @@ -340,6 +418,9 @@ CreateTxdImageForVideoCard() delete []buf; delete pDir; CStreaming::RemoveTxd(i); +#ifdef LIBRW + rw::gl3::needToReadBackTextures = false; +#endif return false; } @@ -366,6 +447,10 @@ CreateTxdImageForVideoCard() RwStreamClose(img, nil); delete []buf; +#ifdef LIBRW + rw::gl3::needToReadBackTextures = false; +#endif + if (!pDir->WriteDirFile("models\\txd.dir")) { DealWithTxdWriteError(i, TXDSTORESIZE, "CVT_ERR"); delete pDir; diff --git a/vendor/librw b/vendor/librw index 7e80d45c..4ac67e5d 160000 --- a/vendor/librw +++ b/vendor/librw @@ -1 +1 @@ -Subproject commit 7e80d45cdb6663f97d89ed443198ce6e37c4435e +Subproject commit 4ac67e5df87da7d94725789cedad2b69e8687007