diff --git a/.vs/shader3/v14/.suo b/.vs/shader3/v14/.suo
index 1e3b2d6..166c1eb 100644
Binary files a/.vs/shader3/v14/.suo and b/.vs/shader3/v14/.suo differ
diff --git a/main.cpp b/main.cpp
index f4a3e27..de97841 100644
--- a/main.cpp
+++ b/main.cpp
@@ -44,8 +44,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
RECT rect;
rect.left = 0;
rect.top = 0;
- rect.right = 256;
- rect.bottom = 256;
+ rect.right = 512;
+ rect.bottom = 512;
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
HWND hwnd = CreateWindowEx(NULL, "OpenGL", "RenderWindow", WS_OVERLAPPEDWINDOW, 100, 100, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, NULL);
@@ -72,33 +72,45 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
glewInit();
- //init fsqgpu program
- GPUProgram originalProgram;
- originalProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
- originalProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad.fs");
- originalProgram.Link();
- originalProgram.DetectAttribute("pos");
- originalProgram.DetectAttribute("texcoord");
- originalProgram.DetectUniform("U_MainTexture");
-
- //高斯模糊
- GPUProgram gaussianProgram;
- gaussianProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
- gaussianProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad_gaussian.fs");
- gaussianProgram.Link();
- gaussianProgram.DetectAttribute("pos");
- gaussianProgram.DetectAttribute("texcoord");
- gaussianProgram.DetectUniform("U_MainTexture");
+ //combine program
+ GPUProgram combineProgram1;
+ combineProgram1.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
+ combineProgram1.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd.fs");
+ combineProgram1.Link();
+ combineProgram1.DetectAttribute("pos");
+ combineProgram1.DetectAttribute("texcoord");
+ combineProgram1.DetectUniform("U_BaseTexture");
+ combineProgram1.DetectUniform("U_BlendTexture");
+
+ //combine program
+ GPUProgram combineProgram2;
+ combineProgram2.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
+ combineProgram2.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd_inverse.fs");
+ combineProgram2.Link();
+ combineProgram2.DetectAttribute("pos");
+ combineProgram2.DetectAttribute("texcoord");
+ combineProgram2.DetectUniform("U_BaseTexture");
+ combineProgram2.DetectUniform("U_BlendTexture");
+
+ //combine program
+ GPUProgram combineProgram3;
+ combineProgram3.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
+ combineProgram3.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd_dark.fs");
+ combineProgram3.Link();
+ combineProgram3.DetectAttribute("pos");
+ combineProgram3.DetectAttribute("texcoord");
+ combineProgram3.DetectUniform("U_BaseTexture");
+ combineProgram3.DetectUniform("U_BlendTexture");
//combine program
- GPUProgram combineProgram;
- combineProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
- combineProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/normal_blend.fs");
- combineProgram.Link();
- combineProgram.DetectAttribute("pos");
- combineProgram.DetectAttribute("texcoord");
- combineProgram.DetectUniform("U_BaseTexture");
- combineProgram.DetectUniform("U_BlendTexture");
+ GPUProgram combineProgram4;
+ combineProgram4.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
+ combineProgram4.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd_light.fs");
+ combineProgram4.Link();
+ combineProgram4.DetectAttribute("pos");
+ combineProgram4.DetectAttribute("texcoord");
+ combineProgram4.DetectUniform("U_BaseTexture");
+ combineProgram4.DetectUniform("U_BlendTexture");
@@ -127,16 +139,9 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
FullScreenQuad fsq;
fsq.Init();
- //初始化FBO
- FBO fbo[2];
- fbo[0].AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight);
- fbo[0].AttachDepthBuffer("depth", viewportWidth, viewportHeight);
- fbo[1].AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight);
- fbo[1].AttachDepthBuffer("depth", viewportWidth, viewportHeight);
-
- GLuint head = CreateTextureFromFile("res/image/head.png");
- GLuint grass = CreateTextureFromFile("res/image/grass.png");
+ GLuint head = CreateTextureFromFile("res/image/wood.bmp");
+ GLuint grass = CreateTextureFromFile("res/image/earth.bmp");
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
@@ -161,24 +166,41 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glActiveTexture(GL_TEXTURE0);
- glUseProgram(originalProgram.mProgram);
+ glUseProgram(combineProgram1.mProgram);
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, head);
- glUniform1i(originalProgram.GetLocation("U_MainTexture"), 0);
- fsq.DrawToLeftTop(originalProgram.GetLocation("pos"), originalProgram.GetLocation("texcoord"));
+ glUniform1i(combineProgram1.GetLocation("U_BaseTexture"), 0);
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, grass);
+ glUniform1i(combineProgram1.GetLocation("U_BlendTexture"), 1);
+ fsq.DrawToLeftTop(combineProgram1.GetLocation("pos"), combineProgram1.GetLocation("texcoord"));
- glUseProgram(originalProgram.mProgram);
+ glUseProgram(combineProgram2.mProgram);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, head);
+ glUniform1i(combineProgram2.GetLocation("U_BaseTexture"), 0);
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, grass);
+ glUniform1i(combineProgram2.GetLocation("U_BlendTexture"), 1);
+ fsq.DrawToRightTop(combineProgram2.GetLocation("pos"), combineProgram2.GetLocation("texcoord"));
+
+ glUseProgram(combineProgram3.mProgram);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, head);
+ glUniform1i(combineProgram3.GetLocation("U_BaseTexture"), 0);
+ glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, grass);
- glUniform1i(originalProgram.GetLocation("U_MainTexture"), 0);
- fsq.DrawToRightTop(originalProgram.GetLocation("pos"), originalProgram.GetLocation("texcoord"));
+ glUniform1i(combineProgram3.GetLocation("U_BlendTexture"), 1);
+ fsq.DrawToLeftBottom(combineProgram3.GetLocation("pos"), combineProgram3.GetLocation("texcoord"));
- glUseProgram(combineProgram.mProgram);
+ glUseProgram(combineProgram4.mProgram);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, head);
- glUniform1i(combineProgram.GetLocation("U_BaseTexture"), 0);
+ glUniform1i(combineProgram4.GetLocation("U_BaseTexture"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, grass);
- glUniform1i(combineProgram.GetLocation("U_BlendTexture"), 1);
- fsq.DrawToRightBottom(combineProgram.GetLocation("pos"), combineProgram.GetLocation("texcoord"));
+ glUniform1i(combineProgram4.GetLocation("U_BlendTexture"), 1);
+ fsq.DrawToRightBottom(combineProgram4.GetLocation("pos"), combineProgram4.GetLocation("texcoord"));
glDisable(GL_BLEND);
glFlush();
diff --git a/res/image/earth.bmp b/res/image/earth.bmp
new file mode 100644
index 0000000..9c9c48e
Binary files /dev/null and b/res/image/earth.bmp differ
diff --git a/res/shader/zpdd.fs b/res/shader/zpdd.fs
new file mode 100644
index 0000000..ab57fee
--- /dev/null
+++ b/res/shader/zpdd.fs
@@ -0,0 +1,11 @@
+varying vec2 V_Texcoord;
+
+uniform sampler2D U_BaseTexture;
+uniform sampler2D U_BlendTexture;
+
+void main()
+{
+ vec4 baseColor = texture2D(U_BaseTexture, V_Texcoord);
+ vec4 blendColor = texture2D(U_BlendTexture, V_Texcoord);
+ gl_FragColor = baseColor*blendColor;
+}
\ No newline at end of file
diff --git a/res/shader/zpdd_dark.fs b/res/shader/zpdd_dark.fs
new file mode 100644
index 0000000..70d265a
--- /dev/null
+++ b/res/shader/zpdd_dark.fs
@@ -0,0 +1,11 @@
+varying vec2 V_Texcoord;
+
+uniform sampler2D U_BaseTexture;
+uniform sampler2D U_BlendTexture;
+
+void main()
+{
+ vec4 baseColor = texture2D(U_BaseTexture, V_Texcoord);
+ vec4 blendColor = texture2D(U_BlendTexture, V_Texcoord);
+ gl_FragColor = vec4(1.0)-(vec4(1.0)-baseColor)/blendColor;
+}
\ No newline at end of file
diff --git a/res/shader/zpdd_inverse.fs b/res/shader/zpdd_inverse.fs
new file mode 100644
index 0000000..12ccb93
--- /dev/null
+++ b/res/shader/zpdd_inverse.fs
@@ -0,0 +1,11 @@
+varying vec2 V_Texcoord;
+
+uniform sampler2D U_BaseTexture;
+uniform sampler2D U_BlendTexture;
+
+void main()
+{
+ vec4 baseColor = texture2D(U_BaseTexture, V_Texcoord);
+ vec4 blendColor = texture2D(U_BlendTexture, V_Texcoord);
+ gl_FragColor = vec4(1.0) - ((vec4(1.0)-blendColor) * (vec4(1.0)-baseColor));
+}
\ No newline at end of file
diff --git a/res/shader/zpdd_light.fs b/res/shader/zpdd_light.fs
new file mode 100644
index 0000000..2cff4d1
--- /dev/null
+++ b/res/shader/zpdd_light.fs
@@ -0,0 +1,11 @@
+varying vec2 V_Texcoord;
+
+uniform sampler2D U_BaseTexture;
+uniform sampler2D U_BlendTexture;
+
+void main()
+{
+ vec4 baseColor = texture2D(U_BaseTexture, V_Texcoord);
+ vec4 blendColor = texture2D(U_BlendTexture, V_Texcoord);
+ gl_FragColor = baseColor/(vec4(1.0)-blendColor);
+}
\ No newline at end of file
diff --git a/shader3.vcxproj b/shader3.vcxproj
index 47ed762..d470d2d 100644
--- a/shader3.vcxproj
+++ b/shader3.vcxproj
@@ -82,9 +82,10 @@
-
-
-
+
+
+
+
diff --git a/shader3.vcxproj.filters b/shader3.vcxproj.filters
index 9fbcebf..e28ec95 100644
--- a/shader3.vcxproj.filters
+++ b/shader3.vcxproj.filters
@@ -46,13 +46,16 @@
-
+
src
-
+
src
-
+
+ src
+
+
src