diff --git a/.gitignore b/.gitignore index fe859ac..69e604d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,9 +14,10 @@ local.properties .classpath .settings/ .loadpath - +*.peg.* +*.so* .externalToolBuilders/ - +Bin/AwesomeBump *.launch .cproject diff --git a/Bin/Core/Render/AwesomeBump.frag b/Bin/Core/Render/AwesomeBump.frag new file mode 100644 index 0000000..ce27647 --- /dev/null +++ b/Bin/Core/Render/AwesomeBump.frag @@ -0,0 +1,576 @@ +#version 330 core +// -------------------------------------------------------------------- +// DO NOT CHANGE this part of code: Uniforms below must be define +// those variables are always provided by AwesomeBump. However one may +// use them in your custom shader. +// -------------------------------------------------------------------- +// Uniform textures +uniform sampler2D texDiffuse; +uniform sampler2D texNormal; +uniform sampler2D texSpecular; +uniform sampler2D texHeight; +uniform sampler2D texSSAO; +uniform sampler2D texRoughness; +uniform sampler2D texMetallic; +uniform sampler2D texMaterial; + +uniform samplerCube texPrefilteredEnvMap; // prefilltered diffuse cube map +uniform samplerCube texSourceEnvMap; // full cube map +uniform int num_mipmaps; // number of mipmaps of texSourceEnvMap + +// Camera/light/matrices +uniform vec3 cameraPos; // View Camera Position +uniform vec3 lightDirection; // Light direction always points to the center of the center of system (0,0,0) normalized. Mouse cause rotation of this light +uniform vec4 lightPos; // Another light position. Here: z-th component ie equal z=5.0. Mouse changes only the x,y components. (Flashlight behaviour). + +uniform mat4 ModelMatrix; // Pure Translation/Rotation of the oryginal components of the rendered Mesh +uniform mat4 ModelViewMatrix; // ViewMatrix * ModelMatrix; Here ViewMatrix is generated by Camera with lookAt method. +uniform mat3 NormalMatrix; // NormalMatrix obtained from ModelViewMatrix. + + +// Uniform controlable from GUI, those parameters are used in AwesomeBump.frag shader +// you may use them to customize your rendering +uniform bool gui_bSpecular; // enable specular texture +uniform bool gui_bOcclusion; // enable Occlusion texture +uniform bool gui_bHeight; // enable Height texture +uniform bool gui_bDiffuse; // enable Diffuse texture +uniform bool gui_bNormal; // enable Normal texture +uniform bool gui_bRoughness; // enable Roughness texture +uniform bool gui_bMetallic; // enable Metallic texture +uniform bool gui_bUseSimplePBR; // enable simplified version of PBR shading +uniform bool gui_bMaterialsPreviewEnabled; // enable Material texture preview +uniform bool gui_bShowTriangleEdges; // show mesh triangles + +// Lightning related variables +uniform float gui_LightPower; // Light power variable +uniform float gui_LightRadius; // Light radius variable +uniform float gui_SpecularIntensity; // Intensity of Specular effect +uniform float gui_DiffuseIntensity; // Intensity of Diffuse effect +uniform int gui_noPBRRays; // Number of rays taken in high quality PRB calulations + +// UV related variables +uniform float gui_depthScale; // UV relief depth scale + +// Enums accesible from GUI +uniform int gui_shading_type; // 0 - relief mapping , 1 - parallax normal mapping , 2 - tessellation +uniform int gui_shading_model; // 0 - PBR , 1 - Bump mapping + + + +// -------------------------------------------------------------------- +// DO NOT CHANGE this part of code: Necessary outcome from fragment +// shader. Four buffors are used for further post-processing. +// -------------------------------------------------------------------- + +layout(location = 0) out vec4 FragColor; // Final Color of pixel +layout(location = 1) out vec4 FragNormal; // Frag Normal - Not used +layout(location = 2) out vec4 FragGlowColor; // Glow Color - initial color taken form Glow effect calulation +layout(location = 3) out vec4 FragPosition; // Frag Eye space position - need to be vec4(ESVertexPosition,1) used for DOF caclulation + + +// -------------------------------------------------------------------- +// DO NOT CHANGE this part of code: Incoming attributes and small +// explanation how they were computed in geometry shader - see comments +// -------------------------------------------------------------------- + +// Eye space attributed computed in geometry shader +in vec3 ESVertexPosition; // Vertex position defined as: ModelViewMatrix * vPosition, where vPosition i basically oryginal position in Obj. +in vec3 ESVertexNormal; // Vertex normal = NormalMatrix * vNormal +in vec3 ESVertexTangent; // Vertex tangent = NormalMatrix * vTangent +in vec3 ESVertexBitangent; // Vertex bitangent = NormalMatrix * vBitangent +in vec3 ESHalfVector; // ES Half vector is computed: normalize((0,0,5)+ESVertexPosition.xyz) + + +// Tangent space variables used for Relief mapping are following: + +// Let us define two vectors: eyeLightVectors and eyeViewVectors +// vec3 eyeLightVectors[2]; +// eyeLightVectors[0] = normalize(-ESVertexPosition.xyz); +// eyeLightVectors[1] = normalize(lightPos.xyz-ESVertexPosition.xyz); +// vec3 eyeViewVectors[2]; +// eyeViewVectors[0] = -normalize(ESVertexPosition.xyz); +// eyeViewVectors[1] = -normalize(ESVertexPosition.xyz); + +// Additionally ESTBN matrix is computed: ESTBN = transpose(mat3(ESVertexTangent,ESVertexBitangent,ESVertexNormal)); + +const int no_lights = 2; +in vec3 TSLightPosition[no_lights]; // TSLightPosition[i] = ESTBN * eyeLightDir[i]; +in vec3 TSViewDirection[no_lights]; // TSViewDirection[i] = ESTBN * eyeViewVectors[i]; +in vec3 TSHalfVector; // then tangent space half vector is calculated as TSHalfVector = ESTBN * ESHalfVector + +in vec3 texcoord; // Frag UV coordinate + +// World space attributes evaluated in geometry shader +in vec3 WSTangent; // Tangent vector calculated as: mat3(ModelMatrix)*vTangent +in vec3 WSBitangent; // Bitangent vector calculated as: mat3(ModelMatrix)*vBitangent +in vec3 WSNormal; // Normal vector calculated as: mat3(ModelMatrix)*vNormal +in vec3 WSPosition; // Position calculate from: (ModelMatrix * vec4( newPos[i],1)).xyz; +in mat3 TBN; // Wordl space TBN matrix calculated from transpose(mat3(WSTangent,WSBitangent,WSNormal)); + + +// -------------------------------------------------------------------- +// Shader definition, here you can put defined by you new uniform +// variables. +// Supported type: +// - float +// - int +// The number of user defined uniform variables is limited to about 20 for now. +// *** +// EXAMPLE usage of user define variable: +uniform float example_float; // value=0.0; min = -10.0 ; max= 10.0 ; step = 0.1 ; name = "Example float" ; description = "This parameter does nothing" +// NOTE that each uniform has to be followed by special one line comment: +// min (must be define)- minimum allowed value +// max (must be define)- maximum value +// value (must be define)- default value which will be loaded each time you start AB +// step (must be define)- singleStep +// name (optional) - human readable name visible in GUI +// description (optional) - explanation for other users what this parameter does +// -------------------------------------------------------------------- + + +// --------------------------------------------------------------------- +// AwesomeBump - shader written by Krzysztof Kolasinski @2015 +// --------------------------------------------------------------------- + + + +// Global variables +vec3 Kd = vec3(gui_DiffuseIntensity); +vec3 Ks = vec3(gui_SpecularIntensity*0.5); +vec3 Ka = vec3(0.0); +float alpha = 1.0 / (gui_LightRadius*0.1 + 0.01); + +vec3 LightSource_diffuse = vec3(1.0); +vec3 LightSource_ambient = vec3(1.0); +vec3 LightSource_specular = vec3(1.0); + +// global variables +vec3 fvESVertexNormal; +vec4 fvBaseColor; +vec4 fvSpecularColor; +vec4 fvSSAOColor; +float fvGlossiness; +vec4 fvRoughness; +vec4 fvMetallic; + +vec4 bump_mapping(int lightIndeks,vec2 texcoord){ + + vec3 fvTSLightPosition = normalize( TSLightPosition[lightIndeks] ); + float fNDotL = max(dot( fvESVertexNormal, fvTSLightPosition ),0.0); + vec3 fvReflection = normalize( ( ( 2.0 * fvESVertexNormal ) * fNDotL ) - fvTSLightPosition ); + vec3 fvTSViewDirection = normalize( TSViewDirection[lightIndeks] ); + float fRDotV = max( 0.0, dot( fvReflection, fvTSViewDirection ) ); + + vec4 fvTotalAmbient = vec4(Ka * LightSource_ambient,1) * fvBaseColor; + vec4 fvTotalDiffuse = gui_LightPower * vec4(Kd * LightSource_diffuse,1) * fNDotL * fvBaseColor; + vec3 lightDirection = normalize( TSLightPosition[lightIndeks] ); + vec4 fvTotalSpecular = gui_LightPower * vec4(Ks * LightSource_specular,1) * ( pow( fRDotV, alpha*fvGlossiness ) ) * fvSpecularColor * 3; + + if(!gui_bSpecular) fvTotalSpecular = vec4(0); + + return ( fvTotalDiffuse*fvSSAOColor + fvTotalSpecular); +} + +vec2 parallax_normal_mapping(){ + vec2 newTexCoord; + vec3 h = normalize(TSHalfVector);//half vector + + float scale = gui_depthScale*0.04; + float bias = -0.03; + if (gui_bHeight) + { + float height = texture(texHeight, texcoord.st).r; + + height = height * scale + bias; + newTexCoord = texcoord.st + (height * h.xy); + } + else + { + newTexCoord = texcoord.st; + } + return newTexCoord; +} + + + +float depth = 0.04*gui_depthScale; + +// based on https://github.com/kiirala/reliefmap +vec2 relief_mapping() { + if (gui_bHeight){ + vec3 N = normalize(ESVertexNormal); + vec3 eview = normalize(ESVertexPosition); + vec3 etangent = normalize(ESVertexTangent); + vec3 ebitangent = normalize(ESVertexBitangent); + + vec3 tview = normalize(vec3(dot(eview, etangent), dot(eview, ebitangent), dot(eview, -N))); + vec2 ds = tview.xy * depth / tview.z; + vec2 dp = texcoord.xy; + + + const int linear_steps = 15; + const int binary_steps = 15; + float depth_step = 1.0 / linear_steps; + float size = depth_step; + float depth = 1.0; + float best_depth = 1.0; + for (int i = 0 ; i < linear_steps - 1 ; ++i) { + depth -= size; + vec4 t = texture(texHeight, dp + ds * depth); + if (depth >= 1.0 - t.r) + best_depth = depth; + } + depth = best_depth - size; + for (int i = 0 ; i < binary_steps ; ++i) { + size *= 0.5; + vec4 t = texture(texHeight, dp + ds * depth); + if (depth >= 1.0 - t.r) { + best_depth = depth; + depth -= 2 * size; + } + depth += size; + } + + return dp + best_depth * ds; + }else return texcoord.st; +} + + + + +vec3 normalizedLightDirection = normalize(lightDirection); + +const float PI = 3.14159; +float chiGGX(float v) +{ + return (v > 0) ? 1.0 : 0.0; +} + +float GGX_Distribution(vec3 n, vec3 h, float alpha) +{ + float NoH = dot(n,h); + float alpha2 = alpha * alpha; + float NoH2 = NoH * NoH; + float den = NoH2 * alpha2 + (1 - NoH2); + return (chiGGX(NoH) * alpha2) / ( PI * den * den ); +} + + +float GGX_PartialGeometryTerm(vec3 v, vec3 n, vec3 h, float alpha2) +{ + float VoH2 = clamp(dot(v,h),0,1); + float chi = chiGGX( VoH2 / clamp(dot(v,n),0,1) ); + VoH2 = VoH2 * VoH2; + float tan2 = ( 1 - VoH2 ) / VoH2; + return (chi * 2) / ( 1 + sqrt( 1 + alpha2 * tan2 ) ); +} + + +float GGX_PartialGeometryTerm_OPT(float VdotH, float VdotN, float alpha2) +{ + float VoH2 = VdotH;//clamp(dot(v,h),0,1); + float chi = chiGGX( VoH2 / VdotN ); + VoH2 = VoH2 * VoH2; + float tan2 = ( 1 - VoH2 ) / VoH2; + return (chi * 2) / ( 1 + sqrt( 1 + alpha2 * tan2 ) ); +} + + + +vec3 Fresnel_Schlick(float cosT, vec3 F0) +{ + return F0 + (1-F0)* pow( cosT, 4.0); +} + + +// randon number starting seed +ivec2 seed = ivec2(+64523*length(WSPosition.yz)*gl_FragCoord.y, + +62310*length(WSPosition.xz)*gl_FragCoord.x); + + +// Random number generator based on: +// http://www.reedbeta.com/blog/2013/01/12/quick-and-easy-gpu-random-numbers-in-d3d11/ +vec2 wang_hash() +{ + seed = (seed ^ 61) ^ (seed >> 16); + seed *= 9; + seed = seed ^ (seed >> 4); + seed *= 0x27d4eb2d; + seed = seed ^ (seed >> 15); + return seed*(1.0 / 4294967296.0); +} + +vec3 calc_random_vec(float roughness,vec3 up,vec3 right,vec3 dir){ + + vec2 fseed = clamp(wang_hash(),vec2(0),vec2(1)); + + + float theta = atan(roughness*sqrt(fseed.x)/sqrt(1-fseed.x)); + float phi = 4*PI*fseed.y; + vec3 temp = cos(phi) * up + sin(phi) * right; + return (cos(theta) * dir + sin(theta) * temp); +} + +// Based on: +// http://www.codinglabs.net/article_physically_based_rendering_cook_torrance.aspx +vec4 PBR_Specular(float roughness, + vec3 F0, + inout vec3 kS, + samplerCube texSourceEnvMap, + vec3 surfacePosition, + vec3 surfaceNormal,vec2 texcoords){ + + + + vec3 v = normalize(cameraPos - surfacePosition); + vec3 n = surfaceNormal; // approximated normal in world space + //vec3 n = normalize(surfaceNormal);// face based normal + vec3 l = normalize(reflect(-v,n)); + vec3 h = normalize(l + v); + + vec3 up = vec3(0,1,0); + vec3 right = normalize(cross(up,l)); + up = cross(l,right); + + vec3 radiance = vec3(0); + float NdotV = clamp(dot(n, v),0,1); + + + //int no_mipmap = textureQueryLevels(texSourceEnvMap); // get number of mipmaps + + int no_samples = gui_noPBRRays; + // do the lighting calculation for each fragment. + + float r2 = roughness * roughness; + for(int i = 0 ; i < no_samples ; i++ ){ + vec3 lp = calc_random_vec(r2,up,right,l); + + + + // Calculate the half vector + vec3 halfVector = normalize(lp + v); + + + float VdotH = clamp(dot( halfVector, v ),0.01,1.0); + float HdotN = max(dot( halfVector, n ),0.01); + float LdotN = max(dot( lp, n ),0.01); + float LdotH = max(dot( lp, halfVector ),0.01); + + + vec3 fresnel = Fresnel_Schlick( (1-VdotH), F0 ); + + // Geometry term + float geometry = GGX_PartialGeometryTerm_OPT( VdotH, NdotV, r2) + * GGX_PartialGeometryTerm_OPT( LdotH, LdotN, r2); + + // Calculate the Cook-Torrance denominator + float denominator = clamp( 4 * (NdotV * HdotN + 0.05) ,0,1); + + kS += fresnel ; + + + // Accumulate the radiance + float light = max(dot(normalizedLightDirection,lp),0.0); + light = 1-exp(-pow((5*gui_LightRadius*light),4)); + + vec3 color = texture( texSourceEnvMap, lp ).rgb * exp(-0.1*gui_LightPower) + gui_LightPower * light *0.4; + + radiance += color * geometry/denominator * fresnel ; + + } + // Scale back for the samples count + kS = clamp( kS / no_samples ,0,1); + return vec4(radiance / no_samples,1); +} + +vec4 PBR_Specular_SIMPLE(float roughness, + vec3 F0, + inout vec3 kS, + samplerCube texSourceEnvMap, + vec3 surfacePosition, + vec3 surfaceNormal,vec2 texcoords){ + + + + vec3 v = normalize(cameraPos - surfacePosition); + vec3 n = surfaceNormal; // approximated normal in world space + //vec3 n = normalize(surfaceNormal);// face based normal + vec3 l = normalize(reflect(-v,n)); + vec3 h = normalize(l + v); + + vec3 up = vec3(0,1,0); + vec3 right = normalize(cross(up,l)); + up = cross(l,right); + + vec3 radiance = vec3(0); + float NdotV = clamp(dot(n, v),0,1); + + + int no_mipmap = num_mipmaps; + //textureQueryLevels(texSourceEnvMap); // get number of mipmaps + + int no_samples = 1; + // do the lighting calculation for each fragment. + + float r2 = roughness * roughness; + + vec3 lp = l; + // Calculate the half vector + vec3 halfVector = normalize(lp + v); + + + float VdotH = max(dot( halfVector, v ),0.01); + float HdotN = max(dot( halfVector, n ),0.01); + float LdotN = max(dot( lp, n ),0.01); + float LdotH = max(dot( lp, halfVector ),0.01); + + + vec3 fresnel = Fresnel_Schlick( VdotH, F0 ); + + // Geometry term + float geometry = GGX_PartialGeometryTerm_OPT( VdotH, NdotV, r2) + * GGX_PartialGeometryTerm_OPT( LdotH, LdotN, r2); + + // Calculate the Cook-Torrance denominator + float denominator = clamp( 4 * (NdotV * HdotN + 0.05) ,0,1); + + kS = fresnel ; + float light = max(dot(normalizedLightDirection,lp),0.0); + light = 1-exp(-pow((5*gui_LightRadius*light),4)); + // Accumulate the radiance + vec3 color = texture( texSourceEnvMap, lp , roughness * no_mipmap ).rgb * exp(-0.1*gui_LightPower) + gui_LightPower * light *0.4; + + radiance = color * geometry * fresnel / denominator;// * sinT; + + // Scale back for the samples count + kS = clamp( kS ,0,1); + return vec4(radiance ,1); +} + + + +void main( void ) +{ + + // Triangle edges: + if(gui_bShowTriangleEdges){ + if(gui_bMaterialsPreviewEnabled) FragColor = texture(texDiffuse, texcoord.st); + else FragColor = vec4(0); + FragColor.a = 1; + FragNormal = vec4(0); + FragGlowColor = vec4(0); + FragPosition = vec4(10); + return; + } + + if(gui_bMaterialsPreviewEnabled){ + FragColor = texture(texMaterial, texcoord.st); + FragNormal = vec4(0); + FragGlowColor = vec4(0); + FragPosition = vec4(0); + return; + } + + // calculate uv coords based on selected algorithm + vec2 texcoords = texcoord.st; + if(gui_shading_type == 0){ + texcoords = relief_mapping(); + }else if(gui_shading_type == 1){ + texcoords = parallax_normal_mapping(); + } + + // setting up global variables + fvESVertexNormal = normalize( ( texture( texNormal, texcoords.xy ).xyz * 2.0 ) - 1.0 ); + if(!gui_bNormal) fvESVertexNormal = vec3(0,0,1); + + fvBaseColor = texture( texDiffuse, texcoords.xy ); + fvSpecularColor = texture( texSpecular, texcoords.xy ); + fvSSAOColor = texture( texSSAO, texcoords.xy ); + fvRoughness = texture( texRoughness, texcoords.xy ); + fvMetallic = texture( texMetallic, texcoords.xy ); + fvGlossiness = clamp(fvRoughness.r,0.0,1.0)*100+1.0; + + if(!gui_bRoughness) fvGlossiness = 1.0; + + if(!gui_bDiffuse) fvBaseColor = vec4(0.8); // some gray color + if(!gui_bOcclusion)fvSSAOColor = vec4(1.0); + if(!gui_bSpecular) fvSpecularColor = vec4(0); + // TODO: add here R and M control + + vec3 ts_normal = fvESVertexNormal; + mat3 iTBN = transpose(TBN); + vec3 snormal = iTBN*normalize(vec3(ts_normal.x,ts_normal.y,5*ts_normal.z)); + vec3 surfaceNormal= normalize(snormal); // approximated normal in world space + + vec4 finalColor = vec4(0); + + if(gui_shading_model == 1){ + // apply standarnd normal mapping + + vec3 irradiance = texture(texPrefilteredEnvMap, normalize(surfaceNormal)).rgb; + vec3 diffuse = fvBaseColor.rgb * irradiance ; + fvBaseColor.rgb = diffuse; + vec4 bumpMapShadingColor = (bump_mapping(0,texcoords)+bump_mapping(1,texcoords))/2; + //bumpMapShadingColor = bump_mapping(0,texcoords); + FragColor = bumpMapShadingColor; + finalColor = FragColor ; + + }else{ // in case of PBR model + + // PBR calculations + vec3 materialColour = fvBaseColor.rgb; + vec4 aoColour = fvSSAOColor; + float roughness = clamp(fvRoughness.r,0,1); + vec3 metallicColour = clamp(fvMetallic.rgb,vec3(0),vec3(1)); + + if(!gui_bRoughness) roughness = 0.0; + if(!gui_bMetallic) metallicColour = vec3(0.5); + + vec3 F0 = vec3(metallicColour); + vec3 kS = vec3(0); + + vec4 specular = vec4(0); + + // in case of simple calculation use mipmaps instead integration + if(gui_bUseSimplePBR) + { + specular = PBR_Specular_SIMPLE(roughness, + F0,kS, + texSourceEnvMap, + WSPosition, + surfaceNormal,texcoords); + }else{ + specular = PBR_Specular(roughness, + F0,kS, + texSourceEnvMap, + WSPosition, + surfaceNormal,texcoords); + } + + vec3 kD = (1 - kS) ; + if(!gui_bSpecular) fvSpecularColor = vec4(1.0); + // Calculate the diffuse contribution + float NdotL = max(dot(surfaceNormal,normalizedLightDirection),0.0); + + vec3 irradiance = texture(texPrefilteredEnvMap, normalize(surfaceNormal)).rgb * exp(-0.1*gui_LightPower) + vec3(NdotL * gui_LightPower *0.4); + vec3 diffuse = materialColour * irradiance ; + + FragColor = gui_DiffuseIntensity * vec4(kD * diffuse,1) * aoColour + + gui_SpecularIntensity * fvSpecularColor * vec4(materialColour,1) * ( specular ) ; + + finalColor = FragColor ; + } + + // Final colors + FragNormal = vec4(WSPosition,1); + + float bloomLevel = 0.2; + float level = dot(finalColor.rgb,finalColor.rgb)/3; + FragGlowColor = vec4(0); + if(level > bloomLevel )FragGlowColor = finalColor; + + FragPosition = vec4(ESVertexPosition,1); + + + +} diff --git a/Bin/Core/Render/Template.frag b/Bin/Core/Render/Template.frag new file mode 100644 index 0000000..6b768ca --- /dev/null +++ b/Bin/Core/Render/Template.frag @@ -0,0 +1,297 @@ +#version 330 core +// You may try to use higher versions of GLSL if you not use GL330 compatibility +// AB version. +// -------------------------------------------------------------------- +// DO NOT CHANGE this part of code: Uniforms below must be define +// those variables are always provided by AwesomeBump. However one may +// use them in your custom shader. +// -------------------------------------------------------------------- +// Uniform textures +uniform sampler2D texDiffuse; +uniform sampler2D texNormal; +uniform sampler2D texSpecular; +uniform sampler2D texHeight; +uniform sampler2D texSSAO; +uniform sampler2D texRoughness; +uniform sampler2D texMetallic; +uniform sampler2D texMaterial; + +uniform samplerCube texPrefilteredEnvMap; // prefilltered diffuse cube map +uniform samplerCube texSourceEnvMap; // full cube map +uniform int num_mipmaps; // number of mipmaps of texSourceEnvMap + +// Camera/light/matrices +uniform vec3 cameraPos; // View Camera Position +uniform vec3 lightDirection; // Light direction always points to the center of the center of system (0,0,0) normalized. Mouse cause rotation of this light +uniform vec4 lightPos; // Another light position. Here: z-th component ie equal z=5.0. Mouse changes only the x,y components. (Flashlight behaviour). + +uniform mat4 ModelMatrix; // Pure Translation/Rotation of the oryginal components of the rendered Mesh +uniform mat4 ModelViewMatrix; // ViewMatrix * ModelMatrix; Here ViewMatrix is generated by Camera with lookAt method. +uniform mat3 NormalMatrix; // NormalMatrix obtained from ModelViewMatrix. + + +// Uniform controlable from GUI, those parameters are used in AwesomeBump.frag shader +// you may use them to customize your rendering +uniform bool gui_bSpecular; // enable specular texture +uniform bool gui_bOcclusion; // enable Occlusion texture +uniform bool gui_bHeight; // enable Height texture +uniform bool gui_bDiffuse; // enable Diffuse texture +uniform bool gui_bNormal; // enable Normal texture +uniform bool gui_bRoughness; // enable Roughness texture +uniform bool gui_bMetallic; // enable Metallic texture +uniform bool gui_bUseSimplePBR; // enable simplified version of PBR shading +uniform bool gui_bMaterialsPreviewEnabled; // enable Material texture preview +uniform bool gui_bShowTriangleEdges; // show mesh triangles + +// Lightning related variables +uniform float gui_LightPower; // Light power variable +uniform float gui_LightRadius; // Light radius variable +uniform float gui_SpecularIntensity; // Intensity of Specular effect +uniform float gui_DiffuseIntensity; // Intensity of Diffuse effect +uniform int gui_noPBRRays; // Number of rays taken in high quality PRB calulations + +// UV related variables +uniform float gui_depthScale; // UV relief depth scale + +// Enums accesible from GUI +uniform int gui_shading_type; // 0 - relief mapping , 1 - parallax normal mapping , 2 - tessellation +uniform int gui_shading_model; // 0 - PBR , 1 - Bump mapping + + +// -------------------------------------------------------------------- +// DO NOT CHANGE this part of code: Necessary outcome from fragment +// shader. Four buffors are used for further post-processing. +// -------------------------------------------------------------------- + +layout(location = 0) out vec4 FragColor; // Final Color of pixel +layout(location = 1) out vec4 FragNormal; // Frag Normal - Not used +layout(location = 2) out vec4 FragGlowColor; // Glow Color - initial color taken form Glow effect caluclation +layout(location = 3) out vec4 FragPosition; // Frag Eye space position - need to be vec4(ESVertexPosition,1) used for DOF caclulation + + +// -------------------------------------------------------------------- +// DO NOT CHANGE this part of code: Incoming attributes and small +// explanation how they were computed in geometry shader - see comments +// -------------------------------------------------------------------- + +// Eye space attributed computed in geometry shader +in vec3 ESVertexPosition; // Vertex position defined as: ModelViewMatrix * vPosition, where vPosition i basically oryginal position in Obj. +in vec3 ESVertexNormal; // Vertex normal = NormalMatrix * vNormal +in vec3 ESVertexTangent; // Vertex tangent = NormalMatrix * vTangent +in vec3 ESVertexBitangent; // Vertex bitangent = NormalMatrix * vBitangent +in vec3 ESHalfVector; // ES Half vector is computed: normalize((0,0,5)+ESVertexPosition.xyz) + + +// Tangent space variables used for Relief mapping are following: + +// Let us define two vectors: eyeLightVectors and eyeViewVectors +// vec3 eyeLightVectors[2]; +// eyeLightVectors[0] = normalize(-ESVertexPosition.xyz); +// eyeLightVectors[1] = normalize(lightPos.xyz-ESVertexPosition.xyz); +// vec3 eyeViewVectors[2]; +// eyeViewVectors[0] = -normalize(ESVertexPosition.xyz); +// eyeViewVectors[1] = -normalize(ESVertexPosition.xyz); + +// Additionally ESTBN matrix is computed: ESTBN = transpose(mat3(ESVertexTangent,ESVertexBitangent,ESVertexNormal)); + +const int no_lights = 2; +in vec3 TSLightPosition[no_lights]; // TSLightPosition[i] = ESTBN * eyeLightDir[i]; +in vec3 TSViewDirection[no_lights]; // TSViewDirection[i] = ESTBN * eyeViewVectors[i]; +in vec3 TSHalfVector; // then tangent space half vector is calculated as TSHalfVector = ESTBN * ESHalfVector + +in vec3 texcoord; // Frag UV coordinate + +// World space attributes evaluated in geometry shader +in vec3 WSTangent; // Tangent vector calculated as: mat3(ModelMatrix)*vTangent +in vec3 WSBitangent; // Bitangent vector calculated as: mat3(ModelMatrix)*vBitangent +in vec3 WSNormal; // Normal vector calculated as: mat3(ModelMatrix)*vNormal +in vec3 WSPosition; // Position calculate from: (ModelMatrix * vec4( newPos[i],1)).xyz; +in mat3 TBN; // Wordl space TBN matrix calculated from transpose(mat3(WSTangent,WSBitangent,WSNormal)); + + +// -------------------------------------------------------------------- +// HERE you can put defined by you new uniform variables. +// +// Supported types: +// - float +// - int +// The number of user defined uniform variables is limited to about 20 for now. +// *** +// EXAMPLE usage of user define uniform variable: +uniform float example_float; // value=0.0; min = -10.0 ; max= 10.0 ; step = 0.1 ; name = "Example float" ; description = "This parameter does nothing" +// NOTE that each uniform has to be followed by special one line comment: filled with following parameters +// min (must be define)- minimum allowed value +// max (must be define)- maximum value +// value (must be define)- default value which will be loaded each time you start AB +// step (must be define)- singleStep +// name (optional) - human readable name visible in GUI +// description (optional) - explanation for other users what this parameter does +// -------------------------------------------------------------------- + +uniform float glow_Level; // value = 0.4 ; min = 0.0 ; max = 1.0 ; step = 0.01 ; name = "Glow level" ; description = "Changes the cutoff color of the glow input image" +uniform float specular_Strength; // value = 3.0; min=0.0;max=100;step =0.1 ; name = "Specular strength" ; description = "Change the specular reflection influence" +// --------------------------------------------------------------------- +// TEMPLATE FRAGMENT SHADER - written by Krzysztof Kolasinski @2015 +// Only standard relief mapping is done here +// --------------------------------------------------------------------- + +float depth = 0.04*gui_depthScale; + +// Global variables +vec3 Kd = vec3(gui_DiffuseIntensity); +vec3 Ks = vec3(gui_SpecularIntensity*0.5); +vec3 Ka = vec3(0.0); +float alpha = 1.0 / (gui_LightRadius*0.1 + 0.01); + +vec3 LightSource_diffuse = vec3(1.0); +vec3 LightSource_ambient = vec3(1.0); +vec3 LightSource_specular = vec3(1.0); +vec3 normalizedLightDirection = normalize(lightDirection); +// global variables +vec3 fvESVertexNormal; +vec4 fvBaseColor; +vec4 fvSpecularColor; +vec4 fvSSAOColor; +float fvGlossiness; +vec4 fvRoughness; +vec4 fvMetallic; + + +// Implemenetation of typical bump-mapping glsl shader based on phong model +vec4 bump_mapping(int lightIndeks,vec2 texcoord){ + + vec3 fvTSLightPosition = normalize( TSLightPosition[lightIndeks] ); + float fNDotL = max(dot( fvESVertexNormal, fvTSLightPosition ),0.0); + vec3 fvReflection = normalize( ( ( 2.0 * fvESVertexNormal ) * fNDotL ) - fvTSLightPosition ); + vec3 fvTSViewDirection = normalize( TSViewDirection[lightIndeks] ); + float fRDotV = max( 0.0, dot( fvReflection, fvTSViewDirection ) ); + + vec4 fvTotalAmbient = vec4(Ka * LightSource_ambient,1) * fvBaseColor; + vec4 fvTotalDiffuse = gui_LightPower * vec4(Kd * LightSource_diffuse,1) * fNDotL * fvBaseColor; + vec3 lightDirection = normalize( TSLightPosition[lightIndeks] ); + vec4 fvTotalSpecular = gui_LightPower * vec4(Ks * LightSource_specular,1) * ( pow( fRDotV, alpha*fvGlossiness ) ) * fvSpecularColor * specular_Strength; + + if(!gui_bSpecular) fvTotalSpecular = vec4(0); + + return ( fvTotalDiffuse*fvSSAOColor + fvTotalSpecular); +} + + +// This function is based on shader from kiirala github repo: url: https://github.com/kiirala/reliefmap +// Calculation of frag depth based on height map and ES vectors +vec2 relief_mapping() { + if (gui_bHeight){ + vec3 N = normalize(ESVertexNormal); + vec3 eview = normalize(ESVertexPosition); + vec3 etangent = normalize(ESVertexTangent); + vec3 ebitangent = normalize(ESVertexBitangent); + + vec3 tview = normalize(vec3(dot(eview, etangent), dot(eview, ebitangent), dot(eview, -N))); + vec2 ds = tview.xy * depth / tview.z; + vec2 dp = texcoord.xy; + + const int linear_steps = 15; + const int binary_steps = 15; + float depth_step = 1.0 / linear_steps; + float size = depth_step; + float depth = 1.0; + float best_depth = 1.0; + for (int i = 0 ; i < linear_steps - 1 ; ++i) { + depth -= size; + vec4 t = texture(texHeight, dp + ds * depth); + if (depth >= 1.0 - t.r) + best_depth = depth; + } + depth = best_depth - size; + for (int i = 0 ; i < binary_steps ; ++i) { + size *= 0.5; + vec4 t = texture(texHeight, dp + ds * depth); + if (depth >= 1.0 - t.r) { + best_depth = depth; + depth -= 2 * size; + } + depth += size; + } + + return dp + best_depth * ds; + }else return texcoord.st; +} + +// --------------------------------------------------------------------- +// Template shader - main function +// returns: +// FragColor - Final color of pixel +// FragGlowColor - Glow effect +// FragPosition - DOF post processing +// --------------------------------------------------------------------- + +void main( void ) +{ + + // This + if(gui_bShowTriangleEdges){ + if(gui_bMaterialsPreviewEnabled) FragColor = texture(texDiffuse, texcoord.st); + else FragColor = vec4(0); + FragColor.a = 1; + FragNormal = vec4(0); + FragGlowColor = vec4(0); + FragPosition = vec4(10); + return; + } + + if(gui_bMaterialsPreviewEnabled){ + FragColor = texture(texMaterial, texcoord.st); + FragNormal = vec4(0); + FragGlowColor = vec4(0); + FragPosition = vec4(0); + return; + } + + // calculate uv coords based on selected algorithm + vec2 texcoords = relief_mapping(); + + + // setting up global variables + fvESVertexNormal = normalize( ( texture( texNormal, texcoords.xy ).xyz * 2.0 ) - 1.0 ); + if(!gui_bNormal) fvESVertexNormal = vec3(0,0,1); + + fvBaseColor = texture( texDiffuse, texcoords.xy ); + fvSpecularColor = texture( texSpecular, texcoords.xy ); + fvSSAOColor = texture( texSSAO, texcoords.xy ); + fvRoughness = texture( texRoughness, texcoords.xy ); + fvMetallic = texture( texMetallic, texcoords.xy ); + fvGlossiness = clamp(fvRoughness.r,0.0,1.0)*100+1.0; + + if(!gui_bRoughness) fvGlossiness = 1.0; + if(!gui_bDiffuse) fvBaseColor = vec4(0.8); // some gray color + if(!gui_bOcclusion)fvSSAOColor = vec4(1.0); + if(!gui_bSpecular) fvSpecularColor = vec4(0); + + + vec3 surfaceNormal= normalize(transpose(TBN)*fvESVertexNormal); // approximated normal in world space + vec3 irradiance = texture(texPrefilteredEnvMap, normalize(surfaceNormal)).rgb; + fvBaseColor.rgb *= irradiance ; + + vec4 bumpMapShadingColor = (bump_mapping(0,texcoords)+bump_mapping(1,texcoords))/2; + FragColor = bumpMapShadingColor; + + + // ------------------------------------------------------------- + // Output for glow effect + // ------------------------------------------------------------- + + float level = dot(FragColor.rgb,FragColor.rgb)/3; + FragGlowColor = vec4(0); + if(level > glow_Level )FragGlowColor = FragColor; + + // ------------------------------------------------------------- + // Not used: + // ------------------------------------------------------------- + FragNormal = vec4(0); + + // ------------------------------------------------------------- + // This must be like this: + // ------------------------------------------------------------- + FragPosition = vec4(ESVertexPosition,1); + +} diff --git a/Sources/AwesomeBump.pro b/Sources/AwesomeBump.pro index e87e32e..54e4371 100644 --- a/Sources/AwesomeBump.pro +++ b/Sources/AwesomeBump.pro @@ -2,6 +2,30 @@ TEMPLATE = app CONFIG += c++11 QT += opengl gui widgets +# QtnProperty project source files +# open the QtnProperty project and +# compile it. Then compile AB +TOP_BUILD_DIR=utils/QtnProperty +BIN_DIR = $$TOP_BUILD_DIR/bin +LIBS += -L$$BIN_DIR -lQtnPropertyCore -lQtnPropertyWidget + +include($$TOP_BUILD_DIR/Common.pri) +PEG_TOOL = $$BIN_DIR/QtnPEG +include($$TOP_BUILD_DIR/PEG.pri) + +INCLUDEPATH += utils/QtnProperty/Core +INCLUDEPATH += utils/QtnProperty/PropertyWidget + + +PEG_SOURCES += properties/Filter3DDOF.pef \ + properties/Filter3DBloom.pef \ + properties/Filter3DLensFlares.pef \ + properties/Filter3DToneMapping.pef \ + properties/GLSLParsedFragShader.pef \ + properties/ImageProperties.pef \ + properties/Filters3D.pef + + DESTDIR = Build/Bin OBJECTS_DIR = Build/Obj MOC_DIR = Build/Ui @@ -27,7 +51,8 @@ CONFIG(release_gl330) { DEFINES += RESOURCE_BASE=\\\"./\\\" VPATH += ../shared -INCLUDEPATH += ../shared include +INCLUDEPATH += ../shared include \ + utils/ HEADERS = glwidget.h \ mainwindow.h \ @@ -50,7 +75,10 @@ HEADERS = glwidget.h \ allaboutdialog.h \ formimagebase.h \ dockwidget3dsettings.h \ - gpuinfo.h + gpuinfo.h \ + properties/Dialog3DGeneralSettings.h \ + utils/glslshaderparser.h \ + utils/glslparsedshadercontainer.h SOURCES = glwidget.cpp \ main.cpp \ @@ -73,7 +101,10 @@ SOURCES = glwidget.cpp \ allaboutdialog.cpp \ formimagebase.cpp \ dockwidget3dsettings.cpp \ - gpuinfo.cpp + gpuinfo.cpp \ + properties/Dialog3DGeneralSettings.cpp \ + utils/glslshaderparser.cpp \ + utils/glslparsedshadercontainer.cpp RESOURCES += content.qrc @@ -91,12 +122,21 @@ FORMS += \ formmaterialindicesmanager.ui \ allaboutdialog.ui \ dialogshortcuts.ui \ - dockwidget3dsettings.ui + dockwidget3dsettings.ui \ + properties/Dialog3DGeneralSettings.ui ICON = resources/icon.icns DISTFILES += \ - resources/quad.obj + resources/quad.obj \ + properties/Filter3DDOF.pef \ + properties/Filter3DBloom.pef \ + properties/Filter3DLensFlares.pef \ + properties/Filter3DToneMapping.pef \ + properties/Filters3D.pef \ + properties/GLSLParsedFragShader.pef \ + properties/ImageProperties.pef + # install additional files into target destination # (require "make install") diff --git a/Sources/CommonObjects.h b/Sources/CommonObjects.h index 0ae2b23..4c94765 100644 --- a/Sources/CommonObjects.h +++ b/Sources/CommonObjects.h @@ -7,7 +7,7 @@ #include #include "qopenglerrorcheck.h" #include - +#include "properties/ImageProperties.peg.h" #define TAB_SETTINGS 9 #define TAB_TILING 10 @@ -21,7 +21,9 @@ +//#define TEXTURE_FORMAT GL_RGB16F #define TEXTURE_FORMAT GL_RGB16F +#define TEXTURE_3DRENDER_FORMAT GL_RGB16F #define KEY_SHOW_MATERIALS Qt::Key_S @@ -411,6 +413,7 @@ struct BaseMapConvLevelProperties{ // Main object. Contains information about Image and the post process parameters class FBOImageProporties{ public: + QtnPropertySetFormImageProp* properties; bool bSkipProcessing; QGLFramebufferObject *fbo ; // output image @@ -831,7 +834,9 @@ class FBOImageProporties{ break; } */ - GLCHK(FBOImages::create(fbo , image.width(), image.height())); + GLuint internal_format = TEXTURE_FORMAT; + if(imageType == HEIGHT_TEXTURE) internal_format = TEXTURE_3DRENDER_FORMAT; + GLCHK(FBOImages::create(fbo , image.width(), image.height(),internal_format)); } @@ -845,9 +850,9 @@ class FBOImageProporties{ void resizeFBO(int width, int height){ - GLCHK(FBOImages::resize(fbo ,width,height)); - // double memUsage = width * height * 4 * 16 / (1024.0*1024.0*8); - // qDebug() << "Resized image memory usage:" << memUsage << "[MB]"; + GLuint internal_format = TEXTURE_FORMAT; + if(imageType == HEIGHT_TEXTURE) internal_format = TEXTURE_3DRENDER_FORMAT; + GLCHK(FBOImages::resize(fbo,width,height,internal_format)); bFirstDraw = true; } diff --git a/Sources/content.qrc b/Sources/content.qrc index 4894561..1face61 100644 --- a/Sources/content.qrc +++ b/Sources/content.qrc @@ -67,5 +67,7 @@ resources/lensdirt.png resources/lensstar.png resources/showGrunge.png + resources/recompileShader.png + resources/settings3d.png diff --git a/Sources/dialoglogger.cpp b/Sources/dialoglogger.cpp index 5d1015a..0407c56 100644 --- a/Sources/dialoglogger.cpp +++ b/Sources/dialoglogger.cpp @@ -6,6 +6,7 @@ DialogLogger::DialogLogger(QWidget *parent) : ui(new Ui::DialogLogger) { ui->setupUi(this); + } DialogLogger::~DialogLogger() diff --git a/Sources/dialoglogger.ui b/Sources/dialoglogger.ui index 5775bd7..6a78fb0 100644 --- a/Sources/dialoglogger.ui +++ b/Sources/dialoglogger.ui @@ -11,7 +11,7 @@ - Dialog + AwesomeBump log @@ -43,7 +43,7 @@ 0 0 796 - 277 + 269 diff --git a/Sources/dockwidget3dsettings.cpp b/Sources/dockwidget3dsettings.cpp index aeb1849..dcf26d9 100644 --- a/Sources/dockwidget3dsettings.cpp +++ b/Sources/dockwidget3dsettings.cpp @@ -9,8 +9,6 @@ DockWidget3DSettings::DockWidget3DSettings(QWidget *parent, GLWidget* ptr_gl) : ui->setupUi(this); close(); setContentsMargins(0,0,0,0); - //setWindowFlags(Qt::Widget); - // Connect all the sliders and other widgets connect(ui->horizontalSliderDepthScale ,SIGNAL(valueChanged(int)),this,SLOT(updateSettings(int))); diff --git a/Sources/dockwidget3dsettings.ui b/Sources/dockwidget3dsettings.ui index a0f830f..30d365d 100644 --- a/Sources/dockwidget3dsettings.ui +++ b/Sources/dockwidget3dsettings.ui @@ -9,7 +9,7 @@ 0 0 - 503 + 515 200 @@ -21,7 +21,7 @@ - 490 + 515 200 @@ -44,7 +44,7 @@ QDockWidget::NoDockWidgetFeatures - Qt::NoDockWidgetArea + Qt::AllDockWidgetAreas 3D settings @@ -1124,8 +1124,6 @@ - - line line_2 diff --git a/Sources/formimagebase.h b/Sources/formimagebase.h index 3dd453f..ae4d092 100644 --- a/Sources/formimagebase.h +++ b/Sources/formimagebase.h @@ -3,7 +3,7 @@ #include #include "CommonObjects.h" - +#include "properties/ImageProperties.peg.h" // Manages all the input/output operations // like : open & save from/to file // paste & copy from/to clipboard @@ -23,6 +23,7 @@ class FormImageBase : public QWidget virtual void saveImageToDir(const QString &dir,QImage& image); FBOImageProporties imageProp; // for simplicity I made this public, why not... + protected: void dropEvent(QDropEvent *event); diff --git a/Sources/formimageprop.cpp b/Sources/formimageprop.cpp index 40b62d2..975abed 100644 --- a/Sources/formimageprop.cpp +++ b/Sources/formimageprop.cpp @@ -9,6 +9,14 @@ FormImageProp::FormImageProp(QMainWindow *parent, QGLWidget* qlW_ptr) : ui(new Ui::FormImageProp) { ui->setupUi(this); + imageProp.properties = new QtnPropertySetFormImageProp(this); + ui->widgetProperty->setParts(QtnPropertyWidgetPartsDescriptionPanel); + ui->widgetProperty->setPropertySet(imageProp.properties); + + connect(imageProp.properties,SIGNAL(propertyDidChange(const QtnPropertyBase*,const QtnPropertyBase*,QtnPropertyChangeReason)), + this,SLOT(propertyChanged(const QtnPropertyBase*,const QtnPropertyBase*,QtnPropertyChangeReason))); + + connect(imageProp.properties,SIGNAL(propertyDidFinishEditing()),this,SLOT(propertyFinishedEditing())); bOpenNormalMapMixer = false; @@ -254,6 +262,25 @@ FormImageProp::FormImageProp(QMainWindow *parent, QGLWidget* qlW_ptr) : setFocusPolicy(Qt::ClickFocus); } +void FormImageProp::propertyChanged(const QtnPropertyBase* changedProperty, + const QtnPropertyBase* firedProperty, + QtnPropertyChangeReason reason){ + if (reason & QtnPropertyChangeReasonValue){ + // + if(dynamic_cast(changedProperty)) + { + qDebug() << changedProperty << firedProperty; + emit imageChanged(); + + } + } +} +void FormImageProp::propertyFinishedEditing(){ + qDebug() << "asd"; + emit imageChanged(); +} + + FormImageProp::~FormImageProp() { diff --git a/Sources/formimageprop.h b/Sources/formimageprop.h index ca5cda8..ed9c409 100644 --- a/Sources/formimageprop.h +++ b/Sources/formimageprop.h @@ -16,6 +16,8 @@ #include "formbasemapconversionlevels.h" + + namespace Ui { class FormImageProp; } @@ -54,7 +56,10 @@ class FormImageProp : public FormImageBase public slots: - + void propertyChanged(const QtnPropertyBase* changedProperty, + const QtnPropertyBase* firedProperty, + QtnPropertyChangeReason reason); + void propertyFinishedEditing(); void reloadImageSettings(); void pasteFromClipboard(); void copyToClipboard(); diff --git a/Sources/formimageprop.ui b/Sources/formimageprop.ui index c73ea28..8e77953 100644 --- a/Sources/formimageprop.ui +++ b/Sources/formimageprop.ui @@ -6,8 +6,8 @@ 0 0 - 279 - 4085 + 304 + 4309 @@ -221,6 +221,22 @@ + + + + + 0 + 0 + + + + + 0 + 400 + + + + @@ -4923,6 +4939,14 @@ + + + QtnPropertyWidget + QWidget +
PropertyWidget.h
+ 1 +
+
diff --git a/Sources/glimageeditor.cpp b/Sources/glimageeditor.cpp index d091010..081a15b 100644 --- a/Sources/glimageeditor.cpp +++ b/Sources/glimageeditor.cpp @@ -116,7 +116,7 @@ void GLImage::cleanup() QSize GLImage::minimumSizeHint() const { - return QSize(360, 360); + return QSize(100, 100); } @@ -438,7 +438,14 @@ void GLImage::render(){ break; } - +// GLuint internal_format = TEXTURE_FORMAT; +// if(conversionType != CONVERT_NONE || activeImage->bConversionBaseMap){ +// internal_format = TEXTURE_3DRENDER_FORMAT; +// FBOImages::create(auxFBO1,activeFBO->width(),activeFBO->height(),internal_format); +// FBOImages::create(auxFBO2,activeFBO->width(),activeFBO->height(),internal_format); +// FBOImages::create(auxFBO3,activeFBO->width(),activeFBO->height(),internal_format); +// FBOImages::create(auxFBO4,activeFBO->width(),activeFBO->height(),internal_format); +// } // create or resize when image was changed FBOImages::resize(auxFBO1,activeFBO->width(),activeFBO->height()); FBOImages::resize(auxFBO2,activeFBO->width(),activeFBO->height()); @@ -1206,6 +1213,10 @@ void GLImage::applyColorHueFilter( QGLFramebufferObject* inputFBO, GLCHK( program->setUniformValue("quad_pos" , QVector2D(0.0,0.0)) ); GLCHK( program->setUniformValue("gui_hue" , float(activeImage->colorHue)) ); + qDebug() << activeImage->properties->Basic.ColorHue; + GLCHK( program->setUniformValue("gui_hue" , float(activeImage->properties->Basic.ColorHue)) ); + + GLCHK( glBindTexture(GL_TEXTURE_2D, inputFBO->texture()) ); GLCHK( glDrawElements(GL_TRIANGLES, 3*2, GL_UNSIGNED_INT, 0) ); outputFBO->bindDefault(); diff --git a/Sources/glwidget.cpp b/Sources/glwidget.cpp index a98fc08..2de7660 100644 --- a/Sources/glwidget.cpp +++ b/Sources/glwidget.cpp @@ -71,10 +71,13 @@ GLWidget::GLWidget(QWidget *parent, QGLWidget * shareWidget) outputFBO= NULL; auxFBO = NULL; for(int i = 0; i < 4; i++){ - glowInputColor[i] = NULL; + glowInputColor[i] = NULL; glowOutputColor[i] = NULL; } - + // initializing tone mapping FBOs with nulls + for(int i = 0; i < 10; i++){ + toneMipmaps[i] = NULL; + } cameraInterpolation = 1.0; QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -102,7 +105,7 @@ void GLWidget::cleanup() deleteTexture(lensStarTexture); - delete program; + delete line_program; delete skybox_program; delete env_program; @@ -180,6 +183,9 @@ void GLWidget::toggleMetallicView(bool enable){ void GLWidget::initializeGL() { + + + initializeOpenGLFunctions(); glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); makeCurrent(); @@ -198,14 +204,6 @@ void GLWidget::initializeGL() QOpenGLShader *teshader = NULL; QOpenGLShader *gshader = NULL; - - - qDebug() << "Loading quad (fragment shader)"; - fshader = new QOpenGLShader(QOpenGLShader::Fragment, this); - fshader->compileSourceFile(":/resources/plane.frag"); - if (!fshader->log().isEmpty()) qDebug() << fshader->log(); - else qDebug() << "done"; - qDebug() << "Loading quad (geometry shader)"; gshader = new QOpenGLShader(QOpenGLShader::Geometry, this); QFile gFile(":/resources/plane.geom"); @@ -218,63 +216,85 @@ void GLWidget::initializeGL() if (!gshader->log().isEmpty()) qDebug() << gshader->log(); else qDebug() << "done"; - program = new QOpenGLShaderProgram(this); +#ifndef USE_OPENGL_330 + qDebug() << "Loading quad (vertex shader)"; + vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); + vshader->compileSourceFile(":/resources/plane.vert"); + if (!vshader->log().isEmpty()) qDebug() << vshader->log(); + else qDebug() << "done"; + + qDebug() << "Loading quad (tessellation control shader)"; + tcshader = new QOpenGLShader(QOpenGLShader::TessellationControl, this); + tcshader->compileSourceFile(":/resources/plane.tcs.vert"); + if (!tcshader->log().isEmpty()) qDebug() << tcshader->log(); + else qDebug() << "done"; + qDebug() << "Loading quad (tessellation evaluation shader)"; + teshader = new QOpenGLShader(QOpenGLShader::TessellationEvaluation, this); + teshader->compileSourceFile(":/resources/plane.tes.vert"); + if (!teshader->log().isEmpty()) qDebug() << teshader->log(); + else qDebug() << "done"; - #ifndef USE_OPENGL_330 - qDebug() << "Loading quad (vertex shader)"; - vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); - vshader->compileSourceFile(":/resources/plane.vert"); - if (!vshader->log().isEmpty()) qDebug() << vshader->log(); - else qDebug() << "done"; - qDebug() << "Loading quad (tessellation control shader)"; - tcshader = new QOpenGLShader(QOpenGLShader::TessellationControl, this); - tcshader->compileSourceFile(":/resources/plane.tcs.vert"); - if (!tcshader->log().isEmpty()) qDebug() << tcshader->log(); +// setting shaders for 3.30 version of openGL +#else + qDebug() << "Loading quad (vertex shader) for openGL 3.30"; + vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); + vshader->compileSourceFile(":/resources/plane_330.vert"); + if (!vshader->log().isEmpty()) qDebug() << vshader->log(); + else qDebug() << "done"; +#endif + GLSLShaderParser* lastIndex = currentShader; + for(int ip = 0 ; ip < glslShadersList->glslParsedShaders.size();ip++){ + currentShader = glslShadersList->glslParsedShaders[ip]; + currentShader->program = new QOpenGLShaderProgram(this); + + // ----------------------------------------- + // Load custom fragment shader. + // ----------------------------------------- + qDebug() << "Loading parsed glsl fragmend shader"; + QOpenGLShader* pfshader = new QOpenGLShader(QOpenGLShader::Fragment, this); + pfshader->compileSourceFile(currentShader->shaderPath); + if (!pfshader->log().isEmpty()) qDebug() << pfshader->log(); else qDebug() << "done"; - qDebug() << "Loading quad (tessellation evaluation shader)"; - teshader = new QOpenGLShader(QOpenGLShader::TessellationEvaluation, this); - teshader->compileSourceFile(":/resources/plane.tes.vert"); - if (!teshader->log().isEmpty()) qDebug() << teshader->log(); - else qDebug() << "done"; - program->addShader(tcshader); - program->addShader(teshader); + #ifndef USE_OPENGL_330 + currentShader->program->addShader(tcshader); + currentShader->program->addShader(teshader); + #endif + currentShader->program->addShader(vshader); + currentShader->program->addShader(pfshader); + currentShader->program->addShader(gshader); + currentShader->program->bindAttributeLocation("FragColor",0); + currentShader->program->bindAttributeLocation("FragNormal",1); + currentShader->program->bindAttributeLocation("FragGlowColor",2); + currentShader->program->bindAttributeLocation("FragPosition",3); + GLCHK(currentShader->program->link()); + + delete pfshader; - // setting shaders for 3.30 version of openGL - #else - qDebug() << "Loading quad (vertex shader) for openGL 3.30"; - vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); - vshader->compileSourceFile(":/resources/plane_330.vert"); - if (!vshader->log().isEmpty()) qDebug() << vshader->log(); - else qDebug() << "done"; - #endif - program->addShader(vshader); - program->addShader(fshader); - program->addShader(gshader); - program->bindAttributeLocation("FragColor",0); - program->bindAttributeLocation("FragNormal",1); - program->bindAttributeLocation("FragGlowColor",2); - program->bindAttributeLocation("FragPosition",3); - GLCHK(program->link()); + GLCHK(currentShader->program->bind()); + currentShader->program->setUniformValue("texDiffuse" , 0); + currentShader->program->setUniformValue("texNormal" , 1); + currentShader->program->setUniformValue("texSpecular" , 2); + currentShader->program->setUniformValue("texHeight" , 3); + currentShader->program->setUniformValue("texSSAO" , 4); + currentShader->program->setUniformValue("texRoughness", 5); + currentShader->program->setUniformValue("texMetallic", 6); + currentShader->program->setUniformValue("texMaterial", 7); - GLCHK(program->bind()); - program->setUniformValue("texDiffuse" , 0); - program->setUniformValue("texNormal" , 1); - program->setUniformValue("texSpecular" , 2); - program->setUniformValue("texHeight" , 3); - program->setUniformValue("texSSAO" , 4); - program->setUniformValue("texRoughness", 5); - program->setUniformValue("texMetallic", 6); - program->setUniformValue("texMaterial", 7); + currentShader->program->setUniformValue("texPrefilteredEnvMap", 8); + currentShader->program->setUniformValue("texSourceEnvMap" , 9); - program->setUniformValue("texDiffuseEnvMap", 8); - program->setUniformValue("texEnvMap" , 9); + GLCHK(currentShader->program->release()); + Dialog3DGeneralSettings::updateParsedShaders(); + } // end of loading parsed shaders + currentShader = lastIndex; + Dialog3DGeneralSettings::updateParsedShaders(); // lines shader @@ -311,8 +331,8 @@ void GLWidget::initializeGL() line_program->setUniformValue("texMetallic", 6); line_program->setUniformValue("texMaterial", 7); - line_program->setUniformValue("texDiffuseEnvMap", 8); - line_program->setUniformValue("texEnvMap" , 9); + line_program->setUniformValue("texPrefilteredEnvMap", 8); + line_program->setUniformValue("texSourceEnvMap" , 9); if(vshader != NULL) delete vshader; @@ -489,7 +509,6 @@ void GLWidget::paintGL() double w = cameraInterpolation; camera.position = camera.position*(1-w) + newCamera.position * w; cameraInterpolation += 0.01; - } @@ -544,7 +563,7 @@ void GLWidget::paintGL() // --------------------------------------------------------- // Drawing model // --------------------------------------------------------- - QOpenGLShaderProgram* program_ptrs[2] = {program,line_program}; + QOpenGLShaderProgram* program_ptrs[2] = {currentShader->program,line_program}; GLCHK( glEnable(GL_CULL_FACE) ); @@ -558,6 +577,12 @@ void GLWidget::paintGL() QOpenGLShaderProgram* program_ptr = program_ptrs[pindex]; GLCHK( program_ptr->bind() ); + // Update uniforms from parsed file. + if(pindex == 0){ + Dialog3DGeneralSettings::setUniforms(); + } + + GLCHK( program_ptr->setUniformValue("ProjectionMatrix", projectionMatrix) ); objectMatrix.setToIdentity(); @@ -681,16 +706,16 @@ void GLWidget::paintGL() // do post processing if materials are not shown if( keyPressed != KEY_SHOW_MATERIALS ){ + + copyTexToFBO(colorFBO->fbo->texture(),outputFBO->fbo); + // ----------------------------------------------------------- // Post processing: // 1. Bloom (can be disabled/enabled by gui) // ----------------------------------------------------------- - // enable of disable bloom effect if(display3Dparameters.bBloomEffect){ applyGlowFilter(outputFBO->fbo); - copyTexToFBO(outputFBO->fbo->texture(),colorFBO->fbo); - }// end of if bloom effect // ----------------------------------------------------------- @@ -698,8 +723,7 @@ void GLWidget::paintGL() // 2. DOF (can be disabled/enabled by gui) // ----------------------------------------------------------- if(display3Dparameters.bDofEffect){ - applyDofFilter(colorFBO->fbo->texture(),outputFBO->fbo); - copyTexToFBO(outputFBO->fbo->texture(),colorFBO->fbo); + applyDofFilter(colorFBO->fbo->texture(),outputFBO->fbo); } // ----------------------------------------------------------- @@ -708,12 +732,11 @@ void GLWidget::paintGL() // ----------------------------------------------------------- if(display3Dparameters.bLensFlares){ applyLensFlaresFilter(colorFBO->fbo->texture(),outputFBO->fbo); - copyTexToFBO(outputFBO->fbo->texture(),colorFBO->fbo); } applyToneFilter(colorFBO->fbo->texture(),outputFBO->fbo); - //copyTexToFBO(outputFBO->fbo->texture(),colorFBO->fbo); + applyNormalFilter(outputFBO->fbo->texture()); }else{ // end of if SHOW MATERIALS TEXTURE DISABLED @@ -1027,12 +1050,109 @@ void GLWidget::chooseSkyBox(QString cubeMapName,bool bFirstTime){ } void GLWidget::updatePerformanceSettings(Display3DSettings settings){ - qDebug() << "Changing 3D settings"; + display3Dparameters = settings; updateGL(); } +void GLWidget::recompileRenderShader(){ + + makeCurrent(); + currentShader->reparseShader(); + currentShader->program->release(); + delete currentShader->program; + currentShader->program = new QOpenGLShaderProgram(this); + + QOpenGLShader *vshader = NULL; + QOpenGLShader *tcshader = NULL; + QOpenGLShader *teshader = NULL; + QOpenGLShader *gshader = NULL; + + qDebug() << "Recompiling shaders:"; + gshader = new QOpenGLShader(QOpenGLShader::Geometry, this); + QFile gFile(":/resources/plane.geom"); + gFile.open(QFile::ReadOnly); + QTextStream in(&gFile); + QString shaderCode = in.readAll(); + QString preambule = "#version 330 core\n" + "layout(triangle_strip, max_vertices = 3) out;\n" ; + gshader->compileSourceCode(preambule+shaderCode); + if (!gshader->log().isEmpty()) qDebug() << gshader->log(); + else qDebug() << " Geometry shader: OK"; + +#ifndef USE_OPENGL_330 + vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); + vshader->compileSourceFile(":/resources/plane.vert"); + if (!vshader->log().isEmpty()) qDebug() << vshader->log(); + else qDebug() << " Vertex shader (GLSL4.0): OK"; + + tcshader = new QOpenGLShader(QOpenGLShader::TessellationControl, this); + tcshader->compileSourceFile(":/resources/plane.tcs.vert"); + if (!tcshader->log().isEmpty()) qDebug() << tcshader->log(); + else qDebug() << " Tessellation control shader (GLSL4.0): OK"; + + teshader = new QOpenGLShader(QOpenGLShader::TessellationEvaluation, this); + teshader->compileSourceFile(":/resources/plane.tes.vert"); + if (!teshader->log().isEmpty()) qDebug() << teshader->log(); + else qDebug() << " Tessellation evaluation shader (GLSL4.0): OK"; + +// setting shaders for 3.30 version of openGL +#else + qDebug() << "Loading quad (vertex shader) for openGL 3.30"; + vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); + vshader->compileSourceFile(":/resources/plane_330.vert"); + if (!vshader->log().isEmpty()) qDebug() << vshader->log(); + else qDebug() << " Vertex shader (GLSL3.3): OK"; +#endif + + // ----------------------------------------- + // Load custom fragment shader. + // ----------------------------------------- + QOpenGLShader* pfshader = new QOpenGLShader(QOpenGLShader::Fragment, this); + pfshader->compileSourceFile(currentShader->shaderPath); + if (!pfshader->log().isEmpty()) qDebug() << pfshader->log(); + else qDebug() << " Custom Fragment Shader (GLSL3.3): OK"; + + + #ifndef USE_OPENGL_330 + currentShader->program->addShader(tcshader); + currentShader->program->addShader(teshader); + #endif + currentShader->program->addShader(vshader); + currentShader->program->addShader(pfshader); + currentShader->program->addShader(gshader); + currentShader->program->bindAttributeLocation("FragColor",0); + currentShader->program->bindAttributeLocation("FragNormal",1); + currentShader->program->bindAttributeLocation("FragGlowColor",2); + currentShader->program->bindAttributeLocation("FragPosition",3); + GLCHK(currentShader->program->link()); + + delete pfshader; + if(vshader != NULL) delete vshader; + if(tcshader != NULL) delete tcshader; + if(teshader != NULL) delete teshader; + if(gshader != NULL) delete gshader; + + + GLCHK(currentShader->program->bind()); + currentShader->program->setUniformValue("texDiffuse" , 0); + currentShader->program->setUniformValue("texNormal" , 1); + currentShader->program->setUniformValue("texSpecular" , 2); + currentShader->program->setUniformValue("texHeight" , 3); + currentShader->program->setUniformValue("texSSAO" , 4); + currentShader->program->setUniformValue("texRoughness", 5); + currentShader->program->setUniformValue("texMetallic", 6); + currentShader->program->setUniformValue("texMaterial", 7); + + currentShader->program->setUniformValue("texPrefilteredEnvMap", 8); + currentShader->program->setUniformValue("texSourceEnvMap" , 9); + + GLCHK(currentShader->program->release()); + Dialog3DGeneralSettings::updateParsedShaders(); + updateGL(); + +} // ------------------------------------------------------------------------------- // // POST PROCESSING TOOLS @@ -1050,7 +1170,7 @@ void GLWidget::resizeFBOs(){ if(auxFBO != NULL) delete auxFBO; auxFBO = new GLFrameBufferObject(width(),height()); - + // initializing/resizing glow FBOS for(int i = 0; i < 4 ; i++){ if(glowInputColor[i] != NULL) delete glowInputColor[i]; @@ -1058,6 +1178,11 @@ void GLWidget::resizeFBOs(){ glowInputColor[i] = new GLFrameBufferObject(width()/pow(2.0,i+1),height()/pow(2.0,i+1)); glowOutputColor[i] = new GLFrameBufferObject(width()/pow(2.0,i+1),height()/pow(2.0,i+1)); } + // initializing/resizing tone mapping FBOs + for(int i = 0; i < 10 ; i++){ + if(toneMipmaps[i] != NULL) delete toneMipmaps[i]; + toneMipmaps[i] = new GLFrameBufferObject(qMax(width()/pow(2.0,i+1),1.0),qMax(height()/pow(2.0,i+1),1.0)); + } } void GLWidget::deleteFBOs(){ @@ -1069,6 +1194,9 @@ void GLWidget::deleteFBOs(){ if(glowInputColor[i] != NULL) delete glowInputColor[i]; if(glowOutputColor[i] != NULL) delete glowOutputColor[i]; } + for(int i = 0; i < 10 ; i++){ + if(toneMipmaps[i] != NULL) delete toneMipmaps[i]; + } } void GLWidget::applyNormalFilter(GLuint input_tex){ @@ -1076,8 +1204,6 @@ void GLWidget::applyNormalFilter(GLuint input_tex){ filter_program = post_processing_programs["NORMAL_FILTER"]; filter_program->bind(); GLCHK( glViewport(0,0,width(),height()) ); - //GLCHK( glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &subroutines["mode_normal_filter"]) ); - GLCHK( filter_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) ); GLCHK( filter_program->setUniformValue("quad_pos" , QVector2D(0.0,0.0)) ); GLCHK( glActiveTexture(GL_TEXTURE0) ); @@ -1094,7 +1220,6 @@ void GLWidget::copyTexToFBO(GLuint input_tex,QGLFramebufferObject* dst){ filter_program->bind(); dst->bind(); GLCHK( glViewport(0,0,dst->width(),dst->height()) ); - // GLCHK( glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &subroutines["mode_normal_filter"]) ); GLCHK( filter_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) ); GLCHK( filter_program->setUniformValue("quad_pos" , QVector2D(0.0,0.0)) ); GLCHK( glActiveTexture(GL_TEXTURE0) ); @@ -1139,15 +1264,30 @@ void GLWidget::applyGaussFilter( GLuint input_tex, void GLWidget::applyDofFilter(GLuint input_tex, QGLFramebufferObject* outputFBO){ - //applyGaussFilter(input_tex,auxFBO,outputFBO,15.0); + // Skip processing if effect is disabled + if(!settings3D->DOF.EnableEffect) return; filter_program = post_processing_programs["DOF_FILTER"]; filter_program->bind(); GLCHK( glViewport(0,0,outputFBO->width(),outputFBO->height()) ); - // GLCHK( glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &subroutines["mode_dof_filter"]) ); + GLCHK( filter_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) ); GLCHK( filter_program->setUniformValue("quad_pos" , QVector2D(0.0,0.0)) ); + GLCHK( filter_program->setUniformValue("dof_FocalLenght", settings3D->DOF.FocalLenght ) ); + GLCHK( filter_program->setUniformValue("dof_FocalDepth" , settings3D->DOF.FocalDepth ) ); + GLCHK( filter_program->setUniformValue("dof_FocalStop" , settings3D->DOF.FocalStop ) ); + GLCHK( filter_program->setUniformValue("dof_NoSamples" , settings3D->DOF.NoSamples ) ); + GLCHK( filter_program->setUniformValue("dof_NoRings" , settings3D->DOF.NoRings ) ); + GLCHK( filter_program->setUniformValue("dof_bNoise" , settings3D->DOF.Noise ) ); + GLCHK( filter_program->setUniformValue("dof_Coc" , settings3D->DOF.Coc ) ); + GLCHK( filter_program->setUniformValue("dof_Threshold" , settings3D->DOF.Threshold ) ); + GLCHK( filter_program->setUniformValue("dof_Gain" , settings3D->DOF.Gain ) ); + GLCHK( filter_program->setUniformValue("dof_BokehBias" , settings3D->DOF.BokehBias ) ); + GLCHK( filter_program->setUniformValue("dof_BokehFringe", settings3D->DOF.BokehFringe ) ); + GLCHK( filter_program->setUniformValue("dof_DitherAmount", (float)settings3D->DOF.DitherAmount ) ); + + GLCHK( glActiveTexture(GL_TEXTURE0) ); GLCHK( glBindTexture(GL_TEXTURE_2D, input_tex) ); GLCHK( glActiveTexture(GL_TEXTURE1) ); @@ -1157,22 +1297,21 @@ void GLWidget::applyDofFilter(GLuint input_tex, outputFBO->bind(); quad_mesh->drawMesh(true); outputFBO->bindDefault(); - GLCHK( glActiveTexture(GL_TEXTURE0) ); - + copyTexToFBO(outputFBO->texture(),colorFBO->fbo); + GLCHK( glActiveTexture(GL_TEXTURE0) ); } void GLWidget::applyGlowFilter(QGLFramebufferObject* outputFBO){ - - + // Skip processing if effect is disabled + if(!settings3D->Bloom.EnableEffect) return; applyGaussFilter(colorFBO->getAttachedTexture(1),glowInputColor[0]->fbo,glowOutputColor[0]->fbo); applyGaussFilter(glowOutputColor[0]->fbo->texture(),glowInputColor[0]->fbo,glowOutputColor[0]->fbo); - applyGaussFilter(glowOutputColor[0]->fbo->texture(),glowInputColor[1]->fbo,glowOutputColor[1]->fbo); applyGaussFilter(glowOutputColor[1]->fbo->texture(),glowInputColor[1]->fbo,glowOutputColor[1]->fbo); @@ -1187,9 +1326,16 @@ void GLWidget::applyGlowFilter(QGLFramebufferObject* outputFBO){ outputFBO->bind(); GLCHK( glViewport(0,0,outputFBO->width(),outputFBO->height()) ); - // GLCHK( glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &subroutines["mode_bloom_filter"]) ); + GLCHK( filter_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) ); GLCHK( filter_program->setUniformValue("quad_pos" , QVector2D(0.0,0.0)) ); + GLCHK( filter_program->setUniformValue("bloom_WeightA" , settings3D->Bloom.WeightA ) ); + GLCHK( filter_program->setUniformValue("bloom_WeightB" , settings3D->Bloom.WeightB ) ); + GLCHK( filter_program->setUniformValue("bloom_WeightB" , settings3D->Bloom.WeightC ) ); + GLCHK( filter_program->setUniformValue("bloom_WeightC" , settings3D->Bloom.WeightD ) ); + GLCHK( filter_program->setUniformValue("bloom_Vignette" , settings3D->Bloom.Vignette ) ); + GLCHK( filter_program->setUniformValue("bloom_VignetteAtt", settings3D->Bloom.VignetteAtt ) ); + GLCHK( glActiveTexture(GL_TEXTURE0) ); GLCHK( glBindTexture(GL_TEXTURE_2D, colorFBO->fbo->texture()) ); GLCHK( glActiveTexture(GL_TEXTURE1) ); @@ -1204,31 +1350,79 @@ void GLWidget::applyGlowFilter(QGLFramebufferObject* outputFBO){ GLCHK( glActiveTexture(GL_TEXTURE0) ); outputFBO->bindDefault(); + // copy obtained result to main FBO + copyTexToFBO(outputFBO->texture(),colorFBO->fbo); } void GLWidget::applyToneFilter(GLuint input_tex,QGLFramebufferObject* outputFBO){ + // Skip processing if effect is disabled + if(!settings3D->ToneMapping.EnableEffect) return; filter_program = post_processing_programs["TONE_MAPPING_FILTER"]; filter_program->bind(); + + // 1. Step calculate luminance of each pixel outputFBO->bind(); GLCHK( glViewport(0,0,outputFBO->width(),outputFBO->height()) ); - GLCHK( filter_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) ); + GLCHK( filter_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) ); GLCHK( filter_program->setUniformValue("quad_pos" , QVector2D(0.0,0.0)) ); + GLCHK( filter_program->setUniformValue("tm_step", 1 ) ); + + GLCHK( filter_program->setUniformValue("tm_Delta" , settings3D->ToneMapping.Delta ) ); + GLCHK( filter_program->setUniformValue("tm_Scale" , settings3D->ToneMapping.Scale ) ); + GLCHK( filter_program->setUniformValue("tm_LumMaxWhite" , settings3D->ToneMapping.LumMaxWhite ) ); + GLCHK( filter_program->setUniformValue("tm_GammaCorrection" , settings3D->ToneMapping.GammaCorrection ) ); + GLCHK( filter_program->setUniformValue("tm_BlendingWeight" , settings3D->ToneMapping.BlendingWeight ) ); GLCHK( glActiveTexture(GL_TEXTURE0) ); GLCHK( glBindTexture(GL_TEXTURE_2D, input_tex) ); + + quad_mesh->drawMesh(true); + outputFBO->bindDefault(); + + // 2. Caclulating averaged luminance of image + GLuint averagedTexID = outputFBO->texture(); + GLCHK( filter_program->setUniformValue("tm_step", 2 ) ); + for(int i = 0 ; i < 10 ; i++){ + + toneMipmaps[i]->fbo->bind(); + GLCHK( glViewport(0,0,toneMipmaps[i]->fbo->width(),toneMipmaps[i]->fbo->height()) ); + GLCHK( glActiveTexture(GL_TEXTURE0) ); + GLCHK( glBindTexture(GL_TEXTURE_2D, averagedTexID) ); + + quad_mesh->drawMesh(true); + averagedTexID = toneMipmaps[i]->fbo->texture(); + } + + // 3. Step. + outputFBO->bind(); + GLCHK( glViewport(0,0,outputFBO->width(),outputFBO->height()) ); + GLCHK( filter_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) ); + GLCHK( filter_program->setUniformValue("quad_pos" , QVector2D(0.0,0.0)) ); + GLCHK( filter_program->setUniformValue("tm_step", 3 ) ); + + GLCHK( glActiveTexture(GL_TEXTURE0) ); + GLCHK( glBindTexture(GL_TEXTURE_2D, averagedTexID) ); + GLCHK( glActiveTexture(GL_TEXTURE1) ); - GLCHK( glBindTexture(GL_TEXTURE_2D, glowOutputColor[3]->fbo->texture()) ); + GLCHK( glBindTexture(GL_TEXTURE_2D, input_tex) ); + quad_mesh->drawMesh(true); outputFBO->bindDefault(); GLCHK( glActiveTexture(GL_TEXTURE0) ); + // Copy result to Color FBO + copyTexToFBO(outputFBO->texture(),colorFBO->fbo); } void GLWidget::applyLensFlaresFilter(GLuint input_tex,QGLFramebufferObject* outputFBO){ + + // Skip processing if effect is disabled + if(!settings3D->Flares.EnableEffect) return; + // Based on: http://john-chapman-graphics.blogspot.com/2013/02/pseudo-lens-flare.html // prepare mask image - if(!display3Dparameters.bBloomEffect){ + if(!display3Dparameters.bBloomEffect || !settings3D->Bloom.EnableEffect){ applyGaussFilter(colorFBO->getAttachedTexture(1),glowInputColor[0]->fbo,glowOutputColor[0]->fbo); applyGaussFilter(glowOutputColor[0]->fbo->texture(),glowInputColor[0]->fbo,glowOutputColor[0]->fbo); } @@ -1237,6 +1431,12 @@ void GLWidget::applyLensFlaresFilter(GLuint input_tex,QGLFramebufferObject* outp filter_program->bind(); // First step -- prepare treshold image + GLCHK( filter_program->setUniformValue("lf_NoSamples" , settings3D->Flares.NoSamples ) ); + GLCHK( filter_program->setUniformValue("lf_Dispersal" , settings3D->Flares.Dispersal ) ); + GLCHK( filter_program->setUniformValue("lf_HaloWidth" , settings3D->Flares.HaloWidth ) ); + GLCHK( filter_program->setUniformValue("lf_Distortion" , settings3D->Flares.Distortion ) ); + GLCHK( filter_program->setUniformValue("lf_weightLF" , settings3D->Flares.weightLF ) ); + glowInputColor[0]->fbo->bind(); GLCHK( glViewport(0,0,glowInputColor[0]->fbo->width(),glowInputColor[0]->fbo->height()) ); @@ -1314,6 +1514,6 @@ void GLWidget::applyLensFlaresFilter(GLuint input_tex,QGLFramebufferObject* outp GLCHK( glActiveTexture(GL_TEXTURE4) ); GLCHK( glBindTexture(GL_TEXTURE_2D, glowOutputColor[3]->fbo->texture()) ); // exposure reference quad_mesh->drawMesh(true); - + copyTexToFBO(outputFBO->texture(),colorFBO->fbo); GLCHK( glActiveTexture(GL_TEXTURE0) ); } diff --git a/Sources/glwidget.h b/Sources/glwidget.h index b5d140d..8ce310e 100644 --- a/Sources/glwidget.h +++ b/Sources/glwidget.h @@ -51,6 +51,13 @@ #include "utils/qglbuffers.h" #include "glwidgetbase.h" #include "glimageeditor.h" +#include "properties/Dialog3DGeneralSettings.h" +#include "utils/glslshaderparser.h" + +#define settings3D Dialog3DGeneralSettings::settings3D +#define currentShader Dialog3DGeneralSettings::currentRenderShader +#define glslShadersList Dialog3DGeneralSettings::glslParsedShaders + #ifdef USE_OPENGL_330 #include @@ -97,7 +104,7 @@ public slots: // pbr functions void chooseSkyBox(QString cubeMapName, bool bFirstTime = false); void updatePerformanceSettings(Display3DSettings settings); - + void recompileRenderShader(); // read and compile custom fragment shader again, can be called from 3D settings GUI. signals: void renderGL(); @@ -127,7 +134,7 @@ public slots: QVector4D& objectCoordinate); void bakeEnviromentalMaps(); // calculate prefiltered enviromental map - QOpenGLShaderProgram *program; + QOpenGLShaderProgram *line_program; // same as "program" but instead of triangles lines are used QOpenGLShaderProgram *skybox_program; QOpenGLShaderProgram *env_program; @@ -185,6 +192,8 @@ public slots: // glow FBOs GLFrameBufferObject* glowInputColor[4]; GLFrameBufferObject* glowOutputColor[4]; + // tone mapping mipmaps FBOS + GLFrameBufferObject* toneMipmaps[10]; GLuint lensFlareColorsTexture; GLuint lensDirtTexture; diff --git a/Sources/main.cpp b/Sources/main.cpp index aa9d095..a869c71 100644 --- a/Sources/main.cpp +++ b/Sources/main.cpp @@ -69,7 +69,7 @@ QString _find_data_dir(const QString& path) #else fpath = path; #endif - qDebug() << "fphath2:" << fpath; + return fpath; } @@ -193,9 +193,14 @@ int main(int argc, char *argv[]) #endif QGLFormat::setDefaultFormat(glFormat); - - - qInstallMessageHandler(customMessageHandler); + QSurfaceFormat format; + format.setDepthBufferSize(24); + format.setStencilBufferSize(8); + format.setVersion(4, 0); + format.setProfile(QSurfaceFormat::CoreProfile); + QSurfaceFormat::setDefaultFormat(format); + + //qInstallMessageHandler(customMessageHandler); qDebug() << "Starting application:"; if(!checkOpenGL()){ diff --git a/Sources/mainwindow.cpp b/Sources/mainwindow.cpp index 27aff9f..12baae6 100644 --- a/Sources/mainwindow.cpp +++ b/Sources/mainwindow.cpp @@ -24,6 +24,7 @@ MainWindow::MainWindow(QWidget *parent) : + connect(glImage,SIGNAL(rendered()),this,SLOT(initializeImages())); diffuseImageProp = new FormImageProp(this,glImage); @@ -58,7 +59,17 @@ MainWindow::MainWindow(QWidget *parent) : glWidget->setPointerToTexture(&roughnessImageProp->getImageProporties()->fbo,ROUGHNESS_TEXTURE); glWidget->setPointerToTexture(&metallicImageProp->getImageProporties()->fbo ,METALLIC_TEXTURE); glWidget->setPointerToTexture(&materialManager->getImageProporties()->fbo,MATERIAL_TEXTURE); - //glWidget->setPointerToTexture(&grungeImageProp->getImageProporties()->fbo,GRUNGE_TEXTURE); + + +// ab3dRendererWidget->setPointerToTexture(&diffuseImageProp->getImageProporties() ->fbo,DIFFUSE_TEXTURE); +// ab3dRendererWidget->setPointerToTexture(&normalImageProp->getImageProporties() ->fbo,NORMAL_TEXTURE); +// ab3dRendererWidget->setPointerToTexture(&specularImageProp->getImageProporties() ->fbo,SPECULAR_TEXTURE); +// ab3dRendererWidget->setPointerToTexture(&heightImageProp->getImageProporties() ->fbo,HEIGHT_TEXTURE); +// ab3dRendererWidget->setPointerToTexture(&occlusionImageProp->getImageProporties()->fbo,OCCLUSION_TEXTURE); +// ab3dRendererWidget->setPointerToTexture(&roughnessImageProp->getImageProporties()->fbo,ROUGHNESS_TEXTURE); +// ab3dRendererWidget->setPointerToTexture(&metallicImageProp->getImageProporties() ->fbo,METALLIC_TEXTURE); +// ab3dRendererWidget->setPointerToTexture(&materialManager->getImageProporties() ->fbo,MATERIAL_TEXTURE); + // Selecting type of image for each texture diffuseImageProp ->getImageProporties()->imageType = DIFFUSE_TEXTURE; @@ -187,12 +198,17 @@ MainWindow::MainWindow(QWidget *parent) : // 3D settings widget // ------------------------------------------------------- dock3Dsettings = new DockWidget3DSettings(this,glWidget); + ui->verticalLayout3DImage->addWidget(dock3Dsettings); setDockNestingEnabled(true); connect(dock3Dsettings,SIGNAL(signalSelectedShadingModel(int)),this,SLOT(selectShadingModel(int))); // show hide 3D settings connect(ui->pushButton3DSettings ,SIGNAL(toggled(bool)),dock3Dsettings,SLOT(setVisible(bool))); + dialog3dGeneralSettings = new Dialog3DGeneralSettings(this); + connect(ui->pushButton3DGeneralSettings,SIGNAL(released()),dialog3dGeneralSettings,SLOT(show())); + connect(dialog3dGeneralSettings,SIGNAL(signalPropertyChanged()),glWidget,SLOT(repaint())); + connect(dialog3dGeneralSettings,SIGNAL(signalRecompileCustomShader()),glWidget,SLOT(recompileRenderShader())); ui->verticalLayout3DImage->addWidget(glWidget); ui->verticalLayout2DImage->addWidget(glImage); @@ -475,7 +491,7 @@ MainWindow::MainWindow(QWidget *parent) : logAction = new QAction("Show log file",this); dialogLogger = new DialogLogger(this); dialogShortcuts = new DialogShortcuts(this); - dialogLogger->setModal(true); + //dialogLogger->setModal(true); dialogShortcuts->setModal(true); connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); @@ -502,6 +518,7 @@ MainWindow::~MainWindow() delete materialManager; delete settingsContainer; delete dock3Dsettings; + delete dialog3dGeneralSettings; delete diffuseImageProp; delete normalImageProp; delete specularImageProp; @@ -513,6 +530,7 @@ MainWindow::~MainWindow() delete statusLabel; delete glImage; + delete glWidget; delete ui; @@ -1369,8 +1387,8 @@ void MainWindow::updateSpinBoxes(int){ void MainWindow::selectShadingModel(int i){ - if(i == 0) ui->tabWidget->setTabText(5,"Roughness"); - if(i == 1) ui->tabWidget->setTabText(5,"Glossiness"); + if(i == 0) ui->tabWidget->setTabText(5,"Rgnss"); + if(i == 1) ui->tabWidget->setTabText(5,"Gloss"); } @@ -1827,6 +1845,7 @@ void MainWindow::showSettingsManager(){ settingsContainer->show(); } + void MainWindow::saveSettings(){ qDebug() << "Calling" << Q_FUNC_INFO << "Saving to :"<< QString(AB_INI); diff --git a/Sources/mainwindow.h b/Sources/mainwindow.h index 6458359..4e6a380 100644 --- a/Sources/mainwindow.h +++ b/Sources/mainwindow.h @@ -8,6 +8,7 @@ #include #include #include "glwidget.h" + #include "glimageeditor.h" #include "formimageprop.h" #include "formsettingscontainer.h" @@ -16,7 +17,10 @@ #include "dialoglogger.h" #include "dialogshortcuts.h" #include "dockwidget3dsettings.h" + #include "gpuinfo.h" +#include "Property.h" +#include "properties/Dialog3DGeneralSettings.h" namespace Ui { class MainWindow; @@ -56,7 +60,6 @@ public slots: // the same as above but Image is choosen by proper switch using the given type void loadImageSettings(TextureTypes type); void showSettingsManager(); - void setOutputFormat(int index); void replotAllImages(); @@ -131,6 +134,7 @@ public slots: // Pointers Ui::MainWindow *ui; GLWidget* glWidget; + GLImage* glImage; bool bSaveCheckedImages; @@ -155,6 +159,9 @@ public slots: // 3D settings manager DockWidget3DSettings *dock3Dsettings; + // 3D shading & display settings dialog + Dialog3DGeneralSettings* dialog3dGeneralSettings; + QAction *aboutQtAction; QAction *aboutAction; QAction *logAction; // show logger diff --git a/Sources/mainwindow.ui b/Sources/mainwindow.ui index f0e0b63..1093574 100644 --- a/Sources/mainwindow.ui +++ b/Sources/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 1529 - 617 + 1486 + 841 @@ -48,7 +48,7 @@ - 320 + 100 0 @@ -62,7 +62,7 @@ QTabWidget::East - 8 + 5 Qt::ElideMiddle @@ -74,8 +74,12 @@ 0 + + + :/resources/showDiffuse.png:/resources/showDiffuse.png + - Diffuse + Diffuse Image @@ -115,8 +119,8 @@ 0 0 - 96 - 26 + 449 + 768 @@ -148,8 +152,12 @@ 0 + + + :/resources/showNormal.png:/resources/showNormal.png + - Normal + Normal image @@ -189,8 +197,8 @@ 0 0 - 96 - 26 + 449 + 768 @@ -222,8 +230,12 @@ 0 + + + :/resources/showSpecular.png:/resources/showSpecular.png + - Specular + @@ -266,8 +278,8 @@ 0 0 - 96 - 26 + 449 + 768 @@ -299,8 +311,12 @@ 0 + + + :/resources/showHeight.png:/resources/showHeight.png + - Height + @@ -337,8 +353,8 @@ 0 0 - 96 - 26 + 449 + 768 @@ -370,8 +386,12 @@ 0 + + + :/resources/showOcclusion.png:/resources/showOcclusion.png + - Occlusion + @@ -408,8 +428,8 @@ 0 0 - 96 - 26 + 449 + 768 @@ -441,8 +461,12 @@ 0 + + + :/resources/showRoughness.png:/resources/showRoughness.png + - Roughness + Rgnss @@ -476,8 +500,8 @@ 0 0 - 96 - 26 + 449 + 768 @@ -509,8 +533,12 @@ 0 + + + :/resources/showMetallic.png:/resources/showMetallic.png + - Metallic + @@ -550,8 +578,8 @@ 0 0 - 96 - 26 + 449 + 768 @@ -577,8 +605,12 @@ + + + :/resources/showMaterials.png:/resources/showMaterials.png + - Materials + @@ -587,6 +619,9 @@ 2 + + 2 + 2 @@ -603,8 +638,8 @@ 0 0 - 87 - 24 + 447 + 766 @@ -636,10 +671,32 @@ + + + 0 + 0 + + + + + :/resources/showGrunge.png:/resources/showGrunge.png + - Grunge + + + 2 + + + 2 + + + 2 + + + 2 + @@ -651,10 +708,25 @@ 0 0 447 - 528 + 766 + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + @@ -666,7 +738,7 @@ - + 0 0 @@ -683,10 +755,14 @@ 16777215 + + + :/resources/showSettings.png:/resources/showSettings.png + - Output + - + 2 @@ -736,12 +812,12 @@ 0 0 - 376 - 761 + 449 + 722 - + 0 0 @@ -752,23 +828,26 @@ 16777215 - + + + 2 + - 0 + 2 - 0 + 2 - 0 + 2 - 0 + 2 - + 0 0 @@ -782,7 +861,10 @@ Image settings - + + + 2 + 2 @@ -1148,7 +1230,7 @@ - + 0 0 @@ -1168,7 +1250,10 @@ Save settings - + + + 3 + 2 @@ -1448,20 +1533,33 @@ - - - + + + - + 0 0 - - - 0 - 0 - + + + + + Height image postfix + + + _h + + + + + + + + 0 + 0 + @@ -1473,31 +1571,34 @@ - :/resources/showMetallic.png + :/resources/showOcclusion.png true - - + + 0 0 + + + - Metallic postfix + Ambient occlusion postfix - _m + _o - - + + 0 @@ -1514,40 +1615,27 @@ - :/resources/showDiffuse.png + :/resources/showSpecular.png true - - - - - 0 - 0 - - - - - - - Diffuse image postfix - - - _d - - - - - + + 0 0 + + + 0 + 0 + + 26 @@ -1558,34 +1646,31 @@ - :/resources/showSpecular.png + :/resources/showRoughness.png true - - + + 0 0 - - - - Specular image postfix + Roughness postfix - _s + _r - - + + 0 @@ -1602,15 +1687,15 @@ - :/resources/showNormal.png + :/resources/showDiffuse.png true - - + + 0 @@ -1627,15 +1712,15 @@ - :/resources/showOcclusion.png + :/resources/showNormal.png true - - + + 0 @@ -1646,15 +1731,15 @@ - Ambient occlusion postfix + Normal image postfix - _o + _n - - + + 0 @@ -1665,10 +1750,29 @@ - Normal image postfix + Specular image postfix - _n + _s + + + + + + + + 0 + 0 + + + + + + + Diffuse image postfix + + + _d @@ -1697,27 +1801,8 @@ - - - - - 0 - 0 - - - - - - - Height image postfix - - - _h - - - - - + + 0 @@ -1740,15 +1825,15 @@ - :/resources/showRoughness.png + :/resources/showMetallic.png true - - + + 0 @@ -1756,10 +1841,10 @@ - Roughness postfix + Metallic postfix - _r + _m @@ -1826,76 +1911,33 @@ - - - - - 0 - 0 - - - - - 2000 - 16777215 - - - - GUI Style - - - - 2 - - - 2 - - - 2 - - - 2 - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - Select style, save and restart AB - - - - - - - - - + + + + 8 + + + 50 + + + + + + + Font size (in pixels) + + + + Mouse sensitivity - + 200 @@ -1905,20 +1947,26 @@ - - + + + + + 0 + 0 + + - Font size (in pixels) + GUI style (needs restart) - - - - 8 - - - 50 + + + + + 0 + 0 + @@ -2028,8 +2076,12 @@ 0 + + + :/resources/showUVs.png:/resources/showUVs.png + - UV/Tilling + @@ -2060,8 +2112,8 @@ 0 0 - 357 - 579 + 449 + 768 @@ -2681,6 +2733,29 @@ + + + + <html><head/><body><p>AB 3D rendering settings.</p></body></html> + + + + + + + :/resources/settings3d.png:/resources/settings3d.png + + + + 19 + 19 + + + + true + + + @@ -3024,7 +3099,7 @@ 0 0 - 1529 + 1486 25 diff --git a/Sources/properties/Dialog3DGeneralSettings.cpp b/Sources/properties/Dialog3DGeneralSettings.cpp new file mode 100644 index 0000000..0e19c34 --- /dev/null +++ b/Sources/properties/Dialog3DGeneralSettings.cpp @@ -0,0 +1,168 @@ +#include "Dialog3DGeneralSettings.h" +#include "ui_Dialog3DGeneralSettings.h" + +QtnPropertySetFilters3D* Dialog3DGeneralSettings::settings3D = NULL; +GLSLShaderParser* Dialog3DGeneralSettings::currentRenderShader = NULL; +GLSLParsedShaderContainer* Dialog3DGeneralSettings::glslParsedShaders = NULL; + +Dialog3DGeneralSettings::Dialog3DGeneralSettings(QWidget* parent) : + QDialog(parent), + ui(new Ui::PropertyDialog) +{ + ui->setupUi(this); + hide(); + ui->widget->setParts(QtnPropertyWidgetPartsDescriptionPanel); + + + QtnPropertySetFilters3D* settings = new QtnPropertySetFilters3D(this); + + settings3D = settings; + + ui->widget->setPropertySet(settings); + // --------------------------------------------------- + // Read settings from file + // --------------------------------------------------- + QFile file("Configs/settings3D.dat"); + file.open(QIODevice::ReadOnly); + if(file.isOpen()){ + QString property; + QTextStream outstream(&file); + property = outstream.readAll(); + settings3D->fromStr(property); + } + + connect(ui->pushButtonCancel,SIGNAL(pressed()),this,SLOT(cancelSettings())); + connect(ui->pushButtonOK ,SIGNAL(pressed()),this,SLOT(acceptSettings())); + connect(ui->pushButtonRecompileShaders,SIGNAL(released()),this,SLOT(recompileCustomShader())); + connect(settings,SIGNAL(propertyDidChange(const QtnPropertyBase*,const QtnPropertyBase*,QtnPropertyChangeReason)), + this,SLOT(propertyChanged(const QtnPropertyBase*,const QtnPropertyBase*,QtnPropertyChangeReason))); + + + glslParsedShaders = new GLSLParsedShaderContainer; // parse and creat list of avaiable shaders in Render folder + + // Create list of available shaders + QStringList shaderList; + for(int i = 0 ; i < glslParsedShaders->glslParsedShaders.size(); i++){ + shaderList << glslParsedShaders->glslParsedShaders.at(i)->shaderName; + } + ui->comboBoxShadersList->addItems(shaderList); + // Setup pointer and comboBox + int lastIndex = settings->ParsedShader.LastShaderIndex.value(); + ui->comboBoxShadersList->setCurrentIndex(lastIndex); + currentRenderShader = glslParsedShaders->glslParsedShaders[lastIndex]; + + connect(ui->comboBoxShadersList,SIGNAL(currentIndexChanged(int)),this,SLOT(shaderChanged(int))); + +} + +void Dialog3DGeneralSettings::propertyChanged(const QtnPropertyBase* changedProperty, + const QtnPropertyBase* firedProperty, + QtnPropertyChangeReason reason){ + if (reason & QtnPropertyChangeReasonValue){ + emit signalPropertyChanged(); + } +} + +void Dialog3DGeneralSettings::recompileCustomShader(){ + emit signalRecompileCustomShader(); +} + +void Dialog3DGeneralSettings::shaderChanged(int index){ + currentRenderShader = glslParsedShaders->glslParsedShaders[index]; + updateParsedShaders(); + emit signalPropertyChanged(); +} + +// Each time button ok is pressed the settings are saved +// to local file. This file is used during the application +// initialization to load last settings. +void Dialog3DGeneralSettings::closeEvent(QCloseEvent *event){ + cancelSettings(); +} + +void Dialog3DGeneralSettings::show(){ + QtnPropertySet* properties = ui->widget->propertySet(); + // copy of properties + cpyPropertySet = properties->createCopy(this); + Q_ASSERT(cpyPropertySet); + this->showNormal(); +} + +void Dialog3DGeneralSettings::cancelSettings(){ + this->reject(); + QtnPropertySet* properties = ui->widget->propertySet(); + properties->copyValues(cpyPropertySet, QtnPropertyStateInvisible); +} +void Dialog3DGeneralSettings::acceptSettings(){ + this->accept(); + saveSettings(); +} + +void Dialog3DGeneralSettings::saveSettings(){ + QFile file("Configs/settings3D.dat"); + file.open(QIODevice::WriteOnly); + QString property; + settings3D->ParsedShader.LastShaderIndex.setValue(ui->comboBoxShadersList->currentIndex()); + settings3D->toStr(property); + QTextStream outstream(&file); + outstream << property; +} + +void Dialog3DGeneralSettings::updateParsedShaders(){ + GLSLShaderParser* parsedShader = currentRenderShader; + int maxParams = settings3D->ParsedShader.MaxParams; + int noParsedParams = parsedShader->uniforms.size(); + // Check if parsed number uniform is greater than supported number of params + // if YES display warning message. + if(noParsedParams > maxParams){ + QMessageBox msgBox; + msgBox.setText("Error!"); + msgBox.setInformativeText("Custom shader with name:"+parsedShader->shaderName+ + " has more than maxiumum allowed number of user-defined uniforms. \n"+ + "Current number of parameters:"+QString::number(noParsedParams)+".\n"+ + "Supported number:"+QString::number(maxParams)+".\n"+ + "Custom shader has been linked but may not work properly."); + msgBox.setStandardButtons(QMessageBox::Cancel); + msgBox.exec(); + return; + } + // hide all by default + for(int i = 0 ; i < maxParams ; i++) { + QtnPropertyFloat* p = (QtnPropertyFloat*)(settings3D->ParsedShader.findChildProperty(i+1)); + p->switchState(QtnPropertyStateInvisible,true); + } + + // update property set based on parsed fragment shader + for(int i = 0 ; i < qMin(noParsedParams,maxParams) ; i++){ + QtnPropertyFloat* p = (QtnPropertyFloat*)(settings3D->ParsedShader.findChildProperty(i+1)); + UniformData& uniform = parsedShader->uniforms[i]; + p->switchState(QtnPropertyStateInvisible,false); + p->setDescription(uniform.description); + p->setName(uniform.name); + p->setValue(uniform.value); + p->setMaxValue(uniform.max); + p->setMinValue(uniform.min); + p->setStepValue(uniform.step); + } +} + +void Dialog3DGeneralSettings::setUniforms(){ + GLSLShaderParser* parsedShader = currentRenderShader; + int maxParams = settings3D->ParsedShader.MaxParams; + int noParsedParams = parsedShader->uniforms.size(); + // update property set based on parsed fragment shader + for(int i = 0 ; i < qMin(noParsedParams,maxParams) ; i++){ + QtnPropertyFloat* p = (QtnPropertyFloat*)(settings3D->ParsedShader.findChildProperty(i+1)); + UniformData& uniform = parsedShader->uniforms[i]; + uniform.value = (float)p->value(); + } + parsedShader->setParsedUniforms(); +} + +Dialog3DGeneralSettings::~Dialog3DGeneralSettings() +{ + settings3D = NULL; + delete glslParsedShaders; + glslParsedShaders = NULL; + delete ui; +} diff --git a/Sources/properties/Dialog3DGeneralSettings.h b/Sources/properties/Dialog3DGeneralSettings.h new file mode 100644 index 0000000..a506505 --- /dev/null +++ b/Sources/properties/Dialog3DGeneralSettings.h @@ -0,0 +1,50 @@ +#ifndef MYDIALOG_H +#define MYDIALOG_H + +#include +#include +#include +#include + +#include "Filters3D.peg.h" +#include "utils/glslshaderparser.h" +#include "utils/glslparsedshadercontainer.h" + +namespace Ui { +class PropertyDialog; +} + +class Dialog3DGeneralSettings : public QDialog +{ + Q_OBJECT + +public: + Dialog3DGeneralSettings(QWidget* parent); + ~Dialog3DGeneralSettings(); + void closeEvent(QCloseEvent* event); + + void saveSettings(); // save current properties to file +public slots: + void show(); // opens settings window + void cancelSettings(); // restore last settings when window is cancelled + void acceptSettings(); // save current settings to file when OK button is pressed + void propertyChanged(const QtnPropertyBase*changedProperty, const QtnPropertyBase*firedProperty, QtnPropertyChangeReason reason); + void recompileCustomShader(); + void shaderChanged(int index); + static void updateParsedShaders(); + static void setUniforms(); +signals: + void signalPropertyChanged(); + void signalRecompileCustomShader(); +private: + QtnPropertyDelegateInfo delegate; + Ui::PropertyDialog *ui; + QtnPropertySet* cpyPropertySet;//keeps last settings before window was open +public: + static QtnPropertySetFilters3D* settings3D; + static GLSLShaderParser* currentRenderShader; + static GLSLParsedShaderContainer* glslParsedShaders; + +}; + +#endif // MYDIALOG_H diff --git a/Sources/properties/Dialog3DGeneralSettings.ui b/Sources/properties/Dialog3DGeneralSettings.ui new file mode 100644 index 0000000..7a30c48 --- /dev/null +++ b/Sources/properties/Dialog3DGeneralSettings.ui @@ -0,0 +1,145 @@ + + + PropertyDialog + + + + 0 + 0 + 328 + 532 + + + + Rendering settings + + + false + + + false + + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + 0 + 0 + + + + + + + + + + + 0 + 0 + + + + Select rendering shader + + + + + + + + 24 + 16777215 + + + + <html><head/><body><p>Recompile current shader. If there were errors in custom shader you may try to fix them manualy and compile&amp;link shaders again.</p></body></html> + + + + + + + :/resources/recompileShader.png:/resources/recompileShader.png + + + + 16 + 16 + + + + false + + + + + + + + 0 + 0 + + + + + + + + + + + + + QLayout::SetDefaultConstraint + + + + + <html><head/><body><p>Settings will be restored previous ones.</p></body></html> + + + Cancel + + + + + + + <html><head/><body><p>Save current settings. Those settings will be loaded next time you start AB.</p></body></html> + + + OK + + + + + + + + + + QtnPropertyWidget + QWidget +
PropertyWidget.h
+ 1 +
+
+ + + + +
diff --git a/Sources/properties/Filter3DBloom.pef b/Sources/properties/Filter3DBloom.pef new file mode 100644 index 0000000..a5a20b5 --- /dev/null +++ b/Sources/properties/Filter3DBloom.pef @@ -0,0 +1,70 @@ +#include "../Core/PropertyCore.h" +#include "../Core/PropertyGUI.h" + + +property_set Filter3DBloom +{ + Bool EnableEffect + { + description = "EnableEffect"; + name = "Enable Bloom"; + value = true; + } + Float WeightA + { + description = "Weight of Layer A."; + name = "Layer A"; + value = 0.25; + minValue = 0.0; + maxValue = 1.0; + stepValue = 0.01; + } + Float WeightB + { + description = "Weight of Layer B"; + name = "Layer B"; + value = 0.25; + minValue = 0.0; + maxValue = 1.0; + stepValue = 0.01; + } + Float WeightC + { + description = "Weight of Layer C"; + name = "Layer C"; + value = 0.25; + minValue = 0.0; + maxValue = 1.0; + stepValue = 0.01; + } + Float WeightD + { + description = "Weight of Layer D"; + name = "Layer D"; + value = 0.25; + minValue = 0.0; + maxValue = 1.0; + stepValue = 0.01; + } + + Float Vignette + { + description = "Vignette size"; + name = "Vignette size"; + value = 0.4; + minValue = 0.0; + maxValue = 1.0; + stepValue = 0.01; + } + + Float VignetteAtt + { + description = "Vignette attenuation"; + name = "Vignette attenuation"; + value = 0.8; + minValue = 0.0; + maxValue = 1.0; + stepValue = 0.01; + } + +} diff --git a/Sources/properties/Filter3DDOF.pef b/Sources/properties/Filter3DDOF.pef new file mode 100644 index 0000000..a29246f --- /dev/null +++ b/Sources/properties/Filter3DDOF.pef @@ -0,0 +1,127 @@ +#include "../Core/PropertyCore.h" +#include "../Core/PropertyGUI.h" + + +property_set Filter3DDOF +{ + Bool EnableEffect + { + description = "EnableEffect"; + name = "Enable DOF"; + value = true; + } + Float FocalLenght + { + description = "Focal length in mm"; + name = "Focal Lenght"; + value = 25.0; + minValue = 0; + maxValue = 100; + stepValue = 1.0; + + } + + Float FocalDepth + { + description = "Focal distance value in meters, but you may use autofocus option below"; + value = 10.0; + minValue = 0; + maxValue = 100; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // not used in GUI + } + + Float FocalStop + { + description = "f-stop value"; + name = "f-stop"; + value = 140.0; + minValue = 0; + maxValue = 400; + stepValue = 2.0; + } + + Int NoSamples + { + description = "Number of samples on the first ring"; + name = "Num. samples"; + value = 4; + minValue = 1; + maxValue = 20; + stepValue = 1; + } + + Int NoRings + { + description = "Number of rings"; + name = "Num. rings"; + value = 7; + minValue = 1; + maxValue = 20; + stepValue = 1; + } + + Bool Noise + { + description = "Use noise instead of pattern for sample dithering"; + value = false; + } + + Float Coc + { + description = "Circle of confusion size in mm (35mm film = 0.03mm)"; + name = "Confusion circle"; + value = 0.03; + minValue = 0.0; + maxValue = 0.1; + stepValue = 0.001; + } + + Float Threshold + { + description = "Highlight threshold"; + value = 0.25; + minValue = 0.0; + maxValue = 2.0; + stepValue = 0.01; + } + + Float Gain + { + description = "Highlight gain"; + value = 1.0; + minValue = 0.0; + maxValue = 1.0; + stepValue = 0.01; + } + + Float BokehBias + { + description = "Bokeh edge bias"; + name = "Bokeh bias"; + value = 0.25; + minValue = 0.0; + maxValue = 5.0; + stepValue = 0.01; + } + + Float BokehFringe + { + description = "Bokeh chromatic aberration/fringing"; + name = "Fringing"; + value = 0.7; + minValue = 0.0; + maxValue = 5.0; + stepValue = 0.01; + } + + Double DitherAmount + { + description = "Dither amount"; + name = "Dither amount"; + value = 0.0001; + minValue = 0.0; + maxValue = 0.001; + stepValue = 0.00001; + } +} diff --git a/Sources/properties/Filter3DLensFlares.pef b/Sources/properties/Filter3DLensFlares.pef new file mode 100644 index 0000000..9eae0af --- /dev/null +++ b/Sources/properties/Filter3DLensFlares.pef @@ -0,0 +1,59 @@ +#include "../Core/PropertyCore.h" +#include "../Core/PropertyGUI.h" + +property_set Filter3DLensFlares +{ + Bool EnableEffect + { + description = "EnableEffect"; + name = "Enable Lens Flares"; + value = true; + } + Int NoSamples + { + description = "Number of samples"; + name = "Num. samples"; + value = 8; + minValue = 1; + maxValue = 20; + stepValue = 1; + } + Float Dispersal + { + description = "Dispersal"; + name = "Dispersal"; + value = 0.25; + minValue = 0.0; + maxValue = 5.0; + stepValue = 0.05; + } + Float HaloWidth + { + description = "Halo width"; + name = "Halo width"; + value = 0.5; + minValue = 0.0; + maxValue = 1.0; + stepValue = 0.05; + } + Float Distortion + { + description = "Distortion"; + name = "Distortion"; + value = 1.0; + minValue = 0.0; + maxValue = 10.0; + stepValue = 1.0; + } + + Float weightLF + { + description = "Effect strength"; + name = "Strength"; + value =10.0; + minValue = 0.0; + maxValue =50.0; + stepValue = 0.5; + + } +} diff --git a/Sources/properties/Filter3DToneMapping.pef b/Sources/properties/Filter3DToneMapping.pef new file mode 100644 index 0000000..09050f0 --- /dev/null +++ b/Sources/properties/Filter3DToneMapping.pef @@ -0,0 +1,61 @@ +#include "../Core/PropertyCore.h" +#include "../Core/PropertyGUI.h" + + +property_set Filter3DToneMapping +{ + Bool EnableEffect + { + description = "EnableEffect"; + name = "Enable Reinhard tone mapping."; + value = true; + } + + Float Delta + { + description = "Logarithm offset"; + name = "Delta"; + value = 1.0; + minValue = 0.01; + maxValue = 1.0; + stepValue = 0.01; + } + Float Scale + { + description = "Parameter that scales the exposure of the pixel. Small values (0.0 to 0.2) will underexpose the image and higher values (0.5 to 1.0) will tend to overexpose the image."; + name = "Scale"; + value = 0.5; + minValue = 0.0; + maxValue = 2.0; + stepValue = 0.01; + } + Float LumMaxWhite + { + description = "It is the smallest luminance that will be mapped to pure white."; + name = "Max. white"; + value = 1.0; + minValue = 0.0; + maxValue = 5.0; + stepValue = 0.01; + } + + Float GammaCorrection + { + description = "Gamma correction"; + name = "Gamma"; + value = 0.6; + minValue = 0.0; + maxValue = 1.5; + stepValue = 0.01; + } + + Float BlendingWeight + { + description = "Performe mixing between oryginal image and tonned one. Weight=0 restores oryginal image."; + name = "Weight"; + value = 0.8; + minValue = 0.0; + maxValue = 1.0; + stepValue = 0.01; + } +} diff --git a/Sources/properties/Filters3D.pef b/Sources/properties/Filters3D.pef new file mode 100644 index 0000000..877e863 --- /dev/null +++ b/Sources/properties/Filters3D.pef @@ -0,0 +1,67 @@ +#include "../Core/PropertyCore.h" +#include "../Core/PropertyGUI.h" + +#include "Filter3DBloom.peg.h" +#include "Filter3DDOF.peg.h" +#include "Filter3DLensFlares.peg.h" +#include "Filter3DToneMapping.peg.h" +#include "GLSLParsedFragShader.peg.h" + + +property_set Filters3D +{ + + extern property_set Filter3DDOF DOF + { + description = "" + "GLSL depth of field with bokeh v2.4 implementation based on:" + "Martins Upitis shader
" + ""; + name = "Depth of Field"; + state = QtnPropertyStateCollapsed; + } + extern property_set Filter3DBloom Bloom + { + description = "Glow effect."; + name = "Glow"; + state = QtnPropertyStateCollapsed; + } + extern property_set Filter3DLensFlares Flares + { + description = "" + "Lens flares effect based on " + "John Chapman article.
" + ""; + name = "Pseudo lens flares."; + state = QtnPropertyStateCollapsed; + } + extern property_set Filter3DToneMapping ToneMapping + { + description = "" + "Minimal version of Reinhard's tone mapping algorithm based on " + "Nutty Shell article.
" + ""; + name = "Reinhard's tone mapping"; + state = QtnPropertyStateCollapsed; + } + + + extern property_set GLSLParsedFragShader ParsedShader + { + description = "AwesomeBump engine can be supplied with " + "custom GLSL fragment shader in order to " + "customize 3D render output to your engine." + "In order to make " + "custom fragment shader you must create a new " + ".frag file in Core/Render folder. Created file " + "will be then parsed during the initialization process." + "See Template.frag file to undersdand how this shader " + "should be written in order to be compatible with AB." + "Note: Saving option does not work for this feature, thus " + "all the settings has to be defined in your *.frag file."; + name = "Custom rednder settings"; + state = QtnPropertyStateCollapsed; + } + + +} diff --git a/Sources/properties/GLSLParsedFragShader.pef b/Sources/properties/GLSLParsedFragShader.pef new file mode 100644 index 0000000..13b09b4 --- /dev/null +++ b/Sources/properties/GLSLParsedFragShader.pef @@ -0,0 +1,218 @@ +#include "../Core/PropertyCore.h" +#include "../Core/PropertyGUI.h" + + +property_set GLSLParsedFragShader +{ + + Int MaxParams + { + value = 10; + state = QtnPropertyStateInvisible; // by default not Used by user + } + Int LastShaderIndex // index of shader from combobox + { + value = 0; + state = QtnPropertyStateInvisible; // by default not Used by user + } + Float fParam1 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 1; + } + Float fParam2 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 2; + } + Float fParam3 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 3; + } + Float fParam4 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 4; + } + Float fParam5 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 5; + } + Float fParam6 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 6; + } + Float fParam7 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 7; + } + Float fParam8 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 8; + } + Float fParam9 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 9; + } + Float fParam10 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 10; + } + Float fParam11 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 11; + } + Float fParam12 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 12; + } + Float fParam13 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 13; + } + Float fParam14 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 14; + } + Float fParam15 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 15; + } + Float fParam16 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 16; + } + Float fParam17 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 17; + } + Float fParam18 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 18; + } + Float fParam19 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 19; + } + Float fParam20 + { + description = "None"; + value = 50.0; + minValue = 0.0; + maxValue = 100.0; + stepValue = 1.0; + state = QtnPropertyStateInvisible; // by default + id = 20; + } +} diff --git a/Sources/properties/ImageProperties.pef b/Sources/properties/ImageProperties.pef new file mode 100644 index 0000000..3785bad --- /dev/null +++ b/Sources/properties/ImageProperties.pef @@ -0,0 +1,814 @@ +#include "../Core/PropertyCore.h" +#include "../Core/PropertyGUI.h" + +#include_cpp + +enum COLOR +{ + red (1, "red"), + blue (2, "blue"), + green (3, "green") +} + +enum FLAGS +{ + opt1(1, "Option1"), + opt2(2, "Option2"), + opt3(4, "Option3") +} + +enum SHADINGMODEL +{ + pbr(0, "PBR shading"), + bumpMapping(1, "Bump mapping") +} + +enum BLENDINGMODE +{ + blendNormal(0, "Normal"), + blendMultiply(1, "Multiply"), + blendAdd(2, "Add"), + blendSubtract(3, "Subtract"), + blendDifference(4, "Difference"), + blendDivide(5, "Divide"), + blendScreen(6, "Screen"), + blendOverlay(7, "Overlay"), + blendDodge(8, "Dodge"), + blendBurn(9, "Burn"), + blendDarkenOnly(10, "Darken Only"), + blendLightenOnly(11, "Lighten Only") +} + +enum INPUTIMAGE +{ + inputCurrent(0, "Current image"), + inputHeightInput(1, "Height (Input)"), + inputHeightOutput(2, "Height (Output)") +} + +property_set ColorComponentsProperty{ + +Bool InvertAll { + description = "Invert all components"; + value=false; + + slot propertyDidChange + { + InvertRed.setValue(InvertAll.value()); + InvertBlue.setValue(InvertAll.value()); + InvertGreen.setValue(InvertAll.value()); + } +} + +Bool InvertRed { + description = "Invert red"; + value=false; +} + +Bool InvertBlue { + description = "Invert red"; + value=false; +} + +Bool InvertGreen { + description = "Invert red"; + value=false; +} + +} // end of color property + +property_set GrayScaleProperty{ + Bool EnableGrayScale { + description = "Enable"; + value=false; + + slot propertyDidChange + { + GrayScaleR.switchState(QtnPropertyStateInvisible, !EnableGrayScale); + GrayScaleG.switchState(QtnPropertyStateInvisible, !EnableGrayScale); + GrayScaleB.switchState(QtnPropertyStateInvisible, !EnableGrayScale); + } + } + + Float GrayScaleR { + description = ""; + minValue=0; + maxValue=255; + stepValue=1; + value=100; + } + Float GrayScaleG { + description = ""; + minValue=0; + maxValue=255; + stepValue=1; + value=100; + } + Float GrayScaleB { + description = ""; + minValue=0; + maxValue=255; + stepValue=1; + value=100; + } + +} + + +property_set BasicProperty +{ + +extern property_set GrayScaleProperty GrayScale +{ + description = "Gray scale "; + state = QtnPropertyStateCollapsed; +} + +extern property_set ColorComponentsProperty ColorComponents +{ + description = "Components "; + state = QtnPropertyStateCollapsed; +} + + +Float ColorHue { + description = "Change color Hue"; + minValue=0; + maxValue=1; + stepValue=0.01; + value=0; +} +Float EnhanceDetails { + description = "The same as above."; + minValue=0; + maxValue=10; + stepValue=1; + value=0; +} + +Float MediumDetails { + description = "The same as above."; + minValue=0; + maxValue=100; + stepValue=1; + value=0; +} +Float SmallDetails { + description = "

