- [FXAA] Add moer effect controls.

This commit is contained in:
Tanasart 2024-05-07 17:40:18 +07:00
parent 79b3d8b5be
commit 5aa848c087
4 changed files with 58 additions and 41 deletions

View file

@ -27,7 +27,7 @@ if(winMan_isMinimized()) exit;
break; break;
case VALUE_TYPE.curve : case VALUE_TYPE.curve :
draw_tooltip_text($"[{__txt("Curve Object"}]"); draw_tooltip_text($"[{__txt("Curve Object")}]");
break; break;
case VALUE_TYPE.color : case VALUE_TYPE.color :
@ -51,12 +51,11 @@ if(winMan_isMinimized()) exit;
break; break;
case VALUE_TYPE.rigid : case VALUE_TYPE.rigid :
draw_tooltip_text($"[{__txt("Rigidbody Object")} (id: {content[$ "object"]})]"); draw_tooltip_text($"[{__txt("Rigidbody Object")} (id: {content.object})]");
break; break;
case VALUE_TYPE.particle : case VALUE_TYPE.particle :
var txt = $"[{__txt("Particle Object")} (size: {array_length(content)}) ]"; draw_tooltip_text($"[{__txt("Particle Object")} (size: {array_length(content)}) ]");
draw_tooltip_text(txt);
break; break;
case VALUE_TYPE.pathnode : case VALUE_TYPE.pathnode :

View file

@ -1,7 +1,7 @@
{ {
"$GMObject": "", "$GMObject":"",
"%Name": "o_main", "%Name":"o_main",
"eventList": [ "eventList":[
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":0,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":0,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":64,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":64,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":3,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":3,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
@ -19,35 +19,35 @@
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":60,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":60,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":70,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":70,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":20,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":20,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"resourceVersion":"1.0","name":"","resourceType":"GMEvent","eventNum":1,"eventType":9,"isDnD":false,}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":9,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"resourceVersion":"1.0","name":"","resourceType":"GMEvent","eventNum":1,"eventType":10,"isDnD":false,}, {"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":10,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
], ],
"managed": true, "managed":true,
"name": "o_main", "name":"o_main",
"overriddenProperties": [], "overriddenProperties":[],
"parent": { "parent":{
"name": "main", "name":"main",
"path": "folders/main.yy", "path":"folders/main.yy",
}, },
"parentObjectId": null, "parentObjectId":null,
"persistent": true, "persistent":true,
"physicsAngularDamping": 0.1, "physicsAngularDamping":0.1,
"physicsDensity": 0.5, "physicsDensity":0.5,
"physicsFriction": 0.2, "physicsFriction":0.2,
"physicsGroup": 1, "physicsGroup":1,
"physicsKinematic": false, "physicsKinematic":false,
"physicsLinearDamping": 0.1, "physicsLinearDamping":0.1,
"physicsObject": false, "physicsObject":false,
"physicsRestitution": 0.1, "physicsRestitution":0.1,
"physicsSensor": false, "physicsSensor":false,
"physicsShape": 1, "physicsShape":1,
"physicsShapePoints": [], "physicsShapePoints":[],
"physicsStartAwake": true, "physicsStartAwake":true,
"properties": [], "properties":[],
"resourceType": "GMObject", "resourceType":"GMObject",
"resourceVersion": "2.0", "resourceVersion":"2.0",
"solid": false, "solid":false,
"spriteId": null, "spriteId":null,
"spriteMaskId": null, "spriteMaskId":null,
"visible": true, "visible":true,
} }

View file

