Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
 
(49 intermediate revisions by one user not shown)
Line 1: Line 1:
EP0-TS2
+
define TransparentMirrorReflection()
0xCD7FE87A
+
0x1C0532FA
+
0x59C623B0
+
0xFF886B27
+
# contentviewer
+
 
+
#
+
# Various material definitions for the ContentViewer.
+
#
+
 
+
# note: don't check this in -- seems to cause a crash if
+
# you don't have the debugger set up correctly
+
#enableShaderProgramDebugging -vertex
+
 
+
# anything extra needed by the contentviewer should be moved
+
# from config.matShad to common.matShad.
+
#include "config.matshad"
+
 
+
# Lab extension stuff
+
 
+
define ShowRenderTypeMaterial()
+
 
   material
 
   material
       shader
+
       if (viewerRenderType = $kRenderTypeShadow)
        viewerRenderTypePred viewerRenderType
+
         create StandardShaderShadow()
 
+
      else
         pass -fixedFunction           
+
        if (viewerRenderType = $kRenderTypeThumbnail)
            ffMatCoef -diff (1, 0, 0)
+
             create TransparentBlankMirrorMaterial($kRenderTypeThumbnail)
            seti rt (viewerRenderType + 1)
+
        else           
             setc rtColor ((floor($rt / 4) % 2), (floor($rt / 2) % 2), (floor($rt) % 2))
+
            if (not $mirrorReflectionsEnabled)
            ffMatCoef -diff $rtColor
+
              set currentType (viewerRenderType)
            create LightingStates()
+
              create TransparentBlankMirrorMaterial($currentType)
              
+
             else
            stage
+
               create TransparentMirrorReflectionMaterial()
               textureBlend select(diffuse) select(diffuse)
+
             endif           
             end
+
         endif       
         end
+
       endif
       end
+
 
   end
 
   end
 
enddef
 
enddef
  
define TestGlow-AsmVertexProgram(numPass)
+
define TransparentBlankMirrorMaterial(renderType)
  vertexFormatPred position 0 true
+
 
+
  shaderProgram -target vertexProgram -method assemble
+
      bindConstants 0 -bindingID geomToCamera -constantCount 3
+
      bindConstants 3 -bindingID cameraToClip -constantCount 4
+
 
+
      shaderSource
+
        vs_1_1
+
        dcl_position v0
+
        dcl_normal  v1
+
 
+
        def c7,$color,0
+
        def c8,$offset,0
+
        def c9,$glowOffset,0
+
        def c10,$glowColor
+
        def c11, &{numPass},&{numPass},&{numPass},0
+
       
+
        add r0, v0, c8    ; add the offset
+
       
+
        ; add the glow offset along the normal
+
        mov  r1, c9
+
        mov  r2, v1
+
        mul  r0, c11, r1  ; numPass * glowOffset
+
        mad  r0, r2, r0, v0 ; (numPass * glowOffset * normal) + pos
+
        add  r0, r0, c8    ; (numPass * glowOffset * normal) + pos + offset
+
       
+
        m4x3 r1.xyz, r0, c0
+
        mov  r1.w,  v0.w
+
        m4x4 oPos,  r1, c3
+
        mov  r2,    c7
+
        add  oD0,    r2, c10
+
      endShaderSource
+
  end
+
enddef
+
 
+
define SimpleVS()
+
  # vertex program
+
  shaderProgram -target vertexProgram -method assemble
+
      bindConstants 0 -bindingID geomToCamera -constantCount 3
+
      bindConstants 3 -bindingID cameraToClip -constantCount 4
+
     
+
      shaderSource
+
        vs_1_1
+
        dcl_position v0
+
       
+
        def c7,$color
+
       
+
        m4x3 r1.xyz, v0, c0
+
        mov  r1.w,  v0.w
+
       
+
        m4x4 oPos,  r1, c3       
+
        mov  oD0,    c7
+
      endShaderSource
+
  end
+
enddef
+
 
+
define SimplePS()       
+
  # pixel program
+
  shaderProgram -target pixelProgram -method assemble
+
      shaderSource
+
        ps_1_1
+
        mov r0, v0
+
      endShaderSource
+
  end
+
enddef
+
 
+
setb glowEnabled false
+
define MaterialWithGlow()
+
# test material for glow effect
+
  seti maxRenderTargets (queryIntegerGraphicsDeviceCap(numSimultaneousRTs))
+
 
+
  material
+
 
       shader
 
       shader
         if ($maxRenderTargets > 1) # MRTs allowed, write out two color values in a single pass       
+
         validateRenderShaderContext -viewerRenderType &renderType
            pass
+
              renderTarget viewerRenderTarget -colorBuffers 2 # use two of the color buffers from the glow texture
+
              vertexFormatPred position 0 true
+
             
+
              # vertex program
+
              shaderProgram -target vertexProgram -method assemble
+
                  bindConstants 0 -bindingID geomToCamera -constantCount 3
+
                  bindConstants 3 -bindingID cameraToClip -constantCount 4
+
                 
+
                  shaderSource
+
                    vs_3_0
+
                    dcl_position v0
+
                    dcl_position0 o0
+
                    dcl_color o1
+
                   
+
                    def c7,$color
+
                   
+
                    m4x3 r1.xyz, v0, c0
+
                    mov  r1.w,  v0.w
+
                   
+
                    m4x4 o0,  r1, c3       
+
                    mov  o1,  c7
+
                  endShaderSource
+
              end
+
             
+
              # pixel program
+
              shaderProgram -target pixelProgram -method assemble
+
                  shaderSource
+
                    ps_3_0
+
                   
+
                    dcl_color v0
+
                    mov oC0, v0
+
                    mov oC1, v0
+
                  endShaderSource
+
              end
+
            end
+
        else  # only one render target allowed, use two passes
+
            if ($glowEnabled)
+
              pass # 1
+
                  # render object to glow buffer
+
                  renderTarget viewerRenderTarget
+
                 
+
                  vertexFormatPred position 0 true             
+
                  create SimpleVS()
+
                  create SimplePS()
+
              end
+
            endif       
+
 
          
 
          
             pass # 2
+
        pass              
              # render object to backbuffer
+
            shaderProgram -target vertexProgram -method assemble
              # Note: The backbuffer rendering pass should generally come after
+
               bindConstants 0 -bindingID geomToClip -constantCount 4
              # all passes that render to other textures.
+
               shaderSource
              # This is so that the render target is set to the backbuffer for
+
                  vs_1_1
               # the next object to be rendered (which may not explicitly set it).
+
                  dcl_position v0
               renderTarget viewerCompositingTarget
+
                  m4x4 oPos, v0, c0
             
+
               endShaderSource
              vertexFormatPred position 0 true           
+
              create SimpleVS()
+
               create SimplePS()
+
 
             end
 
             end
        endif
+
           
      end
+
            colorScalar (0,0,0) 0.5
  end
+
            stage
 +
              textureBlend select(colorScalar) select(colorScalar)
 +
            end          
 +
        end
 +
      end    
 
enddef
 
enddef
  
 +
define TransparentMirrorReflectionMaterial()
 +
     
 +
      shader -layer -9998  # this material must render first
 +
        validateRenderShaderContext -viewerRenderType $kRenderTypeMirror  # reflection render
  
if (not varExists(mvMaterialDefinition))
+
        pass -renderEachFrame
  set mvMaterialDefinition  StandardMaterial
+
            renderTarget $reflectionRenderTarget -setViewport viewportFromParentRenderContext
endif
+
  
materialDefinition MVLab-CubeMat
+
            depthTest true -enableDepthWrite true
  setDefinition $mvMaterialDefinition
+
  addParam stdMatDiffCoef (0, 0, 1)
+
end
+
  
materialDefinition "MVLab-SphereMat"
+
            applyStencilStateForOverlappingReflections
  setDefinition $mvMaterialDefinition
+
end
+
  
materialDefinition "MVLab-ConeMat"
+
            alphaBlend srcFactor(zero) add dstFactor(one)
  setDefinition $mvMaterialDefinition
+
  addParam stdMatDiffCoef (1, 0.5, 0)
+
end
+
  
materialDefinition MVLab-CylinderMat
+
            cullmode none
  setDefinition $mvMaterialDefinition
+
  addParam stdMatDiffCoef (1, 1, 0)
+
end
+
  
materialDefinition MVLab-MeshMat
+
            shaderProgram -target vertexProgram -method assemble           
  setDefinition $mvMaterialDefinition
+
              bindConstants 0 -bindingID geomToClipFromParentView -constantCount 4
  addParam stdMatDiffCoef (0, 0, 1) 
+
              shaderSource
end
+
                  vs_1_1
 
+
                  dcl_position v0
materialDefinition MVLab-CylinderTopMat
+
                  def c5, 1,0,0,1
  setDefinition $mvMaterialDefinition
+
                  m4x4 r0,   v0,  c0
  addParam stdMatDiffCoef $blue
+
                  mov oPos.x,  -r0
end
+
                  mov oPos.yzw, r0                 
 
+
               endShaderSource
materialDefinition MVLab-CylinderBottomMat
+
             end
  setDefinition $mvMaterialDefinition
+
  addParam stdMatDiffCoef $blue
+
end
+
 
+
materialDefinition MVLab-CylinderPanel0Mat
+
  setDefinition $mvMaterialDefinition
+
  addParam stdMatDiffCoef $green
+
end
+
 
+
materialDefinition MVLab-CylinderPanel1Mat
+
  setDefinition $mvMaterialDefinition
+
  addParam stdMatDiffCoef $yellow
+
end
+
 
+
materialDefinition MVLab-CylinderPanel2Mat
+
  setDefinition $mvMaterialDefinition
+
  addParam stdMatDiffCoef $purple
+
end
+
 
+
materialDefinition MVLab-CylinderPanel3Mat
+
  setDefinition $mvMaterialDefinition
+
  addParam stdMatDiffCoef $red
+
end
+
 
+
 
+
 
+
 
+
##############################################################
+
# Render to texture stuff
+
#
+
set mvAspect 1
+
set mvOffset ((1 - $mvAspect) / 2)
+
 
+
define MVLab-RenderToTexture()
+
  material
+
      shader
+
        vertexFormatPred position 0 true
+
 
+
        pass -fixedFunction
+
            create LightingStatesNoStdLights()
+
            colorScalar (0.8, 0.8, 1, 1)
+
 
+
            stage
+
              texture "MVLab-RenderTargetTexture"
+
 
+
              textureFilterHint bilinear bilinear
+
              textureMIPFilterHint disabled
+
              textureAddressing clamp clamp clamp
+
           
+
              ffTextureMatrix -scalev (1, $mvAspect) -trans (0, $mvOffset)
+
              textureTransformType vector2
+
             
+
               textureBlend multiply(texture colorScalar) select(texture)
+
             end  
+
 
         end
 
         end
 
       end
 
       end
  end
 
enddef
 
  
#
+
      shader -layer 6
# Doesn't perform any reflection itself -- merely texture maps
+
        validateRenderShaderContext -viewerRenderType $kRenderTypeNormal
# a screen-size texture onto geometry.
+
        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
  
# TODO: we should set a script variable or predicate
+
            alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
# if hardware vertex shaders are not available.
+
            depthTest true -enableDepthWrite false
 +
            colorScalar (0,0,0) 0.25
  
define MVLab-RenderToTextureReflection()
 
  material
 
      shader
 
        vertexFormatPred position 0 true
 
 
        pass -fixedFunction
 
           
 
            colorScalar (0.8, 0.8, 1, 1)
 
           
 
 
             stage
 
             stage
              ffTextureCoordsSource fromPosition
+
               textureTransformType vector3 homogeneous
              ffTextureMatrix -cameraToClip -scalev (-0.5, (0.5 * -$mvAspect)) -trans (0.5, 0.5)
+
              textureAddressing clamp clamp
               textureTransformType vector4 homogeneous
+
               texture $reflectionRenderTarget
           
+
               textureBlend select(texture) select(colorScalar)
               texture "MVLab-RenderTargetTexture"
+
             end
               textureBlend multiply(texture colorScalar) select(texture)
+
                     
             end  
+
 
         end
 
         end
 
       end
 
       end
   end
+
     
enddef
+
      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
# Used to clear the glow render target texture.
+
            colorScalar (0,0,0) 0.25
# by varying 'feedback', you control how much of
+
# the previous frame feeds through into the current.
+
#
+
setf feedback 0.5
+
define MVLab-Dimmer()
+
  material
+
      shader -layer -31
+
        vertexFormatPred position 0 true
+
  
+
             stage
        pass                       
+
              textureAddressing clamp clamp
             shaderProgram -target vertexProgram -method assemble
+
              texture $reflectionRenderTarget
       
+
              textureBlend select(texture) select(colorScalar)
bindConstants 0 -bindingID immediateData -data (((1 - $mvAspect) / 2), $mvAspect, 1, 1)   
+
             end
+
shaderSource
+
+
vs_1_1
+
dcl_position0 v0
+
dcl_texcoord0 v1
+
 
+
mov r0.x, -v0.x
+
mov r0.y, v0.z
+
mov r0.zw, c0
+
                                   
+
mov oPos, r0
+
 
+
mov oT0.x, v1.x
+
mul r0.y, v1.y, c0.y
+
add oT0.y, r0.y, c0.x
+
               
+
endShaderSource
+
+
            end
+
 
+
            colorScalar (0, 0, 0, (1 - $feedback))
+
             cullmode none
+
            depthTest false
+
 
              
 
              
            alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 
            stage
 
              textureBlend select(colorScalar) select(colorScalar)
 
            end
 
 
         end
 
         end
 
       end
 
       end
  end
 
 
enddef
 
enddef
  
 +
#---------------------------------------------------------------------------------------------------------------#
  
 
+
materialDefinition transparent_mirror_reflection
materialDefinition MVLab-RenderTargetMaterial
+
   setDefinition TransparentMirrorReflection
   setDefinition MVLab-RenderToTexture
+
end
+
 
+
materialDefinition MVLab-RenderTargetReflectionMaterial
+
  setDefinition MVLab-RenderToTextureReflection
+
end
+
 
+
materialDefinition MVLab-RenderTargetGlowMaterial
+
  setDefinition MVLab-Dimmer
+
  addParam feedback 0.8
+
end
+
 
+
materialDefinition MVLab-DimmerMaterial
+
  setDefinition MVLab-Dimmer
+
  addParam feedback 0.8
+
end
+
 
+
# Test of skybox compositing pass.
+
materialDefinition MVLab-CompositingPass0Material
+
  setDefinition SkyboxCompositionPassMaterial
+
  addParam skyboxCubeTexture reflectionoutdoorwater-envcube
+
end
+
 
+
materialDefinition MVLab-LightingTest
+
  setDefinition StandardMaterial
+
  addParam stdMatDiffCoef (0.5, 0.5, 0.5)
+
 
end
 
end

Latest revision as of 05: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