mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-25 06:26:42 +01:00
- [RM PRimitive] Add texture property.
This commit is contained in:
parent
a6aeffcf66
commit
14e9e0f82f
2 changed files with 34 additions and 5 deletions
|
@ -129,6 +129,11 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro
|
|||
inputs[| 35] = nodeValue("Reflective", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.)
|
||||
.setDisplay(VALUE_DISPLAY.slider);
|
||||
|
||||
inputs[| 36] = nodeValue("Texture", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, false);
|
||||
|
||||
inputs[| 37] = nodeValue("Triplanar Smoothing", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1.)
|
||||
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 10, 0.1 ] });
|
||||
|
||||
outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
|
||||
|
||||
input_display_list = [ 0,
|
||||
|
@ -136,7 +141,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro
|
|||
["Modify", false], 12, 11,
|
||||
["Deform", true], 15, 16, 17, 18, 19,
|
||||
["Transform", false], 2, 3, 4,
|
||||
["Material", false], 9, 35,
|
||||
["Material", false], 9, 36, 35, 37,
|
||||
["Camera", false], 13, 14, 5, 6,
|
||||
["Render", false], 31, 30, 34, 10, 7, 8,
|
||||
["Tile", false], 20, 29,
|
||||
|
@ -283,6 +288,9 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro
|
|||
var bgEnv = _data[34];
|
||||
var _refl = _data[35];
|
||||
|
||||
var _text = _data[36];
|
||||
var _triS = _data[37];
|
||||
|
||||
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1]);
|
||||
|
||||
for (var i = 0, n = array_length(temp_surface); i < n; i++)
|
||||
|
@ -291,6 +299,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro
|
|||
var tx = 1024;
|
||||
surface_set_shader(temp_surface[0]);
|
||||
draw_surface_stretched_safe(bgEnv, tx * 0, tx * 0, tx, tx);
|
||||
draw_surface_stretched_safe(_text, tx * 1, tx * 0, tx, tx);
|
||||
surface_reset_shader();
|
||||
|
||||
gpu_set_texfilter(true);
|
||||
|
@ -369,8 +378,10 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro
|
|||
|
||||
shader_set_i("volumetric", _vol);
|
||||
shader_set_f("volumeDensity", _vden);
|
||||
shader_set_f("triplanar", _triS);
|
||||
|
||||
shader_set_i("useEnv", is_surface(bgEnv));
|
||||
shader_set_i("useEnv", is_surface(bgEnv));
|
||||
shader_set_i("useTexture", is_surface(_text));
|
||||
|
||||
draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _dim[0], _dim[1]);
|
||||
surface_reset_shader();
|
||||
|
|
|
@ -60,6 +60,8 @@ uniform vec4 ambient;
|
|||
uniform float reflective;
|
||||
|
||||
uniform int useEnv;
|
||||
uniform int useTexture;
|
||||
uniform float triplanar;
|
||||
|
||||
uniform int volumetric;
|
||||
uniform float volumeDensity;
|
||||
|
@ -376,6 +378,22 @@ mat3 rotMatrix, irotMatrix;
|
|||
|
||||
#endregion
|
||||
|
||||
#region ////=========== Texturing ============
|
||||
|
||||
vec4 boxmap( in int textureIndex, in vec3 p, in vec3 n, in float k ) {
|
||||
// project+fetch
|
||||
vec4 x = sampleTexture( textureIndex, fract(p.yz) );
|
||||
vec4 y = sampleTexture( textureIndex, fract(p.zx) );
|
||||
vec4 z = sampleTexture( textureIndex, fract(p.xy) );
|
||||
|
||||
// blend weights
|
||||
vec3 w = pow( abs(n), vec3(k) );
|
||||
// blend and return
|
||||
return (x * w.x + y * w.y + z * w.z) / (w.x + w.y + w.z);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
////========= Ray Marching ==========
|
||||
|
||||
float sceneSDF(vec3 p) {
|
||||
|
@ -507,15 +525,15 @@ void main() {
|
|||
float dist = march(eye, dir);
|
||||
vec3 coll = eye + dir * dist;
|
||||
vec3 wcoll = irotMatrix * coll;
|
||||
vec3 norm = normal(coll);
|
||||
|
||||
if(dist > viewRange.y - EPSILON) // Not hitting anything.
|
||||
return;
|
||||
|
||||
vec3 c = ambient.rgb;
|
||||
vec3 c = useTexture == 1? boxmap(1, coll, norm, triplanar).rgb * ambient.rgb : ambient.rgb;
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
float distNorm = (dist - viewRange.x) / (viewRange.y - viewRange.x);
|
||||
distNorm = 1. - distNorm;
|
||||
distNorm = smoothstep(.0, .3, distNorm);
|
||||
|
@ -523,7 +541,6 @@ void main() {
|
|||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
vec3 norm = normal(coll);
|
||||
vec3 ref = reflect(dir, norm);
|
||||
|
||||
if(useEnv == 1) {
|
||||
|
@ -544,5 +561,6 @@ void main() {
|
|||
vec3 light = normalize(lightPosition);
|
||||
float lamo = min(1., max(0., dot(norm, light)) + ambientIntns);
|
||||
c = mix(background.rgb, c, lamo);
|
||||
|
||||
gl_FragColor = vec4(c, 1.);
|
||||
}
|
Loading…
Reference in a new issue