GLSL, OpenGLES2.0 glFog :: OPEN GL ES[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

OPEN GL ES
[1]
등록일:2020-05-07 00:32:51 (0%)
작성자:
제목:GLSL, OpenGLES2.0 glFog

OpenGLES2.0 not support glFog. So If you want fog effect, you have to a code using glsl.


1. Calculate

  GL_FOG_MODE have 3 modes.


GL_LINEAR : f = (end - z)/(end - start)

GL_EXP :  f = exp(-density*z) 

GL_EXP2 : f = exp2(-(density*z)*(density*z))

Color = Color_source*f + (1-f)Color_fog



  start - fog start distionce(usually 0.0f)

  end - fog's end distance (usually 1.0f)

  Color_source is fragment color.

  Color_fog is fog-color set by GL_FOG_COLOR


2. GLSL Code

  Below show glsl code. It is very simple code

tmp_color is rgba color that texture color and source color modulated. 

enable_fog is set by glUniform1i c++ code. Default mode is GL_LINEAR. 

To get fragment's depth buffer value, I used gl_FragCoord.z that is [0-1].


void main(void)
{	
	if(enable_fog == 1)
	{
		float f = 0.0;
		float z = gl_FragCoord.z;
		float alpha = tmp_color.a;
		if(fog_mode == FOG_EXP)
		{
			f = clamp(exp(-fog_density*z),0.0, 1.0);
		}
		else if(fog_mode == FOG_EXP2)
		{
			f = clamp(exp((fog_density*z)*(fog_density*z)),0.0, 1.0);
		}
		else
		{
			float divide = fog_end - fog_start;
			if(divide != 0.0)
				f = clamp((fog_end - z)/(divide),0.0, 1.0);
		}
		tmp_color = f*tmp_color + (1.0 - f)*fog_color;
		tmp_color.a = alpha;
	}
	
	gl_FragColor = tmp_color;
}


Below show result,

(OpenGL Diary)




출처: https://shakddoo.tistory.com/entry/GLSL-OpenGLES20-glFog [겨울팥죽 여름빙수]
[본문링크] GLSL, OpenGLES2.0 glFog
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=34938
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.