Cg/HSL 셰이더 프로그램을 사용함과 더불어 OpenGL 셰이딩 언어(GLSL) 셰이더를 직접 작성할 수 있습니다.
하지만 원시 GLSL은 테스트용으로만 사용하거나 타겟이 Mac OS X, OpenGL ES 모바일 디바이스 임을 알고 있는 경우에만 사용하는 것이 좋습니다. 모든 일반적인 경우에는 Unity가 필요할 때 Cg/HLSL를 최적화된 GLSL로 크로스 컴파일합니다.
GLSL 프로그램 스니핏은 GLSLPROGRAM
및 ENDGLSL
키워드 사이에 작성됩니다.
GLSL에서는 모든 셰이더 함수 엔트리 포인트를 main()
이라고 해야 합니다. Unity는 GLSL 셰이더를 로드할 때 소스를 VERTEX
프리프로세서 정의를 사용하여 버텍스 프로그램을 위해 한 번 로드하고 FRAGMENT
프리프로세서 정의를 사용하여 프래그먼트 프로그램을 위해 한 번 더 로드합니다. 따라서 GLSL 스니핏의 버텍스 및 프래그먼트 프로그램 부분을 분리하려면 #ifdef VERTEX .. #endif
와 #ifdef FRAGMENT .. #endif
로 둘러싸는 방법을 사용합니다. 각 GLSL 스니핏에는 버텍스 프로그램과 프래그먼트 프로그램이 모두 포함되어야 합니다.
스탠다드 포함 파일은 Cg/HLSL 셰이더를 위해 제공된 것과 일치하고, .glslinc
확장자가 있을 뿐입니다.
UnityCG.glslinc
버텍스 셰이더 입력은 미리 정의된 GLSL 변수(gl_Vertex
, gl_MultiTexCoord0
, …)에서 비롯되거나, 사용자 정의 속성입니다. 일반적으로 탄젠트 벡터에만 사용자 정의 속성이 필요합니다.
attribute vec4 Tangent;
데이터는 varying 변수를 통해 버텍스 프로그램에서 프래그먼트 프로그램으로 전달됩니다. 예:
varying vec3 lightDir; // vertex shader computes this, fragment shader uses this
Unity는 일부 프리프로세싱을 셰이더 컴파일 중에 수행합니다. 예를 들어 texture2D/texture2DProj
함수는 그래픽스 API(GlES3, GLCore)에 따라 texture/textureProj
로 바뀔 수 있습니다. 일부 확장자는 GL_OES_EGL_image_external
를 비롯한 새로운 규칙을 지원하지 않습니다.
GLSL 셰이더에서 외부 텍스처를 샘플링하려면 texture2D/texture2DProj
대신 textureExternal/textureProjExternal
호출을 사용해야 합니다.
예:
gl_FragData[0] = textureExternal(_MainTex, uv);
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.