Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
(pool-2b)
 
(6 intermediate revisions by one user not shown)
Line 1: Line 1:
shaderSource
+
define TransparentMirrorReflection()
float4 frameInfo : register(c7);
+
  material
float4 waveDataX : register(c11);
+
      if (viewerRenderType = $kRenderTypeShadow)
float4 waveDataY : register(c12);
+
        create StandardShaderShadow()
float4 waveDataHelper : register(c13);
+
      else
float4x4 clipSpaceMatrix : register(c0);
+
        if (viewerRenderType = $kRenderTypeThumbnail)
float4x3 cameraSpaceMatrix : register(c4);
+
            create TransparentBlankMirrorMaterial($kRenderTypeThumbnail)
float4x3 cameraToGlobalMatrix : register(c18);
+
        else           
float4x3 cameraToGeomMatrix : register(c21);
+
             if (not $mirrorReflectionsEnabled)
             float4 nightColor: register(c25);
+
              set currentType (viewerRenderType)
float4 lightDirection : register(c14);
+
              create TransparentBlankMirrorMaterial($currentType)
float4 lightColor : register(c15);
+
            else
float4 lightSpecular : register(c16);
+
              create TransparentMirrorReflectionMaterial()
const static float4 refractionWeights={1,1,2,0};
+
            endif           
const static float4 layerBlue={0.3, 0.7, 1.0, 1};
+
        endif       
+
      endif
struct InputVertex
+
  end
{
+
enddef
float3 position: POSITION0;
+
 
float3 normal : NORMAL0;
+
define TransparentBlankMirrorMaterial(renderType)
};
+
      shader
+
        validateRenderShaderContext -viewerRenderType  &renderType
struct OutputVertex
+
       
{
+
        pass           
float4 clipPosition : POSITION;
+
            shaderProgram -target vertexProgram -method assemble
float4 sPos        : TEXCOORD0;
+
               bindConstants 0 -bindingID geomToClip -constantCount 4
float2 Wave0        : TEXCOORD1;
+
               shaderSource
               float2 Wave1        : TEXCOORD2;
+
                  vs_1_1
               float2 Wave2        : TEXCOORD3;
+
                  dcl_position v0
              float2 Wave3        : TEXCOORD4;
+
                  m4x4 oPos, v0, c0
              float3 Eye          : TEXCOORD5;
+
               endShaderSource
               float4 specular    : COLOR0;   
+
            end
};
+
 
              
 
              
OutputVertex VertexMain( InputVertex inputVertex)
+
            colorScalar (0,0,0) 0.5
{
+
            stage
// Do Y-direction waves
+
              textureBlend select(colorScalar) select(colorScalar)
// r0 = (x, y, z, t)
+
             end           
+
        end
OutputVertex outputVertex;
+
      end     
+
enddef
float4 posAndTime;
+
posAndTime.xyz = inputVertex.position;
+
posAndTime.w = frameInfo.w;
+
+
float temp = dot(posAndTime, waveDataX);
+
float z = sin(temp) * waveDataX.z + inputVertex.position.z;
+
temp = dot(posAndTime, waveDataY);
+
posAndTime.z =  z + sin(temp) * waveDataY.z;
+
posAndTime.w = 1.0f;
+
+
outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix);
+
outputVertex.sPos = float4(0.5f*(outputVertex.clipPosition.ww - outputVertex.clipPosition.xy), outputVertex.clipPosition.ww);
+
+
float3 waveNormal = normalize(inputVertex.normal + float3(cos(temp)*waveDataHelper.xy, 0));
+
        float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix));
+
float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix);
+
float3 viewVector = normalize(-cameraSpacePosition);
+
+
float3 halfVector = normalize(viewVector + lightDirection);
+
outputVertex.specular = lightSpecular*pow(dot(cameraSpaceNormal, halfVector), 50)*nightColor*lightColor*0.5;
+
+
+
float2 fTranslation=float2(fmod(frameInfo.w, 100)*0.005, fmod(frameInfo.w, 100)*0.005);
+
              float2 vTexCoords = posAndTime.xy*0.05;
+
               
+
              // Output bump layers texture coordinates   
+
              float fSinTranslation=sin(fTranslation*100)*0.005;
+
              float2 vTranslation0=fTranslation+fSinTranslation;
+
              float2 vTranslation1=fTranslation-fSinTranslation;