@ -5,10 +5,17 @@ function Node_FXAA(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
inputs[| 1] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); inputs[| 1] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
inputs[| 2] = nodeValue("Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.5)
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 3] = nodeValue("Mix", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.setDisplay(VALUE_DISPLAY.slider);
active_index = 1; active_index = 1;
input_display_list = [ input_display_list = [
1, 0, 1, 0,
["Effect", false], 2, 3,
] ]
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
@ -19,6 +26,9 @@ function Node_FXAA(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
surface_set_shader(_outSurf, sh_FXAA); surface_set_shader(_outSurf, sh_FXAA);
gpu_set_tex_filter(true); gpu_set_tex_filter(true);
shader_set_f("dimension", surface_get_width_safe(_data[0]), surface_get_height_safe(_data[0])); shader_set_f("dimension", surface_get_width_safe(_data[0]), surface_get_height_safe(_data[0]));
shader_set_f("cornerDis", _data[2]);
shader_set_f("mixAmo", _data[3]);
draw_surface_safe(_data[0], 0, 0); draw_surface_safe(_data[0], 0, 0);
gpu_set_tex_filter(false); gpu_set_tex_filter(false);
surface_reset_shader(); surface_reset_shader();

View file

@ -6,6 +6,8 @@ varying vec4 v_vColour;
//Texel size (1/resolution) //Texel size (1/resolution)
uniform vec2 dimension; uniform vec2 dimension;
uniform float cornerDis;
uniform float mixAmo;
#define SPAN_MAX (8.0) //Maximum texel span #define SPAN_MAX (8.0) //Maximum texel span
//These are more technnical and probably don't need changing: //These are more technnical and probably don't need changing:
@ -16,10 +18,10 @@ vec4 textureFXAA(sampler2D tex, vec2 uv) {
vec2 u_texel = 1. / dimension; vec2 u_texel = 1. / dimension;
//Sample center and 4 corners //Sample center and 4 corners
vec3 rgbCC = texture2D(tex, uv).rgb; vec3 rgbCC = texture2D(tex, uv).rgb;
vec3 rgb00 = texture2D(tex, uv + vec2( -0.5, -0.5) * u_texel).rgb; vec3 rgb00 = texture2D(tex, uv + vec2( -cornerDis, -cornerDis) * u_texel).rgb;
vec3 rgb10 = texture2D(tex, uv + vec2( +0.5, -0.5) * u_texel).rgb; vec3 rgb10 = texture2D(tex, uv + vec2( +cornerDis, -cornerDis) * u_texel).rgb;
vec3 rgb01 = texture2D(tex, uv + vec2( -0.5, +0.5) * u_texel).rgb; vec3 rgb01 = texture2D(tex, uv + vec2( -cornerDis, +cornerDis) * u_texel).rgb;
vec3 rgb11 = texture2D(tex, uv + vec2( +0.5, +0.5) * u_texel).rgb; vec3 rgb11 = texture2D(tex, uv + vec2( +cornerDis, +cornerDis) * u_texel).rgb;
//Luma coefficients //Luma coefficients
const vec3 luma = vec3(0.299, 0.587, 0.114); const vec3 luma = vec3(0.299, 0.587, 0.114);
@ -32,13 +34,18 @@ vec4 textureFXAA(sampler2D tex, vec2 uv) {
//Compute gradient from luma values //Compute gradient from luma values
vec2 dir = vec2((luma01 + luma11) - (luma00 + luma10), (luma00 + luma01) - (luma10 + luma11)); vec2 dir = vec2((luma01 + luma11) - (luma00 + luma10), (luma00 + luma01) - (luma10 + luma11));
//Diminish dir length based on total luma //Diminish dir length based on total luma
float dirReduce = max((luma00 + luma10 + luma01 + luma11) * REDUCE_MUL, REDUCE_MIN); float dirReduce = max((luma00 + luma10 + luma01 + luma11) * REDUCE_MUL, REDUCE_MIN);
//Divide dir by the distance to nearest edge plus dirReduce //Divide dir by the distance to nearest edge plus dirReduce
float rcpDir = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce); float rcpDir = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
//Multiply by reciprocal and limit to pixel span //Multiply by reciprocal and limit to pixel span
dir = clamp(dir * rcpDir, -SPAN_MAX, SPAN_MAX) * u_texel.xy; dir = clamp(dir * rcpDir, -SPAN_MAX, SPAN_MAX) * u_texel.xy;
vec4 O = texture2D(tex, uv);
//Average middle texels along dir line //Average middle texels along dir line
vec4 A = 0.5 * ( vec4 A = 0.5 * (
texture2D(tex, uv - dir * (1.0 / 6.0)) + texture2D(tex, uv - dir * (1.0 / 6.0)) +
@ -56,8 +63,9 @@ vec4 textureFXAA(sampler2D tex, vec2 uv) {
//Get average luma //Get average luma
float lumaB = dot(B.rgb, luma); float lumaB = dot(B.rgb, luma);
//If the average is outside the luma range, using the middle average //If the average is outside the luma range, using the middle average
return ((lumaB < lumaMin) || (lumaB > lumaMax)) ? A : B; return mix(O, ((lumaB < lumaMin) || (lumaB > lumaMax)) ? A : B, mixAmo);
} }
void main() { void main() {