*/}}
YimingWu 1 anno fa
parent
commit
2818727b2c
4 ha cambiato i file con 39 aggiunte e 7 eliminazioni
  1. 24 6
      ouroperations.c
  2. 4 0
      ourpaint.h
  3. 9 1
      ourshader.cpp
  4. 2 0
      ourtranslations.c

+ 24 - 6
ouroperations.c

@@ -226,8 +226,10 @@ void ourui_ColorPanel(laUiList *uil, laPropPack *This, laPropPack *DetachedProps
     }laElse(uil,b);{
         laShowItemFull(uil,c,0,"our.current_color",LA_WIDGET_FLOAT_COLOR_HCY,0,0,0)->Flags|=LA_UI_FLAGS_COLOR_SPACE_CLAY;
     }laEndCondition(uil,b);
-
-    laShowItem(uil,c,0,"our.current_color");
+    b=laBeginRow(uil,c,0,0);
+    laShowItem(uil,c,0,"our.preferences.spectral_mode");
+    laShowItem(uil,c,0,"our.current_color")->Expand=1;
+    laEndRow(uil,b);
 }
 void ourui_BrushPage(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
     laColumn* c=laFirstColumn(uil); laColumn* cl,*cr; laSplitColumn(uil,c,0.5); cl=laLeftColumn(c,0);cr=laRightColumn(c,15);
@@ -281,7 +283,8 @@ void ourui_OurPreference(laUiList *uil, laPropPack *This, laPropPack *DetachedPr
     laShowItem(uil,cr,0,"our.preferences.lock_radius");
     laShowItem(uil,cl,0,"our.preferences.allow_none_pressure");
     laShowItem(uil,cr,0,"our.preferences.bad_event_tolerance");
-    laShowItem(uil,cl,0,"our.preferences.canvas_default_scale");
+    laShowItem(uil,cl,0,"our.preferences.spectral_mode");
+    laShowItem(uil,cr,0,"our.preferences.canvas_default_scale");
 
     laShowSeparator(uil,c);
 
@@ -1187,7 +1190,7 @@ STRUCTURE(OurSmudgeSegement){
 };
 void our_PaintDoDabsWithSmudgeSegments(OurLayer* l,int tl, int tr, int tu, int tb){
     laListHandle Segments={0}; int from=0,to=Our->NextDab; if(!Our->NextDab) return;
-    OurSmudgeSegement* oss;
+    OurSmudgeSegement* oss; unsigned int uniforms[2];
     oss=lstAppendPointerSized(&Segments, 0,sizeof(OurSmudgeSegement));
     for(int i=1;i<to;i++){
         if(Our->Dabs[i].ResampleSmudge){ oss->Start=from; oss->End=i; from=i;
@@ -1199,10 +1202,15 @@ void our_PaintDoDabsWithSmudgeSegments(OurLayer* l,int tl, int tr, int tu, int t
 
     glUseProgram(Our->CanvasProgram);
     glUniform1i(Our->uBrushErasing,Our->Erasing);
+    uniforms[Our->uBrushRoutineSelection]=Our->RoutineDoDabs;
+    uniforms[Our->uMixRoutineSelection]=Our->SpectralMode?Our->RoutineDoMixSpectral:Our->RoutineDoMixNormal;
+    glUniformSubroutinesuiv(GL_COMPUTE_SHADER,2,uniforms);
+    
 
     while(oss=lstPopItem(&Segments)){
         if(oss->Resample || Our->CurrentBrush->SmudgeRestart){
-            glUniformSubroutinesuiv(GL_COMPUTE_SHADER,1,&Our->RoutineDoSample);
+            uniforms[Our->uBrushRoutineSelection]=Our->RoutineDoSample;
+            glUniformSubroutinesuiv(GL_COMPUTE_SHADER,2,uniforms);
             int x=Our->Dabs[oss->Start].X, y=Our->Dabs[oss->Start].Y; float usize=Our->Dabs[oss->Start].Size;
             float ssize=(usize>15)?(usize+1.5):(usize*1.1); if(ssize<3) ssize=3;
             int colmax=(int)(floor(OUR_TILE_CTR+(float)(x+ssize)/OUR_TILE_W_USE+0.5)); TNS_CLAMP(colmax,0,OUR_TILES_PER_ROW-1);
@@ -1218,7 +1226,8 @@ void our_PaintDoDabsWithSmudgeSegments(OurLayer* l,int tl, int tr, int tu, int t
                 }
             }
             Our->CurrentBrush->SmudgeRestart=0;
-            glUniformSubroutinesuiv(GL_COMPUTE_SHADER,1,&Our->RoutineDoDabs);
+            uniforms[Our->uBrushRoutineSelection]=Our->RoutineDoDabs;
+            glUniformSubroutinesuiv(GL_COMPUTE_SHADER,2,uniforms);
             glUniform1i(Our->uBrushErasing,Our->Erasing);
         }
 
@@ -1874,6 +1883,9 @@ void ourRegisterEverything(){
     laAddEnumItemAs(p,"CLAY","Clay","Convert pixels into non-linear Clay (AdobeRGB 1998 compatible)",OUR_EXPORT_COLOR_MODE_CLAY,0);
     laAddIntProperty(pc,"paint_undo_limit","Paint Undo Limit","Undo step limit for painting actions.",0,0," Steps",256,5,1,100,0,offsetof(OurPaint,PaintUndoLimit),0,0,0,0,0,0,0,0,0,0,0);
     laAddFloatProperty(pc,"canvas_default_scale","Canvas Default Scale","Default scale of the canvas",0,0,0,4,0.25,0.1,0.5,0,offsetof(OurPaint,DefaultScale),0,0,0,0,0,0,0,0,0,0,0);
+    p=laAddEnumProperty(pc,"spectral_mode","Spectral Brush","Use spectral mixing in brush strokes",LA_WIDGET_ENUM_HIGHLIGHT,0,0,0,0,offsetof(OurPaint,SpectralMode),0,0,0,0,0,0,0,0,0,0);
+    laAddEnumItemAs(p,"NONE","None","Use regular RGB mixing for brushes",0,0);
+    laAddEnumItemAs(p,"SPECTRAL","Spectral","Use spectral mixing for brushes",1,0);
     
     pc=laAddPropertyContainer("our_tools","Our Tools","OurPaint tools",0,0,sizeof(OurPaint),0,0,1);
     laPropContainerExtraFunctions(pc,0,0,0,ourpropagate_Tools,0);
@@ -2054,6 +2066,10 @@ int ourInit(){
     Our->uBrushRoutineSelection=glGetSubroutineUniformLocation(Our->CanvasProgram, GL_COMPUTE_SHADER, "uBrushRoutineSelection");
     Our->RoutineDoDabs=glGetSubroutineIndex(Our->CanvasProgram, GL_COMPUTE_SHADER, "DoDabs");
     Our->RoutineDoSample=glGetSubroutineIndex(Our->CanvasProgram, GL_COMPUTE_SHADER, "DoSample");
+    
+    Our->uMixRoutineSelection=glGetSubroutineUniformLocation(Our->CanvasProgram, GL_COMPUTE_SHADER, "uMixRoutineSelection");
+    Our->RoutineDoMixNormal=glGetSubroutineIndex(Our->CanvasProgram, GL_COMPUTE_SHADER, "DoMixNormal");
+    Our->RoutineDoMixSpectral=glGetSubroutineIndex(Our->CanvasProgram, GL_COMPUTE_SHADER, "DoMixSpectral");
 
     Our->uBlendMode=glGetUniformLocation(Our->CompositionProgram,"uBlendMode");
     Our->uAlphaTop=glGetUniformLocation(Our->CompositionProgram,"uAlphaTop");
@@ -2065,6 +2081,8 @@ int ourInit(){
     Our->Y=2400/2;  Our->H=2400;
     Our->BorderAlpha=0.6;
 
+    Our->SpectralMode=1;
+
     Our->LockRadius=1;
     Our->EnableBrushCircle=1;
     Our->PaintUndoLimit=100;

+ 4 - 0
ourpaint.h

@@ -281,6 +281,7 @@ STRUCTURE(OurPaint){
     int DefaultBitDepth;
     int DefaultColorProfile;
     int PaintUndoLimit;
+    int SpectralMode;
 
     tnsTexture* SmudgeTexture;
     GLuint CanvasShader;      GLuint CanvasProgram;
@@ -295,9 +296,12 @@ STRUCTURE(OurPaint){
     GLint uBrushSlender;
     GLint uBrushAngle;
     GLint uBrushRoutineSelection;
+    GLint uMixRoutineSelection;
     GLint uBrushErasing;
     GLint RoutineDoDabs;
     GLint RoutineDoSample;
+    GLint RoutineDoMixNormal;
+    GLint RoutineDoMixSpectral;
     GLint uBlendMode;
     GLint uAlphaTop;
     GLint uAlphaBottom;

+ 9 - 1
ourshader.cpp

@@ -77,7 +77,11 @@ vec3 spectral_to_rgb (float spectral[10]) {
     for (int i=0; i<3; i++) {rgb_[i] = clamp((tmp[i] - WGM_EPSILON) / offset, 0.0f, 1.0f);}
     return rgb_;
 }
-vec4 spectral_mix(vec4 a, vec4 b, float fac_a){
+subroutine vec4 MixRoutines(vec4 a, vec4 b, float fac_a);
+subroutine(MixRoutines) vec4 DoMixNormal(vec4 a, vec4 b, float fac_a){
+    return mix(a,b,1-fac_a);
+}
+subroutine(MixRoutines) vec4 DoMixSpectral(vec4 a, vec4 b, float fac_a){
     vec4 result = vec4(0,0,0,0);
     result.a=mix(a.a,b.a,1-fac_a);
     float spec_a[10] = {0,0,0,0,0,0,0,0,0,0}; rgb_to_spectral(a.rgb, spec_a);
@@ -87,6 +91,10 @@ vec4 spectral_mix(vec4 a, vec4 b, float fac_a){
     result.rgb=spectral_to_rgb(spectralmix);
     return result;
 }
+subroutine uniform MixRoutines uMixRoutineSelection;
+vec4 spectral_mix(vec4 a, vec4 b, float fac_a){
+    return uMixRoutineSelection(a,b,fac_a);
+}
 vec4 spectral_mix_unpre(vec4 colora, vec4 colorb, float fac){
     vec4 ca=(colora.a==0)?colora:vec4(colora.rgb/colora.a,colora.a);
     vec4 cb=(colorb.a==0)?colorb:vec4(colorb.rgb/colorb.a,colorb.a);

+ 2 - 0
ourtranslations.c

@@ -23,6 +23,8 @@ extern tnsMain* T;
 extern OurPaint *Our;
 
 static const char *entries[]={
+"Spectral Brush","光谱笔刷",
+"Spectral","光谱",
 "Canvas Default Scale","画布默认比例",
 "Help","帮助",
 "Report a Bug","报告程序问题",