You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-15 13:51:40 +00:00
Use double emulation on modelview
This commit is contained in:
@@ -404,7 +404,27 @@ void vertex_shader(vec3 vertex_input,
|
|||||||
|
|
||||||
float roughness_highp = 1.0;
|
float roughness_highp = 1.0;
|
||||||
|
|
||||||
|
#ifdef USE_DOUBLE_PRECISION
|
||||||
mat4 modelview = scene_data.view_matrix * model_matrix;
|
mat4 modelview = scene_data.view_matrix * model_matrix;
|
||||||
|
|
||||||
|
// We separate the basis from the origin because the basis is fine with single point precision.
|
||||||
|
// Then we combine the translations from the model matrix and the view matrix using emulated doubles.
|
||||||
|
// We add the result to the vertex and ignore the final lost precision.
|
||||||
|
vec3 model_origin = model_matrix[3].xyz;
|
||||||
|
if (sc_multimesh()) {
|
||||||
|
modelview = modelview * matrix;
|
||||||
|
|
||||||
|
vec3 instance_origin = mat3(model_matrix) * matrix[3].xyz;
|
||||||
|
model_origin = double_add_vec3(model_origin, model_precision, instance_origin, vec3(0.0), model_precision);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overwrite the translation part of modelview with improved precision.
|
||||||
|
vec3 temp_precision; // Will be ignored.
|
||||||
|
modelview[3].xyz = double_add_vec3(model_origin, model_precision, scene_data.inv_view_matrix[3].xyz, view_precision, temp_precision);
|
||||||
|
modelview[3].xyz = mat3(scene_data.view_matrix) * modelview[3].xyz;
|
||||||
|
#else
|
||||||
|
mat4 modelview = scene_data.view_matrix * model_matrix;
|
||||||
|
#endif
|
||||||
mat3 modelview_normal = mat3(scene_data.view_matrix) * model_normal_matrix;
|
mat3 modelview_normal = mat3(scene_data.view_matrix) * model_normal_matrix;
|
||||||
mat4 read_view_matrix = scene_data.view_matrix;
|
mat4 read_view_matrix = scene_data.view_matrix;
|
||||||
vec2 read_viewport_size = scene_data.viewport_size;
|
vec2 read_viewport_size = scene_data.viewport_size;
|
||||||
@@ -421,22 +441,8 @@ void vertex_shader(vec3 vertex_input,
|
|||||||
// using local coordinates (default)
|
// using local coordinates (default)
|
||||||
#if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED)
|
#if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED)
|
||||||
|
|
||||||
#ifdef USE_DOUBLE_PRECISION
|
|
||||||
// We separate the basis from the origin because the basis is fine with single point precision.
|
|
||||||
// Then we combine the translations from the model matrix and the view matrix using emulated doubles.
|
|
||||||
// We add the result to the vertex and ignore the final lost precision.
|
|
||||||
vec3 model_origin = model_matrix[3].xyz;
|
|
||||||
if (sc_multimesh()) {
|
|
||||||
vertex = mat3(matrix) * vertex;
|
|
||||||
model_origin = double_add_vec3(model_origin, model_precision, matrix[3].xyz, vec3(0.0), model_precision);
|
|
||||||
}
|
|
||||||
vertex = mat3(inv_view_matrix * modelview) * vertex;
|
|
||||||
vec3 temp_precision; // Will be ignored.
|
|
||||||
vertex += double_add_vec3(model_origin, model_precision, scene_data.inv_view_matrix[3].xyz, view_precision, temp_precision);
|
|
||||||
vertex = mat3(scene_data.view_matrix) * vertex;
|
|
||||||
#else
|
|
||||||
vertex = (modelview * vec4(vertex, 1.0)).xyz;
|
vertex = (modelview * vec4(vertex, 1.0)).xyz;
|
||||||
#endif
|
|
||||||
#ifdef NORMAL_USED
|
#ifdef NORMAL_USED
|
||||||
normal = modelview_normal * normal;
|
normal = modelview_normal * normal;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -432,10 +432,30 @@ void vertex_shader(in vec3 vertex,
|
|||||||
|
|
||||||
float roughness_highp = 1.0;
|
float roughness_highp = 1.0;
|
||||||
|
|
||||||
mat4 modelview = view_matrix * model_matrix;
|
#ifdef USE_DOUBLE_PRECISION
|
||||||
mat3 modelview_normal = mat3(view_matrix) * model_normal_matrix;
|
mat4 modelview = scene_data.view_matrix * model_matrix;
|
||||||
mat4 read_view_matrix = view_matrix;
|
|
||||||
vec2 read_viewport_size = viewport_size;
|
// We separate the basis from the origin because the basis is fine with single point precision.
|
||||||
|
// Then we combine the translations from the model matrix and the view matrix using emulated doubles.
|
||||||
|
// We add the result to the vertex and ignore the final lost precision.
|
||||||
|
vec3 model_origin = model_matrix[3].xyz;
|
||||||
|
if (sc_multimesh()) {
|
||||||
|
modelview = modelview * matrix;
|
||||||
|
|
||||||
|
vec3 instance_origin = mat3(model_matrix) * matrix[3].xyz;
|
||||||
|
model_origin = double_add_vec3(model_origin, model_precision, instance_origin, vec3(0.0), model_precision);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overwrite the translation part of modelview with improved precision.
|
||||||
|
vec3 temp_precision; // Will be ignored.
|
||||||
|
modelview[3].xyz = double_add_vec3(model_origin, model_precision, scene_data.inv_view_matrix[3].xyz, view_precision, temp_precision);
|
||||||
|
modelview[3].xyz = mat3(scene_data.view_matrix) * modelview[3].xyz;
|
||||||
|
#else
|
||||||
|
mat4 modelview = scene_data.view_matrix * model_matrix;
|
||||||
|
#endif
|
||||||
|
mat3 modelview_normal = mat3(scene_data.view_matrix) * model_normal_matrix;
|
||||||
|
mat4 read_view_matrix = scene_data.view_matrix;
|
||||||
|
vec2 read_viewport_size = scene_data.viewport_size;
|
||||||
|
|
||||||
{
|
{
|
||||||
#CODE : VERTEX
|
#CODE : VERTEX
|
||||||
@@ -450,22 +470,8 @@ void vertex_shader(in vec3 vertex,
|
|||||||
// using local coordinates (default)
|
// using local coordinates (default)
|
||||||
#if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED)
|
#if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED)
|
||||||
|
|
||||||
#ifdef USE_DOUBLE_PRECISION
|
|
||||||
// We separate the basis from the origin because the basis is fine with single point precision.
|
|
||||||
// Then we combine the translations from the model matrix and the view matrix using emulated doubles.
|
|
||||||
// We add the result to the vertex and ignore the final lost precision.
|
|
||||||
vec3 model_origin = model_matrix[3].xyz;
|
|
||||||
if (sc_multimesh()) {
|
|
||||||
vertex = mat3(matrix) * vertex;
|
|
||||||
model_origin = double_add_vec3(model_origin, model_precision, matrix[3].xyz, vec3(0.0), model_precision);
|
|
||||||
}
|
|
||||||
vertex = mat3(inv_view_matrix * modelview) * vertex;
|
|
||||||
vec3 temp_precision;
|
|
||||||
vertex += double_add_vec3(model_origin, model_precision, inv_view_matrix[3].xyz, view_precision, temp_precision);
|
|
||||||
vertex = mat3(view_matrix) * vertex;
|
|
||||||
#else
|
|
||||||
vertex = (modelview * vec4(vertex, 1.0)).xyz;
|
vertex = (modelview * vec4(vertex, 1.0)).xyz;
|
||||||
#endif
|
|
||||||
#ifdef NORMAL_USED
|
#ifdef NORMAL_USED
|
||||||
normal_highp = modelview_normal * normal_highp;
|
normal_highp = modelview_normal * normal_highp;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user