diff options
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_material.h | 21 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 15 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 10 |
5 files changed, 36 insertions, 16 deletions
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index eef07fdb783..64ce936e64a 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -84,14 +84,15 @@ typedef enum GPUType { } GPUType; typedef enum GPUBuiltin { - GPU_VIEW_MATRIX = 1, - GPU_OBJECT_MATRIX = 2, - GPU_INVERSE_VIEW_MATRIX = 4, - GPU_INVERSE_OBJECT_MATRIX = 8, - GPU_VIEW_POSITION = 16, - GPU_VIEW_NORMAL = 32, - GPU_OBCOLOR = 64, - GPU_AUTO_BUMPSCALE = 128, + GPU_VIEW_MATRIX = (1 << 0), + GPU_OBJECT_MATRIX = (1 << 1), + GPU_INVERSE_VIEW_MATRIX = (1 << 2), + GPU_INVERSE_OBJECT_MATRIX = (1 << 3), + GPU_VIEW_POSITION = (1 << 4), + GPU_VIEW_NORMAL = (1 << 5), + GPU_OBCOLOR = (1 << 6), + GPU_AUTO_BUMPSCALE = (1 << 7), + GPU_CAMERA_TEXCO_FACTORS = (1 << 8), } GPUBuiltin; typedef enum GPUOpenGLBuiltin { @@ -101,7 +102,7 @@ typedef enum GPUOpenGLBuiltin { typedef enum GPUMatType { GPU_MATERIAL_TYPE_MESH = 1, - GPU_MATERIAL_TYPE_WORLD = 2, + GPU_MATERIAL_TYPE_WORLD = 2, } GPUMatType; @@ -177,7 +178,7 @@ void GPU_material_free(struct ListBase *gpumaterial); void GPU_materials_free(void); bool GPU_lamp_override_visible(GPULamp *lamp, struct SceneRenderLayer *srl, struct Material *ma); -void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap, float viewmat[4][4], float viewinv[4][4], bool scenelock); +void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap, float viewmat[4][4], float viewinv[4][4], float cameraborder[4], bool scenelock); void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[4][4], float obcol[4], float autobumpscale); void GPU_material_unbind(GPUMaterial *material); int GPU_material_bound(GPUMaterial *material); diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index e77ea32e574..97064f43f5d 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -383,6 +383,8 @@ const char *GPU_builtin_name(GPUBuiltin builtin) return "unfobcolor"; else if (builtin == GPU_AUTO_BUMPSCALE) return "unfobautobumpscale"; + else if (builtin == GPU_CAMERA_TEXCO_FACTORS) + return "unfcameratexfactors"; else return ""; } diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 6ff076bb02b..4a93fbac48e 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -1384,6 +1384,7 @@ static struct GPUMaterialState { bool gscenelock; float (*gviewmat)[4]; float (*gviewinv)[4]; + float (*gviewcamtexcofac); bool backface_culling; @@ -1492,6 +1493,7 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O GMS.gscenelock = (v3d->scenelock != 0); GMS.gviewmat= rv3d->viewmat; GMS.gviewinv= rv3d->viewinv; + GMS.gviewcamtexcofac = rv3d->viewcamtexcofac; /* alpha pass setup. there's various cases to handle here: * - object transparency on: only solid materials draw in the first pass, @@ -1650,7 +1652,7 @@ int GPU_enable_material(int nr, void *attribs) gpumat = GPU_material_from_blender(GMS.gscene, mat); GPU_material_vertex_attributes(gpumat, gattribs); - GPU_material_bind(gpumat, GMS.gob->lay, GMS.glay, 1.0, !(GMS.gob->mode & OB_MODE_TEXTURE_PAINT), GMS.gviewmat, GMS.gviewinv, GMS.gscenelock); + GPU_material_bind(gpumat, GMS.gob->lay, GMS.glay, 1.0, !(GMS.gob->mode & OB_MODE_TEXTURE_PAINT), GMS.gviewmat, GMS.gviewinv, GMS.gviewcamtexcofac, GMS.gscenelock); auto_bump_scale = GMS.gob->derivedFinal != NULL ? GMS.gob->derivedFinal->auto_bump_scale : 1.0f; GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, GMS.gob->col, auto_bump_scale); diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 4638ad216e0..53e20ec31ca 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -101,6 +101,7 @@ struct GPUMaterial { int viewmatloc, invviewmatloc; int obmatloc, invobmatloc; int obcolloc, obautobumpscaleloc; + int cameratexcofacloc; ListBase lamps; }; @@ -228,6 +229,8 @@ static int GPU_material_construct_end(GPUMaterial *material, const char *passnam material->obcolloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_OBCOLOR)); if (material->builtins & GPU_AUTO_BUMPSCALE) material->obautobumpscaleloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_AUTO_BUMPSCALE)); + if (material->builtins & GPU_CAMERA_TEXCO_FACTORS) + material->cameratexcofacloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_CAMERA_TEXCO_FACTORS)); return 1; } @@ -277,7 +280,7 @@ bool GPU_lamp_override_visible(GPULamp *lamp, SceneRenderLayer *srl, Material *m return true; } -void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap, float viewmat[4][4], float viewinv[4][4], bool scenelock) +void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap, float viewmat[4][4], float viewinv[4][4], float camerafactors[4], bool scenelock) { if (material->pass) { LinkData *nlink; @@ -337,6 +340,16 @@ void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double tim if (material->builtins & GPU_INVERSE_VIEW_MATRIX) { GPU_shader_uniform_vector(shader, material->invviewmatloc, 16, 1, (float*)viewinv); } + if (material->builtins & GPU_CAMERA_TEXCO_FACTORS) { + if (camerafactors) { + GPU_shader_uniform_vector(shader, material->cameratexcofacloc, 4, 1, (float*)camerafactors); + } + else { + /* use default, no scaling no offset */ + float borders[4] = {1.0f, 1.0f, 0.0f, 0.0f}; + GPU_shader_uniform_vector(shader, material->cameratexcofacloc, 4, 1, (float*)borders); + } + } GPU_pass_update_uniforms(material->pass); diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index a7bb4fe16f7..229abd7c5a6 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -2368,7 +2368,7 @@ void node_geometry(vec3 I, vec3 N, mat4 toworld, backfacing = (gl_FrontFacing)? 0.0: 1.0; } -void node_tex_coord(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, +void node_tex_coord(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, vec4 camerafac, vec3 attr_orco, vec3 attr_uv, out vec3 generated, out vec3 normal, out vec3 uv, out vec3 object, out vec3 camera, out vec3 window, out vec3 reflection) @@ -2379,7 +2379,7 @@ void node_tex_coord(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, object = (obinvmat*(viewinvmat*vec4(I, 1.0))).xyz; camera = vec3(I.xy, -I.z); vec4 projvec = gl_ProjectionMatrix * vec4(I, 1.0); - window = vec3(mtex_2d_mapping(projvec.xyz/projvec.w).xy, 0.0); + window = vec3(mtex_2d_mapping(projvec.xyz/projvec.w).xy * camerafac.xy + camerafac.zw, 0.0); vec3 shade_I; shade_view(I, shade_I); @@ -2387,7 +2387,7 @@ void node_tex_coord(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, reflection = (viewinvmat*vec4(view_reflection, 0.0)).xyz; } -void node_tex_coord_background(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, +void node_tex_coord_background(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, vec4 camerafac, vec3 attr_orco, vec3 attr_uv, out vec3 generated, out vec3 normal, out vec3 uv, out vec3 object, out vec3 camera, out vec3 window, out vec3 reflection) @@ -2406,7 +2406,9 @@ void node_tex_coord_background(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, object = coords; camera = vec3(co.xy, -co.z); - window = (gl_ProjectionMatrix[3][3] == 0.0) ? vec3(mtex_2d_mapping(I).xy, 0.0) : vec3(0.5, 0.5, 0.0); + window = (gl_ProjectionMatrix[3][3] == 0.0) ? + vec3(mtex_2d_mapping(I).xy * camerafac.xy + camerafac.zw, 0.0) : + vec3(vec2(0.5) * camerafac.xy + camerafac.zw, 0.0); reflection = -coords; } |