evas_canvas3d: sets for shadow rendering
Summary: Add possibility change quality and offsets for shadow. Add mesh API's to sets size, step and bias constant. Add scene API to sets depth values. Reviewers: Hermet, cedric Reviewed By: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D3056 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
parent
eeba25397f
commit
28d69200f9
|
@ -132,6 +132,9 @@ _mesh_init(Evas_Canvas3D_Mesh_Data *pd)
|
|||
pd->color_pick_key.b = 0.0;
|
||||
#endif
|
||||
pd->color_pick_enabled = EINA_FALSE;
|
||||
pd->shadows_edges_filtering_level = 4;
|
||||
pd->shadows_edges_size = 300.0;
|
||||
pd->shadows_constant_bias = 0.00015;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
@ -1078,4 +1081,40 @@ _evas_canvas3d_mesh_color_pick_enable_set(Eo *obj, Evas_Canvas3D_Mesh_Data *pd,
|
|||
eo_do(obj, evas_canvas3d_object_change(EVAS_CANVAS3D_STATE_MESH_COLOR_PICK, NULL));
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_evas_canvas3d_mesh_shadows_edges_filtering_set(Eo *obj, Evas_Canvas3D_Mesh_Data *pd,
|
||||
int blur_level, Evas_Real edges_size)
|
||||
{
|
||||
if (blur_level > 0)
|
||||
pd->shadows_edges_filtering_level = blur_level;
|
||||
if (edges_size >= 0)
|
||||
pd->shadows_edges_size = edges_size;
|
||||
eo_do(obj, evas_canvas3d_object_change(EVAS_CANVAS3D_STATE_MESH_SHADOWS_EDGES_FILTERING, NULL));
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_evas_canvas3d_mesh_shadows_edges_filtering_get(Eo *obj EINA_UNUSED, Evas_Canvas3D_Mesh_Data *pd,
|
||||
int *blur_level, Evas_Real *edges_size)
|
||||
{
|
||||
if (blur_level) *blur_level = pd->shadows_edges_filtering_level;
|
||||
if (edges_size) *edges_size = pd->shadows_edges_size;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_evas_canvas3d_mesh_shadows_constant_bias_set(Eo *obj EINA_UNUSED, Evas_Canvas3D_Mesh_Data *pd,
|
||||
Evas_Real bias)
|
||||
{
|
||||
if (pd->shadows_constant_bias != bias)
|
||||
{
|
||||
pd->shadows_constant_bias = bias;
|
||||
eo_do(obj, evas_canvas3d_object_change(EVAS_CANVAS3D_STATE_MESH_SHADOWS_CONSTANT_BIAS, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
EOLIAN static Evas_Real
|
||||
_evas_canvas3d_mesh_shadows_constant_bias_get(Eo *obj EINA_UNUSED, Evas_Canvas3D_Mesh_Data *pd)
|
||||
{
|
||||
return pd->shadows_constant_bias;
|
||||
}
|
||||
|
||||
#include "canvas/evas_canvas3d_mesh.eo.c"
|
||||
|
|
|
@ -360,7 +360,33 @@ class Evas.Canvas3D.Mesh (Evas.Canvas3D.Object, Evas.Common_Interface, Efl.File)
|
|||
assembly: Evas.Canvas3D.Vertex_Assembly; [[The vertex assembly.]]
|
||||
}
|
||||
}
|
||||
@property shadows_edges_filtering {
|
||||
set {
|
||||
[[Set the shadow edges blur parameters.
|
||||
|
||||
The averaging values in window is used for blurring.
|
||||
User can set the size of window and num of points in window.
|
||||
]]
|
||||
}
|
||||
get {
|
||||
[[Get the shadow edges blur parameters.]]
|
||||
}
|
||||
values {
|
||||
blur_level: int; [[Number of points within a bluring radius.]]
|
||||
edges_size: Evas.Real; [[The bluring radius.]]
|
||||
}
|
||||
}
|
||||
@property shadows_constant_bias {
|
||||
set {
|
||||
[[Set offset shadow toward object.]]
|
||||
}
|
||||
get {
|
||||
[[Get offset shadow toward object.]]
|
||||
}
|
||||
values {
|
||||
bias: Evas.Real; [[Offset.]]
|
||||
}
|
||||
}
|
||||
}
|
||||
implements {
|
||||
Eo.Base.constructor;
|
||||
|
|
|
@ -74,6 +74,8 @@ _evas_canvas3d_scene_eo_base_constructor(Eo *obj, Evas_Canvas3D_Scene_Data *pd)
|
|||
pd->color_pick_enabled = EINA_FALSE;
|
||||
pd->node_mesh_colors = NULL;
|
||||
pd->colors_node_mesh = NULL;
|
||||
pd->depth_offset = 4.0;
|
||||
pd->depth_constant = 100.0;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -804,4 +806,21 @@ _evas_canvas3d_scene_color_pick_enable_set(Eo *obj EINA_UNUSED, Evas_Canvas3D_Sc
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_evas_canvas3d_scene_shadows_depth_set(Eo *obj EINA_UNUSED, Evas_Canvas3D_Scene_Data *pd,
|
||||
Evas_Real depth_offset, Evas_Real depth_constant)
|
||||
{
|
||||
pd->depth_offset = depth_offset;
|
||||
pd->depth_constant = depth_constant;
|
||||
eo_do(obj, evas_canvas3d_object_change(EVAS_CANVAS3D_STATE_SCENE_SHADOWS_DEPTH, NULL));
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_evas_canvas3d_scene_shadows_depth_get(Eo *obj EINA_UNUSED, Evas_Canvas3D_Scene_Data *pd,
|
||||
Evas_Real *depth_offset, Evas_Real *depth_constant)
|
||||
{
|
||||
if (depth_offset) *depth_offset = pd->depth_offset;
|
||||
if (depth_constant) *depth_constant = pd->depth_constant;
|
||||
}
|
||||
|
||||
#include "canvas/evas_canvas3d_scene.eo.c"
|
||||
|
|
|
@ -145,6 +145,21 @@ class Evas.Canvas3D.Scene (Evas.Canvas3D.Object, Evas.Common_Interface)
|
|||
camera node for the scene.]]
|
||||
}
|
||||
}
|
||||
@property shadows_depth {
|
||||
set {
|
||||
[[Set scale and units used to calculate depth values.]]
|
||||
}
|
||||
get {
|
||||
[[Get scale and units used to calculate depth values.]]
|
||||
}
|
||||
values {
|
||||
depth_offset: Evas.Real; [[Scale factor that is used to
|
||||
create a variable depth offset
|
||||
for each polygon.]]
|
||||
depth_constant: Evas.Real; [[Value to create a constant
|
||||
depth offset]]
|
||||
}
|
||||
}
|
||||
}
|
||||
implements {
|
||||
Eo.Base.constructor;
|
||||
|
|
|
@ -2694,6 +2694,8 @@ _3d_render(Evas *eo_e, Evas_Object *eo_obj EINA_UNUSED,
|
|||
scene_data.bg_color = pd_scene->bg_color;
|
||||
scene_data.shadows_enabled = pd_scene->shadows_enabled;
|
||||
scene_data.camera_node = pd_scene->camera_node;
|
||||
scene_data.depth_offset = pd_scene->depth_offset;
|
||||
scene_data.depth_constant = pd_scene->depth_constant;
|
||||
|
||||
/* Phase 1 - Update scene graph tree. */
|
||||
eo_do(scene, evas_canvas3d_object_update());
|
||||
|
|
|
@ -264,6 +264,7 @@ enum Evas.Canvas3D.State
|
|||
scene_size,
|
||||
scene_shadows_enabled,
|
||||
scene_updated, [[@since 1.14]]
|
||||
scene_shadows_depth,
|
||||
|
||||
texture_data = 1,
|
||||
texture_wrap,
|
||||
|
@ -285,6 +286,8 @@ enum Evas.Canvas3D.State
|
|||
mesh_blending,
|
||||
mesh_alpha_test,
|
||||
mesh_color_pick,
|
||||
mesh_shadows_edges_filtering,
|
||||
mesh_shadows_constant_bias,
|
||||
|
||||
camera_projection = 1,
|
||||
|
||||
|
|
|
@ -229,6 +229,9 @@ struct _Evas_Canvas3D_Scene
|
|||
|
||||
Eina_Hash *node_mesh_colors;
|
||||
Eina_Hash *colors_node_mesh;
|
||||
/*sets constant for shadow rendering*/
|
||||
Evas_Real depth_offset;
|
||||
Evas_Real depth_constant;
|
||||
};
|
||||
|
||||
struct _Evas_Canvas3D_Node_Mesh
|
||||
|
@ -387,6 +390,10 @@ struct _Evas_Canvas3D_Mesh
|
|||
Evas_Color color_pick_key;
|
||||
#endif
|
||||
Eina_Bool color_pick_enabled :1;
|
||||
/*sets of the quality and offsets for shadow rendering*/
|
||||
int shadows_edges_filtering_level;
|
||||
Evas_Real shadows_edges_size;
|
||||
Evas_Real shadows_constant_bias;
|
||||
};
|
||||
|
||||
struct _Evas_Canvas3D_Texture
|
||||
|
@ -440,6 +447,10 @@ struct _Evas_Canvas3D_Scene_Public_Data
|
|||
|
||||
Eina_Hash *node_mesh_colors;
|
||||
Eina_Hash *colors_node_mesh;
|
||||
|
||||
/*sets constant for shadow rendering*/
|
||||
Evas_Real depth_offset;
|
||||
Evas_Real depth_constant;
|
||||
};
|
||||
|
||||
struct _Evas_Canvas3D_Pick_Data
|
||||
|
|
|
@ -1005,7 +1005,14 @@ _mesh_draw_data_build(E3D_Draw_Data *data,
|
|||
data->flags |= E3D_SHADER_FLAG_ALPHA_TEST_ENABLED;
|
||||
|
||||
if (pdmesh->shadowed)
|
||||
data->flags |= E3D_SHADER_FLAG_SHADOWED;
|
||||
{
|
||||
data->flags |= E3D_SHADER_FLAG_SHADOWED;
|
||||
data->pcf_size = 1 / pdmesh->shadows_edges_size;
|
||||
data->pcf_step = (Evas_Real)pdmesh->shadows_edges_filtering_level;
|
||||
#ifdef GL_GLES
|
||||
data->constant_bias = pdmesh->shadows_constant_bias;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (pdmesh->color_pick_enabled)
|
||||
data->color_pick_key = pdmesh->color_pick_key;
|
||||
|
@ -1178,7 +1185,7 @@ void _shadowmap_render(E3D_Drawable *drawable, E3D_Renderer *renderer,
|
|||
Evas_Mat4 matrix_vp;
|
||||
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(4.0, 100.0);
|
||||
glPolygonOffset(data->depth_offset, data->depth_constant);
|
||||
#ifdef GL_GLES
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, drawable->shadow_fbo);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, drawable->depth_render_buf);
|
||||
|
|
|
@ -110,6 +110,12 @@ struct _E3D_Draw_Data
|
|||
double color_pick_key;
|
||||
#else
|
||||
Evas_Color color_pick_key;
|
||||
#endif
|
||||
/*Sets of the quality of shadow rendering*/
|
||||
Evas_Real pcf_step;
|
||||
Evas_Real pcf_size;
|
||||
#ifdef GL_GLES
|
||||
Evas_Real constant_bias;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -45,6 +45,11 @@ typedef enum _E3D_Uniform
|
|||
E3D_UNIFORM_TEXTURE_MATRIX_TRANSFORM_NORMAL1,
|
||||
|
||||
E3D_UNIFORM_SHADOWMAP,
|
||||
E3D_UNIFORM_SHADOWS_PCF_STEP,
|
||||
E3D_UNIFORM_SHADOWS_PCF_SIZE,
|
||||
#ifdef GL_GLES
|
||||
E3D_UNIFORM_SHADOWS_CONSTANT_BIAS,
|
||||
#endif
|
||||
|
||||
E3D_UNIFORM_LIGHT_POSITION,
|
||||
E3D_UNIFORM_LIGHT_SPOT_DIR,
|
||||
|
@ -337,6 +342,11 @@ static const char *uniform_names[] =
|
|||
"uTextureMatrixTransformEmission1",
|
||||
"uTextureMatrixTransformNormal1",
|
||||
"uShadowMap",
|
||||
"uShadowsPCFStep",
|
||||
"uShadowsPCFSize",
|
||||
#ifdef GL_GLES
|
||||
"uShadowsConstantBias",
|
||||
#endif
|
||||
"uLightPosition",
|
||||
"uLightSpotDir",
|
||||
"uLightSpotExp",
|
||||
|
@ -512,6 +522,17 @@ _uniform_upload(E3D_Uniform u, GLint loc, const E3D_Draw_Data *data)
|
|||
case E3D_UNIFORM_SHADOWMAP:
|
||||
glUniform1i(loc, data->smap_sampler);
|
||||
break;
|
||||
case E3D_UNIFORM_SHADOWS_PCF_STEP:
|
||||
glUniform1f(loc, data->pcf_step);
|
||||
break;
|
||||
case E3D_UNIFORM_SHADOWS_PCF_SIZE:
|
||||
glUniform1f(loc, data->pcf_size);
|
||||
break;
|
||||
#ifdef GL_GLES
|
||||
case E3D_UNIFORM_SHADOWS_CONSTANT_BIAS:
|
||||
glUniform1f(loc, data->constant_bias);
|
||||
break;
|
||||
#endif
|
||||
case E3D_UNIFORM_LIGHT_POSITION:
|
||||
glUniform4f(loc, data->light.position.x, data->light.position.y,
|
||||
data->light.position.z, data->light.position.w);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
static const char vertex_color_vert_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -46,7 +46,7 @@ static const char vertex_color_vert_glsl[] =
|
|||
|
||||
static const char vertex_color_frag_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -116,7 +116,7 @@ static const char vertex_color_frag_glsl[] =
|
|||
|
||||
static const char diffuse_vert_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -160,7 +160,7 @@ static const char diffuse_vert_glsl[] =
|
|||
|
||||
static const char diffuse_frag_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -261,7 +261,7 @@ static const char diffuse_frag_glsl[] =
|
|||
|
||||
static const char flat_vert_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -386,7 +386,7 @@ static const char flat_vert_glsl[] =
|
|||
|
||||
static const char flat_frag_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -401,27 +401,31 @@ static const char flat_frag_glsl[] =
|
|||
"#ifdef SHADOWED\n"
|
||||
"varying vec4 vLightPosition;\n"
|
||||
"uniform sampler2D uShadowMap;\n"
|
||||
"uniform float uShadowsPCFStep;\n"
|
||||
"uniform float uShadowsPCFSize;\n"
|
||||
"uniform float uShadowsConstantBias;\n"
|
||||
"float shadow;\n"
|
||||
"float pcf(vec4 lpos, float size)\n"
|
||||
"float pcf(vec4 lpos)\n"
|
||||
"{\n"
|
||||
" vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
|
||||
" float i, j, shadow;\n"
|
||||
" float i, j, shadow, q, c;\n"
|
||||
" q = floor(uShadowsPCFStep * 2.0);\n"
|
||||
" c = floor(uShadowsPCFStep * uShadowsPCFStep * 4.0);\n"
|
||||
" shadow = 0.0;\n"
|
||||
"#ifndef GL_ES\n"
|
||||
" for (i = -4.0; i < 4.0; i++)\n"
|
||||
" for (j = -4.0; j < 4.0; j++)\n"
|
||||
" shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n"
|
||||
" for (i = -uShadowsPCFStep; i < uShadowsPCFStep; i += 1.0)\n"
|
||||
" for (j = -uShadowsPCFStep; j < uShadowsPCFStep; j += 1.0)\n"
|
||||
" shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / q, j / q) * uShadowsPCFSize).x);\n"
|
||||
"#else\n"
|
||||
" const vec4 unpack = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);\n"
|
||||
" const float bias = 0.00015 /*TODO Optimizate set of offset*/;\n"
|
||||
" for (i = -4.0; i < 4.0; i++)\n"
|
||||
" for (j = -4.0; j < 4.0; j++)\n"
|
||||
" for (i = -uShadowsPCFStep; i < uShadowsPCFStep; i += 1.0)\n"
|
||||
" for (j = -uShadowsPCFStep; j < uShadowsPCFStep; j += 1.0)\n"
|
||||
" {\n"
|
||||
" vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size);\n"
|
||||
" shadow += float(smcoord.z < dot(zvalue, unpack) + bias);\n"
|
||||
" vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / q, j / q) * uShadowsPCFSize);\n"
|
||||
" shadow += float(smcoord.z < dot(zvalue, unpack) + uShadowsConstantBias);\n"
|
||||
" }\n"
|
||||
"#endif //GL_ES\n"
|
||||
" return shadow / 64.0;\n"
|
||||
" return shadow / c;\n"
|
||||
"}\n"
|
||||
"#endif //SHADOWED\n"
|
||||
"#ifdef DIFFUSE\n"
|
||||
|
@ -570,7 +574,7 @@ static const char flat_frag_glsl[] =
|
|||
"void main() {\n"
|
||||
" vec4 color;\n"
|
||||
"#ifdef SHADOWED\n"
|
||||
" shadow = pcf(vLightPosition, 1.0 / 200.0);\n"
|
||||
" shadow = pcf(vLightPosition);\n"
|
||||
"#endif //SHADOWED\n"
|
||||
" color = fragmentFlat();\n"
|
||||
"#ifdef ALPHA_TEST_ENABLED\n"
|
||||
|
@ -628,7 +632,7 @@ static const char flat_frag_glsl[] =
|
|||
|
||||
static const char phong_vert_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -721,7 +725,7 @@ static const char phong_vert_glsl[] =
|
|||
|
||||
static const char phong_frag_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -738,27 +742,31 @@ static const char phong_frag_glsl[] =
|
|||
"#ifdef SHADOWED\n"
|
||||
"varying vec4 vLightPosition;\n"
|
||||
"uniform sampler2D uShadowMap;\n"
|
||||
"uniform float uShadowsPCFStep;\n"
|
||||
"uniform float uShadowsPCFSize;\n"
|
||||
"uniform float uShadowsConstantBias;\n"
|
||||
"float shadow;\n"
|
||||
"float pcf(vec4 lpos, float size)\n"
|
||||
"float pcf(vec4 lpos)\n"
|
||||
"{\n"
|
||||
" vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
|
||||
" float i, j, shadow;\n"
|
||||
" float i, j, shadow, q, c;\n"
|
||||
" q = floor(uShadowsPCFStep * 2.0);\n"
|
||||
" c = floor(uShadowsPCFStep * uShadowsPCFStep * 4.0);\n"
|
||||
" shadow = 0.0;\n"
|
||||
"#ifndef GL_ES\n"
|
||||
" for (i = -4.0; i < 4.0; i++)\n"
|
||||
" for (j = -4.0; j < 4.0; j++)\n"
|
||||
" shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n"
|
||||
" for (i = -uShadowsPCFStep; i < uShadowsPCFStep; i += 1.0)\n"
|
||||
" for (j = -uShadowsPCFStep; j < uShadowsPCFStep; j += 1.0)\n"
|
||||
" shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / q, j / q) * uShadowsPCFSize).x);\n"
|
||||
"#else\n"
|
||||
" const vec4 unpack = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);\n"
|
||||
" const float bias = 0.00015 /*TODO Optimizate set of offset*/;\n"
|
||||
" for (i = -4.0; i < 4.0; i++)\n"
|
||||
" for (j = -4.0; j < 4.0; j++)\n"
|
||||
" for (i = -uShadowsPCFStep; i < uShadowsPCFStep; i += 1.0)\n"
|
||||
" for (j = -uShadowsPCFStep; j < uShadowsPCFStep; j += 1.0)\n"
|
||||
" {\n"
|
||||
" vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size);\n"
|
||||
" shadow += float(smcoord.z < dot(zvalue, unpack) + bias);\n"
|
||||
" vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / q, j / q) * uShadowsPCFSize);\n"
|
||||
" shadow += float(smcoord.z < dot(zvalue, unpack) + uShadowsConstantBias);\n"
|
||||
" }\n"
|
||||
"#endif //GL_ES\n"
|
||||
" return shadow / 64.0;\n"
|
||||
" return shadow / c;\n"
|
||||
"}\n"
|
||||
"#endif //SHADOWED\n"
|
||||
"#ifdef DIFFUSE\n"
|
||||
|
@ -943,7 +951,7 @@ static const char phong_frag_glsl[] =
|
|||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"#ifdef SHADOWED\n"
|
||||
" shadow = pcf(vLightPosition, 1.0 / 300.0);\n"
|
||||
" shadow = pcf(vLightPosition);\n"
|
||||
"#endif //SHADOWED\n"
|
||||
" color = fragmentPhong();\n"
|
||||
"#ifdef ALPHA_TEST_ENABLED\n"
|
||||
|
@ -1001,7 +1009,7 @@ static const char phong_frag_glsl[] =
|
|||
|
||||
static const char normal_map_vert_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -1151,7 +1159,7 @@ static const char normal_map_vert_glsl[] =
|
|||
|
||||
static const char normal_map_frag_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -1168,27 +1176,31 @@ static const char normal_map_frag_glsl[] =
|
|||
"#ifdef SHADOWED\n"
|
||||
"varying vec4 vLightPosition;\n"
|
||||
"uniform sampler2D uShadowMap;\n"
|
||||
"uniform float uShadowsPCFStep;\n"
|
||||
"uniform float uShadowsPCFSize;\n"
|
||||
"uniform float uShadowsConstantBias;\n"
|
||||
"float shadow;\n"
|
||||
"float pcf(vec4 lpos, float size)\n"
|
||||
"float pcf(vec4 lpos)\n"
|
||||
"{\n"
|
||||
" vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
|
||||
" float i, j, shadow;\n"
|
||||
" float i, j, shadow, q, c;\n"
|
||||
" q = floor(uShadowsPCFStep * 2.0);\n"
|
||||
" c = floor(uShadowsPCFStep * uShadowsPCFStep * 4.0);\n"
|
||||
" shadow = 0.0;\n"
|
||||
"#ifndef GL_ES\n"
|
||||
" for (i = -4.0; i < 4.0; i++)\n"
|
||||
" for (j = -4.0; j < 4.0; j++)\n"
|
||||
" shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n"
|
||||
" for (i = -uShadowsPCFStep; i < uShadowsPCFStep; i += 1.0)\n"
|
||||
" for (j = -uShadowsPCFStep; j < uShadowsPCFStep; j += 1.0)\n"
|
||||
" shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / q, j / q) * uShadowsPCFSize).x);\n"
|
||||
"#else\n"
|
||||
" const vec4 unpack = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);\n"
|
||||
" const float bias = 0.00015 /*TODO Optimizate set of offset*/;\n"
|
||||
" for (i = -4.0; i < 4.0; i++)\n"
|
||||
" for (j = -4.0; j < 4.0; j++)\n"
|
||||
" for (i = -uShadowsPCFStep; i < uShadowsPCFStep; i += 1.0)\n"
|
||||
" for (j = -uShadowsPCFStep; j < uShadowsPCFStep; j += 1.0)\n"
|
||||
" {\n"
|
||||
" vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size);\n"
|
||||
" shadow += float(smcoord.z < dot(zvalue, unpack) + bias);\n"
|
||||
" vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / q, j / q) * uShadowsPCFSize);\n"
|
||||
" shadow += float(smcoord.z < dot(zvalue, unpack) + uShadowsConstantBias);\n"
|
||||
" }\n"
|
||||
"#endif //GL_ES\n"
|
||||
" return shadow / 64.0;\n"
|
||||
" return shadow / c;\n"
|
||||
"}\n"
|
||||
"#endif //SHADOWED\n"
|
||||
"#ifdef NORMAL_TEXTURE\n"
|
||||
|
@ -1417,7 +1429,7 @@ static const char normal_map_frag_glsl[] =
|
|||
"void main() {\n"
|
||||
" vec4 color;\n"
|
||||
"#ifdef SHADOWED\n"
|
||||
" shadow = pcf(vLightPosition, 1.0 / 200.0);\n"
|
||||
" shadow = pcf(vLightPosition);\n"
|
||||
"#endif //SHADOWED\n"
|
||||
" color = fragmentNormalMap();\n"
|
||||
"#ifdef ALPHA_TEST_ENABLED\n"
|
||||
|
@ -1474,7 +1486,7 @@ static const char normal_map_frag_glsl[] =
|
|||
|
||||
static const char shadow_map_vert_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -1510,7 +1522,7 @@ static const char shadow_map_vert_glsl[] =
|
|||
"#endif // VERTEX_POSITION\n"
|
||||
"#endif //VERTEX_POSITION_BLEND\n"
|
||||
"#ifdef ALPHA_TEST_ENABLED\n"
|
||||
" #ifdef VERTEX_TEXCOORD_BLEND\n"
|
||||
"#ifdef VERTEX_TEXCOORD_BLEND\n"
|
||||
" vTexCoord = mix(aTexCoord1.st, aTexCoord0.st, uTexCoordWeight);\n"
|
||||
"#else\n"
|
||||
"#ifdef VERTEX_TEXCOORD\n"
|
||||
|
@ -1524,7 +1536,7 @@ static const char shadow_map_vert_glsl[] =
|
|||
|
||||
static const char shadow_map_frag_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -1627,7 +1639,7 @@ static const char shadow_map_frag_glsl[] =
|
|||
|
||||
static const char color_pick_vert_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -1654,7 +1666,7 @@ static const char color_pick_vert_glsl[] =
|
|||
|
||||
static const char color_pick_frag_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -1723,7 +1735,7 @@ static const char color_pick_frag_glsl[] =
|
|||
|
||||
static const char parallax_occlusion_vert_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -1843,7 +1855,7 @@ static const char parallax_occlusion_vert_glsl[] =
|
|||
|
||||
static const char parallax_occlusion_frag_glsl[] =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"precision highp float;\n"
|
||||
"precision mediump int;\n"
|
||||
"precision lowp sampler2D;\n"
|
||||
"#endif\n"
|
||||
|
@ -1871,27 +1883,31 @@ static const char parallax_occlusion_frag_glsl[] =
|
|||
"#ifdef SHADOWED\n"
|
||||
"varying vec4 vLightPosition;\n"
|
||||
"uniform sampler2D uShadowMap;\n"
|
||||
"uniform float uShadowsPCFStep;\n"
|
||||
"uniform float uShadowsPCFSize;\n"
|
||||
"uniform float uShadowsConstantBias;\n"
|
||||
"float shadow;\n"
|
||||
"float pcf(vec4 lpos, float size)\n"
|
||||
"float pcf(vec4 lpos)\n"
|
||||
"{\n"
|
||||
" vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
|
||||
" float i, j, shadow;\n"
|
||||
" float i, j, shadow, q, c;\n"
|
||||
" q = floor(uShadowsPCFStep * 2.0);\n"
|
||||
" c = floor(uShadowsPCFStep * uShadowsPCFStep * 4.0);\n"
|
||||
" shadow = 0.0;\n"
|
||||
"#ifndef GL_ES\n"
|
||||
" for (i = -4.0; i < 4.0; i++)\n"
|
||||
" for (j = -4.0; j < 4.0; j++)\n"
|
||||
" shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n"
|
||||
" for (i = -uShadowsPCFStep; i < uShadowsPCFStep; i += 1.0)\n"
|
||||
" for (j = -uShadowsPCFStep; j < uShadowsPCFStep; j += 1.0)\n"
|
||||
" shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / q, j / q) * uShadowsPCFSize).x);\n"
|
||||
"#else\n"
|
||||
" const vec4 unpack = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);\n"
|
||||
" const float bias = 0.00015 /*TODO Optimizate set of offset*/;\n"
|
||||
" for (i = -4.0; i < 4.0; i++)\n"
|
||||
" for (j = -4.0; j < 4.0; j++)\n"
|
||||
" for (i = -uShadowsPCFStep; i < uShadowsPCFStep; i += 1.0)\n"
|
||||
" for (j = -uShadowsPCFStep; j < uShadowsPCFStep; j += 1.0)\n"
|
||||
" {\n"
|
||||
" vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size);\n"
|
||||
" shadow += float(smcoord.z < dot(zvalue, unpack) + bias);\n"
|
||||
" vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / q, j / q) * uShadowsPCFSize);\n"
|
||||
" shadow += float(smcoord.z < dot(zvalue, unpack) + uShadowsConstantBias);\n"
|
||||
" }\n"
|
||||
"#endif //GL_ES\n"
|
||||
" return shadow / 64.0;\n"
|
||||
" return shadow / c;\n"
|
||||
"}\n"
|
||||
"#endif //SHADOWED\n"
|
||||
"#ifdef DIFFUSE\n"
|
||||
|
@ -2119,7 +2135,7 @@ static const char parallax_occlusion_frag_glsl[] =
|
|||
"void main() {\n"
|
||||
" vec4 color;\n"
|
||||
"#ifdef SHADOWED\n"
|
||||
" shadow = pcf(vLightPosition, 1.0 / 200.0);\n"
|
||||
" shadow = pcf(vLightPosition);\n"
|
||||
"#endif //SHADOWED\n"
|
||||
" color = fragmentParallaxMap();\n"
|
||||
"#ifdef ALPHA_TEST_ENABLED\n"
|
||||
|
|
|
@ -49,7 +49,7 @@ vec4 fragmentFlat()
|
|||
void main() {
|
||||
vec4 color;
|
||||
#ifdef SHADOWED
|
||||
shadow = pcf(vLightPosition, 1.0 / 200.0);
|
||||
shadow = pcf(vLightPosition);
|
||||
#endif //SHADOWED
|
||||
|
||||
color = fragmentFlat();
|
||||
|
|
|
@ -40,27 +40,33 @@ define(`FRAGMENT_SHADER_USE_SHADOWS', `
|
|||
#ifdef SHADOWED
|
||||
varying vec4 vLightPosition;
|
||||
uniform sampler2D uShadowMap;
|
||||
uniform float uShadowsPCFStep;
|
||||
uniform float uShadowsPCFSize;
|
||||
#ifdef GL_ES
|
||||
uniform float uShadowsConstantBias;
|
||||
#endif //GL_ES'
|
||||
float shadow;
|
||||
float pcf(vec4 lpos, float size)
|
||||
float pcf(vec4 lpos)
|
||||
{
|
||||
vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
|
||||
float i, j, shadow;
|
||||
float i, j, shadow, q, c;
|
||||
q = floor(uShadowsPCFStep * 2.0);
|
||||
c = floor(uShadowsPCFStep * uShadowsPCFStep * 4.0);
|
||||
shadow = 0.0;
|
||||
`#ifndef GL_ES'
|
||||
for (i = -4.0; i < 4.0; i++)
|
||||
for (j = -4.0; j < 4.0; j++)
|
||||
shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);
|
||||
for (i = -uShadowsPCFStep; i < uShadowsPCFStep; i += 1.0)
|
||||
for (j = -uShadowsPCFStep; j < uShadowsPCFStep; j += 1.0)
|
||||
shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / q, j / q) * uShadowsPCFSize).x);
|
||||
`#else'
|
||||
const vec4 unpack = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
|
||||
const float bias = 0.00015 /*TODO Optimizate set of offset*/;
|
||||
for (i = -4.0; i < 4.0; i++)
|
||||
for (j = -4.0; j < 4.0; j++)
|
||||
for (i = -uShadowsPCFStep; i < uShadowsPCFStep; i += 1.0)
|
||||
for (j = -uShadowsPCFStep; j < uShadowsPCFStep; j += 1.0)
|
||||
{
|
||||
vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size);
|
||||
shadow += float(smcoord.z < dot(zvalue, unpack) + bias);
|
||||
vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / q, j / q) * uShadowsPCFSize);
|
||||
shadow += float(smcoord.z < dot(zvalue, unpack) + uShadowsConstantBias);
|
||||
}
|
||||
`#endif //GL_ES'
|
||||
return shadow / 64.0;
|
||||
return shadow / c;
|
||||
}
|
||||
#endif //SHADOWED')
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ vec4 fragmentNormalMap()
|
|||
void main() {
|
||||
vec4 color;
|
||||
#ifdef SHADOWED
|
||||
shadow = pcf(vLightPosition, 1.0 / 200.0);
|
||||
shadow = pcf(vLightPosition);
|
||||
#endif //SHADOWED
|
||||
|
||||
color = fragmentNormalMap();
|
||||
|
|
|
@ -216,7 +216,7 @@ vec4 fragmentParallaxMap()
|
|||
void main() {
|
||||
vec4 color;
|
||||
#ifdef SHADOWED
|
||||
shadow = pcf(vLightPosition, 1.0 / 200.0);
|
||||
shadow = pcf(vLightPosition);
|
||||
#endif //SHADOWED
|
||||
|
||||
color = fragmentParallaxMap();
|
||||
|
|
|
@ -87,7 +87,7 @@ void main()
|
|||
{
|
||||
vec4 color;
|
||||
#ifdef SHADOWED
|
||||
shadow = pcf(vLightPosition, 1.0 / 300.0);
|
||||
shadow = pcf(vLightPosition);
|
||||
#endif //SHADOWED
|
||||
|
||||
color = fragmentPhong();
|
||||
|
|
Loading…
Reference in New Issue