-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
731cd72
commit 63596d3
Showing
10 changed files
with
187 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
$input v2f_texCoord0, v2f_posWS | ||
|
||
#include "../../utils/bgfx_compute.sh" | ||
#include "velocity_uniforms.sh" | ||
|
||
#define bufferSize 512 | ||
|
||
BUFFER_RO(_isFluid, float, 0); | ||
BUFFER_RO(_curVelX, float, 1); | ||
BUFFER_RO(_curVelY, float, 2); | ||
|
||
vec3 HSVtoRGB(float H, float S, float V) { | ||
// Normalize the hue to [0, 360) | ||
if (H < 0.0) H += 360.0; | ||
if (H >= 360.0) H -= 360.0; | ||
|
||
float C = V * S; | ||
float X = C * (1.0 - abs(mod(H / 60.0, 2.0) - 1.0)); | ||
float m = V - C; | ||
|
||
float r, g, b; | ||
|
||
if (H >= 0.0 && H < 60.0) { | ||
r = C; g = X; b = 0.0; | ||
} else if (H >= 60.0 && H < 120.0) { | ||
r = X; g = C; b = 0.0; | ||
} else if (H >= 120.0 && H < 180.0) { | ||
r = 0.0; g = C; b = X; | ||
} else if (H >= 180.0 && H < 240.0) { | ||
r = 0.0; g = X; b = C; | ||
} else if (H >= 240.0 && H < 300.0) { | ||
r = X; g = 0.0; b = C; | ||
} else { | ||
r = C; g = 0.0; b = X; | ||
} | ||
|
||
// Add m to the final result to adjust brightness | ||
r += m; | ||
g += m; | ||
b += m; | ||
|
||
// Return the final color in RGB | ||
return vec3(r, g, b); | ||
} | ||
|
||
float dir2Angle(float x, float y) { | ||
float angle = atan2(x, y) * 180.0f / 3.14159; | ||
if(angle < 0) angle += 360.0f; | ||
|
||
return angle; | ||
} | ||
|
||
void main() { | ||
int index = int(gl_FragCoord.x) + bufferSize * int(gl_FragCoord.y); | ||
|
||
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); | ||
|
||
float dis = distance(v2f_posWS, vec3(uMousePosX, uMousePosY, uInterPosZ)); | ||
|
||
if(dis < uRadius) { | ||
if (abs(_curVelX[index]) < 1e-5 && abs(_curVelY[index]) < 1e-5) { | ||
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); | ||
} else { | ||
vec2 velDir = vec2(_curVelX[index], _curVelY[index]); | ||
float angle = dir2Angle(velDir.y, velDir.x); | ||
float speed = length(velDir); | ||
|
||
float H = angle; | ||
float S = min(speed / 10.0f, 1.0f); | ||
float V = min(speed / 10.0f, 1.0f); | ||
|
||
vec3 color = HSVtoRGB(H, 1.0, 1.0); | ||
|
||
gl_FragColor = vec4(color, 1.0); | ||
} | ||
} else { | ||
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); | ||
} | ||
|
||
//gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
vec3 v2f_posWS : TEXCOORD2 = vec3(0.0, 0.0, 0.0); | ||
vec2 v2f_texCoord0 : TEXCOORD0 = vec2(0.0, 0.0); | ||
|
||
vec3 a_position : POSITION; | ||
vec2 a_texcoord0 : TEXCOORD0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
$input a_position, a_texcoord0 | ||
$output v2f_texCoord0 | ||
$output v2f_texCoord0, v2f_posWS | ||
|
||
#include "../../utils/bgfx_shader.sh" | ||
|
||
void main() { | ||
//gl_Position = vec4(a_position, 1.0); | ||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); | ||
v2f_texCoord0 = a_texcoord0; | ||
v2f_posWS = mul(u_model[0], vec4(a_position, 1.0)).xyz; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters