Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- texture theEnvironmentCube
- <
- string ResourceName = "default_reflection.dds";
- string TextureType = "CUBE";
- >;
- samplerCUBE environmentTexture = sampler_state
- {
- Texture = <theEnvironmentCube>;
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- AddressW = Clamp;
- };
- /************* NON-TWEAKABLES **************/
- float4x4 viewI : ViewInverse < string UIWidget="None"; >;
- float4x4 viewT : ViewTranspose < string UIWidget="None"; >;
- float4x4 worldIT : WorldInverseTranspose < string UIWidget="None"; >;
- float4x4 world : World < string UIWidget="None"; >;
- float4x4 worldView : WorldView < string UIWidget="None"; >;
- float4x4 worldViewIT : WorldViewInverseTranspose < string UIWidget="None"; >;
- float4x4 worldViewProj : WorldViewProjection < string UIWidget="None"; >;
- /*********** Vertex shader ******/
- void reflectionVS(float4 position : POSITION,
- float4 normal : NORMAL,
- out float4 clipPosition : POSITION,
- out float3 reflectDirection : TEXCOORD0) {
- // compute standard clip position
- clipPosition = mul(position, worldViewProj);
- // In order to complete this exercise, you need to add some
- // code to this vertex shader in order to compute
- // the reflected direction of a ray from the viewing
- // direction and normal vector, both expressed in the
- // world coordinate system. Then, repeat the exercise, but this
- // computing both the viewing direction and the normal in the
- // camera coordinate system
- float3 worldSurfaceNormal = normalize( mul(normal, worldIT).xyz);
- float3 worldPosition = mul(position, world).xyz;
- float3 viewingDirection = normalize( worldPosition - viewI[3].xyz );
- reflectDirection = reflect(viewingDirection, worldSurfaceNormal);
- }
- void reflectionPS(float3 reflectDirection : TEXCOORD0,
- out float4 color : COLOR) {
- color = texCUBE(environmentTexture, reflectDirection);
- }
- technique reflection {
- pass p0 {
- VertexShader = compile vs_1_1 reflectionVS();
- PixelShader = compile ps_2_0 reflectionPS();
- }
- }
- void reflectionVS2(float4 position : POSITION,
- float4 normal : NORMAL,
- out float4 clipPosition : POSITION,
- out float3 normalOut : TEXCOORD0,
- out float4 posOut : TEXCOORD1) {
- // compute standard clip position
- clipPosition = mul(position, worldViewProj);
- // In order to complete this exercise, you need to add some
- // code to this vertex shader in order to compute
- // the reflected direction of a ray from the viewing
- // direction and normal vector, both expressed in the
- // world coordinate system. Then, repeat the exercise, but this
- // computing both the viewing direction and the normal in the
- // camera coordinate system
- normalOut = normal;
- posOut = position;
- //reflectDirection = reflect(viewingDirection, worldSurfaceNormal);
- }
- void reflectionPS2(float3 normal : TEXCOORD0,
- float3 position : TEXCOORD1,
- out float4 color : COLOR) {
- float3 worldSurfaceNormal = normalize( mul(normal, worldIT).xyz);
- float3 worldPosition = mul(position, world).xyz;
- float3 viewingDirection = normalize( worldPosition - viewI[3].xyz );
- float3 reflectDirection = reflect(viewingDirection, worldSurfaceNormal);
- color = texCUBE(environmentTexture, reflectDirection);
- }
- technique reflection2 {
- pass p0 {
- VertexShader = compile vs_1_1 reflectionVS2();
- PixelShader = compile ps_2_0 reflectionPS2();
- }
- }
- void reflectionVS3(float4 position : POSITION,
- float4 normal : NORMAL,
- out float4 clipPosition : POSITION,
- out float3 normalOut : TEXCOORD0,
- out float4 posOut : TEXCOORD1) {
- // compute standard clip position
- clipPosition = mul(position, worldViewProj);
- // In order to complete this exercise, you need to add some
- // code to this vertex shader in order to compute
- // the reflected direction of a ray from the viewing
- // direction and normal vector, both expressed in the
- // world coordinate system. Then, repeat the exercise, but this
- // computing both the viewing direction and the normal in the
- // camera coordinate system
- normalOut = normal;
- posOut = position;
- //reflectDirection = reflect(viewingDirection, worldSurfaceNormal);
- }
- void reflectionPS3(float3 normal : TEXCOORD0,
- float3 position : TEXCOORD1,
- out float4 color : COLOR) {
- float3 worldSurfaceNormal = normalize( mul(normal, worldViewIT).xyz);
- float3 worldPosition = mul(position, worldView).xyz;
- float3 viewingDirection = normalize( worldPosition );
- float3 reflectDirection = reflect(viewingDirection, worldSurfaceNormal);
- color = texCUBE(environmentTexture, reflectDirection);
- }
- technique reflection3 {
- pass p0 {
- VertexShader = compile vs_1_1 reflectionVS3();
- PixelShader = compile ps_2_0 reflectionPS3();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement