- [Raymarhers] Add environment texture interpolation settings.

This commit is contained in:
Tanasart 2024-07-20 15:34:32 +07:00
parent 34d195b760
commit 08928e15cb
5 changed files with 60 additions and 21 deletions

View File

@ -66,10 +66,12 @@ function RM_Object() constructor {
var tx = 1024;
surface_set_shader(textureAtlas);
for (var i = 0; i < shapeAmount; i++)
for (var i = 0; i < shapeAmount; i++) {
draw_surface_stretched_safe(texture[i], tx * (i % 8), tx * floor(i / 8), tx, tx);
}
surface_reset_shader();
textureAtl = textureAtlas;
}

View File

@ -56,6 +56,8 @@ function Node_RM_Combine(_x, _y, _group = noone) : Node_RM(_x, _y, _group) const
inputs[| 17] = nodeValue("Render", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
inputs[| 18] = nodeValue("Env Interpolation", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
outputs[| 1] = nodeValue("Shape Data", self, JUNCTION_CONNECT.output, VALUE_TYPE.sdf, noone);
@ -63,7 +65,7 @@ function Node_RM_Combine(_x, _y, _group = noone) : Node_RM(_x, _y, _group) const
input_display_list = [ 0,
["Combine", false], 15, 16, 13, 14,
["Camera", false], 11, 12, 1, 2, 3, 4, 5,
["Render", false, 17], 6, 7, 8, 10, 9,
["Render", false, 17], 6, 7, 8, 10, 18, 9,
]
temp_surface = [ 0, 0 ];
@ -104,6 +106,8 @@ function Node_RM_Combine(_x, _y, _group = noone) : Node_RM(_x, _y, _group) const
var _mer = _data[16];
var _ren = _data[17];
var _eint = _data[18];
var _outSurf = _outData[0];
if(!is_instanceof(_sh0, RM_Object)) return [ _outSurf, noone ];
@ -116,7 +120,9 @@ function Node_RM_Combine(_x, _y, _group = noone) : Node_RM(_x, _y, _group) const
var tx = 1024;
surface_set_shader(temp_surface[0]);
gpu_set_tex_filter(_eint);
draw_surface_stretched_safe(_env, tx * 0, tx * 0, tx, tx);
gpu_set_tex_filter(false);
surface_reset_shader();
switch(_typ) {

View File

@ -163,6 +163,8 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 49] = nodeValue("Env Interpolation", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
outputs[| 1] = nodeValue("Shape Data", self, JUNCTION_CONNECT.output, VALUE_TYPE.sdf, noone);
@ -176,7 +178,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
["Material", false], 9, 36, 35, 37, 38,
["Camera", false], 42, 43, 13, 14, 5, 6,
["Render", false, 44], 31, 30, 34, 10, 7, 8,
["Render", false, 44], 31, 30, 34, 49, 10, 7, 8,
["Volumetric", true, 32], 33,
];
@ -585,6 +587,8 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
var _tileRot = _data[47];
var _tileSca = _data[48];
var _eint = _data[49];
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1]);
for (var i = 0, n = array_length(temp_surface); i < n; i++)
@ -592,7 +596,9 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
var tx = 1024;
surface_set_shader(temp_surface[0]);
gpu_set_tex_filter(_eint);
draw_surface_stretched_safe(bgEnv, tx * 0, tx * 0, tx, tx);
gpu_set_tex_filter(false);
surface_reset_shader();
var _shape = shape_types[_shp];

View File