+
              float2 vTranslation2=fTranslation;
+
               
+
              // Scale texture coordinates to get mix of low/high frequency details
+
              outputVertex.Wave0.xy = vTexCoords.xy+fTranslation*2.0;
+
              outputVertex.Wave1.xy = vTexCoords.xy*2.0+fTranslation*4.0;
+
              outputVertex.Wave2.xy = vTexCoords.xy*7.0+fTranslation*2.0;
+
              outputVertex.Wave3.xy = vTexCoords.xy*12.0+fTranslation;               
+
                                   
+
            // compute binormal
+
            float3 binormal = normalize(cross(waveNormal, float3(1.0f, 0.0f, 0.0f)));              
+
            float3 tangent = normalize(cross(binormal, waveNormal));
+
           
+
            // tangent space matrix
+
            float3x3 objToTangentSpace = float3x3(tangent, binormal, waveNormal);
+
           
+
            float3 viewVectorInObjSpace = mul(viewVector, (float3x3)cameraToGeomMatrix);
+
           
+
            outputVertex.Eye.xyz = mul(objToTangentSpace, viewVectorInObjSpace);
+
+
+
return(outputVertex);
+
}
+
  
 +
define TransparentMirrorReflectionMaterial()
 +
     
 +
      shader -layer -9998  # this material must render first
 +
        validateRenderShaderContext -viewerRenderType $kRenderTypeMirror  # reflection render
  
endShaderSource 
+
        pass -renderEachFrame
end # shaderProgram
+
             renderTarget $reflectionRenderTarget -setViewport viewportFromParentRenderContext
+
shaderProgram -target pixelProgram -method compile -version 2_0             
+
        shaderSource                           
+
             sampler reflect; 
+
            sampler bump;         
+
            struct cInputPixel
+
            {             
+
              float4 sPos        : TEXCOORD0;             
+
              float2 Wave0        : TEXCOORD1;
+
              float2 Wave1        : TEXCOORD2;
+
              float2 Wave2        : TEXCOORD3;
+
              float2 Wave3        : TEXCOORD4;
+
              float3 Eye          : TEXCOORD5;
+
              float4 specular    : COLOR0;
+
            };
+
           
+
            float Fresnel(float NdotL, float fresnelBias, float fresnelPow, float facing)
+
            {             
+
              return max(fresnelBias + (1.0f - fresnelBias)*pow(facing, fresnelPow), 0.0);
+
            }
+
           
+
            float4 PixelMain(cInputPixel pi) : COLOR
+
            {       
+
              float3 vEye = normalize(pi.Eye);
+
  
              // Get bump layers
+
            depthTest true -enableDepthWrite true
              float3 vBumpTexA = tex2D(bump, pi.Wave0.xy).xyz;
+
 
              float3 vBumpTexB = tex2D(bump, pi.Wave1.xy).xyz;
+
            applyStencilStateForOverlappingReflections
               float3 vBumpTexC = tex2D(bump, pi.Wave2.xy).xyz;
+
 
               float3 vBumpTexD = tex2D(bump, pi.Wave3.xy).xyz;
+
            alphaBlend srcFactor(zero) add dstFactor(one)
                  
+
 
               // Average bump layers
+
            cullmode none
               float3 vBumpTex=normalize(2.0 * (vBumpTexA.xyz + vBumpTexB.xyz + vBumpTexC.xyz + vBumpTexD.xyz)-4.0);
+
 
               
+
            shaderProgram -target vertexProgram -method assemble           
               // Apply individual bump scale for refraction and reflection             
+
               bindConstants 0 -bindingID geomToClipFromParentView -constantCount 4
              float3 vReflBump = vBumpTex.xyz * float3(0.1, 0.1, 1.0); 
+
               shaderSource
             
+
                  vs_1_1
              float4 vReflection = tex2Dproj(reflect, pi.sPos + float4(vReflBump.xy, 0.0f, 0.0f));//*0.001 + float4(2.0*vBumpTexD-1.0f.xxx, 1);
+
                  dcl_position v0
             
+
                  def c5, 1,0,0,1
              // Compute Fresnel term
+
                  m4x4 r0,  v0,  c0
              float NdotL = max(dot(vEye, vReflBump), 0);
+
                  mov oPos.x,  -r0
              float facing = (1.0 - NdotL);
+
                  mov oPos.yzw, r0                  
              float fresnel = Fresnel(NdotL, 0.2, 5.0, facing);
+
               endShaderSource
                             
+
            end
              vReflection.a = fresnel;             
+
        end
               return saturate(vReflection + float4(0.0, 0.25, 0.5, 0.0) + pi.specular);
+
      end
             }
