﻿﻿﻿﻿﻿﻿ SSISO Community ﻿
﻿ ﻿﻿  SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
 추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기 우측부분 최근 포스트 리스트 IT블로그 리스트 아무것도 안볼래요
 회원가입 I 비밀번호 찾기
회원: 1명 카페짱: ssiso10 클럽생성일: 2012-01-26 11:58:10
안드로이드(android)
﻿
공지사항 및 게시판
사진게시판
SSISO Community카페
OPEN GL ES
 이름 제목 패스워드 HTML

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 [겨울팥죽 여름빙수] 사진첨부

﻿
 Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved. 