Enhance small details. This option is connected with Depth scroll bar.

Note that if Depth scroll bar is set to zero, this parameter does not affect the image.

< /body>"; + minValue=0; + maxValue=100; + stepValue=1; + value=0; +} +Float DetailDepth { + description = "

It changes the depth of the Small details and Medium details effect.

"; + minValue=0; + maxValue=100; + stepValue=1; + value=40; +} + +Float SharpenBlur { + description = "

Smooth or sharpen the image (it uses the gaussian distribution in both cases).

"; + minValue=-20; + maxValue=20; + stepValue=1; + value=0; +} + +} // end of BasicProperty + +property_set FormImageProp +{ + + extern property_set BasicProperty Basic + { + description = "Basic "; + state = !QtnPropertyStateCollapsed; + } +/* + Int GrungeRadius { + description = "

It scales the UVs of generated random image. Value 1 is neutral.

"; + minValue=1; + maxValue=100; + stepValue=0; + value=1; + } + Int GrungeOverallWeight { + description = "

Set common blending weight factor for all textures blending.

"; + minValue=0; + maxValue=100; + stepValue=0; + value=0; + } + Int GrungeSeed { + description = "

When 0 - use orginal image, otherwise generate random seamless image.

"; + minValue=0; + maxValue=100; + stepValue=0; + value=0; + } + Int GrungeNormalWarp { + description = "