+
 
         endShaderSource
+
      shader -layer 6
       end                                                    
+
        validateRenderShaderContext -viewerRenderType $kRenderTypeNormal
 +
        pass -modifiedEachFrameHint
 +
            shaderProgram -target vertexProgram -method assemble           
 +
               bindConstants 0 -bindingID geomToClip -constantCount 4
 +
              bindConstants 4 -bindingID clipToViewTarget -constantCount 4
 +
               shaderSource
 +
                  vs_1_1
 +
                  dcl_position v0
 +
                  def c8,    -0.5, -0.5, 1, 1
 +
                  def c9,     0.5, 0.5, 0, 0
 +
                  def c10,    0.25, 0.25, 0, 0
 +
                  m4x4 r0,  v0,  c0
 +
                  mov oPos, r0
 +
                  mul r2, c9, r0.w
 +
                  mad r4, r0, c8, r2
 +
                  rcp r3.x, c4.x                                 
 +
                  rcp r3.y, c5.y
 +
                  mov r3.zw, c9.zw
 +
                  mul r3, r3, c10
 +
                  mad r6, r0, r3, r4
 +
                  mov oT0, r6.xyww
 +
               endShaderSource             
 +
            end
 +
 
 +
            alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
            depthTest true -enableDepthWrite false
 +
            colorScalar (0,0,0) 0.25
 +
 
 +
            stage
 +
              textureTransformType vector3 homogeneous
 +
              textureAddressing clamp clamp
 +
              texture $reflectionRenderTarget
 +
              textureBlend select(texture) select(colorScalar)
 +
             end
 +
                     
 +
         end
 +
       end
 
        
 
        
       sampler reflect
+
       shader -layer 6     
         texture "PoolReflection"
+
         validateRenderShaderContext -viewerRenderType $kRenderTypeNormal
         textureAddressing clamp clamp
+
         pass -modifiedEachFrameHint
      end
+
            shaderProgram -target vertexProgram -method assemble           
     
+
              bindConstants 0 -bindingID geomToClip -constantCount 4
      sampler bump
+
              bindConstants 4 -bindingID clipToViewTarget -constantCount 4
        texture "poolShape-body-bump"
+
              shaderSource
        textureAddressing tile tile
+
                  vs_1_1
      end  
+
                  dcl_position v0
 +
                  def c8,    -0.5, -0.5, 1, 1
 +
                  def c9,    0.5,  0.5, 0, 0
 +
                  def c10,    0.25, 0.25, 0, 0
 +
                  m4x4 r0,  v0,  c0
 +
                  mov oPos, r0
 +
                  mul r2, c9, r0.w
 +
                  mad r4, r0, c8, r2
 +
                  rcp r3.x, c4.x                                 
 +
                  rcp r3.y, c5.y
 +
                  mov r3.zw, c9.zw
 +
                  mul r3, r3, c10
 +
                  mad r1, r0, r3, r4
 +
                  rcp r1.w, r1.w
 +
                  mul oT0.xy, r1.w, r1.xy
 +
              endShaderSource             
 +
            end
 +
 
 +
            alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
            depthTest true -enableDepthWrite false
 +
            colorScalar (0,0,0) 0.25
 +
 
 +
            stage
 +
              textureAddressing clamp clamp
 +
              texture $reflectionRenderTarget
 +
              textureBlend select(texture) select(colorScalar)
 +
            end
 
              
 
              
end # end pass
+
        end
 
+
      end
 
enddef
 
enddef
 +
 +
#---------------------------------------------------------------------------------------------------------------#
 +
 +
materialDefinition transparent_mirror_reflection
 +
  setDefinition TransparentMirrorReflection
 +
end

Latest revision as of 00:44, 9 July 2009

define TransparentMirrorReflection()

  material
     if (viewerRenderType = $kRenderTypeShadow)
        create StandardShaderShadow()
     else
        if (viewerRenderType = $kRenderTypeThumbnail)
           create TransparentBlankMirrorMaterial($kRenderTypeThumbnail)
        else            
           if (not $mirrorReflectionsEnabled)
              set currentType (viewerRenderType)
              create TransparentBlankMirrorMaterial($currentType)
           else
              create TransparentMirrorReflectionMaterial()
           endif            
        endif         
     endif
  end

