ambient_generic: Precache sound inside ::Spawned() and not ::SpawnKey()
This commit is contained in:
parent
2d3ea1ba20
commit
60e681a6c9
2 changed files with 65 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
|||
!!samps diffuse lightmap
|
||||
!!cvardf gl_mono=0
|
||||
!!cvardf gl_stipplealpha=0
|
||||
!!cvardf r_waterRipples=0
|
||||
|
||||
#include "sys/defs.h"
|
||||
#include "sys/fog.h"
|
||||
|
@ -34,11 +35,33 @@ varying vec2 lm0;
|
|||
#define USEALPHA float(ALPHA)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// Hash functions shamefully stolen from:
|
||||
// https://www.shadertoy.com/view/4djSRW
|
||||
#define HASHSCALE1 .1031
|
||||
#define HASHSCALE3 vec3(.1031, .1030, .0973)
|
||||
|
||||
float hash12(vec2 p)
|
||||
{
|
||||
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);
|
||||
p3 += dot(p3, p3.yzx + 19.19);
|
||||
return fract((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
|
||||
vec2 hash22(vec2 p)
|
||||
{
|
||||
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE3);
|
||||
p3 += dot(p3, p3.yzx+19.19);
|
||||
return fract((p3.xx+p3.yz)*p3.zy);
|
||||
|
||||
}
|
||||
|
||||
void main ()
|
||||
{
|
||||
vec2 ntc;
|
||||
ntc.s = tc.s + sin(tc.t+e_time)*0.125;
|
||||
ntc.t = tc.t + sin(tc.s+e_time)*0.125;
|
||||
ntc.s = tc.s + sin(tc.t+ e_time)*0.125;
|
||||
ntc.t = tc.t + sin(tc.s+ e_time)*0.125;
|
||||
vec4 diffuse_f = texture2D(s_diffuse, ntc);
|
||||
|
||||
diffuse_f *= e_colourident;
|
||||
|
@ -70,6 +93,45 @@ varying vec2 lm0;
|
|||
}
|
||||
#else
|
||||
#ifdef LIT
|
||||
|
||||
#define MAX_RADIUS 2
|
||||
|
||||
#if r_waterRipples ==1
|
||||
float resolution = 5.0f;
|
||||
float riptime = e_time;
|
||||
vec2 uv = tc.xy * resolution;
|
||||
vec2 p0 = floor(uv);
|
||||
vec2 circles = vec2(0.);
|
||||
for (int j = -MAX_RADIUS; j <= MAX_RADIUS; ++j) {
|
||||
for (int i = -MAX_RADIUS; i <= MAX_RADIUS; ++i) {
|
||||
vec2 pi = p0 + vec2(i, j);
|
||||
#if DOUBLE_HASH
|
||||
vec2 hsh = hash22(pi);
|
||||
#else
|
||||
vec2 hsh = pi;
|
||||
#endif
|
||||
vec2 p = pi + hash22(hsh);
|
||||
|
||||
float t = fract(0.3* riptime + hash12(hsh));
|
||||
vec2 v = p - uv;
|
||||
float d = length(v) - (float(MAX_RADIUS) + 1.)*t;
|
||||
|
||||
float h = 1e-3;
|
||||
float d1 = d - h;
|
||||
float d2 = d + h;
|
||||
float p1 = sin(31.*d1) * smoothstep(-0.6, -0.3, d1) * smoothstep(0., -0.3, d1);
|
||||
float p2 = sin(31.*d2) * smoothstep(-0.6, -0.3, d2) * smoothstep(0., -0.3, d2);
|
||||
circles += .05 * normalize(v) * ((p2 - p1) / (2. * h) * (1. - t) * (1. - t));
|
||||
}
|
||||
}
|
||||
circles /= float((MAX_RADIUS*2+1)*(MAX_RADIUS*2+1));
|
||||
|
||||
float intensity = mix(0.01, 0.15, smoothstep(0.1, 0.6, abs(fract(0.05* riptime + 0.5)*2.-1.)));
|
||||
vec3 n = vec3(circles, sqrt(1. - dot(circles, circles)));
|
||||
|
||||
diffuse_f = texture2D(s_diffuse, tc + n.yz);
|
||||
#endif
|
||||
//diffuse_f.rgb += pow(clamp(dot(n, normalize(vec3(1., 0.7, 0.5))), 0., 1.), 6.);
|
||||
diffuse_f.rgb *= (texture2D(s_lightmap, lm0) * e_lmscale).rgb;
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -170,7 +170,6 @@ ambient_generic::SpawnKey(string strKey, string strValue)
|
|||
switch (strKey) {
|
||||
case "message":
|
||||
m_strSpawnPath = strValue;
|
||||
precache_sound(m_strSpawnPath);
|
||||
message = __NULL__;
|
||||
break;
|
||||
case "volume":
|
||||
|
@ -207,6 +206,7 @@ void
|
|||
ambient_generic::Spawned(void)
|
||||
{
|
||||
super::Spawned();
|
||||
precache_sound(m_strSpawnPath);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue