56 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| uniform float4x4 ViewProj;
 | |
| uniform texture2d image;
 | |
| uniform texture2d displacementMap;
 | |
| uniform float2 texelScale;
 | |
| uniform float2 displacementScale;
 | |
| 
 | |
| sampler_state textureSampler {
 | |
| 	Filter    = Linear;
 | |
| 	AddressU  = Wrap;
 | |
| 	AddressV  = Wrap;
 | |
| };
 | |
| sampler_state dispTextureSampler {
 | |
| 	Filter    = Linear;
 | |
| 	AddressU  = Clamp;
 | |
| 	AddressV  = Clamp;
 | |
| };
 | |
| 
 | |
| struct VertDataIn {
 | |
| 	float4 pos : POSITION;
 | |
| 	float2 uv  : TEXCOORD0;
 | |
| };
 | |
| 
 | |
| struct VertDataOut {
 | |
| 	float4 pos : POSITION;
 | |
| 	float2 uv  : TEXCOORD0;
 | |
| };
 | |
| 
 | |
| VertDataOut VSDefault(VertDataIn v_in)
 | |
| {
 | |
| 	VertDataOut vert_out;
 | |
| 	vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
 | |
| 	vert_out.uv  = v_in.uv;
 | |
| 	return vert_out;
 | |
| }
 | |
| 
 | |
| float4 PSDisplace(VertDataOut v_in) : TARGET
 | |
| {
 | |
| 	float2 disp = displacementMap.Sample(dispTextureSampler, v_in.uv).rg - float2(.5, .5);
 | |
| 
 | |
| 	// Method 1: Only Math
 | |
| 	disp = (floor(abs(disp * 255.0)) / 255.0) * sign(disp);
 | |
| 
 | |
| 	float2 uv = v_in.uv + (disp * texelScale * displacementScale);
 | |
| 
 | |
| 	return image.Sample(textureSampler, uv);
 | |
| }
 | |
| 
 | |
| technique Draw
 | |
| {
 | |
| 	pass
 | |
| 	{
 | |
| 		vertex_shader = VSDefault(v_in);
 | |
| 		pixel_shader  = PSDisplace(v_in);
 | |
| 	}
 | |
| }
 |