Warps grunge texture pixels along normals of normal texture.

"; + minValue=-100; + maxValue=100; + stepValue=0; + value=0; + } + Int GrungeImageWeight { + description = "

This is blending factor for grunge image. 0 - no grunge.

"; + minValue=0; + maxValue=100; + stepValue=0; + value=0; + } + Int GrungeMainImageWeight { + description = "

This is blending factor for this image. 0 - no grunge.

< /body>"; + minValue=0; + maxValue=100; + stepValue=0; + value=0; + } + Int ConversionHNDepth { + description = "

It changes the depth of the calculated normal map in pixels unit.

For example: lets assume that you have picture of wall of size 1x1 m2 in real world with bricks pattern and your image has size 1024x1024 pixels. Then you want to generate normals for texture which depth is 3cm = 0.03 m. So the depth in pixels is 0.03*1024 = 30.72 ~ 31 pixels.

"; + minValue=0; + maxValue=500; + stepValue=1; + value=20; + } + Int NormalMixerAngle { + description = ""; + minValue=-180; + maxValue=99; + stepValue=0; + value=0; + } + Int NormalMixerScale { + description = ""; + minValue=0; + maxValue=100; + stepValue=0; + value=10; + } + Int NormalMixerPosX { + description = ""; + minValue=-100; + maxValue=100; + stepValue=0; + value=0; + } + Int NormalMixerPosY { + description = ""; + minValue=-100; + maxValue=100; + stepValue=0; + value=0; + } + Int NormalMixerDepth { + description = ""; + minValue=-200; + maxValue=200; + stepValue=0; + value=0; + } + Int SSAONoIters { + description = "

