*/}}
소스 검색

Composition gamma support.

YimingWu 1 년 전
부모
커밋
55c762cb5c
7개의 변경된 파일77개의 추가작업 그리고 20개의 파일을 삭제
  1. 1 0
      la_interface.h
  2. 25 13
      la_kernel.c
  3. 2 0
      la_tns.h
  4. 7 0
      la_tns_kernel.c
  5. 12 6
      resources/la_properties.c
  6. 12 0
      resources/la_templates.c
  7. 18 1
      resources/la_tns_shaders.cpp

+ 1 - 0
la_interface.h

@@ -609,6 +609,7 @@ STRUCTURE(laWindow){
     int IsDocking;
     int OutputColorSpace;
     int OutputShowStripes;
+    int UseComposing; real ComposingGamma,ComposingBlackpoint;
     int IsFullScreen;
     int Redraw;
     int RedrawTouched;

+ 25 - 13
la_kernel.c

@@ -479,6 +479,11 @@ int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
     la_SetCurrentGLContextDebug();
     glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
     la_SetupWindowGLStates(window);
+
+    window->OutputShowStripes=1; window->Redraw=1;
+    window->GLDebugNeedsUpdate=1;
+    window->UseComposing=0; window->ComposingGamma=1.0; window->ComposingBlackpoint=0.0;
+
     return 1;
 };
 
