Browse Source

正片叠加,反正品叠加,dark,light

master
blobt 4 years ago
parent
commit
9bbd9cbe14
  1. BIN
      .vs/shader3/v14/.suo
  2. 114
      main.cpp
  3. BIN
      res/image/earth.bmp
  4. 11
      res/shader/zpdd.fs
  5. 11
      res/shader/zpdd_dark.fs
  6. 11
      res/shader/zpdd_inverse.fs
  7. 11
      res/shader/zpdd_light.fs
  8. 7
      shader3.vcxproj
  9. 9
      shader3.vcxproj.filters

BIN
.vs/shader3/v14/.suo

114
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();

BIN
res/image/earth.bmp

11
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;
}

11
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;
}

11
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));
}

11
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);
}

7
shader3.vcxproj

@ -82,9 +82,10 @@
<ClInclude Include="utils.h" />
</ItemGroup>
<ItemGroup>
<None Include="res\shader\normal_blend.fs" />
<None Include="res\shader\test.fs" />
<None Include="res\shader\test.vs" />
<None Include="res\shader\zpdd.fs" />
<None Include="res\shader\zpdd_dark.fs" />
<None Include="res\shader\zpdd_inverse.fs" />
<None Include="res\shader\zpdd_light.fs" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

9
shader3.vcxproj.filters

@ -46,13 +46,16 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="res\shader\test.fs">
<None Include="res\shader\zpdd.fs">
<Filter>src</Filter>
</None>
<None Include="res\shader\test.vs">
<None Include="res\shader\zpdd_dark.fs">
<Filter>src</Filter>
</None>
<None Include="res\shader\normal_blend.fs">
<None Include="res\shader\zpdd_inverse.fs">
<Filter>src</Filter>
</None>
<None Include="res\shader\zpdd_light.fs">
<Filter>src</Filter>
</None>
</ItemGroup>
Loading…
Cancel
Save