Šviesos laužimas per pikselį
Išvaizda
- Panaudosime įstatyta HLSL funkciją refract.
- Vertex shader kodas yra toks:
float4 view_position; float4x4 view_proj_matrix; struct VS_OUTPUT { float4 Pos: POSITION; float3 Normal: TEXCOORD0; float3 View: TEXCOORD1; }; VS_OUTPUT vs_main(float4 inPos: POSITION, float3 inNormal: NORMAL) { VS_OUTPUT Out; // Compute the projected position and send out the normal Out.Pos = mul(view_proj_matrix, inPos); Out.Normal = normalize(inNormal); // Determine the view direction (i.e: eye vector) for our // refraction calculations Out.View = normalize(view_position-inPos); return Out; }
- Pixel shader kodas yra toks:
float indexOfRefractionRatio; sampler Environment; float4 ps_main(float3 inNormal: TEXCOORD0, float3 inView: TEXCOORD1) : COLOR { // Make sure all incoming vectors are normalized inNormal = normalize(inNormal); inView = normalize(inView); // Refraction texture lookup float3 refrVect = refract(-inView,inNormal,indexOfRefractionRatio).xyz; float4 refraction = texCUBE(Environment,refrVect); // Output refracted color return refraction; }