enddef

define TransparentBlankMirrorMaterial(renderType)

     shader
        validateRenderShaderContext -viewerRenderType  &renderType
        
        pass             
           shaderProgram -target vertexProgram -method assemble
              bindConstants 0 -bindingID geomToClip -constantCount 4
              shaderSource
                 vs_1_1
                 dcl_position v0
                 m4x4 oPos, v0, c0
              endShaderSource
           end
           
           colorScalar (0,0,0) 0.5
           stage
              textureBlend select(colorScalar) select(colorScalar)
           end            
        end
     end      

enddef

define TransparentMirrorReflectionMaterial()

     shader -layer -9998   # this material must render first
        validateRenderShaderContext -viewerRenderType $kRenderTypeMirror  # reflection render
        pass -renderEachFrame
           renderTarget $reflectionRenderTarget -setViewport viewportFromParentRenderContext
           depthTest true -enableDepthWrite true
           applyStencilStateForOverlappingReflections
           alphaBlend srcFactor(zero) add dstFactor(one)
           cullmode none
           shaderProgram -target vertexProgram -method assemble            
              bindConstants 0 -bindingID geomToClipFromParentView -constantCount 4
              shaderSource
                 vs_1_1
                 dcl_position v0
                 def c5, 1,0,0,1
                 m4x4 r0,   v0,  c0
                 mov oPos.x,  -r0
                 mov oPos.yzw, r0                  
              endShaderSource
           end
        end
     end
     shader -layer 6
        validateRenderShaderContext -viewerRenderType $kRenderTypeNormal
        pass -modifiedEachFrameHint
           shaderProgram -target vertexProgram -method assemble            
              bindConstants 0 -bindingID geomToClip -constantCount 4
              bindConstants 4 -bindingID clipToViewTarget -constantCount 4
              shaderSource
                 vs_1_1
                 dcl_position v0
                 def c8,    -0.5, -0.5, 1, 1
                 def c9,     0.5,  0.5, 0, 0 
                 def c10,    0.25, 0.25, 0, 0
                 m4x4 r0,   v0,  c0
                 mov oPos, r0
                 mul r2, c9, r0.w
                 mad r4, r0, c8, r2
                 rcp r3.x, c4.x                                   
                 rcp r3.y, c5.y
                 mov r3.zw, c9.zw
                 mul r3, r3, c10
                 mad r6, r0, r3, r4
                 mov oT0, r6.xyww
              endShaderSource               
           end
           alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
           depthTest true -enableDepthWrite false
           colorScalar (0,0,0) 0.25
           stage
              textureTransformType vector3 homogeneous
              textureAddressing clamp clamp
              texture $reflectionRenderTarget
              textureBlend select(texture) select(colorScalar)
           end
                      
        end
     end
     
     shader -layer 6      
        validateRenderShaderContext -viewerRenderType $kRenderTypeNormal
        pass -modifiedEachFrameHint
           shaderProgram -target vertexProgram -method assemble            
              bindConstants 0 -bindingID geomToClip -constantCount 4
              bindConstants 4 -bindingID clipToViewTarget -constantCount 4
              shaderSource
                 vs_1_1
                 dcl_position v0
                 def c8,    -0.5, -0.5, 1, 1
                 def c9,     0.5,  0.5, 0, 0
                 def c10,    0.25, 0.25, 0, 0
                 m4x4 r0,   v0,  c0
                 mov oPos, r0
                 mul r2, c9, r0.w
                 mad r4, r0, c8, r2
                 rcp r3.x, c4.x                                   
                 rcp r3.y, c5.y
                 mov r3.zw, c9.zw
                 mul r3, r3, c10
                 mad r1, r0, r3, r4
                 rcp r1.w, r1.w
                 mul oT0.xy, r1.w, r1.xy
              endShaderSource               
           end
           alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
           depthTest true -enableDepthWrite false
           colorScalar (0,0,0) 0.25
           stage
              textureAddressing clamp clamp
              texture $reflectionRenderTarget
              textureBlend select(texture) select(colorScalar)
           end
           
        end
     end

enddef

  1. ---------------------------------------------------------------------------------------------------------------#

materialDefinition transparent_mirror_reflection

  setDefinition TransparentMirrorReflection

end

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox