Просмотр исходного кода

device: convert sRGB colors to linear before processing

Daniele Bartolini 5 лет назад
Родитель
Сommit
84bd6ea594
3 измененных файлов с 6 добавлено и 12 удалено
  1. 5 7
      samples/core/shaders/default.shader
  2. 0 4
      src/device/pipeline.cpp
  3. 1 1
      src/device/pipeline.h

+ 5 - 7
samples/core/shaders/default.shader

@@ -83,7 +83,7 @@ bgfx_shaders = {
 			void main()
 			{
 				gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
-				v_color0 = a_color0;
+				v_color0 = toLinearAccurate(a_color0);
 			}
 		"""
 
@@ -127,7 +127,7 @@ bgfx_shaders = {
 		#ifdef DIFFUSE_MAP
 				v_texcoord0 = a_texcoord0;
 		#endif // DIFFUSE_MAP
-				v_color0 = a_color0;
+				v_color0 = toLinearAccurate(a_color0);
 			}
 		"""
 
@@ -188,8 +188,7 @@ bgfx_shaders = {
 
 			void main()
 			{
-				vec4 color = texture2D(u_albedo, v_texcoord0);
-				gl_FragColor = color * u_color;
+				gl_FragColor = texture2D(u_albedo, v_texcoord0) * toLinearAccurate(u_color);
 			}
 		"""
 	}
@@ -257,7 +256,7 @@ bgfx_shaders = {
 				vec3 l = u_light_direction.xyz;
 
 				float nl = max(0.0, dot(n, l));
-				vec4 light_diffuse = nl * u_light_color * u_light_intensity.x;
+				vec4 light_diffuse = nl * toLinearAccurate(u_light_color) * u_light_intensity.x;
 
 				vec4 color = max(u_diffuse * light_diffuse, u_ambient);
 		#else
@@ -392,12 +391,11 @@ bgfx_shaders = {
 		"""
 
 		fs_code = """
-			uniform vec4 u_invGamma;
 			SAMPLER2D(s_texColor, 0);
 
 			void main()
 			{
-				gl_FragColor.rgb = pow(texture2D(s_texColor, v_texcoord0).rgb, vec3(u_invGamma.x));
+				gl_FragColor.rgb = toGammaAccurate(texture2D(s_texColor, v_texcoord0).rgb);
 			}
 		"""
 	}

+ 0 - 4
src/device/pipeline.cpp

@@ -106,7 +106,6 @@ void Pipeline::create(uint16_t width, uint16_t height)
 {
 	PosTexCoord0Vertex::init();
 	_tex_color = bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler);
-	_inv_gamma = bgfx::createUniform("u_invGamma", bgfx::UniformType::Vec4);
 
 	reset(width, height);
 }
@@ -116,7 +115,6 @@ void Pipeline::destroy()
 	bgfx::destroy(_frame_buffer);
 	bgfx::destroy(_buffers[1]);
 	bgfx::destroy(_buffers[0]);
-	bgfx::destroy(_inv_gamma);
 	bgfx::destroy(_tex_color);
 }
 
@@ -176,8 +174,6 @@ void Pipeline::render(ShaderManager& sm, StringId32 program, uint8_t view, uint1
 		;
 	bgfx::setTexture(0, _tex_color, _buffers[0], samplerFlags);
 	screenSpaceQuad(width, height, 0.0f, caps->originBottomLeft);
-	f32 gamma[] = { 1.0f/2.2f, 0.0f, 0.0f, 0.0f };
-	bgfx::setUniform(_inv_gamma, gamma);
 	sm.submit(program, view, 0, BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A);
 }
 

+ 1 - 1
src/device/pipeline.h

@@ -29,8 +29,8 @@ struct Pipeline
 	bgfx::TextureHandle _buffers[2];
 	bgfx::FrameBufferHandle _frame_buffer;
 	bgfx::UniformHandle _tex_color;
-	bgfx::UniformHandle _inv_gamma;
 
+	///
 	Pipeline();
 
 	///