Page Menu
Home
Search
Configure Global Search
Log In
Files
F20527
double_sided_emulate.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Brecht Van Lommel (brecht)
Nov 13 2013, 4:25 PM
Size
4 KB
Subscribers
None
double_sided_emulate.patch
View Options
diff --git source/blender/editors/space_view3d/drawobject.c source/blender/editors/space_view3d/drawobject.c
index 1f57845..4cf0830 100644
--- source/blender/editors/space_view3d/drawobject.c
+++ source/blender/editors/space_view3d/drawobject.c
@@ -2902,11 +2902,30 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d,
else {
/* 3 floats for position,
* 3 for normal and times two because the faces may actually be quads instead of triangles */
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED);
-
glEnable(GL_LIGHTING);
glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
- finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, GPU_enable_material, NULL, NULL, 0);
+
+ if(!(me->flag & ME_TWOSIDED)) {
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED );
+ finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, GPU_enable_material, NULL, NULL, 0);
+ }
+ else {
+ /* workaround for double sided lighting not supported in hw,
+ we draw twice and flip light directions */
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
+ glEnable(GL_CULL_FACE);
+
+ glCullFace(GL_BACK);
+ finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, GPU_enable_material, NULL, NULL, 0);
+
+ GPU_default_lights_flip();
+ glCullFace(GL_FRONT);
+ finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, GPU_enable_material, NULL, NULL, 0);
+ GPU_default_lights_flip();
+
+ glDisable(GL_CULL_FACE);
+ }
+
glFrontFace(GL_CCW);
glDisable(GL_LIGHTING);
@@ -3226,6 +3245,9 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
}
else {
Paint *p;
+ float planes[4][4];
+ float (*fpl)[4] = NULL;
+ int fast= 0;
if ( (v3d->flag & V3D_SELECT_OUTLINE) &&
((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) &&
@@ -3236,15 +3258,11 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
draw_mesh_object_outline(v3d, ob, dm);
}
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED );
-
glEnable(GL_LIGHTING);
- glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
+ /* sculpt mode fast drawing and clipping */
if(ob->sculpt && (p=paint_get_active(scene))) {
- float planes[4][4];
- float (*fpl)[4] = NULL;
- int fast= (p->flags & PAINT_FAST_NAVIGATE) && (rv3d->rflag & RV3D_NAVIGATING);
+ fast= (p->flags & PAINT_FAST_NAVIGATE) && (rv3d->rflag & RV3D_NAVIGATING);
if(ob->sculpt->partial_redraw) {
if(ar->do_draw & RGN_DRAW_PARTIAL) {
@@ -3253,11 +3271,30 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
ob->sculpt->partial_redraw = 0;
}
}
+ }
+ glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
+
+ if(!(me->flag & ME_TWOSIDED)) {
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED );
dm->drawFacesSolid(dm, fpl, fast, GPU_enable_material);
}
- else
- dm->drawFacesSolid(dm, NULL, 0, GPU_enable_material);
+ else {
+ /* workaround for double sided lighting not supported in hw,
+ we draw twice and flip light directions */
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
+ glEnable(GL_CULL_FACE);
+
+ glCullFace(GL_BACK);
+ dm->drawFacesSolid(dm, fpl, fast, GPU_enable_material);
+
+ GPU_default_lights_flip();
+ glCullFace(GL_FRONT);
+ dm->drawFacesSolid(dm, fpl, fast, GPU_enable_material);
+ GPU_default_lights_flip();
+
+ glDisable(GL_CULL_FACE);
+ }
GPU_disable_material();
diff --git source/blender/gpu/GPU_draw.h source/blender/gpu/GPU_draw.h
index f73bd40..9ea0b66 100644
--- source/blender/gpu/GPU_draw.h
+++ source/blender/gpu/GPU_draw.h
@@ -92,6 +92,7 @@ int GPU_set_tpage(struct MTFace *tface, int mipmap, int transp);
int GPU_default_lights(void);
int GPU_scene_object_lights(struct Scene *scene, struct Object *ob,
int lay, float viewmat[][4], int ortho);
+void GPU_default_lights_flip(void);
/* Text render
* - based on moving uv coordinates */
diff --git source/blender/gpu/intern/gpu_draw.c source/blender/gpu/intern/gpu_draw.c
index 5d36ba1..371e8c4 100644
--- source/blender/gpu/intern/gpu_draw.c
+++ source/blender/gpu/intern/gpu_draw.c
@@ -1226,6 +1226,24 @@ void GPU_end_object_materials(void)
/* Lights */
+void GPU_default_lights_flip()
+{
+ float position[4];
+ int a;
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+
+ for(a=0; a<3; a++) {
+ glGetLightfv(GL_LIGHT0+a, GL_POSITION, position);
+ negate_v3(position);
+ glLightfv(GL_LIGHT0+a, GL_POSITION, position);
+ }
+
+ glPopMatrix();
+}
+
int GPU_default_lights(void)
{
float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}, position[4];
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e0/6c/575588ce33e30b21ad8c86a5f5ac
Event Timeline
Log In to Comment