You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

5 years ago
  1. // Copyright (c) <2015> <Playdead>
  2. // This file is subject to the MIT License as seen in the root of this folder structure (LICENSE.TXT)
  3. // AUTHOR: Lasse Jon Fuglsang Pedersen <lasse@playdead.com>
  4. #ifndef __NOISE_CGINC__
  5. #define __NOISE_CGINC__
  6. //====
  7. //note: normalized random, float=[0;1[
  8. float PDnrand( float2 n ) {
  9. return frac( sin(dot(n.xy, float2(12.9898f, 78.233f)))* 43758.5453f );
  10. }
  11. float2 PDnrand2( float2 n ) {
  12. return frac( sin(dot(n.xy, float2(12.9898f, 78.233f)))* float2(43758.5453f, 28001.8384f) );
  13. }
  14. float3 PDnrand3( float2 n ) {
  15. return frac( sin(dot(n.xy, float2(12.9898f, 78.233f)))* float3(43758.5453f, 28001.8384f, 50849.4141f ) );
  16. }
  17. float4 PDnrand4( float2 n ) {
  18. return frac( sin(dot(n.xy, float2(12.9898f, 78.233f)))* float4(43758.5453f, 28001.8384f, 50849.4141f, 12996.89f) );
  19. }
  20. //====
  21. //note: signed random, float=[-1;1[
  22. float PDsrand( float2 n ) {
  23. return PDnrand( n ) * 2 - 1;
  24. }
  25. float2 PDsrand2( float2 n ) {
  26. return PDnrand2( n ) * 2 - 1;
  27. }
  28. float3 PDsrand3( float2 n ) {
  29. return PDnrand3( n ) * 2 - 1;
  30. }
  31. float4 PDsrand4( float2 n ) {
  32. return PDnrand4( n ) * 2 - 1;
  33. }
  34. #endif//__NOISE_CGINC__