Browse Source

平滑,锐化,edge detect

master
blobt 4 years ago
parent
commit
d16d7102d8
  1. BIN
      .vs/shader3/v14/.suo
  2. 40
      main.cpp
  3. 28
      res/shader/edge_detect.fs
  4. 29
      res/shader/sharpen.fs
  5. 28
      res/shader/smooth.fs
  6. 8
      shader3.vcxproj
  7. 8
      shader3.vcxproj.filters

BIN
.vs/shader3/v14/.suo

40
main.cpp

@ -75,42 +75,38 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
//combine program //combine program
GPUProgram combineProgram1; GPUProgram combineProgram1;
combineProgram1.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); combineProgram1.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
combineProgram1.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd.fs");
combineProgram1.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad.fs");
combineProgram1.Link(); combineProgram1.Link();
combineProgram1.DetectAttribute("pos"); combineProgram1.DetectAttribute("pos");
combineProgram1.DetectAttribute("texcoord"); combineProgram1.DetectAttribute("texcoord");
combineProgram1.DetectUniform("U_BaseTexture");
combineProgram1.DetectUniform("U_BlendTexture");
combineProgram1.DetectUniform("U_MainTexture");
//combine program //combine program
GPUProgram combineProgram2; GPUProgram combineProgram2;
combineProgram2.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); combineProgram2.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
combineProgram2.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd_inverse.fs");
combineProgram2.AttachShader(GL_FRAGMENT_SHADER, "res/shader/smooth.fs");
combineProgram2.Link(); combineProgram2.Link();
combineProgram2.DetectAttribute("pos"); combineProgram2.DetectAttribute("pos");
combineProgram2.DetectAttribute("texcoord"); combineProgram2.DetectAttribute("texcoord");
combineProgram2.DetectUniform("U_BaseTexture");
combineProgram2.DetectUniform("U_BlendTexture");
combineProgram2.DetectUniform("U_MainTexture");
//combine program //combine program
GPUProgram combineProgram3; GPUProgram combineProgram3;
combineProgram3.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); combineProgram3.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
combineProgram3.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd_dark.fs");
combineProgram3.AttachShader(GL_FRAGMENT_SHADER, "res/shader/sharpen.fs");
combineProgram3.Link(); combineProgram3.Link();
combineProgram3.DetectAttribute("pos"); combineProgram3.DetectAttribute("pos");
combineProgram3.DetectAttribute("texcoord"); combineProgram3.DetectAttribute("texcoord");
combineProgram3.DetectUniform("U_BaseTexture");
combineProgram3.DetectUniform("U_BlendTexture");
combineProgram3.DetectUniform("U_MainTexture");
//combine program //combine program
GPUProgram combineProgram4; GPUProgram combineProgram4;
combineProgram4.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); combineProgram4.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs");
combineProgram4.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd_light.fs");
combineProgram4.AttachShader(GL_FRAGMENT_SHADER, "res/shader/edge_detect.fs");
combineProgram4.Link(); combineProgram4.Link();
combineProgram4.DetectAttribute("pos"); combineProgram4.DetectAttribute("pos");
combineProgram4.DetectAttribute("texcoord"); combineProgram4.DetectAttribute("texcoord");
combineProgram4.DetectUniform("U_BaseTexture");
combineProgram4.DetectUniform("U_BlendTexture");
combineProgram4.DetectUniform("U_MainTexture");
@ -169,37 +165,25 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
glUseProgram(combineProgram1.mProgram); glUseProgram(combineProgram1.mProgram);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, head); glBindTexture(GL_TEXTURE_2D, head);
glUniform1i(combineProgram1.GetLocation("U_BaseTexture"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, grass);
glUniform1i(combineProgram1.GetLocation("U_BlendTexture"), 1);
glUniform1i(combineProgram1.GetLocation("U_MainTexture"), 0);
fsq.DrawToLeftTop(combineProgram1.GetLocation("pos"), combineProgram1.GetLocation("texcoord")); fsq.DrawToLeftTop(combineProgram1.GetLocation("pos"), combineProgram1.GetLocation("texcoord"));
glUseProgram(combineProgram2.mProgram); glUseProgram(combineProgram2.mProgram);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, head); 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);
glUniform1i(combineProgram2.GetLocation("U_MainTexture"), 0);
fsq.DrawToRightTop(combineProgram2.GetLocation("pos"), combineProgram2.GetLocation("texcoord")); fsq.DrawToRightTop(combineProgram2.GetLocation("pos"), combineProgram2.GetLocation("texcoord"));
glUseProgram(combineProgram3.mProgram); glUseProgram(combineProgram3.mProgram);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, head); glBindTexture(GL_TEXTURE_2D, head);
glUniform1i(combineProgram3.GetLocation("U_BaseTexture"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, grass);
glUniform1i(combineProgram3.GetLocation("U_BlendTexture"), 1);
glUniform1i(combineProgram3.GetLocation("U_MainTexture"), 0);
fsq.DrawToLeftBottom(combineProgram3.GetLocation("pos"), combineProgram3.GetLocation("texcoord")); fsq.DrawToLeftBottom(combineProgram3.GetLocation("pos"), combineProgram3.GetLocation("texcoord"));
glUseProgram(combineProgram4.mProgram); glUseProgram(combineProgram4.mProgram);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, head); glBindTexture(GL_TEXTURE_2D, head);
glUniform1i(combineProgram4.GetLocation("U_BaseTexture"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, grass);
glUniform1i(combineProgram4.GetLocation("U_BlendTexture"), 1);
glUniform1i(combineProgram4.GetLocation("U_MainTexture"), 0);
fsq.DrawToRightBottom(combineProgram4.GetLocation("pos"), combineProgram4.GetLocation("texcoord")); fsq.DrawToRightBottom(combineProgram4.GetLocation("pos"), combineProgram4.GetLocation("texcoord"));
glDisable(GL_BLEND); glDisable(GL_BLEND);

28
res/shader/edge_detect.fs

@ -0,0 +1,28 @@
varying vec2 V_Texcoord;
uniform sampler2D U_MainTexture;
void main()
{
//1 2 1
//2 4 2
//1 2 1
vec4 color = vec4(0.0);
int coreSize = 3;
float texelOffset = 1/150.0;
float kernel[9];
kernel[6]=0;kernel[7]=1;kernel[8]=0;
kernel[3]=1;kernel[4]=-4;kernel[5]=1;
kernel[0]=0;kernel[1]=1;kernel[2]=0;
int index = 0;
for(int y=0; y<coreSize; y++){
for(int x=0; x<coreSize; x++){
vec4 currentColor = texture2D(U_MainTexture, V_Texcoord+vec2((-1+x)*texelOffset, (-1+y)*texelOffset));
color += currentColor*kernel[index++];
}
}
gl_FragColor=4.0*color+texture2D(U_MainTexture,V_Texcoord);
}

29
res/shader/sharpen.fs

@ -0,0 +1,29 @@
varying vec2 V_Texcoord;
uniform sampler2D U_MainTexture;
void main()
{
//1 2 1
//2 4 2
//1 2 1
vec4 color = vec4(0.0);
int coreSize = 3;
float texelOffset = 1/100.0;
float kernel[9];
kernel[6]=0;kernel[7]=-1;kernel[8]=0;
kernel[3]=-1;kernel[4]=4;kernel[5]=-1;
kernel[0]=0;kernel[1]=-1;kernel[2]=0;
int index = 0;
for(int y=0; y<coreSize; y++){
for(int x=0; x<coreSize; x++){
vec4 currentColor = texture2D(U_MainTexture, V_Texcoord+vec2((-1+x)*texelOffset, (-1+y)*texelOffset));
color += currentColor*kernel[index++];
}
}
gl_FragColor = 1.2*color+texture2D(U_MainTexture,V_Texcoord);
}

28
res/shader/smooth.fs

@ -0,0 +1,28 @@
varying vec2 V_Texcoord;
uniform sampler2D U_MainTexture;
void main()
{
vec4 color = vec4(0.0);
int coreSize = 3;
float texelOffset = 1/150.0;
float kernel[9];
kernel[6]=1;kernel[7]=2;kernel[8]=1;
kernel[3]=1;kernel[4]=4;kernel[5]=1;
kernel[0]=1;kernel[1]=2;kernel[2]=1;
int index = 0;
for(int y=0; y<coreSize; y++){
for(int x=0; x<coreSize; x++){
vec4 currentColor = texture2D(U_MainTexture, V_Texcoord+vec2((-1+x)*texelOffset, (-1+y)*texelOffset));
color += currentColor*kernel[index++];
}
}
color/=9;
gl_FragColor = color;
}

8
shader3.vcxproj

@ -82,10 +82,10 @@
<ClInclude Include="utils.h" /> <ClInclude Include="utils.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<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" />
<None Include="res\shader\edge_detect.fs" />
<None Include="res\shader\fullscreenquad.fs" />
<None Include="res\shader\sharpen.fs" />
<None Include="res\shader\smooth.fs" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

8
shader3.vcxproj.filters

@ -46,16 +46,16 @@
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="res\shader\zpdd.fs">
<None Include="res\shader\edge_detect.fs">
<Filter>src</Filter> <Filter>src</Filter>
</None> </None>
<None Include="res\shader\zpdd_dark.fs">
<None Include="res\shader\sharpen.fs">
<Filter>src</Filter> <Filter>src</Filter>
</None> </None>
<None Include="res\shader\zpdd_inverse.fs">
<None Include="res\shader\smooth.fs">
<Filter>src</Filter> <Filter>src</Filter>
</None> </None>
<None Include="res\shader\zpdd_light.fs">
<None Include="res\shader\fullscreenquad.fs">
<Filter>src</Filter> <Filter>src</Filter>
</None> </None>
</ItemGroup> </ItemGroup>
Loading…
Cancel
Save