- Provant el shader crt-pi

This commit is contained in:
2024-06-27 18:37:30 +02:00
parent 37a9e981a5
commit 16d8d5c5b5
2 changed files with 23 additions and 19 deletions

View File

@@ -41,7 +41,7 @@ MASK_TYPE defines what, if any, shadow mask to use. MASK_BRIGHTNESS defines how
#define MULTISAMPLE
#define GAMMA
//#define FAKE_GAMMA
//#define CURVATURE
#define CURVATURE
//#define SHARPER
// MASK_TYPE: 0 = none, 1 = green/magenta, 2 = trinitron(ish)
#define MASK_TYPE 1
@@ -64,8 +64,8 @@ uniform COMPAT_PRECISION float BLOOM_FACTOR;
uniform COMPAT_PRECISION float INPUT_GAMMA;
uniform COMPAT_PRECISION float OUTPUT_GAMMA;
#else
#define CURVATURE_X 0.10
#define CURVATURE_Y 0.25
#define CURVATURE_X 0.25
#define CURVATURE_Y 0.45
#define MASK_BRIGHTNESS 0.70
#define SCANLINE_WEIGHT 6.0
#define SCANLINE_GAP_BRIGHTNESS 0.12
@@ -78,7 +78,7 @@ uniform COMPAT_PRECISION float OUTPUT_GAMMA;
- GLSL compilers
*/
uniform vec2 TextureSize;
//uniform vec2 TextureSize;
#if defined(CURVATURE)
varying vec2 screenScale;
#endif
@@ -86,20 +86,20 @@ varying vec2 TEX0;
varying float filterWidth;
#if defined(VERTEX)
uniform mat4 MVPMatrix;
attribute vec4 VertexCoord;
attribute vec2 TexCoord;
uniform vec2 InputSize;
uniform vec2 OutputSize;
//uniform mat4 MVPMatrix;
//attribute vec4 VertexCoord;
//attribute vec2 TexCoord;
//uniform vec2 InputSize;
//uniform vec2 OutputSize;
void main()
{
#if defined(CURVATURE)
screenScale = TextureSize / InputSize;
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
#endif
filterWidth = (InputSize.y / OutputSize.y) / 3.0;
TEX0 = TexCoord*1.0001;
gl_Position = MVPMatrix * VertexCoord;
filterWidth = (768.0 / 240.0) / 3.0;
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#elif defined(FRAGMENT)
@@ -146,6 +146,7 @@ float CalcScanLine(float dy)
void main()
{
vec2 TextureSize = vec2(320.0, 240.0);
#if defined(CURVATURE)
vec2 texcoord = Distort(TEX0);
if (texcoord.x < 0.0)

View File

@@ -21,8 +21,8 @@
#include <SDL2/SDL_opengl_glext.h>
#endif
const int WIN_WIDTH = 640;
const int WIN_HEIGHT = 480;
const int WIN_WIDTH = 1024;
const int WIN_HEIGHT = 768;
const int WORLD_WIDTH = 320;
const int WORLD_HEIGHT = 240;
@@ -81,8 +81,11 @@ GLuint compileShader(const char* source, GLuint shaderType) {
//std::cout << "Compilando shader:" << std::endl << source << std::endl;
// Create ID for shader
GLuint result = glCreateShader(shaderType);
const char *sources[2] = { shaderType==GL_VERTEX_SHADER?"#define VERTEX\n":"#define FRAGMENT\n", source };
// Define shader text
glShaderSource(result, 1, &source, NULL);
glShaderSource(result, 2, sources, NULL);
// Compile shader
glCompileShader(result);
@@ -118,9 +121,6 @@ GLuint compileProgram(const char* vtxFile, const char* fragFile) {
std::string source((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
/*const char *sources[2] = { "#define VERTEX\n", source.c_str() };
glShaderSourceARB(shader, 2, sources, NULL);*/
vtxShaderId = compileShader(source.c_str(), GL_VERTEX_SHADER);
f=std::ifstream(fragFile);
@@ -159,6 +159,8 @@ void presentBackBuffer(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* bac
GLint oldProgramId;
// Guarrada para obtener el textureid (en driverdata->texture)
//Detach the texture
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderClear(renderer);
@@ -291,6 +293,7 @@ int main(int argc, char **argv){
while ( ! done ) {
//Render to the texture
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_SetRenderTarget(renderer, texTarget);
SDL_RenderClear(renderer);