@ -45,11 +45,13 @@ function Node_RM_Render(_x, _y, _group = noone) : Node_RM(_x, _y, _group) constr
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 14] = nodeValue("Env Interpolation", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
input_display_list = [ 0, 13,
["Camera", false], 11, 12, 1, 2, 3, 4, 5,
["Render", false], 6, 7, 8, 10, 9,
["Render", false], 6, 7, 8, 10, 14, 9,
]
temp_surface = [ 0, 0 ];
@ -81,7 +83,8 @@ function Node_RM_Render(_x, _y, _group = noone) : Node_RM(_x, _y, _group) constr
var _crt = _data[11];
var _csa = _data[12];
var _shp = _data[13];
var _shp = _data[13];
var _eint = _data[14];
if(!is_instanceof(_shp, RM_Object)) return _outSurf;
@ -92,7 +95,9 @@ function Node_RM_Render(_x, _y, _group = noone) : Node_RM(_x, _y, _group) constr
var tx = 1024;
surface_set_shader(temp_surface[0]);
gpu_set_tex_filter(_eint);
draw_surface_stretched_safe(_env, tx * 0, tx * 0, tx, tx);
gpu_set_tex_filter(false);
surface_reset_shader();
object = _shp;

View File

@ -13,9 +13,10 @@ const float EPSILON = 1e-5;
const float PI = 3.14159265358979323846;
const float SUBTEXTURE_SIZE = 1024.;
const float TEXTURE_N = 8192. / SUBTEXTURE_SIZE;
const float TEXTURE_S = TEXTURE_N * TEXTURE_N;
const float TEXTURE_T = SUBTEXTURE_SIZE / 8192.;
const float TEXTURE_N = 8192. / SUBTEXTURE_SIZE;
const float TEXTURE_S = TEXTURE_N * TEXTURE_N;
const float TEXTURE_T = SUBTEXTURE_SIZE / 8192.;
const float TEXTURE_TX = 1. / SUBTEXTURE_SIZE;
uniform sampler2D texture0;
uniform sampler2D texture1;
@ -158,7 +159,7 @@ float influences[MAX_SHAPES];
float dot2( in vec3 v ) { return dot(v,v); }
float ndot( in vec2 a, in vec2 b ) { return a.x*b.x - a.y*b.y; }
vec4 sampleTexture(int textureIndex, vec2 coord) {
vec4 sampleTexture(int textureIndex, vec2 coord, int interpolation) {
if(coord.x < 0. || coord.y < 0. || coord.x > 1. || coord.y > 1.) return vec4(0.);
float i = float(textureIndex);
@ -169,15 +170,34 @@ float influences[MAX_SHAPES];
float row = floor(stcInd / TEXTURE_N);
float col = stcInd - row * TEXTURE_N;
vec2 tx = vec2(col, row) * TEXTURE_T;
vec2 sm = tx + coord * TEXTURE_T;
vec2 cl = vec2(col, row);
vec2 sm = (cl + coord) * TEXTURE_T;
if(txIndex == 0.) return texture2D(texture0, sm);
else if(txIndex == 1.) return texture2D(texture1, sm);
else if(txIndex == 2.) return texture2D(texture2, sm);
else if(txIndex == 3.) return texture2D(texture3, sm);
if(interpolation == 0) {
if(txIndex == 0.) return texture2D(texture0, sm);
else if(txIndex == 1.) return texture2D(texture1, sm);
else if(txIndex == 2.) return texture2D(texture2, sm);
else return texture2D(texture3, sm);
} else if(interpolation == 1) {
vec2 fr = fract(coord * SUBTEXTURE_SIZE);
vec2 sm1 = (cl + clamp(coord + vec2(TEXTURE_TX, 0.), 0., 1.)) * TEXTURE_T;
vec2 sm2 = (cl + clamp(coord + vec2( 0., TEXTURE_TX), 0., 1.)) * TEXTURE_T;
vec2 sm3 = (cl + clamp(coord + vec2(TEXTURE_TX, TEXTURE_TX), 0., 1.)) * TEXTURE_T;
if(txIndex == 0.) return mix(mix(texture2D(texture0, sm ), texture2D(texture0, sm1), fr.x),
mix(texture2D(texture0, sm2), texture2D(texture0, sm3), fr.x), fr.y);
else if(txIndex == 1.) return mix(mix(texture2D(texture1, sm ), texture2D(texture1, sm1), fr.x),
mix(texture2D(texture1, sm2), texture2D(texture1, sm3), fr.x), fr.y);
else if(txIndex == 2.) return mix(mix(texture2D(texture2, sm ), texture2D(texture2, sm1), fr.x),
mix(texture2D(texture2, sm2), texture2D(texture2, sm3), fr.x), fr.y);
else return mix(mix(texture2D(texture3, sm ), texture2D(texture3, sm1), fr.x),
mix(texture2D(texture3, sm2), texture2D(texture3, sm3), fr.x), fr.y);
}
return texture2D(texture0, sm);
return vec4(0.);
}
vec2 equirectangularUv(vec3 dir) {
@ -493,9 +513,9 @@ float influences[MAX_SHAPES];
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) );
vec4 x = sampleTexture( textureIndex, fract(p.yz), 0 );
vec4 y = sampleTexture( textureIndex, fract(p.zx), 0 );
vec4 z = sampleTexture( textureIndex, fract(p.xy), 0 );
// blend weights
vec3 w = pow( abs(n), vec3(k) );
@ -865,7 +885,7 @@ vec4 scene() {
if(useEnv == 1) {
vec3 ref = reflect(dir, norm);
vec4 refC = sampleTexture(0, equirectangularUv(ref));
vec4 refC = sampleTexture(0, equirectangularUv(ref), 0);
c = mix(c, c * refC.rgb, refl);
}
@ -913,7 +933,7 @@ void main() {
dir = normalize(camIrotMatrix * dir);
vec2 envUV = equirectangularUv(dir);
vec4 endC = sampleTexture(0, envUV);
vec4 endC = sampleTexture(0, envUV, 0);
bg = endC;
}