- [Raymarching] Add orthographic projection.

This commit is contained in:
Tanasart 2024-07-08 12:12:45 +07:00
parent 39acafebd7
commit 533fd6ec75
5 changed files with 22 additions and 14 deletions

Binary file not shown.

View File

@ -7,8 +7,7 @@ function Node_RM_Combine(_x, _y, _group = noone) : Node_RM(_x, _y, _group) const
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 1] = nodeValue("Projection", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) inputs[| 1] = nodeValue("Projection", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Perspective", "Orthographic" ]) .setDisplay(VALUE_DISPLAY.enum_button, [ "Perspective", "Orthographic" ]);
.setVisible(false, false);
inputs[| 2] = nodeValue("FOV", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 30) inputs[| 2] = nodeValue("FOV", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 30)
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 90, 1 ] }); .setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 90, 1 ] });

View File

@ -59,10 +59,9 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
.setDisplay(VALUE_DISPLAY.slider); .setDisplay(VALUE_DISPLAY.slider);
inputs[| 13] = nodeValue("Projection", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) inputs[| 13] = nodeValue("Projection", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Perspective", "Orthographic" ]) .setDisplay(VALUE_DISPLAY.enum_button, [ "Perspective", "Orthographic" ]);
.setVisible(false, false);
inputs[| 14] = nodeValue("Ortho Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 5.) inputs[| 14] = nodeValue("Ortho Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1.)
inputs[| 15] = nodeValue("Wave Amplitude", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 4, 4, 4 ]) inputs[| 15] = nodeValue("Wave Amplitude", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 4, 4, 4 ])
.setDisplay(VALUE_DISPLAY.vector); .setDisplay(VALUE_DISPLAY.vector);

View File

@ -7,8 +7,7 @@ function Node_RM_Render(_x, _y, _group = noone) : Node_RM(_x, _y, _group) constr
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 1] = nodeValue("Projection", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) inputs[| 1] = nodeValue("Projection", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Perspective", "Orthographic" ]) .setDisplay(VALUE_DISPLAY.enum_button, [ "Perspective", "Orthographic" ]);
.setVisible(false, false);
inputs[| 2] = nodeValue("FOV", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 30) inputs[| 2] = nodeValue("FOV", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 30)
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 90, 1 ] }); .setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 90, 1 ] });

View File

@ -780,15 +780,26 @@ vec4 scene() {
mat3 camRotMatrix = rx * ry * rz; mat3 camRotMatrix = rx * ry * rz;
mat3 camIrotMatrix = inverse(camRotMatrix); mat3 camIrotMatrix = inverse(camRotMatrix);
float dz = 1. / tan(radians(fov) / 2.); vec3 dir, eye;
vec2 cps = (v_vTexcoord - .5) * 2.; vec2 cps = (v_vTexcoord - .5) * 2.;
cps.x *= camRatio; cps.x *= camRatio;
vec3 dir = vec3(cps, -dz); if(ortho == 0) {
vec3 eye = vec3(0., 0., 5.); float dz = 1. / tan(radians(fov) / 2.);
dir = vec3(cps, -dz);
eye = vec3(0., 0., 5.);
} else if(ortho == 1) {
dir = vec3(0., 0., -1.);
eye = vec3(cps * orthoScale, 5.);
}
dir = normalize(camIrotMatrix * dir); dir = normalize(camIrotMatrix * dir);
eye = camIrotMatrix * eye; eye = camIrotMatrix * eye;
eye /= camScale; eye /= camScale;
if(volumetric[0] == 1) { if(volumetric[0] == 1) {