Radius of the mask. Large number will lead to poor performance. For small images (about 1024x1024) this should not be a problem, but for larger you should use this parameter carefully.

"; + minValue=1; + maxValue=50; + stepValue=0; + value=4; + } + Int SSAODepth { + description = "It changes the scale of the effect. "; + minValue=1; + maxValue=100; + stepValue=0; + value=1; + } + Int SSAOIntensity { + description = "It changes the contrast of the image. "; + minValue=0; + maxValue=500; + stepValue=0; + value=100; + } + Int SSAOBias { + description = "This again allows you to control the contrast of the image."; + minValue=-400; + maxValue=400; + stepValue=0; + value=0; + } + Int RoughnessDepth { + description = "

Changes range of the effect.

"; + minValue=0; + maxValue=100; + stepValue=0; + value=0; + } + Int RoughnessTreshold { + description = "

Basically it sets the cutoff level of roughness. Lower values will lead to higher rgouhness level.

"; + minValue=-255; + maxValue=255; + stepValue=0; + value=0; + } + Int RoughnessAmplifier { + description = "

Amplifies the effect.

"; + minValue=-100; + maxValue=100; + stepValue=0; + value=0; + } + Int RoughnessColorOffset { + description = "Offset value of color comparison test"; + minValue=-100; + maxValue=100; + stepValue=0; + value=0; + } + Int RoughnessColorAmplifier { + description = "Amplify effect"; + minValue=-100; + maxValue=100; + stepValue=0; + value=0; + } + Int RoughnessColorGlobalOffset { + description = ""; + minValue=-255; + maxValue=255; + stepValue=0; + value=0; + } + Int NormalToHeightItersLarge { + description = "Number of iterations done on large grid."; + minValue=0; + maxValue=99; + stepValue=10; + value=0; + } + Int NormalToHeightItersVerySmall { + description = "Number of iterations done on very small grid (nearest neighbours)."; + minValue=0; + maxValue=99; + stepValue=10; + value=0; + } + Int NormalToHeightItersSmall { + description = "Number of iterations done on small grid (second nearest neighbours)."; + minValue=0; + maxValue=99; + stepValue=10; + value=0; + } + Int NormalToHeightItersVeryLarge { + description = "Number of iterations done on very large grid."; + minValue=0; + maxValue=100; + stepValue=10; + value=4; + } + Int NormalToHeightItersMedium { + description = "Number of iterations done on medium grid."; + minValue=0; + maxValue=99; + stepValue=10; + value=0; + } + Int NormalToHeightItersHuge { + description = "

