bgfx/examples/46-fsr/fs_fsr_forward_grid.sc
Richard Schubert fc513e163b
Add new Example - AMD FidelityFX-FSR (#2612)
* Add new sample

* Add FSR shaders

* Add example template

* Add Antialiasing

* Add multi resolution rendering

* Implement magnifier

* Implement FSR EASU pass

* Implement FSR RCAS pass

* Improve wording of comments and UI

* Remove use of ffx_a.h in cpp

* Remove example external files

* Perform bilinear upsampling by compute shader

* Add FSR 16 Bit support

* Improve magnifier picking

* Fix magnifier picking

* Render magnifier widget

* Renaming of stuff

* Separate magnifier functionality

* Move FSR into separate class

* Reduce scope of FSR resources

* Fix FSR for Vulkan

* Fix OpenGL support

* Update sample screenshot
2021-10-05 09:01:50 -07:00

59 lines
1.5 KiB
Python

$input v_normal, v_texcoord0, v_texcoord1, v_texcoord2
/*
* Copyright 2021 elven cache. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#include "../common/common.sh"
// struct ModelUniforms
uniform vec4 u_modelParams[2];
#define u_color (u_modelParams[0].xyz)
#define u_lightPosition (u_modelParams[1].xyz)
int ModHelper (float a, float b)
{
return int( a - (b*floor(a/b)));
}
vec3 GetGridColor (vec2 position, float width, vec3 color)
{
position = abs(floor( position + vec2(-width, -width) ));
int posXMod = ModHelper(position.x, 2.0);
int posYMod = ModHelper(position.y, 2.0);
float gridColorScale = (posXMod == posYMod) ? 0.75 : 1.25;
return toLinear(color) * gridColorScale;
}
void main()
{
vec3 worldSpacePosition = v_texcoord1.xyz; // contains ws pos
vec2 gridCoord = worldSpacePosition.xz; // assuming y is up
vec3 gridColor = GetGridColor(gridCoord.xy, 0.002, u_color);
// get vertex normal
vec3 normal = normalize(v_normal);
vec3 light = (u_lightPosition - worldSpacePosition);
light = normalize(light);
float NdotL = saturate(dot(normal, light));
float diffuse = NdotL * 1.0;
vec3 V = v_texcoord2.xyz; // contains view vector
vec3 H = normalize(V+light);
float NdotH = saturate(dot(normal, H));
float specular = 5.0 * pow(NdotH, 256);
float ambient = 0.1;
float lightAmount = ambient + diffuse;
vec3 color = gridColor * lightAmount + specular;
// leave color in linear space for better dof filter result
gl_FragColor = vec4(color, 1.0);
}