background.cg

来自「3D Game Engine Design Source Code非常棒」· CG 代码 · 共 30 行

CG
30
字号
void vmain(
    in float4 iPosition : POSITION,
    out float4 oPosition : POSITION,
    out float2 oTex : TEXCOORD0)
{
    // This shader requires that you pass in vertices in screen coords.
    // This is basically a "screen polygon" shader.

	float4 ProjectionPosition;
    ProjectionPosition.xyz = iPosition.xyz;
    ProjectionPosition.w = 1.0f;
	oPosition = ProjectionPosition;

	// Determine what the texture coordinates for this vertex is in screen space
    // (Very convenient!)
    float q = 1.0 / ProjectionPosition.w;
	float2 ClipCoords = ProjectionPosition.xy * q;
	// Convert from screen coords in the range [-1...1] to [0...1] for texture lookup
	oTex.xy = (ClipCoords + 1.0) * 0.5;
}

void pmain(
    in float2 iTex : TEXCOORD0,
    out float4 oColor : COLOR,
    uniform sampler2D BackTex)
{
    // Lookup into the background texture.
    oColor = tex2D( BackTex, iTex );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?