- pscene->verts = NULL;
- pscene->indices = NULL;
- pscene->vertex_count = 0;
- pscene->indice_count = 0;
- pscene->shadowers = NULL;
- pscene->shadower_count = 0;
- pscene->shadower_cap = 0;
- pscene->submesh.indice_start = 0;
- pscene->submesh.indice_count = 0;
-
- v3_fill( pscene->bbx[0], 999999.9f );
- v3_fill( pscene->bbx[1], -999999.9f );
-
- static int noise_ready = 0;
- if( !noise_ready )
- {
- noise_ready = 1;
-
- u8 *buf = malloc( 256*256*2 );
-
- for( int i=0; i<256*256; i++ )
- {
- u8 val = rand()&0xff;
- buf[i*2] = val;
- }
-
- for( int y=0; y<256; y++ )
- {
- for( int x=0; x<256; x++ )
- {
- u8 *pr = &buf[(y*256+x)*2],
- *pg = &buf[(((y+17)&0xff)*256+((x+37)&0xff))*2+1];
- *pg = *pr;
- }
- }
-
- /* TODO: This texture should be delted somewhere */
- glGenTextures( 1, &tex_dual_noise );
- glBindTexture( GL_TEXTURE_2D, tex_dual_noise );
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RG, 256, 256, 0, GL_RG,
- GL_UNSIGNED_BYTE, buf );
-
- vg_tex2d_linear();
- vg_tex2d_repeat();
-
- free( buf );
- }
-}
-
-/* https://www.shadertoy.com/view/4sfGzS */
-#define SHADER_VALUE_NOISE_3D \
-"uniform sampler2D uTexNoise;" \
-"" \
-"float noise( vec3 x )" \
-"{" \
- "vec3 i = floor(x);" \
- "vec3 f = fract(x);" \
- "f = f*f*(3.0-2.0*f);" \
- "vec2 uv = (i.xy+vec2(37.0,17.0)*i.z) + f.xy;" \
- "vec2 rg = texture( uTexNoise, (uv+0.5)/256.0).yx;"\
- "return mix( rg.x, rg.y, f.z );" \
-"}" \
-"" \
-"const mat3 m = mat3( 0.00, 0.80, 0.60," \
- "-0.80, 0.36, -0.48," \
- "-0.60, -0.48, 0.64 );" \
-"" \
-"float fractalNoise( vec3 x )" \
-"{" \
- "vec3 q = 8.0*x;" \
- "float f;" \
- "f = 0.5000*noise( q ); q = m*q*2.01;" \
- "f += 0.2500*noise( q ); q = m*q*2.02;" \
- "f += 0.1250*noise( q ); q = m*q*2.03;" \
- "f += 0.0625*noise( q ); q = m*q*2.01;" \
- "return f;" \
-"}"
-
-SHADER_DEFINE( shader_debug_vcol,
-
- /*Include*/ VERTEX_STANDARD_ATTRIBUTES
-
- "uniform mat4 uPv;"
- "uniform mat4x3 uMdl;"
- "uniform float uTime;"
- "uniform float uSwayAmt;"
- ""
- "out vec4 aColour;"
- "out vec2 aUv;"
- "out vec3 aNorm;"
- "out vec3 aCo;"
- ""
- "vec3 compute_sway( vec3 pos )"
- "{"
- "vec4 sines = vec4( sin(uTime + pos.x)*1.0,"
- "sin(uTime*1.2 + pos.z*2.0)*1.1,"
- "sin(uTime*2.33)*0.5,"
- "sin(uTime*0.6 + pos.x*0.3)*1.3 );"
-
- "vec3 offset = vec3( sines.x+sines.y*sines.w, 0.0, sines.x+sines.z );"
- "return pos + offset*a_colour.r*uSwayAmt;"
- "}"
- ""
- "void main()"
- "{"
- "vec3 swaypos = compute_sway( a_co );"
- "gl_Position = uPv * vec4(uMdl * vec4(swaypos,1.0), 1.0 );"
- "aColour = a_colour;"
- "aUv = a_uv;"
- "aNorm = normalize(mat3(uMdl) * a_norm);"
- "aCo = a_co;"
- "}",
- /* Fragment */
- "out vec4 FragColor;"
- ""
- "uniform int uMode;"
- "uniform sampler2D uTexMain;"
- "uniform sampler2D uTexGradients;"
- ""
- /*Include*/ SHADER_VALUE_NOISE_3D
- ""
- "in vec4 aColour;"
- "in vec2 aUv;"
- "in vec3 aNorm;"
- "in vec3 aCo;"
- ""
- "void main()"
- "{"
- "vec4 colour = vec4(1.0,0.0,0.5,1.0);"
- "vec4 diffuse = texture( uTexMain, aUv );"
-
- "if( uMode == 1 )"
- "{"
- "colour = vec4(aNorm * 0.5 + 0.5, 1.0);"
- "}"
- "if( uMode == 2 )"
- "{"
- "colour = aColour;"
- "}"
- "if( uMode == 3 )"
- "{"
- "float light = dot(aNorm, vec3(0.2,0.8,0.1));"
- "vec3 grid3 = fract(aCo);"
-
- "colour = vec4(vec3(light)*(1.0-grid3*0.3),1.0);"
- "}"
- "if( uMode == 4 )"
- "{"
- "colour = vec4( aUv, 0.0, 1.0 );"
- "}"
- "if( uMode == 5 )"
- "{"
- "if( diffuse.a < 0.45 ) discard;"
- "colour = diffuse;"
- "}"
- "if( uMode == 6 )"
- "{"
- "float r1 = fractalNoise(aCo);"
- "colour = vec4( vec3(r1), 1.0 );"
- "}"
- "if( uMode == 7 )"
- "{"
- "if( diffuse.a < 0.2 ) discard;"
- "float lighting = 1.0 - aColour.g*0.8;"
-
- "float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));"
- "float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));"
- "vec3 lt = vec3(0.2,0.2,0.2 ) + "
- "vec3(1.0,1.0,0.9)*light1 + "
- "vec3(0.1,0.3,0.4 )*light2;"
-
-
- "colour = vec4(vec3(pow(lighting,1.6)*(diffuse.r*0.7+0.5)),1.0);"
- "colour = vec4(colour.rgb*lt,1.0);"
-
- "vec2 gradUV = vec2(lighting*1.9,aColour.b*0.8);"
- "vec4 gradient_sample = texture( uTexGradients, gradUV );"
- "colour = colour*gradient_sample;"
- "}"
- "if( uMode == 8 )"
- "{"
- "if( diffuse.a < 0.45 ) discard;"
- "float light = 1.0 - aColour.g;"
- "light = pow(light,1.6)*(diffuse.r*0.7+0.5);"
- "float r1 = fractalNoise(aCo*0.01);"
-
- "vec2 gradUV = vec2(light*1.9,r1+aColour.b);"
- "vec4 gradient_sample = texture( uTexGradients, gradUV );"
- "colour = gradient_sample*light;"
- "}"
-
- "FragColor = colour;"
- "}"
- ,
- UNIFORMS({ "uPv", "uMode", "uTexMain", "uTexGradients", "uTexNoise", \
- "uTime", "uSwayAmt", "uMdl" })
-)
-
-SHADER_DEFINE( shader_standard_lit,
-
- /*Include*/ VERTEX_STANDARD_ATTRIBUTES
-
- "uniform mat4 uPv;"
- "uniform mat4x3 uMdl;"
- ""
- "out vec4 aColour;"
- "out vec2 aUv;"
- "out vec3 aNorm;"
- "out vec3 aCo;"
- ""
- "void main()"
- "{"
- "gl_Position = uPv * vec4( uMdl * vec4(a_co,1.0), 1.0 );"
- "aColour = a_colour;"
- "aUv = a_uv;"
- "aNorm = mat3(uMdl) * a_norm;"
- "aCo = a_co;"
- "}",
- /* Fragment */
- "out vec4 FragColor;"
- ""
- "uniform sampler2D uTexMain;"
- "uniform vec4 uColour;"
- ""
- "in vec4 aColour;"
- "in vec2 aUv;"
- "in vec3 aNorm;"
- "in vec3 aCo;"
- ""
- "void main()"
- "{"
- "vec3 diffuse = texture( uTexMain, aUv ).rgb;"
-
- "float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));"
- "float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));"
- "diffuse += vec3(0.2,0.2,0.2) + "
- "vec3(1.0,1.0,0.9)*light1 + "
- "vec3(0.1,0.3,0.4)*light2;"
-
- "FragColor = vec4(diffuse*uColour.rgb, aColour.a*uColour.a);"
- "}"
- ,
- UNIFORMS({ "uColour","uTexMain","uPv","uMdl" })
-)
-
-SHADER_DEFINE( shader_unlit,
-
- /*Include*/ VERTEX_STANDARD_ATTRIBUTES
-
- "uniform mat4 uPv;"
- "uniform mat4x3 uMdl;"
- ""
- "out vec4 aColour;"
- "out vec2 aUv;"
- "out vec3 aNorm;"
- "out vec3 aCo;"
- ""
- "void main()"
- "{"
- "gl_Position = uPv * vec4(uMdl * vec4(a_co,1.0), 1.0);"
- "aColour = a_colour;"
- "aUv = a_uv;"
- "aNorm = mat3(uMdl) * a_norm;"
- "aCo = a_co;"
- "}",
- /* Fragment */
- "out vec4 FragColor;"
- ""
- "uniform sampler2D uTexMain;"
- "uniform vec4 uColour;"
- ""
- "in vec4 aColour;"
- "in vec2 aUv;"
- "in vec3 aNorm;"
- "in vec3 aCo;"
- ""
- "void main()"
- "{"
- "vec3 diffuse = texture( uTexMain, aUv ).rgb;"
- "FragColor = vec4(pow(diffuse,vec3(1.0)),1.0);"
- "}"
- ,
- UNIFORMS({ "uTexMain", "uPv", "uMdl" })
-)
-
-static void *buffer_reserve( void *buffer, u32 count, u32 *cap, u32 amount,
- size_t emsize )
-{
- if( count+amount > *cap )
- {
- *cap = VG_MAX( (*cap)*2, (*cap)+amount );
-
- return realloc( buffer, (*cap) * emsize );
- }