Number of iterations done on huge grid.

"; + minValue=0; + maxValue=99; + stepValue=10; + value=0; + } + + Int RemoveShadingLFBlending { + description = ""; + minValue=0; + maxValue=100; + stepValue=0; + value=0; + } + Int RemoveShadingLFRadius { + description = "

Set the mask radius: larger values remove lower frequencies, lower values - higher frequencies. This tool is a analogical to Low Frequency Even GIMP plugin.

"; + minValue=0; + maxValue=100; + stepValue=0; + value=0; + } + Int RemoveShadingGaussIter { + description = "

In case if option Remove shading is enabled it changes the number of iterations to be performed.

"; + minValue=1; + maxValue=100; + stepValue=2; + value=10; + } + Int AOCancelation { + description = "

Remove dark regions using calculated AO map.

"; + minValue=0; + maxValue=100; + stepValue=0; + value=0; + } + Int BlurNoPasses { + description = "

Basically it works like gamma correction.

Especially useful in case of height texture.

"; + minValue=0; + maxValue=10; + stepValue=1; + value=0; + } + + Int NormalsStep { + description = "

It changes the steepness of the normal image in %.

For example 100% means that the image is not changed. 0% means that the image is completely flat.

"; + minValue=-500; + maxValue=500; + stepValue=10; + value=0; + } + + Int HeightAveRadius { + description = ""; + minValue=1; + maxValue=100; + stepValue=0; + value=1; + } + Int HeightProcMinValue { + description = ""; + minValue=0; + maxValue=200; + stepValue=0; + value=0; + } + Int HeightProcMaxValue { + description = ""; + minValue=0; + maxValue=200; + stepValue=0; + value=200; + } + Int HeightOffsetValue { + description = ""; + minValue=-100; + maxValue=100; + stepValue=0; + value=0; + } + Int SpeculatW1 { + description = "Radius of the first gaussian"; + minValue=1; + maxValue=4000; + stepValue=50; + value=10; + } + Int SpecularW2 { + description = "Radius of the second gaussian"; + minValue=1; + maxValue=4000; + stepValue=50; + value=1000; + } + Int SpecularRadius { + description = "

Mask radius. Usually it is greater than Weight #1 and Weight #2. But here you can choose any value.

"; + minValue=1; + maxValue=40; + stepValue=1; + value=10; + } + Int SpecularContrast { + description = "It changes the contrast of the image."; + minValue=0; + maxValue=200; + stepValue=5; + value=105; + } + Int SpecularAmplifier { + description = "It multiplies the output image by a given number."; + minValue=-100; + maxValue=100; + stepValue=1; + value=30; + } + Int SpecularBrightness { + description = ""; + minValue=-100; + maxValue=100; + stepValue=10; + value=0; + } + Int SelectiveBlurMaskRadius { + description = "Gaussian blur radius"; + minValue=0; + maxValue=50; + stepValue=10; + value=5; + } + Int SelectiveBlurBlending { + description = "Strenght of the effect. "; + minValue=0; + maxValue=100; + stepValue=0; + value=0; + } + Int SelectiveBlurNoIters { + description = "Number of gaussian blur iterations"; + minValue=1; + maxValue=10; + stepValue=0; + value=1; + } + Int SelectiveBlurDOGRadius { + description = "Difference of Gaussians blur radius. First image is not blured."; + minValue=0; + maxValue=50; + stepValue=0; + value=5; + } + Int SelectiveBlurDOGContrast { + description = ""; + minValue=-100; + maxValue=100; + stepValue=0; + value=0; + } + Int SelectiveBlurDOGAmplifier { + description = ""; + minValue=-100; + maxValue=100; + stepValue=0; + value=-30; + } + Int SelectiveBlurDOGOffset { + description = "Move the result value up/down"; + minValue=-255; + maxValue=255; + stepValue=0; + value=0; + } + Int SelectiveBlurMinValue { + description = ""; + minValue=0; + maxValue=255; + stepValue=0; + value=0; + } + Int SelectiveBlurMaxValue { + description = ""; + minValue=0; + maxValue=255; + stepValue=0; + value=255; + } + Int SelectiveBlurDetails { + description = ""; + minValue=1; + maxValue=100; + stepValue=0; + value=1; + } + Int SelectiveBlurOffset { + description = ""; + minValue=-255; + maxValue=255; + stepValue=0; + value=0; + } + Int BaseToOthersAngleCorrection { + description = ""; + minValue=0; + maxValue=360; + stepValue=0; + value=0; + } + Int BaseToOthersAngleWeight { + description = ""; + minValue=-100; + maxValue=100; + stepValue=0; + value=0; + } + +*/ +} + +property_set AwesomeBump +{ + // Diffuse image + extern property_set FormImageProp DiffuseImage + { + description = "Diffuse Image"; + state = QtnPropertyStateCollapsed; + } + + // Normal image + extern property_set FormImageProp NormalImage + { + description = "Normal Image"; + state = QtnPropertyStateCollapsed; + } + + // Specular image + extern property_set FormImageProp SpecularImage + { + description = "Specular processing"; + state = QtnPropertyStateCollapsed; + } + + // Occlusion image + extern property_set FormImageProp OcclusionImage + { + description = "Occlusion Image"; + state = QtnPropertyStateCollapsed; + } + + // Roughness image + extern property_set FormImageProp RoughnessImage + { + description = "Roughness Image"; + state = QtnPropertyStateCollapsed; + } + + // Metallic image + extern property_set FormImageProp MetallicImage + { + description = "Metallic Image"; + state = QtnPropertyStateCollapsed; + } + + // Materials image + property_set MaterialsImageType MaterialsImage + { + description = "Materials Image"; + state = QtnPropertyStateCollapsed; + QString Dummy + { + description = "Dummy"; + } + } + + // Grunge general settings + property_set GrungeGeneralSettingsType GrungeGeneralSettings + { + description = "Grunge general settings"; + + Int OverallWeight + { + description = "Set common blending weight factor for all textures blending."; + value = 0; + minValue = 0; + maxValue = 100; + stepValue = 1; + } + + Int Randomize + { + description = "When 0 - use orginal image, otherwise generate random seamless image."; + value = 0; + minValue = 0; + maxValue = 100; + stepValue = 1; + } + + Int Scale + { + description = "It scales the UVs of generated random image. Value 1 is neutral."; + value = 1; + minValue = 1; + maxValue = 100; + stepValue = 25; + } + + Int NormalWarp + { + description = "Warps grunge texture pixels along normals of normal texture."; + value = 0; + minValue = -100; + maxValue = 100; + stepValue = 1; + } + + QString Predefined + { + description = "Load predefined grunge map from list. Note that predefined grunge textures are located in Core/2D/grungefolder. You can paste there your own images in oder to make your own list of grunge images."; + delegate List + { + items = QStringList() << "one" << "two" << "three" << "four"; + } + } + + Bool RandomTranslations + { + description = "Random translations."; + value = false; + } + + Bool ReplotAllTexturesWhenChanges + { + description = "Replot all textures when changes."; + value = false; + } + } // end group + + + // Grunge pattern + property_set GrungePatternType GrungePattern + { + description = "Grunge pattern"; + + Enum BlendingMode + { + description = "Blending modes are same as in GIMP program."; + enumInfo = &BLENDINGMODE::info(); + value = BLENDINGMODE::blendNormal; + } + + Int GrungeWeight + { + description = "This is blending factor for grunge image. 0 - no grunge."; + value = 0; + minValue = 0; + maxValue = 100; + stepValue = 1; + } + + Int ImageWeight + { + description = "This is blending factor for this image. 0 - no grunge."; + value = 0; + minValue = 0; + maxValue = 100; + stepValue = 1; + } + } // GrungePattern + + // UV&Tiling settings + property_set UVSettingsType UVSettings + { + description = "UV/Tiling Settings"; + Int SeamlessContrastPower { + description = "