@@ -1835,9 +1840,19 @@ void la_PanelDrawToWindow(laPanel *p, laWindow *w){
     if(MAIN.EnableColorManagement){
         tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
         tnsUniformShowColorOverflowStripes(T->immShader,w->OutputShowStripes);
+        tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
     }else{
         tnsUniformOutputColorSpace(T->immShader,0);
         tnsUniformShowColorOverflowStripes(T->immShader,0);
+        tnsUniformColorComposing(T->immShader,0,0,0);
+    }
+
+    if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99))){
+        tnsUseNoTexture();
+        if (!p->IsMenuPanel){
+            la_PanelDrawDescendBorder(p, (*p->BT), MAIN.SolidShadowLength, MAIN.FloatingAlpha);
+        }
+        tnsFlush();
     }
 
     switch (p->AnimationMode){
@@ -1933,6 +1948,7 @@ void la_PanelDrawToWindow(laPanel *p, laWindow *w){
 
     tnsUniformOutputColorSpace(T->immShader,0);
     tnsUniformShowColorOverflowStripes(T->immShader,0);
+    tnsUniformColorComposing(T->immShader,0,0,0);
 }
 void la_PanelDrawToOffsceen(laPanel *p, laUiList *uil){
     if (p->OffScr){ tnsEnsureOffscreenStatus(p->OffScr, p->W,p->H); }
@@ -2064,17 +2080,7 @@ void la_PanelDefDraw(laWindow *w, laPanel *p, laBoxedTheme *bt){
         tnsDrawToScreen();
         tnsViewportWithScissor(0, 0, w->CW, w->CH);
         tnsOrtho(0, w->CW, w->CH, 0, -100, 100);
-
-        if (p->Mode && (!p->AnimationMode || (p->AnimationMode && p->AnimationRatio > 0.99))){
-            tnsUseNoTexture();
-            if (!p->IsMenuPanel){
-                la_PanelDrawDescendBorder(p, bt, MAIN.SolidShadowLength, MAIN.FloatingAlpha);
-            }
-            tnsFlush();
-        }
-
         la_PanelDrawToWindow(p, w);
-
     }elif (p->AnimationMode){
         la_PanelDrawToWindow(p, w);
     }
@@ -2211,8 +2217,10 @@ void la_BlockDefDrawSelf(laBlock *b, int CH){
     tnsUseImmShader(); tnsEnableShaderv(T->immShader);
     if(MAIN.EnableColorManagement){
         tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
+        tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
     }else{
         tnsUniformOutputColorSpace(T->immShader,0);
+        tnsUniformColorComposing(T->immShader,0,0,0);
     }
 
     for (p = b->Panels.pFirst; p; p = p->Item.pNext){
@@ -2276,6 +2284,7 @@ void la_BlockDefDrawSelf(laBlock *b, int CH){
     tnsFlush();
 
     tnsUniformOutputColorSpace(T->immShader,0);
+    tnsUniformColorComposing(T->immShader,0,0,0);
 }
 void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
     laBoxedTheme *bt = _LA_THEME_PANEL;
@@ -2284,8 +2293,10 @@ void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
     tnsUseImmShader(); tnsEnableShaderv(T->immShader);
     if(MAIN.EnableColorManagement){
         tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
+        tnsUniformColorComposing(T->immShader,MAIN.CurrentWindow->UseComposing,MAIN.CurrentWindow->ComposingGamma,MAIN.CurrentWindow->ComposingBlackpoint);
     }else{
         tnsUniformOutputColorSpace(T->immShader,0);
+        tnsUniformColorComposing(T->immShader,0,0,0);
     }
     
     tnsUseNoTexture();
@@ -2302,6 +2313,7 @@ void la_BlockDefDrawSelfEmpty(laBlock *b, int CH){
     tnsFlush();
 
     tnsUniformOutputColorSpace(T->immShader,0);
+    tnsUniformColorComposing(T->immShader,0,0,0);
 }
 void la_BlockDefDrawRecursive(laWindow *w, laBoxedTheme *bt, laBlock *b){
     if (b->B1){
@@ -2405,9 +2417,11 @@ void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
         if(p->Refresh){
             tnsUseShader(T->immShader);tnsEnableShaderv(T->immShader);
             if(MAIN.EnableColorManagement){
-                tnsUniformOutputColorSpace(T->immShader,MAIN.CurrentWindow->OutputColorSpace);
+                tnsUniformOutputColorSpace(T->immShader,w->OutputColorSpace);
+                tnsUniformColorComposing(T->immShader,w->UseComposing,w->ComposingGamma,w->ComposingBlackpoint);
             }else{
                 tnsUniformOutputColorSpace(T->immShader,0);
+                tnsUniformColorComposing(T->immShader,0,0,0);
             }
             if(p->Refresh&LA_TAG_RECALC){
                 laRecalcPanelImmediate(p);
@@ -2500,8 +2514,6 @@ laWindow *laDesignWindow(int X, int Y, int W, int H){
 
     strSafeSet(&n->Title, "Empty SYSWINDOW");
     n->X = X; n->Y = Y; n->W = W; n->H = H;
-    n->OutputShowStripes=1; n->Redraw=1;
-    n->GLDebugNeedsUpdate=1;
 
     la_CreateSystemWindow(n, MAIN.Windows.pFirst!=0);
 

+ 2 - 0
la_tns.h

@@ -104,6 +104,7 @@ struct _tnsShader{
     int iTextureMode, StateTextureMode, iColorMode,iHCYGamma;
     int iSampleAmount, StateSampleAmount;
     int iInputColorSpace, iOutputColorSpace, iShowStripes;
+    int iComposing, iComposingGamma, iComposingBlackpoint;
     int iDoOffset;
 
     int uViewDir,uViewPos,uFOV,uNear,uFar;
@@ -1209,6 +1210,7 @@ void tnsUniformHCYGamma(tnsShader* s, float Gamma);
 void tnsUniformInputColorSpace(tnsShader* s, int ColorSpace);
 void tnsUniformOutputColorSpace(tnsShader* s, int ColorSpace);
 void tnsUniformShowColorOverflowStripes(tnsShader* s, int Show);
+void tnsUniformColorComposing(tnsShader* s, int Composing, real gamma, real blackpoint);
 void tnsUniformUseMultiplyColor(tnsShader* s, int enable);
 void tnsUseMaskTexture(tnsTexture *t);
 void tnsUseTexture(tnsTexture *t);

+ 7 - 0
la_tns_kernel.c

@@ -263,6 +263,9 @@ void tnsShaderMakeIndex(tnsShader *tns){
     tns->iOutputColorSpace=glGetUniformLocation(program, "OutputColorSpace");
     tns->iInputColorSpace=glGetUniformLocation(program, "InputColorSpace");
     tns->iShowStripes=glGetUniformLocation(program, "ShowStripes");
+    tns->iComposing=glGetUniformLocation(program, "Composing");
+    tns->iComposingGamma=glGetUniformLocation(program, "ComposingGamma");
+    tns->iComposingBlackpoint=glGetUniformLocation(program, "ComposingBlackpoint");
     if(tns->iTexColor>=0){glUniform1i(tns->iTexColor, 0);}
     if(tns->iTexColorMS>=0){glUniform1i(tns->iTexColorMS, 1);}
     tns->iDoOffset = glGetUniformLocation(program, "DoOffset");
@@ -1817,6 +1820,10 @@ void tnsUniformOutputColorSpace(tnsShader* s, int ColorSpace){
 void tnsUniformShowColorOverflowStripes(tnsShader* s, int Show){
     glUniform1i(s->iShowStripes,Show);
 }
+void tnsUniformColorComposing(tnsShader* s, int Composing, real gamma, real blackpoint){
+    glUniform1i(s->iComposing,Composing); glUniform1f(s->iComposingGamma,gamma);
+    glUniform1f(s->iComposingBlackpoint,blackpoint);
+}
 
 void tnsDraw2DTextureDirectly(tnsTexture *t, real x, real y, real w, real h){
     real Verts[8];

+ 12 - 6
resources/la_properties.c

@@ -529,12 +529,11 @@ void* laset_CurrentAnimationAction(void* unused_a, laAction* c){
     laNotifyUsers("la.animation.current_action");
 }
 
-void laset_WindowColorSpace(laWindow* w, int space){
-    w->OutputColorSpace=space; if(w->win) laRedrawCurrentWindow();
-}
-void laset_WindowShowStripes(laWindow* w, int stripes){
-    w->OutputShowStripes=stripes; if(w->win) laRedrawCurrentWindow();
-}
+void laset_WindowColorSpace(laWindow* w, int space){ w->OutputColorSpace=space; if(w->win) laRedrawCurrentWindow(); }
+void laset_WindowShowStripes(laWindow* w, int stripes){ w->OutputShowStripes=stripes; if(w->win) laRedrawCurrentWindow(); }
+void laset_WindowUseComposing(laWindow* w, int comp){ w->UseComposing=comp; if(w->win) laRedrawCurrentWindow(); }
+void laset_WindowComposingGamma(laWindow* w, real v){ w->ComposingGamma=v; if(w->win) laRedrawCurrentWindow(); }
+void laset_WindowComposingBlackpoint(laWindow* w, real v){ w->ComposingBlackpoint=v; if(w->win) laRedrawCurrentWindow(); }
 
 void *tnsget_TnsMain(void *unused,void *unused2){
     return T;
@@ -1465,6 +1464,13 @@ void la_RegisterInternalProps(){
                 laAddEnumItemAs(ep, "NONE", "None", "Don't show overflow", 0,0);
                 laAddEnumItemAs(ep, "STRIPES", "Stripes", "Show overflowing colors as stripes", 1, 0);
             }
+            ep = laAddEnumProperty(p, "use_composing", "Use Composing", "Compose and adjust window colors, best for outdoor lighting", LA_WIDGET_ENUM_HIGHLIGHT,0,0,0,0,offsetof(laWindow, UseComposing), 0,laset_WindowUseComposing, 0,0,0,0,0,0,0,0);{
+                laAddEnumItemAs(ep, "NONE", "None", "Do not use composing", 0, 0);
+                laAddEnumItemAs(ep, "SUN", "Sun", "Compose with outdoor sunlight options", 1, 0);
+            }
+            laAddFloatProperty(p, "composing_gamma", "Composing Gamma", "Composing gamma", 0,0,0,2,0.25,0.05,1.0,0,offsetof(laWindow, ComposingGamma), 0,laset_WindowComposingGamma,0,0,0,0,0,0,0,0,0);
+            laAddFloatProperty(p, "composing_blackpoint", "Composing Blackpoint", "Composing blackpoint", 0,0,0,0.5,0,0.05,0.0,0,offsetof(laWindow, ComposingBlackpoint), 0,laset_WindowComposingBlackpoint,0,0,0,0,0,0,0,0,0);
+
             laAddIntProperty(p, "is_fullscreen", "Is Fullscreen", "Is the window fullscreen", 0,0,0,0,0,0,0,0,offsetof(laWindow, IsFullScreen),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
         }
 

+ 12 - 0
resources/la_templates.c

@@ -557,6 +557,18 @@ void laui_DefaultMenuBarActual(laUiList *uil, laPropPack *pp, laPropPack *actins
             laShowSeparator(uil,c);
             laShowItem(uil,c,0,"la.windows.output_color_space");
             laShowItemFull(uil,c,0,"la.windows.output_show_overflow",0,"text=🟩;",0,0);
+            laShowItemFull(uil,c,0,"la.windows.use_composing",0,"text=☀",0,0);
+            laUiItem* cmp=laOnConditionThat(uil,c,laPropExpression(0,"la.windows.use_composing"));{
+                muil = laMakeMenuPage(uil, c, "⯆");{ mc = laFirstColumn(muil);
+                    laUiItem*b,*ui;
+                    b=laBeginRow(muil,mc,0,0); laShowLabel(muil,mc,"γ",0,0);
+                    ui=laShowItem(muil, mc, 0, "la.windows.composing_gamma"); ui->Expand=1;
+                    laShowItem(muil,mc,&ui->PP,"restore")->Flags|=LA_UI_FLAGS_NO_CONFIRM|LA_UI_FLAGS_ICON; laEndRow(muil,b);
+                    b=laBeginRow(muil,mc,0,0); laShowLabel(muil,mc,"◩",0,0);
+                    ui=laShowItem(muil, mc, 0, "la.windows.composing_blackpoint"); ui->Expand=1;
+                    laShowItem(muil,mc,&ui->PP,"restore")->Flags|=LA_UI_FLAGS_NO_CONFIRM|LA_UI_FLAGS_ICON; laEndRow(muil,b);
+                }
+            }laEndCondition(uil, cmp);
         }laEndCondition(uil, uc);
 
         if(MAIN.MenuExtras){ laShowSeparator(uil,c); MAIN.MenuExtras(uil,0,0,0,0); }

+ 18 - 1
resources/la_tns_shaders.cpp

@@ -624,6 +624,9 @@ uniform int SampleAmount;
 uniform int UseNormal;
 uniform int InputColorSpace;
 uniform int OutputColorSpace;
+uniform int Composing;
+uniform float ComposingGamma;
+uniform float ComposingBlackpoint;
 uniform int ShowStripes;
 uniform float HCYGamma;
 uniform vec3 uViewPos;
@@ -683,7 +686,21 @@ void main(){
         outNormal = oNormal;
     }
     color=vec4(ConvertColorSpace(color.rgb),color.a); color.a=clamp(color.a,0,1);
-    outColor = color; 
+	if(Composing!=0){
+		if(color.rgb!=vec3(0,0,0)){
+			//vec3 cl=srgb_to_okhsl(color.rgb);
+			//cl.z=cl.z/1.0f*(1.0f-ComposingBlackpoint)+ComposingBlackpoint;
+			//cl.z=pow(cl.z,ComposingGamma);
+			//color.rgb=okhsl_to_srgb(cl);
+			color.rgb=pow(color.rgb,vec3(ComposingGamma,ComposingGamma,ComposingGamma));
+			color.r=color.r/1.0f*(1.0f-ComposingBlackpoint)+ComposingBlackpoint;
+			color.g=color.g/1.0f*(1.0f-ComposingBlackpoint)+ComposingBlackpoint;
+			color.b=color.b/1.0f*(1.0f-ComposingBlackpoint)+ComposingBlackpoint;
+		}else{
+			color.rgb=vec3(ComposingBlackpoint,ComposingBlackpoint,ComposingBlackpoint);
+		}
+	}
+    outColor = color;
     outGPos = fGPos;
 })";