shaders for bloom (i'm working on it!)
This commit is contained in:
parent
be98e05537
commit
65c0f5ae4a
@ -15,6 +15,8 @@
|
||||
<None Include="shaders\shader_4_sun.vert" />
|
||||
<None Include="shaders\shader_4_tex.frag" />
|
||||
<None Include="shaders\shader_4_tex.vert" />
|
||||
<None Include="shaders\shader_bloom.frag" />
|
||||
<None Include="shaders\shader_bloom.vert" />
|
||||
<None Include="shaders\shader_color.frag" />
|
||||
<None Include="shaders\shader_color.vert" />
|
||||
<None Include="shaders\shader_skybox.frag" />
|
||||
@ -47,7 +49,7 @@
|
||||
<ProjectGuid>{1B448102-E76C-4347-BDC7-40D02A567DB6}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>grk-cw9</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
||||
<ProjectName>grk-project</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
@ -55,14 +57,14 @@
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
|
@ -48,6 +48,12 @@
|
||||
<None Include="shaders\shader_skybox.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Box.cpp">
|
||||
|
50
shaders/shader_bloom.frag
Normal file
50
shaders/shader_bloom.frag
Normal file
@ -0,0 +1,50 @@
|
||||
#version 430 core
|
||||
layout (location = 0) out vec4 fragColor;
|
||||
layout (location = 1) out vec4 BrightColor;
|
||||
|
||||
in vec3 fragPos;
|
||||
in vec3 interpNormal;
|
||||
in vec2 vTexCoords;
|
||||
|
||||
struct PointLight {
|
||||
vec3 position;
|
||||
vec3 color;
|
||||
};
|
||||
|
||||
#define NR_POINT_LIGHTS 2
|
||||
|
||||
uniform vec3 objectColor;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 cameraPos;
|
||||
uniform sampler2D colorTexture;
|
||||
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 result = vec3(0,0,0);
|
||||
vec4 textureColor = texture2D(colorTexture, -vTexCoords);
|
||||
vec4 ambient = vec4(0.1, 0.1, 0.1, 1.0) * textureColor;
|
||||
vec3 normal = normalize(interpNormal);
|
||||
for(int i = 0; i < NR_POINT_LIGHTS; i++)
|
||||
{
|
||||
vec3 lightDir = normalize(pointLights[i].position - fragPos);
|
||||
|
||||
vec3 V = normalize(cameraPos-fragPos);
|
||||
vec3 R = reflect(-normalize(lightDir),normal);
|
||||
|
||||
float specular = pow(max(0,dot(R,V)),10);
|
||||
float diffuse = max(0,dot(normal,normalize(lightDir)));
|
||||
vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z) * pointLights[i].color;
|
||||
result += mix(texture,texture*diffuse+vec3(1)*specular,0.9);
|
||||
}
|
||||
|
||||
result = (fragColor + ambient).xyz;
|
||||
|
||||
// check whether result is higher than some threshold, if so, output as bloom threshold color
|
||||
float brightness = dot(result, vec3(0.2126, 0.7152, 0.0722));
|
||||
if(brightness > 1.0)
|
||||
BrightColor = vec4(result, 1.0);
|
||||
else
|
||||
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
fragColor = vec4(result, 1.0);
|
||||
}
|
22
shaders/shader_bloom.vert
Normal file
22
shaders/shader_bloom.vert
Normal file
@ -0,0 +1,22 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 vertexPosition;
|
||||
layout (location = 1) in vec3 vertexNormal;
|
||||
layout (location = 2) in vec2 vertexTexCoords;
|
||||
|
||||
out vec3 fragPos;
|
||||
out vec3 interpNormal;
|
||||
out vec2 vTexCoords;
|
||||
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 matrixModel;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragPos = vec3(matrixModel * vec4(vertexPosition, 1.0));
|
||||
vTexCoords = vertexTexCoords;
|
||||
|
||||
mat3 normalMatrix = transpose(inverse(mat3(matrixModel)));
|
||||
interpNormal = normalize(normalMatrix * vertexNormal);
|
||||
|
||||
gl_Position = transformation * matrixModel * vec4(vertexPosition, 1.0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user