Another parameter which allows you to control blending weights between two colors.

"; + minValue=0; + maxValue=99; + stepValue=10; + value=0; + } + Int SeamlessContrastStrenght { + description = "

It corrects the blending equation according to contrast between two mixed colors. When slider is set to zero standard linear interpolation is applied. This tool works best with simple tilling algorithm.


"; + minValue=0; + maxValue=100; + stepValue=10; + value=0; + } + Int MakeSeamlessRadius { + description = ""; + minValue=0; + maxValue=100; + stepValue=10; + value=50; + } + Int RandomPatchesInnerRadius { + description = ""; + minValue=0; + maxValue=100; + stepValue=10; + value=20; + } + Int RandomPatchesRotate { + description = ""; + minValue=-180; + maxValue=180; + stepValue=10; + value=0; + } + Int RandomPatchesOuterRadius { + description = ""; + minValue=0; + maxValue=100; + stepValue=10; + value=40; + } + } + + // Input image + Enum InputImage + { + description = "Choose the input image for further processing. Warning: when current image is selected and UV transformation are applied then output normal image may not by transformed properly."; + enumInfo = &INPUTIMAGE::info(); + value = INPUTIMAGE::inputCurrent; + } + + Float DepthInPixels + { + description = "It changes the depth of the calculated normal map in pixels unit. For example: lets assume that you have picture of wall of size 1x1 m2 in real world with bricks pattern and your image has size 1024x1024 pixels. Then you want to generate normals for texture which depth is 3cm = 0.03 m. So the depth in pixels is 0.03*1024 = 30.72 ~ 31 pixels."; + value = 20; + minValue = 0; + maxValue = 1000; + stepValue = 1; + } + + //Action RecalculateFromNormals { + // description = ""; + //} +} diff --git a/Sources/resources/filters_3d.frag b/Sources/resources/filters_3d.frag index 3e3fccd..6565810 100644 --- a/Sources/resources/filters_3d.frag +++ b/Sources/resources/filters_3d.frag @@ -88,55 +88,86 @@ vec4 ffilter(){ #ifdef BLOOM_FILTER +uniform float bloom_WeightA; +uniform float bloom_WeightB; +uniform float bloom_WeightC; +uniform float bloom_WeightD; +uniform float bloom_Vignette; +uniform float bloom_VignetteAtt; vec4 ffilter(){ vec3 color = texture(layerA, v2QuadCoords.st).rgb; - vec3 b1 = texture(layerB, v2QuadCoords.st).rgb; - vec3 b2 = texture(layerC, v2QuadCoords.st).rgb; - vec3 b3 = texture(layerD, v2QuadCoords.st).rgb; - vec3 b4 = texture(layerE, v2QuadCoords.st).rgb; + vec3 b1 = texture(layerB, v2QuadCoords.st).rgb*bloom_WeightA; + vec3 b2 = texture(layerC, v2QuadCoords.st).rgb*bloom_WeightB; + vec3 b3 = texture(layerD, v2QuadCoords.st).rgb*bloom_WeightC; + vec3 b4 = texture(layerE, v2QuadCoords.st).rgb*bloom_WeightD; - vec3 bloom = (b1*0.4f + b2*0.8f + b3*0.6f + b4*0.8f)/2.5; + vec3 bloom = (b1 + b2 + b3 + b4); float x = v2QuadCoords.x; float y = v2QuadCoords.y; - float attenuateX = 1.0 - 0.8*(1 - smoothstep(0.0,0.4,x) + smoothstep(0.6,1.0,x)); - float attenuateY = 1.0 - 0.8*(1 - smoothstep(0.0,0.4,y) + smoothstep(0.6,1.0,y)); + float attenuateX = 1.0 - bloom_VignetteAtt*(1 - smoothstep(0.0,bloom_Vignette,x) + smoothstep(1-bloom_Vignette,1.0,x)); + float attenuateY = 1.0 - bloom_VignetteAtt*(1 - smoothstep(0.0,bloom_Vignette,y) + smoothstep(1-bloom_Vignette,1.0,y)); return vec4( color + bloom * attenuateX * attenuateY ,1); } #endif #ifdef TONE_MAPPING_FILTER +uniform int tm_step; // 1-calculate luminance,2-integrate image,3-tone mapping -float A = 0.15; -float B = 0.50; -float C = 0.10; -float D = 0.20; -float E = 0.02; -float F = 0.30; -float W = 1.2; +// Reinhard tone mapping based on article from Nutty shell company: +// url: http://www.nutty.ca/?page_id=2 +// article-url: http://www.nutty.ca/?page_id=352&link=hdr -vec3 Uncharted2Tonemap(vec3 x) -{ - return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F; -} - -vec4 ffilter(){ +uniform float tm_Delta; +uniform float tm_Scale; +uniform float tm_LumMaxWhite; +uniform float tm_GammaCorrection; +uniform float tm_BlendingWeight; - vec3 texColor = texture(layerA, v2QuadCoords.st).rgb; - vec3 bloom = texture(layerB, vec2(0.5,0.5)).rgb; +float delta = tm_Delta; +float alpha = tm_Scale; +float Lwhite= tm_LumMaxWhite; +float gamma = tm_GammaCorrection; +const mat3 RGBtoXYZ = mat3( 0.4124,0.3576,0.1805, + 0.2126,0.7152,0.0722, + 0.0193,0.1192,0.9505); - float ExposureBias = 1+0.5*length(bloom); - vec3 curr = Uncharted2Tonemap(ExposureBias*texColor); - - vec3 whiteScale = 1.0f/Uncharted2Tonemap(vec3(W)); - vec3 color = curr*whiteScale; - - vec3 retColor = pow(color,vec3(2.5/2.2)); - - return vec4(retColor,1); +const mat3 XYZtoRGB = mat3( 3.2406,-1.5372,-0.4986, + -0.9689, 1.8758, 0.0415, + 0.0557,-0.2040, 1.0570); +vec4 ffilter(){ + if(tm_step == 1){ + vec3 texColor = texture(layerA, v2QuadCoords.st).rgb; + float luminance = log(delta + dot(texColor.rgb,vec3(0.2126,0.7152,0.0722))); + return vec4(vec3(luminance),1)/2; + }else if(tm_step == 2){ + return texture(layerA, v2QuadCoords.st); + }else{ // step 3 + float N = width*height; + vec3 texColor = texture(layerB, v2QuadCoords.st).rgb; + vec3 orgColor = texColor; + // Calulate luminance from Reinhard model + float Lwxy = dot(texColor.rgb,vec3(0.2126,0.7152,0.0722)); + float aveLxy = exp(texture(layerA, v2QuadCoords.st).r-delta); + float Lxy = alpha * Lwxy / aveLxy; + float Ld = Lxy*(1+Lxy/(Lwhite*Lwhite))/(1+Lxy); + + vec3 XYZ = RGBtoXYZ*texColor; + float sXYZ = XYZ.x + XYZ.y + XYZ.z; + vec3 xyY = vec3(XYZ.x/sXYZ,XYZ.y/sXYZ,XYZ.y); + // Apply luminance + float x = xyY.x; + float y = xyY.y; + float Y = xyY.z*Ld; + // Go back to RGB + XYZ = vec3(Y/y*x,Y,Y/y*(1-x-y)); + texColor = XYZtoRGB*XYZ; + texColor = pow(texColor, vec3(gamma)); + return vec4(mix(orgColor,texColor,tm_BlendingWeight),1); + } } #endif @@ -144,11 +175,18 @@ vec4 ffilter(){ #ifdef LENS_FLARES_FILTER -int uSamples = 8; -float uDispersal = 0.25; -float uHaloWidth = 0.5; -float uDistortion = 1.0; +uniform int lf_NoSamples; +uniform float lf_Dispersal; +uniform float lf_HaloWidth; +uniform float lf_Distortion; +uniform float lf_weightLF; + +int uSamples = lf_NoSamples; +float uDispersal = lf_Dispersal; +float uHaloWidth = lf_HaloWidth; +float uDistortion = lf_Distortion; +float weightLF = lf_weightLF; /** Lens flares effect based on: @@ -256,7 +294,7 @@ vec4 ffilter() { float exposureBias = max(1-0.5*length(exposureColor),0.0); //return lensColor; - return texture(layerA, v2QuadCoords.st) + 10*(starColor+dirtColor)*lensColor*exposureBias; + return texture(layerA, v2QuadCoords.st) + weightLF*(starColor+dirtColor)*lensColor*exposureBias; } } @@ -311,34 +349,43 @@ changelog: #ifdef DOF_FILTER -const float focalDepth = 10.0; //focal distance value in meters, but you may use autofocus option below -const float focalLength = 25.0; //focal length in mm -const float fstop = 140.0; //f-stop value +uniform float dof_FocalLenght; +uniform float dof_FocalDepth; +uniform float dof_FocalStop; + +uniform float dof_Coc; +uniform float dof_Threshold; +uniform float dof_Gain; +uniform float dof_BokehBias; +uniform float dof_BokehFringe; +uniform float dof_DitherAmount; +uniform int dof_NoSamples; +uniform int dof_NoRings; +uniform bool dof_bNoise; #define PI 3.14159265 //------------------------------------------ -//user variables - -const int samples = 4; //samples on the first ring -const int rings = 7; //ring count +// User variables +//------------------------------------------ +int samples = dof_NoSamples; //samples on the first ring +int rings = dof_NoRings; //ring count +float CoC = dof_Coc; //circle of confusion size in mm (35mm film = 0.03mm) +float focalDepth = dof_FocalDepth; //focal distance value in meters, but you may use autofocus option below +float focalLength = dof_FocalLenght; //focal length in mm +float fstop = dof_FocalStop; //f-stop value -const float CoC = 0.03;//circle of confusion size in mm (35mm film = 0.03mm) +float threshold = dof_Threshold; //highlight threshold; +float gain = dof_Gain; //highlight gain; +float bias = dof_BokehBias; //bokeh edge bias 0.5 +float fringe = dof_BokehFringe; //bokeh chromatic aberration/fringing +bool noise = dof_bNoise; //use noise instead of pattern for sample dithering +float namount = dof_DitherAmount; //dither amount const vec2 focus = vec2(0.5,0.5); // autofocus point on screen (0.0,0.0 - left lower corner, 1.0,1.0 - upper right) const float maxblur = 1.0; //clamp value of max blur (0.0 = no blur,1.0 default) -const float threshold = 0.25; //highlight threshold; -const float gain = 1.0; //highlight gain; - -const float bias = 0.25; //bokeh edge bias 0.5 -const float fringe = 0.7; //bokeh chromatic aberration/fringing - -const bool noise = false; //use noise instead of pattern for sample dithering -const float namount = 0.0001; //dither amount - - vec3 color(vec2 coords,float blur) //processing the sample diff --git a/Sources/resources/plane.frag b/Sources/resources/plane.frag index 7d94021..a7bce58 100644 --- a/Sources/resources/plane.frag +++ b/Sources/resources/plane.frag @@ -222,7 +222,7 @@ float GGX_PartialGeometryTerm_OPT(float VdotH, float VdotN, float alpha2) vec3 Fresnel_Schlick(float cosT, vec3 F0) { - return F0 + (1-F0) * pow( 1 - cosT, 5); + return F0 + (1-F0)* pow( cosT, 4.0); } @@ -294,13 +294,13 @@ vec4 PBR_Specular(float roughness, vec3 halfVector = normalize(lp + v); - float VdotH = max(dot( halfVector, v ),0.01); + float VdotH = clamp(dot( halfVector, v ),0.01,1.0); float HdotN = max(dot( halfVector, n ),0.01); float LdotN = max(dot( lp, n ),0.01); float LdotH = max(dot( lp, halfVector ),0.01); - vec3 fresnel = Fresnel_Schlick( VdotH, F0 ); + vec3 fresnel = Fresnel_Schlick( (1-VdotH), F0 ); // Geometry term float geometry = GGX_PartialGeometryTerm_OPT( VdotH, NdotV, r2) @@ -318,7 +318,7 @@ vec4 PBR_Specular(float roughness, vec3 color = texture( texEnvMap, lp ).rgb * exp(-0.1*gui_LightPower) + gui_LightPower * light *0.4; - radiance += color * geometry * fresnel / denominator;// * sinT; + radiance += color * geometry/denominator * fresnel ; } // Scale back for the samples count diff --git a/Sources/resources/recompileShader.png b/Sources/resources/recompileShader.png new file mode 100644 index 0000000..cf2517c Binary files /dev/null and b/Sources/resources/recompileShader.png differ diff --git a/Sources/resources/recompileShader.svg b/Sources/resources/recompileShader.svg new file mode 100644 index 0000000..79f9146 --- /dev/null +++ b/Sources/resources/recompileShader.svg @@ -0,0 +1,158 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/resources/settings3d.png b/Sources/resources/settings3d.png new file mode 100644 index 0000000..3e43a8c Binary files /dev/null and b/Sources/resources/settings3d.png differ diff --git a/Sources/utils/QtnProperty b/Sources/utils/QtnProperty new file mode 160000 index 0000000..230a2e4 --- /dev/null +++ b/Sources/utils/QtnProperty @@ -0,0 +1 @@ +Subproject commit 230a2e43307515cb1be6183ca5c9adaab6d6ca96 diff --git a/Sources/utils/glslparsedshadercontainer.cpp b/Sources/utils/glslparsedshadercontainer.cpp new file mode 100644 index 0000000..8ffa64f --- /dev/null +++ b/Sources/utils/glslparsedshadercontainer.cpp @@ -0,0 +1,31 @@ +#include "glslparsedshadercontainer.h" +extern QString _find_data_dir(const QString& path); + + +GLSLParsedShaderContainer::GLSLParsedShaderContainer() +{ + // ------------------------------------------------------- // + // Parsing shaders from Render folder + // ------------------------------------------------------- // + qDebug() << "Parsing shaders in Render folder:"; + QDir currentDir(_find_data_dir(QString(RESOURCE_BASE) + "Core/Render")); + currentDir.setFilter(QDir::Files); + QStringList entries = currentDir.entryList(); + qDebug() << "Looking for shaders in Core/Render directory"; + for( QStringList::ConstIterator entry=entries.begin(); entry!=entries.end(); ++entry ){ + QString dirname=*entry; + GLSLShaderParser* parser = new GLSLShaderParser; + parser->parseShader("Core/Render/"+dirname); + glslParsedShaders.push_back(parser); + }// end of for + +} + +GLSLParsedShaderContainer::~GLSLParsedShaderContainer() +{ + for(int i = 0 ; i < glslParsedShaders.size() ; i++){ + delete glslParsedShaders[i]; + } + glslParsedShaders.clear(); +} + diff --git a/Sources/utils/glslparsedshadercontainer.h b/Sources/utils/glslparsedshadercontainer.h new file mode 100644 index 0000000..780dc9f --- /dev/null +++ b/Sources/utils/glslparsedshadercontainer.h @@ -0,0 +1,17 @@ +#ifndef GLSLPARSEDSHADERCONTAINER_H +#define GLSLPARSEDSHADERCONTAINER_H + +#include "CommonObjects.h" +#include "glslshaderparser.h" + +#define RENDER_FOLDER "Core/Render/" + +class GLSLParsedShaderContainer +{ +public: + GLSLParsedShaderContainer(); + ~GLSLParsedShaderContainer(); + QVector glslParsedShaders; +}; + +#endif // GLSLPARSEDSHADERCONTAINER_H diff --git a/Sources/utils/glslshaderparser.cpp b/Sources/utils/glslshaderparser.cpp new file mode 100644 index 0000000..15389aa --- /dev/null +++ b/Sources/utils/glslshaderparser.cpp @@ -0,0 +1,156 @@ +#include "glslshaderparser.h" + +GLSLShaderParser::GLSLShaderParser() +{ + initializeOpenGLFunctions(); + reservedNames << "num_mipmaps" + << "gui_bSpecular" + << "bOcclusion" + << "gui_bHeight" + << "gui_bDiffuse" + << "gui_bOcclusion" + << "gui_bNormal" + << "gui_bRoughness" + << "gui_bMetallic" + << "gui_LightPower" + << "gui_LightRadius" + << "gui_noPBRRays" + << "gui_bUseSimplePBR" + << "gui_bMaterialsPreviewEnabled" + << "gui_bShowTriangleEdges" + << "gui_depthScale" + << "gui_SpecularIntensity" + << "gui_DiffuseIntensity" + << "gui_shading_type" + << "gui_shading_model" + << "cameraPos" + << "lightDirection" + << "lightPos" + << "ModelMatrix" + << "ModelViewMatrix"; + + supportedTypes << "int" << "float"; + + supportedParams << "[ ]*max[ ]*=[ ]*[+-]?[0-9]*\.?[0-9]+" + << "[ ]*min[ ]*=[ ]*[+-]?[0-9]*\.?[0-9]+" + << "[ ]*value[ ]*=[ ]*[+-]?[0-9]*\.?[0-9]+" + << "[ ]*step[ ]*=[ ]*[+-]?[0-9]*\.?[0-9]+" + << "[ ]*name[ ]*=[ ]*\"[a-zA-Z0-9 -+'()]*\"" + << "[ ]*description[ ]*=[ ]*\"[a-zA-Z0-9 -+'()]*\""; + program = NULL; + +} + +void GLSLShaderParser::cleanup(){ + if(program != NULL )delete program; +} + +GLSLShaderParser::~GLSLShaderParser() +{ + cleanup(); +} + + +bool GLSLShaderParser::parseShader(QString path){ + + QFile file(path); + shaderPath = path; + + + if(!file.exists()){ + qDebug() << "GLSL Parser::File:" << path << " does not extist."; + return false; + } + QFileInfo fileInfo(file); + shaderName = fileInfo.baseName(); + qDebug() << "GLSL Parser::Shader name:" << shaderName; + + // Scann whole file and look for uniforms + if (file.open(QIODevice::ReadOnly)) + { + QTextStream in(&file); + while (!in.atEnd()) + { + QString line = in.readLine(); + parseLine(line); + } + file.close(); + } + + + return true; +} + +void GLSLShaderParser::reparseShader(){ + uniforms.clear(); + parseShader(shaderPath); +} + +void GLSLShaderParser::parseLine(const QString &line){ + + if(line.contains("uniform", Qt::CaseSensitive)){ + QStringList lineList = line.split(" ",QString::SkipEmptyParts); + QString uName = lineList.at(2); + // get name and remove semicolon + uName = uName.split(";",QString::SkipEmptyParts).at(0); + QString uType = lineList.at(1); // type is usually second after "uniform" key + // check if name is in the resevedNames and type is supported + if(!reservedNames.contains(uName,Qt::CaseSensitive) && + supportedTypes.contains(uType,Qt::CaseSensitive)){ + // Parsing parameters of uniform variable + UniformData parsedUniform; + if(uType == "int") parsedUniform.type = UNIFORM_TYPE_INT; + if(uType == "float") parsedUniform.type = UNIFORM_TYPE_FLOAT; + parsedUniform.varName = uName; + QStringListIterator iterator(supportedParams); + while (iterator.hasNext()) + parseUniformParameters(parsedUniform,line,iterator.next()); + + qDebug() << parsedUniform.toString(); + uniforms.push_back(parsedUniform); + } + } +} + + +void GLSLShaderParser::parseUniformParameters(UniformData& parsedUniform,const QString &line, const QString ¶m){ + + QRegularExpression regLine(param); + QRegularExpressionMatch match = regLine.match(line); + // Reading data + if (match.hasMatch()) { + QString matched = match.captured(0); + QStringList splitted = matched.split("=",QString::SkipEmptyParts); + + if(splitted[0].contains("min")){ + parsedUniform.min = QVariant(splitted[1]).toFloat(); + }else if(splitted[0].contains("max")){ + parsedUniform.max = QVariant(splitted[1]).toFloat(); + }else if(splitted[0].contains("value")){ + parsedUniform.value = QVariant(splitted[1]).toFloat(); + }else if(splitted[0].contains("step")){ + parsedUniform.step = QVariant(splitted[1]).toFloat(); + }else if(splitted[0].contains("name")){ + parsedUniform.name = (splitted[1]); + }else if(splitted[0].contains("description")){ + parsedUniform.description = (splitted[1]); + } + } +} + + +void GLSLShaderParser::setParsedUniforms(){ + for(unsigned int u = 0 ; u < uniforms.size() ; u++){ + UniformData& uniform = uniforms[u]; + switch (uniform.type) { + case UNIFORM_TYPE_FLOAT: + GLCHK( program->setUniformValue(uniform.varName.toStdString().c_str(), (float)uniform.value) ); + break; + case UNIFORM_TYPE_INT: + GLCHK( program->setUniformValue(uniform.varName.toStdString().c_str(), (int)uniform.value) ); + break; + default: + break; + } + } +} diff --git a/Sources/utils/glslshaderparser.h b/Sources/utils/glslshaderparser.h new file mode 100644 index 0000000..f88de4e --- /dev/null +++ b/Sources/utils/glslshaderparser.h @@ -0,0 +1,77 @@ +#ifndef GLSLSHADERPARSER_H +#define GLSLSHADERPARSER_H + + +#include +#include +#include +#include +#include +#include +#include "CommonObjects.h" + + +enum UniformDataType{ + UNIFORM_TYPE_INT = 0, + UNIFORM_TYPE_FLOAT +}; +struct UniformData{ + UniformDataType type; + float value; + float min; + float max; + float step; + QString varName; + QString name; + QString description; + UniformData(){ + value = 50.0; + min = 0.0; + max = 100.0; + step = 1.0; + name = "param#"; + description = "None"; + } + QString toString(){ + QString uniformString = + "Uniform :" + name + "\n" + "Type :" + QString::number(type) + "\n" + "Data :" + QString::number(value) + " range=["+ QString::number(min)+","+ QString::number(max)+";"+ QString::number(step)+"]\n" + "Description:" + description; + return uniformString; + } +}; + +class GLSLShaderParser: public QOpenGLFunctions_3_3_Core +{ +public: + GLSLShaderParser(); + bool parseShader(QString path); + void reparseShader(); + void setParsedUniforms(); + ~GLSLShaderParser(); + +private: + void cleanup(); + void parseLine(const QString& line); + void parseUniformParameters(UniformData &uniform, const QString &line, const QString& param); + + QStringList reservedNames; // List of uniforms names which will be not parsed + QStringList supportedTypes; // List of types (int,float,...) which can be parsed + QStringList supportedParams;// List of regular expresions to obtain the maxium, minium etc parameters of the uniform + +public: + QString shaderName; + QVector uniforms; // Contains all editable parsed uniforms + QString shaderPath; + QOpenGLShaderProgram *program; // glsl shader + +}; + + +//QOpenGLShaderProgram* program_ptr = program_ptrs[pindex]; +//GLCHK( program_ptr->bind() ); + +//GLCHK( program_ptr->setUniformValue("ProjectionMatrix", projectionMatrix) ); + +#endif // GLSLSHADERPARSER_H diff --git a/Sources/utils/qglbuffers.cpp b/Sources/utils/qglbuffers.cpp index 4f5f4f1..8ee37f7 100644 --- a/Sources/utils/qglbuffers.cpp +++ b/Sources/utils/qglbuffers.cpp @@ -352,7 +352,7 @@ GLFrameBufferObject::GLFrameBufferObject(int width, int height) fbo = NULL; attachments.clear(); QGLFramebufferObjectFormat format; - format.setInternalTextureFormat(TEXTURE_FORMAT); + format.setInternalTextureFormat(TEXTURE_3DRENDER_FORMAT); format.setTextureTarget(GL_TEXTURE_2D); format.setMipmap(true); format.setAttachment(QGLFramebufferObject::Depth); @@ -404,7 +404,7 @@ bool GLFrameBufferObject::addTexture(GLenum COLOR_ATTACHMENTn){ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); - glTexImage2D(GL_TEXTURE_2D, 0, TEXTURE_FORMAT, fbo->width(), fbo->height(), 0,GL_RGB, GL_UNSIGNED_BYTE, 0); + glTexImage2D(GL_TEXTURE_2D, 0, TEXTURE_3DRENDER_FORMAT, fbo->width(), fbo->height(), 0,GL_RGB, GL_UNSIGNED_BYTE, 0); glBindTexture(GL_TEXTURE_2D, 0); if(!glIsTexture(tex[0])){ qDebug() << "Error: Cannot create additional texture. Process stopped." << endl; diff --git a/Wiki/Tests/Test_MinMaxBaseMapColorConversionTool.jpg b/Wiki/Tests/Test_MinMaxBaseMapColorConversionTool.jpg new file mode 100644 index 0000000..38c219f Binary files /dev/null and b/Wiki/Tests/Test_MinMaxBaseMapColorConversionTool.jpg differ diff --git a/Wiki/Tests/Test_MinMaxBaseMapColorConversionTool_SourceImage.jpg b/Wiki/Tests/Test_MinMaxBaseMapColorConversionTool_SourceImage.jpg new file mode 100644 index 0000000..473cdcc Binary files /dev/null and b/Wiki/Tests/Test_MinMaxBaseMapColorConversionTool_SourceImage.jpg differ