mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-10 21:10:15 +00:00
Start adding snow shaders
This commit is contained in:
parent
7d70fb3f4a
commit
23aa03fcdd
105
diff.diff
105
diff.diff
@ -1,105 +0,0 @@
|
||||
diff --git a/gfx/drivers_shader/shader_glsl.c b/gfx/drivers_shader/shader_glsl.c
|
||||
index 203f0c6..6cb5f9a 100644
|
||||
--- a/gfx/drivers_shader/shader_glsl.c
|
||||
+++ b/gfx/drivers_shader/shader_glsl.c
|
||||
@@ -1330,15 +1330,13 @@ fallback:
|
||||
|
||||
#define gl_glsl_set_coord_array(attr, coord1, coord2, coords, size, multiplier) \
|
||||
{ \
|
||||
- unsigned y; \
|
||||
- attr->loc = coord1; \
|
||||
- attr->size = multiplier; \
|
||||
- attr->offset = size * sizeof(GLfloat); \
|
||||
- attribs_size++; \
|
||||
- attr++; \
|
||||
- for (y = 0; y < (multiplier * coords->vertices); y++) \
|
||||
- buffer[y + size] = coord2[y]; \
|
||||
- size += multiplier * coords->vertices; \
|
||||
+ attr->loc = coord1; \
|
||||
+ attr->size = multiplier; \
|
||||
+ attr->offset = size * sizeof(GLfloat); \
|
||||
+ attribs_size++; \
|
||||
+ glBufferSubData(GL_ARRAY_BUFFER, attr->offset, multiplier * coords->vertices * sizeof(GLfloat), coord2); \
|
||||
+ size += multiplier * coords->vertices; \
|
||||
+ attr++; \
|
||||
}
|
||||
|
||||
static bool gl_glsl_set_coords(void *handle_data, void *shader_data, const struct video_coords *coords)
|
||||
@@ -1357,35 +1355,56 @@ static bool gl_glsl_set_coords(void *handle_data, void *shader_data, const struc
|
||||
goto fallback;
|
||||
|
||||
buffer = short_buffer;
|
||||
- if (coords->vertices > 4)
|
||||
- buffer = (GLfloat*)calloc(coords->vertices *
|
||||
- (2 + 2 + 4 + 2), sizeof(*buffer));
|
||||
-
|
||||
- if (!buffer)
|
||||
- goto fallback;
|
||||
|
||||
attr = attribs;
|
||||
uni = &glsl->uniforms[glsl->active_idx];
|
||||
|
||||
- if (uni->tex_coord >= 0)
|
||||
- gl_glsl_set_coord_array(attr, uni->tex_coord, coords->tex_coord, coords, size, 2);
|
||||
+ glBindBuffer(GL_ARRAY_BUFFER, glsl->vbo[glsl->active_idx].vbo_primary);
|
||||
+ {
|
||||
+ size_t i;
|
||||
+ size_t elems = 0;
|
||||
|
||||
- if (uni->vertex_coord >= 0)
|
||||
- gl_glsl_set_coord_array(attr, uni->vertex_coord, coords->vertex, coords, size, 2);
|
||||
+ elems += (uni->color >= 0) * 4;
|
||||
+ elems += (uni->tex_coord >= 0) * 2;
|
||||
+ elems += (uni->vertex_coord >= 0) * 2;
|
||||
+ elems += (uni->lut_tex_coord >= 0) * 2;
|
||||
|
||||
- if (uni->color >= 0)
|
||||
- gl_glsl_set_coord_array(attr, uni->color, coords->color, coords, size, 4);
|
||||
+ elems *= coords->vertices;
|
||||
|
||||
- if (uni->lut_tex_coord >= 0)
|
||||
- gl_glsl_set_coord_array(attr, uni->lut_tex_coord, coords->lut_tex_coord, coords, size, 2);
|
||||
+ if (elems) {
|
||||
|
||||
- if (size)
|
||||
- gl_glsl_set_attribs(glsl,
|
||||
- glsl->vbo[glsl->active_idx].vbo_primary,
|
||||
- &glsl->vbo[glsl->active_idx].buffer_primary,
|
||||
- &glsl->vbo[glsl->active_idx].size_primary,
|
||||
- buffer, size,
|
||||
- attribs, attribs_size);
|
||||
+ glBufferData(GL_ARRAY_BUFFER, elems * sizeof(GLfloat), NULL, GL_STREAM_DRAW);
|
||||
+
|
||||
+ if (uni->tex_coord >= 0)
|
||||
+ gl_glsl_set_coord_array(attr, uni->tex_coord, coords->tex_coord, coords, size, 2);
|
||||
+
|
||||
+ if (uni->vertex_coord >= 0)
|
||||
+ gl_glsl_set_coord_array(attr, uni->vertex_coord, coords->vertex, coords, size, 2);
|
||||
+
|
||||
+ if (uni->color >= 0)
|
||||
+ gl_glsl_set_coord_array(attr, uni->color, coords->color, coords, size, 4);
|
||||
+
|
||||
+ if (uni->lut_tex_coord >= 0)
|
||||
+ gl_glsl_set_coord_array(attr, uni->lut_tex_coord, coords->lut_tex_coord, coords, size, 2);
|
||||
+
|
||||
+ for (i = 0; i < attribs_size; i++)
|
||||
+ {
|
||||
+ GLint loc = attribs[i].loc;
|
||||
+
|
||||
+ if (glsl->attribs.index < ARRAY_SIZE(glsl->attribs.elems))
|
||||
+ {
|
||||
+ glEnableVertexAttribArray(loc);
|
||||
+ glVertexAttribPointer(loc, attribs[i].size, GL_FLOAT, GL_FALSE, 0,
|
||||
+ (const GLvoid*)(uintptr_t)attribs[i].offset);
|
||||
+ glsl->attribs.elems[glsl->attribs.index++] = loc;
|
||||
+ }
|
||||
+ else
|
||||
+ RARCH_WARN("Attrib array buffer was overflown!\n");
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
if (buffer != short_buffer)
|
||||
free(buffer);
|
31
gfx/drivers/gl_shaders/legacy_pipeline_snow.glsl.vert.h
Normal file
31
gfx/drivers/gl_shaders/legacy_pipeline_snow.glsl.vert.h
Normal file
@ -0,0 +1,31 @@
|
||||
#include "shaders_common.h"
|
||||
|
||||
static const char *stock_vertex_xmb_simple_legacy = GLSL(
|
||||
attribute vec3 VertexCoord;
|
||||
uniform float time;
|
||||
float iqhash( float n )
|
||||
{
|
||||
return fract(sin(n)*43758.5453);
|
||||
}
|
||||
|
||||
float noise( vec3 x )
|
||||
{
|
||||
vec3 p = floor(x);
|
||||
vec3 f = fract(x);
|
||||
f = f*f*(3.0-2.0*f);
|
||||
float n = p.x + p.y*57.0 + 113.0*p.z;
|
||||
|
||||
return mix(mix(mix( iqhash(n+0.0 ), iqhash(n+1.0 ),f.x),
|
||||
mix( iqhash(n+57.0 ), iqhash(n+58.0 ),f.x),f.y),
|
||||
mix(mix( iqhash(n+113.0), iqhash(n+114.0),f.x),
|
||||
mix( iqhash(n+170.0), iqhash(n+171.0),f.x),f.y),f.z);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 v = vec3(VertexCoord.x, 0.0, VertexCoord.y);
|
||||
vec3 v2 = v;
|
||||
v.y = v.z;
|
||||
gl_Position = vec4(VertexCoord.x, VertexCoord.y, VertexCoord.y, 1.0);
|
||||
}
|
||||
);
|
33
gfx/drivers/gl_shaders/modern_pipeline_snow.glsl.vert.h
Normal file
33
gfx/drivers/gl_shaders/modern_pipeline_snow.glsl.vert.h
Normal file
@ -0,0 +1,33 @@
|
||||
#include "shaders_common.h"
|
||||
|
||||
static const char *stock_vertex_xmb_simple_modern = GLSL(
|
||||
in vec3 VertexCoord;
|
||||
uniform float time;
|
||||
|
||||
float iqhash( float n )
|
||||
{
|
||||
return fract(sin(n)*43758.5453);
|
||||
}
|
||||
|
||||
float noise( vec3 x )
|
||||
{
|
||||
vec3 p = floor(x);
|
||||
vec3 f = fract(x);
|
||||
f = f*f*(3.0-2.0*f);
|
||||
float n = p.x + p.y*57.0 + 113.0*p.z;
|
||||
return mix(mix(mix( iqhash(n+0.0 ), iqhash(n+1.0 ),f.x),
|
||||
mix( iqhash(n+57.0 ), iqhash(n+58.0 ),f.x),f.y),
|
||||
mix(mix( iqhash(n+113.0), iqhash(n+114.0),f.x),
|
||||
mix( iqhash(n+170.0), iqhash(n+171.0),f.x),f.y),f.z);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 v = vec3(VertexCoord.x, 0.0, VertexCoord.y);
|
||||
//vec3 v2 = v;
|
||||
//v2.x = v2.x + time/2.0;
|
||||
//v2.z = v.z * 3.0;
|
||||
//v.y = -cos((v.x+v.z/3.0+time)*2.0)/10.0 - noise(v2.xyz)/4.0;
|
||||
gl_Position = vec4(v, 1.0);
|
||||
}
|
||||
);
|
60
gfx/drivers/gl_shaders/pipeline_snow.cg.h
Normal file
60
gfx/drivers/gl_shaders/pipeline_snow.cg.h
Normal file
@ -0,0 +1,60 @@
|
||||
#include "shaders_common.h"
|
||||
|
||||
static const char *stock_xmb_simple = CG(
|
||||
struct input
|
||||
{
|
||||
float time;
|
||||
};
|
||||
|
||||
float iqhash(float n)
|
||||
{
|
||||
return frac(sin(n)*43758.5453);
|
||||
}
|
||||
|
||||
float noise(float3 x)
|
||||
{
|
||||
float3 p = floor(x);
|
||||
float3 f = frac(x);
|
||||
f = f * f * (3.0 - 2.0 * f);
|
||||
float n = p.x + p.y * 57.0 + 113.0 * p.z;
|
||||
return lerp(lerp(lerp(iqhash(n+0.0), iqhash(n+1.0), f.x),
|
||||
lerp(iqhash(n+57.0), iqhash(n+58.0), f.x), f.y),
|
||||
lerp(lerp(iqhash(n+113.0), iqhash(n+114.0), f.x),
|
||||
lerp(iqhash(n+170.0), iqhash(n+171.0), f.x), f.y), f.z);
|
||||
}
|
||||
|
||||
void main_vertex
|
||||
(
|
||||
float2 position : POSITION,
|
||||
float4 color : COLOR,
|
||||
float2 texCoord : TEXCOORD0,
|
||||
|
||||
uniform input IN,
|
||||
|
||||
out float4 oPosition : POSITION,
|
||||
out float4 oColor : COLOR,
|
||||
out float2 otexCoord : TEXCOORD
|
||||
)
|
||||
{
|
||||
float3 v = float3(position.x, 0.0, position.y);
|
||||
float3 v2 = v;
|
||||
v2.x = v2.x + IN.time / 2.0;
|
||||
v2.z = v.z * 3.0;
|
||||
v.y = -cos((v.x + v.z / 3.0 + IN.time) * 2.0) / 10.0 - noise(v2.xyz) / 3.0;
|
||||
oPosition = float4(v, 1.0);
|
||||
oColor = color;
|
||||
otexCoord = texCoord;
|
||||
}
|
||||
|
||||
struct output
|
||||
{
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
output main_fragment(uniform input IN)
|
||||
{
|
||||
output OUT;
|
||||
OUT.color = float4(1.0, 1.0, 1.0, 0.05);
|
||||
return OUT;
|
||||
}
|
||||
);
|
65
gfx/drivers/gl_shaders/pipeline_snow.glsl.frag.h
Normal file
65
gfx/drivers/gl_shaders/pipeline_snow.glsl.frag.h
Normal file
@ -0,0 +1,65 @@
|
||||
#include "shaders_common.h"
|
||||
|
||||
static const char *stock_fragment_xmb_simple = GLSL(
|
||||
uniform float time;
|
||||
vec2 res = vec2(1920*3, 1080*3);
|
||||
|
||||
// High quality = larger patterns
|
||||
// quality * 84 is the number of seconds in a loop
|
||||
float quality = 8.0;
|
||||
|
||||
float Cellular2D(vec2 P) {
|
||||
// https://github.com/BrianSharpe/Wombat/blob/master/Cellular2D.glsl
|
||||
vec2 Pi = floor(P);
|
||||
vec2 Pf = P - Pi;
|
||||
vec4 Pt = vec4( Pi.xy, Pi.xy + 1.0 );
|
||||
Pt = Pt - floor(Pt * ( 1.0 / 71.0 )) * 71.0;
|
||||
Pt += vec2( 26.0, 161.0 ).xyxy;
|
||||
Pt *= Pt;
|
||||
Pt = Pt.xzxz * Pt.yyww;
|
||||
vec4 hash_x = fract( Pt * ( 1.0 / 951.135664 ) );
|
||||
vec4 hash_y = fract( Pt * ( 1.0 / 642.949883 ) );
|
||||
hash_x = hash_x * 2.0 - 1.0;
|
||||
hash_y = hash_y * 2.0 - 1.0;
|
||||
const float JITTER_WINDOW = 0.25;
|
||||
hash_x = ( ( hash_x * hash_x * hash_x ) - sign( hash_x ) ) * JITTER_WINDOW + vec4( 0.0, 1.0, 0.0, 1.0 );
|
||||
hash_y = ( ( hash_y * hash_y * hash_y ) - sign( hash_y ) ) * JITTER_WINDOW + vec4( 0.0, 0.0, 1.0, 1.0 );
|
||||
vec4 dx = Pf.xxxx - hash_x;
|
||||
vec4 dy = Pf.yyyy - hash_y;
|
||||
vec4 d = dx * dx + dy * dy;
|
||||
d.xy = min(d.xy, d.zw);
|
||||
return min(d.x, d.y) * ( 1.0 / 1.125 );
|
||||
}
|
||||
|
||||
float snow(vec2 pos, float time, float scale) {
|
||||
// add wobble
|
||||
pos.x += cos(pos.y*4.0 + time*3.14159*2.0 + 1.0/scale)/(8.0/scale);
|
||||
// add gravity
|
||||
pos += time*scale*vec2(-0.5, 1.0);
|
||||
return max(
|
||||
1.0 - Cellular2D(mod(pos/scale, scale*quality)*16.0)*1024.0,
|
||||
0.0
|
||||
) * (scale*0.5 + 0.5);
|
||||
}
|
||||
|
||||
void main( void ) {
|
||||
float winscale = max(res.x, res.y);
|
||||
float tim = mod(time/8.0, 84.0*quality);
|
||||
vec2 pos = gl_FragCoord.xy/winscale;
|
||||
float a = 0.0;
|
||||
// Each of these is a layer of snow
|
||||
// Remove some for better performance
|
||||
// Changing the scale (3rd value) will mess with the looping
|
||||
a += snow(pos, tim, 1.0);
|
||||
a += snow(pos, tim, 0.7);
|
||||
a += snow(pos, tim, 0.6);
|
||||
a += snow(pos, tim, 0.5);
|
||||
a += snow(pos, tim, 0.4);
|
||||
a += snow(pos, tim, 0.3);
|
||||
a += snow(pos, tim, 0.25);
|
||||
a += snow(pos, tim, 0.125);
|
||||
a = a * min(pos.y*4.0, 1.0);
|
||||
gl_FragColor = vec4(1.0, 1.0, 1.0, a);
|
||||
}
|
||||
|
||||
);
|
Loading…
Reference in New Issue
Block a user