Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
Line 1: Line 1:
# Caustics
+
seti GMpoolWaterLayer 5
#
+
setf GMwmTransparency  1
 +
setf wmXSpeedGM        3    # min:0 max:100
 +
setf wmXRepeatGM      5    # min:0 max:100
 +
setf wmXWaveHeightGM  0.02  # min:0 max:100
 +
setf wmYSpeedGM        5    # min:0 max:100
 +
setf wmYRepeatGM      5  # min:0 max:100
 +
setf wmYWaveHeightGM  0.01  # min:0 max:100
  
define TiledTextureAnimShaderProgram(tilesX tilesY speed)
+
set wmReflectionTextureGM water_spec
  shaderProgram -target vertexProgram -method assemble
+
setb wmRefractionGMEnabled true
 
+
set wmRefractionTextureGM water_spec
      bindConstants 0 -bindingID frameInfo            # for time in .w
+
      bindConstants 1 -data      (&tilesX, &tilesY, &speed, 1)        # tx, ty, speed
+
      bindConstants 2 -data      ((1/&tilesX), (1/&tilesY), (&tilesY - 1), 1) # 1/tx 1/ty ty-1     
+
      if (tsIsDay)
+
        bindConstants 3 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)
+
      else
+
        bindConstants 3 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)
+
      endif
+
     
+
      shaderSource
+
        vs_1_1
+
        dcl_position v0
+
        dcl_texcoord v1
+
  
        mov oPos, v0  # clip space quad, no transforms needed.
 
     
 
        # tiled texture animation
 
        mov r0, c0
 
        mul r1, c1.z, r0.w
 
        frc r5.y, r1.y
 
       
 
        mul r1, c1.y, r5.y    # f -> [0, ty)
 
        frc r5.y, r1
 
        sub r3.y, r1, r5.y    # v' = floor(f)
 
       
 
        mul r1, c1.x, r5.y    # f -> [0, tx)
 
        frc r5.y, r1
 
        sub r3.x, r1, r5.y    # u' = floor(f)
 
  
        add r8.xy, v1.xy,  r3.xy
+
define PoolWaterSurfaceMaterialGunModWaves()
        mul oT0.xy, r8.xy, c2.xy
+
       
+
        mov oD0, c3 # also spit out diffuse color with modcolor information
+
       
+
      endShaderSource
+
 
+
  end
+
enddef
+
 
+
define CausticsGeneratorMaterial()  
+
 
   material       
 
   material       
       # This material updates a render target with the current frame
+
       shader -layer $GMpoolWaterLayer
       # of the tile animation. This is the only way to handle a repeated
+
        validateRenderShaderContext -vertexFormat position 0 required
       # animating texture (not to mention using it for projective texturing)
+
      # in the absence of clip maps.
+
        create DetermineHardwareSupport()
 +
          create GunModWaves()
 +
      end #end shader PoolWaterSurfaceMaterialGunModWaves
 +
 
 +
      # fallback shader
 +
       shader -layer $GMpoolWaterLayer
 +
        if
 +
          if ($useSWVertexShaderPath or $useFixedFunctionPath)
 +
          create SimplifiedWaterSurfaceEP3()  # common  fallback
 +
          else
 +
          create RegularWavesHLSL()
 +
          endif
 +
        else
 +
        create SimplifiedWaterSurface()      # basic fallback.
 +
        endif
 +
       end #end shader # fallback shader
 +
  end  #end material
 +
enddef # PoolWaterSurfaceMaterialGunModWaves
 +
 
 +
 
 +
define GunModWaves()
 +
 
 +
  pass
 +
#fillmode wireframe
 +
alphaBlend srcFactor(one) add dstFactor(one)
 +
 +
      shaderProgram -target vertexProgram -method compile -version 1_1
 
        
 
        
      create DetermineHardwareSupport()
+
        bindConstants 0 -bindingID geomToClip -constantCount 4
 +
        bindConstants 4 -bindingID geomToCamera -constantCount 3
 
        
 
        
      if ($causticsEnabled and $useFixedFunctionPath = false and $useSWVertexShaderPath = false)
+
        bindConstants 7 -bindingID frameInfo
 
        
 
        
         shader -layer +9999
+
         bindConstants 11 -bindingID immediateData -data ($wmXRepeatGM, 0, $wmXWaveHeightGM, $wmXSpeedGM)
 +
        bindConstants 12 -bindingID immediateData -data (0, $wmYRepeatGM, $wmYWaveHeightGM, $wmYSpeedGM)
 +
     
 +
        # pre-evaluate these
 +
        setf xscale (-$wmXRepeatGM * $wmXWaveHeightGM)
 +
        setf yscale (-$wmYRepeatGM * $wmYWaveHeightGM)
 +
        bindConstants 13 -bindingID immediateData -data ($xscale,$yscale, 1,0)
 +
        bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float
 +
        bindConstants 18 -bindingID cameraToGlobal -constantCount 3
 +
 
 +
        shaderSource
 +
     
 +
            float4 frameInfo : register(c7);
 +
            float4 waveDataX : register(c11);
 +
            float4 waveDataY : register(c12);
 +
            float4 waveDataHelper : register(c13);
 +
            float4x4 clipSpaceMatrix : register(c0);
 +
            float4x3 cameraSpaceMatrix : register(c4);
 +
            float4x3 cameraToGlobalMatrix : register(c18);
 +
           
 +
            float4 lightDirection : register(c14);
 +
            float4 lightColor : register(c15);
 +
            const static float4 refractionWeights={1,1,2,0};
 +
           
 +
            struct InputVertex
 +
            {
 +
              float4 position: POSITION0;
 +
              float3 normal : NORMAL0;
 +
              float2 texc : TEXCOORD0;
 +
            };
 +
           
 +
            struct OutputVertex
 +
            {
 +
              float4 clipPosition : POSITION;
 +
              float3 normal : TEXCOORD0;
 +
              float3 viewVector : TEXCOORD1;
 +
       
 +
            };
 +
           
 +
            static float2 waveCenter1 = {0.0, 0.0};
 +
            static float2 waveCenter2 = {-0.6, 0.2};
 +
           
 +
            static float2 timeScale = {2,1};
 +
            static float2 waveHeight = {0.04, 0.02};
 +
            static float2 distScale = {12, 8};
 +
           
 +
           
 +
           
 +
            float4 ComputeWavePositionTwoWay(float2 pos1, float2 pos2)
 +
            {
 +
           
 +
  float2 vec;
 +
              float4 dist;
 +
             
 +
              vec = waveCenter1 - pos1;
 +
              dist.x = dot(vec, vec);
 +
             
 +
              vec = waveCenter2 - pos1;
 +
              dist.y = dot(vec,vec);
 +
             
 +
  vec = waveCenter2 - pos2;
 +
              dist.z = dot(vec, vec);
 +
             
 +
              vec = waveCenter2 - pos2;
 +
              dist.w = dot(vec,vec);
 +
 
 +
  dist *= distScale.xyxy;
 +
 
 +
  float4 sinResult = sin(dist + frameInfo.w * timeScale.xyxy);
  
             pass             
+
  //sinResult = 1.0- abs(sinResult);
               renderClipSpaceRect
+
 +
  return(sinResult);
 +
 +
             }
 +
           
 +
            float2 ComputeWavePosition(float2 pos1)
 +
            {
 +
           
 +
  float2 vec;
 +
              float2 dist;
 +
 
 +
  vec = waveCenter1 - pos1;
 +
               dist.x = dot(vec, vec);
 
                
 
                
               renderTarget causticsTile -fixed (64, 64) -allocateDepthBuffer false -undo
+
               vec = waveCenter2 - pos1;
 +
              dist.y = dot(vec,vec);
 +
               
 +
  dist *= distScale.xy;
 +
 
 +
  float2 sinResult = sin(dist + frameInfo.w * timeScale);
  
               create TiledTextureAnimShaderProgram(8 4 1)
+
  //sinResult = 1.0- abs(sinResult);
 +
 +
  return(sinResult);
 +
 +
            }
 +
           
 +
            OutputVertex VertexMain( InputVertex inputVertex)
 +
            {
 +
               // Do Y-direction waves
 +
              // r0 = (x, y, z, t)
 
                
 
                
               alphaBlend srcFactor(one) add dstFactor(zero)
+
               OutputVertex outputVertex;
              alphaTest false 0
+
              alphaTestFunction acceptIfGreater
+
float4 pos = inputVertex.position;
 +
 +
float2 sample1, sample2, sample3;
 +
 +
sample1 = inputVertex.position;
 +
sample2 = inputVertex.position;
 +
sample3 = inputVertex.position;
 +
sample2.x += 0.1;
 +
sample3.y += 0.1;
 +
 +
float4 heights1=ComputeWavePositionTwoWay(sample1, sample2);
 +
float2 heights2=ComputeWavePosition(sample3);
 +
 +
 +
float3 pos1, pos2;
 +
pos1 = pos;
 +
pos2 = pos;
 +
 +
  pos.z += (heights1.x* waveHeight.x);// + heights1.y *  waveHeight.y);
 +
  pos1.z += (heights1.z* waveHeight.x);// + heights1.w *  waveHeight.y);
 +
  pos2.z += (heights2.x* waveHeight.x);// + heights2.y *  waveHeight.y);
 +
 +
pos1.x +=0.1;
 +
pos2.y +=0.1;
 +
float3 vec1, vec2;
 +
vec1 = normalize(pos1 - pos);
 +
vec2 = normalize(pos2 - pos);
 +
 +
float3 normal = cross(vec1, vec2);
 +
 +
normal = mul(normal, (float3x3)cameraSpaceMatrix);
  
              depthTest false -enableDepthWrite false
+
float3 viewVector = mul(pos, cameraSpaceMatrix);
              depthTestFunction accept
+
 
+
outputVertex.viewVector = normalize(-viewVector);
              # 7/24/2004 Fix bug with kRenderTypeNormal default stencil state and nv40.
+
               # It reads random stencil values even this target has no depth stencil target.              
+
               outputVertex.clipPosition = mul(pos, clipSpaceMatrix);
               # This stencil call will break pixo, but pixo does not show caustics.
+
               outputVertex.normal = normal;
               stencil false
+
               return(outputVertex);
 
+
              fillmode $stdMatFillMode                           
+
 
                
 
                
              shaderProgram -target pixelProgram -method compile -version 1_1             
+
        }
                  shaderSource                           
+
           
                    sampler caustics;
+
        endShaderSource
                    struct cInputPixel
+
     
                    {
+
      end # end shaderProgram
                        float4 color : COLOR;
+
                        float2 tc0 : TEXCOORD0;
+
                    };
+
                    float4 PixelMain(cInputPixel pi) : COLOR
+
                    {       
+
                        float4 texColor = tex2D(caustics, pi.tc0);                                               
+
                        return texColor*pi.color;                       
+
                    }
+
                  endShaderSource
+
              end                                                   
+
             
+
              sampler 0
+
                  texture causticsTiled
+
                  textureAddressing tile tile                 
+
              end
+
                             
+
            end  
+
        end
+
      else
+
        shader
+
 
          
 
          
         end
+
      shaderProgram -target pixelProgram -method assemble
       endif
+
         bindConstants 0 -bindingID allStandardLightData -constantCount 4 -constantType float
  end
+
 
enddef
+
        shaderSource
   
+
            ps_2_0
setf causticsStrength 0.8
+
            def c10,20,4,0,0
setf causticsBaseStrength 0.5
+
            def c11, 0,0.5,1,2
 +
            dcl t0
 +
            dcl t1 ; v
 +
dcl_cube s0
 +
     
 +
            nrm r0, t0       ; n
 +
           
 +
            add r1, r0, r0  ; 2N
 +
           
 +
            dp3 r1.w, r0, t1 ; N.V
 +
mad r2.xyz, r1, r1.w, -t1    ; 2N * (N.V) -V
 +
 +
texld r5, r2, s0
 +
 +
dp3 r3.x, r2, c0 ; R.L
 +
pow r4, r3.x, c10.x
 +
 +
mov_sat r1.x, r1.w
 +
 +
add r6.x, c11.z, -r1.x      ; 1 - Fresnel
 +
 +
pow r3.y, r6.x, c10.y  ; N.V ^ 4
 +
 +
mul r7, r5, r3.y
 +
mad r4, r4, r3.y, r7
 +
mul r4, r4, c11.y
 +
 +
mov oC0, r4
 +
           
 +
        endShaderSource
 +
      end
 +
     
 +
      sampler 0
 +
texture $wmReflectionTextureGM
 +
textureAddressing clamp clamp clamp
 +
      end
 +
  end  # pass
 +
 
 +
enddef # GunModWaves

Revision as of 23:56, 2 September 2007

seti GMpoolWaterLayer 5 setf GMwmTransparency 1 setf wmXSpeedGM 3 # min:0 max:100 setf wmXRepeatGM 5 # min:0 max:100 setf wmXWaveHeightGM 0.02 # min:0 max:100 setf wmYSpeedGM 5 # min:0 max:100 setf wmYRepeatGM 5 # min:0 max:100 setf wmYWaveHeightGM 0.01 # min:0 max:100

set wmReflectionTextureGM water_spec setb wmRefractionGMEnabled true set wmRefractionTextureGM water_spec


define PoolWaterSurfaceMaterialGunModWaves()

  material      
     shader -layer $GMpoolWaterLayer
        validateRenderShaderContext -vertexFormat position 0 required

        create DetermineHardwareSupport()
          create GunModWaves()
     end #end shader PoolWaterSurfaceMaterialGunModWaves
      # fallback shader
     shader -layer $GMpoolWaterLayer
        if 
          if ($useSWVertexShaderPath or $useFixedFunctionPath)
          create SimplifiedWaterSurfaceEP3()  # common  fallback
          else
          create RegularWavesHLSL()
          endif
        else
        create SimplifiedWaterSurface()      # basic fallback.
        endif
     end #end shader # fallback shader
  end  #end material

enddef # PoolWaterSurfaceMaterialGunModWaves


define GunModWaves()

  pass

#fillmode wireframe alphaBlend srcFactor(one) add dstFactor(one)

     shaderProgram -target vertexProgram -method compile -version 1_1
     
        bindConstants 0 -bindingID geomToClip -constantCount 4
        bindConstants 4 -bindingID geomToCamera -constantCount 3
     
        bindConstants 7 -bindingID frameInfo 
     
        bindConstants 11 -bindingID immediateData -data ($wmXRepeatGM, 0, $wmXWaveHeightGM, $wmXSpeedGM)
        bindConstants 12 -bindingID immediateData -data (0, $wmYRepeatGM, $wmYWaveHeightGM, $wmYSpeedGM)
     
        # pre-evaluate these
        setf xscale (-$wmXRepeatGM * $wmXWaveHeightGM)
        setf yscale (-$wmYRepeatGM * $wmYWaveHeightGM)
        bindConstants 13 -bindingID immediateData -data ($xscale,$yscale, 1,0)
        bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float
        bindConstants 18 -bindingID cameraToGlobal -constantCount 3
  
        shaderSource
     
           float4 frameInfo : register(c7);
           float4 waveDataX : register(c11);
           float4 waveDataY : register(c12);
           float4 waveDataHelper : register(c13);
           float4x4 clipSpaceMatrix : register(c0);
           float4x3 cameraSpaceMatrix : register(c4);
           float4x3 cameraToGlobalMatrix : register(c18);
           
           float4 lightDirection : register(c14);
           float4 lightColor : register(c15);
           const static float4 refractionWeights={1,1,2,0};
           
           struct InputVertex
           {
              float4 position: POSITION0;
              float3 normal : NORMAL0;
              float2 texc : TEXCOORD0;
           };
           
           struct OutputVertex
           {
              float4 clipPosition : POSITION;
              float3 normal : TEXCOORD0;
              float3 viewVector : TEXCOORD1;
        
           };
           
           static float2 waveCenter1 = {0.0, 0.0};
           static float2 waveCenter2 = {-0.6, 0.2};
           
           static float2 timeScale = {2,1};
           static float2 waveHeight = {0.04, 0.02};
           static float2 distScale = {12, 8};
           
           
           
           float4 ComputeWavePositionTwoWay(float2 pos1, float2 pos2)
           {
           

float2 vec;

              float4 dist;
              
              vec = waveCenter1 - pos1;
              dist.x = dot(vec, vec);
              
              vec = waveCenter2 - pos1;
              dist.y = dot(vec,vec);
              

vec = waveCenter2 - pos2;

              dist.z = dot(vec, vec);
              
              vec = waveCenter2 - pos2;
              dist.w = dot(vec,vec);

dist *= distScale.xyxy;

float4 sinResult = sin(dist + frameInfo.w * timeScale.xyxy);

//sinResult = 1.0- abs(sinResult);

return(sinResult);

           }
           
           float2 ComputeWavePosition(float2 pos1)
           {
           

float2 vec;

              float2 dist;

vec = waveCenter1 - pos1;

              dist.x = dot(vec, vec);
              
              vec = waveCenter2 - pos1;
              dist.y = dot(vec,vec);
              		   

dist *= distScale.xy;

float2 sinResult = sin(dist + frameInfo.w * timeScale);

//sinResult = 1.0- abs(sinResult);

return(sinResult);

           }
           
           OutputVertex VertexMain( InputVertex inputVertex)
           {
              // Do	Y-direction	waves
              // r0	= (x, y, z,	t)
              
              OutputVertex outputVertex;

float4 pos = inputVertex.position;

float2 sample1, sample2, sample3;

sample1 = inputVertex.position; sample2 = inputVertex.position; sample3 = inputVertex.position; sample2.x += 0.1; sample3.y += 0.1;

float4 heights1=ComputeWavePositionTwoWay(sample1, sample2); float2 heights2=ComputeWavePosition(sample3);


float3 pos1, pos2; pos1 = pos; pos2 = pos;

pos.z += (heights1.x* waveHeight.x);// + heights1.y * waveHeight.y); pos1.z += (heights1.z* waveHeight.x);// + heights1.w * waveHeight.y); pos2.z += (heights2.x* waveHeight.x);// + heights2.y * waveHeight.y);

pos1.x +=0.1; pos2.y +=0.1; float3 vec1, vec2; vec1 = normalize(pos1 - pos); vec2 = normalize(pos2 - pos);

float3 normal = cross(vec1, vec2);

normal = mul(normal, (float3x3)cameraSpaceMatrix);

float3 viewVector = mul(pos, cameraSpaceMatrix);

outputVertex.viewVector = normalize(-viewVector);

              outputVertex.clipPosition = mul(pos, clipSpaceMatrix);
              outputVertex.normal = normal;
              return(outputVertex);
              
        }
           
        endShaderSource
     
     end # end shaderProgram
        
     shaderProgram -target pixelProgram -method assemble
        bindConstants 0 -bindingID allStandardLightData -constantCount 4 -constantType float
        shaderSource
           ps_2_0
           def c10,20,4,0,0
           def c11, 0,0.5,1,2
           dcl t0
           dcl t1 ; v

dcl_cube s0

           nrm r0, t0       ; n
           
           add r1, r0, r0  ; 2N
           
           dp3 r1.w, r0, t1 ; N.V

mad r2.xyz, r1, r1.w, -t1  ; 2N * (N.V) -V

texld r5, r2, s0

dp3 r3.x, r2, c0  ; R.L pow r4, r3.x, c10.x

mov_sat r1.x, r1.w

add r6.x, c11.z, -r1.x  ; 1 - Fresnel

pow r3.y, r6.x, c10.y  ; N.V ^ 4

mul r7, r5, r3.y mad r4, r4, r3.y, r7 mul r4, r4, c11.y

mov oC0, r4

        endShaderSource
     end
     
     sampler 0 

texture $wmReflectionTextureGM textureAddressing clamp clamp clamp

     end
  end  # pass
  

enddef # GunModWaves

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox